Switch software renderer to lockable framebuffer

SDL2 surfaces may require locking
This commit is contained in:
Clownacy 2020-09-10 15:47:27 +01:00
parent 0bdbb4f6bb
commit b6c9467151
6 changed files with 30 additions and 7 deletions

View file

@ -35,7 +35,7 @@ RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_w
if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen)) if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
{ {
size_t pitch; size_t pitch;
framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&pitch); framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&pitch);
framebuffer.width = screen_width; framebuffer.width = screen_width;
framebuffer.height = screen_height; framebuffer.height = screen_height;
framebuffer.pitch = pitch; framebuffer.pitch = pitch;
@ -57,10 +57,12 @@ void RenderBackend_Deinit(void)
void RenderBackend_DrawScreen(void) void RenderBackend_DrawScreen(void)
{ {
WindowBackend_Software_UnlockFramebuffer();
WindowBackend_Software_Display(); WindowBackend_Software_Display();
size_t pitch; size_t pitch;
framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&pitch); framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&pitch);
framebuffer.pitch = pitch; framebuffer.pitch = pitch;
} }

View file

@ -4,6 +4,7 @@
bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen); bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen);
void WindowBackend_Software_DestroyWindow(void); void WindowBackend_Software_DestroyWindow(void);
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch); unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch);
void WindowBackend_Software_UnlockFramebuffer(void);
void WindowBackend_Software_Display(void); void WindowBackend_Software_Display(void);
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height); void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height);

View file

@ -95,13 +95,18 @@ void WindowBackend_Software_DestroyWindow(void)
glfwDestroyWindow(window); glfwDestroyWindow(window);
} }
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch) unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
{ {
*pitch = framebuffer_width * 3; *pitch = framebuffer_width * 3;
return framebuffer; return framebuffer;
} }
void WindowBackend_Software_UnlockFramebuffer(void)
{
// Nothing to do here
}
void WindowBackend_Software_Display(void) void WindowBackend_Software_Display(void)
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View file

@ -28,13 +28,18 @@ void WindowBackend_Software_DestroyWindow(void)
free(framebuffer); free(framebuffer);
} }
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch) unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
{ {
*pitch = framebuffer_pitch; *pitch = framebuffer_pitch;
return framebuffer; return framebuffer;
} }
void WindowBackend_Software_UnlockFramebuffer(void)
{
// Nothing to do here
}
void WindowBackend_Software_Display(void) void WindowBackend_Software_Display(void)
{ {

View file

@ -64,13 +64,18 @@ void WindowBackend_Software_DestroyWindow(void)
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
} }
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch) unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
{ {
*pitch = framebuffer_sdlsurface->pitch; *pitch = framebuffer_sdlsurface->pitch;
return (unsigned char*)framebuffer_sdlsurface->pixels; return (unsigned char*)framebuffer_sdlsurface->pixels;
} }
void WindowBackend_Software_UnlockFramebuffer(void)
{
// Nothing to do here
}
void WindowBackend_Software_Display(void) void WindowBackend_Software_Display(void)
{ {
if (SDL_BlitSurface(framebuffer_sdlsurface, NULL, window_sdlsurface, NULL) < 0) if (SDL_BlitSurface(framebuffer_sdlsurface, NULL, window_sdlsurface, NULL) < 0)

View file

@ -206,13 +206,18 @@ void WindowBackend_Software_DestroyWindow(void)
free(fake_framebuffer); free(fake_framebuffer);
} }
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch) unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
{ {
*pitch = fake_framebuffer_width * 3; *pitch = fake_framebuffer_width * 3;
return fake_framebuffer; return fake_framebuffer;
} }
void WindowBackend_Software_UnlockFramebuffer(void)
{
// Nothing to do here
}
ATTRIBUTE_HOT void WindowBackend_Software_Display(void) ATTRIBUTE_HOT void WindowBackend_Software_Display(void)
{ {
// Convert frame from RGB24 to RGBA32, and upload it to the GPU texture // Convert frame from RGB24 to RGBA32, and upload it to the GPU texture