diff src/SDL_compat.c @ 5150:ad50b3db78bd

The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Feb 2011 19:19:43 -0800
parents c8e049de174c
children be02be2ea897
line wrap: on
line diff
--- a/src/SDL_compat.c	Tue Feb 01 19:15:42 2011 -0800
+++ b/src/SDL_compat.c	Tue Feb 01 19:19:43 2011 -0800
@@ -31,7 +31,7 @@
 #include "video/SDL_yuv_sw_c.h"
 
 static SDL_Window *SDL_VideoWindow = NULL;
-static SDL_RendererInfo SDL_VideoRendererInfo;
+static SDL_Renderer *SDL_VideoRenderer = NULL;
 static SDL_Texture *SDL_VideoTexture = NULL;
 static SDL_Surface *SDL_VideoSurface = NULL;
 static SDL_Surface *SDL_ShadowSurface = NULL;
@@ -467,7 +467,8 @@
     /* Destroy the screen texture and recreate it */
     SDL_QueryTexture(SDL_VideoTexture, &format, &access, &w, &h);
     SDL_DestroyTexture(SDL_VideoTexture);
-    SDL_VideoTexture = SDL_CreateTexture(format, access, width, height);
+    SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, format,
+                                         access, width, height);
     if (!SDL_VideoTexture) {
         return -1;
     }
@@ -667,20 +668,20 @@
     }
 
     /* Create a renderer for the window */
-    if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
+    SDL_VideoRenderer = SDL_CreateRenderer(SDL_VideoWindow, -1, 0);
+    if (!SDL_VideoRenderer) {
         return NULL;
     }
-    SDL_GetRendererInfo(&SDL_VideoRendererInfo);
 
     /* Create a texture for the screen surface */
-    SDL_VideoTexture =
-        SDL_CreateTexture(desired_format, SDL_TEXTUREACCESS_STREAMING, width,
-                          height);
+    SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desired_format,
+                                         SDL_TEXTUREACCESS_STREAMING,
+                                         width, height);
 
     if (!SDL_VideoTexture) {
-        SDL_VideoTexture =
-            SDL_CreateTexture(desktop_format,
-                              SDL_TEXTUREACCESS_STREAMING, width, height);
+        SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desktop_format,
+                                             SDL_TEXTUREACCESS_STREAMING,
+                                             width, height);
     }
     if (!SDL_VideoTexture) {
         return NULL;
@@ -890,8 +891,8 @@
         rect.y = 0;
         rect.w = screen->w;
         rect.h = screen->h;
-        SDL_RenderCopy(SDL_VideoTexture, &rect, &rect);
-        SDL_RenderPresent();
+        SDL_RenderCopy(SDL_VideoRenderer, SDL_VideoTexture, &rect, &rect);
+        SDL_RenderPresent(SDL_VideoRenderer);
     }
 }
 
@@ -1584,7 +1585,8 @@
     }
 
     overlay->hwdata->texture =
-        SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h);
+        SDL_CreateTexture(SDL_VideoRenderer, texture_format,
+                          SDL_TEXTUREACCESS_STREAMING, w, h);
     if (overlay->hwdata->texture) {
         overlay->hwdata->sw = NULL;
     } else {
@@ -1600,7 +1602,7 @@
         SDL_GetCurrentDisplayMode(&current_mode);
         texture_format = current_mode.format;
         overlay->hwdata->texture =
-            SDL_CreateTexture(texture_format,
+            SDL_CreateTexture(SDL_VideoRenderer, texture_format,
                               SDL_TEXTUREACCESS_STREAMING, w, h);
     }
     if (!overlay->hwdata->texture) {
@@ -1688,10 +1690,10 @@
         SDL_SetError("Passed a NULL overlay or dstrect");
         return -1;
     }
-    if (SDL_RenderCopy(overlay->hwdata->texture, NULL, dstrect) < 0) {
+    if (SDL_RenderCopy(SDL_VideoRenderer, overlay->hwdata->texture, NULL, dstrect) < 0) {
         return -1;
     }
-    SDL_RenderPresent();
+    SDL_RenderPresent(SDL_VideoRenderer);
     return 0;
 }