Don't delete vao each frame when update vertex buffer
This commit is contained in:
parent
63267391ef
commit
ec59e3f573
@ -62,59 +62,7 @@ SPDynamicDrawCall::SPDynamicDrawCall(scene::E_PRIMITIVE_TYPE pt,
|
|||||||
SPTextureManager::get()->addGLCommandFunction
|
SPTextureManager::get()->addGLCommandFunction
|
||||||
(std::bind(&SPDynamicDrawCall::initTextureDyDc, this));
|
(std::bind(&SPDynamicDrawCall::initTextureDyDc, this));
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
recreateDynamicVAO();
|
|
||||||
#endif
|
|
||||||
} // SPDynamicDrawCall
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
bool SPDynamicDrawCall::initTextureDyDc()
|
|
||||||
{
|
|
||||||
#ifndef SERVER_ONLY
|
|
||||||
for (unsigned i = 0; i < m_stk_material.size(); i++)
|
|
||||||
{
|
|
||||||
for (unsigned j = 0; j < 6; j++)
|
|
||||||
{
|
|
||||||
if (!m_textures[i][j]->initialized())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!(CVS->useArrayTextures() || CVS->isARBBindlessTextureUsable()))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_ibo);
|
|
||||||
if (CVS->useArrayTextures())
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
uint16_t array_index = (uint16_t)
|
|
||||||
m_textures[0][i]->getTextureArrayIndex();
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 32 + (i * 2), 2, &array_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 32 + (i * 8), 8,
|
|
||||||
m_textures[0][i]->getTextureHandlePointer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
} // initTextureDyDc
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void SPDynamicDrawCall::recreateDynamicVAO()
|
|
||||||
{
|
|
||||||
#ifndef SERVER_ONLY
|
|
||||||
if (m_vao[0] != 0)
|
|
||||||
{
|
|
||||||
glDeleteVertexArrays(1, &m_vao[0]);
|
|
||||||
}
|
|
||||||
glGenVertexArrays(1, &m_vao[0]);
|
glGenVertexArrays(1, &m_vao[0]);
|
||||||
glBindVertexArray(m_vao[0]);
|
glBindVertexArray(m_vao[0]);
|
||||||
|
|
||||||
@ -220,8 +168,48 @@ void SPDynamicDrawCall::recreateDynamicVAO()
|
|||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
} // recreateVAO
|
} // SPDynamicDrawCall
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
bool SPDynamicDrawCall::initTextureDyDc()
|
||||||
|
{
|
||||||
|
#ifndef SERVER_ONLY
|
||||||
|
for (unsigned i = 0; i < m_stk_material.size(); i++)
|
||||||
|
{
|
||||||
|
for (unsigned j = 0; j < 6; j++)
|
||||||
|
{
|
||||||
|
if (!m_textures[i][j]->initialized())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!(CVS->useArrayTextures() || CVS->isARBBindlessTextureUsable()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, m_ibo);
|
||||||
|
if (CVS->useArrayTextures())
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
uint16_t array_index = (uint16_t)
|
||||||
|
m_textures[0][i]->getTextureArrayIndex();
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 32 + (i * 2), 2, &array_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < 6; i++)
|
||||||
|
{
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, 32 + (i * 8), 8,
|
||||||
|
m_textures[0][i]->getTextureHandlePointer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
} // initTextureDyDc
|
||||||
|
|
||||||
}
|
}
|
@ -61,8 +61,6 @@ private:
|
|||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool initTextureDyDc();
|
bool initTextureDyDc();
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
void recreateDynamicVAO();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SPDynamicDrawCall(scene::E_PRIMITIVE_TYPE pt, SPShader* shader,
|
SPDynamicDrawCall(scene::E_PRIMITIVE_TYPE pt, SPShader* shader,
|
||||||
@ -93,28 +91,29 @@ public:
|
|||||||
m_texture_trans.X, m_texture_trans.Y, 0.0f, 0);
|
m_texture_trans.X, m_texture_trans.Y, 0.0f, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_ibo);
|
glBindBuffer(GL_ARRAY_BUFFER, m_ibo);
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, 32, &id);
|
glBufferSubData(GL_ARRAY_BUFFER, 0, 32, &id);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
if (m_update_offset >= 0 && !m_vertices.empty())
|
if (m_update_offset >= 0 && !m_vertices.empty())
|
||||||
{
|
{
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||||
if ((unsigned)m_vertices.capacity() > m_gl_vbo_size)
|
if ((unsigned)m_vertices.capacity() > m_gl_vbo_size)
|
||||||
{
|
{
|
||||||
m_update_offset = 0;
|
m_update_offset = 0;
|
||||||
glDeleteBuffers(1, &m_vbo);
|
|
||||||
glGenBuffers(1, &m_vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
|
||||||
m_gl_vbo_size = (unsigned)m_vertices.capacity();
|
m_gl_vbo_size = (unsigned)m_vertices.capacity();
|
||||||
glBufferData(GL_ARRAY_BUFFER, m_gl_vbo_size * 48, NULL,
|
glBufferData(GL_ARRAY_BUFFER, m_gl_vbo_size * 48,
|
||||||
GL_DYNAMIC_DRAW);
|
m_vertices.data(), GL_DYNAMIC_DRAW);
|
||||||
recreateDynamicVAO();
|
|
||||||
}
|
}
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
else
|
||||||
const int length = ((int)m_vertices.size() - m_update_offset) * 48;
|
{
|
||||||
assert(length > 0);
|
const int length =
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, m_update_offset * 48, length,
|
((int)m_vertices.size() - m_update_offset) * 48;
|
||||||
m_vertices.data() + m_update_offset);
|
assert(length > 0);
|
||||||
|
glBufferSubData(GL_ARRAY_BUFFER, m_update_offset * 48, length,
|
||||||
|
m_vertices.data() + m_update_offset);
|
||||||
|
}
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
m_update_offset = -1;
|
m_update_offset = -1;
|
||||||
}
|
}
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user