From 1e1ba34f45f44b9880ade6a5540ac3e6a9e66f40 Mon Sep 17 00:00:00 2001 From: vlj Date: Thu, 28 Aug 2014 21:32:04 +0200 Subject: [PATCH] Use a separate update() member --- src/graphics/stkanimatedmesh.cpp | 54 +++++++++++++------------------ src/graphics/stkanimatedmesh.hpp | 1 + src/graphics/stkmeshscenenode.cpp | 28 +++++++++------- src/graphics/stkmeshscenenode.hpp | 1 + 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index 6c9cf872c..257e97a49 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -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); diff --git a/src/graphics/stkanimatedmesh.hpp b/src/graphics/stkanimatedmesh.hpp index c5c113da0..333ed0495 100644 --- a/src/graphics/stkanimatedmesh.hpp +++ b/src/graphics/stkanimatedmesh.hpp @@ -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), diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 7d6b6fb78..6e5aad50d 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -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(); diff --git a/src/graphics/stkmeshscenenode.hpp b/src/graphics/stkmeshscenenode.hpp index d9e16283b..21fb62249 100644 --- a/src/graphics/stkmeshscenenode.hpp +++ b/src/graphics/stkmeshscenenode.hpp @@ -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();