X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fscreen.h;h=6b52a094730c06e6f089efe1e5244554095a2d37;hp=ddcf8cace42c35083c763c874250fcd2009c7a63;hb=e35bf651e7ebfe4932e877780bb00397c41a7ec2;hpb=bdda0103bf26d215d41093316ca0e15cd67fec1d diff --git a/src/screen.h b/src/screen.h index ddcf8ca..6b52a09 100644 --- a/src/screen.h +++ b/src/screen.h @@ -1,15 +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). */ @@ -40,7 +42,7 @@ namespace IPDF 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; @@ -58,6 +60,18 @@ namespace IPDF 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;} private: void ResizeViewport(int width, int height); void DebugFontFlush(); @@ -66,10 +80,19 @@ namespace IPDF 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; @@ -79,6 +102,8 @@ namespace IPDF 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; }; }