ref: 11bbad7372539841811bffad257e425283ecc79d
parent: 392d5898a3cd3d6ff8f25117402f1843dd3e4d6f
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Sep 15 15:40:10 EDT 2020
Cleanup Now RenderBackend_DrawGlyph doesn't pass an unnecessary parameter
--- a/src/Backends/Rendering.h
+++ b/src/Backends/Rendering.h
@@ -27,6 +27,6 @@
void RenderBackend_DestroyGlyphAtlas(RenderBackend_GlyphAtlas *atlas);
void RenderBackend_UploadGlyph(RenderBackend_GlyphAtlas *atlas, size_t x, size_t y, const unsigned char *pixels, size_t width, size_t height);
void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBackend_Surface *destination_surface, unsigned char red, unsigned char green, unsigned char blue);
-void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height);
+void RenderBackend_DrawGlyph(long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height);
void RenderBackend_HandleRenderTargetLoss(void);
void RenderBackend_HandleWindowResize(size_t width, size_t height);
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -65,8 +65,8 @@
GLuint id;
struct
{
- GLint texture_coordinate_transform;
GLint vertex_transform;
+ GLint texture_coordinate_transform;
} uniforms;
} program_texture;
@@ -75,8 +75,8 @@
GLuint id;
struct
{
- GLint texture_coordinate_transform;
GLint vertex_transform;
+ GLint texture_coordinate_transform;
} uniforms;
} program_texture_colour_key;
@@ -95,8 +95,8 @@
GLuint id;
struct
{
- GLint texture_coordinate_transform;
GLint vertex_transform;
+ GLint texture_coordinate_transform;
GLint colour;
} uniforms;
} program_glyph;
@@ -118,8 +118,6 @@
static RenderBackend_Surface framebuffer;
-static RenderBackend_Surface *glyph_destination_surface;
-
static size_t actual_screen_width;
static size_t actual_screen_height;
@@ -196,7 +194,9 @@
gl_FragColor = colour * vec4(1.0, 1.0, 1.0, texture2D(tex, texture_coordinates).r); \
} \
";
+
#else
+
static const GLchar *vertex_shader_plain = " \
#version 150 core\n \
uniform mat4 vertex_transform; \
@@ -270,6 +270,8 @@
} \
";
#endif
+
+// This was used back when CSE2 used GLEW instead of glad
/*
static void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void* userParam)
{
@@ -283,6 +285,7 @@
Backend_PrintInfo("OpenGL debug: %s", message);
}
*/
+
////////////////////////
// Shader compilation //
////////////////////////
@@ -677,7 +680,6 @@
vertex_buffer_slot->vertices[1][1].texture.y = 0.0f;
vertex_buffer_slot->vertices[1][2].texture.x = 0.0f;
vertex_buffer_slot->vertices[1][2].texture.y = 0.0f;
-
}
FlushVertexBuffer();
@@ -979,21 +981,17 @@
void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBackend_Surface *destination_surface, unsigned char red, unsigned char green, unsigned char blue)
{
- (void)atlas;
-
static unsigned char last_red;
static unsigned char last_green;
static unsigned char last_blue;
- glyph_destination_surface = destination_surface;
-
// Flush vertex data if a context-change is needed
- if (last_render_mode != MODE_DRAW_GLYPH || last_destination_texture != glyph_destination_surface->texture_id || last_source_texture != atlas->texture_id || last_red != red || last_green != green || last_blue != blue)
+ if (last_render_mode != MODE_DRAW_GLYPH || last_destination_texture != destination_surface->texture_id || last_source_texture != atlas->texture_id || last_red != red || last_green != green || last_blue != blue)
{
FlushVertexBuffer();
last_render_mode = MODE_DRAW_GLYPH;
- last_destination_texture = glyph_destination_surface->texture_id;
+ last_destination_texture = destination_surface->texture_id;
last_source_texture = atlas->texture_id;
last_red = red;
last_green = green;
@@ -1000,8 +998,8 @@
last_blue = blue;
const GLfloat vertex_transform[4 * 4] = {
- 2.0f / glyph_destination_surface->width, 0.0f, 0.0f, -1.0f,
- 0.0f, 2.0f / glyph_destination_surface->height, 0.0f, -1.0f,
+ 2.0f / destination_surface->width, 0.0f, 0.0f, -1.0f,
+ 0.0f, 2.0f / destination_surface->height, 0.0f, -1.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
};
@@ -1012,8 +1010,8 @@
glUniformMatrix4fv(program_glyph.uniforms.vertex_transform, 1, GL_FALSE, vertex_transform);
// Point our framebuffer to the destination texture
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glyph_destination_surface->texture_id, 0);
- glViewport(0, 0, glyph_destination_surface->width, glyph_destination_surface->height);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destination_surface->texture_id, 0);
+ glViewport(0, 0, destination_surface->width, destination_surface->height);
glEnable(GL_BLEND);
@@ -1024,7 +1022,7 @@
}
}
-void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
+void RenderBackend_DrawGlyph(long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
{
// Add data to the vertex queue
VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot();
--- a/src/Backends/Rendering/SDLSurface.cpp
+++ b/src/Backends/Rendering/SDLSurface.cpp
@@ -26,7 +26,8 @@
static RenderBackend_Surface framebuffer;
-static SDL_Surface *glyph_destination_sdlsurface;
+static RenderBackend_GlyphAtlas *glyph_atlas;
+static RenderBackend_Surface *glyph_destination_surface;
static void RectToSDLRect(const RenderBackend_Rect *rect, SDL_Rect *sdl_rect)
{
@@ -230,13 +231,14 @@
void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBackend_Surface *destination_surface, unsigned char red, unsigned char green, unsigned char blue)
{
- glyph_destination_sdlsurface = destination_surface->sdlsurface;
+ glyph_atlas = atlas;
+ glyph_destination_surface = destination_surface;
if (SDL_SetSurfaceColorMod(atlas->sdlsurface, red, green, blue) < 0)
Backend_PrintError("Couldn't set color value: %s", SDL_GetError());
}
-void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
+void RenderBackend_DrawGlyph(long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
{
SDL_Rect source_rect;
source_rect.x = glyph_x;
@@ -250,7 +252,7 @@
destination_rect.w = glyph_width;
destination_rect.h = glyph_height;
- if (SDL_BlitSurface(atlas->sdlsurface, &source_rect, glyph_destination_sdlsurface, &destination_rect) < 0)
+ if (SDL_BlitSurface(glyph_atlas->sdlsurface, &source_rect, glyph_destination_surface->sdlsurface, &destination_rect) < 0)
Backend_PrintError("Couldn't blit glyph indivual surface to final glyph surface: %s", SDL_GetError());
}
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -43,6 +43,8 @@
static RenderBackend_Surface *surface_list_head;
+static RenderBackend_GlyphAtlas *glyph_atlas;
+
static void RectToSDLRect(const RenderBackend_Rect *rect, SDL_Rect *sdl_rect)
{
sdl_rect->x = (int)rect->left;
@@ -371,7 +373,7 @@
void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBackend_Surface *destination_surface, unsigned char red, unsigned char green, unsigned char blue)
{
- (void)atlas;
+ glyph_atlas = atlas;
if (SDL_SetRenderTarget(renderer, destination_surface->texture) < 0)
Backend_PrintError("Couldn't set texture as current rendering target: %s", SDL_GetError());
@@ -386,7 +388,7 @@
}
-void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
+void RenderBackend_DrawGlyph(long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
{
SDL_Rect source_rect;
source_rect.x = glyph_x;
@@ -400,7 +402,7 @@
destination_rect.w = glyph_width;
destination_rect.h = glyph_height;
- if (SDL_RenderCopy(renderer, atlas->texture, &source_rect, &destination_rect) < 0)
+ if (SDL_RenderCopy(renderer, glyph_atlas->texture, &source_rect, &destination_rect) < 0)
Backend_PrintError("Couldn't copy glyph texture portion to renderer: %s", SDL_GetError());
}
--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -28,8 +28,9 @@
static RenderBackend_Surface framebuffer;
-static unsigned char glyph_colour_channels[3];
+static RenderBackend_GlyphAtlas *glyph_atlas;
static RenderBackend_Surface *glyph_destination_surface;
+static unsigned char glyph_colour_channels[3];
RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
@@ -272,8 +273,7 @@
void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBackend_Surface *destination_surface, unsigned char red, unsigned char green, unsigned char blue)
{
- (void)atlas;
-
+ glyph_atlas = atlas;
glyph_destination_surface = destination_surface;
glyph_colour_channels[0] = red;
@@ -281,13 +281,13 @@
glyph_colour_channels[2] = blue;
}
-void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
+void RenderBackend_DrawGlyph(long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
{
for (unsigned int iy = MAX(-y, 0); y + iy < MIN(y + glyph_height, glyph_destination_surface->height); ++iy)
{
for (unsigned int ix = MAX(-x, 0); x + ix < MIN(x + glyph_width, glyph_destination_surface->width); ++ix)
{
- const unsigned char alpha_int = atlas->pixels[(glyph_y + iy) * atlas->width + (glyph_x + ix)];
+ const unsigned char alpha_int = glyph_atlas->pixels[(glyph_y + iy) * glyph_atlas->width + (glyph_x + ix)];
if (alpha_int != 0)
{
--- a/src/Backends/Rendering/WiiU.cpp
+++ b/src/Backends/Rendering/WiiU.cpp
@@ -86,6 +86,7 @@
static GX2ContextState *gx2_context;
+static RenderBackend_GlyphAtlas *glyph_atlas;
static RenderBackend_Surface *glyph_destination_surface;
static Viewport tv_viewport;
@@ -774,16 +775,15 @@
void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBackend_Surface *destination_surface, unsigned char red, unsigned char green, unsigned char blue)
{
- (void)atlas;
-
static unsigned char last_red;
static unsigned char last_green;
static unsigned char last_blue;
+ glyph_atlas = atlas;
glyph_destination_surface = destination_surface;
// Flush vertex data if a context-change is needed
- if (last_render_mode != MODE_DRAW_GLYPH || last_destination_texture != &glyph_destination_surface->texture || last_source_texture != &atlas->texture || last_red != red || last_green != green || last_blue != blue)
+ if (last_render_mode != MODE_DRAW_GLYPH || last_destination_texture != &destination_surface->texture || last_source_texture != &atlas->texture || last_red != red || last_green != green || last_blue != blue)
{
FlushVertexBuffer();
@@ -819,7 +819,7 @@
}
}
-void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
+void RenderBackend_DrawGlyph(long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
{
VertexBufferSlot *vertex_buffer_slot = GetVertexBufferSlot();
@@ -840,10 +840,10 @@
vertex_buffer_slot->vertices[3].position.x = vertex_left;
vertex_buffer_slot->vertices[3].position.y = vertex_bottom;
- const float texture_left = glyph_x / (float)atlas->texture.surface.width;
- const float texture_top = glyph_y / (float)atlas->texture.surface.height;
- const float texture_right = (glyph_x + glyph_width) / (float)atlas->texture.surface.width;
- const float texture_bottom = (glyph_y + glyph_height) / (float)atlas->texture.surface.height;
+ const float texture_left = glyph_x / (float)glyph_atlas->texture.surface.width;
+ const float texture_top = glyph_y / (float)glyph_atlas->texture.surface.height;
+ const float texture_right = (glyph_x + glyph_width) / (float)glyph_atlas->texture.surface.width;
+ const float texture_bottom = (glyph_y + glyph_height) / (float)glyph_atlas->texture.surface.height;
// Set texture coordinate buffer
vertex_buffer_slot->vertices[0].texture.x = texture_left;
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -1162,7 +1162,7 @@
const long letter_x = x + pen_x + glyph->x_offset;
const long letter_y = y + glyph->y_offset;
- RenderBackend_DrawGlyph(font->atlas, letter_x, letter_y, glyph->x, glyph->y, glyph->width, glyph->height);
+ RenderBackend_DrawGlyph(letter_x, letter_y, glyph->x, glyph->y, glyph->width, glyph->height);
pen_x += glyph->x_advance;
}