From ebaad0f35a1af5ba4d77501f38b9a542af9de129 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 25 Dec 2020 18:01:39 +1000 Subject: [PATCH] Common/GL: Add replace method to texture --- src/common/gl/texture.cpp | 14 +++++++++++++- src/common/gl/texture.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/common/gl/texture.cpp b/src/common/gl/texture.cpp index 416c40d23..065991cc3 100644 --- a/src/common/gl/texture.cpp +++ b/src/common/gl/texture.cpp @@ -36,6 +36,7 @@ bool Texture::Create(u32 width, u32 height, u32 samples, GLenum internal_format, if (samples > 1) { + Assert(!data); if (GLAD_GL_ARB_texture_storage || GLAD_GL_ES_VERSION_3_1) glTexStorage2DMultisample(target, samples, internal_format, width, height, GL_FALSE); else @@ -43,7 +44,7 @@ bool Texture::Create(u32 width, u32 height, u32 samples, GLenum internal_format, } else { - if (GLAD_GL_ARB_texture_storage || GLAD_GL_ES_VERSION_3_0) + if ((GLAD_GL_ARB_texture_storage || GLAD_GL_ES_VERSION_3_0) && !data) glTexStorage2D(target, 1, internal_format, width, height); else glTexImage2D(target, 0, internal_format, width, height, 0, format, type, data); @@ -74,6 +75,17 @@ bool Texture::Create(u32 width, u32 height, u32 samples, GLenum internal_format, return true; } +void Texture::Replace(u32 width, u32 height, GLenum internal_format, GLenum format, GLenum type, const void* data) +{ + Assert(IsValid() && m_samples == 1); + + m_width = width; + m_height = height; + + glBindTexture(GL_TEXTURE_2D, m_id); + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, type, data); +} + void Texture::SetLinearFilter(bool enabled) { Assert(!IsMultisampled()); diff --git a/src/common/gl/texture.h b/src/common/gl/texture.h index 3a8102fda..1a7016a09 100644 --- a/src/common/gl/texture.h +++ b/src/common/gl/texture.h @@ -12,6 +12,7 @@ public: bool Create(u32 width, u32 height, u32 samples, GLenum internal_format, GLenum format, GLenum type, const void* data = nullptr, bool linear_filter = false, bool wrap = false); + void Replace(u32 width, u32 height, GLenum internal_format, GLenum format, GLenum type, const void* data); bool CreateFramebuffer(); void Destroy();