Overhauls text rendering to improve performance. Renderer was really ineffient, sending a separate GPU draw call for every character rendered. This created a bottleneck, especially with text-heavy UI stuff like the wallpaper. - The 'TextRenderer' now generates a single texture atlas for all font glyhs on load so all characters share a single texture. - 'begin()' / 'flush()' was added to the 'TextRenderer'. Calls to 'render_text' now buffer vertex data (position, texture coords, colour) instead of drawing immediately. A single 'flush()' call at the end of a pass draws all buffered text in one draw call. - A simple batching introduced some shitty visual layering bugs. to solve this, a staged flushing architecture has been implemented. Each logical UI component is now responsible for managing its own rendering passes, beginning and flushing text batches as needed to ensure correct back-to-front layering.
31 lines
938 B
C++
31 lines
938 B
C++
#pragma once
|
|
|
|
#include "gfx/shape_renderer.h"
|
|
#include "gfx/txt_renderer.h"
|
|
#include "gfx/types.h"
|
|
|
|
/*
|
|
* I'm so damn sick of working between two rendering systems!
|
|
* Here! Have a wrapper around the low-level renderers to provide a f.cking
|
|
* consistant top-left origin for all UI components.
|
|
*/
|
|
class UIRenderer {
|
|
public:
|
|
UIRenderer(ShapeRenderer* shape_renderer, TextRenderer* txt_renderer, int screen_height);
|
|
|
|
void draw_rect(int x, int y, int width, int height, const Color& color);
|
|
void draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, const Color& color);
|
|
void render_text(const char* text, int x, int y, const Color& color);
|
|
|
|
void begin_text(void);
|
|
void flush_text(void);
|
|
|
|
/* Expose underlying text renderer for things like width calculation. */
|
|
TextRenderer* get_text_renderer(void);
|
|
|
|
private:
|
|
ShapeRenderer* _shape_renderer;
|
|
TextRenderer* _txt_renderer;
|
|
int _screen_height;
|
|
};
|