Merge branch 'master' of github.com:supertuxkart/stk-code
This commit is contained in:
commit
94457e7a53
@ -50,8 +50,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
STKInstancedSceneNode *InstancedBox = 0;
|
||||
|
||||
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN2(a, b) ((a) > (b) ? (b) : (a))
|
||||
|
||||
|
@ -8,6 +8,9 @@ STKInstancedSceneNode::STKInstancedSceneNode(irr::scene::IMesh* mesh, ISceneNode
|
||||
const irr::core::vector3df& scale) :
|
||||
CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale)
|
||||
{
|
||||
m_ref_count = 0;
|
||||
irr_driver->grabAllTextures(mesh);
|
||||
|
||||
if (irr_driver->isGLSL())
|
||||
{
|
||||
createGLMeshes();
|
||||
@ -42,6 +45,9 @@ void STKInstancedSceneNode::cleanGL()
|
||||
|
||||
STKInstancedSceneNode::~STKInstancedSceneNode()
|
||||
{
|
||||
irr_driver->dropAllTextures(getMesh());
|
||||
irr_driver->removeMeshFromCache(getMesh());
|
||||
|
||||
if (irr_driver->isGLSL())
|
||||
cleanGL();
|
||||
}
|
||||
|
@ -2,10 +2,12 @@
|
||||
#define STKINSTANCEDSCENENODE_HPP
|
||||
|
||||
#include "stkmesh.hpp"
|
||||
#include "utils/leak_check.hpp"
|
||||
|
||||
class STKInstancedSceneNode : public irr::scene::CMeshSceneNode
|
||||
{
|
||||
protected:
|
||||
int m_ref_count;
|
||||
std::vector<GLMesh *> GeometricMesh[FPSM_COUNT];
|
||||
std::vector<GLMesh *> ShadedMesh[SM_COUNT];
|
||||
std::vector<GLMesh> GLmeshes;
|
||||
@ -26,6 +28,18 @@ public:
|
||||
~STKInstancedSceneNode();
|
||||
virtual void render();
|
||||
void addInstance(const core::vector3df &origin, const core::vector3df &orientation, const core::vector3df &scale);
|
||||
|
||||
void instanceGrab() { m_ref_count++; }
|
||||
void instanceDrop()
|
||||
{
|
||||
m_ref_count--;
|
||||
if (m_ref_count <= 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
LEAK_CHECK();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -136,6 +136,7 @@ STKInstancedSceneNode* ModelDefinitionLoader::instanciate(const irr::core::vecto
|
||||
}
|
||||
|
||||
m_instancing_nodes[name]->addInstance(position, rotation, scale);
|
||||
m_instancing_nodes[name]->instanceGrab();
|
||||
return m_instancing_nodes[name];
|
||||
}
|
||||
|
||||
|
@ -162,6 +162,7 @@ TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNo
|
||||
ModelDefinitionLoader& model_def_loader) : TrackObjectPresentationSceneNode(xml_node)
|
||||
{
|
||||
m_instancing_group = NULL;
|
||||
m_fallback_scene_node = NULL;
|
||||
|
||||
std::string instancing_model;
|
||||
xml_node.get("instancing_model", &instancing_model);
|
||||
@ -179,13 +180,32 @@ TrackObjectPresentationInstancing::TrackObjectPresentationInstancing(const XMLNo
|
||||
}
|
||||
else
|
||||
{
|
||||
m_instancing_group = new STKInstancedSceneNode(model_def_loader.getFirstMeshFor(instancing_model),
|
||||
m_node, irr_driver->getSceneManager(), -1);
|
||||
scene::IMesh* mesh = model_def_loader.getFirstMeshFor(instancing_model);
|
||||
scene::IMeshSceneNode* node = irr_driver->addMesh(mesh, m_node);
|
||||
node->grab();
|
||||
irr_driver->grabAllTextures(mesh);
|
||||
mesh->grab();
|
||||
World::getWorld()->getTrack()->addNode(node);
|
||||
|
||||
m_fallback_scene_node = node;
|
||||
}
|
||||
}
|
||||
|
||||
TrackObjectPresentationInstancing::~TrackObjectPresentationInstancing()
|
||||
{
|
||||
if (m_instancing_group != NULL)
|
||||
m_instancing_group->instanceDrop();
|
||||
|
||||
if (m_fallback_scene_node != NULL)
|
||||
{
|
||||
scene::IMesh* mesh = m_fallback_scene_node->getMesh();
|
||||
irr_driver->dropAllTextures(mesh);
|
||||
mesh->drop();
|
||||
if (mesh->getReferenceCount() == 1)
|
||||
irr_driver->removeMeshFromCache(mesh);
|
||||
|
||||
m_fallback_scene_node->drop();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <IAnimatedMeshSceneNode.h>
|
||||
namespace irr
|
||||
{
|
||||
namespace scene { class IAnimatedMesh; class ISceneNode; }
|
||||
namespace scene { class IAnimatedMesh; class IMeshSceneNode; class ISceneNode; }
|
||||
}
|
||||
using namespace irr;
|
||||
|
||||
@ -170,6 +170,7 @@ public:
|
||||
class TrackObjectPresentationInstancing : public TrackObjectPresentationSceneNode
|
||||
{
|
||||
STKInstancedSceneNode* m_instancing_group;
|
||||
scene::IMeshSceneNode* m_fallback_scene_node;
|
||||
public:
|
||||
|
||||
TrackObjectPresentationInstancing(const XMLNode& xml_node,
|
||||
|
Loading…
Reference in New Issue
Block a user