mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-07 10:17:14 +00:00
refactor: made renderer clean buffer
This commit is contained in:
parent
e7f4dfd79e
commit
57641ebcca
|
|
@ -434,6 +434,7 @@ void LevelRenderer::setLevel(int playerIndex, MultiPlayerLevel* level) {
|
|||
// actually exiting the game, so only when the primary player sets there
|
||||
// level to nullptr
|
||||
if (playerIndex == InputManager.GetPrimaryPad()) {
|
||||
RenderManager.CBuffDeleteAll();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_csRenderableTileEntities);
|
||||
renderableTileEntities.clear();
|
||||
|
|
|
|||
|
|
@ -527,7 +527,6 @@ static void pushRenderState() {
|
|||
|
||||
static GLuint s_sVAO_std = 0, s_sVBO_std = 0;
|
||||
static GLsizeiptr s_streamVBOSize = 0;
|
||||
static bool s_useMapRange = false;
|
||||
|
||||
static void bindStdAttribs() {
|
||||
glEnableVertexAttribArray(0);
|
||||
|
|
@ -903,27 +902,11 @@ void C4JRender::DrawVertices(ePrimitiveType ptype, int count, void* dataIn,
|
|||
|
||||
glBindVertexArray(s_sVAO_std);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, s_sVBO_std);
|
||||
// orphan buffer
|
||||
if ((GLsizeiptr)bytes != s_streamVBOSize) {
|
||||
s_streamVBOSize = (GLsizeiptr)bytes;
|
||||
glBufferData(GL_ARRAY_BUFFER, s_streamVBOSize, nullptr, GL_STREAM_DRAW);
|
||||
}
|
||||
|
||||
if (s_useMapRange) {
|
||||
void* dst = glMapBufferRange(
|
||||
GL_ARRAY_BUFFER, 0, (GLsizeiptr)bytes,
|
||||
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT |
|
||||
GL_MAP_UNSYNCHRONIZED_BIT);
|
||||
if (dst) {
|
||||
memcpy(dst, dataIn, bytes);
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
} else {
|
||||
s_useMapRange = false;
|
||||
}
|
||||
}
|
||||
if (!s_useMapRange) {
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizeiptr)bytes, dataIn);
|
||||
}
|
||||
// Standard orphaning
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)bytes, nullptr, GL_STREAM_DRAW);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizeiptr)bytes, dataIn);
|
||||
s_streamVBOSize = (GLsizeiptr)bytes;
|
||||
|
||||
glDrawArrays(glMode, 0, count);
|
||||
|
||||
|
|
@ -959,6 +942,16 @@ void C4JRender::CBuffDelete(int first, int count) {
|
|||
pthread_mutex_unlock(&s_glCallMtx);
|
||||
}
|
||||
|
||||
void C4JRender::CBuffDeleteAll() {
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
for (auto& kv : s_chunkPool) {
|
||||
kv.second.destroy();
|
||||
}
|
||||
s_chunkPool.clear();
|
||||
s_nextListBase = 1;
|
||||
pthread_mutex_unlock(&s_glCallMtx);
|
||||
}
|
||||
|
||||
void C4JRender::CBuffStart(int index, bool) {
|
||||
s_recListId = index;
|
||||
s_recVerts.clear();
|
||||
|
|
@ -987,7 +980,10 @@ void C4JRender::CBuffEnd() {
|
|||
void C4JRender::CBuffClear(int index) {
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
auto it = s_chunkPool.find(index);
|
||||
if (it != s_chunkPool.end()) it->second.destroy();
|
||||
if (it != s_chunkPool.end()) {
|
||||
it->second.destroy();
|
||||
s_chunkPool.erase(it);
|
||||
}
|
||||
pthread_mutex_unlock(&s_glCallMtx);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ public:
|
|||
void CBuffLockStaticCreations();
|
||||
int CBuffCreate(int count);
|
||||
void CBuffDelete(int first, int count);
|
||||
void CBuffDeleteAll();
|
||||
void CBuffStart(int index, bool full = false);
|
||||
void CBuffClear(int index);
|
||||
int CBuffSize(int index);
|
||||
|
|
|
|||
Loading…
Reference in a new issue