From 9494d2276d6f1419873f2d1d01372e62452a9de2 Mon Sep 17 00:00:00 2001 From: parax0 Date: Fri, 27 Nov 2015 16:28:35 -0700 Subject: [PATCH] Bunch of backend rendering reshuffling; getting rid of DrawAsset, adding convenience functions, renaming some things --- Common/CRayCollisionTester.cpp | 12 ++++ Common/CRayCollisionTester.h | 2 + Core/CGraphics.cpp | 10 +++- Core/CGraphics.h | 3 +- Core/CRenderBucket.cpp | 5 +- Core/CRenderer.cpp | 8 +-- Core/CRenderer.h | 4 +- Core/ERenderCommand.h | 4 +- Core/IRenderable.h | 3 +- Core/SRenderablePtr.h | 2 +- Scene/CCollisionNode.cpp | 7 +-- Scene/CCollisionNode.h | 2 +- Scene/CLightNode.cpp | 4 +- Scene/CLightNode.h | 2 +- Scene/CModelNode.cpp | 60 +++---------------- Scene/CModelNode.h | 3 +- Scene/CSceneNode.cpp | 24 +++++++- Scene/CSceneNode.h | 1 + Scene/CScriptNode.cpp | 102 +++++++++----------------------- Scene/CScriptNode.h | 3 +- Scene/CStaticNode.cpp | 36 ++++------- Scene/CStaticNode.h | 3 +- Scene/script/CWaypointExtra.cpp | 6 +- Scene/script/CWaypointExtra.h | 2 +- UI/CGizmo.cpp | 18 +++--- UI/CGizmo.h | 2 +- UI/CWorldEditor.cpp | 6 +- 27 files changed, 134 insertions(+), 200 deletions(-) diff --git a/Common/CRayCollisionTester.cpp b/Common/CRayCollisionTester.cpp index 81f77740..bce25130 100644 --- a/Common/CRayCollisionTester.cpp +++ b/Common/CRayCollisionTester.cpp @@ -19,6 +19,18 @@ void CRayCollisionTester::AddNode(CSceneNode *pNode, u32 AssetIndex, float Dista Intersection.Distance = Distance; } +void CRayCollisionTester::AddNodeModel(CSceneNode *pNode, CBasicModel *pModel) +{ + // Check each of the model's surfaces and queue them for further testing if they hit + for (u32 iSurf = 0; iSurf < pModel->GetSurfaceCount(); iSurf++) + { + std::pair SurfResult = pModel->GetSurfaceAABox(iSurf).Transformed(pNode->Transform()).IntersectsRay(mRay); + + if (SurfResult.first) + AddNode(pNode, iSurf, SurfResult.second); + } +} + SRayIntersection CRayCollisionTester::TestNodes(const SViewInfo& ViewInfo) { // Sort nodes by distance from ray diff --git a/Common/CRayCollisionTester.h b/Common/CRayCollisionTester.h index dadb0da8..fe73bbd3 100644 --- a/Common/CRayCollisionTester.h +++ b/Common/CRayCollisionTester.h @@ -7,6 +7,7 @@ #include "SRayIntersection.h" #include "types.h" #include +#include #include @@ -22,6 +23,7 @@ public: ~CRayCollisionTester(); const CRay& Ray() const; void AddNode(CSceneNode *pNode, u32 AssetIndex, float Distance); + void AddNodeModel(CSceneNode *pNode, CBasicModel *pModel); SRayIntersection TestNodes(const SViewInfo& ViewInfo); }; diff --git a/Core/CGraphics.cpp b/Core/CGraphics.cpp index 8141b162..244e7c69 100644 --- a/Core/CGraphics.cpp +++ b/Core/CGraphics.cpp @@ -45,7 +45,7 @@ void CGraphics::Initialize() mpPixelBlockBuffer = new CUniformBuffer(sizeof(sPixelBlock)); mpLightBlockBuffer = new CUniformBuffer(sizeof(sLightBlock)); - sLightMode = WorldLighting; + sLightMode = eWorldLighting; sNumLights = 0; sWorldLightMultiplier = 1.f; @@ -162,6 +162,14 @@ void CGraphics::SetDefaultLighting() UpdateVertexBlock(); } +void CGraphics::SetupAmbientColor() +{ + if (sLightMode == eWorldLighting) + sVertexBlock.COLOR0_Amb = sAreaAmbientColor.ToVector4f() * sWorldLightMultiplier; + else + sVertexBlock.COLOR0_Amb = skDefaultAmbientColor.ToVector4f(); +} + void CGraphics::SetIdentityMVP() { sMVPBlock.ModelMatrix = CMatrix4f::skIdentity; diff --git a/Core/CGraphics.h b/Core/CGraphics.h index f1059d37..14023322 100644 --- a/Core/CGraphics.h +++ b/Core/CGraphics.h @@ -68,7 +68,7 @@ public: static SLightBlock sLightBlock; // Lighting-related - enum ELightingMode { NoLighting, BasicLighting, WorldLighting }; + enum ELightingMode { eNoLighting, eBasicLighting, eWorldLighting }; static ELightingMode sLightMode; static u32 sNumLights; static const CColor skDefaultAmbientColor; @@ -92,6 +92,7 @@ public: static void ReleaseContext(u32 Index); static void SetActiveContext(u32 Index); static void SetDefaultLighting(); + static void SetupAmbientColor(); static void SetIdentityMVP(); }; diff --git a/Core/CRenderBucket.cpp b/Core/CRenderBucket.cpp index 45dda2e1..170306ed 100644 --- a/Core/CRenderBucket.cpp +++ b/Core/CRenderBucket.cpp @@ -79,10 +79,7 @@ void CRenderBucket::Draw(const SViewInfo& ViewInfo) for (u32 n = 0; n < mSize; n++) { if (mRenderables[n].Command == eDrawMesh) - mRenderables[n].pRenderable->Draw(Options, ViewInfo); - - else if (mRenderables[n].Command == eDrawAsset) - mRenderables[n].pRenderable->DrawAsset(Options, mRenderables[n].Asset, ViewInfo); + mRenderables[n].pRenderable->Draw(Options, mRenderables[n].ComponentIndex, ViewInfo); else if (mRenderables[n].Command == eDrawSelection) mRenderables[n].pRenderable->DrawSelection(); diff --git a/Core/CRenderer.cpp b/Core/CRenderer.cpp index 7445a4c4..371cdd88 100644 --- a/Core/CRenderer.cpp +++ b/Core/CRenderer.cpp @@ -311,21 +311,21 @@ void CRenderer::RenderSky(CModel *pSkyboxModel, const SViewInfo& ViewInfo) pSkyboxModel->Draw(mOptions, 0); } -void CRenderer::AddOpaqueMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command) +void CRenderer::AddOpaqueMesh(IRenderable *pRenderable, int AssetID, CAABox& AABox, ERenderCommand Command) { SRenderablePtr ptr; ptr.pRenderable = pRenderable; - ptr.Asset = AssetID; + ptr.ComponentIndex = AssetID; ptr.AABox = AABox; ptr.Command = Command; mOpaqueBucket.Add(ptr); } -void CRenderer::AddTransparentMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command) +void CRenderer::AddTransparentMesh(IRenderable *pRenderable, int AssetID, CAABox& AABox, ERenderCommand Command) { SRenderablePtr ptr; ptr.pRenderable = pRenderable; - ptr.Asset = AssetID; + ptr.ComponentIndex = AssetID; ptr.AABox = AABox; ptr.Command = Command; mTransparentBucket.Add(ptr); diff --git a/Core/CRenderer.h b/Core/CRenderer.h index 940a57ea..e2ae9505 100644 --- a/Core/CRenderer.h +++ b/Core/CRenderer.h @@ -75,8 +75,8 @@ public: void RenderBuckets(const SViewInfo& ViewInfo); void RenderBloom(); void RenderSky(CModel *pSkyboxModel, const SViewInfo& ViewInfo); - void AddOpaqueMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command); - void AddTransparentMesh(IRenderable *pRenderable, u32 AssetID, CAABox& AABox, ERenderCommand Command); + void AddOpaqueMesh(IRenderable *pRenderable, int AssetID, CAABox& AABox, ERenderCommand Command); + void AddTransparentMesh(IRenderable *pRenderable, int AssetID, CAABox& AABox, ERenderCommand Command); void BeginFrame(); void EndFrame(); void ClearDepthBuffer(); diff --git a/Core/ERenderCommand.h b/Core/ERenderCommand.h index ffd82b2a..287de1cf 100644 --- a/Core/ERenderCommand.h +++ b/Core/ERenderCommand.h @@ -4,9 +4,7 @@ enum ERenderCommand { eDrawMesh, - eDrawAsset, - eDrawSelection, - eDrawExtras + eDrawSelection }; #endif // ERENDERCOMMAND diff --git a/Core/IRenderable.h b/Core/IRenderable.h index 729a76c7..8f7161f2 100644 --- a/Core/IRenderable.h +++ b/Core/IRenderable.h @@ -13,8 +13,7 @@ public: IRenderable() {} virtual ~IRenderable() {} virtual void AddToRenderer(CRenderer* pRenderer, const SViewInfo& ViewInfo) = 0; - virtual void Draw(ERenderOptions /*options*/, const SViewInfo& /*ViewInfo*/) {} - virtual void DrawAsset(ERenderOptions /*options*/, u32 /*asset*/, const SViewInfo& /*ViewInfo*/) {} + virtual void Draw(ERenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& /*ViewInfo*/) {} virtual void DrawSelection() {} }; diff --git a/Core/SRenderablePtr.h b/Core/SRenderablePtr.h index 1a220216..f471c009 100644 --- a/Core/SRenderablePtr.h +++ b/Core/SRenderablePtr.h @@ -10,7 +10,7 @@ struct SRenderablePtr { IRenderable *pRenderable; - u32 Asset; + u32 ComponentIndex; CAABox AABox; ERenderCommand Command; }; diff --git a/Scene/CCollisionNode.cpp b/Scene/CCollisionNode.cpp index 03d2da9d..0065a1cf 100644 --- a/Scene/CCollisionNode.cpp +++ b/Scene/CCollisionNode.cpp @@ -21,15 +21,14 @@ void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewIn if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; if (ViewInfo.GameMode) return; - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh); + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); if (mSelected) - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection); + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } -void CCollisionNode::Draw(ERenderOptions, const SViewInfo& ViewInfo) +void CCollisionNode::Draw(ERenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& ViewInfo) { - // Not using parameter 1 (ERenderOptions - Options) if (!mpCollision) return; LoadModelMatrix(); diff --git a/Scene/CCollisionNode.h b/Scene/CCollisionNode.h index 0b3853f9..de781bec 100644 --- a/Scene/CCollisionNode.h +++ b/Scene/CCollisionNode.h @@ -13,7 +13,7 @@ public: CCollisionNode(CSceneManager *pScene, CSceneNode *pParent = 0, CCollisionMeshGroup *pCollision = 0); ENodeType NodeType(); void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(ERenderOptions Options, const SViewInfo& ViewInfo); + void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); void SetCollision(CCollisionMeshGroup *pCollision); }; diff --git a/Scene/CLightNode.cpp b/Scene/CLightNode.cpp index 8bc7717c..ef9abeba 100644 --- a/Scene/CLightNode.cpp +++ b/Scene/CLightNode.cpp @@ -30,10 +30,10 @@ void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; if (ViewInfo.GameMode) return; - pRenderer->AddOpaqueMesh(this, 0, CAABox(mPosition + 0.5f, mPosition - 0.5f), eDrawMesh); + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); } -void CLightNode::Draw(ERenderOptions /*Options*/, const SViewInfo& ViewInfo) +void CLightNode::Draw(ERenderOptions /*Options*/, int /*ComponentIndex*/, const SViewInfo& ViewInfo) { CDrawUtil::DrawLightBillboard(mpLight->GetType(), mpLight->GetColor(), mPosition, BillboardScale(), TintColor(ViewInfo)); diff --git a/Scene/CLightNode.h b/Scene/CLightNode.h index cace7961..e259640f 100644 --- a/Scene/CLightNode.h +++ b/Scene/CLightNode.h @@ -11,7 +11,7 @@ public: CLightNode(CSceneManager *pScene, CSceneNode *pParent = 0, CLight *Light = 0); ENodeType NodeType(); void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(ERenderOptions Options, const SViewInfo& ViewInfo); + void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); void RayAABoxIntersectTest(CRayCollisionTester& Tester); SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); CLight* Light(); diff --git a/Scene/CModelNode.cpp b/Scene/CModelNode.cpp index 8ac549f3..5f39ef51 100644 --- a/Scene/CModelNode.cpp +++ b/Scene/CModelNode.cpp @@ -24,29 +24,15 @@ void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) if (ViewInfo.GameMode) return; if (!mpModel->HasTransparency(mActiveMatSet)) - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh); - + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); else - { - u32 SurfaceCount = mpModel->GetSurfaceCount(); - - for (u32 iSurf = 0; iSurf < SurfaceCount; iSurf++) - { - if (ViewInfo.ViewFrustum.BoxInFrustum(mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()))) - { - if (!mpModel->IsSurfaceTransparent(iSurf, mActiveMatSet)) - pRenderer->AddOpaqueMesh(this, iSurf, mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()), eDrawAsset); - else - pRenderer->AddTransparentMesh(this, iSurf, mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()), eDrawAsset); - } - } - } + AddSurfacesToRenderer(pRenderer, mpModel, mActiveMatSet, ViewInfo); if (mSelected) - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection); + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } -void CModelNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo) +void CModelNode::Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo) { if (!mpModel) return; if (mForceAlphaOn) Options = (ERenderOptions) (Options & ~eNoAlpha); @@ -67,32 +53,10 @@ void CModelNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo) CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f(); LoadModelMatrix(); - mpModel->Draw(Options, mActiveMatSet); -} - -void CModelNode::DrawAsset(ERenderOptions Options, u32 Asset, const SViewInfo& ViewInfo) -{ - if (!mpModel) return; - if (mForceAlphaOn) Options = (ERenderOptions) (Options & ~eNoAlpha); - - if (mLightingEnabled) - { - CGraphics::SetDefaultLighting(); - CGraphics::UpdateLightBlock(); - CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::skDefaultAmbientColor.ToVector4f(); - } + if (ComponentIndex < 0) + mpModel->Draw(Options, mActiveMatSet); else - { - CGraphics::sNumLights = 0; - CGraphics::sVertexBlock.COLOR0_Amb = CColor::skBlack.ToVector4f(); - } - - CGraphics::sPixelBlock.TevColor = CVector4f(1,1,1,1); - CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f(); - CGraphics::UpdatePixelBlock(); - LoadModelMatrix(); - - mpModel->DrawSurface(Options, Asset, mActiveMatSet); + mpModel->DrawSurface(Options, ComponentIndex, mActiveMatSet); } void CModelNode::DrawSelection() @@ -110,15 +74,7 @@ void CModelNode::RayAABoxIntersectTest(CRayCollisionTester &Tester) std::pair BoxResult = AABox().IntersectsRay(Ray); if (BoxResult.first) - { - for (u32 iSurf = 0; iSurf < mpModel->GetSurfaceCount(); iSurf++) - { - std::pair SurfResult = mpModel->GetSurfaceAABox(iSurf).IntersectsRay(Ray); - - if (SurfResult.first) - Tester.AddNode(this, iSurf, SurfResult.second); - } - } + Tester.AddNodeModel(this, mpModel); } SRayIntersection CModelNode::RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo) diff --git a/Scene/CModelNode.h b/Scene/CModelNode.h index ad571e35..ab29978d 100644 --- a/Scene/CModelNode.h +++ b/Scene/CModelNode.h @@ -17,8 +17,7 @@ public: virtual ENodeType NodeType(); virtual void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - virtual void Draw(ERenderOptions Options, const SViewInfo& ViewInfo); - virtual void DrawAsset(ERenderOptions Options, u32 asset, const SViewInfo& ViewInfo); + virtual void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); virtual void DrawSelection(); virtual void RayAABoxIntersectTest(CRayCollisionTester &Tester); virtual SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); diff --git a/Scene/CSceneNode.cpp b/Scene/CSceneNode.cpp index e3bbcbb4..6caad3f3 100644 --- a/Scene/CSceneNode.cpp +++ b/Scene/CSceneNode.cpp @@ -184,7 +184,7 @@ void CSceneNode::LoadLights(const SViewInfo& ViewInfo) { CGraphics::sNumLights = 0; - if (CGraphics::sLightMode == CGraphics::WorldLighting || ViewInfo.GameMode) + if (CGraphics::sLightMode == CGraphics::eWorldLighting || ViewInfo.GameMode) { // World lighting: world ambient color, node dynamic lights CGraphics::sVertexBlock.COLOR0_Amb = mAmbientColor.ToVector4f(); @@ -193,14 +193,14 @@ void CSceneNode::LoadLights(const SViewInfo& ViewInfo) mLights[iLight]->Load(); } - else if (CGraphics::sLightMode == CGraphics::BasicLighting) + else if (CGraphics::sLightMode == CGraphics::eBasicLighting) { // Basic lighting: default ambient color, default dynamic lights CGraphics::SetDefaultLighting(); CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::skDefaultAmbientColor.ToVector4f(); } - else if (CGraphics::sLightMode == CGraphics::NoLighting) + else if (CGraphics::sLightMode == CGraphics::eNoLighting) { // No lighting: default ambient color, no dynamic lights CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::skDefaultAmbientColor.ToVector4f(); @@ -214,6 +214,24 @@ void CSceneNode::DrawBoundingBox() CDrawUtil::DrawWireCube(AABox(), CColor::skWhite); } +void CSceneNode::AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 MatSet, const SViewInfo& rkViewInfo) +{ + u32 SurfaceCount = pModel->GetSurfaceCount(); + + for (u32 iSurf = 0; iSurf < SurfaceCount; iSurf++) + { + CAABox TransformedBox = pModel->GetSurfaceAABox(iSurf).Transformed(Transform()); + + if (rkViewInfo.ViewFrustum.BoxInFrustum(TransformedBox)) + { + if (!pModel->IsSurfaceTransparent(iSurf, MatSet)) + pRenderer->AddOpaqueMesh(this, (int) iSurf, TransformedBox, eDrawMesh); + else + pRenderer->AddTransparentMesh(this, (int) iSurf, TransformedBox, eDrawMesh); + } + } +} + // ************ TRANSFORM ************ void CSceneNode::Translate(const CVector3f& translation, ETransformSpace transformSpace) { diff --git a/Scene/CSceneNode.h b/Scene/CSceneNode.h index 8a86e830..42aca57b 100644 --- a/Scene/CSceneNode.h +++ b/Scene/CSceneNode.h @@ -70,6 +70,7 @@ public: void BuildLightList(CGameArea *pArea); void LoadLights(const SViewInfo& ViewInfo); void DrawBoundingBox(); + void AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 MatSet, const SViewInfo& ViewInfo); // Transform void Translate(const CVector3f& translation, ETransformSpace transformSpace); diff --git a/Scene/CScriptNode.cpp b/Scene/CScriptNode.cpp index c9568c57..85bfd328 100644 --- a/Scene/CScriptNode.cpp +++ b/Scene/CScriptNode.cpp @@ -134,33 +134,15 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) if (ViewInfo.ViewFrustum.BoxInFrustum(AABox())) { if (!mpActiveModel) - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh); + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); else { - if (!mpActiveModel->IsBuffered()) - mpActiveModel->BufferGL(); - if (!mpActiveModel->HasTransparency(0)) - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh); - + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); else - { - u32 SubmeshCount = mpActiveModel->GetSurfaceCount(); - - for (u32 s = 0; s < SubmeshCount; s++) - { - if (ViewInfo.ViewFrustum.BoxInFrustum(mpActiveModel->GetSurfaceAABox(s).Transformed(Transform()))) - { - if (!mpActiveModel->IsSurfaceTransparent(s, 0)) - pRenderer->AddOpaqueMesh(this, s, mpActiveModel->GetSurfaceAABox(s).Transformed(Transform()), eDrawAsset); - else - pRenderer->AddTransparentMesh(this, s, mpActiveModel->GetSurfaceAABox(s).Transformed(Transform()), eDrawAsset); - } - } - } + AddSurfacesToRenderer(pRenderer, mpActiveModel, 0, ViewInfo); } - } } } @@ -170,28 +152,46 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) // Script nodes always draw their selections regardless of frustum planes // in order to ensure that script connection lines don't get improperly culled. if (ShouldDraw) - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection); + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); if (mHasVolumePreview && (!mpExtra || mpExtra->ShouldDrawVolume())) mpVolumePreviewNode->AddToRenderer(pRenderer, ViewInfo); } } -void CScriptNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo) +void CScriptNode::Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo) { if (!mpInstance) return; // Draw model - if (mpActiveModel) + if (mpActiveModel || !mpBillboard) { + CGraphics::SetupAmbientColor(); + CGraphics::UpdateVertexBlock(); LoadModelMatrix(); LoadLights(ViewInfo); - if (mpExtra) CGraphics::sPixelBlock.TevColor = mpExtra->TevColor().ToVector4f(); - else CGraphics::sPixelBlock.TevColor = CColor::skWhite.ToVector4f(); + // Draw model if possible! + if (mpActiveModel) + { + if (mpExtra) CGraphics::sPixelBlock.TevColor = mpExtra->TevColor().ToVector4f(); + else CGraphics::sPixelBlock.TevColor = CColor::skWhite.ToVector4f(); + CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f(); + CGraphics::UpdatePixelBlock(); - CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f(); - mpActiveModel->Draw(Options, 0); + if (ComponentIndex < 0) + mpActiveModel->Draw(Options, 0); + else + mpActiveModel->DrawSurface(Options, ComponentIndex, 0); + } + + // If no model or billboard, default to drawing a purple box + else + { + glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ZERO); + glDepthMask(GL_TRUE); + CDrawUtil::DrawShadedCube(CColor::skTransparentPurple * TintColor(ViewInfo)); + } } // Draw billboard @@ -199,41 +199,6 @@ void CScriptNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo) { CDrawUtil::DrawBillboard(mpBillboard, mPosition, BillboardScale(), TintColor(ViewInfo)); } - - // If no model or billboard, default to drawing a purple box - else - { - glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ZERO); - glDepthMask(GL_TRUE); - - LoadModelMatrix(); - LoadLights(ViewInfo); - CGraphics::UpdateVertexBlock(); - CGraphics::UpdateLightBlock(); - CDrawUtil::DrawShadedCube(CColor::skTransparentPurple * TintColor(ViewInfo)); - return; - } -} - -void CScriptNode::DrawAsset(ERenderOptions Options, u32 Asset, const SViewInfo& ViewInfo) -{ - if (!mpInstance) return; - if (!mpActiveModel) return; - - if (CGraphics::sLightMode == CGraphics::WorldLighting) - CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::sAreaAmbientColor.ToVector4f() * CGraphics::sWorldLightMultiplier; - else - CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::skDefaultAmbientColor.ToVector4f(); - - LoadModelMatrix(); - LoadLights(ViewInfo); - - if (mpExtra) CGraphics::sPixelBlock.TevColor = mpExtra->TevColor().ToVector4f(); - else CGraphics::sPixelBlock.TevColor = CColor::skWhite.ToVector4f(); - - CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f(); - - mpActiveModel->DrawSurface(Options, Asset, 0); } void CScriptNode::DrawSelection() @@ -293,16 +258,7 @@ void CScriptNode::RayAABoxIntersectTest(CRayCollisionTester &Tester) if (BoxResult.first) { - if (mpActiveModel) - { - for (u32 iSurf = 0; iSurf < mpActiveModel->GetSurfaceCount(); iSurf++) - { - std::pair SurfResult = mpActiveModel->GetSurfaceAABox(iSurf).Transformed(Transform()).IntersectsRay(Ray); - - if (SurfResult.first) - Tester.AddNode(this, iSurf, SurfResult.second); - } - } + if (mpActiveModel) Tester.AddNodeModel(this, mpActiveModel); else Tester.AddNode(this, 0, BoxResult.second); } } diff --git a/Scene/CScriptNode.h b/Scene/CScriptNode.h index 3c2bbd3d..b4b0b7fd 100644 --- a/Scene/CScriptNode.h +++ b/Scene/CScriptNode.h @@ -29,8 +29,7 @@ public: ENodeType NodeType(); TString PrefixedName() const; void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(ERenderOptions Options, const SViewInfo& ViewInfo); - void DrawAsset(ERenderOptions Options, u32 Asset, const SViewInfo& ViewInfo); + void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); void DrawSelection(); void RayAABoxIntersectTest(CRayCollisionTester &Tester); SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); diff --git a/Scene/CStaticNode.cpp b/Scene/CStaticNode.cpp index afc988e7..a61672d5 100644 --- a/Scene/CStaticNode.cpp +++ b/Scene/CStaticNode.cpp @@ -26,23 +26,25 @@ void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; if (!mpModel->IsTransparent()) - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh); + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawMesh); else { - u32 sm_count = mpModel->GetSurfaceCount(); - for (u32 s = 0; s < sm_count; s++) + u32 NumSurfaces = mpModel->GetSurfaceCount(); + for (u32 iSurf = 0; iSurf < NumSurfaces; iSurf++) { - if (ViewInfo.ViewFrustum.BoxInFrustum(mpModel->GetSurfaceAABox(s).Transformed(Transform()))) - pRenderer->AddTransparentMesh(this, s, mpModel->GetSurfaceAABox(s).Transformed(Transform()), eDrawAsset); + CAABox TransformedBox = mpModel->GetSurfaceAABox(iSurf).Transformed(Transform()); + + if (ViewInfo.ViewFrustum.BoxInFrustum(TransformedBox)) + pRenderer->AddTransparentMesh(this, iSurf, TransformedBox, eDrawMesh); } } if (mSelected && !ViewInfo.GameMode) - pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection); + pRenderer->AddOpaqueMesh(this, -1, AABox(), eDrawSelection); } -void CStaticNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo) +void CStaticNode::Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo) { if (!mpModel) return; @@ -54,22 +56,10 @@ void CStaticNode::Draw(ERenderOptions Options, const SViewInfo& ViewInfo) CGraphics::UpdateLightBlock(); LoadModelMatrix(); - mpModel->Draw(Options); -} - -void CStaticNode::DrawAsset(ERenderOptions Options, u32 Asset, const SViewInfo& ViewInfo) -{ - if (!mpModel) return; - - CGraphics::sVertexBlock.COLOR0_Amb = CVector4f(0,0,0,1); - CGraphics::sPixelBlock.TevColor = CVector4f(1,1,1,1); - CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo).ToVector4f(); - CGraphics::sNumLights = 0; - CGraphics::UpdateLightBlock(); - LoadModelMatrix(); - - mpModel->DrawSurface(Options, Asset); - //CDrawUtil::DrawWireCube(mpModel->GetSurfaceAABox(Asset), CColor::skWhite); + if (ComponentIndex < 0) + mpModel->Draw(Options); + else + mpModel->DrawSurface(Options, ComponentIndex); } void CStaticNode::DrawSelection() diff --git a/Scene/CStaticNode.h b/Scene/CStaticNode.h index b5dd4365..32609ca2 100644 --- a/Scene/CStaticNode.h +++ b/Scene/CStaticNode.h @@ -12,8 +12,7 @@ public: CStaticNode(CSceneManager *pScene, CSceneNode *pParent = 0, CStaticModel *pModel = 0); ENodeType NodeType(); void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void Draw(ERenderOptions Options, const SViewInfo& ViewInfo); - void DrawAsset(ERenderOptions Options, u32 asset, const SViewInfo& ViewInfo); + void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); void DrawSelection(); void RayAABoxIntersectTest(CRayCollisionTester &Tester); SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); diff --git a/Scene/script/CWaypointExtra.cpp b/Scene/script/CWaypointExtra.cpp index 4590b4be..3092ee5b 100644 --- a/Scene/script/CWaypointExtra.cpp +++ b/Scene/script/CWaypointExtra.cpp @@ -89,12 +89,12 @@ void CWaypointExtra::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewIn CScriptNode *pNode = mLinks[iLink].pWaypoint; if (pNode->IsVisible() && !pNode->IsSelected() && ViewInfo.ViewFrustum.BoxInFrustum(mLinks[iLink].LineAABB)) - pRenderer->AddOpaqueMesh(this, iLink, mLinks[iLink].LineAABB, eDrawAsset); + pRenderer->AddOpaqueMesh(this, iLink, mLinks[iLink].LineAABB, eDrawMesh); } } } -void CWaypointExtra::DrawAsset(ERenderOptions /*Options*/, u32 AssetID, const SViewInfo& /*ViewInfo*/) +void CWaypointExtra::Draw(ERenderOptions /*Options*/, int ComponentIndex, const SViewInfo& /*ViewInfo*/) { glBlendFunc(GL_ONE, GL_ZERO); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); @@ -102,5 +102,5 @@ void CWaypointExtra::DrawAsset(ERenderOptions /*Options*/, u32 AssetID, const SV CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity; CGraphics::UpdateMVPBlock(); - CDrawUtil::DrawLine(mpParent->AABox().Center(), mLinks[AssetID].pWaypoint->AABox().Center(), mColor); + CDrawUtil::DrawLine(mpParent->AABox().Center(), mLinks[ComponentIndex].pWaypoint->AABox().Center(), mColor); } diff --git a/Scene/script/CWaypointExtra.h b/Scene/script/CWaypointExtra.h index be11a1d0..7a6bc517 100644 --- a/Scene/script/CWaypointExtra.h +++ b/Scene/script/CWaypointExtra.h @@ -24,7 +24,7 @@ public: void LinksModified(); void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void DrawAsset(ERenderOptions Options, u32 AssetID, const SViewInfo& ViewInfo); + void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); }; #endif // CWAYPOINTEXTRA_H diff --git a/UI/CGizmo.cpp b/UI/CGizmo.cpp index 2f380606..a0f28c52 100644 --- a/UI/CGizmo.cpp +++ b/UI/CGizmo.cpp @@ -61,24 +61,24 @@ void CGizmo::AddToRenderer(CRenderer *pRenderer, const SViewInfo&) // Add to renderer... if (pModel->HasTransparency(setID)) - pRenderer->AddTransparentMesh(this, iPart, pModel->AABox().Transformed(mTransform), eDrawAsset); + pRenderer->AddTransparentMesh(this, iPart, pModel->AABox().Transformed(mTransform), eDrawMesh); else - pRenderer->AddOpaqueMesh(this, iPart, pModel->AABox().Transformed(mTransform), eDrawAsset); + pRenderer->AddOpaqueMesh(this, iPart, pModel->AABox().Transformed(mTransform), eDrawMesh); pPart++; } } -void CGizmo::DrawAsset(ERenderOptions /*options*/, u32 asset, const SViewInfo& /*ViewInfo*/) +void CGizmo::Draw(ERenderOptions /*Options*/, int ComponentIndex, const SViewInfo& /*ViewInfo*/) { // Determine which SModelPart array to use - if (asset >= mNumCurrentParts) return; + if (ComponentIndex >= (int) mNumCurrentParts) return; SModelPart *pPart = mpCurrentParts; // Set model matrix - if (pPart[asset].isBillboard) + if (pPart[ComponentIndex].isBillboard) CGraphics::sMVPBlock.ModelMatrix = mBillboardTransform.ToMatrix4f(); - else if ((mMode == eScale) && ((mSelectedAxes & pPart[asset].modelAxes) != 0)) + else if ((mMode == eScale) && ((mSelectedAxes & pPart[ComponentIndex].modelAxes) != 0)) CGraphics::sMVPBlock.ModelMatrix = mScaledTransform.ToMatrix4f(); else CGraphics::sMVPBlock.ModelMatrix = mTransform.ToMatrix4f(); @@ -90,12 +90,12 @@ void CGizmo::DrawAsset(ERenderOptions /*options*/, u32 asset, const SViewInfo& / CGraphics::UpdatePixelBlock(); // Choose material set - EGizmoAxes partAxes = pPart[asset].modelAxes; - bool isHighlighted = (partAxes != eNone) && ((mSelectedAxes & partAxes) == pPart[asset].modelAxes); + EGizmoAxes partAxes = pPart[ComponentIndex].modelAxes; + bool isHighlighted = (partAxes != eNone) && ((mSelectedAxes & partAxes) == pPart[ComponentIndex].modelAxes); u32 setID = (isHighlighted ? 1 : 0); // Draw model - pPart[asset].pModel->Draw((ERenderOptions) 0, setID); + pPart[ComponentIndex].pModel->Draw((ERenderOptions) 0, setID); } void CGizmo::IncrementSize() diff --git a/UI/CGizmo.h b/UI/CGizmo.h index e23eacbe..63b3903d 100644 --- a/UI/CGizmo.h +++ b/UI/CGizmo.h @@ -125,7 +125,7 @@ public: ~CGizmo(); void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo); - void DrawAsset(ERenderOptions options, u32 asset, const SViewInfo& ViewInfo); + void Draw(ERenderOptions Options, int ComponentIndex, const SViewInfo& ViewInfo); void IncrementSize(); void DecrementSize(); diff --git a/UI/CWorldEditor.cpp b/UI/CWorldEditor.cpp index 32781bef..1eb7babb 100644 --- a/UI/CWorldEditor.cpp +++ b/UI/CWorldEditor.cpp @@ -377,7 +377,7 @@ void CWorldEditor::on_ActionDrawSky_triggered() void CWorldEditor::on_ActionNoLighting_triggered() { - CGraphics::sLightMode = CGraphics::NoLighting; + CGraphics::sLightMode = CGraphics::eNoLighting; ui->ActionNoLighting->setChecked(true); ui->ActionBasicLighting->setChecked(false); ui->ActionWorldLighting->setChecked(false); @@ -385,7 +385,7 @@ void CWorldEditor::on_ActionNoLighting_triggered() void CWorldEditor::on_ActionBasicLighting_triggered() { - CGraphics::sLightMode = CGraphics::BasicLighting; + CGraphics::sLightMode = CGraphics::eBasicLighting; ui->ActionNoLighting->setChecked(false); ui->ActionBasicLighting->setChecked(true); ui->ActionWorldLighting->setChecked(false); @@ -393,7 +393,7 @@ void CWorldEditor::on_ActionBasicLighting_triggered() void CWorldEditor::on_ActionWorldLighting_triggered() { - CGraphics::sLightMode = CGraphics::WorldLighting; + CGraphics::sLightMode = CGraphics::eWorldLighting; ui->ActionNoLighting->setChecked(false); ui->ActionBasicLighting->setChecked(false); ui->ActionWorldLighting->setChecked(true);