mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 05:27:20 +00:00
[client] egl: use persistant mapped texture buffers
While it is recommended to use memory barriers when updating a buffer like we are, since we double buffer it is unlikely we will corrupt a prior frame, and even if we do since it's just texture data at worst we might see a tear.
This commit is contained in:
parent
087387087e
commit
fc66a4a19c
@ -47,6 +47,7 @@ struct EGL_Texture
|
||||
int pboIndex;
|
||||
bool needsUpdate;
|
||||
size_t pboBufferSize;
|
||||
void * pboMap[2];
|
||||
};
|
||||
|
||||
bool egl_texture_init(EGL_Texture ** texture)
|
||||
@ -75,7 +76,15 @@ void egl_texture_free(EGL_Texture ** texture)
|
||||
}
|
||||
|
||||
if ((*texture)->hasPBO)
|
||||
{
|
||||
for(int i = 0; i < 2; ++i)
|
||||
{
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, (*texture)->pbo[i]);
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
}
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glDeleteBuffers(2, (*texture)->pbo);
|
||||
}
|
||||
|
||||
free(*texture);
|
||||
*texture = NULL;
|
||||
@ -189,14 +198,26 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_
|
||||
for(int i = 0; i < 2; ++i)
|
||||
{
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[i]);
|
||||
glBufferData(
|
||||
glBufferStorage(
|
||||
GL_PIXEL_UNPACK_BUFFER,
|
||||
height * stride,
|
||||
NULL,
|
||||
GL_DYNAMIC_DRAW
|
||||
texture->pboBufferSize,
|
||||
0,
|
||||
GL_MAP_PERSISTENT_BIT |
|
||||
GL_MAP_WRITE_BIT |
|
||||
GL_MAP_COHERENT_BIT
|
||||
);
|
||||
|
||||
texture->pboMap[i] = glMapBufferRange(
|
||||
GL_PIXEL_UNPACK_BUFFER,
|
||||
0,
|
||||
texture->pboBufferSize,
|
||||
GL_MAP_PERSISTENT_BIT |
|
||||
GL_MAP_WRITE_BIT |
|
||||
GL_MAP_UNSYNCHRONIZED_BIT |
|
||||
GL_MAP_INVALIDATE_BUFFER_BIT
|
||||
);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
}
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -215,10 +236,9 @@ bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer)
|
||||
if (++texture->pboIndex == 2)
|
||||
texture->pboIndex = 0;
|
||||
|
||||
/* initiate the data upload */
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[texture->pboIndex]);
|
||||
glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, texture->pboBufferSize, buffer);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
/* update the GPU buffer */
|
||||
memcpy(texture->pboMap[texture->pboIndex], buffer, texture->pboBufferSize);
|
||||
|
||||
texture->needsUpdate = true;
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user