//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRendering) { OverlayItemRectMap itemRectMap; calculateOverlayItemLayout(&itemRectMap); // Must setup a scissor to limit the overlay items to the current viewport, as they might setup a local viewport (e.g. navigation cube) GLboolean scissorWasOn = glIsEnabled(GL_SCISSOR_TEST); int scissorBox[4] = {0, 0, -1, -1}; glGetIntegerv(GL_SCISSOR_BOX, scissorBox); glScissor(static_cast<GLsizei>(m_camera->viewport()->x()), static_cast<GLsizei>(m_camera->viewport()->y()), static_cast<GLsizei>(m_camera->viewport()->width()), static_cast<GLsizei>(m_camera->viewport()->height())); glEnable(GL_SCISSOR_TEST); OverlayItemRectMap::iterator it; for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it) { OverlayItem* item = it->first; Recti rect = it->second; if (useSoftwareRendering) { item->renderSoftware(oglContext, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height()))); } else { item->render(oglContext, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height()))); } } // Restore scissor settings if (!scissorWasOn) glDisable(GL_SCISSOR_TEST); glScissor(scissorBox[0], scissorBox[1], scissorBox[2], scissorBox[3]); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST(RectTest, FromMinMax) { { Rectd rect = Rectd::fromMinMax(Vec2d(-1, 2), Vec2d(10, 12)); EXPECT_TRUE(rect.isValid()); EXPECT_DOUBLE_EQ(-1, rect.min().x()); EXPECT_DOUBLE_EQ(2, rect.min().y()); EXPECT_DOUBLE_EQ(10, rect.max().x()); EXPECT_DOUBLE_EQ(12, rect.max().y()); EXPECT_DOUBLE_EQ(11, rect.width()); EXPECT_DOUBLE_EQ(10, rect.height()); } { Recti rect = Recti::fromMinMax(Vec2i(-1, 2), Vec2i(10, 12)); EXPECT_TRUE(rect.isValid()); EXPECT_EQ(-1, rect.min().x()); EXPECT_EQ( 2, rect.min().y()); EXPECT_EQ(10, rect.max().x()); EXPECT_EQ(12, rect.max().y()); EXPECT_EQ(11, rect.width()); EXPECT_EQ(10, rect.height()); } { Rectui rect = Rectui::fromMinMax(Vec2ui(1, 2), Vec2ui(11, 22)); EXPECT_TRUE(rect.isValid()); EXPECT_EQ( 1, rect.min().x()); EXPECT_EQ( 2, rect.min().y()); EXPECT_EQ(11, rect.max().x()); EXPECT_EQ(22, rect.max().y()); EXPECT_EQ(10, rect.width()); EXPECT_EQ(20, rect.height()); } }
TYPED_TEST(BufferTest, ShouldReturnRect) { Buffer<TypeParam> buffer(50, 50); Recti rect = buffer.rect(); ASSERT_EQ(0, rect.x()); ASSERT_EQ(0, rect.y()); ASSERT_EQ(50, rect.width()); ASSERT_EQ(50, rect.height()); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRendering) { OverlayItemRectMap itemRectMap; calculateOverlayItemLayout(&itemRectMap); // Must setup a scissor to limit the overlay items to the current viewport, as they might setup a local viewport (e.g. navigation cube) GLboolean scissorWasOn = glIsEnabled(GL_SCISSOR_TEST); int scissorBox[4] = {0, 0, -1, -1}; glGetIntegerv(GL_SCISSOR_BOX, scissorBox); glScissor(static_cast<GLsizei>(m_camera->viewport()->x()), static_cast<GLsizei>(m_camera->viewport()->y()), static_cast<GLsizei>(m_camera->viewport()->width()), static_cast<GLsizei>(m_camera->viewport()->height())); glEnable(GL_SCISSOR_TEST); const size_t numOverlayItems = m_overlayItems.size(); for (size_t i = 0; i < numOverlayItems; i++) { OverlayItem* item = m_overlayItems.at(i); Vec2i pos(0, 0); Vec2ui size(0, 0); if (item->layoutScheme() == OverlayItem::FIXED_POSITION) { pos = item->fixedPosition(); size = item->sizeHint(); } else { // Item should be laid out already - grab its pos/size from the layout map OverlayItemRectMap::iterator it = itemRectMap.find(item); if (it != itemRectMap.end()) { Recti rect = it->second; pos = rect.min(); size.set(static_cast<uint>(rect.width()), static_cast<uint>(rect.height())); } } if (!size.isZero()) { if (useSoftwareRendering) { item->renderSoftware(oglContext, pos, size); } else { item->render(oglContext, pos, size); } } } // Restore scissor settings if (!scissorWasOn) glDisable(GL_SCISSOR_TEST); glScissor(scissorBox[0], scissorBox[1], scissorBox[2], scissorBox[3]); }
//-------------------------------------------------------------------------------------------------- /// Get the the overlay item (if any) at the given cursor position //-------------------------------------------------------------------------------------------------- OverlayItem* Rendering::overlayItemFromWindowCoordinates(int x, int y) { OverlayItemRectMap itemRectMap; calculateOverlayItemLayout(&itemRectMap); OverlayItemRectMap::iterator it; for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it) { OverlayItem* item = it->first; Recti rect = it->second; if (item->pick(x, y, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height())))) { return item; } } return NULL; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRendering) { OverlayItemRectMap itemRectMap; calculateOverlayItemLayout(&itemRectMap); OverlayItemRectMap::iterator it; for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it) { OverlayItem* item = it->first; Recti rect = it->second; if (useSoftwareRendering) { item->renderSoftware(oglContext, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height()))); } else { item->render(oglContext, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height()))); } } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRendering) { OverlayItemRectMap itemRectMap; calculateOverlayItemLayout(&itemRectMap); OverlayItemRectMap::iterator it; for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it) { OverlayItem* item = it->first; Recti rect = it->second; if (useSoftwareRendering) { item->renderSoftware(oglContext, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height()))); } else { item->render(oglContext, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height()))); } } for (size_t i = 0; i < m_overlayItems.size(); i++) { OverlayItemLayout item = m_overlayItems.at(i); if ((item.corner == OverlayItem::UNMANAGED) ) { Vec2ui size = item.overlayItem->sizeHint(); Vec2i pos = item.overlayItem->unmanagedPosition(); if (useSoftwareRendering) { item.overlayItem->renderSoftware(oglContext, pos, size); } else { item.overlayItem->render(oglContext, pos, size); } } } }
//-------------------------------------------------------------------------------------------------- /// Get the the overlay item (if any) at the given cursor position //-------------------------------------------------------------------------------------------------- OverlayItem* Rendering::overlayItemFromWindowCoordinates(int x, int y) { OverlayItemRectMap itemRectMap; calculateOverlayItemLayout(&itemRectMap); const size_t numOverlayItems = m_overlayItems.size(); for (size_t i = 0; i < numOverlayItems; i++) { OverlayItem* item = m_overlayItems.at(i); OverlayItemRectMap::iterator it = itemRectMap.find(item); if (it != itemRectMap.end()) { Recti rect = it->second; if (item->pick(x, y, rect.min(), Vec2ui(static_cast<cvf::uint>(rect.width()), static_cast<cvf::uint>(rect.height())))) { return item; } } } return NULL; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- TEST(RectTest, RectTypes) { // Rectf { Rectf rect; EXPECT_FLOAT_EQ(0.0f, rect.min().x()); EXPECT_FLOAT_EQ(0.0f, rect.min().y()); EXPECT_FLOAT_EQ(0.0f, rect.width()); EXPECT_FLOAT_EQ(0.0f, rect.height()); EXPECT_FALSE(rect.isValid()); } { Rectf rect(-1.0f, -2.0f, 5.0f, 10.0f); EXPECT_FLOAT_EQ(-1.0f, rect.min().x()); EXPECT_FLOAT_EQ(-2.0f, rect.min().y()); EXPECT_FLOAT_EQ(5.0f, rect.width()); EXPECT_FLOAT_EQ(10.0f, rect.height()); EXPECT_TRUE(rect.isValid()); } // Recti { Recti rect; EXPECT_EQ(0, rect.min().x()); EXPECT_EQ(0, rect.min().y()); EXPECT_EQ(0, rect.width()); EXPECT_EQ(0, rect.height()); EXPECT_FALSE(rect.isValid()); } { Recti rect(-1, -2, 5, 10); EXPECT_EQ(-1, rect.min().x()); EXPECT_EQ(-2, rect.min().y()); EXPECT_EQ(5, rect.width()); EXPECT_EQ(10, rect.height()); EXPECT_TRUE(rect.isValid()); } // Rectui { Rectui rect; EXPECT_EQ(0, rect.min().x()); EXPECT_EQ(0, rect.min().y()); EXPECT_EQ(0, rect.width()); EXPECT_EQ(0, rect.height()); EXPECT_FALSE(rect.isValid()); } { Rectui rect(1, 2, 5, 10); EXPECT_EQ(1, rect.min().x()); EXPECT_EQ(2, rect.min().y()); EXPECT_EQ(5, rect.width()); EXPECT_EQ(10, rect.height()); EXPECT_TRUE(rect.isValid()); } }