summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/3rdparty/glsl-optimizer/src/node/compiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/3rdparty/glsl-optimizer/src/node/compiler.cpp')
-rw-r--r--3rdparty/bgfx/3rdparty/glsl-optimizer/src/node/compiler.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/3rdparty/bgfx/3rdparty/glsl-optimizer/src/node/compiler.cpp b/3rdparty/bgfx/3rdparty/glsl-optimizer/src/node/compiler.cpp
new file mode 100644
index 00000000000..af2f4920722
--- /dev/null
+++ b/3rdparty/bgfx/3rdparty/glsl-optimizer/src/node/compiler.cpp
@@ -0,0 +1,87 @@
+#include "compiler.h"
+
+using namespace v8;
+using namespace node;
+
+
+Persistent<Function> Compiler::constructor;
+
+//----------------------------------------------------------------------
+
+Compiler::Compiler(glslopt_target target)
+{
+ _binding = glslopt_initialize(target);
+}
+
+//----------------------------------------------------------------------
+
+Compiler::~Compiler()
+{
+ release();
+}
+
+//----------------------------------------------------------------------
+
+void Compiler::release()
+{
+ if (_binding)
+ {
+ glslopt_cleanup(_binding);
+
+ _binding = 0;
+ }
+}
+
+//----------------------------------------------------------------------
+
+void Compiler::Init(Handle<Object> exports)
+{
+ NanScope();
+
+ // Prepare constructor template
+ Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
+
+ tpl->SetClassName(NanNew<String>("Compiler"));
+ tpl->InstanceTemplate()->SetInternalFieldCount(1);
+
+ // Prototype
+ NanSetPrototypeTemplate(tpl, "dispose", NanNew<FunctionTemplate>(Dispose));
+
+ // Export the class
+ NanAssignPersistent<Function>(constructor, tpl->GetFunction());
+ exports->Set(NanNew<String>("Compiler"), tpl->GetFunction());
+}
+
+//----------------------------------------------------------------------
+
+NAN_METHOD(Compiler::New)
+{
+ NanScope();
+
+ if (args.IsConstructCall()) {
+ glslopt_target target = kGlslTargetOpenGL;
+ if (args[0]->IsInt32())
+ target = (glslopt_target)args[0]->Int32Value();
+ else if (args[0]->IsBoolean())
+ target = (glslopt_target)( (int)args[0]->BooleanValue() );
+
+ Compiler* obj = new Compiler(target);
+ obj->Wrap(args.This());
+ NanReturnValue(args.This());
+ } else {
+ Local<Function> cons = NanNew<Function>(constructor);
+ NanReturnValue(cons->NewInstance());
+ }
+}
+
+//----------------------------------------------------------------------
+
+NAN_METHOD(Compiler::Dispose)
+{
+ NanScope();
+
+ Compiler* obj = ObjectWrap::Unwrap<Compiler>(args.This());
+ obj->release();
+
+ NanReturnUndefined();
+}