{
scr.Clear();
view.Render(scr.ViewportWidth(), scr.ViewportHeight());
- scr.DebugFontPrintF("[CPU] Render took %lf ms (%lf FPS)\n", (SDL_GetPerformanceCounter() - init_time)* 1000.0/SDL_GetPerformanceFrequency(), SDL_GetPerformanceFrequency()/(SDL_GetPerformanceCounter() - init_time));
+ scr.DebugFontPrintF("[CPU] Render took %lf ms (%lf FPS)\n", (scr.GetLastFrameTimeCPU())* 1000.0, 1.0/scr.GetLastFrameTimeCPU());
+ scr.DebugFontPrintF("[GPU] Render took %lf ms (%lf FPS)\n", (scr.GetLastFrameTimeGPU())* 1000.0, 1.0/scr.GetLastFrameTimeGPU());
scr.DebugFontPrintF("View bounds: %s\n", view.GetBounds().Str().c_str());
if (view.UsingGPUTransform())
{
Fatal("Your system does not support the ARB_explicit_attrib_location extension, which is required.");
}
+ m_frame_begin_time = SDL_GetPerformanceCounter();
+ m_last_frame_time = 0;
+ m_last_frame_gpu_timer = 0;
+ glGenQueries(1, &m_frame_gpu_timer);
+ glBeginQuery(GL_TIME_ELAPSED, m_frame_gpu_timer);
+
glDebugMessageCallback(opengl_debug_callback, 0);
GLuint default_vao;
{
if (m_debug_font_atlas)
DebugFontFlush();
+ m_last_frame_time = SDL_GetPerformanceCounter() - m_frame_begin_time;
+ glEndQuery(GL_TIME_ELAPSED);
SDL_GL_SwapWindow(m_window);
+ m_frame_begin_time = SDL_GetPerformanceCounter();
+ if (m_last_frame_gpu_timer)
+ glDeleteQueries(1, &m_last_frame_gpu_timer);
+ m_last_frame_gpu_timer = m_frame_gpu_timer;
+ glGenQueries(1, &m_frame_gpu_timer);
+ glBeginQuery(GL_TIME_ELAPSED, m_frame_gpu_timer);
+}
+
+double Screen::GetLastFrameTimeGPU() const
+{
+ if (!m_last_frame_gpu_timer)
+ return 0;
+ uint64_t frame_time_ns;
+ glGetQueryObjectui64v(m_last_frame_gpu_timer, GL_QUERY_RESULT, &frame_time_ns);
+ return frame_time_ns/1000000000.0;
}
void Screen::ScreenShot(const char * filename) const
void ScreenShot(const char * filename) const;
void RenderBMP(const char * filename) const;
+
+ // 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;
private:
void ResizeViewport(int width, int height);
void DebugFontFlush();
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;