GLProgram: define initialize in ruby, allow attaching shaders

This commit is contained in:
josh committed 2014-07-22 18:59:01 -04:00
1 parent bd188f9e83
commit 6a22ae4ad4
3 files changed
+26 -13

No files matched your search

+17 -13
View File
@@ -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)