Change software renderer sub-backend API
No more locking
This commit is contained in:
parent
30ea89d3fa
commit
2bcab6adee
6 changed files with 14 additions and 33 deletions
|
@ -35,7 +35,7 @@ RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t scree
|
|||
{
|
||||
if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
|
||||
{
|
||||
framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&framebuffer.pitch);
|
||||
framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&framebuffer.pitch);
|
||||
framebuffer.width = screen_width;
|
||||
framebuffer.height = screen_height;
|
||||
|
||||
|
@ -56,11 +56,10 @@ void RenderBackend_Deinit(void)
|
|||
|
||||
void RenderBackend_DrawScreen(void)
|
||||
{
|
||||
WindowBackend_Software_UnlockFramebuffer();
|
||||
|
||||
WindowBackend_Software_Display();
|
||||
|
||||
framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&framebuffer.pitch);
|
||||
// Backends may use double-buffering, so fetch a new framebuffer just in case
|
||||
framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&framebuffer.pitch);
|
||||
}
|
||||
|
||||
RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen);
|
||||
void WindowBackend_Software_DestroyWindow(void);
|
||||
unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch);
|
||||
void WindowBackend_Software_UnlockFramebuffer(void);
|
||||
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch);
|
||||
void WindowBackend_Software_Display(void);
|
||||
void WindowBackend_Software_HandleWindowResize(size_t width, size_t height);
|
||||
|
|
|
@ -95,18 +95,13 @@ void WindowBackend_Software_DestroyWindow(void)
|
|||
glfwDestroyWindow(window);
|
||||
}
|
||||
|
||||
unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
|
||||
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
|
||||
{
|
||||
*pitch = framebuffer_width * 3;
|
||||
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
void WindowBackend_Software_UnlockFramebuffer(void)
|
||||
{
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
void WindowBackend_Software_Display(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
|
|
@ -28,18 +28,13 @@ void WindowBackend_Software_DestroyWindow(void)
|
|||
free(framebuffer);
|
||||
}
|
||||
|
||||
unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
|
||||
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
|
||||
{
|
||||
*pitch = framebuffer_pitch;
|
||||
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
void WindowBackend_Software_UnlockFramebuffer(void)
|
||||
{
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
void WindowBackend_Software_Display(void)
|
||||
{
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen
|
|||
|
||||
if (framebuffer_sdlsurface != NULL)
|
||||
{
|
||||
SDL_LockSurface(framebuffer_sdlsurface); // If this errors then oh dear
|
||||
|
||||
Backend_PostWindowCreation();
|
||||
|
||||
return true;
|
||||
|
@ -64,26 +66,22 @@ void WindowBackend_Software_DestroyWindow(void)
|
|||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
|
||||
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
|
||||
{
|
||||
if (SDL_LockSurface(framebuffer_sdlsurface) < 0)
|
||||
return NULL;
|
||||
|
||||
*pitch = framebuffer_sdlsurface->pitch;
|
||||
|
||||
return (unsigned char*)framebuffer_sdlsurface->pixels;
|
||||
}
|
||||
|
||||
void WindowBackend_Software_UnlockFramebuffer(void)
|
||||
{
|
||||
SDL_UnlockSurface(framebuffer_sdlsurface);
|
||||
}
|
||||
|
||||
void WindowBackend_Software_Display(void)
|
||||
{
|
||||
SDL_UnlockSurface(framebuffer_sdlsurface);
|
||||
|
||||
if (SDL_BlitSurface(framebuffer_sdlsurface, NULL, window_sdlsurface, NULL) < 0)
|
||||
Backend_PrintError("Couldn't blit framebuffer surface to window surface: %s", SDL_GetError());
|
||||
|
||||
SDL_LockSurface(framebuffer_sdlsurface); // If this errors then oh dear
|
||||
|
||||
if (SDL_UpdateWindowSurface(window) < 0)
|
||||
Backend_PrintError("Couldn't copy window surface to the screen: %s", SDL_GetError());
|
||||
}
|
||||
|
|
|
@ -206,18 +206,13 @@ void WindowBackend_Software_DestroyWindow(void)
|
|||
free(fake_framebuffer);
|
||||
}
|
||||
|
||||
unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
|
||||
unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
|
||||
{
|
||||
*pitch = fake_framebuffer_width * 3;
|
||||
|
||||
return fake_framebuffer;
|
||||
}
|
||||
|
||||
void WindowBackend_Software_UnlockFramebuffer(void)
|
||||
{
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
ATTRIBUTE_HOT void WindowBackend_Software_Display(void)
|
||||
{
|
||||
// Convert frame from RGB24 to RGBA32, and upload it to the GPU texture
|
||||
|
|
Loading…
Add table
Reference in a new issue