From 43487eb415e8e19ef70118efa2520e43f9959570 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 22 Jul 2014 20:24:24 -0400 Subject: [PATCH] finish off GLShader_new() --- src/GLShader.cc | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) 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); }