Use a separate update() member

This commit is contained in:
vlj 2014-08-28 21:32:04 +02:00
parent 61d70ea599
commit 1e1ba34f45
4 changed files with 41 additions and 43 deletions

View File

@ -54,21 +54,13 @@ void STKAnimatedMesh::setMesh(scene::IAnimatedMesh* mesh)
CAnimatedMeshSceneNode::setMesh(mesh);
}
void STKAnimatedMesh::render()
void STKAnimatedMesh::update()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
bool isTransparentPass =
SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT;
++PassCount;
scene::IMesh* m = getMeshForCurrentFrame();
if (m)
{
Box = m->getBoundingBox();
}
else
{
Log::error("animated mesh", "Animated Mesh returned no mesh to render.");
@ -143,33 +135,33 @@ void STKAnimatedMesh::render()
const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i];
if (isObject(material.MaterialType))
{
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == TRANSPARENT_PASS)
{
glBindVertexArray(0);
size_t size = mb->getVertexCount() * GLmeshes[i].Stride;
if (irr_driver->hasARB_base_instance())
glBindBuffer(GL_ARRAY_BUFFER, VAOManager::getInstance()->getVBO(mb->getVertexType()));
else
glBindBuffer(GL_ARRAY_BUFFER, GLmeshes[i].vertex_buffer);
GLbitfield bitfield = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT;
void * buf = glMapBufferRange(GL_ARRAY_BUFFER, GLmeshes[i].vaoBaseVertex * GLmeshes[i].Stride, size, bitfield);
memcpy(buf, mb->getVertices(), size);
glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
glBindVertexArray(0);
size_t size = mb->getVertexCount() * GLmeshes[i].Stride;
if (irr_driver->hasARB_base_instance())
glBindBuffer(GL_ARRAY_BUFFER, VAOManager::getInstance()->getVBO(mb->getVertexType()));
else
glBindBuffer(GL_ARRAY_BUFFER, GLmeshes[i].vertex_buffer);
GLbitfield bitfield = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT;
void * buf = glMapBufferRange(GL_ARRAY_BUFFER, GLmeshes[i].vaoBaseVertex * GLmeshes[i].Stride, size, bitfield);
memcpy(buf, mb->getVertices(), size);
glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
if (mb)
GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0);
video::IMaterialRenderer* rnd = driver->getMaterialRenderer(Materials[i].MaterialType);
bool transparent = (rnd && rnd->isTransparent());
// only render transparent buffer if this is the transparent render pass
// and solid only in solid pass
if (transparent != isTransparentPass)
continue;
}
}
void STKAnimatedMesh::render()
{
bool isTransparentPass =
SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT;
++PassCount;
update();
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == SHADOW_PASS)
{
ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation);

View File

@ -17,6 +17,7 @@ protected:
core::matrix4 ModelViewProjectionMatrix;
void cleanGLMeshes();
public:
void update();
STKAnimatedMesh(irr::scene::IAnimatedMesh* mesh, irr::scene::ISceneNode* parent,
irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position = irr::core::vector3df(0,0,0),

View File

@ -183,6 +183,21 @@ void STKMeshSceneNode::updatevbo()
static video::ITexture *spareWhiteTex = 0;
void STKMeshSceneNode::update()
{
Box = Mesh->getBoundingBox();
setFirstTimeMaterial();
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0);
}
}
void STKMeshSceneNode::OnRegisterSceneNode()
{
@ -201,24 +216,13 @@ void STKMeshSceneNode::render()
++PassCount;
Box = Mesh->getBoundingBox();
setFirstTimeMaterial();
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0);
}
update();
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS && immediate_draw)
{
core::matrix4 invmodel;
AbsoluteTransformation.getInverse(invmodel);
glDisable(GL_CULL_FACE);
if (update_each_frame)
updatevbo();

View File

@ -32,6 +32,7 @@ public:
const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f),
bool createGLMeshes = true);
virtual void render();
void update();
virtual void setMesh(irr::scene::IMesh* mesh);
virtual void OnRegisterSceneNode();
virtual ~STKMeshSceneNode();