JSGraphics.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "Precompiled.h"
  5. #include "../Javascript/JSGraphics.h"
  6. #include "../Javascript/JSVM.h"
  7. #include "../Graphics/Light.h"
  8. namespace Atomic
  9. {
  10. static int Light_SetShadowCascade(duk_context* ctx)
  11. {
  12. //CascadeParameters(float split1, float split2, float split3, float split4, float fadeStart, float biasAutoAdjust = 1.0f) :
  13. int numargs = duk_get_top(ctx);
  14. float split1;
  15. float split2;
  16. float split3;
  17. float split4;
  18. float fadeStart;
  19. float biasAutoAdjust = 1.0f;
  20. split1 = (float) duk_to_number(ctx, 0);
  21. split2 = (float) duk_to_number(ctx, 1);
  22. split3 = (float) duk_to_number(ctx, 2);
  23. split4 = (float) duk_to_number(ctx, 3);
  24. fadeStart = (float) duk_to_number(ctx, 4);
  25. if (numargs == 6)
  26. biasAutoAdjust = (float) duk_to_number(ctx, 5);
  27. CascadeParameters cparms(split1, split2, split3, split4, fadeStart, biasAutoAdjust);
  28. duk_push_this(ctx);
  29. Light* light = js_to_class_instance<Light>(ctx, -1, 0);
  30. light->SetShadowCascade(cparms);
  31. return 0;
  32. }
  33. static int Light_SetShadowBias(duk_context* ctx)
  34. {
  35. float constantBias = (float) duk_to_number(ctx, 0);
  36. float slopeScaledBias = (float) duk_to_number(ctx, 1);
  37. BiasParameters bparms(constantBias, slopeScaledBias);
  38. duk_push_this(ctx);
  39. Light* light = js_to_class_instance<Light>(ctx, -1, 0);
  40. light->SetShadowBias(bparms);
  41. return 0;
  42. }
  43. void jsapi_init_graphics(JSVM* vm)
  44. {
  45. duk_context* ctx = vm->GetJSContext();
  46. js_class_get_prototype(ctx, "Light");
  47. duk_push_c_function(ctx, Light_SetShadowCascade, DUK_VARARGS);
  48. duk_put_prop_string(ctx, -2, "setShadowCascade");
  49. duk_push_c_function(ctx, Light_SetShadowBias, 2);
  50. duk_put_prop_string(ctx, -2, "setShadowBias");
  51. duk_pop(ctx);
  52. }
  53. }