- // Draw some grid lines at fixed pixel positions
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0, 1.0, 1.0, 0.0, -1.f, 1.f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glColor4f(0.9,0.9,0.9,0.1);
- const float num_lines = 50.0;
- for (float i = 0; i < num_lines; ++i)
+ Rect out;
+ out.x = (inp.x - m_bounds.x) / m_bounds.w;
+ out.y = (inp.y - m_bounds.y) / m_bounds.h;
+ out.w = inp.w / m_bounds.w;
+ out.h = inp.h / m_bounds.h;
+ return out;
+}
+
+/**
+ * Render the view
+ * Updates FrameBuffer if the document, object bounds, or view bounds have changed, then Blits it
+ * Otherwise just Blits the cached FrameBuffer
+ * @param width - Width of View to render
+ * @param height - Height of View to render
+ */
+void View::Render(int width, int height)
+{
+ // View dimensions have changed (ie: Window was resized)
+ int prev_width = m_cached_display.GetWidth();
+ int prev_height = m_cached_display.GetHeight();
+ if (width != prev_width || height != prev_height)
+ {
+ m_cached_display.Create(width, height);
+ m_bounds_dirty = true;
+ }
+
+ // View bounds have not changed; blit the FrameBuffer as it is
+ if (!m_bounds_dirty)
+ {
+ m_cached_display.UnBind();
+ m_cached_display.Blit();
+ return;
+ }
+
+ // Bind FrameBuffer for rendering, and clear it
+
+
+ if (m_render_dirty) // document has changed
+ PrepareRender();
+
+ if (m_buffer_dirty) // object bounds have changed
+ UpdateObjBoundsVBO();
+
+ if (m_use_gpu_transform)
+ {
+ GLfloat glbounds[] = {static_cast<GLfloat>(Float(m_bounds.x)), static_cast<GLfloat>(Float(m_bounds.y)), static_cast<GLfloat>(Float(m_bounds.w)), static_cast<GLfloat>(Float(m_bounds.h))};
+ m_bounds_ubo.Upload(sizeof(float)*4, glbounds);
+ }
+ else
+ {
+ GLfloat glbounds[] = {0.0f, 0.0f, 1.0f, 1.0f};
+ m_bounds_ubo.Upload(sizeof(float)*4, glbounds);
+ }
+ m_bounds_dirty = false;
+
+ m_cached_display.Bind(); //NOTE: This is redundant; Clear already calls Bind
+ m_cached_display.Clear();
+
+
+ // Render using GPU
+ if (m_use_gpu_rendering)