VideoBackends / VideoCommon: add type enum to dictate whether a texture is a 2D texture, a texture array, or a cube map; support 2D texture type across backends

Co-authored-by: TellowKrinkle <tellowkrinkle@gmail.com>
This commit is contained in:
iwubcode
2023-12-09 19:00:11 -06:00
parent 370474a7cb
commit 12dd15c8dd
16 changed files with 271 additions and 81 deletions

View File

@ -140,29 +140,61 @@ OGLTexture::OGLTexture(const TextureConfig& tex_config, std::string_view name)
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, m_config.levels - 1);
GLenum gl_internal_format = GetGLInternalFormatForTextureFormat(m_config.format, true);
if (g_ogl_config.bSupportsTextureStorage && m_config.IsCubeMap())
if (g_ogl_config.bSupportsTextureStorage && m_config.type == AbstractTextureType::Texture_CubeMap)
{
glTexStorage2D(target, m_config.levels, gl_internal_format, m_config.width, m_config.height);
}
else if (tex_config.IsMultisampled())
{
ASSERT(g_ogl_config.bSupportsMSAA);
if (g_ogl_config.SupportedMultisampleTexStorage != MultisampleTexStorageType::TexStorageNone)
if (m_config.type == AbstractTextureType::Texture_2DArray)
{
glTexStorage3DMultisample(target, tex_config.samples, gl_internal_format, m_config.width,
if (g_ogl_config.SupportedMultisampleTexStorage != MultisampleTexStorageType::TexStorageNone)
{
glTexStorage3DMultisample(target, tex_config.samples, gl_internal_format, m_config.width,
m_config.height, m_config.layers, GL_FALSE);
}
else
{
ASSERT(!g_ogl_config.bIsES);
glTexImage3DMultisample(target, tex_config.samples, gl_internal_format, m_config.width,
m_config.height, m_config.layers, GL_FALSE);
}
}
else if (m_config.type == AbstractTextureType::Texture_2D)
{
if (g_ogl_config.SupportedMultisampleTexStorage != MultisampleTexStorageType::TexStorageNone)
{
glTexStorage2DMultisample(target, tex_config.samples, gl_internal_format, m_config.width,
m_config.height, GL_FALSE);
}
else
{
ASSERT(!g_ogl_config.bIsES);
glTexImage2DMultisample(target, tex_config.samples, gl_internal_format, m_config.width,
m_config.height, GL_FALSE);
}
}
else
{
ASSERT(!g_ogl_config.bIsES);
glTexImage3DMultisample(target, tex_config.samples, gl_internal_format, m_config.width,
m_config.height, m_config.layers, GL_FALSE);
ASSERT(false);
}
}
else if (g_ogl_config.bSupportsTextureStorage)
{
glTexStorage3D(target, m_config.levels, gl_internal_format, m_config.width, m_config.height,
m_config.layers);
if (m_config.type == AbstractTextureType::Texture_2DArray)
{
glTexStorage3D(target, m_config.levels, gl_internal_format, m_config.width, m_config.height,
m_config.layers);
}
else if (m_config.type == AbstractTextureType::Texture_2D)
{
glTexStorage2D(target, m_config.levels, gl_internal_format, m_config.width, m_config.height);
}
else
{
ASSERT(false);
}
}
if (m_config.IsRenderTarget())
@ -271,7 +303,7 @@ void OGLTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8
GLenum gl_internal_format = GetGLInternalFormatForTextureFormat(m_config.format, false);
if (IsCompressedFormat(m_config.format))
{
if (m_config.IsCubeMap())
if (m_config.type == AbstractTextureType::Texture_CubeMap)
{
if (g_ogl_config.bSupportsTextureStorage)
{
@ -285,7 +317,20 @@ void OGLTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8
width, height, 0, static_cast<GLsizei>(buffer_size), buffer);
}
}
else
else if (m_config.type == AbstractTextureType::Texture_2D)
{
if (g_ogl_config.bSupportsTextureStorage)
{
glCompressedTexSubImage2D(target, level, 0, 0, width, height, gl_internal_format,
static_cast<GLsizei>(buffer_size), buffer);
}
else
{
glCompressedTexImage2D(target, level, gl_internal_format, width, height, 0,
static_cast<GLsizei>(buffer_size), buffer);
}
}
else if (m_config.type == AbstractTextureType::Texture_2DArray)
{
if (g_ogl_config.bSupportsTextureStorage)
{
@ -298,12 +343,16 @@ void OGLTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8
static_cast<GLsizei>(buffer_size), buffer);
}
}
else
{
PanicAlertFmt("Failed to handle compressed texture load - unhandled type");
}
}
else
{
GLenum gl_format = GetGLFormatForTextureFormat(m_config.format);
GLenum gl_type = GetGLTypeForTextureFormat(m_config.format);
if (m_config.IsCubeMap())
if (m_config.type == AbstractTextureType::Texture_CubeMap)
{
if (g_ogl_config.bSupportsTextureStorage)
{
@ -316,7 +365,19 @@ void OGLTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8
height, 0, gl_format, gl_type, buffer);
}
}
else
else if (m_config.type == AbstractTextureType::Texture_2D)
{
if (g_ogl_config.bSupportsTextureStorage)
{
glTexSubImage2D(target, level, 0, 0, width, height, gl_format, gl_type, buffer);
}
else
{
glTexImage2D(target, level, gl_internal_format, width, height, 0, gl_format, gl_type,
buffer);
}
}
else if (m_config.type == AbstractTextureType::Texture_2DArray)
{
if (g_ogl_config.bSupportsTextureStorage)
{
@ -328,6 +389,10 @@ void OGLTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8
buffer);
}
}
else
{
PanicAlertFmt("Failed to handle texture load - unhandled type");
}
}
if (row_length != width)