From 884ad6557b7e54edbea9d0924e56db43c263d90d Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 23 Sep 2018 15:56:47 +1000 Subject: [PATCH] [egl] cleanup texture API --- client/renderers/egl.c | 12 +++++------- client/renderers/egl_texture.c | 25 ++++++++++++------------- client/renderers/egl_texture.h | 3 +-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/client/renderers/egl.c b/client/renderers/egl.c index 0dff3814..ae845575 100644 --- a/client/renderers/egl.c +++ b/client/renderers/egl.c @@ -282,19 +282,17 @@ bool egl_render(void * opaque, SDL_Window * window) if (this->sourceChanged) { this->sourceChanged = false; - egl_texture_init_streaming( + if (!egl_texture_init_streaming( this->textures.desktop, this->format.width, this->format.height, this->frameSize - ); + )) + return false; } - egl_texture_stream_buffer( - this->textures.desktop, - this->data, - this->frameSize - ); + if (!egl_texture_stream_buffer(this->textures.desktop, this->data)) + return false; this->update = false; } diff --git a/client/renderers/egl_texture.c b/client/renderers/egl_texture.c index 29572b39..33b2c39e 100644 --- a/client/renderers/egl_texture.c +++ b/client/renderers/egl_texture.c @@ -30,10 +30,11 @@ Place, Suite 330, Boston, MA 02111-1307 USA struct EGL_Texture { GLuint texture; + size_t width, height; + bool hasPBO; GLuint pbo[2]; int pboIndex; - size_t pboWidth, pboHeight; 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) { - texture->pboWidth = width; - texture->pboHeight = height; + texture->width = width; + texture->height = height; + texture->pboBufferSize = bufferSize; glBindTexture(GL_TEXTURE_2D, texture->texture); 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); if (!texture->hasPBO) + { glGenBuffers(2, texture->pbo); + texture->hasPBO = true; + } 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); } - texture->hasPBO = true; return true; } -bool egl_texture_is_streaming(EGL_Texture * texture) -{ - return texture->hasPBO; -} - -bool egl_texture_stream_buffer(EGL_Texture * texture, const uint8_t * buffer, size_t bufferSize) +bool egl_texture_stream_buffer(EGL_Texture * texture, const uint8_t * buffer) { if (++texture->pboIndex == 2) texture->pboIndex = 0; glBindTexture(GL_TEXTURE_2D, texture->texture); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture->pbo[texture->pboIndex]); - glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, 0, GL_DYNAMIC_DRAW); - glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, bufferSize, buffer); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->pboWidth, texture->pboHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); + glBufferData(GL_PIXEL_UNPACK_BUFFER, texture->pboBufferSize, 0, GL_DYNAMIC_DRAW); + glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, texture->pboBufferSize, buffer); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->width, texture->height, GL_RGBA, GL_UNSIGNED_BYTE, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); diff --git a/client/renderers/egl_texture.h b/client/renderers/egl_texture.h index 4566fae2..8dc5d0d1 100644 --- a/client/renderers/egl_texture.h +++ b/client/renderers/egl_texture.h @@ -31,6 +31,5 @@ bool egl_texture_init(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_is_streaming (EGL_Texture * texture); -bool egl_texture_stream_buffer (EGL_Texture * texture, const uint8_t * buffer, size_t bufferSize); +bool egl_texture_stream_buffer (EGL_Texture * texture, const uint8_t * buffer); void egl_texture_bind (EGL_Texture * texture); \ No newline at end of file