From 70e494e68a38ad380f2d7eb35207749296d710d8 Mon Sep 17 00:00:00 2001 From: Black Phoenix Date: Sun, 19 May 2013 03:42:41 +0300 Subject: [PATCH 1/5] Added silhouette outline rendering flag for drawing outlines --- src/geometry/glc_mesh.cpp | 47 +++++++++++++++++++++++++++++- src/geometry/glc_mesh.h | 3 ++ src/shading/glc_renderproperties.h | 3 +- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/geometry/glc_mesh.cpp b/src/geometry/glc_mesh.cpp index 0a65129b..5f4a7961 100644 --- a/src/geometry/glc_mesh.cpp +++ b/src/geometry/glc_mesh.cpp @@ -977,7 +977,11 @@ void GLC_Mesh::glDraw(const GLC_RenderProperties& renderProperties) activateVertexArray(); } - if (GLC_State::isInSelectionMode()) + if (renderProperties.renderingFlag() == glc::OutlineSilhouetteRenderFlag) { + GLC_Context::current()->glcEnableLighting(false); + outlineSilhouetteRenderLoop(renderProperties, vboIsUsed); + } + else if (GLC_State::isInSelectionMode()) { if (renderProperties.renderingMode() == glc::PrimitiveSelection) { @@ -1499,6 +1503,47 @@ void GLC_Mesh::primitiveSelectedRenderLoop(const GLC_RenderProperties& renderPro } } +// The outline silhouette render loop (draws in special colors for edge detection, passes extra data encoded in color) +void GLC_Mesh::outlineSilhouetteRenderLoop(const GLC_RenderProperties& renderProperties, bool vboIsUsed) +{ + const bool isTransparent= (renderProperties.renderingFlag() == glc::TransparentRenderFlag); + if ((!m_IsSelected || !isTransparent) || GLC_State::isInSelectionMode()) + { + LodPrimitiveGroups::iterator iGroup= m_PrimitiveGroups.value(m_CurrentLod)->begin(); + while (iGroup != m_PrimitiveGroups.value(m_CurrentLod)->constEnd()) + { + GLC_PrimitiveGroup* pCurrentGroup= iGroup.value(); + //GLC_Material* pCurrentMaterial= m_MaterialHash.value(pCurrentGroup->id()); + + // Encode silhouette information in RGBA color + int uid = pCurrentGroup->id() + 1024*id(); + GLfloat pSpecialColor[4]= { (1.0f/255.0f)*((uid % 256)), + (1.0f/255.0f)*((uid / 256) % 256), + (1.0f/255.0f)*((uid / 65536) % 256), + 0.0f}; + + glDisable(GL_TEXTURE_2D); + glColor4fv(pSpecialColor); + + // Choose the primitives to render + if (1) //m_IsSelected || GLC_State::isInSelectionMode()) // || materialIsrenderable + { + + if (vboIsUsed) + { + vboDrawPrimitivesOf(pCurrentGroup); + } + else + { + vertexArrayDrawPrimitivesOf(pCurrentGroup); + } + } + + ++iGroup; + } + } +} + void GLC_Mesh::copyIndex(int lodIndex, GLC_Mesh* pLodMesh, QHash& sourceToTargetIndexMap, QHash& tagetToSourceIndexMap, int& maxIndex, int targetLod) { //! The list of LOD material ID diff --git a/src/geometry/glc_mesh.h b/src/geometry/glc_mesh.h index 8a295a4d..0d585cb2 100644 --- a/src/geometry/glc_mesh.h +++ b/src/geometry/glc_mesh.h @@ -382,6 +382,9 @@ class GLC_LIB_EXPORT GLC_Mesh : public GLC_Geometry //! The primitive Selected render loop void primitiveSelectedRenderLoop(const GLC_RenderProperties&, bool); + //! The outline silhouette render loop (draws in special colors for edge detection, passes extra data encoded in color) + void outlineSilhouetteRenderLoop(const GLC_RenderProperties&, bool); + //! Copy index of this mesh from the given LOD into the given mesh void copyIndex(int lod, GLC_Mesh* pLodMesh, QHash& sourceToTargetIndexMap, QHash& tagetToSourceIndexMap, int& maxIndex, int targetLod); diff --git a/src/shading/glc_renderproperties.h b/src/shading/glc_renderproperties.h index a936a09b..8c9ffb67 100644 --- a/src/shading/glc_renderproperties.h +++ b/src/shading/glc_renderproperties.h @@ -55,7 +55,8 @@ namespace glc { ShadingFlag= 800, WireRenderFlag, - TransparentRenderFlag + TransparentRenderFlag, + OutlineSilhouetteRenderFlag }; }; ////////////////////////////////////////////////////////////////////// From 5fbcbe3386791fbc13191c8b0a3420a2cb899114 Mon Sep 17 00:00:00 2001 From: Black Phoenix Date: Sun, 19 May 2013 16:28:51 +0300 Subject: [PATCH 2/5] Back and front faces are now rendered with different color coding - outlines are drawn correctly for concave objects --- src/geometry/glc_mesh.cpp | 44 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/geometry/glc_mesh.cpp b/src/geometry/glc_mesh.cpp index 5f4a7961..b56234f3 100644 --- a/src/geometry/glc_mesh.cpp +++ b/src/geometry/glc_mesh.cpp @@ -1516,29 +1516,41 @@ void GLC_Mesh::outlineSilhouetteRenderLoop(const GLC_RenderProperties& renderPro //GLC_Material* pCurrentMaterial= m_MaterialHash.value(pCurrentGroup->id()); // Encode silhouette information in RGBA color - int uid = pCurrentGroup->id() + 1024*id(); - GLfloat pSpecialColor[4]= { (1.0f/255.0f)*((uid % 256)), - (1.0f/255.0f)*((uid / 256) % 256), - (1.0f/255.0f)*((uid / 65536) % 256), - 0.0f}; + GLubyte colorId[4]; + int uid = pCurrentGroup->id() + (id() << 16); glDisable(GL_TEXTURE_2D); - glColor4fv(pSpecialColor); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); - // Choose the primitives to render - if (1) //m_IsSelected || GLC_State::isInSelectionMode()) // || materialIsrenderable + // Draw front faces + glc::encodeRgbId(uid,colorId); + glColor4ubv(colorId); + glFrontFace(GL_CCW); + if (vboIsUsed) + { + vboDrawPrimitivesOf(pCurrentGroup); + } + else { + vertexArrayDrawPrimitivesOf(pCurrentGroup); + } - if (vboIsUsed) - { - vboDrawPrimitivesOf(pCurrentGroup); - } - else - { - vertexArrayDrawPrimitivesOf(pCurrentGroup); - } + // Draw back faces + glc::encodeRgbId((~uid) & 0xFFFFFF,colorId); + glColor4ubv(colorId); + glFrontFace(GL_CW); + if (vboIsUsed) + { + vboDrawPrimitivesOf(pCurrentGroup); + } + else + { + vertexArrayDrawPrimitivesOf(pCurrentGroup); } + glFrontFace(GL_CCW); + glDisable(GL_CULL_FACE); ++iGroup; } } From 8190b37fbf4302c860a24b7232c4bd6c8e35f157 Mon Sep 17 00:00:00 2001 From: Black Phoenix Date: Fri, 24 May 2013 22:36:03 +0300 Subject: [PATCH 3/5] Fixed small typo --- src/sceneGraph/glc_3dviewinstance.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sceneGraph/glc_3dviewinstance.h b/src/sceneGraph/glc_3dviewinstance.h index 35582d83..30273f6c 100644 --- a/src/sceneGraph/glc_3dviewinstance.h +++ b/src/sceneGraph/glc_3dviewinstance.h @@ -289,7 +289,7 @@ class GLC_LIB_EXPORT GLC_3DViewInstance : public GLC_Object ////////////////////////////////////////////////////////////////////// public: //! Display the instance - void render(glc::RenderFlag renderFlag= glc::ShadingFlag, bool useLoad= false, GLC_Viewport* pView= NULL); + void render(glc::RenderFlag renderFlag= glc::ShadingFlag, bool useLod= false, GLC_Viewport* pView= NULL); //! Display the instance in Body selection mode void renderForBodySelection(); From d53c40fbb223d88848ad128501dc6be7e10c688c Mon Sep 17 00:00:00 2001 From: Black Phoenix Date: Fri, 24 May 2013 23:49:16 +0300 Subject: [PATCH 4/5] Silhouette renderer now includes information about which objects are selected --- src/geometry/glc_mesh.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/geometry/glc_mesh.cpp b/src/geometry/glc_mesh.cpp index b56234f3..62ca1339 100644 --- a/src/geometry/glc_mesh.cpp +++ b/src/geometry/glc_mesh.cpp @@ -1507,7 +1507,8 @@ void GLC_Mesh::primitiveSelectedRenderLoop(const GLC_RenderProperties& renderPro void GLC_Mesh::outlineSilhouetteRenderLoop(const GLC_RenderProperties& renderProperties, bool vboIsUsed) { const bool isTransparent= (renderProperties.renderingFlag() == glc::TransparentRenderFlag); - if ((!m_IsSelected || !isTransparent) || GLC_State::isInSelectionMode()) + //if ((!m_IsSelected || !isTransparent) || GLC_State::isInSelectionMode()) + if ((!isTransparent) || GLC_State::isInSelectionMode()) { LodPrimitiveGroups::iterator iGroup= m_PrimitiveGroups.value(m_CurrentLod)->begin(); while (iGroup != m_PrimitiveGroups.value(m_CurrentLod)->constEnd()) @@ -1518,13 +1519,17 @@ void GLC_Mesh::outlineSilhouetteRenderLoop(const GLC_RenderProperties& renderPro // Encode silhouette information in RGBA color GLubyte colorId[4]; int uid = pCurrentGroup->id() + (id() << 16); + int uid_flags = 0; + if (renderProperties.isSelected()) { + uid_flags = uid_flags | 0x800000; //Selection flag + } glDisable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); // Draw front faces - glc::encodeRgbId(uid,colorId); + glc::encodeRgbId(((uid) & 0x7FFFFF) | uid_flags,colorId); glColor4ubv(colorId); glFrontFace(GL_CCW); if (vboIsUsed) @@ -1537,7 +1542,7 @@ void GLC_Mesh::outlineSilhouetteRenderLoop(const GLC_RenderProperties& renderPro } // Draw back faces - glc::encodeRgbId((~uid) & 0xFFFFFF,colorId); + glc::encodeRgbId(((~uid) & 0x7FFFFF) | uid_flags,colorId); glColor4ubv(colorId); glFrontFace(GL_CW); if (vboIsUsed) From f20f9a4e619740d2bf24f877d383e18b6e6e8ac5 Mon Sep 17 00:00:00 2001 From: Black Phoenix Date: Sat, 25 May 2013 13:28:31 +0300 Subject: [PATCH 5/5] There is an option to disable the selection material now (setUseSelectionMaterial) --- src/shading/glc_selectionmaterial.cpp | 8 ++++++++ src/shading/glc_selectionmaterial.h | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/shading/glc_selectionmaterial.cpp b/src/shading/glc_selectionmaterial.cpp index 22ccc77b..8c20f3a2 100644 --- a/src/shading/glc_selectionmaterial.cpp +++ b/src/shading/glc_selectionmaterial.cpp @@ -30,6 +30,7 @@ QHash GLC_SelectionMaterial::m_SelectionShaderHash; GLC_uint GLC_SelectionMaterial::m_SelectionMaterialId= 0; GLC_Material* GLC_SelectionMaterial::m_pMaterial= NULL; +bool GLC_SelectionMaterial::m_NoSelectionMaterial = false; GLC_SelectionMaterial::GLC_SelectionMaterial() { @@ -68,10 +69,17 @@ void GLC_SelectionMaterial::useDefautSelectionColor() } } +// Use selection material? +void GLC_SelectionMaterial::setUseSelectionMaterial(bool useSelectionMaterial) { + m_NoSelectionMaterial = !useSelectionMaterial; +} + // Execute OpenGL Material void GLC_SelectionMaterial::glExecute() { + if (m_NoSelectionMaterial) return; + if (NULL != m_pMaterial) { m_pMaterial->glExecute(); diff --git a/src/shading/glc_selectionmaterial.h b/src/shading/glc_selectionmaterial.h index ca334574..0f1f2dd8 100644 --- a/src/shading/glc_selectionmaterial.h +++ b/src/shading/glc_selectionmaterial.h @@ -56,6 +56,9 @@ class GLC_LIB_EXPORT GLC_SelectionMaterial //! Use the given material as selection material static void useMaterial(GLC_Material* pMaterial); + //! Use selection material? + static void setUseSelectionMaterial(bool useSelectionMaterial); + //! Use the default selection color /*! if a selection material is used, unused it*/ static void useDefautSelectionColor(); @@ -103,6 +106,9 @@ class GLC_LIB_EXPORT GLC_SelectionMaterial //! Material of this selection material static GLC_Material* m_pMaterial; + //! Don't use selection material + static bool m_NoSelectionMaterial; + }; #endif /*GLC_SELECTIONMATERIAL_H_*/