diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index 2764ce7e..ddd24448 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -20,6 +20,7 @@ void Backend_Deinit(void); void Backend_DrawScreen(void); Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height); void Backend_FreeSurface(Backend_Surface *surface); +BOOL Backend_IsSurfaceLost(Backend_Surface *surface); unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch); void Backend_UnlockSurface(Backend_Surface *surface); void Backend_Blit(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y, BOOL colour_key); @@ -28,5 +29,5 @@ BOOL Backend_SupportsSubpixelGlyphs(void); Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width, unsigned int height, int pitch, FontPixelMode pixel_mode); void Backend_UnloadGlyph(Backend_Glyph *glyph); void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours); -void Backend_HandleDeviceLoss(void); +void Backend_HandleRenderTargetLoss(void); void Backend_HandleWindowResize(void); diff --git a/src/Backends/Rendering/OpenGL3.cpp b/src/Backends/Rendering/OpenGL3.cpp index 7f2220c3..acd01592 100644 --- a/src/Backends/Rendering/OpenGL3.cpp +++ b/src/Backends/Rendering/OpenGL3.cpp @@ -463,6 +463,11 @@ void Backend_FreeSurface(Backend_Surface *surface) free(surface); } +BOOL Backend_IsSurfaceLost(Backend_Surface *surface) +{ + return FALSE; +} + unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch) { if (surface == NULL) @@ -786,7 +791,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l vertex_buffer_slot->vertices[1][2].vertex_coordinate.y = vertex_bottom; } -void Backend_HandleDeviceLoss(void) +void Backend_HandleRenderTargetLoss(void) { // No problem for us } diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index 1e976c3a..48b32660 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -93,6 +93,11 @@ void Backend_FreeSurface(Backend_Surface *surface) free(surface); } +BOOL Backend_IsSurfaceLost(Backend_Surface *surface) +{ + return FALSE; +} + unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch) { if (surface == NULL) @@ -226,7 +231,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l SDL_BlitSurface(glyph->sdlsurface, NULL, surface->sdlsurface, &rect); } -void Backend_HandleDeviceLoss(void) +void Backend_HandleRenderTargetLoss(void) { // No problem for us } diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index a9f3307f..4aba2a17 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -18,6 +18,10 @@ typedef struct Backend_Surface unsigned char *pixels; unsigned int width; unsigned int height; + BOOL lost; + + struct Backend_Surface *next; + struct Backend_Surface *prev; } Backend_Surface; typedef struct Backend_Glyph @@ -31,6 +35,8 @@ static SDL_Renderer *renderer; static Backend_Surface framebuffer; +static Backend_Surface *surface_list_head; + static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) { sdl_rect->x = (int)rect->left; @@ -103,6 +109,12 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) surface->width = width; surface->height = height; + surface->lost = FALSE; + + // Add to linked-list + surface->prev = NULL; + surface->next = surface_list_head; + surface_list_head = surface; return surface; } @@ -112,10 +124,21 @@ void Backend_FreeSurface(Backend_Surface *surface) if (surface == NULL) return; + // Remove from linked list + if (surface->next != NULL) + surface->next->prev = surface->prev; + if (surface->prev != NULL) + surface->prev->next = surface->next; + SDL_DestroyTexture(surface->texture); free(surface); } +BOOL Backend_IsSurfaceLost(Backend_Surface *surface) +{ + return surface->lost; +} + unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch) { if (surface == NULL) @@ -305,14 +328,10 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l SDL_RenderCopy(renderer, glyph->texture, NULL, &destination_rect); } -void Backend_HandleDeviceLoss(void) +void Backend_HandleRenderTargetLoss(void) { - // TODO - RestoreSurfaces - // All of our target-textures have been lost, so regenerate them -// RestoreSurfaces(); -// RestoreStripper(); -// RestoreMapName(); -// RestoreTextScript(); + for (Backend_Surface *surface = surface_list_head; surface != NULL; surface = surface->next) + surface->lost = TRUE; } void Backend_HandleWindowResize(void) diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index 937b18f7..918574ba 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -100,6 +100,11 @@ void Backend_FreeSurface(Backend_Surface *surface) free(surface); } +BOOL Backend_IsSurfaceLost(Backend_Surface *surface) +{ + return FALSE; +} + unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch) { if (surface == NULL) @@ -398,7 +403,7 @@ void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, l } } -void Backend_HandleDeviceLoss(void) +void Backend_HandleRenderTargetLoss(void) { // No problem for us } diff --git a/src/Draw.cpp b/src/Draw.cpp index 483dff2f..d8c9371b 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -523,7 +523,7 @@ void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no) Backend_ColourFill(surf[surf_no], &dst_rect, red, green, blue); } -/* + BOOL DummiedOutLogFunction(int unknown) { char unknown2[0x100]; @@ -545,23 +545,12 @@ int RestoreSurfaces(void) // Guessed function name - this doesn't exist in the L RECT rect; int surfaces_regenerated = 0; - if (frontbuffer == NULL) + if (framebuffer == NULL) return surfaces_regenerated; - if (backbuffer == NULL) - return surfaces_regenerated; - - if (frontbuffer->IsLost() == DDERR_SURFACELOST) + if (Backend_IsSurfaceLost(framebuffer)) { ++surfaces_regenerated; - frontbuffer->Restore(); - DummiedOutLogFunction(0x66); - } - - if (backbuffer->IsLost() == DDERR_SURFACELOST) - { - ++surfaces_regenerated; - backbuffer->Restore(); DummiedOutLogFunction(0x62); } @@ -569,10 +558,9 @@ int RestoreSurfaces(void) // Guessed function name - this doesn't exist in the L { if (surf[s] != NULL) { - if (surf[s]->IsLost() == DDERR_SURFACELOST) + if (Backend_IsSurfaceLost(surf[s])) { ++surfaces_regenerated; - surf[s]->Restore(); DummiedOutLogFunction(0x30 + s); if (!surface_metadata[s].bSystem) @@ -602,7 +590,7 @@ int RestoreSurfaces(void) // Guessed function name - this doesn't exist in the L return surfaces_regenerated; } -*/ + // TODO - Inaccurate stack frame void InitTextObject(const char *name) { diff --git a/src/Main.cpp b/src/Main.cpp index 705e238a..873c0bc6 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -8,6 +8,7 @@ #include "WindowsWrapper.h" +#include "Backends/Rendering.h" #include "CommonDefines.h" #include "Config.h" #include "Draw.h" @@ -558,6 +559,11 @@ BOOL SystemTask(void) case SDL_WINDOWEVENT_FOCUS_GAINED: ActiveWindow(); break; + + case SDL_WINDOWEVENT_RESIZED: + case SDL_WINDOWEVENT_SIZE_CHANGED: + Backend_HandleWindowResize(); + break; } break; @@ -565,6 +571,11 @@ BOOL SystemTask(void) case SDL_QUIT: StopOrganyaMusic(); return FALSE; + + case SDL_RENDER_TARGETS_RESET: + Backend_HandleRenderTargetLoss(); + break; + } }