mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 13:37:22 +00:00
[egl] cleanup texture API
This commit is contained in:
parent
00658f3d64
commit
884ad6557b
@ -282,19 +282,17 @@ bool egl_render(void * opaque, SDL_Window * window)
|
|||||||
if (this->sourceChanged)
|
if (this->sourceChanged)
|
||||||
{
|
{
|
||||||
this->sourceChanged = false;
|
this->sourceChanged = false;
|
||||||
egl_texture_init_streaming(
|
if (!egl_texture_init_streaming(
|
||||||
this->textures.desktop,
|
this->textures.desktop,
|
||||||
this->format.width,
|
this->format.width,
|
||||||
this->format.height,
|
this->format.height,
|
||||||
this->frameSize
|
this->frameSize
|
||||||
);
|
))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
egl_texture_stream_buffer(
|
if (!egl_texture_stream_buffer(this->textures.desktop, this->data))
|
||||||
this->textures.desktop,
|
return false;
|
||||||
this->data,
|
|
||||||
this->frameSize
|
|
||||||
);
|
|
||||||
|
|
||||||
this->update = false;
|
this->update = false;
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,11 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
struct EGL_Texture
|
struct EGL_Texture
|
||||||
{
|
{
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
|
size_t width, height;
|
||||||
|
|
||||||
bool hasPBO;
|
bool hasPBO;
|
||||||
GLuint pbo[2];
|
GLuint pbo[2];
|
||||||
int pboIndex;
|
int pboIndex;
|
||||||
size_t pboWidth, pboHeight;
|
|
||||||
size_t pboBufferSize;
|
size_t pboBufferSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,8 +69,9 @@ void egl_texture_free(EGL_Texture ** texture)
|
|||||||
|
|
||||||
bool egl_texture_init_streaming(EGL_Texture * texture, size_t width, size_t height, size_t bufferSize)
|
bool egl_texture_init_streaming(EGL_Texture * texture, size_t width, size_t height, size_t bufferSize)
|
||||||
{
|
{
|
||||||
texture->pboWidth = width;
|
texture->width = width;
|
||||||
texture->pboHeight = height;
|
texture->height = height;
|
||||||
|
texture->pboBufferSize = bufferSize;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->texture);
|
glBindTexture(GL_TEXTURE_2D, texture->texture);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
@ -80,7 +82,10 @@ bool egl_texture_init_streaming(EGL_Texture * texture, size_t width, size_t heig
|
|||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
if (!texture->hasPBO)
|
if (!texture->hasPBO)
|
||||||
|
{
|
||||||
glGenBuffers(2, texture->pbo);
|
glGenBuffers(2, texture->pbo);
|
||||||
|
texture->hasPBO = true;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 2; ++i)
|
for(int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
@ -94,25 +99,19 @@ bool egl_texture_init_streaming(EGL_Texture * texture, size_t width, size_t heig
|
|||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
texture->hasPBO = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool egl_texture_is_streaming(EGL_Texture * texture)
|
bool egl_texture_stream_buffer(EGL_Texture * texture, const uint8_t * buffer)
|
||||||
{
|
|
||||||
return texture->hasPBO;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool egl_texture_stream_buffer(EGL_Texture * texture, const uint8_t * buffer, size_t bufferSize)
|
|
||||||
{
|
{
|
||||||
if (++texture->pboIndex == 2)
|
if (++texture->pboIndex == 2)
|
||||||
texture->pboIndex = 0;
|
texture->pboIndex = 0;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->texture);
|
glBindTexture(GL_TEXTURE_2D, texture->texture);
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[texture->pboIndex]);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[texture->pboIndex]);
|
||||||
glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, 0, GL_DYNAMIC_DRAW);
|
glBufferData(GL_PIXEL_UNPACK_BUFFER, texture->pboBufferSize, 0, GL_DYNAMIC_DRAW);
|
||||||
glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, bufferSize, buffer);
|
glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, texture->pboBufferSize, buffer);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->pboWidth, texture->pboHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->width, texture->height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
@ -31,6 +31,5 @@ bool egl_texture_init(EGL_Texture ** tex);
|
|||||||
void egl_texture_free(EGL_Texture ** tex);
|
void egl_texture_free(EGL_Texture ** tex);
|
||||||
|
|
||||||
bool egl_texture_init_streaming(EGL_Texture * texture, size_t width, size_t height, size_t bufferSize);
|
bool egl_texture_init_streaming(EGL_Texture * texture, size_t width, size_t height, size_t bufferSize);
|
||||||
bool egl_texture_is_streaming (EGL_Texture * texture);
|
bool egl_texture_stream_buffer (EGL_Texture * texture, const uint8_t * buffer);
|
||||||
bool egl_texture_stream_buffer (EGL_Texture * texture, const uint8_t * buffer, size_t bufferSize);
|
|
||||||
void egl_texture_bind (EGL_Texture * texture);
|
void egl_texture_bind (EGL_Texture * texture);
|
Loading…
Reference in New Issue
Block a user