diff --git a/inc/main.h b/inc/main.h index a40daa1..28a3378 100644 --- a/inc/main.h +++ b/inc/main.h @@ -73,6 +73,8 @@ typedef struct IDirectDrawImpl DEVMODE mode; struct { int width; int height; int x; int y; } viewport; + LONG paletteUpdated; + LONG surfaceUpdated; } render; HWND hWnd; diff --git a/src/palette.c b/src/palette.c index d7e6bd5..fb965b2 100644 --- a/src/palette.c +++ b/src/palette.c @@ -62,6 +62,7 @@ HRESULT __stdcall ddraw_palette_SetEntries(IDirectDrawPaletteImpl *This, DWORD d /* FIXME: only refresh the screen when the primary palette is changed */ if(ddraw->primary && ddraw->render.run) { + InterlockedExchange(&ddraw->render.paletteUpdated, TRUE); ReleaseSemaphore(ddraw->render.sem, 1, NULL); } diff --git a/src/render.c b/src/render.c index b0f1fbe..5cee066 100644 --- a/src/render.c +++ b/src/render.c @@ -477,10 +477,18 @@ DWORD WINAPI render_main(void) if (paletteConvProgram) { glBindTexture(GL_TEXTURE_2D, paletteTexId); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 1, GL_RGBA, GL_UNSIGNED_BYTE, ddraw->primary->palette->data_bgr); + if (InterlockedExchange(&ddraw->render.paletteUpdated, FALSE)) + { + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 1, GL_RGBA, GL_UNSIGNED_BYTE, + ddraw->primary->palette->data_bgr); + } glBindTexture(GL_TEXTURE_2D, surfaceTexId); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ddraw->width, ddraw->height, surfaceFormat, GL_UNSIGNED_BYTE, ddraw->primary->surface); + if (InterlockedExchange(&ddraw->render.surfaceUpdated, FALSE)) + { + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ddraw->width, ddraw->height, surfaceFormat, GL_UNSIGNED_BYTE, + ddraw->primary->surface); + } } else { diff --git a/src/surface.c b/src/surface.c index a917536..569fa17 100644 --- a/src/surface.c +++ b/src/surface.c @@ -107,11 +107,12 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR int dst_w = lpDestRect->right - lpDestRect->left; int dst_h = lpDestRect->bottom - lpDestRect->top; - for (int y = 0; y < dst_h; y++) + int y, x; + for (y = 0; y < dst_h; y++) { int ydst = This->width * (y + lpDestRect->top); - for (int x = 0; x < dst_w; x++) + for (x = 0; x < dst_w; x++) { ((unsigned char *)This->surface)[x + lpDestRect->left + ydst] = lpDDBltFx->dwFillColor; } @@ -169,6 +170,7 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR if(This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT) && ddraw->render.run) { + InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE); ReleaseSemaphore(ddraw->render.sem, 1, NULL); if (ddraw->renderer != render_main) { @@ -255,6 +257,7 @@ HRESULT __stdcall ddraw_surface_Flip(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWS if(This->caps & DDSCAPS_PRIMARYSURFACE && ddraw->render.run) { + InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE); ReleaseSemaphore(ddraw->render.sem, 1, NULL); if (ddraw->renderer != render_main) { @@ -430,6 +433,7 @@ HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRe if(This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT) && ddraw->render.run) { + InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE); ReleaseSemaphore(ddraw->render.sem, 1, NULL); }