From 237a7ad06f7e6901f561f7c12503ea4d37790ae9 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 5 Jul 2015 19:10:48 -0400 Subject: [PATCH] Separate transform calc and render --- src/ui/GLPanel.cpp | 16 +++++++++------- src/ui/GLPanel.h | 3 ++- src/ui/UITestContext.cpp | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ui/GLPanel.cpp b/src/ui/GLPanel.cpp index aed5d6b..4643966 100644 --- a/src/ui/GLPanel.cpp +++ b/src/ui/GLPanel.cpp @@ -2,7 +2,9 @@ #include "GLPanel.h" #include "cubic_math.h" -GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), contentsVisible(true), transform(CubicVR::mat4::identity()) { +using namespace CubicVR; + +GLPanel::GLPanel() : fillType(GLPANEL_FILL_SOLID), contentsVisible(true), transform(mat4::identity()) { pos[0] = 0.0f; pos[1] = 0.0f; size[0] = 1.0f; @@ -203,7 +205,8 @@ void GLPanel::drawChildren() { std::vector::iterator panel_i; for (panel_i = children.begin(); panel_i != children.end(); panel_i++) { - (*panel_i)->draw(transform, this); + (*panel_i)->calcTransform(transform); + (*panel_i)->draw(); } } } @@ -212,10 +215,7 @@ void GLPanel::drawPanelContents() { drawChildren(); } -void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) { - using namespace CubicVR; - - +void GLPanel::calcTransform(mat4 transform_in) { // compute local transform localTransform = mat4::translate(pos[0], pos[1], 0) * mat4::scale(size[0], size[1], 0); // compute global transform @@ -247,7 +247,9 @@ void GLPanel::draw(CubicVR::mat4 transform_in, GLPanel *parent) { if (marginPx) { transform *= mat4::scale(1.0 - marginPx * 2.0 * pvec.x / size[0], 1.0 - marginPx * 2.0 * pvec.y / size[1], 0); } - +} + +void GLPanel::draw() { glLoadMatrixf(transform); if (fillType != GLPANEL_FILL_NONE) { diff --git a/src/ui/GLPanel.h b/src/ui/GLPanel.h index 22d7600..c4c1ed2 100644 --- a/src/ui/GLPanel.h +++ b/src/ui/GLPanel.h @@ -78,7 +78,8 @@ public: void drawChildren(); virtual void drawPanelContents(); - void draw(CubicVR::mat4 transform, GLPanel *parent=NULL); + void calcTransform(CubicVR::mat4 transform); + void draw(); }; diff --git a/src/ui/UITestContext.cpp b/src/ui/UITestContext.cpp index f5c597b..5279d1f 100644 --- a/src/ui/UITestContext.cpp +++ b/src/ui/UITestContext.cpp @@ -57,7 +57,8 @@ void UITestContext::DrawBegin() { } void UITestContext::Draw() { - testPanel.draw(CubicVR::mat4::identity()); + testPanel.calcTransform(CubicVR::mat4::identity()); + testPanel.draw(); } void UITestContext::DrawEnd() {