mirror of
https://github.com/PabloMK7/citra.git
synced 2025-09-12 05:40:04 +00:00
rasterizer_cache: Remove remaining OpenGL code
This commit is contained in:
parent
fc450edd14
commit
1579f96397
5 changed files with 77 additions and 140 deletions
|
@ -717,27 +717,21 @@ bool RasterizerOpenGL::Draw(bool accelerate, bool is_indexed) {
|
|||
}
|
||||
|
||||
OGLTexture temp_tex;
|
||||
if (need_duplicate_texture && (GLAD_GL_ARB_copy_image || GLES)) {
|
||||
if (need_duplicate_texture) {
|
||||
const auto& tuple = GetFormatTuple(color_surface->pixel_format);
|
||||
const GLsizei levels = color_surface->max_level + 1;
|
||||
|
||||
// The game is trying to use a surface as a texture and framebuffer at the same time
|
||||
// which causes unpredictable behavior on the host.
|
||||
// Making a copy to sample from eliminates this issue and seems to be fairly cheap.
|
||||
temp_tex.Create();
|
||||
glBindTexture(GL_TEXTURE_2D, temp_tex.handle);
|
||||
auto [internal_format, format, type] = GetFormatTuple(color_surface->pixel_format);
|
||||
OGLTexture::Allocate(GL_TEXTURE_2D, color_surface->max_level + 1, internal_format, format,
|
||||
type, color_surface->GetScaledWidth(),
|
||||
color_surface->GetScaledHeight());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glBindTexture(GL_TEXTURE_2D, state.texture_units[0].texture_2d);
|
||||
temp_tex.Allocate(GL_TEXTURE_2D, levels, tuple.internal_format,
|
||||
color_surface->GetScaledWidth(),
|
||||
color_surface->GetScaledHeight());
|
||||
|
||||
for (u32 level{0}; level <= color_surface->max_level; ++level) {
|
||||
glCopyImageSubData(color_surface->texture.handle, GL_TEXTURE_2D, level, 0, 0, 0,
|
||||
temp_tex.handle, GL_TEXTURE_2D, level, 0, 0, 0,
|
||||
color_surface->GetScaledWidth() >> level,
|
||||
color_surface->GetScaledHeight() >> level, 1);
|
||||
}
|
||||
temp_tex.CopyFrom(color_surface->texture, GL_TEXTURE_2D, levels,
|
||||
color_surface->GetScaledWidth(),
|
||||
color_surface->GetScaledHeight());
|
||||
|
||||
for (auto& unit : state.texture_units) {
|
||||
if (unit.texture_2d == color_surface->texture.handle) {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
#include "video_core/renderer_opengl/gl_state.h"
|
||||
#include "video_core/renderer_opengl/gl_vars.h"
|
||||
|
||||
MICROPROFILE_DEFINE(OpenGL_ResourceCreation, "OpenGL", "Resource Creation", MP_RGB(128, 128, 192));
|
||||
MICROPROFILE_DEFINE(OpenGL_ResourceDeletion, "OpenGL", "Resource Deletion", MP_RGB(128, 128, 192));
|
||||
|
@ -14,16 +13,18 @@ MICROPROFILE_DEFINE(OpenGL_ResourceDeletion, "OpenGL", "Resource Deletion", MP_R
|
|||
namespace OpenGL {
|
||||
|
||||
void OGLRenderbuffer::Create() {
|
||||
if (handle != 0)
|
||||
if (handle != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
|
||||
glGenRenderbuffers(1, &handle);
|
||||
}
|
||||
|
||||
void OGLRenderbuffer::Release() {
|
||||
if (handle == 0)
|
||||
if (handle == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
|
||||
glDeleteRenderbuffers(1, &handle);
|
||||
|
@ -32,16 +33,18 @@ void OGLRenderbuffer::Release() {
|
|||
}
|
||||
|
||||
void OGLTexture::Create() {
|
||||
if (handle != 0)
|
||||
if (handle != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
|
||||
glGenTextures(1, &handle);
|
||||
}
|
||||
|
||||
void OGLTexture::Release() {
|
||||
if (handle == 0)
|
||||
if (handle == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
|
||||
glDeleteTextures(1, &handle);
|
||||
|
@ -49,73 +52,66 @@ void OGLTexture::Release() {
|
|||
handle = 0;
|
||||
}
|
||||
|
||||
void OGLTexture::Allocate(GLenum target, GLsizei levels, GLenum internalformat, GLenum format,
|
||||
GLenum type, GLsizei width, GLsizei height, GLsizei depth) {
|
||||
const bool tex_storage = GLAD_GL_ARB_texture_storage || GLES;
|
||||
void OGLTexture::Allocate(GLenum target, GLsizei levels, GLenum internalformat,
|
||||
GLsizei width, GLsizei height, GLsizei depth) {
|
||||
GLuint old_tex = OpenGLState::GetCurState().texture_units[0].texture_2d;
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, handle);
|
||||
|
||||
switch (target) {
|
||||
case GL_TEXTURE_1D:
|
||||
case GL_TEXTURE:
|
||||
if (tex_storage) {
|
||||
glTexStorage1D(target, levels, internalformat, width);
|
||||
} else {
|
||||
for (GLsizei level{0}; level < levels; ++level) {
|
||||
glTexImage1D(target, level, internalformat, width, 0, format, type, nullptr);
|
||||
width >>= 1;
|
||||
}
|
||||
}
|
||||
glTexStorage1D(target, levels, internalformat, width);
|
||||
break;
|
||||
case GL_TEXTURE_2D:
|
||||
case GL_TEXTURE_1D_ARRAY:
|
||||
case GL_TEXTURE_RECTANGLE:
|
||||
case GL_TEXTURE_CUBE_MAP:
|
||||
if (tex_storage) {
|
||||
glTexStorage2D(target, levels, internalformat, width, height);
|
||||
} else {
|
||||
for (GLsizei level{0}; level < levels; ++level) {
|
||||
glTexImage2D(target, level, internalformat, width, height, 0, format, type,
|
||||
nullptr);
|
||||
width >>= 1;
|
||||
if (target != GL_TEXTURE_1D_ARRAY)
|
||||
height >>= 1;
|
||||
}
|
||||
}
|
||||
glTexStorage2D(target, levels, internalformat, width, height);
|
||||
break;
|
||||
case GL_TEXTURE_3D:
|
||||
case GL_TEXTURE_2D_ARRAY:
|
||||
case GL_TEXTURE_CUBE_MAP_ARRAY:
|
||||
if (tex_storage) {
|
||||
glTexStorage3D(target, levels, internalformat, width, height, depth);
|
||||
} else {
|
||||
for (GLsizei level{0}; level < levels; ++level) {
|
||||
glTexImage3D(target, level, internalformat, width, height, depth, 0, format, type,
|
||||
nullptr);
|
||||
|
||||
width >>= 1;
|
||||
height >>= 1;
|
||||
if (target == GL_TEXTURE_3D)
|
||||
depth >>= 1;
|
||||
}
|
||||
}
|
||||
glTexStorage3D(target, levels, internalformat, width, height, depth);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!tex_storage) {
|
||||
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels - 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, old_tex);
|
||||
}
|
||||
|
||||
void OGLTexture::CopyFrom(const OGLTexture& other, GLenum target, GLsizei levels,
|
||||
GLsizei width, GLsizei height) {
|
||||
GLuint old_tex = OpenGLState::GetCurState().texture_units[0].texture_2d;
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, handle);
|
||||
|
||||
for (u32 level = 0; level < levels; level++) {
|
||||
glCopyImageSubData(other.handle, target, level, 0, 0, 0,
|
||||
handle, target, level, 0, 0, 0,
|
||||
width >> level,
|
||||
height >> level, 1);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, old_tex);
|
||||
}
|
||||
|
||||
void OGLSampler::Create() {
|
||||
if (handle != 0)
|
||||
if (handle != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
|
||||
glGenSamplers(1, &handle);
|
||||
}
|
||||
|
||||
void OGLSampler::Release() {
|
||||
if (handle == 0)
|
||||
if (handle == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
|
||||
glDeleteSamplers(1, &handle);
|
||||
|
|
|
@ -58,8 +58,11 @@ public:
|
|||
/// Deletes the internal OpenGL resource
|
||||
void Release();
|
||||
|
||||
static void Allocate(GLenum target, GLsizei levels, GLenum internalformat, GLenum format,
|
||||
GLenum type, GLsizei width, GLsizei height = 1, GLsizei depth = 1);
|
||||
void Allocate(GLenum target, GLsizei levels, GLenum internalformat,
|
||||
GLsizei width, GLsizei height = 1, GLsizei depth = 1);
|
||||
|
||||
void CopyFrom(const OGLTexture& other, GLenum target, GLsizei levels,
|
||||
GLsizei width, GLsizei height);
|
||||
|
||||
GLuint handle = 0;
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <vector>
|
||||
#include <fmt/chrono.h>
|
||||
#include "common/logging/log.h"
|
||||
#include "video_core/rasterizer_cache/rasterizer_cache.h"
|
||||
#include "video_core/rasterizer_cache/rasterizer_cache_utils.h"
|
||||
#include "video_core/renderer_opengl/gl_state.h"
|
||||
#include "video_core/renderer_opengl/texture_downloader_es.h"
|
||||
#include "shaders/depth_to_color.frag"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue