X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fscreen.h;h=aed042d51ae345b6b0cdd05d8e65c7cccdcb2e8a;hp=8452efcb76908f0e479f8e6a8552d267b4e31aef;hb=398e6b2732decd57cdb57deb3f91d3ff08669e8b;hpb=e6c66a8e58f1dda071e6fc4abed39afe49d348f8 diff --git a/src/screen.h b/src/screen.h index 8452efc..aed042d 100644 --- a/src/screen.h +++ b/src/screen.h @@ -1,12 +1,17 @@ #ifndef _SCREEN_H #define _SCREEN_H -#include +#include "SDL.h" #include +#include "stb_truetype.h" +#include "graphicsbuffer.h" +#include "shaderprogram.h" + namespace IPDF { + class View; /* * The "Screen" class handles managing the OS window (using SDL2). */ @@ -20,15 +25,24 @@ namespace IPDF // Returns 'false' if the program should quit. bool PumpEvents(); + // Clears the screen to a given colour. + void Clear(float r=1.0, float g=1.0, float b=1.0, float a=1.0); + // Finishes rendering a frame, and presents it on the screen. void Present(); // Get the current width/height of the window's viewport. - int ViewportWidth() { return m_viewport_width; } - int ViewportHeight() { return m_viewport_height; } + int ViewportWidth() const { return m_viewport_width; } + int ViewportHeight() const { return m_viewport_height; } + + // Debug Font handling + void DebugFontInit(const char *font_name, float font_size = 12); + void DebugFontClear(); + void DebugFontPrint(const char *str); + void DebugFontPrintF(const char *fmt, ...); // Handle mouse input. - typedef std::function MouseHandler; + typedef void(*MouseHandler)(int x, int y, int button, int wheel, Screen * scr, View * view); void SetMouseHandler(MouseHandler handler) { m_mouse_handler = handler; @@ -43,15 +57,57 @@ namespace IPDF CursorHand }; void SetMouseCursor(MouseCursors cursor); + + void ScreenShot(const char * filename) const; + void RenderBMP(const char * filename) const; + void RenderPixels(int x, int y, int w, int h, uint8_t * pixels) const; + + + void SetView(View * new_view) {m_view = new_view;} + + // Returns the CPU time (in seconds) it took to render the last completed frame. + double GetLastFrameTimeCPU() const { return m_last_frame_time / SDL_GetPerformanceFrequency(); } + // Returns the GPU time (in seconds) it took to render the last completed frame. + double GetLastFrameTimeGPU() const; + + void RequestQuit() {m_no_quit_requested = false;} + bool QuitRequested() const {return !m_no_quit_requested;} + + void ShowDebugFont(bool show = true) {m_show_debug_font = show;} + bool DebugFontShown() const {return m_show_debug_font;} private: void ResizeViewport(int width, int height); + void DebugFontFlush(); MouseHandler m_mouse_handler; + int m_last_mouse_x; + int m_last_mouse_y; + + double m_last_frame_time; + double m_frame_begin_time; + GLuint m_frame_gpu_timer; + GLuint m_last_frame_gpu_timer; int m_viewport_width; int m_viewport_height; SDL_Window *m_window; SDL_GLContext m_gl_context; + ShaderProgram m_texture_prog; + ShaderProgram m_font_prog; + GLint m_colour_uniform_location; + GraphicsBuffer m_viewport_ubo; + stbtt_bakedchar m_debug_font_rects[96]; + unsigned int m_debug_font_atlas; + float m_debug_font_x; + float m_debug_font_y; + float m_debug_font_size; + GraphicsBuffer m_debug_font_vertices; + GraphicsBuffer m_debug_font_indices; + int m_debug_font_vertex_head; + int m_debug_font_index_head; + View * m_view; + bool m_no_quit_requested; + bool m_show_debug_font; }; }