mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 23:07:18 +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;
|
int pboIndex;
|
||||||
bool needsUpdate;
|
bool needsUpdate;
|
||||||
size_t pboBufferSize;
|
size_t pboBufferSize;
|
||||||
|
void * pboMap[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
bool egl_texture_init(EGL_Texture ** texture)
|
bool egl_texture_init(EGL_Texture ** texture)
|
||||||
@ -75,7 +76,15 @@ void egl_texture_free(EGL_Texture ** texture)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((*texture)->hasPBO)
|
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);
|
glDeleteBuffers(2, (*texture)->pbo);
|
||||||
|
}
|
||||||
|
|
||||||
free(*texture);
|
free(*texture);
|
||||||
*texture = NULL;
|
*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)
|
for(int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[i]);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[i]);
|
||||||
glBufferData(
|
glBufferStorage(
|
||||||
GL_PIXEL_UNPACK_BUFFER,
|
GL_PIXEL_UNPACK_BUFFER,
|
||||||
height * stride,
|
texture->pboBufferSize,
|
||||||
NULL,
|
0,
|
||||||
GL_DYNAMIC_DRAW
|
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;
|
return true;
|
||||||
@ -215,10 +236,9 @@ bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer)
|
|||||||
if (++texture->pboIndex == 2)
|
if (++texture->pboIndex == 2)
|
||||||
texture->pboIndex = 0;
|
texture->pboIndex = 0;
|
||||||
|
|
||||||
/* initiate the data upload */
|
/* update the GPU buffer */
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[texture->pboIndex]);
|
memcpy(texture->pboMap[texture->pboIndex], buffer, texture->pboBufferSize);
|
||||||
glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, texture->pboBufferSize, buffer);
|
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
|
||||||
texture->needsUpdate = true;
|
texture->needsUpdate = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user