generate mipmaps (for now)

This commit is contained in:
Khangaroo 2019-08-09 12:57:05 -04:00 committed by James Rowe
parent f09489475a
commit 650fe6447d
2 changed files with 32 additions and 17 deletions

View file

@ -948,7 +948,6 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
bool dump_tex = false; bool dump_tex = false;
bool use_custom_tex = false; bool use_custom_tex = false;
std::string dump_path; // Has to be declared here for logging later std::string dump_path; // Has to be declared here for logging later
Core::CustomTexInfo custom_tex_info;
u64 tex_hash = 0; u64 tex_hash = 0;
Common::Rectangle custom_rect = Common::Rectangle custom_rect =
rect; // Required for rect to function properly with custom textures rect; // Required for rect to function properly with custom textures
@ -957,7 +956,7 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
tex_hash = Common::ComputeHash64(gl_buffer.get(), gl_buffer_size); tex_hash = Common::ComputeHash64(gl_buffer.get(), gl_buffer_size);
if (Settings::values.custom_textures) if (Settings::values.custom_textures)
use_custom_tex = LoadCustomTexture(tex_hash, custom_tex_info, custom_rect); is_custom = use_custom_tex = LoadCustomTexture(tex_hash, custom_tex_info, custom_rect);
if (Settings::values.dump_textures && !use_custom_tex) { if (Settings::values.dump_textures && !use_custom_tex) {
auto temp_dump_path = GetDumpPath(tex_hash); auto temp_dump_path = GetDumpPath(tex_hash);
@ -1541,12 +1540,23 @@ Surface RasterizerCacheOpenGL::GetTextureSurface(const Pica::Texture::TextureInf
state.Apply(); state.Apply();
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, max_level); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, max_level);
u32 width = surface->width * surface->res_scale; u32 width;
u32 height = surface->height * surface->res_scale; u32 height;
if (surface->is_custom) {
width = surface->custom_tex_info.width;
height = surface->custom_tex_info.height;
} else {
width = surface->width * surface->res_scale;
height = surface->height * surface->res_scale;
}
for (u32 level = surface->max_level + 1; level <= max_level; ++level) { for (u32 level = surface->max_level + 1; level <= max_level; ++level) {
glTexImage2D(GL_TEXTURE_2D, level, format_tuple.internal_format, width >> level, glTexImage2D(GL_TEXTURE_2D, level, format_tuple.internal_format, width >> level,
height >> level, 0, format_tuple.format, format_tuple.type, nullptr); height >> level, 0, format_tuple.format, format_tuple.type, nullptr);
} }
if (surface->is_custom) {
// TODO: proper mipmap support for custom textures
glGenerateMipmap(GL_TEXTURE_2D);
}
surface->max_level = max_level; surface->max_level = max_level;
} }
@ -1579,6 +1589,7 @@ Surface RasterizerCacheOpenGL::GetTextureSurface(const Pica::Texture::TextureInf
} }
state.ResetTexture(level_surface->texture.handle); state.ResetTexture(level_surface->texture.handle);
state.Apply(); state.Apply();
if (!surface->is_custom) {
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
level_surface->texture.handle, 0); level_surface->texture.handle, 0);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
@ -1594,6 +1605,7 @@ Surface RasterizerCacheOpenGL::GetTextureSurface(const Pica::Texture::TextureInf
glBlitFramebuffer(src_rect.left, src_rect.bottom, src_rect.right, src_rect.top, glBlitFramebuffer(src_rect.left, src_rect.bottom, src_rect.right, src_rect.top,
dst_rect.left, dst_rect.bottom, dst_rect.right, dst_rect.top, dst_rect.left, dst_rect.bottom, dst_rect.right, dst_rect.top,
GL_COLOR_BUFFER_BIT, GL_LINEAR); GL_COLOR_BUFFER_BIT, GL_LINEAR);
}
watcher->Validate(); watcher->Validate();
} }
} }

View file

@ -362,6 +362,9 @@ struct CachedSurface : SurfaceParams, std::enable_shared_from_this<CachedSurface
/// level_watchers[i] watches the (i+1)-th level mipmap source surface /// level_watchers[i] watches the (i+1)-th level mipmap source surface
std::array<std::shared_ptr<SurfaceWatcher>, 7> level_watchers; std::array<std::shared_ptr<SurfaceWatcher>, 7> level_watchers;
bool is_custom = false;
Core::CustomTexInfo custom_tex_info;
static constexpr unsigned int GetGLBytesPerPixel(PixelFormat format) { static constexpr unsigned int GetGLBytesPerPixel(PixelFormat format) {
// OpenGL needs 4 bpp alignment for D24 since using GL_UNSIGNED_INT as type // OpenGL needs 4 bpp alignment for D24 since using GL_UNSIGNED_INT as type
return format == PixelFormat::Invalid return format == PixelFormat::Invalid