Skip to content

Commit

Permalink
Use SDL_LockTexture() instead of SDL_UpdateTexture() (#90)
Browse files Browse the repository at this point in the history
* Use SDL_LockTexture() instead of SDL_UpdateTexture()

* Blit directly to texture

* revert to simple solution for vgatext_main()

* use native texture format

---------

Co-authored-by: Fabian Greffrath <fabian@greffrath.com>
  • Loading branch information
erysdren and fabiangreffrath authored Oct 31, 2024
1 parent 1e70c8a commit 7fc2dac
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions rott/modexlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ void SetShowCursor(int show)
void GraphicsMode ( void )
{
uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
uint32_t pixel_format;

uint32_t rmask, gmask, bmask, amask;
int bpp;

if (SDL_InitSubSystem (SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
{
Expand Down Expand Up @@ -143,16 +139,11 @@ void GraphicsMode ( void )
0, 0, 0, 0);
SDL_FillRect(sdl_surface, NULL, 0);

pixel_format = SDL_GetWindowPixelFormat(screen);
SDL_PixelFormatEnumToMasks(pixel_format, &bpp,
&rmask, &gmask, &bmask, &amask);
argbbuffer = SDL_CreateRGBSurface(0,
iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT, bpp,
rmask, gmask, bmask, amask);
argbbuffer = SDL_CreateRGBSurfaceWithFormatFrom(NULL, iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT, 0, 0, SDL_PIXELFORMAT_ARGB8888);

SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
texture = SDL_CreateTexture(renderer,
pixel_format,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT);

Expand Down Expand Up @@ -386,14 +377,18 @@ void VL_DePlaneVGA (void)

void VH_UpdateScreen (void)
{

if (StretchScreen){//bna++
StretchMemPicture ();
}else{
DrawCenterAim ();
}
SDL_LowerBlit(VL_GetVideoSurface(), &blit_rect, argbbuffer, &blit_rect);
SDL_UpdateTexture(texture, NULL, argbbuffer->pixels, argbbuffer->pitch);

if (SDL_LockTexture(texture, NULL, &argbbuffer->pixels, &argbbuffer->pitch) == 0)
{
SDL_LowerBlit(VL_GetVideoSurface(), &blit_rect, argbbuffer, &blit_rect);
SDL_UnlockTexture(texture);
}

SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
Expand All @@ -410,13 +405,18 @@ void VH_UpdateScreen (void)

void XFlipPage ( void )
{
if (StretchScreen){//bna++
if (StretchScreen){//bna++
StretchMemPicture ();
}else{
DrawCenterAim ();
}
SDL_LowerBlit(sdl_surface, &blit_rect, argbbuffer, &blit_rect);
SDL_UpdateTexture(texture, NULL, argbbuffer->pixels, argbbuffer->pitch);

if (SDL_LockTexture(texture, NULL, &argbbuffer->pixels, &argbbuffer->pitch) == 0)
{
SDL_LowerBlit(sdl_surface, &blit_rect, argbbuffer, &blit_rect);
SDL_UnlockTexture(texture);
}

SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
Expand Down

0 comments on commit 7fc2dac

Please sign in to comment.