ref: 8524d1e34944348c635173e58d22a88d2ff059b5
parent: 7ca33677f8ef4137d6cdec2636b8c99e60b2de69
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Apr 15 17:59:23 EDT 2020
Change software renderer backend API
--- a/src/Backends/GLFW3/Window-Software.cpp
+++ b/src/Backends/GLFW3/Window-Software.cpp
@@ -24,7 +24,7 @@
static GLuint screen_texture_id;
-unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen, size_t *pitch)
+bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
{
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
@@ -81,11 +81,9 @@
framebuffer = (unsigned char*)malloc(framebuffer_width * framebuffer_height * 3);
- *pitch = framebuffer_width * 3;
-
Backend_PostWindowCreation();
- return framebuffer;
+ return true;
}
else
{
@@ -92,7 +90,7 @@
Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window");
}
- return NULL;
+ return false;
}
void WindowBackend_Software_DestroyWindow(void)
@@ -100,6 +98,13 @@
free(framebuffer);
glDeleteTextures(1, &screen_texture_id);
glfwDestroyWindow(window);
+}
+
+unsigned char* WindowBackend_Software_GetFramebuffer(size_t *pitch)
+{
+ *pitch = framebuffer_width * 3;
+
+ return framebuffer;
}
void WindowBackend_Software_Display(void)
--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -33,19 +33,22 @@
RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
{
- size_t pitch;
- framebuffer.pixels = WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen, &pitch);
- framebuffer.width = screen_width;
- framebuffer.height = screen_height;
- framebuffer.pitch = pitch;
+ if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
+ {
+ size_t pitch;
+ framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&pitch);
+ framebuffer.width = screen_width;
+ framebuffer.height = screen_height;
+ framebuffer.pitch = pitch;
- if (framebuffer.pixels == NULL)
+ return &framebuffer;
+ }
+ else
{
Backend_PrintError("Failed to create window");
- return NULL;
}
- return &framebuffer;
+ return NULL;
}
void RenderBackend_Deinit(void)
@@ -56,6 +59,10 @@
void RenderBackend_DrawScreen(void)
{
WindowBackend_Software_Display();
+
+ size_t pitch;
+ framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&pitch);
+ framebuffer.pitch = pitch;
}
RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height)
--- a/src/Backends/Window-Software.h
+++ b/src/Backends/Window-Software.h
@@ -2,7 +2,8 @@
#include <stddef.h>
-unsigned char* WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen, size_t *pitch);
+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);
void WindowBackend_Software_Display(void);
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height);