foxygit / doom Log in
commit a61f85c35583c5e000698a8a6591d81e7b2787b5
Author:     Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Wed Feb 18 19:20:21 2015 +0100
Commit:     Fabian Greffrath <fabian@greffrath.com>
CommitDate: Wed Feb 18 19:20:21 2015 +0100

    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.
---
 src/i_video.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/i_video.c b/src/i_video.c
index e66891b8..fd11eb2f 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -157,6 +157,8 @@ static char *window_title = "";
 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 @@ void I_FinishUpdate (void)
     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