+ 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 (!Valid() || !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::RenderPixels(int x, int y, int w, int h, uint8_t *pixels) const
+{
+ GLenum texture_format = GL_RGBA;
+
+ m_texture_prog.Use();
+ GraphicsBuffer quad_vertex_buffer;
+ quad_vertex_buffer.SetUsage(GraphicsBuffer::BufferUsageStaticDraw);
+ quad_vertex_buffer.SetType(GraphicsBuffer::BufferTypeVertex);
+ //rectangular texture == 2 triangles
+ GLfloat quad[] = {
+ 0, 0, (float)x, (float)y,
+ 1, 0, (float)(x+w), (float)y,
+ 0, 1, (float)x, (float)(y+h),
+ 1, 1, (float)(x+w), (float)(y+h)
+ };
+ quad_vertex_buffer.Upload(sizeof(GLfloat) * 16, quad);
+ quad_vertex_buffer.Bind();
+ m_viewport_ubo.Bind();
+
+ glUniform4f(m_colour_uniform_location, 1.0f, 1.0f, 1.0f, 1.0f);
+
+ GLuint texID;
+ glGenTextures(1, &texID);
+ glBindTexture(GL_TEXTURE_2D, texID);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, texture_format, GL_UNSIGNED_BYTE, pixels);
+
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (void*)(2*sizeof(float)));
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), 0);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ glDisableVertexAttribArray(1);
+ glDisableVertexAttribArray(0);
+