Port yuzu-emu/yuzu#1137: "renderer_opengl: Namespace OpenGL code" (#4423)

* renderer_opengl: Namespace OpenGL code

Namespaces all OpenGL code under the OpenGL namespace.

Prevents polluting the global namespace and allows clear distinction
between other renderers' code in the future.

* Also namespace TextureCubeConfig
This commit is contained in:
Tobias 2018-11-17 08:29:10 +01:00 committed by bunnei
parent 7f727177bf
commit 46e8237e7e
22 changed files with 166 additions and 125 deletions

View file

@ -7,7 +7,9 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hw/gpu.h" #include "core/hw/gpu.h"
namespace OpenGL {
struct ScreenInfo; struct ScreenInfo;
}
namespace Pica { namespace Pica {
namespace Shader { namespace Shader {
@ -63,7 +65,7 @@ public:
/// Attempt to use a faster method to display the framebuffer to screen /// Attempt to use a faster method to display the framebuffer to screen
virtual bool AccelerateDisplay(const GPU::Regs::FramebufferConfig& config, virtual bool AccelerateDisplay(const GPU::Regs::FramebufferConfig& config,
PAddr framebuffer_addr, u32 pixel_stride, PAddr framebuffer_addr, u32 pixel_stride,
ScreenInfo& screen_info) { OpenGL::ScreenInfo& screen_info) {
return false; return false;
} }

View file

@ -22,7 +22,7 @@ void RendererBase::RefreshRasterizerSetting() {
opengl_rasterizer_active = hw_renderer_enabled; opengl_rasterizer_active = hw_renderer_enabled;
if (hw_renderer_enabled) { if (hw_renderer_enabled) {
rasterizer = std::make_unique<RasterizerOpenGL>(render_window); rasterizer = std::make_unique<OpenGL::RasterizerOpenGL>(render_window);
} else { } else {
rasterizer = std::make_unique<VideoCore::SWRasterizer>(); rasterizer = std::make_unique<VideoCore::SWRasterizer>();
} }

View file

@ -25,6 +25,8 @@
#include "video_core/renderer_opengl/pica_to_gl.h" #include "video_core/renderer_opengl/pica_to_gl.h"
#include "video_core/renderer_opengl/renderer_opengl.h" #include "video_core/renderer_opengl/renderer_opengl.h"
namespace OpenGL {
using PixelFormat = SurfaceParams::PixelFormat; using PixelFormat = SurfaceParams::PixelFormat;
using SurfaceType = SurfaceParams::SurfaceType; using SurfaceType = SurfaceParams::SurfaceType;
@ -102,35 +104,35 @@ RasterizerOpenGL::RasterizerOpenGL(EmuWindow& window)
state.draw.vertex_buffer = vertex_buffer.GetHandle(); state.draw.vertex_buffer = vertex_buffer.GetHandle();
state.Apply(); state.Apply();
glVertexAttribPointer(GLShader::ATTRIBUTE_POSITION, 4, GL_FLOAT, GL_FALSE, glVertexAttribPointer(ATTRIBUTE_POSITION, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, position)); (GLvoid*)offsetof(HardwareVertex, position));
glEnableVertexAttribArray(GLShader::ATTRIBUTE_POSITION); glEnableVertexAttribArray(ATTRIBUTE_POSITION);
glVertexAttribPointer(GLShader::ATTRIBUTE_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), glVertexAttribPointer(ATTRIBUTE_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
(GLvoid*)offsetof(HardwareVertex, color)); (GLvoid*)offsetof(HardwareVertex, color));
glEnableVertexAttribArray(GLShader::ATTRIBUTE_COLOR); glEnableVertexAttribArray(ATTRIBUTE_COLOR);
glVertexAttribPointer(GLShader::ATTRIBUTE_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, glVertexAttribPointer(ATTRIBUTE_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, tex_coord0)); (GLvoid*)offsetof(HardwareVertex, tex_coord0));
glVertexAttribPointer(GLShader::ATTRIBUTE_TEXCOORD1, 2, GL_FLOAT, GL_FALSE, glVertexAttribPointer(ATTRIBUTE_TEXCOORD1, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, tex_coord1)); (GLvoid*)offsetof(HardwareVertex, tex_coord1));
glVertexAttribPointer(GLShader::ATTRIBUTE_TEXCOORD2, 2, GL_FLOAT, GL_FALSE, glVertexAttribPointer(ATTRIBUTE_TEXCOORD2, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, tex_coord2)); (GLvoid*)offsetof(HardwareVertex, tex_coord2));
glEnableVertexAttribArray(GLShader::ATTRIBUTE_TEXCOORD0); glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD0);
glEnableVertexAttribArray(GLShader::ATTRIBUTE_TEXCOORD1); glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD1);
glEnableVertexAttribArray(GLShader::ATTRIBUTE_TEXCOORD2); glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD2);
glVertexAttribPointer(GLShader::ATTRIBUTE_TEXCOORD0_W, 1, GL_FLOAT, GL_FALSE, glVertexAttribPointer(ATTRIBUTE_TEXCOORD0_W, 1, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, tex_coord0_w)); (GLvoid*)offsetof(HardwareVertex, tex_coord0_w));
glEnableVertexAttribArray(GLShader::ATTRIBUTE_TEXCOORD0_W); glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD0_W);
glVertexAttribPointer(GLShader::ATTRIBUTE_NORMQUAT, 4, GL_FLOAT, GL_FALSE, glVertexAttribPointer(ATTRIBUTE_NORMQUAT, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, normquat)); (GLvoid*)offsetof(HardwareVertex, normquat));
glEnableVertexAttribArray(GLShader::ATTRIBUTE_NORMQUAT); glEnableVertexAttribArray(ATTRIBUTE_NORMQUAT);
glVertexAttribPointer(GLShader::ATTRIBUTE_VIEW, 3, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), glVertexAttribPointer(ATTRIBUTE_VIEW, 3, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex),
(GLvoid*)offsetof(HardwareVertex, view)); (GLvoid*)offsetof(HardwareVertex, view));
glEnableVertexAttribArray(GLShader::ATTRIBUTE_VIEW); glEnableVertexAttribArray(ATTRIBUTE_VIEW);
// Create render framebuffer // Create render framebuffer
framebuffer.Create(); framebuffer.Create();
@ -367,7 +369,7 @@ void RasterizerOpenGL::SetupVertexArray(u8* array_ptr, GLintptr buffer_offset,
bool RasterizerOpenGL::SetupVertexShader() { bool RasterizerOpenGL::SetupVertexShader() {
MICROPROFILE_SCOPE(OpenGL_VS); MICROPROFILE_SCOPE(OpenGL_VS);
GLShader::PicaVSConfig vs_config(Pica::g_state.regs, Pica::g_state.vs); PicaVSConfig vs_config(Pica::g_state.regs, Pica::g_state.vs);
return shader_program_manager->UseProgrammableVertexShader(vs_config, Pica::g_state.vs); return shader_program_manager->UseProgrammableVertexShader(vs_config, Pica::g_state.vs);
} }
@ -375,11 +377,11 @@ bool RasterizerOpenGL::SetupGeometryShader() {
MICROPROFILE_SCOPE(OpenGL_GS); MICROPROFILE_SCOPE(OpenGL_GS);
const auto& regs = Pica::g_state.regs; const auto& regs = Pica::g_state.regs;
if (regs.pipeline.use_gs == Pica::PipelineRegs::UseGS::No) { if (regs.pipeline.use_gs == Pica::PipelineRegs::UseGS::No) {
GLShader::PicaFixedGSConfig gs_config(regs); PicaFixedGSConfig gs_config(regs);
shader_program_manager->UseFixedGeometryShader(gs_config); shader_program_manager->UseFixedGeometryShader(gs_config);
return true; return true;
} else { } else {
GLShader::PicaGSConfig gs_config(regs, Pica::g_state.gs); PicaGSConfig gs_config(regs, Pica::g_state.gs);
return shader_program_manager->UseProgrammableGeometryShader(gs_config, Pica::g_state.gs); return shader_program_manager->UseProgrammableGeometryShader(gs_config, Pica::g_state.gs);
} }
} }
@ -1588,7 +1590,7 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(
} }
void RasterizerOpenGL::SetShader() { void RasterizerOpenGL::SetShader() {
auto config = GLShader::PicaFSConfig::BuildFromRegs(Pica::g_state.regs); auto config = PicaFSConfig::BuildFromRegs(Pica::g_state.regs);
shader_program_manager->UseFragmentShader(config); shader_program_manager->UseFragmentShader(config);
} }
@ -2105,3 +2107,5 @@ void RasterizerOpenGL::UploadUniforms(bool accelerate_draw, bool use_gs) {
uniform_buffer.Unmap(used_bytes); uniform_buffer.Unmap(used_bytes);
} }
} // namespace OpenGL

View file

@ -30,9 +30,10 @@
#include "video_core/shader/shader.h" #include "video_core/shader/shader.h"
class EmuWindow; class EmuWindow;
struct ScreenInfo;
class ShaderProgramManager; class ShaderProgramManager;
namespace OpenGL {
class RasterizerOpenGL : public VideoCore::RasterizerInterface { class RasterizerOpenGL : public VideoCore::RasterizerInterface {
public: public:
explicit RasterizerOpenGL(EmuWindow& renderer); explicit RasterizerOpenGL(EmuWindow& renderer);
@ -307,3 +308,5 @@ private:
bool allow_shadow; bool allow_shadow;
}; };
} // namespace OpenGL

View file

@ -32,6 +32,8 @@
#include "video_core/utils.h" #include "video_core/utils.h"
#include "video_core/video_core.h" #include "video_core/video_core.h"
namespace OpenGL {
using SurfaceType = SurfaceParams::SurfaceType; using SurfaceType = SurfaceParams::SurfaceType;
using PixelFormat = SurfaceParams::PixelFormat; using PixelFormat = SurfaceParams::PixelFormat;
@ -1727,3 +1729,5 @@ void RasterizerCacheOpenGL::UpdatePagesCachedCount(PAddr addr, u32 size, int del
if (delta < 0) if (delta < 0)
cached_pages.add({pages_interval, delta}); cached_pages.add({pages_interval, delta});
} }
} // namespace OpenGL

View file

@ -31,6 +31,50 @@
#include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/texture/texture_decode.h" #include "video_core/texture/texture_decode.h"
namespace OpenGL {
struct TextureCubeConfig {
PAddr px;
PAddr nx;
PAddr py;
PAddr ny;
PAddr pz;
PAddr nz;
u32 width;
Pica::TexturingRegs::TextureFormat format;
bool operator==(const TextureCubeConfig& rhs) const {
return std::tie(px, nx, py, ny, pz, nz, width, format) ==
std::tie(rhs.px, rhs.nx, rhs.py, rhs.ny, rhs.pz, rhs.nz, rhs.width, rhs.format);
}
bool operator!=(const TextureCubeConfig& rhs) const {
return !(*this == rhs);
}
};
} // namespace OpenGL
namespace std {
template <>
struct hash<OpenGL::TextureCubeConfig> {
std::size_t operator()(const OpenGL::TextureCubeConfig& config) const {
std::size_t hash = 0;
boost::hash_combine(hash, config.px);
boost::hash_combine(hash, config.nx);
boost::hash_combine(hash, config.py);
boost::hash_combine(hash, config.ny);
boost::hash_combine(hash, config.pz);
boost::hash_combine(hash, config.nz);
boost::hash_combine(hash, config.width);
boost::hash_combine(hash, static_cast<u32>(config.format));
return hash;
}
};
} // namespace std
namespace OpenGL {
struct CachedSurface; struct CachedSurface;
using Surface = std::shared_ptr<CachedSurface>; using Surface = std::shared_ptr<CachedSurface>;
using SurfaceSet = std::set<Surface>; using SurfaceSet = std::set<Surface>;
@ -351,44 +395,6 @@ private:
std::list<std::weak_ptr<SurfaceWatcher>> watchers; std::list<std::weak_ptr<SurfaceWatcher>> watchers;
}; };
struct TextureCubeConfig {
PAddr px;
PAddr nx;
PAddr py;
PAddr ny;
PAddr pz;
PAddr nz;
u32 width;
Pica::TexturingRegs::TextureFormat format;
bool operator==(const TextureCubeConfig& rhs) const {
return std::tie(px, nx, py, ny, pz, nz, width, format) ==
std::tie(rhs.px, rhs.nx, rhs.py, rhs.ny, rhs.pz, rhs.nz, rhs.width, rhs.format);
}
bool operator!=(const TextureCubeConfig& rhs) const {
return !(*this == rhs);
}
};
namespace std {
template <>
struct hash<TextureCubeConfig> {
std::size_t operator()(const TextureCubeConfig& config) const {
std::size_t hash = 0;
boost::hash_combine(hash, config.px);
boost::hash_combine(hash, config.nx);
boost::hash_combine(hash, config.py);
boost::hash_combine(hash, config.ny);
boost::hash_combine(hash, config.pz);
boost::hash_combine(hash, config.nz);
boost::hash_combine(hash, config.width);
boost::hash_combine(hash, static_cast<u32>(config.format));
return hash;
}
};
} // namespace std
struct CachedTextureCube { struct CachedTextureCube {
OGLTexture texture; OGLTexture texture;
u16 res_scale = 1; u16 res_scale = 1;
@ -486,3 +492,4 @@ private:
std::unordered_map<TextureCubeConfig, CachedTextureCube> texture_cube_cache; std::unordered_map<TextureCubeConfig, CachedTextureCube> texture_cube_cache;
}; };
} // namespace OpenGL

View file

@ -11,6 +11,8 @@
#include "video_core/renderer_opengl/gl_shader_util.h" #include "video_core/renderer_opengl/gl_shader_util.h"
#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_state.h"
namespace OpenGL {
class OGLTexture : private NonCopyable { class OGLTexture : private NonCopyable {
public: public:
OGLTexture() = default; OGLTexture() = default;
@ -102,7 +104,7 @@ public:
return; return;
if (source == nullptr) if (source == nullptr)
return; return;
handle = GLShader::LoadShader(source, type); handle = LoadShader(source, type);
} }
void Release() { void Release() {
@ -135,7 +137,7 @@ public:
void Create(bool separable_program, const std::vector<GLuint>& shaders) { void Create(bool separable_program, const std::vector<GLuint>& shaders) {
if (handle != 0) if (handle != 0)
return; return;
handle = GLShader::LoadProgram(separable_program, shaders); handle = LoadProgram(separable_program, shaders);
} }
/// Creates a new program from given shader soruce code /// Creates a new program from given shader soruce code
@ -294,3 +296,5 @@ public:
GLuint handle = 0; GLuint handle = 0;
}; };
} // namespace OpenGL

View file

@ -13,9 +13,7 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h" #include "video_core/renderer_opengl/gl_shader_decompiler.h"
namespace Pica { namespace OpenGL::ShaderDecompiler {
namespace Shader {
namespace Decompiler {
using nihstro::Instruction; using nihstro::Instruction;
using nihstro::OpCode; using nihstro::OpCode;
@ -23,7 +21,7 @@ using nihstro::RegisterType;
using nihstro::SourceRegister; using nihstro::SourceRegister;
using nihstro::SwizzlePattern; using nihstro::SwizzlePattern;
constexpr u32 PROGRAM_END = MAX_PROGRAM_CODE_LENGTH; constexpr u32 PROGRAM_END = Pica::Shader::MAX_PROGRAM_CODE_LENGTH;
class DecompileFail : public std::runtime_error { class DecompileFail : public std::runtime_error {
public: public:
@ -927,6 +925,4 @@ std::optional<std::string> DecompileProgram(const ProgramCode& program_code,
} }
} }
} // namespace Decompiler } // namespace OpenGL::ShaderDecompiler
} // namespace Shader
} // namespace Pica

View file

@ -9,12 +9,10 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/shader/shader.h" #include "video_core/shader/shader.h"
namespace Pica { namespace OpenGL::ShaderDecompiler {
namespace Shader {
namespace Decompiler {
using ProgramCode = std::array<u32, MAX_PROGRAM_CODE_LENGTH>; using ProgramCode = std::array<u32, Pica::Shader::MAX_PROGRAM_CODE_LENGTH>;
using SwizzleData = std::array<u32, MAX_SWIZZLE_DATA_LENGTH>; using SwizzleData = std::array<u32, Pica::Shader::MAX_SWIZZLE_DATA_LENGTH>;
using RegGetter = std::function<std::string(u32)>; using RegGetter = std::function<std::string(u32)>;
std::string GetCommonDeclarations(); std::string GetCommonDeclarations();
@ -25,6 +23,4 @@ std::optional<std::string> DecompileProgram(const ProgramCode& program_code,
const RegGetter& outputreg_getter, bool sanitize_mul, const RegGetter& outputreg_getter, bool sanitize_mul,
bool is_gs); bool is_gs);
} // namespace Decompiler } // namespace OpenGL::ShaderDecompiler
} // namespace Shader
} // namespace Pica

View file

@ -27,7 +27,7 @@ using Pica::TexturingRegs;
using TevStageConfig = TexturingRegs::TevStageConfig; using TevStageConfig = TexturingRegs::TevStageConfig;
using VSOutputAttributes = RasterizerRegs::VSOutputAttributes; using VSOutputAttributes = RasterizerRegs::VSOutputAttributes;
namespace GLShader { namespace OpenGL {
static const std::string UniformBlockDef = R"( static const std::string UniformBlockDef = R"(
#define NUM_TEV_STAGES 6 #define NUM_TEV_STAGES 6
@ -118,7 +118,7 @@ PicaFSConfig PicaFSConfig::BuildFromRegs(const Pica::Regs& regs) {
state.alpha_test_func = regs.framebuffer.output_merger.alpha_test.enable state.alpha_test_func = regs.framebuffer.output_merger.alpha_test.enable
? regs.framebuffer.output_merger.alpha_test.func.Value() ? regs.framebuffer.output_merger.alpha_test.func.Value()
: Pica::FramebufferRegs::CompareFunc::Always; : FramebufferRegs::CompareFunc::Always;
state.texture0_type = regs.texturing.texture0.type; state.texture0_type = regs.texturing.texture0.type;
@ -237,7 +237,7 @@ PicaFSConfig PicaFSConfig::BuildFromRegs(const Pica::Regs& regs) {
} }
state.shadow_rendering = regs.framebuffer.output_merger.fragment_operation_mode == state.shadow_rendering = regs.framebuffer.output_merger.fragment_operation_mode ==
Pica::FramebufferRegs::FragmentOperationMode::Shadow; FramebufferRegs::FragmentOperationMode::Shadow;
state.shadow_texture_orthographic = regs.texturing.shadow.orthographic != 0; state.shadow_texture_orthographic = regs.texturing.shadow.orthographic != 0;
state.shadow_texture_bias = regs.texturing.shadow.bias << 1; state.shadow_texture_bias = regs.texturing.shadow.bias << 1;
@ -1641,7 +1641,7 @@ std::optional<std::string> GenerateVertexShader(const Pica::Shader::ShaderSetup&
out += "#extension GL_ARB_separate_shader_objects : enable\n"; out += "#extension GL_ARB_separate_shader_objects : enable\n";
} }
out += Pica::Shader::Decompiler::GetCommonDeclarations(); out += ShaderDecompiler::GetCommonDeclarations();
std::array<bool, 16> used_regs{}; std::array<bool, 16> used_regs{};
auto get_input_reg = [&](u32 reg) -> std::string { auto get_input_reg = [&](u32 reg) -> std::string {
@ -1658,7 +1658,7 @@ std::optional<std::string> GenerateVertexShader(const Pica::Shader::ShaderSetup&
return ""; return "";
}; };
auto program_source_opt = Pica::Shader::Decompiler::DecompileProgram( auto program_source_opt = ShaderDecompiler::DecompileProgram(
setup.program_code, setup.swizzle_data, config.state.main_offset, get_input_reg, setup.program_code, setup.swizzle_data, config.state.main_offset, get_input_reg,
get_output_reg, config.state.sanitize_mul, false); get_output_reg, config.state.sanitize_mul, false);
@ -1703,7 +1703,7 @@ layout (std140) uniform vs_config {
static std::string GetGSCommonSource(const PicaGSConfigCommonRaw& config, bool separable_shader) { static std::string GetGSCommonSource(const PicaGSConfigCommonRaw& config, bool separable_shader) {
std::string out = GetVertexInterfaceDeclaration(true, separable_shader); std::string out = GetVertexInterfaceDeclaration(true, separable_shader);
out += UniformBlockDef; out += UniformBlockDef;
out += Pica::Shader::Decompiler::GetCommonDeclarations(); out += ShaderDecompiler::GetCommonDeclarations();
out += '\n'; out += '\n';
for (u32 i = 0; i < config.vs_output_attributes; ++i) { for (u32 i = 0; i < config.vs_output_attributes; ++i) {
@ -1873,7 +1873,7 @@ std::optional<std::string> GenerateGeometryShader(const Pica::Shader::ShaderSetu
return ""; return "";
}; };
auto program_source_opt = Pica::Shader::Decompiler::DecompileProgram( auto program_source_opt = ShaderDecompiler::DecompileProgram(
setup.program_code, setup.swizzle_data, config.state.main_offset, get_input_reg, setup.program_code, setup.swizzle_data, config.state.main_offset, get_input_reg,
get_output_reg, config.state.sanitize_mul, true); get_output_reg, config.state.sanitize_mul, true);
@ -1932,4 +1932,4 @@ void emit() {
return out; return out;
} }
} // namespace GLShader } // namespace OpenGL

View file

@ -14,7 +14,7 @@
#include "video_core/regs.h" #include "video_core/regs.h"
#include "video_core/shader/shader.h" #include "video_core/shader/shader.h"
namespace GLShader { namespace OpenGL {
enum Attributes { enum Attributes {
ATTRIBUTE_POSITION, ATTRIBUTE_POSITION,
@ -255,33 +255,33 @@ std::optional<std::string> GenerateGeometryShader(const Pica::Shader::ShaderSetu
*/ */
std::string GenerateFragmentShader(const PicaFSConfig& config, bool separable_shader); std::string GenerateFragmentShader(const PicaFSConfig& config, bool separable_shader);
} // namespace GLShader } // namespace OpenGL
namespace std { namespace std {
template <> template <>
struct hash<GLShader::PicaFSConfig> { struct hash<OpenGL::PicaFSConfig> {
std::size_t operator()(const GLShader::PicaFSConfig& k) const { std::size_t operator()(const OpenGL::PicaFSConfig& k) const {
return k.Hash(); return k.Hash();
} }
}; };
template <> template <>
struct hash<GLShader::PicaVSConfig> { struct hash<OpenGL::PicaVSConfig> {
std::size_t operator()(const GLShader::PicaVSConfig& k) const { std::size_t operator()(const OpenGL::PicaVSConfig& k) const {
return k.Hash(); return k.Hash();
} }
}; };
template <> template <>
struct hash<GLShader::PicaFixedGSConfig> { struct hash<OpenGL::PicaFixedGSConfig> {
std::size_t operator()(const GLShader::PicaFixedGSConfig& k) const { std::size_t operator()(const OpenGL::PicaFixedGSConfig& k) const {
return k.Hash(); return k.Hash();
} }
}; };
template <> template <>
struct hash<GLShader::PicaGSConfig> { struct hash<OpenGL::PicaGSConfig> {
std::size_t operator()(const GLShader::PicaGSConfig& k) const { std::size_t operator()(const OpenGL::PicaGSConfig& k) const {
return k.Hash(); return k.Hash();
} }
}; };

View file

@ -8,9 +8,11 @@
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include "video_core/renderer_opengl/gl_shader_manager.h" #include "video_core/renderer_opengl/gl_shader_manager.h"
namespace OpenGL {
static void SetShaderUniformBlockBinding(GLuint shader, const char* name, UniformBindings binding, static void SetShaderUniformBlockBinding(GLuint shader, const char* name, UniformBindings binding,
std::size_t expected_size) { std::size_t expected_size) {
GLuint ub_index = glGetUniformBlockIndex(shader, name); const GLuint ub_index = glGetUniformBlockIndex(shader, name);
if (ub_index == GL_INVALID_INDEX) { if (ub_index == GL_INVALID_INDEX) {
return; return;
} }
@ -127,7 +129,7 @@ private:
class TrivialVertexShader { class TrivialVertexShader {
public: public:
explicit TrivialVertexShader(bool separable) : program(separable) { explicit TrivialVertexShader(bool separable) : program(separable) {
program.Create(GLShader::GenerateTrivialVertexShader(separable).c_str(), GL_VERTEX_SHADER); program.Create(GenerateTrivialVertexShader(separable).c_str(), GL_VERTEX_SHADER);
} }
GLuint Get() const { GLuint Get() const {
return program.GetHandle(); return program.GetHandle();
@ -201,18 +203,15 @@ private:
}; };
using ProgrammableVertexShaders = using ProgrammableVertexShaders =
ShaderDoubleCache<GLShader::PicaVSConfig, &GLShader::GenerateVertexShader, GL_VERTEX_SHADER>; ShaderDoubleCache<PicaVSConfig, &GenerateVertexShader, GL_VERTEX_SHADER>;
using ProgrammableGeometryShaders = using ProgrammableGeometryShaders =
ShaderDoubleCache<GLShader::PicaGSConfig, &GLShader::GenerateGeometryShader, ShaderDoubleCache<PicaGSConfig, &GenerateGeometryShader, GL_GEOMETRY_SHADER>;
GL_GEOMETRY_SHADER>;
using FixedGeometryShaders = using FixedGeometryShaders =
ShaderCache<GLShader::PicaFixedGSConfig, &GLShader::GenerateFixedGeometryShader, ShaderCache<PicaFixedGSConfig, &GenerateFixedGeometryShader, GL_GEOMETRY_SHADER>;
GL_GEOMETRY_SHADER>;
using FragmentShaders = using FragmentShaders = ShaderCache<PicaFSConfig, &GenerateFragmentShader, GL_FRAGMENT_SHADER>;
ShaderCache<GLShader::PicaFSConfig, &GLShader::GenerateFragmentShader, GL_FRAGMENT_SHADER>;
class ShaderProgramManager::Impl { class ShaderProgramManager::Impl {
public: public:
@ -270,7 +269,7 @@ ShaderProgramManager::ShaderProgramManager(bool separable, bool is_amd)
ShaderProgramManager::~ShaderProgramManager() = default; ShaderProgramManager::~ShaderProgramManager() = default;
bool ShaderProgramManager::UseProgrammableVertexShader(const GLShader::PicaVSConfig& config, bool ShaderProgramManager::UseProgrammableVertexShader(const PicaVSConfig& config,
const Pica::Shader::ShaderSetup setup) { const Pica::Shader::ShaderSetup setup) {
GLuint handle = impl->programmable_vertex_shaders.Get(config, setup); GLuint handle = impl->programmable_vertex_shaders.Get(config, setup);
if (handle == 0) if (handle == 0)
@ -283,7 +282,7 @@ void ShaderProgramManager::UseTrivialVertexShader() {
impl->current.vs = impl->trivial_vertex_shader.Get(); impl->current.vs = impl->trivial_vertex_shader.Get();
} }
bool ShaderProgramManager::UseProgrammableGeometryShader(const GLShader::PicaGSConfig& config, bool ShaderProgramManager::UseProgrammableGeometryShader(const PicaGSConfig& config,
const Pica::Shader::ShaderSetup setup) { const Pica::Shader::ShaderSetup setup) {
GLuint handle = impl->programmable_geometry_shaders.Get(config, setup); GLuint handle = impl->programmable_geometry_shaders.Get(config, setup);
if (handle == 0) if (handle == 0)
@ -292,7 +291,7 @@ bool ShaderProgramManager::UseProgrammableGeometryShader(const GLShader::PicaGSC
return true; return true;
} }
void ShaderProgramManager::UseFixedGeometryShader(const GLShader::PicaFixedGSConfig& config) { void ShaderProgramManager::UseFixedGeometryShader(const PicaFixedGSConfig& config) {
impl->current.gs = impl->fixed_geometry_shaders.Get(config); impl->current.gs = impl->fixed_geometry_shaders.Get(config);
} }
@ -300,7 +299,7 @@ void ShaderProgramManager::UseTrivialGeometryShader() {
impl->current.gs = 0; impl->current.gs = 0;
} }
void ShaderProgramManager::UseFragmentShader(const GLShader::PicaFSConfig& config) { void ShaderProgramManager::UseFragmentShader(const PicaFSConfig& config) {
impl->current.fs = impl->fragment_shaders.Get(config); impl->current.fs = impl->fragment_shaders.Get(config);
} }
@ -331,3 +330,4 @@ void ShaderProgramManager::ApplyTo(OpenGLState& state) {
state.draw.shader_program = cached_program.handle; state.draw.shader_program = cached_program.handle;
} }
} }
} // namespace OpenGL

View file

@ -11,6 +11,8 @@
#include "video_core/renderer_opengl/gl_shader_gen.h" #include "video_core/renderer_opengl/gl_shader_gen.h"
#include "video_core/renderer_opengl/pica_to_gl.h" #include "video_core/renderer_opengl/pica_to_gl.h"
namespace OpenGL {
enum class UniformBindings : GLuint { Common, VS, GS }; enum class UniformBindings : GLuint { Common, VS, GS };
struct LightSrc { struct LightSrc {
@ -102,19 +104,19 @@ public:
ShaderProgramManager(bool separable, bool is_amd); ShaderProgramManager(bool separable, bool is_amd);
~ShaderProgramManager(); ~ShaderProgramManager();
bool UseProgrammableVertexShader(const GLShader::PicaVSConfig& config, bool UseProgrammableVertexShader(const PicaVSConfig& config,
const Pica::Shader::ShaderSetup setup); const Pica::Shader::ShaderSetup setup);
void UseTrivialVertexShader(); void UseTrivialVertexShader();
bool UseProgrammableGeometryShader(const GLShader::PicaGSConfig& config, bool UseProgrammableGeometryShader(const PicaGSConfig& config,
const Pica::Shader::ShaderSetup setup); const Pica::Shader::ShaderSetup setup);
void UseFixedGeometryShader(const GLShader::PicaFixedGSConfig& config); void UseFixedGeometryShader(const PicaFixedGSConfig& config);
void UseTrivialGeometryShader(); void UseTrivialGeometryShader();
void UseFragmentShader(const GLShader::PicaFSConfig& config); void UseFragmentShader(const PicaFSConfig& config);
void ApplyTo(OpenGLState& state); void ApplyTo(OpenGLState& state);
@ -122,3 +124,4 @@ private:
class Impl; class Impl;
std::unique_ptr<Impl> impl; std::unique_ptr<Impl> impl;
}; };
} // namespace OpenGL

View file

@ -8,7 +8,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "video_core/renderer_opengl/gl_shader_util.h" #include "video_core/renderer_opengl/gl_shader_util.h"
namespace GLShader { namespace OpenGL {
GLuint LoadShader(const char* source, GLenum type) { GLuint LoadShader(const char* source, GLenum type) {
const char* debug_type; const char* debug_type;
@ -95,4 +95,4 @@ GLuint LoadProgram(bool separable_program, const std::vector<GLuint>& shaders) {
return program_id; return program_id;
} }
} // namespace GLShader } // namespace OpenGL

View file

@ -7,7 +7,7 @@
#include <vector> #include <vector>
#include <glad/glad.h> #include <glad/glad.h>
namespace GLShader { namespace OpenGL {
/** /**
* Utility function to create and compile an OpenGL GLSL shader * Utility function to create and compile an OpenGL GLSL shader
@ -24,4 +24,4 @@ GLuint LoadShader(const char* source, GLenum type);
*/ */
GLuint LoadProgram(bool separable_program, const std::vector<GLuint>& shaders); GLuint LoadProgram(bool separable_program, const std::vector<GLuint>& shaders);
} // namespace GLShader } // namespace OpenGL

View file

@ -7,6 +7,8 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_state.h"
namespace OpenGL {
OpenGLState OpenGLState::cur_state; OpenGLState OpenGLState::cur_state;
OpenGLState::OpenGLState() { OpenGLState::OpenGLState() {
@ -411,3 +413,5 @@ OpenGLState& OpenGLState::ResetFramebuffer(GLuint handle) {
} }
return *this; return *this;
} }
} // namespace OpenGL

View file

@ -7,6 +7,8 @@
#include <array> #include <array>
#include <glad/glad.h> #include <glad/glad.h>
namespace OpenGL {
namespace TextureUnits { namespace TextureUnits {
struct TextureUnit { struct TextureUnit {
@ -164,3 +166,5 @@ public:
private: private:
static OpenGLState cur_state; static OpenGLState cur_state;
}; };
} // namespace OpenGL

View file

@ -9,6 +9,8 @@
#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_state.h"
#include "video_core/renderer_opengl/gl_stream_buffer.h" #include "video_core/renderer_opengl/gl_stream_buffer.h"
namespace OpenGL {
OGLStreamBuffer::OGLStreamBuffer(GLenum target, GLsizeiptr size, bool array_buffer_for_amd, OGLStreamBuffer::OGLStreamBuffer(GLenum target, GLsizeiptr size, bool array_buffer_for_amd,
bool prefer_coherent) bool prefer_coherent)
: gl_target(target), buffer_size(size) { : gl_target(target), buffer_size(size) {
@ -98,3 +100,5 @@ void OGLStreamBuffer::Unmap(GLsizeiptr size) {
buffer_pos += size; buffer_pos += size;
} }
} // namespace OpenGL

View file

@ -9,6 +9,8 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_resource_manager.h"
namespace OpenGL {
class OGLStreamBuffer : private NonCopyable { class OGLStreamBuffer : private NonCopyable {
public: public:
explicit OGLStreamBuffer(GLenum target, GLsizeiptr size, bool array_buffer_for_amd, explicit OGLStreamBuffer(GLenum target, GLsizeiptr size, bool array_buffer_for_amd,
@ -43,3 +45,5 @@ private:
GLsizeiptr mapped_size = 0; GLsizeiptr mapped_size = 0;
u8* mapped_ptr = nullptr; u8* mapped_ptr = nullptr;
}; };
} // namespace OpenGL

View file

@ -24,6 +24,8 @@
#include "video_core/renderer_opengl/renderer_opengl.h" #include "video_core/renderer_opengl/renderer_opengl.h"
#include "video_core/video_core.h" #include "video_core/video_core.h"
namespace OpenGL {
static const char vertex_shader[] = R"( static const char vertex_shader[] = R"(
#version 150 core #version 150 core
@ -535,3 +537,5 @@ Core::System::ResultStatus RendererOpenGL::Init() {
/// Shutdown the renderer /// Shutdown the renderer
void RendererOpenGL::ShutDown() {} void RendererOpenGL::ShutDown() {}
} // namespace OpenGL

View file

@ -13,7 +13,7 @@
#include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_state.h"
class EmuWindow; namespace OpenGL {
/// Structure used for storing information about the textures for each 3DS screen /// Structure used for storing information about the textures for each 3DS screen
struct TextureInfo { struct TextureInfo {
@ -78,3 +78,5 @@ private:
GLuint attrib_position; GLuint attrib_position;
GLuint attrib_tex_coord; GLuint attrib_tex_coord;
}; };
} // namespace OpenGL

View file

@ -27,7 +27,7 @@ std::atomic<bool> g_renderer_bg_color_update_requested;
Core::System::ResultStatus Init(EmuWindow& emu_window) { Core::System::ResultStatus Init(EmuWindow& emu_window) {
Pica::Init(); Pica::Init();
g_renderer = std::make_unique<RendererOpenGL>(emu_window); g_renderer = std::make_unique<OpenGL::RendererOpenGL>(emu_window);
Core::System::ResultStatus result = g_renderer->Init(); Core::System::ResultStatus result = g_renderer->Init();
if (result != Core::System::ResultStatus::Success) { if (result != Core::System::ResultStatus::Success) {