diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index a746fd12..8a6ff43c 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -11,16 +11,16 @@ typedef struct Backend_Surface { - SDL_Surface *sdl_surface; + SDL_Surface *sdlsurface; } Backend_Surface; typedef struct Backend_Glyph { - SDL_Surface *sdl_surface; + SDL_Surface *sdlsurface; } Backend_Glyph; static SDL_Window *window; -static SDL_Surface *window_surface; +static SDL_Surface *window_sdlsurface; static Backend_Surface framebuffer; @@ -43,30 +43,28 @@ SDL_Window* Backend_CreateWindow(const char *title, int width, int height) return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); } -BOOL Backend_Init(SDL_Window *p_window) +Backend_Surface* Backend_Init(SDL_Window *p_window) { window = p_window; - window_surface = SDL_GetWindowSurface(window); + window_sdlsurface = SDL_GetWindowSurface(window); - framebuffer.sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, window_surface->w, window_surface->h, 0, SDL_PIXELFORMAT_RGB24); + framebuffer.sdlsurface = SDL_CreateRGBSurfaceWithFormat(0, window_sdlsurface->w, window_sdlsurface->h, 0, SDL_PIXELFORMAT_RGB24); - if (framebuffer.sdl_surface == NULL) - return FALSE; + if (framebuffer.sdlsurface == NULL) + return NULL; - return TRUE; + return &framebuffer; } -void Backend_Deinit(Backend_Surface *framebuffer_surface) +void Backend_Deinit(void) { - (void)framebuffer_surface; - - SDL_FreeSurface(framebuffer.sdl_surface); + SDL_FreeSurface(framebuffer.sdlsurface); } void Backend_DrawScreen(void) { - SDL_BlitSurface(framebuffer.sdl_surface, NULL, window_surface, NULL); + SDL_BlitSurface(framebuffer.sdlsurface, NULL, window_sdlsurface, NULL); SDL_UpdateWindowSurface(window); } @@ -77,9 +75,9 @@ Backend_Surface* Backend_CreateSurface(unsigned int width, unsigned int height) if (surface == NULL) return NULL; - surface->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_RGB24); + surface->sdlsurface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_RGB24); - if (surface->sdl_surface == NULL) + if (surface->sdlsurface == NULL) { free(surface); return NULL; @@ -93,7 +91,7 @@ void Backend_FreeSurface(Backend_Surface *surface) if (surface == NULL) return; - SDL_FreeSurface(surface->sdl_surface); + SDL_FreeSurface(surface->sdlsurface); free(surface); } @@ -102,8 +100,8 @@ unsigned char* Backend_LockSurface(Backend_Surface *surface, unsigned int *pitch if (surface == NULL) return NULL; - *pitch = surface->sdl_surface->pitch; - return (unsigned char*)surface->sdl_surface->pixels; + *pitch = surface->sdlsurface->pitch; + return (unsigned char*)surface->sdlsurface->pixels; } void Backend_UnlockSurface(Backend_Surface *surface) @@ -111,7 +109,7 @@ void Backend_UnlockSurface(Backend_Surface *surface) (void)surface; } -static void BlitCommon(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) { if (source_surface == NULL || destination_surface == NULL) return; @@ -125,22 +123,12 @@ static void BlitCommon(Backend_Surface *source_surface, const RECT *rect, Backen destination_rect.w = source_rect.w; destination_rect.h = source_rect.h; - SDL_SetColorKey(source_surface->sdl_surface, colour_key ? SDL_TRUE : SDL_FALSE, SDL_MapRGB(source_surface->sdl_surface->format, 0, 0, 0)); // Assumes the colour key will always be #000000 (black) + SDL_SetColorKey(source_surface->sdlsurface, colour_key ? SDL_TRUE : SDL_FALSE, SDL_MapRGB(source_surface->sdlsurface->format, 0, 0, 0)); // Assumes the colour key will always be #000000 (black) - SDL_BlitSurface(source_surface->sdl_surface, &source_rect, destination_surface->sdl_surface, &destination_rect); + SDL_BlitSurface(source_surface->sdlsurface, &source_rect, destination_surface->sdlsurface, &destination_rect); } -void Backend_BlitToSurface(Backend_Surface *source_surface, const RECT *rect, Backend_Surface *destination_surface, long x, long y) -{ - BlitCommon(source_surface, rect, destination_surface, x, y, TRUE); -} - -void Backend_BlitToScreen(Backend_Surface *source_surface, const RECT *rect, long x, long y, BOOL colour_key) -{ - BlitCommon(source_surface, rect, &framebuffer, x, y, colour_key); -} - -void Backend_ColourFillToSurface(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) +void Backend_ColourFill(Backend_Surface *surface, const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) { if (surface == NULL) return; @@ -148,17 +136,7 @@ void Backend_ColourFillToSurface(Backend_Surface *surface, const RECT *rect, uns SDL_Rect destination_rect; RectToSDLRect(rect, &destination_rect); - SDL_FillRect(surface->sdl_surface, &destination_rect, SDL_MapRGB(surface->sdl_surface->format, red, green, blue)); -} - -void Backend_ColourFillToScreen(const RECT *rect, unsigned char red, unsigned char green, unsigned char blue) -{ - Backend_ColourFillToSurface(&framebuffer, rect, red, green, blue); -} - -void Backend_ScreenToSurface(Backend_Surface *surface, const RECT *rect) -{ - BlitCommon(&framebuffer, rect, surface, rect->left, rect->top, FALSE); + SDL_FillRect(surface->sdlsurface, &destination_rect, SDL_MapRGB(surface->sdlsurface->format, red, green, blue)); } BOOL Backend_SupportsSubpixelGlyph(void) @@ -173,9 +151,9 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width if (glyph == NULL) return NULL; - glyph->sdl_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_RGBA32); + glyph->sdlsurface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, SDL_PIXELFORMAT_RGBA32); - if (glyph->sdl_surface == NULL) + if (glyph->sdlsurface == NULL) { free(glyph); return NULL; @@ -189,7 +167,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width for (unsigned int y = 0; y < height; ++y) { const unsigned char *source_pointer = pixels + y * pitch; - unsigned char *destination_pointer = (unsigned char*)glyph->sdl_surface->pixels + y * glyph->sdl_surface->pitch; + unsigned char *destination_pointer = (unsigned char*)glyph->sdlsurface->pixels + y * glyph->sdlsurface->pitch; for (unsigned int x = 0; x < width; ++x) { @@ -206,7 +184,7 @@ Backend_Glyph* Backend_LoadGlyph(const unsigned char *pixels, unsigned int width for (unsigned int y = 0; y < height; ++y) { const unsigned char *source_pointer = pixels + y * pitch; - unsigned char *destination_pointer = (unsigned char*)glyph->sdl_surface->pixels + y * glyph->sdl_surface->pitch; + unsigned char *destination_pointer = (unsigned char*)glyph->sdlsurface->pixels + y * glyph->sdlsurface->pitch; for (unsigned int x = 0; x < width; ++x) { @@ -228,11 +206,11 @@ void Backend_UnloadGlyph(Backend_Glyph *glyph) if (glyph == NULL) return; - SDL_FreeSurface(glyph->sdl_surface); + SDL_FreeSurface(glyph->sdlsurface); free(glyph); } -void Backend_DrawGlyphToSurface(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) { if (glyph == NULL || surface == NULL) return; @@ -240,17 +218,12 @@ void Backend_DrawGlyphToSurface(Backend_Surface *surface, Backend_Glyph *glyph, SDL_Rect rect; rect.x = x; rect.y = y; - rect.w = glyph->sdl_surface->w; - rect.h = glyph->sdl_surface->h; + rect.w = glyph->sdlsurface->w; + rect.h = glyph->sdlsurface->h; - SDL_SetSurfaceColorMod(glyph->sdl_surface, colours[0], colours[1], colours[2]); + SDL_SetSurfaceColorMod(glyph->sdlsurface, colours[0], colours[1], colours[2]); - SDL_BlitSurface(glyph->sdl_surface, NULL, surface->sdl_surface, &rect); -} - -void Backend_DrawGlyphToScreen(Backend_Glyph *glyph, long x, long y, const unsigned char *colours) -{ - Backend_DrawGlyphToSurface(&framebuffer, glyph, x, y, colours); + SDL_BlitSurface(glyph->sdlsurface, NULL, surface->sdlsurface, &rect); } void Backend_HandleDeviceLoss(void) @@ -262,5 +235,5 @@ void Backend_HandleWindowResize(void) { // https://wiki.libsdl.org/SDL_GetWindowSurface // We need to fetch a new surface pointer - window_surface = SDL_GetWindowSurface(window); + window_sdlsurface = SDL_GetWindowSurface(window); }