Common/GL: Add replace method to texture

This commit is contained in:
Connor McLaughlin 2020-12-25 18:01:39 +10:00
parent ecbfff3c60
commit ebaad0f35a
2 changed files with 14 additions and 1 deletions

View file

@ -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());

View file

@ -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();