summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/TextureCache.cpp
diff options
context:
space:
mode:
authorMarkus Wick <markus+github@selfnet.de>2015-01-19 00:12:22 +0100
committerMarkus Wick <markus+github@selfnet.de>2015-01-19 00:12:22 +0100
commit5357b9c95ff2458e3b8c3112e303924a0d460ce6 (patch)
treeda7ceb7f8c1d4b8c9d08182d14ecf1edfe94589c /Source/Core/VideoBackends/OGL/TextureCache.cpp
parent37a770bb9f23404cbdc75e8cc2df31dfecb97057 (diff)
parent9f13a77799bc8d91e3022f334900ffb542bc1b43 (diff)
Merge pull request #1899 from degasus/texcache
Texture Pool
Diffstat (limited to 'Source/Core/VideoBackends/OGL/TextureCache.cpp')
-rw-r--r--Source/Core/VideoBackends/OGL/TextureCache.cpp133
1 files changed, 21 insertions, 112 deletions
diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp
index 241b73f719..1f12d5c148 100644
--- a/Source/Core/VideoBackends/OGL/TextureCache.cpp
+++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp
@@ -109,80 +109,28 @@ bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int l
return SaveTexture(filename, GL_TEXTURE_2D_ARRAY, texture, config.width, config.height, level);
}
-TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width, unsigned int height,
- unsigned int tex_levels, PC_TexFormat pcfmt)
+TextureCache::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntryConfig& config)
{
- int gl_format = 0,
- gl_iformat = 0,
- gl_type = 0;
+ TCacheEntry* entry = new TCacheEntry(config);
- if (pcfmt != PC_TEX_FMT_DXT1)
+ glActiveTexture(GL_TEXTURE0+9);
+ glBindTexture(GL_TEXTURE_2D_ARRAY, entry->texture);
+
+ glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, config.levels - 1);
+
+ if (config.rendertarget)
{
- switch (pcfmt)
+ for (u32 level = 0; level <= config.levels; level++)
{
- default:
- case PC_TEX_FMT_NONE:
- PanicAlert("Invalid PC texture format %i", pcfmt);
- case PC_TEX_FMT_BGRA32:
- gl_format = GL_BGRA;
- gl_iformat = GL_RGBA;
- gl_type = GL_UNSIGNED_BYTE;
- break;
-
- case PC_TEX_FMT_RGBA32:
- gl_format = GL_RGBA;
- gl_iformat = GL_RGBA;
- gl_type = GL_UNSIGNED_BYTE;
- break;
- case PC_TEX_FMT_I4_AS_I8:
- gl_format = GL_LUMINANCE;
- gl_iformat = GL_INTENSITY4;
- gl_type = GL_UNSIGNED_BYTE;
- break;
-
- case PC_TEX_FMT_IA4_AS_IA8:
- gl_format = GL_LUMINANCE_ALPHA;
- gl_iformat = GL_LUMINANCE4_ALPHA4;
- gl_type = GL_UNSIGNED_BYTE;
- break;
-
- case PC_TEX_FMT_I8:
- gl_format = GL_LUMINANCE;
- gl_iformat = GL_INTENSITY8;
- gl_type = GL_UNSIGNED_BYTE;
- break;
-
- case PC_TEX_FMT_IA8:
- gl_format = GL_LUMINANCE_ALPHA;
- gl_iformat = GL_LUMINANCE8_ALPHA8;
- gl_type = GL_UNSIGNED_BYTE;
- break;
- case PC_TEX_FMT_RGB565:
- gl_format = GL_RGB;
- gl_iformat = GL_RGB;
- gl_type = GL_UNSIGNED_SHORT_5_6_5;
- break;
+ glTexImage3D(GL_TEXTURE_2D_ARRAY, level, GL_RGBA, config.width, config.height, config.layers, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
}
+ glGenFramebuffers(1, &entry->framebuffer);
+ FramebufferManager::SetFramebuffer(entry->framebuffer);
+ FramebufferManager::FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY, entry->texture, 0);
}
- TCacheEntryConfig config;
- config.width = width;
- config.height = height;
- config.levels = tex_levels;
-
- TCacheEntry &entry = *new TCacheEntry(config);
- entry.gl_format = gl_format;
- entry.gl_iformat = gl_iformat;
- entry.gl_type = gl_type;
- entry.pcfmt = pcfmt;
-
- glActiveTexture(GL_TEXTURE0+9);
- glBindTexture(GL_TEXTURE_2D_ARRAY, entry.texture);
- glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, tex_levels - 1);
-
TextureCache::SetStage();
-
- return &entry;
+ return entry;
}
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
@@ -194,57 +142,18 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
PanicAlert("size of level %d must be %dx%d, but %dx%d requested",
level, std::max(1u, config.width >> level), std::max(1u, config.height >> level), width, height);
- if (pcfmt != PC_TEX_FMT_DXT1)
- {
- glActiveTexture(GL_TEXTURE0+9);
- glBindTexture(GL_TEXTURE_2D_ARRAY, texture);
-
- if (expanded_width != width)
- glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
-
- glTexImage3D(GL_TEXTURE_2D_ARRAY, level, gl_iformat, width, height, 1, 0, gl_format, gl_type, temp);
-
- if (expanded_width != width)
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
- }
- else
- {
- PanicAlert("PC_TEX_FMT_DXT1 support disabled");
- //glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
- //width, height, 0, expanded_width * expanded_height/2, temp);
- }
- TextureCache::SetStage();
-}
-
-TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
- unsigned int scaled_tex_w, unsigned int scaled_tex_h, unsigned int layers)
-{
- TCacheEntryConfig config;
- config.width = scaled_tex_w;
- config.height = scaled_tex_h;
- config.layers = layers;
- config.rendertarget = true;
- TCacheEntry *const entry = new TCacheEntry(config);
-
glActiveTexture(GL_TEXTURE0+9);
- glBindTexture(GL_TEXTURE_2D_ARRAY, entry->texture);
+ glBindTexture(GL_TEXTURE_2D_ARRAY, texture);
- const GLenum
- gl_format = GL_RGBA,
- gl_iformat = GL_RGBA,
- gl_type = GL_UNSIGNED_BYTE;
+ if (expanded_width != width)
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
- glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
- glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, gl_iformat, scaled_tex_w, scaled_tex_h, layers, 0, gl_format, gl_type, nullptr);
- glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
+ glTexImage3D(GL_TEXTURE_2D_ARRAY, level, GL_RGBA, width, height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp);
- glGenFramebuffers(1, &entry->framebuffer);
- FramebufferManager::SetFramebuffer(entry->framebuffer);
- FramebufferManager::FramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_ARRAY, entry->texture, 0);
+ if (expanded_width != width)
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
- SetStage();
-
- return entry;
+ TextureCache::SetStage();
}
void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat,