diff --git a/src/GLShader.cc b/src/GLShader.cc index 7f58a85..8b7371c 100644 --- a/src/GLShader.cc +++ b/src/GLShader.cc @@ -80,11 +80,28 @@ static void GLShader_free(void * ptr) static VALUE GLShader_new(VALUE klass, VALUE type, VALUE source) { GLShader * glshader = new GLShader(); + GLenum shader_type; -#if 0 - /* TODO */ - glshader->id = create_shader(); -#endif + if (type == ID2SYM(rb_intern("vertex"))) + { + shader_type = GL_VERTEX_SHADER; + } + else if (type == ID2SYM(rb_intern("fragment"))) + { + shader_type = GL_FRAGMENT_SHADER; + } + else + { + type = rb_funcall(type, rb_intern("inspect"), 0); + const char * type_cstr = StringValueCStr(type); + rb_raise(rb_eRuntimeError, + "Unknown shader type: %s", + type_cstr); + } + + glshader->id = create_shader(shader_type, + RSTRING_PTR(source), + RSTRING_LEN(source)); return Data_Wrap_Struct(klass, NULL, GLShader_free, glshader); }