From 22bf62be2bd51ee5ab1e2ca679535cb53029ce35 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 14 Mar 2017 10:16:46 -0700 Subject: [PATCH] Allow static GL->GLContext conversion, clean-up --- lime/graphics/opengl/GLES2Context.hx | 5 +++ lime/graphics/opengl/GLES3Context.hx | 7 ++++ lime/graphics/opengl/WebGL2Context.hx | 7 ++++ lime/graphics/opengl/WebGLContext.hx | 7 ++++ .../src/graphics/opengl/OpenGLBindings.cpp | 35 +++++++++---------- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/lime/graphics/opengl/GLES2Context.hx b/lime/graphics/opengl/GLES2Context.hx index db7957ed2..e2358cd61 100644 --- a/lime/graphics/opengl/GLES2Context.hx +++ b/lime/graphics/opengl/GLES2Context.hx @@ -91,6 +91,11 @@ EXTENSIONS, type, version) abstract GLES2Context(GLES3Context) from GLES3Context from GLRenderContext to WebGLContext { + @:from private static function fromGL (gl:Class):GLES2Context { + + return cast GL.context; + + } } \ No newline at end of file diff --git a/lime/graphics/opengl/GLES3Context.hx b/lime/graphics/opengl/GLES3Context.hx index 698c21394..a83c7ba5a 100644 --- a/lime/graphics/opengl/GLES3Context.hx +++ b/lime/graphics/opengl/GLES3Context.hx @@ -3145,4 +3145,11 @@ abstract GLES3Context(GLRenderContext) from GLRenderContext to GLRenderContext t } + @:from private static function fromGL (gl:Class):GLES3Context { + + return cast GL.context; + + } + + } \ No newline at end of file diff --git a/lime/graphics/opengl/WebGL2Context.hx b/lime/graphics/opengl/WebGL2Context.hx index e5d0cb383..0f43ca0a0 100644 --- a/lime/graphics/opengl/WebGL2Context.hx +++ b/lime/graphics/opengl/WebGL2Context.hx @@ -3071,6 +3071,13 @@ abstract WebGL2Context(GLRenderContext) from GLRenderContext to GLRenderContext } + @:from private static function fromGL (gl:Class):WebGL2Context { + + return cast GL.context; + + } + + @:from private static function fromGLES3Context (gl:GLES3Context):WebGL2Context { return (gl:GLRenderContext); diff --git a/lime/graphics/opengl/WebGLContext.hx b/lime/graphics/opengl/WebGLContext.hx index 20d8b09f3..4e70dfd50 100644 --- a/lime/graphics/opengl/WebGLContext.hx +++ b/lime/graphics/opengl/WebGLContext.hx @@ -109,6 +109,13 @@ abstract WebGLContext(WebGL2Context) from GLRenderContext from WebGL2Context { } + @:from private static function fromGL (gl:Class):WebGLContext { + + return cast GL.context; + + } + + @:from private static function fromGLES2Context (gl:GLES2Context):WebGLContext { return cast gl; diff --git a/project/src/graphics/opengl/OpenGLBindings.cpp b/project/src/graphics/opengl/OpenGLBindings.cpp index 238e18123..35ee47c71 100644 --- a/project/src/graphics/opengl/OpenGLBindings.cpp +++ b/project/src/graphics/opengl/OpenGLBindings.cpp @@ -135,6 +135,13 @@ namespace lime { } + //void lime_gl_begin_query (int target, int query) { + // + //glBeginQuery (target, query); + // + //} + + void lime_gl_bind_attrib_location (int program, int index, HxString name) { glBindAttribLocation (program, index, name.__s); @@ -151,15 +158,13 @@ namespace lime { void lime_gl_bind_framebuffer (int target, int framebuffer) { - GLuint id = framebuffer; - - if (!id) { + if (!framebuffer) { - id = OpenGLBindings::defaultFramebuffer; + framebuffer = OpenGLBindings::defaultFramebuffer; } - glBindFramebuffer (target, id); + glBindFramebuffer (target, framebuffer); } @@ -311,7 +316,7 @@ namespace lime { int lime_gl_create_buffer () { - GLuint id; + GLuint id = 0; glGenBuffers (1, &id); return id; @@ -329,8 +334,7 @@ namespace lime { int lime_gl_create_program () { - GLuint id = glCreateProgram (); - return id; + return glCreateProgram (); } @@ -346,8 +350,7 @@ namespace lime { int lime_gl_create_shader (int type) { - GLuint id = glCreateShader (type); - return id; + return glCreateShader (type); } @@ -571,10 +574,8 @@ namespace lime { value lime_gl_get_attached_shaders (int program) { - GLuint id = program; GLsizei maxCount = 0; - - glGetProgramiv (id, GL_ATTACHED_SHADERS, &maxCount); + glGetProgramiv (program, GL_ATTACHED_SHADERS, &maxCount); if (!maxCount) { @@ -585,7 +586,7 @@ namespace lime { GLsizei count; GLuint* shaders = new GLuint[maxCount]; - glGetAttachedShaders (id, maxCount, &count, shaders); + glGetAttachedShaders (program, maxCount, &count, shaders); value data = alloc_array (maxCount); @@ -856,10 +857,8 @@ namespace lime { value lime_gl_get_shader_source (int shader) { - GLuint id = shader; - GLint len = 0; - glGetShaderiv (id, GL_SHADER_SOURCE_LENGTH, &len); + glGetShaderiv (shader, GL_SHADER_SOURCE_LENGTH, &len); if (len == 0) { @@ -868,7 +867,7 @@ namespace lime { } char *buf = new char[len + 1]; - glGetShaderSource (id, len + 1, 0, buf); + glGetShaderSource (shader, len + 1, 0, buf); value result = alloc_string (buf); delete [] buf;