Allow static GL->GLContext conversion, clean-up

This commit is contained in:
Joshua Granick
2017-03-14 10:16:46 -07:00
parent 0d691a3ef2
commit 22bf62be2b
5 changed files with 43 additions and 18 deletions

View File

@@ -91,6 +91,11 @@ EXTENSIONS, type, version)
abstract GLES2Context(GLES3Context) from GLES3Context from GLRenderContext to WebGLContext { abstract GLES2Context(GLES3Context) from GLES3Context from GLRenderContext to WebGLContext {
@:from private static function fromGL (gl:Class<GL>):GLES2Context {
return cast GL.context;
}
} }

View File

@@ -3145,4 +3145,11 @@ abstract GLES3Context(GLRenderContext) from GLRenderContext to GLRenderContext t
} }
@:from private static function fromGL (gl:Class<GL>):GLES3Context {
return cast GL.context;
}
} }

View File

@@ -3071,6 +3071,13 @@ abstract WebGL2Context(GLRenderContext) from GLRenderContext to GLRenderContext
} }
@:from private static function fromGL (gl:Class<GL>):WebGL2Context {
return cast GL.context;
}
@:from private static function fromGLES3Context (gl:GLES3Context):WebGL2Context { @:from private static function fromGLES3Context (gl:GLES3Context):WebGL2Context {
return (gl:GLRenderContext); return (gl:GLRenderContext);

View File

@@ -109,6 +109,13 @@ abstract WebGLContext(WebGL2Context) from GLRenderContext from WebGL2Context {
} }
@:from private static function fromGL (gl:Class<GL>):WebGLContext {
return cast GL.context;
}
@:from private static function fromGLES2Context (gl:GLES2Context):WebGLContext { @:from private static function fromGLES2Context (gl:GLES2Context):WebGLContext {
return cast gl; return cast gl;

View File

@@ -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) { void lime_gl_bind_attrib_location (int program, int index, HxString name) {
glBindAttribLocation (program, index, name.__s); glBindAttribLocation (program, index, name.__s);
@@ -151,15 +158,13 @@ namespace lime {
void lime_gl_bind_framebuffer (int target, int framebuffer) { void lime_gl_bind_framebuffer (int target, int framebuffer) {
GLuint id = framebuffer; if (!framebuffer) {
if (!id) {
id = OpenGLBindings::defaultFramebuffer; framebuffer = OpenGLBindings::defaultFramebuffer;
} }
glBindFramebuffer (target, id); glBindFramebuffer (target, framebuffer);
} }
@@ -311,7 +316,7 @@ namespace lime {
int lime_gl_create_buffer () { int lime_gl_create_buffer () {
GLuint id; GLuint id = 0;
glGenBuffers (1, &id); glGenBuffers (1, &id);
return id; return id;
@@ -329,8 +334,7 @@ namespace lime {
int lime_gl_create_program () { int lime_gl_create_program () {
GLuint id = glCreateProgram (); return glCreateProgram ();
return id;
} }
@@ -346,8 +350,7 @@ namespace lime {
int lime_gl_create_shader (int type) { int lime_gl_create_shader (int type) {
GLuint id = glCreateShader (type); return glCreateShader (type);
return id;
} }
@@ -571,10 +574,8 @@ namespace lime {
value lime_gl_get_attached_shaders (int program) { value lime_gl_get_attached_shaders (int program) {
GLuint id = program;
GLsizei maxCount = 0; GLsizei maxCount = 0;
glGetProgramiv (program, GL_ATTACHED_SHADERS, &maxCount);
glGetProgramiv (id, GL_ATTACHED_SHADERS, &maxCount);
if (!maxCount) { if (!maxCount) {
@@ -585,7 +586,7 @@ namespace lime {
GLsizei count; GLsizei count;
GLuint* shaders = new GLuint[maxCount]; GLuint* shaders = new GLuint[maxCount];
glGetAttachedShaders (id, maxCount, &count, shaders); glGetAttachedShaders (program, maxCount, &count, shaders);
value data = alloc_array (maxCount); value data = alloc_array (maxCount);
@@ -856,10 +857,8 @@ namespace lime {
value lime_gl_get_shader_source (int shader) { value lime_gl_get_shader_source (int shader) {
GLuint id = shader;
GLint len = 0; GLint len = 0;
glGetShaderiv (id, GL_SHADER_SOURCE_LENGTH, &len); glGetShaderiv (shader, GL_SHADER_SOURCE_LENGTH, &len);
if (len == 0) { if (len == 0) {
@@ -868,7 +867,7 @@ namespace lime {
} }
char *buf = new char[len + 1]; char *buf = new char[len + 1];
glGetShaderSource (id, len + 1, 0, buf); glGetShaderSource (shader, len + 1, 0, buf);
value result = alloc_string (buf); value result = alloc_string (buf);
delete [] buf; delete [] buf;