Restore the rendering backend callbacks
Now the SDLSurface backend survives window resizes (also triggered by alt-tabbing while in fullscreen), and the SDLTexture backend properly regenerates its textures after a fullscreen alt-tab in DirectX mode.
This commit is contained in:
parent
0dc9bb6b1b
commit
4e239c3175
7 changed files with 62 additions and 28 deletions
|
@ -20,6 +20,7 @@ void Backend_Deinit(void);
|
||||||
void Backend_DrawScreen(void);
|
void Backend_DrawScreen(void);
|
||||||
Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height);
|
Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height);
|
||||||
void Backend_FreeSurface(Backend_Surface *surface);
|
void Backend_FreeSurface(Backend_Surface *surface);
|
||||||
|
BOOL Backend_IsSurfaceLost(Backend_Surface *surface);
|
||||||
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch);
|
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch);
|
||||||
void Backend_UnlockSurface(Backend_Surface *surface);
|
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);
|
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);
|
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_UnloadGlyph(Backend_Glyph *glyph);
|
||||||
void Backend_DrawGlyph(Backend_Surface *surface, Backend_Glyph *glyph, long x, long y, const unsigned char *colours);
|
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);
|
void Backend_HandleWindowResize(void);
|
||||||
|
|
|
@ -463,6 +463,11 @@ void Backend_FreeSurface(Backend_Surface *surface)
|
||||||
free(surface);
|
free(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL Backend_IsSurfaceLost(Backend_Surface *surface)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch)
|
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch)
|
||||||
{
|
{
|
||||||
if (surface == NULL)
|
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;
|
vertex_buffer_slot->vertices[1][2].vertex_coordinate.y = vertex_bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend_HandleDeviceLoss(void)
|
void Backend_HandleRenderTargetLoss(void)
|
||||||
{
|
{
|
||||||
// No problem for us
|
// No problem for us
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,11 @@ void Backend_FreeSurface(Backend_Surface *surface)
|
||||||
free(surface);
|
free(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL Backend_IsSurfaceLost(Backend_Surface *surface)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch)
|
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch)
|
||||||
{
|
{
|
||||||
if (surface == NULL)
|
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);
|
SDL_BlitSurface(glyph->sdlsurface, NULL, surface->sdlsurface, &rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend_HandleDeviceLoss(void)
|
void Backend_HandleRenderTargetLoss(void)
|
||||||
{
|
{
|
||||||
// No problem for us
|
// No problem for us
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,10 @@ typedef struct Backend_Surface
|
||||||
unsigned char *pixels;
|
unsigned char *pixels;
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
|
BOOL lost;
|
||||||
|
|
||||||
|
struct Backend_Surface *next;
|
||||||
|
struct Backend_Surface *prev;
|
||||||
} Backend_Surface;
|
} Backend_Surface;
|
||||||
|
|
||||||
typedef struct Backend_Glyph
|
typedef struct Backend_Glyph
|
||||||
|
@ -31,6 +35,8 @@ static SDL_Renderer *renderer;
|
||||||
|
|
||||||
static Backend_Surface framebuffer;
|
static Backend_Surface framebuffer;
|
||||||
|
|
||||||
|
static Backend_Surface *surface_list_head;
|
||||||
|
|
||||||
static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect)
|
static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect)
|
||||||
{
|
{
|
||||||
sdl_rect->x = (int)rect->left;
|
sdl_rect->x = (int)rect->left;
|
||||||
|
@ -103,6 +109,12 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height)
|
||||||
|
|
||||||
surface->width = width;
|
surface->width = width;
|
||||||
surface->height = height;
|
surface->height = height;
|
||||||
|
surface->lost = FALSE;
|
||||||
|
|
||||||
|
// Add to linked-list
|
||||||
|
surface->prev = NULL;
|
||||||
|
surface->next = surface_list_head;
|
||||||
|
surface_list_head = surface;
|
||||||
|
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
@ -112,10 +124,21 @@ void Backend_FreeSurface(Backend_Surface *surface)
|
||||||
if (surface == NULL)
|
if (surface == NULL)
|
||||||
return;
|
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);
|
SDL_DestroyTexture(surface->texture);
|
||||||
free(surface);
|
free(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL Backend_IsSurfaceLost(Backend_Surface *surface)
|
||||||
|
{
|
||||||
|
return surface->lost;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch)
|
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch)
|
||||||
{
|
{
|
||||||
if (surface == NULL)
|
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);
|
SDL_RenderCopy(renderer, glyph->texture, NULL, &destination_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend_HandleDeviceLoss(void)
|
void Backend_HandleRenderTargetLoss(void)
|
||||||
{
|
{
|
||||||
// TODO - RestoreSurfaces
|
for (Backend_Surface *surface = surface_list_head; surface != NULL; surface = surface->next)
|
||||||
// All of our target-textures have been lost, so regenerate them
|
surface->lost = TRUE;
|
||||||
// RestoreSurfaces();
|
|
||||||
// RestoreStripper();
|
|
||||||
// RestoreMapName();
|
|
||||||
// RestoreTextScript();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend_HandleWindowResize(void)
|
void Backend_HandleWindowResize(void)
|
||||||
|
|
|
@ -100,6 +100,11 @@ void Backend_FreeSurface(Backend_Surface *surface)
|
||||||
free(surface);
|
free(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL Backend_IsSurfaceLost(Backend_Surface *surface)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch)
|
unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch)
|
||||||
{
|
{
|
||||||
if (surface == NULL)
|
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
|
// No problem for us
|
||||||
}
|
}
|
||||||
|
|
22
src/Draw.cpp
22
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);
|
Backend_ColourFill(surf[surf_no], &dst_rect, red, green, blue);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
BOOL DummiedOutLogFunction(int unknown)
|
BOOL DummiedOutLogFunction(int unknown)
|
||||||
{
|
{
|
||||||
char unknown2[0x100];
|
char unknown2[0x100];
|
||||||
|
@ -545,23 +545,12 @@ int RestoreSurfaces(void) // Guessed function name - this doesn't exist in the L
|
||||||
RECT rect;
|
RECT rect;
|
||||||
int surfaces_regenerated = 0;
|
int surfaces_regenerated = 0;
|
||||||
|
|
||||||
if (frontbuffer == NULL)
|
if (framebuffer == NULL)
|
||||||
return surfaces_regenerated;
|
return surfaces_regenerated;
|
||||||
|
|
||||||
if (backbuffer == NULL)
|
if (Backend_IsSurfaceLost(framebuffer))
|
||||||
return surfaces_regenerated;
|
|
||||||
|
|
||||||
if (frontbuffer->IsLost() == DDERR_SURFACELOST)
|
|
||||||
{
|
{
|
||||||
++surfaces_regenerated;
|
++surfaces_regenerated;
|
||||||
frontbuffer->Restore();
|
|
||||||
DummiedOutLogFunction(0x66);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backbuffer->IsLost() == DDERR_SURFACELOST)
|
|
||||||
{
|
|
||||||
++surfaces_regenerated;
|
|
||||||
backbuffer->Restore();
|
|
||||||
DummiedOutLogFunction(0x62);
|
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] != NULL)
|
||||||
{
|
{
|
||||||
if (surf[s]->IsLost() == DDERR_SURFACELOST)
|
if (Backend_IsSurfaceLost(surf[s]))
|
||||||
{
|
{
|
||||||
++surfaces_regenerated;
|
++surfaces_regenerated;
|
||||||
surf[s]->Restore();
|
|
||||||
DummiedOutLogFunction(0x30 + s);
|
DummiedOutLogFunction(0x30 + s);
|
||||||
|
|
||||||
if (!surface_metadata[s].bSystem)
|
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;
|
return surfaces_regenerated;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
// TODO - Inaccurate stack frame
|
// TODO - Inaccurate stack frame
|
||||||
void InitTextObject(const char *name)
|
void InitTextObject(const char *name)
|
||||||
{
|
{
|
||||||
|
|
11
src/Main.cpp
11
src/Main.cpp
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "WindowsWrapper.h"
|
#include "WindowsWrapper.h"
|
||||||
|
|
||||||
|
#include "Backends/Rendering.h"
|
||||||
#include "CommonDefines.h"
|
#include "CommonDefines.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Draw.h"
|
#include "Draw.h"
|
||||||
|
@ -558,6 +559,11 @@ BOOL SystemTask(void)
|
||||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||||
ActiveWindow();
|
ActiveWindow();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||||
|
Backend_HandleWindowResize();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -565,6 +571,11 @@ BOOL SystemTask(void)
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
StopOrganyaMusic();
|
StopOrganyaMusic();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
case SDL_RENDER_TARGETS_RESET:
|
||||||
|
Backend_HandleRenderTargetLoss();
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue