Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
authorGabriel Jacobo <gabomdq@gmail.com>
Fri, 10 May 2013 10:31:01 -0300
changeset 7160 bfb5f8f4f006
parent 7159 ffc613268eb1
child 7161 1619292eec30
Fixes OpenGL* Clip Rect functions (by Emmanuel Gil Peyrot)
src/render/opengl/SDL_render_gl.c
src/render/opengles/SDL_glesfuncs.h
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_gles2funcs.h
src/render/opengles2/SDL_render_gles2.c
--- a/src/render/opengl/SDL_render_gl.c	Thu May 09 16:30:44 2013 -0700
+++ b/src/render/opengl/SDL_render_gl.c	Fri May 10 10:31:01 2013 -0300
@@ -794,7 +794,7 @@
 
     if (!SDL_RectEmpty(rect)) {
         data->glEnable(GL_SCISSOR_TEST);
-        data->glScissor(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
+        data->glScissor(rect->x, rect->h - rect->y, rect->x, rect->y);
     } else {
         data->glDisable(GL_SCISSOR_TEST);
     }
--- a/src/render/opengles/SDL_glesfuncs.h	Thu May 09 16:30:44 2013 -0700
+++ b/src/render/opengles/SDL_glesfuncs.h	Fri May 10 10:31:01 2013 -0300
@@ -20,6 +20,7 @@
 SDL_PROC(void, glOrthof, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
 SDL_PROC(void, glPixelStorei, (GLenum, GLint))
 SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
+SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
 SDL_PROC(void, glTexCoordPointer, (GLint, GLenum, GLsizei, const GLvoid *))
 SDL_PROC(void, glTexEnvf, (GLenum, GLenum, GLfloat))
 SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *))
--- a/src/render/opengles/SDL_render_gles.c	Thu May 09 16:30:44 2013 -0700
+++ b/src/render/opengles/SDL_render_gles.c	Fri May 10 10:31:01 2013 -0300
@@ -635,13 +635,19 @@
 static int
 GLES_UpdateClipRect(SDL_Renderer * renderer)
 {
+    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
     const SDL_Rect *rect = &renderer->clip_rect;
 
+    if (SDL_CurrentContext != data->context) {
+        /* We'll update the clip rect after we rebind the context */
+        return 0;
+    }
+
     if (!SDL_RectEmpty(rect)) {
-        glEnable(GL_SCISSOR_TEST);
-        glScissor(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
+        data->glEnable(GL_SCISSOR_TEST);
+        data->glScissor(rect->x, rect->h - rect->y, rect->w, rect->h);
     } else {
-        glDisable(GL_SCISSOR_TEST);
+        data->glDisable(GL_SCISSOR_TEST);
     }
     return 0;
 }
--- a/src/render/opengles2/SDL_gles2funcs.h	Thu May 09 16:30:44 2013 -0700
+++ b/src/render/opengles2/SDL_gles2funcs.h	Fri May 10 10:31:01 2013 -0300
@@ -30,6 +30,7 @@
 SDL_PROC(void, glLinkProgram, (GLuint))
 SDL_PROC(void, glPixelStorei, (GLenum, GLint))
 SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
+SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
 SDL_PROC(void, glShaderBinary, (GLsizei, const GLuint *, GLenum, const void *, GLsizei))
 SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const char **, const GLint *))
 SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *))
--- a/src/render/opengles2/SDL_render_gles2.c	Thu May 09 16:30:44 2013 -0700
+++ b/src/render/opengles2/SDL_render_gles2.c	Fri May 10 10:31:01 2013 -0300
@@ -278,13 +278,19 @@
 static int
 GLES2_UpdateClipRect(SDL_Renderer * renderer)
 {
+    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
     const SDL_Rect *rect = &renderer->clip_rect;
 
+    if (SDL_CurrentContext != rdata->context) {
+        /* We'll update the clip rect after we rebind the context */
+        return 0;
+    }
+
     if (!SDL_RectEmpty(rect)) {
-        glEnable(GL_SCISSOR_TEST);
-        glScissor(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
+        rdata->glEnable(GL_SCISSOR_TEST);
+        rdata->glScissor(rect->x, rect->h - rect->y, rect->w, rect->h);
     } else {
-        glDisable(GL_SCISSOR_TEST);
+        rdata->glDisable(GL_SCISSOR_TEST);
     }
     return 0;
 }