From 4cd9220763e18d69fae5dbf8075e29515bfb14d6 Mon Sep 17 00:00:00 2001 From: parax0 Date: Tue, 24 Nov 2015 08:42:01 -0700 Subject: [PATCH] Wireframe render functions for CModel and CStaticModel added --- Core/ERenderOptions.h | 1 + Resource/model/CModel.cpp | 24 +++++++++++++++++++++--- Resource/model/CModel.h | 1 + Resource/model/CStaticModel.cpp | 20 ++++++++++++++++++++ Resource/model/CStaticModel.h | 1 + 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Core/ERenderOptions.h b/Core/ERenderOptions.h index bf282a40..571e03e4 100644 --- a/Core/ERenderOptions.h +++ b/Core/ERenderOptions.h @@ -5,6 +5,7 @@ enum ERenderOptions { + eNoRenderOptions = 0x0, eDrawWorld = 0x1, eDrawWorldCollision = 0x2, eDrawObjects = 0x4, diff --git a/Resource/model/CModel.cpp b/Resource/model/CModel.cpp index 3d0d4f76..2be49bfb 100644 --- a/Resource/model/CModel.cpp +++ b/Resource/model/CModel.cpp @@ -1,4 +1,5 @@ #include "CModel.h" +#include #include #include @@ -97,11 +98,11 @@ void CModel::DrawSurface(ERenderOptions Options, u32 Surface, u32 MatSet) MatSet = mMaterialSets.size() - 1; // Bind material - SSurface *pSurf = mSurfaces[Surface]; - CMaterial *pMat = mMaterialSets[MatSet]->MaterialByIndex(pSurf->MaterialID); - if ((Options & eNoMaterialSetup) == 0) { + SSurface *pSurf = mSurfaces[Surface]; + CMaterial *pMat = mMaterialSets[MatSet]->MaterialByIndex(pSurf->MaterialID); + if ((!(Options & eEnableOccluders)) && (pMat->Options() & CMaterial::eOccluder)) return; @@ -121,6 +122,23 @@ void CModel::DrawSurface(ERenderOptions Options, u32 Surface, u32 MatSet) mVBO.Unbind(); } +void CModel::DrawWireframe(ERenderOptions Options, const CColor& WireColor) +{ + if (!mBuffered) BufferGL(); + + // Set up wireframe + CDrawUtil::UseColorShader(WireColor); + Options |= eNoMaterialSetup; + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + + // Draw surfaces + for (u32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) + DrawSurface(Options, iSurf, 0); + + // Cleanup + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +} + u32 CModel::GetMatSetCount() { return mMaterialSets.size(); diff --git a/Resource/model/CModel.h b/Resource/model/CModel.h index 5e97fe10..2c9f7192 100644 --- a/Resource/model/CModel.h +++ b/Resource/model/CModel.h @@ -27,6 +27,7 @@ public: void ClearGLBuffer(); void Draw(ERenderOptions Options, u32 MatSet); void DrawSurface(ERenderOptions Options, u32 Surface, u32 MatSet); + void DrawWireframe(ERenderOptions Options, const CColor& WireColor = CColor::skWhite); u32 GetMatSetCount(); u32 GetMatCount(); diff --git a/Resource/model/CStaticModel.cpp b/Resource/model/CStaticModel.cpp index ddfa828f..53a53f22 100644 --- a/Resource/model/CStaticModel.cpp +++ b/Resource/model/CStaticModel.cpp @@ -1,4 +1,5 @@ #include "CStaticModel.h" +#include #include #include @@ -104,6 +105,7 @@ void CStaticModel::Draw(ERenderOptions Options) // Draw IBOs mVBO.Bind(); + glLineWidth(1.f); for (u32 iIBO = 0; iIBO < mIBOs.size(); iIBO++) { @@ -122,6 +124,7 @@ void CStaticModel::DrawSurface(ERenderOptions Options, u32 Surface) if (!mBuffered) BufferGL(); mVBO.Bind(); + glLineWidth(1.f); if ((Options & eNoMaterialSetup) == 0) mpMaterial->SetCurrent(Options); for (u32 iIBO = 0; iIBO < mIBOs.size(); iIBO++) @@ -141,6 +144,23 @@ void CStaticModel::DrawSurface(ERenderOptions Options, u32 Surface) mVBO.Unbind(); } +void CStaticModel::DrawWireframe(ERenderOptions Options, const CColor& WireColor) +{ + if (!mBuffered) BufferGL(); + + // Set up wireframe + CDrawUtil::UseColorShader(WireColor); + Options |= eNoMaterialSetup; + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + + // Draw surfaces + for (u32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) + DrawSurface(Options, iSurf); + + // Cleanup + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +} + CMaterial* CStaticModel::GetMaterial() { return mpMaterial; diff --git a/Resource/model/CStaticModel.h b/Resource/model/CStaticModel.h index 930d608a..68105ec6 100644 --- a/Resource/model/CStaticModel.h +++ b/Resource/model/CStaticModel.h @@ -26,6 +26,7 @@ public: void ClearGLBuffer(); void Draw(ERenderOptions Options); void DrawSurface(ERenderOptions Options, u32 Surface); + void DrawWireframe(ERenderOptions Options, const CColor& WireColor); CMaterial* GetMaterial(); void SetMaterial(CMaterial *pMat);