From 4cfe47486170527051e68156cc1afe504c0aef94 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 13 May 2021 16:37:58 +1000 Subject: [PATCH] opengl: wrap uploading to 3D textures Probably won't ever need this, but it felt appropriate --- app/render/opengl/openglrenderer.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/render/opengl/openglrenderer.cpp b/app/render/opengl/openglrenderer.cpp index 85e73e038..c72446c03 100644 --- a/app/render/opengl/openglrenderer.cpp +++ b/app/render/opengl/openglrenderer.cpp @@ -293,22 +293,32 @@ void OpenGLRenderer::UploadToTexture(Texture *texture, const void *data, int lin GLuint t = texture->id().value(); const VideoParams& p = texture->params(); + GLenum tex_type = texture->type() == Texture::k2D ? GL_TEXTURE_2D : GL_TEXTURE_3D; + GLenum tex_binding = texture->type() == Texture::k2D ? GL_TEXTURE_BINDING_2D : GL_TEXTURE_BINDING_3D; + // Store currently bound texture so it can be restored later GLint current_tex; - functions_->glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); + functions_->glGetIntegerv(tex_binding, ¤t_tex); - functions_->glBindTexture(GL_TEXTURE_2D, t); + functions_->glBindTexture(tex_type, t); functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize); - functions_->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, - p.effective_width(), p.effective_height(), - GetPixelFormat(p.channel_count()), GetPixelType(p.format()), - data); + if (texture->type() == Texture::k2D) { + functions_->glTexSubImage2D(tex_type, 0, 0, 0, + p.effective_width(), p.effective_height(), + GetPixelFormat(p.channel_count()), GetPixelType(p.format()), + data); + } else { + context_->extraFunctions()->glTexSubImage3D(tex_type, 0, 0, 0, 0, + p.effective_width(), p.effective_height(), p.effective_depth(), + GetPixelFormat(p.channel_count()), GetPixelType(p.format()), + data); + } functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - functions_->glBindTexture(GL_TEXTURE_2D, current_tex); + functions_->glBindTexture(tex_type, current_tex); } void OpenGLRenderer::DownloadFromTexture(Texture* texture, void *data, int linesize)