lib/glesv2: fix and simplify the implementation of `GLShader::source`
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 30 Nov 2014 22:55:02 +0000 (17:55 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 8 Dec 2014 18:47:48 +0000 (13:47 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/glesv2/glesv2.nit

index 1d5904d..958e1b2 100644 (file)
@@ -85,13 +85,17 @@ extern class GLShader `{GLuint`}
                GLchar *c_code = String_to_cstring(code);
                glShaderSource(recv, 1, (const GLchar * const*)&c_code, NULL);
        `}
-       fun source: nullable String import NativeString.to_s `{
-               int size;
-               glGetShaderiv(recv, GL_SHADER_SOURCE_LENGTH, &size);
-               if (size == 0) return NULL;
+       fun source: nullable String
+       do
+               var size = query(0x8B88)
+               if size == 0 then return null
+               return source_native(size).to_s
+       end
+
+       private fun source_native(size: Int): NativeString `{
                GLchar *code = malloc(size);
                glGetShaderSource(recv, size, NULL, code);
-               return NativeString_to_s(code);
+               return code;
        `}
 
        protected fun query(pname: Int): Int `{