Skip to content
Browse files

SDL2: use SDL_UpdateTexture instead of locking/unlocking

despite documentation warnings that it is slow, it gives me 10 more FPS on iOS simulator…
  • Loading branch information...
1 parent ff58055 commit a61f3e2072cc8140decc420f2835f8f743bcb9e6 @bradallred bradallred committed
Showing with 31 additions and 25 deletions.
  1. +31 −25 gemrb/plugins/SDLVideo/SDL20Video.cpp
View
56 gemrb/plugins/SDLVideo/SDL20Video.cpp
@@ -329,31 +329,37 @@ int SDL20VideoDriver::SwapBuffers(void)
{
int ret = SDLVideoDriver::SwapBuffers();
- void *pixels;
- int pitch;
- if(SDL_LockTexture(screenTexture, NULL, &pixels, &pitch) != GEM_OK) {
- Log(ERROR, "SDL 2 driver", "Unable to lock screen texture: %s", SDL_GetError());
- return GEM_ERROR;
- }
-
- ieByte* src = (ieByte*)backBuf->pixels;
- ieByte* dest = (ieByte*)pixels;
- for( int row = 0; row < height; row++ ) {
- memcpy(dest, src, width * backBuf->format->BytesPerPixel);
- dest += pitch;
- src += backBuf->pitch;
- }
-
-/*
- if (fadeColor.a) {
- SDL_Rect dst = {
- xCorr, yCorr, Viewport.w, Viewport.h
- };
- SDL_SetRenderDrawColor(renderer, fadeColor.r, fadeColor.g, fadeColor.b, fadeColor.a);
- SDL_RenderFillRect(renderer, &dst);
- }
-*/
- SDL_UnlockTexture(screenTexture);
+ SDL_UpdateTexture(screenTexture, NULL, backBuf->pixels, backBuf->pitch);
+ /*
+ Commenting this out because I get better performance (on iOS) with SDL_UpdateTexture
+ Don't know how universal it is yet so leaving this in commented out just in case
+
+ void *pixels;
+ int pitch;
+ if(SDL_LockTexture(screenTexture, NULL, &pixels, &pitch) != GEM_OK) {
+ Log(ERROR, "SDL 2 driver", "Unable to lock screen texture: %s", SDL_GetError());
+ return GEM_ERROR;
+ }
+
+ ieByte* src = (ieByte*)backBuf->pixels;
+ ieByte* dest = (ieByte*)pixels;
+ for( int row = 0; row < height; row++ ) {
+ memcpy(dest, src, width * backBuf->format->BytesPerPixel);
+ dest += pitch;
+ src += backBuf->pitch;
+ }
+ SDL_UnlockTexture(screenTexture);
+ */
+
+ /*
+ if (fadeColor.a) {
+ SDL_Rect dst = {
+ xCorr, yCorr, Viewport.w, Viewport.h
+ };
+ SDL_SetRenderDrawColor(renderer, fadeColor.r, fadeColor.g, fadeColor.b, fadeColor.a);
+ SDL_RenderFillRect(renderer, &dst);
+ }
+ */
SDL_RenderCopy(renderer, screenTexture, NULL, NULL);
SDL_RenderPresent( renderer );
return ret;

0 comments on commit a61f3e2

Please sign in to comment.
Something went wrong with that request. Please try again.