Design a way to render kart and driver differently

This commit is contained in:
Benau 2016-06-12 16:19:34 +08:00
parent 1e1093dccc
commit d520c4477d
8 changed files with 49 additions and 19 deletions

View File

@ -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,

View File

@ -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 <algorithm>
#include <vector>
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<int>& effective_buffer = std::vector<int>())
{
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

View File

@ -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

View File

@ -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<int>& effective_buffer)
{
using namespace scene;
CSkinnedMesh *mesh = dynamic_cast<CSkinnedMesh*>(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

View File

@ -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<int>& effective_buffer = std::vector<int>());
video::ITexture *applyMask(video::ITexture* texture,
const std::string& mask_path);
void displayFPS();

View File

@ -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);
}

View File

@ -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);

View File

@ -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<scene::IMesh*>(clone);
}
else