8 #include "stb_truetype.h"
9 #include "graphicsbuffer.h"
10 #include "shaderprogram.h"
15 * The "Screen" class handles managing the OS window (using SDL2).
23 // 'Pumps' the system event queue.
24 // Returns 'false' if the program should quit.
27 // Clears the screen to a given colour.
28 void Clear(float r=1.0, float g=1.0, float b=1.0, float a=1.0);
30 // Finishes rendering a frame, and presents it on the screen.
33 // Get the current width/height of the window's viewport.
34 int ViewportWidth() const { return m_viewport_width; }
35 int ViewportHeight() const { return m_viewport_height; }
37 // Debug Font handling
38 void DebugFontInit(const char *font_name, float font_size = 12);
39 void DebugFontClear();
40 void DebugFontPrint(const char *str);
41 void DebugFontPrintF(const char *fmt, ...);
43 // Handle mouse input.
44 typedef std::function<void(int x, int y, int button, int wheel)> MouseHandler;
45 void SetMouseHandler(MouseHandler handler)
47 m_mouse_handler = handler;
58 void SetMouseCursor(MouseCursors cursor);
60 void ScreenShot(const char * filename) const;
61 void RenderBMP(const char * filename) const;
62 void RenderPixels(int x, int y, int w, int h, uint8_t * pixels) const;
66 // Returns the CPU time (in seconds) it took to render the last completed frame.
67 double GetLastFrameTimeCPU() const { return m_last_frame_time / SDL_GetPerformanceFrequency(); }
68 // Returns the GPU time (in seconds) it took to render the last completed frame.
69 double GetLastFrameTimeGPU() const;
71 void ResizeViewport(int width, int height);
72 void DebugFontFlush();
74 MouseHandler m_mouse_handler;
78 double m_last_frame_time;
79 double m_frame_begin_time;
80 GLuint m_frame_gpu_timer;
81 GLuint m_last_frame_gpu_timer;
84 int m_viewport_height;
86 SDL_GLContext m_gl_context;
87 ShaderProgram m_texture_prog;
88 ShaderProgram m_font_prog;
89 GLint m_colour_uniform_location;
90 GraphicsBuffer m_viewport_ubo;
91 stbtt_bakedchar m_debug_font_rects[96];
92 unsigned int m_debug_font_atlas;
95 float m_debug_font_size;
96 GraphicsBuffer m_debug_font_vertices;
97 GraphicsBuffer m_debug_font_indices;
98 int m_debug_font_vertex_head;
99 int m_debug_font_index_head;