diff --git a/runtime/lib/gl_program.rb b/runtime/lib/gl_program.rb new file mode 100644 index 0000000..04cf827 --- /dev/null +++ b/runtime/lib/gl_program.rb @@ -0,0 +1,8 @@ +class GLProgram + # @overload initialize(*shaders, options = {}) + # + # @param shaders [Array] Shaders to attach to the program. + # @param options [Hash] Optional parameters. + def initialize(*args) + end +end diff --git a/runtime/main.rb b/runtime/main.rb index ea1dd16..06f8a84 100644 --- a/runtime/main.rb +++ b/runtime/main.rb @@ -4,6 +4,7 @@ end def load_lib_files require "runtime" + require "gl_program" end def main(argv) diff --git a/src/GLProgram.cc b/src/GLProgram.cc index 6a0c8e9..94c7dc8 100644 --- a/src/GLProgram.cc +++ b/src/GLProgram.cc @@ -1,4 +1,5 @@ #include "GLProgram.h" +#include "GLShader.h" #include "ruby.h" #include "gl3w.h" @@ -21,7 +22,7 @@ static void GLProgram_free(void * ptr) delete program; } -static VALUE GLProgram_new(VALUE klass) +static VALUE GLProgram_new(int argc, VALUE * argv, VALUE klass) { GLProgram * glprogram = new GLProgram(); @@ -31,26 +32,29 @@ static VALUE GLProgram_new(VALUE klass) rb_raise(rb_eRuntimeError, "Error allocating GL program object"); } - return Data_Wrap_Struct(klass, NULL, GLProgram_free, glprogram); + VALUE rv = Data_Wrap_Struct(klass, NULL, GLProgram_free, glprogram); + rb_obj_call_init(rv, argc, argv); + + return rv; +} + +static VALUE GLProgram_attach_shader(VALUE self, VALUE gl_shader) +{ + GLProgram * glprogram; + Data_Get_Struct(self, GLProgram, glprogram); + glAttachShader(glprogram->id, GLShader_id(gl_shader)); + + return Qnil; } void GLProgram_Init() { ruby_class = rb_define_class("GLProgram", rb_cObject); - rb_define_singleton_method(ruby_class, "new", (VALUE(*)(...))GLProgram_new, 0); - rb_define_attr(ruby_class, "id", 0, 1); + rb_define_singleton_method(ruby_class, "new", (VALUE(*)(...))GLProgram_new, -1); + rb_define_method(ruby_class, "attach_shader", (VALUE(*)(...))GLProgram_attach_shader, 1); } #if 0 -GLProgram & GLProgram::attach_shader(GLShaderRef shader) -{ - if (m_id > 0u) - { - glAttachShader(m_id, shader->get_id()); - } - return *this; -} - GLProgram & GLProgram::bind_attribute(const char * attribute, GLuint index) { if (m_id > 0u)