8 #include "stb_truetype.h"
9 #include "graphicsbuffer.h"
10 #include "shaderprogram.h"
16 * The "Screen" class handles managing the OS window (using SDL2).
24 // 'Pumps' the system event queue.
25 // Returns 'false' if the program should quit.
28 // Clears the screen to a given colour.
29 void Clear(float r=1.0, float g=1.0, float b=1.0, float a=1.0);
31 // Finishes rendering a frame, and presents it on the screen.
34 // Get the current width/height of the window's viewport.
35 int ViewportWidth() const { return m_viewport_width; }
36 int ViewportHeight() const { return m_viewport_height; }
38 // Debug Font handling
39 void DebugFontInit(const char *font_name, float font_size = 12);
40 void DebugFontClear();
41 void DebugFontPrint(const char *str);
42 void DebugFontPrintF(const char *fmt, ...);
44 // Handle mouse input.
45 typedef void(*MouseHandler)(int x, int y, int button, int wheel, Screen * scr, View * view);
46 void SetMouseHandler(MouseHandler handler)
48 m_mouse_handler = handler;
59 void SetMouseCursor(MouseCursors cursor);
61 void ScreenShot(const char * filename) const;
62 void RenderBMP(const char * filename) const;
63 void RenderPixels(int x, int y, int w, int h, uint8_t * pixels) const;
66 void SetView(View * new_view) {m_view = new_view;}
68 // Returns the CPU time (in seconds) it took to render the last completed frame.
69 double GetLastFrameTimeCPU() const { return m_last_frame_time / SDL_GetPerformanceFrequency(); }
70 // Returns the GPU time (in seconds) it took to render the last completed frame.
71 double GetLastFrameTimeGPU() const;
73 void ResizeViewport(int width, int height);
74 void DebugFontFlush();
76 MouseHandler m_mouse_handler;
80 double m_last_frame_time;
81 double m_frame_begin_time;
82 GLuint m_frame_gpu_timer;
83 GLuint m_last_frame_gpu_timer;
86 int m_viewport_height;
88 SDL_GLContext m_gl_context;
89 ShaderProgram m_texture_prog;
90 ShaderProgram m_font_prog;
91 GLint m_colour_uniform_location;
92 GraphicsBuffer m_viewport_ubo;
93 stbtt_bakedchar m_debug_font_rects[96];
94 unsigned int m_debug_font_atlas;
97 float m_debug_font_size;
98 GraphicsBuffer m_debug_font_vertices;
99 GraphicsBuffer m_debug_font_indices;
100 int m_debug_font_vertex_head;
101 int m_debug_font_index_head;