GLProgram: define initialize in ruby, allow attaching shaders

This commit is contained in:
Josh Holtrop 2014-07-22 18:54:48 -04:00
parent bd188f9e83
commit 6a22ae4ad4
3 changed files with 26 additions and 13 deletions

View File

@ -0,0 +1,8 @@
class GLProgram
# @overload initialize(*shaders, options = {})
#
# @param shaders [Array<GLShader>] Shaders to attach to the program.
# @param options [Hash] Optional parameters.
def initialize(*args)
end
end

View File

@ -4,6 +4,7 @@ end
def load_lib_files def load_lib_files
require "runtime" require "runtime"
require "gl_program"
end end
def main(argv) def main(argv)

View File

@ -1,4 +1,5 @@
#include "GLProgram.h" #include "GLProgram.h"
#include "GLShader.h"
#include "ruby.h" #include "ruby.h"
#include "gl3w.h" #include "gl3w.h"
@ -21,7 +22,7 @@ static void GLProgram_free(void * ptr)
delete program; delete program;
} }
static VALUE GLProgram_new(VALUE klass) static VALUE GLProgram_new(int argc, VALUE * argv, VALUE klass)
{ {
GLProgram * glprogram = new GLProgram(); GLProgram * glprogram = new GLProgram();
@ -31,26 +32,29 @@ static VALUE GLProgram_new(VALUE klass)
rb_raise(rb_eRuntimeError, "Error allocating GL program object"); 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() void GLProgram_Init()
{ {
ruby_class = rb_define_class("GLProgram", rb_cObject); ruby_class = rb_define_class("GLProgram", rb_cObject);
rb_define_singleton_method(ruby_class, "new", (VALUE(*)(...))GLProgram_new, 0); rb_define_singleton_method(ruby_class, "new", (VALUE(*)(...))GLProgram_new, -1);
rb_define_attr(ruby_class, "id", 0, 1); rb_define_method(ruby_class, "attach_shader", (VALUE(*)(...))GLProgram_attach_shader, 1);
} }
#if 0 #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) GLProgram & GLProgram::bind_attribute(const char * attribute, GLuint index)
{ {
if (m_id > 0u) if (m_id > 0u)