shithub: choc

Download patch

ref: a61f85c35583c5e000698a8a6591d81e7b2787b5
parent: 169a49a564acc57a58352e3940a1e1819c0cdfdb
author: Fabian Greffrath <[email protected]>
date: Wed Feb 18 14:20:21 EST 2015

Video: Use intended function sequence to update "streaming" texture

Regarding to the SDL wiki, SDL_UpdateTexture is a fairly slow function,
intended for use with static textures that do not change often.

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -157,6 +157,8 @@
 static SDL_Surface *screenbuffer = NULL;
 static SDL_Surface *rgbabuffer = NULL;
 static SDL_Texture *texture = NULL;
+static int pitch;
+static void *pixels;
 
 // palette
 
@@ -1104,10 +1106,10 @@
     SDL_BlitSurface(screenbuffer, NULL, rgbabuffer, NULL);
 
     // Update the texture with the content of the 32-bit RGBA buffer
-    // (the last argument is the pitch, i.e. 320 pixels of 4 RGBA-bytes)
 
-    SDL_UpdateTexture(texture, NULL, rgbabuffer->pixels,
-                      SCREENWIDTH * sizeof(Uint32));
+    SDL_LockTexture(texture, NULL, &pixels, &pitch);
+    memcpy(pixels, rgbabuffer->pixels, SCREENHEIGHT*pitch);
+    SDL_UnlockTexture(texture);
 
     // Render the texture into the window