Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the GYP build system so the GLSL Optimizer could be built using node-gyp. Created bindings to V8.
- Loading branch information
1 parent
12fcc07
commit 7a190d3
Showing
10 changed files
with
561 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,3 +72,5 @@ glslopt | |
glsl_compiler | ||
.settings/ | ||
.pydevproject | ||
|
||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
'includes': [ | ||
'target_defaults.gypi', | ||
], | ||
'targets': [ | ||
{ | ||
'target_name': 'glslOptimizer', | ||
'dependencies': [ | ||
'src/glsl_optimizer_lib.gyp:*', | ||
], | ||
'sources': [ | ||
'src/node/binding.cpp', | ||
'src/node/compiler.cpp', | ||
'src/node/compiler.h', | ||
'src/node/shader.cpp', | ||
'src/node/shader.h', | ||
], | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
{ | ||
'includes': [ | ||
'../target_defaults.gypi', | ||
], | ||
'targets': [ | ||
{ | ||
'target_name': 'glsl_optimizer_lib', | ||
'type': 'static_library', | ||
'include_dirs': [ | ||
'glsl', | ||
'mesa', | ||
'../include', | ||
'../include/c99', | ||
], | ||
'direct_dependent_settings': { | ||
'include_dirs': [ | ||
'glsl' | ||
], | ||
}, | ||
'sources': [ | ||
'glsl/glcpp/glcpp-lex.c', | ||
'glsl/glcpp/glcpp-parse.c', | ||
'glsl/glcpp/glcpp-parse.h', | ||
'glsl/glcpp/clcpp.h', | ||
'glsl/glcpp/pp.c', | ||
'glsl/ast.h', | ||
'glsl/ast_array_index.cpp', | ||
'glsl/ast_expr.cpp', | ||
'glsl/ast_function.cpp', | ||
'glsl/ast_to_hir.cpp', | ||
'glsl/ast_type.cpp', | ||
'glsl/builtin_function.cpp', | ||
'glsl/builtin_types.h', | ||
'glsl/builtin_variables.cpp', | ||
'glsl/builtin_variables.h', | ||
'glsl/glsl_lexer.cpp', | ||
'glsl/glsl_optimizer.cpp', | ||
'glsl/glsl_optimizer.h', | ||
'glsl/glsl_parser.cpp', | ||
'glsl/glsl_parser.h', | ||
'glsl/glsl_parser_extras.cpp', | ||
'glsl/glsl_parser_extras.h', | ||
'glsl/glsl_symbol_table.cpp', | ||
'glsl/glsl_symbol_table.h', | ||
'glsl/glsl_types.cpp', | ||
'glsl/glsl_types.h', | ||
'glsl/hir_field_selection.cpp', | ||
'glsl/ir.cpp', | ||
'glsl/ir.h', | ||
'glsl/ir_basic_block.cpp', | ||
'glsl/ir_basic_block.h', | ||
'glsl/ir_builder.cpp', | ||
'glsl/ir_builder.h', | ||
'glsl/ir_clone.cpp', | ||
'glsl/ir_constant_expression.cpp', | ||
'glsl/ir_expression_flattening.cpp', | ||
'glsl/ir_expression_flattening.h', | ||
'glsl/ir_function.cpp', | ||
'glsl/ir_function_can_inline.cpp', | ||
'glsl/ir_function_detect_recursion.cpp', | ||
'glsl/ir_function_inlining.h', | ||
'glsl/ir_hierarchical_visitor.cpp', | ||
'glsl/ir_hierarchical_visitor.h', | ||
'glsl/ir_hv_accept.cpp', | ||
'glsl/ir_import_prototypes.cpp', | ||
'glsl/ir_optimization.h', | ||
'glsl/ir_print_glsl_visitor.cpp', | ||
'glsl/ir_print_glsl_visitor.h', | ||
'glsl/ir_print_visitor.cpp', | ||
'glsl/ir_print_visitor.h', | ||
'glsl/ir_reader.cpp', | ||
'glsl/ir_reader.h', | ||
'glsl/ir_rvalue_visitor.cpp', | ||
'glsl/ir_rvalue_visitor.h', | ||
'glsl/ir_reader.cpp', | ||
'glsl/ir_reader.h', | ||
'glsl/ir_rvalue_visitor.cpp', | ||
'glsl/ir_rvalue_visitor.h', | ||
'glsl/ir_uniform.h', | ||
'glsl/ir_unused_structs.cpp', | ||
'glsl/ir_unused_structs.h', | ||
'glsl/ir_validate.cpp', | ||
'glsl/ir_variable_refcount.cpp', | ||
'glsl/ir_variable_refcount.h', | ||
'glsl/ir_visitor.h', | ||
'glsl/link_functions.cpp', | ||
'glsl/link_uniform_block_active_visitor.cpp', | ||
'glsl/link_uniform_block_active_visitor.h', | ||
'glsl/link_uniform_blocks.cpp', | ||
'glsl/link_uniform_initializers.cpp', | ||
'glsl/link_uniforms.cpp', | ||
'glsl/link_varyings.cpp', | ||
'glsl/link_varyings.h', | ||
'glsl/linker.cpp', | ||
'glsl/linker.h', | ||
'glsl/list.h', | ||
'glsl/loop_analysis.cpp', | ||
'glsl/loop_analysis.h', | ||
'glsl/loop_controls.cpp', | ||
'glsl/loop_unroll.cpp', | ||
'glsl/lower_clip_distance.cpp', | ||
'glsl/lower_discard.cpp', | ||
'glsl/lower_discard_flow.cpp', | ||
'glsl/lower_if_to_cond_assign.cpp', | ||
'glsl/lower_instructions.cpp', | ||
'glsl/lower_jumps.cpp', | ||
'glsl/lower_mat_op_to_vec.cpp', | ||
'glsl/lower_noise.cpp', | ||
'glsl/lower_packed_varyings.cpp', | ||
'glsl/lower_packing_builtins.cpp', | ||
'glsl/lower_variable_index_to_cond_assign.cpp', | ||
'glsl/lower_vec_index_to_cond_assign.cpp', | ||
'glsl/lower_vec_index_to_swizzle.cpp', | ||
'glsl/lower_vector.cpp', | ||
'glsl/opt_algebraic.cpp', | ||
'glsl/opt_array_splitting.cpp', | ||
'glsl/opt_constant_folding.cpp', | ||
'glsl/opt_constant_propagation.cpp', | ||
'glsl/opt_constant_variable.cpp', | ||
'glsl/opt_copy_propagation.cpp', | ||
'glsl/opt_copy_propagation_elements.cpp', | ||
'glsl/opt_dead_code.cpp', | ||
'glsl/opt_dead_code_local.cpp', | ||
'glsl/opt_dead_functions.cpp', | ||
'glsl/opt_flatten_nested_if_blocks.cpp', | ||
'glsl/opt_function_inlining.cpp', | ||
'glsl/opt_if_simplification.cpp', | ||
'glsl/opt_noop_swizzle.cpp', | ||
'glsl/opt_redundant_jumps.cpp', | ||
'glsl/opt_structure_splitting.cpp', | ||
'glsl/opt_swizzle_swizzle.cpp', | ||
'glsl/opt_tree_grafting.cpp', | ||
'glsl/program.h', | ||
'glsl/ralloc.c', | ||
'glsl/ralloc.h', | ||
'glsl/s_expression.cpp', | ||
'glsl/s_expression.h', | ||
'glsl/standalone_scaffolding.cpp', | ||
'glsl/standalone_scaffolding.h', | ||
'glsl/strtod.c', | ||
'glsl/strtod.h', | ||
'mesa/main/compiler.h', | ||
'mesa/main/config.h', | ||
'mesa/main/context.h', | ||
'mesa/main/core.h', | ||
'mesa/main/dd.h', | ||
'mesa/main/glheader.h', | ||
'mesa/main/glminimal.h', | ||
'mesa/main/hash_table.c', | ||
'mesa/main/hash_table.h', | ||
'mesa/main/imports.c', | ||
'mesa/main/imports.h', | ||
'mesa/main/macros.h', | ||
'mesa/main/mtypes.h', | ||
'mesa/main/set.c', | ||
'mesa/main/set.h', | ||
'mesa/main/simple_list.h', | ||
'mesa/program/hash_table.h', | ||
'mesa/program/prog_hash_table.c', | ||
'mesa/program/prog_instruction.h', | ||
'mesa/program/prog_parameter.h', | ||
'mesa/program/prog_statevars.h', | ||
'mesa/program/symbol_table.c', | ||
'mesa/program/symbol_table.h', | ||
], | ||
'conditions': [ | ||
['OS=="win"', { | ||
'defines': [ | ||
'_LIB', | ||
'NOMINMAX', | ||
'_CRT_SECURE_NO_WARNINGS', | ||
'_CRT_SECURE_NO_DEPRECATE', | ||
'__STDC_VERSION__=199901L', | ||
'__STDC__', | ||
'strdup=_strdup', | ||
], | ||
'msvs_disabled_warnings': [4996], | ||
}], | ||
], | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <node.h> | ||
#include "shader.h" | ||
|
||
using namespace v8; | ||
|
||
void InitAll(Handle<Object> exports) | ||
{ | ||
// Export constants | ||
exports->Set(String::NewSymbol("VERTEX_SHADER"), Int32::New(kGlslOptShaderVertex), ReadOnly); | ||
exports->Set(String::NewSymbol("FRAGMENT_SHADER"), Int32::New(kGlslOptShaderFragment), ReadOnly); | ||
|
||
// Export classes | ||
Compiler::Init(exports); | ||
Shader::Init(exports); | ||
} | ||
|
||
NODE_MODULE(glslOptimizer, InitAll); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "compiler.h" | ||
|
||
using namespace v8; | ||
using namespace node; | ||
|
||
//---------------------------------------------------------------------- | ||
|
||
Compiler::Compiler(bool essl) | ||
{ | ||
_binding = glslopt_initialize(essl); | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
|
||
Compiler::~Compiler() | ||
{ | ||
release(); | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
|
||
void Compiler::release() | ||
{ | ||
if (_binding) | ||
{ | ||
glslopt_cleanup(_binding); | ||
|
||
_binding = 0; | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
|
||
void Compiler::Init(Handle<Object> exports) | ||
{ | ||
// Prepare constructor template | ||
Local<FunctionTemplate> tpl = FunctionTemplate::New(New); | ||
tpl->SetClassName(String::NewSymbol("Compiler")); | ||
tpl->InstanceTemplate()->SetInternalFieldCount(1); | ||
|
||
// Prototype | ||
SetPrototypeMethod(tpl, "dispose", Dispose); | ||
|
||
// Export the class | ||
Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction()); | ||
exports->Set(String::NewSymbol("Compiler"), constructor); | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
|
||
Handle<Value> Compiler::New(const Arguments& args) | ||
{ | ||
HandleScope scope; | ||
|
||
bool essl = args[0]->IsUndefined() ? true : args[0]->BooleanValue(); | ||
|
||
Compiler* obj = new Compiler(essl); | ||
|
||
obj->Wrap(args.This()); | ||
|
||
return args.This(); | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
|
||
Handle<Value> Compiler::Dispose(const Arguments& args) | ||
{ | ||
HandleScope scope; | ||
|
||
Compiler* obj = ObjectWrap::Unwrap<Compiler>(args.This()); | ||
obj->release(); | ||
|
||
return scope.Close(Undefined()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef COMPILER_H | ||
#define COMPILER_H | ||
|
||
#include <node.h> | ||
#include <glsl_optimizer.h> | ||
|
||
class Compiler : public node::ObjectWrap { | ||
public: | ||
static void Init(v8::Handle<v8::Object> exports); | ||
|
||
inline glslopt_ctx* getBinding() const { return _binding; } | ||
|
||
void release(); | ||
|
||
private: | ||
Compiler(bool essl); | ||
~Compiler(); | ||
|
||
glslopt_ctx* _binding; | ||
|
||
static v8::Handle<v8::Value> New(const v8::Arguments& args); | ||
static v8::Handle<v8::Value> Dispose(const v8::Arguments& args); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.