Skip to content

Commit

Permalink
Only reupload buffer for skidding mark
Browse files Browse the repository at this point in the history
  • Loading branch information
vlj committed Mar 19, 2014
1 parent 4128371 commit 822081d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/graphics/stkmeshscenenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,41 @@ void STKMeshSceneNode::drawSolidPass2(const GLMesh &mesh, ShadedMaterial type)
}
}

void STKMeshSceneNode::updatevbo()
{
for (unsigned i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
GLMesh &mesh = GLmeshes[i];
glBindVertexArray(0);

glBindBuffer(GL_ARRAY_BUFFER, mesh.vertex_buffer);
const void* vertices = mb->getVertices();
const u32 vertexCount = mb->getVertexCount();
const c8* vbuf = static_cast<const c8*>(vertices);
glBufferData(GL_ARRAY_BUFFER, vertexCount * mesh.Stride, vbuf, GL_STATIC_DRAW);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.index_buffer);
const void* indices = mb->getIndices();
mesh.IndexCount = mb->getIndexCount();
GLenum indexSize;
switch (mb->getIndexType())
{
case irr::video::EIT_16BIT:
indexSize = sizeof(u16);
break;
case irr::video::EIT_32BIT:
indexSize = sizeof(u32);
break;
default:
assert(0 && "Wrong index size");
}
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mesh.IndexCount * indexSize, indices, GL_STATIC_DRAW);
}
}

void STKMeshSceneNode::render()
{
irr::video::IVideoDriver* driver = irr_driver->getVideoDriver();
Expand All @@ -284,7 +319,7 @@ void STKMeshSceneNode::render()
return;

if (reload_each_frame)
setMesh(Mesh);
updatevbo();

bool isTransparentPass =
SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT;
Expand Down
1 change: 1 addition & 0 deletions src/graphics/stkmeshscenenode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class STKMeshSceneNode : public irr::scene::CMeshSceneNode
void createGLMeshes();
void cleanGLMeshes();
void setFirstTimeMaterial();
void updatevbo();
bool isMaterialInitialized;
bool reload_each_frame;
public:
Expand Down

0 comments on commit 822081d

Please sign in to comment.