diff src/render/opengl/SDL_render_gl.c @ 5229:2178ffe17222

Added function SDL_RenderSetClipRect()
author Sam Lantinga <slouken@libsdl.org>
date Mon, 07 Feb 2011 20:06:26 -0800
parents daa5463466c5
children 710d00cb3a6a
line wrap: on
line diff
--- a/src/render/opengl/SDL_render_gl.c	Mon Feb 07 20:05:52 2011 -0800
+++ b/src/render/opengl/SDL_render_gl.c	Mon Feb 07 20:06:26 2011 -0800
@@ -52,6 +52,7 @@
 static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
                           const SDL_Rect * rect, void **pixels, int *pitch);
 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static void GL_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect);
 static int GL_RenderClear(SDL_Renderer * renderer);
 static int GL_RenderDrawPoints(SDL_Renderer * renderer,
                                const SDL_Point * points, int count);
@@ -199,6 +200,7 @@
     renderer->UpdateTexture = GL_UpdateTexture;
     renderer->LockTexture = GL_LockTexture;
     renderer->UnlockTexture = GL_UnlockTexture;
+    renderer->SetClipRect = GL_SetClipRect;
     renderer->RenderClear = GL_RenderClear;
     renderer->RenderDrawPoints = GL_RenderDrawPoints;
     renderer->RenderDrawLines = GL_RenderDrawLines;
@@ -511,6 +513,24 @@
 }
 
 static void
+GL_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
+{
+    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+    GL_ActivateRenderer(renderer);
+
+    if (rect) {
+        int w, h;
+
+        SDL_GetWindowSize(renderer->window, &w, &h);
+        data->glScissor(rect->x, (h-(rect->y+rect->h)), rect->w, rect->h);
+        data->glEnable(GL_SCISSOR_TEST);
+    } else {
+        data->glDisable(GL_SCISSOR_TEST);
+    }
+}
+
+static void
 GL_SetBlendMode(GL_RenderData * data, int blendMode)
 {
     if (blendMode != data->blendMode) {