1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-24 17:49:52 +01:00

only update textures if necessary

This commit is contained in:
FunkyFr3sh 2018-07-04 23:27:12 +02:00
parent 4c2272a54e
commit a40392e11a
4 changed files with 19 additions and 4 deletions

View File

@ -73,6 +73,8 @@ typedef struct IDirectDrawImpl
DEVMODE mode; DEVMODE mode;
struct { int width; int height; int x; int y; } viewport; struct { int width; int height; int x; int y; } viewport;
LONG paletteUpdated;
LONG surfaceUpdated;
} render; } render;
HWND hWnd; HWND hWnd;

View File

@ -62,6 +62,7 @@ HRESULT __stdcall ddraw_palette_SetEntries(IDirectDrawPaletteImpl *This, DWORD d
/* FIXME: only refresh the screen when the primary palette is changed */ /* FIXME: only refresh the screen when the primary palette is changed */
if(ddraw->primary && ddraw->render.run) if(ddraw->primary && ddraw->render.run)
{ {
InterlockedExchange(&ddraw->render.paletteUpdated, TRUE);
ReleaseSemaphore(ddraw->render.sem, 1, NULL); ReleaseSemaphore(ddraw->render.sem, 1, NULL);
} }

View File

@ -477,10 +477,18 @@ DWORD WINAPI render_main(void)
if (paletteConvProgram) if (paletteConvProgram)
{ {
glBindTexture(GL_TEXTURE_2D, paletteTexId); 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); 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 else
{ {

View File

@ -107,11 +107,12 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
int dst_w = lpDestRect->right - lpDestRect->left; int dst_w = lpDestRect->right - lpDestRect->left;
int dst_h = lpDestRect->bottom - lpDestRect->top; 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); 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; ((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) if(This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT) && ddraw->render.run)
{ {
InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE);
ReleaseSemaphore(ddraw->render.sem, 1, NULL); ReleaseSemaphore(ddraw->render.sem, 1, NULL);
if (ddraw->renderer != render_main) 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) if(This->caps & DDSCAPS_PRIMARYSURFACE && ddraw->render.run)
{ {
InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE);
ReleaseSemaphore(ddraw->render.sem, 1, NULL); ReleaseSemaphore(ddraw->render.sem, 1, NULL);
if (ddraw->renderer != render_main) 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) if(This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT) && ddraw->render.run)
{ {
InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE);
ReleaseSemaphore(ddraw->render.sem, 1, NULL); ReleaseSemaphore(ddraw->render.sem, 1, NULL);
} }