Remove stkinstancedscenenode.h/cpp
This commit is contained in:
parent
cf85f97315
commit
13e1a40b7b
@ -34,7 +34,6 @@
|
|||||||
#include "graphics/screenquad.hpp"
|
#include "graphics/screenquad.hpp"
|
||||||
#include "graphics/shaders.hpp"
|
#include "graphics/shaders.hpp"
|
||||||
#include "graphics/stkmeshscenenode.hpp"
|
#include "graphics/stkmeshscenenode.hpp"
|
||||||
#include "graphics/stkinstancedscenenode.hpp"
|
|
||||||
#include "graphics/wind.hpp"
|
#include "graphics/wind.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "items/item.hpp"
|
#include "items/item.hpp"
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "graphics/screenquad.hpp"
|
#include "graphics/screenquad.hpp"
|
||||||
#include "graphics/shaders.hpp"
|
#include "graphics/shaders.hpp"
|
||||||
#include "graphics/stkmeshscenenode.hpp"
|
#include "graphics/stkmeshscenenode.hpp"
|
||||||
#include "graphics/stkinstancedscenenode.hpp"
|
|
||||||
#include "graphics/wind.hpp"
|
#include "graphics/wind.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "items/item.hpp"
|
#include "items/item.hpp"
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "graphics/screenquad.hpp"
|
#include "graphics/screenquad.hpp"
|
||||||
#include "graphics/shaders.hpp"
|
#include "graphics/shaders.hpp"
|
||||||
#include "graphics/stkmeshscenenode.hpp"
|
#include "graphics/stkmeshscenenode.hpp"
|
||||||
#include "graphics/stkinstancedscenenode.hpp"
|
|
||||||
#include "graphics/wind.hpp"
|
#include "graphics/wind.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "items/item.hpp"
|
#include "items/item.hpp"
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "graphics/screenquad.hpp"
|
#include "graphics/screenquad.hpp"
|
||||||
#include "graphics/shaders.hpp"
|
#include "graphics/shaders.hpp"
|
||||||
#include "graphics/stkmeshscenenode.hpp"
|
#include "graphics/stkmeshscenenode.hpp"
|
||||||
#include "graphics/stkinstancedscenenode.hpp"
|
|
||||||
#include "graphics/wind.hpp"
|
#include "graphics/wind.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "items/item.hpp"
|
#include "items/item.hpp"
|
||||||
|
@ -1,220 +0,0 @@
|
|||||||
#include "stkinstancedscenenode.hpp"
|
|
||||||
#include "graphics/irr_driver.hpp"
|
|
||||||
#include "graphics/callbacks.hpp"
|
|
||||||
|
|
||||||
STKInstancedSceneNode::STKInstancedSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
|
|
||||||
const irr::core::vector3df& position,
|
|
||||||
const irr::core::vector3df& rotation,
|
|
||||||
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();
|
|
||||||
setAutomaticCulling(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void STKInstancedSceneNode::cleanGL()
|
|
||||||
{
|
|
||||||
for (u32 i = 0; i < GLmeshes.size(); ++i)
|
|
||||||
{
|
|
||||||
GLMesh mesh = GLmeshes[i];
|
|
||||||
if (!mesh.vertex_buffer)
|
|
||||||
continue;
|
|
||||||
if (mesh.vao)
|
|
||||||
glDeleteVertexArrays(1, &(mesh.vao));
|
|
||||||
if (mesh.vertex_buffer)
|
|
||||||
glDeleteBuffers(1, &(mesh.vertex_buffer));
|
|
||||||
if (mesh.index_buffer)
|
|
||||||
glDeleteBuffers(1, &(mesh.index_buffer));
|
|
||||||
if (mesh.instance_buffer)
|
|
||||||
glDeleteBuffers(1, &(mesh.instance_buffer));
|
|
||||||
#ifdef Bindless_Texture_Support
|
|
||||||
for (unsigned j = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
if (mesh.TextureHandles[j] && glIsTextureHandleResidentARB(mesh.TextureHandles[j]))
|
|
||||||
glMakeTextureHandleNonResidentARB(mesh.TextureHandles[j]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
STKInstancedSceneNode::~STKInstancedSceneNode()
|
|
||||||
{
|
|
||||||
irr_driver->dropAllTextures(getMesh());
|
|
||||||
irr_driver->removeMeshFromCache(getMesh());
|
|
||||||
|
|
||||||
if (irr_driver->isGLSL())
|
|
||||||
cleanGL();
|
|
||||||
}
|
|
||||||
|
|
||||||
void STKInstancedSceneNode::createGLMeshes()
|
|
||||||
{
|
|
||||||
for (u32 i = 0; i<Mesh->getMeshBufferCount(); ++i)
|
|
||||||
{
|
|
||||||
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
|
|
||||||
GLmeshes.push_back(allocateMeshBuffer(mb));
|
|
||||||
GLMesh &mesh = GLmeshes.back();
|
|
||||||
if (irr_driver->hasARB_base_instance())
|
|
||||||
{
|
|
||||||
std::pair<unsigned, unsigned> p = VAOManager::getInstance()->getBase(mb);
|
|
||||||
mesh.vaoBaseVertex = p.first;
|
|
||||||
mesh.vaoOffset = p.second;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fillLocalBuffer(mesh, mb);
|
|
||||||
instanceData.push_back(std::vector<InstanceData>());
|
|
||||||
}
|
|
||||||
isMaterialInitialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void STKInstancedSceneNode::initinstancedvaostate(GLMesh &mesh, const std::vector<InstanceData> &instances)
|
|
||||||
{
|
|
||||||
if (!irr_driver->hasARB_base_instance())
|
|
||||||
{
|
|
||||||
mesh.vao = createVAO(mesh.vertex_buffer, mesh.index_buffer, getVTXTYPEFromStride(mesh.Stride));
|
|
||||||
glGenBuffers(1, &(mesh.instance_buffer));
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.instance_buffer);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, instances.size() * sizeof(InstanceData), instances.data(), GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(7);
|
|
||||||
glVertexAttribPointer(7, 3, GL_FLOAT, GL_FALSE, sizeof(InstanceData), 0);
|
|
||||||
glVertexAttribDivisor(7, 1);
|
|
||||||
glEnableVertexAttribArray(8);
|
|
||||||
glVertexAttribPointer(8, 3, GL_FLOAT, GL_FALSE, sizeof(InstanceData), (GLvoid*)(3 * sizeof(float)));
|
|
||||||
glVertexAttribDivisor(8, 1);
|
|
||||||
glEnableVertexAttribArray(9);
|
|
||||||
glVertexAttribPointer(9, 3, GL_FLOAT, GL_FALSE, sizeof(InstanceData), (GLvoid*)(6 * sizeof(float)));
|
|
||||||
glVertexAttribDivisor(9, 1);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void STKInstancedSceneNode::setFirstTimeMaterial()
|
|
||||||
{
|
|
||||||
if (isMaterialInitialized)
|
|
||||||
return;
|
|
||||||
for (u32 i = 0; i<Mesh->getMeshBufferCount(); ++i)
|
|
||||||
{
|
|
||||||
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
|
|
||||||
if (!mb)
|
|
||||||
continue;
|
|
||||||
video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType;
|
|
||||||
|
|
||||||
GLMesh &mesh = GLmeshes[i];
|
|
||||||
MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType());
|
|
||||||
initinstancedvaostate(mesh, instanceData[i]);
|
|
||||||
MeshSolidMaterial[MatType].push_back(&mesh);
|
|
||||||
InitTextures(mesh, MatType);
|
|
||||||
}
|
|
||||||
isMaterialInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void STKInstancedSceneNode::addInstance(const core::vector3df &origin, const core::vector3df &orientation, const core::vector3df &scale)
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < GLmeshes.size(); i++)
|
|
||||||
{
|
|
||||||
GLMesh &mesh = GLmeshes[i];
|
|
||||||
#ifdef Bindless_Texture_Support
|
|
||||||
if (UserConfigParams::m_azdo)
|
|
||||||
{
|
|
||||||
for (unsigned j = 0; j < 2; j++)
|
|
||||||
{
|
|
||||||
if (!mesh.textures[j])
|
|
||||||
mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
|
|
||||||
compressTexture(mesh.textures[j], true);
|
|
||||||
|
|
||||||
if (!mesh.TextureHandles[j])
|
|
||||||
mesh.TextureHandles[j] = glGetTextureSamplerHandleARB(getTextureGLuint(mesh.textures[j]), MeshShader::InstancedNormalMapShader::getInstance()->SamplersId[j]);
|
|
||||||
if (!glIsTextureHandleResidentARB(mesh.TextureHandles[j]))
|
|
||||||
glMakeTextureHandleResidentARB(mesh.TextureHandles[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
InstanceData instance = {
|
|
||||||
{
|
|
||||||
origin.X,
|
|
||||||
origin.Y,
|
|
||||||
origin.Z
|
|
||||||
},
|
|
||||||
{
|
|
||||||
orientation.X,
|
|
||||||
orientation.Y,
|
|
||||||
orientation.Z
|
|
||||||
},
|
|
||||||
{
|
|
||||||
scale.X,
|
|
||||||
scale.Y,
|
|
||||||
scale.Z
|
|
||||||
},
|
|
||||||
mesh.TextureHandles[0],
|
|
||||||
mesh.TextureHandles[1]
|
|
||||||
};
|
|
||||||
instanceData[i].push_back(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core::matrix4 STKInstancedSceneNode::getInstanceTransform(int id)
|
|
||||||
{
|
|
||||||
core::matrix4 mat;
|
|
||||||
|
|
||||||
const InstanceData &instance = instanceData[0][id];
|
|
||||||
mat.setTranslation(core::vector3df(
|
|
||||||
instance.Origin.X,
|
|
||||||
instance.Origin.Y,
|
|
||||||
instance.Origin.Z));
|
|
||||||
mat.setRotationDegrees(core::vector3df(
|
|
||||||
instance.Orientation.X,
|
|
||||||
instance.Orientation.Y,
|
|
||||||
instance.Orientation.Z));
|
|
||||||
mat.setScale(core::vector3df(
|
|
||||||
instance.Scale.X,
|
|
||||||
instance.Scale.Y,
|
|
||||||
instance.Scale.Z));
|
|
||||||
|
|
||||||
return mat;
|
|
||||||
}
|
|
||||||
|
|
||||||
void STKInstancedSceneNode::render()
|
|
||||||
{
|
|
||||||
if (!irr_driver->isGLSL())
|
|
||||||
{
|
|
||||||
CMeshSceneNode::render();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setFirstTimeMaterial();
|
|
||||||
|
|
||||||
/* if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == SHADOW_PASS)
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++)
|
|
||||||
{
|
|
||||||
GLMesh *mesh = MeshSolidMaterial[MAT_DEFAULT][i];
|
|
||||||
ListInstancedMatDefault::getInstance()->push_back(STK::make_tuple(mesh, instanceData[0].size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++)
|
|
||||||
{
|
|
||||||
GLMesh *mesh = MeshSolidMaterial[MAT_ALPHA_REF][i];
|
|
||||||
ListInstancedMatAlphaRef::getInstance()->push_back(STK::make_tuple(mesh, instanceData[0].size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
windDir = getWind();
|
|
||||||
SunLightProvider * const cb = (SunLightProvider *)irr_driver->getCallback(ES_SUNLIGHT);
|
|
||||||
for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++)
|
|
||||||
{
|
|
||||||
GLMesh *mesh = MeshSolidMaterial[MAT_GRASS][i];
|
|
||||||
ListInstancedMatGrass::getInstance()->push_back(STK::make_tuple(mesh, instanceData[0].size(), windDir, cb->getPosition()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < MeshSolidMaterial[MAT_NORMAL_MAP].size(); i++)
|
|
||||||
{
|
|
||||||
GLMesh *mesh = MeshSolidMaterial[MAT_NORMAL_MAP][i];
|
|
||||||
ListInstancedMatNormalMap::getInstance()->push_back(STK::make_tuple(mesh, instanceData[0].size()));
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
#ifndef STKINSTANCEDSCENENODE_HPP
|
|
||||||
#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 *> MeshSolidMaterial[MAT_COUNT];
|
|
||||||
std::vector<GLMesh> GLmeshes;
|
|
||||||
std::vector<std::vector<InstanceData> > instanceData;
|
|
||||||
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView;
|
|
||||||
void createGLMeshes();
|
|
||||||
bool isMaterialInitialized;
|
|
||||||
void setFirstTimeMaterial();
|
|
||||||
void initinstancedvaostate(GLMesh &mesh, const std::vector<InstanceData> &);
|
|
||||||
void cleanGL();
|
|
||||||
core::vector3df windDir;
|
|
||||||
public:
|
|
||||||
STKInstancedSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
|
|
||||||
const irr::core::vector3df& position = irr::core::vector3df(0, 0, 0),
|
|
||||||
const irr::core::vector3df& rotation = irr::core::vector3df(0, 0, 0),
|
|
||||||
const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f));
|
|
||||||
~STKInstancedSceneNode();
|
|
||||||
virtual void render();
|
|
||||||
void addInstance(const core::vector3df &origin, const core::vector3df &orientation, const core::vector3df &scale);
|
|
||||||
|
|
||||||
int getInstanceCount() const { return instanceData[0].size(); }
|
|
||||||
|
|
||||||
core::matrix4 getInstanceTransform(int id);
|
|
||||||
|
|
||||||
void instanceGrab() { m_ref_count++; }
|
|
||||||
void instanceDrop()
|
|
||||||
{
|
|
||||||
m_ref_count--;
|
|
||||||
if (m_ref_count <= 0)
|
|
||||||
{
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LEAK_CHECK();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,6 +1,5 @@
|
|||||||
#include "stkscenemanager.hpp"
|
#include "stkscenemanager.hpp"
|
||||||
#include "stkmesh.hpp"
|
#include "stkmesh.hpp"
|
||||||
#include "stkinstancedscenenode.hpp"
|
|
||||||
#include "irr_driver.hpp"
|
#include "irr_driver.hpp"
|
||||||
#include <ISceneManager.h>
|
#include <ISceneManager.h>
|
||||||
#include <ISceneNode.h>
|
#include <ISceneNode.h>
|
||||||
|
@ -25,7 +25,6 @@ using namespace irr;
|
|||||||
|
|
||||||
#include "graphics/material_manager.hpp"
|
#include "graphics/material_manager.hpp"
|
||||||
#include "graphics/mesh_tools.hpp"
|
#include "graphics/mesh_tools.hpp"
|
||||||
#include "graphics/stkinstancedscenenode.hpp"
|
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "io/xml_node.hpp"
|
#include "io/xml_node.hpp"
|
||||||
#include "modes/world.hpp"
|
#include "modes/world.hpp"
|
||||||
|
@ -22,7 +22,6 @@ using namespace irr;
|
|||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
#include "graphics/lod_node.hpp"
|
#include "graphics/lod_node.hpp"
|
||||||
#include "graphics/mesh_tools.hpp"
|
#include "graphics/mesh_tools.hpp"
|
||||||
#include "graphics/stkinstancedscenenode.hpp"
|
|
||||||
#include "io/xml_node.hpp"
|
#include "io/xml_node.hpp"
|
||||||
#include "tracks/track.hpp"
|
#include "tracks/track.hpp"
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
#include "graphics/particle_emitter.hpp"
|
#include "graphics/particle_emitter.hpp"
|
||||||
#include "graphics/particle_kind.hpp"
|
#include "graphics/particle_kind.hpp"
|
||||||
#include "graphics/particle_kind_manager.hpp"
|
#include "graphics/particle_kind_manager.hpp"
|
||||||
#include "graphics/stkinstancedscenenode.hpp"
|
|
||||||
#include "graphics/stk_text_billboard.hpp"
|
#include "graphics/stk_text_billboard.hpp"
|
||||||
#include "guiengine/scalable_font.hpp"
|
#include "guiengine/scalable_font.hpp"
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include "graphics/particle_emitter.hpp"
|
#include "graphics/particle_emitter.hpp"
|
||||||
#include "graphics/particle_kind_manager.hpp"
|
#include "graphics/particle_kind_manager.hpp"
|
||||||
#include "graphics/stkmeshscenenode.hpp"
|
#include "graphics/stkmeshscenenode.hpp"
|
||||||
#include "graphics/stkinstancedscenenode.hpp"
|
|
||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "io/xml_node.hpp"
|
#include "io/xml_node.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user