shithub: cstory

Download patch

ref: b6c9467151cbfeb6ac13c06c1d4c1acb31820a69
parent: 0bdbb4f6bb5d60f62beac4e581d5efa00d84667a
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 10 11:47:27 EDT 2020

Switch software renderer to lockable framebuffer

SDL2 surfaces may require locking

--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -35,7 +35,7 @@
 	if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
 	{
 		size_t pitch;
-		framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&pitch);
+		framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&pitch);
 		framebuffer.width = screen_width;
 		framebuffer.height = screen_height;
 		framebuffer.pitch = pitch;
@@ -57,10 +57,12 @@
 
 void RenderBackend_DrawScreen(void)
 {
+	WindowBackend_Software_UnlockFramebuffer();
+
 	WindowBackend_Software_Display();
 
 	size_t pitch;
-	framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&pitch);
+	framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&pitch);
 	framebuffer.pitch = pitch;
 }
 
--- a/src/Backends/Rendering/Window/Software.h
+++ b/src/Backends/Rendering/Window/Software.h
@@ -4,6 +4,7 @@
 
 bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen);
 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_HandleWindowResize(unsigned int width, unsigned int height);
--- a/src/Backends/Rendering/Window/Software/GLFW3.cpp
+++ b/src/Backends/Rendering/Window/Software/GLFW3.cpp
@@ -95,11 +95,16 @@
 	glfwDestroyWindow(window);
 }
 
-unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
+unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
 {
 	*pitch = framebuffer_width * 3;
 
 	return framebuffer;
+}
+
+void WindowBackend_Software_UnlockFramebuffer(void)
+{
+	// Nothing to do here
 }
 
 void WindowBackend_Software_Display(void)
--- a/src/Backends/Rendering/Window/Software/Null.cpp
+++ b/src/Backends/Rendering/Window/Software/Null.cpp
@@ -28,11 +28,16 @@
 	free(framebuffer);
 }
 
-unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
+unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
 {
 	*pitch = framebuffer_pitch;
 
 	return framebuffer;
+}
+
+void WindowBackend_Software_UnlockFramebuffer(void)
+{
+	// Nothing to do here
 }
 
 void WindowBackend_Software_Display(void)
--- a/src/Backends/Rendering/Window/Software/SDL2.cpp
+++ b/src/Backends/Rendering/Window/Software/SDL2.cpp
@@ -64,11 +64,16 @@
 	SDL_DestroyWindow(window);
 }
 
-unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
+unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch)
 {
 	*pitch = framebuffer_sdlsurface->pitch;
 
 	return (unsigned char*)framebuffer_sdlsurface->pixels;
+}
+
+void WindowBackend_Software_UnlockFramebuffer(void)
+{
+	// Nothing to do here
 }
 
 void WindowBackend_Software_Display(void)
--- a/src/Backends/Rendering/Window/Software/WiiU.cpp
+++ b/src/Backends/Rendering/Window/Software/WiiU.cpp
@@ -206,11 +206,16 @@
 	free(fake_framebuffer);
 }
 
-unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
+unsigned char* WindowBackend_Software_LockFramebuffer(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)