From d520c4477d3b7c5a71e9cc0dd22578b442d17300 Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 12 Jun 2016 16:19:34 +0800 Subject: [PATCH] Design a way to render kart and driver differently --- lib/irrlicht/include/EMaterialTypes.h | 2 +- lib/irrlicht/include/IMesh.h | 34 ++++++++++++++++++++------- lib/irrlicht/include/IMeshBuffer.h | 12 ++++++++++ src/graphics/irr_driver.cpp | 5 ++-- src/graphics/irr_driver.hpp | 3 ++- src/graphics/stk_animated_mesh.cpp | 2 +- src/graphics/stk_mesh_scene_node.cpp | 2 +- src/karts/kart_model.cpp | 8 +++---- 8 files changed, 49 insertions(+), 19 deletions(-) diff --git a/lib/irrlicht/include/EMaterialTypes.h b/lib/irrlicht/include/EMaterialTypes.h index a6b153738..058a5ec2d 100644 --- a/lib/irrlicht/include/EMaterialTypes.h +++ b/lib/irrlicht/include/EMaterialTypes.h @@ -10,7 +10,7 @@ namespace irr namespace video { - //! Flag for mesh (mainly karts in STK) to use specific render type + //! Flag for mesh buffer (mainly karts in STK) to use specific render type enum E_RENDER_TYPE { ERT_DEFAULT = 0, diff --git a/lib/irrlicht/include/IMesh.h b/lib/irrlicht/include/IMesh.h index 33c5e2ceb..72ebc75b8 100644 --- a/lib/irrlicht/include/IMesh.h +++ b/lib/irrlicht/include/IMesh.h @@ -5,15 +5,18 @@ #ifndef __I_MESH_H_INCLUDED__ #define __I_MESH_H_INCLUDED__ +#include "IMeshBuffer.h" #include "IReferenceCounted.h" #include "SMaterial.h" #include "EHardwareBufferFlags.h" +#include +#include + namespace irr { namespace scene { - class IMeshBuffer; //! Class which holds the geometry of an object. /** An IMesh is nothing more than a collection of some mesh buffers @@ -23,7 +26,7 @@ namespace scene class IMesh : public virtual IReferenceCounted { public: - IMesh() : m_rt(video::ERT_DEFAULT) {} + IMesh() : m_custom_render_type(false) {} virtual ~IMesh() {} @@ -70,14 +73,29 @@ namespace scene on the GPU in the next render cycle. */ virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) = 0; - //! Set the mesh to use a specific render type (mainly karts in STK) - /** \param t New render type for the mesh. */ - void setRenderType(video::E_RENDER_TYPE t) { m_rt = t; } + //! True if this mesh has specific render type (mainly karts in STK) + bool hasCustomRenderType() const { return m_custom_render_type; } - //! Get the specific render type for the mesh (mainly karts in STK) - video::E_RENDER_TYPE getRenderType() const { return m_rt; } + //! Set whether this mesh is having a specific render type (mainly karts in STK) + void setCustomRenderType(bool has_custom) { m_custom_render_type = has_custom; } + + //! Set the mesh to use a specific render type (mainly karts in STK) + /** \param t New render type for the mesh. + \param effective_buffer Mesh buffer numbers which are effected by new render type, + if not given all mesh buffers are affected. */ + void setMeshRenderType(video::E_RENDER_TYPE t, const std::vector& effective_buffer = std::vector()) + { + if (t == video::ERT_DEFAULT) return; + setCustomRenderType(true); + for (int i = 0; i < int(getMeshBufferCount()); i++) + { + if (!effective_buffer.empty() && std::find(effective_buffer.begin(), effective_buffer.end(), i) == effective_buffer.end()) + continue; + getMeshBuffer(i)->setRenderType(t); + } + } private: - video::E_RENDER_TYPE m_rt; + bool m_custom_render_type; }; } // end namespace scene diff --git a/lib/irrlicht/include/IMeshBuffer.h b/lib/irrlicht/include/IMeshBuffer.h index a5a01df58..d04aea2fe 100644 --- a/lib/irrlicht/include/IMeshBuffer.h +++ b/lib/irrlicht/include/IMeshBuffer.h @@ -39,6 +39,9 @@ namespace scene class IMeshBuffer : public virtual IReferenceCounted { public: + IMeshBuffer() : m_rt(video::ERT_DEFAULT) {} + + virtual ~IMeshBuffer() {} //! Get the material of this meshbuffer /** \return Material of this buffer. */ @@ -147,6 +150,15 @@ namespace scene //! Get the currently used ID for identification of changes. /** This shouldn't be used for anything outside the VideoDriver. */ virtual u32 getChangedID_Index() const = 0; + + //! Set the mesh buffer to use a specific render type (mainly karts in STK) + /** \param t New render type for the mesh. */ + void setRenderType(video::E_RENDER_TYPE t) const { m_rt = t; } + + //! Get the specific render type of the mesh buffer (mainly karts in STK) + video::E_RENDER_TYPE getRenderType() const { return m_rt; } + private: + mutable video::E_RENDER_TYPE m_rt; }; } // end namespace scene diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index bb4a22db8..c8b4a72de 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1014,7 +1014,8 @@ scene::IMesh *IrrDriver::getMesh(const std::string &filename) * need it anymore. */ scene::IAnimatedMesh *IrrDriver::copyAnimatedMesh(scene::IAnimatedMesh *orig, - video::E_RENDER_TYPE rt) + video::E_RENDER_TYPE rt, + const std::vector& effective_buffer) { using namespace scene; CSkinnedMesh *mesh = dynamic_cast(orig); @@ -1025,7 +1026,7 @@ scene::IAnimatedMesh *IrrDriver::copyAnimatedMesh(scene::IAnimatedMesh *orig, } scene::IAnimatedMesh* out = mesh->clone(); - out->setRenderType(rt); + out->setMeshRenderType(rt, effective_buffer); return out; } // copyAnimatedMesh diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 94d7d166a..3933fa0e5 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -354,7 +354,8 @@ public: scene::IAnimatedMesh *getAnimatedMesh(const std::string &name); scene::IMesh *getMesh(const std::string &name); scene::IAnimatedMesh *copyAnimatedMesh(scene::IAnimatedMesh *orig, - video::E_RENDER_TYPE rt); + video::E_RENDER_TYPE rt, + const std::vector& effective_buffer = std::vector()); video::ITexture *applyMask(video::ITexture* texture, const std::string& mask_path); void displayFPS(); diff --git a/src/graphics/stk_animated_mesh.cpp b/src/graphics/stk_animated_mesh.cpp index 0fd1c5489..08fcc88f2 100644 --- a/src/graphics/stk_animated_mesh.cpp +++ b/src/graphics/stk_animated_mesh.cpp @@ -126,7 +126,7 @@ void STKAnimatedMesh::updateNoGL() TransparentMaterial TranspMat = getTransparentMaterialFromType(type, MaterialTypeParam, material); TransparentMesh[TranspMat].push_back(&mesh); } - else if (m->getRenderType() == video::ERT_TRANSPARENT) + else if (mb->getRenderType() == video::ERT_TRANSPARENT) { TransparentMesh[TM_ADDITIVE].push_back(&mesh); } diff --git a/src/graphics/stk_mesh_scene_node.cpp b/src/graphics/stk_mesh_scene_node.cpp index 35ef99d06..ab63a8fe1 100644 --- a/src/graphics/stk_mesh_scene_node.cpp +++ b/src/graphics/stk_mesh_scene_node.cpp @@ -173,7 +173,7 @@ void STKMeshSceneNode::updateNoGL() GLMesh &mesh = GLmeshes[i]; Material* material = material_manager->getMaterialFor(mb->getMaterial().getTexture(0), mb); - if (Mesh->getRenderType() == video::ERT_TRANSPARENT) + if (mb->getRenderType() == video::ERT_TRANSPARENT) { if (!immediate_draw) TransparentMesh[TM_ADDITIVE].push_back(&mesh); diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index 2430e00ce..e36fec0f6 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -231,8 +231,7 @@ KartModel::~KartModel() if (m_wheel_model[i]) { // m_wheel_model[i] can be NULL - if (m_wheel_model[i] - ->getRenderType() == video::ERT_TRANSPARENT) + if (m_wheel_model[i]->hasCustomRenderType()) { m_wheel_model[i]->drop(); } @@ -254,8 +253,7 @@ KartModel::~KartModel() assert(!m_is_master); // Drop the cloned model if created - if (m_speed_weighted_objects[i].m_model - ->getRenderType() != video::ERT_DEFAULT) + if (m_speed_weighted_objects[i].m_model->hasCustomRenderType()) { m_speed_weighted_objects[i].m_model->drop(); } @@ -333,7 +331,7 @@ KartModel* KartModel::makeCopy(video::E_RENDER_TYPE rt) { // Only clone the mesh if transparence is used scene::SMesh* clone = mani->createMeshCopy(m_wheel_model[i]); - clone->setRenderType(rt); + clone->setMeshRenderType(rt); km->m_wheel_model[i] = dynamic_cast(clone); } else