From 46e8237e7ee3466a74886763020ba376c02bbe22 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 17 Nov 2018 08:29:10 +0100 Subject: [PATCH] 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 --- src/video_core/rasterizer_interface.h | 4 +- src/video_core/renderer_base.cpp | 2 +- .../renderer_opengl/gl_rasterizer.cpp | 56 +++++++------ .../renderer_opengl/gl_rasterizer.h | 5 +- .../renderer_opengl/gl_rasterizer_cache.cpp | 4 + .../renderer_opengl/gl_rasterizer_cache.h | 83 ++++++++++--------- .../renderer_opengl/gl_resource_manager.h | 8 +- .../renderer_opengl/gl_shader_decompiler.cpp | 10 +-- .../renderer_opengl/gl_shader_decompiler.h | 12 +-- .../renderer_opengl/gl_shader_gen.cpp | 16 ++-- .../renderer_opengl/gl_shader_gen.h | 20 ++--- .../renderer_opengl/gl_shader_manager.cpp | 26 +++--- .../renderer_opengl/gl_shader_manager.h | 11 ++- .../renderer_opengl/gl_shader_util.cpp | 4 +- .../renderer_opengl/gl_shader_util.h | 4 +- src/video_core/renderer_opengl/gl_state.cpp | 4 + src/video_core/renderer_opengl/gl_state.h | 4 + .../renderer_opengl/gl_stream_buffer.cpp | 4 + .../renderer_opengl/gl_stream_buffer.h | 4 + .../renderer_opengl/renderer_opengl.cpp | 4 + .../renderer_opengl/renderer_opengl.h | 4 +- src/video_core/video_core.cpp | 2 +- 22 files changed, 166 insertions(+), 125 deletions(-) diff --git a/src/video_core/rasterizer_interface.h b/src/video_core/rasterizer_interface.h index d1f09fccc..b4d237c61 100644 --- a/src/video_core/rasterizer_interface.h +++ b/src/video_core/rasterizer_interface.h @@ -7,7 +7,9 @@ #include "common/common_types.h" #include "core/hw/gpu.h" +namespace OpenGL { struct ScreenInfo; +} namespace Pica { namespace Shader { @@ -63,7 +65,7 @@ public: /// Attempt to use a faster method to display the framebuffer to screen virtual bool AccelerateDisplay(const GPU::Regs::FramebufferConfig& config, PAddr framebuffer_addr, u32 pixel_stride, - ScreenInfo& screen_info) { + OpenGL::ScreenInfo& screen_info) { return false; } diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cpp index a35ee7ad8..61c1cd1d6 100644 --- a/src/video_core/renderer_base.cpp +++ b/src/video_core/renderer_base.cpp @@ -22,7 +22,7 @@ void RendererBase::RefreshRasterizerSetting() { opengl_rasterizer_active = hw_renderer_enabled; if (hw_renderer_enabled) { - rasterizer = std::make_unique(render_window); + rasterizer = std::make_unique(render_window); } else { rasterizer = std::make_unique(); } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index d4e378aa2..b62320064 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -25,6 +25,8 @@ #include "video_core/renderer_opengl/pica_to_gl.h" #include "video_core/renderer_opengl/renderer_opengl.h" +namespace OpenGL { + using PixelFormat = SurfaceParams::PixelFormat; using SurfaceType = SurfaceParams::SurfaceType; @@ -102,35 +104,35 @@ RasterizerOpenGL::RasterizerOpenGL(EmuWindow& window) state.draw.vertex_buffer = vertex_buffer.GetHandle(); state.Apply(); - glVertexAttribPointer(GLShader::ATTRIBUTE_POSITION, 4, GL_FLOAT, GL_FALSE, - sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, position)); - glEnableVertexAttribArray(GLShader::ATTRIBUTE_POSITION); + glVertexAttribPointer(ATTRIBUTE_POSITION, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), + (GLvoid*)offsetof(HardwareVertex, 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)); - glEnableVertexAttribArray(GLShader::ATTRIBUTE_COLOR); + glEnableVertexAttribArray(ATTRIBUTE_COLOR); - glVertexAttribPointer(GLShader::ATTRIBUTE_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, - sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, tex_coord0)); - glVertexAttribPointer(GLShader::ATTRIBUTE_TEXCOORD1, 2, GL_FLOAT, GL_FALSE, - sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, tex_coord1)); - glVertexAttribPointer(GLShader::ATTRIBUTE_TEXCOORD2, 2, GL_FLOAT, GL_FALSE, - sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, tex_coord2)); - glEnableVertexAttribArray(GLShader::ATTRIBUTE_TEXCOORD0); - glEnableVertexAttribArray(GLShader::ATTRIBUTE_TEXCOORD1); - glEnableVertexAttribArray(GLShader::ATTRIBUTE_TEXCOORD2); + glVertexAttribPointer(ATTRIBUTE_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), + (GLvoid*)offsetof(HardwareVertex, tex_coord0)); + glVertexAttribPointer(ATTRIBUTE_TEXCOORD1, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), + (GLvoid*)offsetof(HardwareVertex, tex_coord1)); + glVertexAttribPointer(ATTRIBUTE_TEXCOORD2, 2, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), + (GLvoid*)offsetof(HardwareVertex, tex_coord2)); + glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD0); + glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD1); + glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD2); - glVertexAttribPointer(GLShader::ATTRIBUTE_TEXCOORD0_W, 1, GL_FLOAT, GL_FALSE, - sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, tex_coord0_w)); - glEnableVertexAttribArray(GLShader::ATTRIBUTE_TEXCOORD0_W); + glVertexAttribPointer(ATTRIBUTE_TEXCOORD0_W, 1, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), + (GLvoid*)offsetof(HardwareVertex, tex_coord0_w)); + glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD0_W); - glVertexAttribPointer(GLShader::ATTRIBUTE_NORMQUAT, 4, GL_FLOAT, GL_FALSE, - sizeof(HardwareVertex), (GLvoid*)offsetof(HardwareVertex, normquat)); - glEnableVertexAttribArray(GLShader::ATTRIBUTE_NORMQUAT); + glVertexAttribPointer(ATTRIBUTE_NORMQUAT, 4, GL_FLOAT, GL_FALSE, sizeof(HardwareVertex), + (GLvoid*)offsetof(HardwareVertex, 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)); - glEnableVertexAttribArray(GLShader::ATTRIBUTE_VIEW); + glEnableVertexAttribArray(ATTRIBUTE_VIEW); // Create render framebuffer framebuffer.Create(); @@ -367,7 +369,7 @@ void RasterizerOpenGL::SetupVertexArray(u8* array_ptr, GLintptr buffer_offset, bool RasterizerOpenGL::SetupVertexShader() { 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); } @@ -375,11 +377,11 @@ bool RasterizerOpenGL::SetupGeometryShader() { MICROPROFILE_SCOPE(OpenGL_GS); const auto& regs = Pica::g_state.regs; if (regs.pipeline.use_gs == Pica::PipelineRegs::UseGS::No) { - GLShader::PicaFixedGSConfig gs_config(regs); + PicaFixedGSConfig gs_config(regs); shader_program_manager->UseFixedGeometryShader(gs_config); return true; } 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); } } @@ -1588,7 +1590,7 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig( } 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); } @@ -2105,3 +2107,5 @@ void RasterizerOpenGL::UploadUniforms(bool accelerate_draw, bool use_gs) { uniform_buffer.Unmap(used_bytes); } + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index f3d3b46c8..807337f75 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -30,9 +30,10 @@ #include "video_core/shader/shader.h" class EmuWindow; -struct ScreenInfo; class ShaderProgramManager; +namespace OpenGL { + class RasterizerOpenGL : public VideoCore::RasterizerInterface { public: explicit RasterizerOpenGL(EmuWindow& renderer); @@ -307,3 +308,5 @@ private: bool allow_shadow; }; + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index e943236de..395a0e8fa 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -32,6 +32,8 @@ #include "video_core/utils.h" #include "video_core/video_core.h" +namespace OpenGL { + using SurfaceType = SurfaceParams::SurfaceType; using PixelFormat = SurfaceParams::PixelFormat; @@ -1727,3 +1729,5 @@ void RasterizerCacheOpenGL::UpdatePagesCachedCount(PAddr addr, u32 size, int del if (delta < 0) cached_pages.add({pages_interval, delta}); } + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index 618c59322..ecced12c7 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -31,6 +31,50 @@ #include "video_core/renderer_opengl/gl_resource_manager.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 { + 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(config.format)); + return hash; + } +}; +} // namespace std + +namespace OpenGL { + struct CachedSurface; using Surface = std::shared_ptr; using SurfaceSet = std::set; @@ -351,44 +395,6 @@ private: std::list> 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 { - 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(config.format)); - return hash; - } -}; -} // namespace std - struct CachedTextureCube { OGLTexture texture; u16 res_scale = 1; @@ -486,3 +492,4 @@ private: std::unordered_map texture_cube_cache; }; +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index 4c20c8849..3fbf5eafb 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h @@ -11,6 +11,8 @@ #include "video_core/renderer_opengl/gl_shader_util.h" #include "video_core/renderer_opengl/gl_state.h" +namespace OpenGL { + class OGLTexture : private NonCopyable { public: OGLTexture() = default; @@ -102,7 +104,7 @@ public: return; if (source == nullptr) return; - handle = GLShader::LoadShader(source, type); + handle = LoadShader(source, type); } void Release() { @@ -135,7 +137,7 @@ public: void Create(bool separable_program, const std::vector& shaders) { if (handle != 0) return; - handle = GLShader::LoadProgram(separable_program, shaders); + handle = LoadProgram(separable_program, shaders); } /// Creates a new program from given shader soruce code @@ -294,3 +296,5 @@ public: GLuint handle = 0; }; + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index b04b08a4a..c464f3a7a 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -13,9 +13,7 @@ #include "common/common_types.h" #include "video_core/renderer_opengl/gl_shader_decompiler.h" -namespace Pica { -namespace Shader { -namespace Decompiler { +namespace OpenGL::ShaderDecompiler { using nihstro::Instruction; using nihstro::OpCode; @@ -23,7 +21,7 @@ using nihstro::RegisterType; using nihstro::SourceRegister; 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 { public: @@ -927,6 +925,4 @@ std::optional DecompileProgram(const ProgramCode& program_code, } } -} // namespace Decompiler -} // namespace Shader -} // namespace Pica +} // namespace OpenGL::ShaderDecompiler diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.h b/src/video_core/renderer_opengl/gl_shader_decompiler.h index 4dd8e73c3..2ec8fddd1 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.h +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.h @@ -9,12 +9,10 @@ #include "common/common_types.h" #include "video_core/shader/shader.h" -namespace Pica { -namespace Shader { -namespace Decompiler { +namespace OpenGL::ShaderDecompiler { -using ProgramCode = std::array; -using SwizzleData = std::array; +using ProgramCode = std::array; +using SwizzleData = std::array; using RegGetter = std::function; std::string GetCommonDeclarations(); @@ -25,6 +23,4 @@ std::optional DecompileProgram(const ProgramCode& program_code, const RegGetter& outputreg_getter, bool sanitize_mul, bool is_gs); -} // namespace Decompiler -} // namespace Shader -} // namespace Pica +} // namespace OpenGL::ShaderDecompiler diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index ddf8583ea..62b1162ec 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -27,7 +27,7 @@ using Pica::TexturingRegs; using TevStageConfig = TexturingRegs::TevStageConfig; using VSOutputAttributes = RasterizerRegs::VSOutputAttributes; -namespace GLShader { +namespace OpenGL { static const std::string UniformBlockDef = R"( #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 ? regs.framebuffer.output_merger.alpha_test.func.Value() - : Pica::FramebufferRegs::CompareFunc::Always; + : FramebufferRegs::CompareFunc::Always; 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 == - Pica::FramebufferRegs::FragmentOperationMode::Shadow; + FramebufferRegs::FragmentOperationMode::Shadow; state.shadow_texture_orthographic = regs.texturing.shadow.orthographic != 0; state.shadow_texture_bias = regs.texturing.shadow.bias << 1; @@ -1641,7 +1641,7 @@ std::optional GenerateVertexShader(const Pica::Shader::ShaderSetup& out += "#extension GL_ARB_separate_shader_objects : enable\n"; } - out += Pica::Shader::Decompiler::GetCommonDeclarations(); + out += ShaderDecompiler::GetCommonDeclarations(); std::array used_regs{}; auto get_input_reg = [&](u32 reg) -> std::string { @@ -1658,7 +1658,7 @@ std::optional GenerateVertexShader(const Pica::Shader::ShaderSetup& 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, 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) { std::string out = GetVertexInterfaceDeclaration(true, separable_shader); out += UniformBlockDef; - out += Pica::Shader::Decompiler::GetCommonDeclarations(); + out += ShaderDecompiler::GetCommonDeclarations(); out += '\n'; for (u32 i = 0; i < config.vs_output_attributes; ++i) { @@ -1873,7 +1873,7 @@ std::optional GenerateGeometryShader(const Pica::Shader::ShaderSetu 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, get_output_reg, config.state.sanitize_mul, true); @@ -1932,4 +1932,4 @@ void emit() { return out; } -} // namespace GLShader +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h index 6f9252373..df27b3aaf 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.h +++ b/src/video_core/renderer_opengl/gl_shader_gen.h @@ -14,7 +14,7 @@ #include "video_core/regs.h" #include "video_core/shader/shader.h" -namespace GLShader { +namespace OpenGL { enum Attributes { ATTRIBUTE_POSITION, @@ -255,33 +255,33 @@ std::optional GenerateGeometryShader(const Pica::Shader::ShaderSetu */ std::string GenerateFragmentShader(const PicaFSConfig& config, bool separable_shader); -} // namespace GLShader +} // namespace OpenGL namespace std { template <> -struct hash { - std::size_t operator()(const GLShader::PicaFSConfig& k) const { +struct hash { + std::size_t operator()(const OpenGL::PicaFSConfig& k) const { return k.Hash(); } }; template <> -struct hash { - std::size_t operator()(const GLShader::PicaVSConfig& k) const { +struct hash { + std::size_t operator()(const OpenGL::PicaVSConfig& k) const { return k.Hash(); } }; template <> -struct hash { - std::size_t operator()(const GLShader::PicaFixedGSConfig& k) const { +struct hash { + std::size_t operator()(const OpenGL::PicaFixedGSConfig& k) const { return k.Hash(); } }; template <> -struct hash { - std::size_t operator()(const GLShader::PicaGSConfig& k) const { +struct hash { + std::size_t operator()(const OpenGL::PicaGSConfig& k) const { return k.Hash(); } }; diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cpp index 0f6839ea8..a5c62a0e1 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp @@ -8,9 +8,11 @@ #include #include "video_core/renderer_opengl/gl_shader_manager.h" +namespace OpenGL { + static void SetShaderUniformBlockBinding(GLuint shader, const char* name, UniformBindings binding, std::size_t expected_size) { - GLuint ub_index = glGetUniformBlockIndex(shader, name); + const GLuint ub_index = glGetUniformBlockIndex(shader, name); if (ub_index == GL_INVALID_INDEX) { return; } @@ -127,7 +129,7 @@ private: class TrivialVertexShader { public: 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 { return program.GetHandle(); @@ -201,18 +203,15 @@ private: }; using ProgrammableVertexShaders = - ShaderDoubleCache; + ShaderDoubleCache; using ProgrammableGeometryShaders = - ShaderDoubleCache; + ShaderDoubleCache; using FixedGeometryShaders = - ShaderCache; + ShaderCache; -using FragmentShaders = - ShaderCache; +using FragmentShaders = ShaderCache; class ShaderProgramManager::Impl { public: @@ -270,7 +269,7 @@ ShaderProgramManager::ShaderProgramManager(bool separable, bool is_amd) ShaderProgramManager::~ShaderProgramManager() = default; -bool ShaderProgramManager::UseProgrammableVertexShader(const GLShader::PicaVSConfig& config, +bool ShaderProgramManager::UseProgrammableVertexShader(const PicaVSConfig& config, const Pica::Shader::ShaderSetup setup) { GLuint handle = impl->programmable_vertex_shaders.Get(config, setup); if (handle == 0) @@ -283,7 +282,7 @@ void ShaderProgramManager::UseTrivialVertexShader() { 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) { GLuint handle = impl->programmable_geometry_shaders.Get(config, setup); if (handle == 0) @@ -292,7 +291,7 @@ bool ShaderProgramManager::UseProgrammableGeometryShader(const GLShader::PicaGSC return true; } -void ShaderProgramManager::UseFixedGeometryShader(const GLShader::PicaFixedGSConfig& config) { +void ShaderProgramManager::UseFixedGeometryShader(const PicaFixedGSConfig& config) { impl->current.gs = impl->fixed_geometry_shaders.Get(config); } @@ -300,7 +299,7 @@ void ShaderProgramManager::UseTrivialGeometryShader() { 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); } @@ -331,3 +330,4 @@ void ShaderProgramManager::ApplyTo(OpenGLState& state) { state.draw.shader_program = cached_program.handle; } } +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index bbc6d5b10..8c740f982 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h @@ -11,6 +11,8 @@ #include "video_core/renderer_opengl/gl_shader_gen.h" #include "video_core/renderer_opengl/pica_to_gl.h" +namespace OpenGL { + enum class UniformBindings : GLuint { Common, VS, GS }; struct LightSrc { @@ -102,19 +104,19 @@ public: ShaderProgramManager(bool separable, bool is_amd); ~ShaderProgramManager(); - bool UseProgrammableVertexShader(const GLShader::PicaVSConfig& config, + bool UseProgrammableVertexShader(const PicaVSConfig& config, const Pica::Shader::ShaderSetup setup); void UseTrivialVertexShader(); - bool UseProgrammableGeometryShader(const GLShader::PicaGSConfig& config, + bool UseProgrammableGeometryShader(const PicaGSConfig& config, const Pica::Shader::ShaderSetup setup); - void UseFixedGeometryShader(const GLShader::PicaFixedGSConfig& config); + void UseFixedGeometryShader(const PicaFixedGSConfig& config); void UseTrivialGeometryShader(); - void UseFragmentShader(const GLShader::PicaFSConfig& config); + void UseFragmentShader(const PicaFSConfig& config); void ApplyTo(OpenGLState& state); @@ -122,3 +124,4 @@ private: class Impl; std::unique_ptr impl; }; +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_shader_util.cpp b/src/video_core/renderer_opengl/gl_shader_util.cpp index 58c54444e..5ffa71562 100644 --- a/src/video_core/renderer_opengl/gl_shader_util.cpp +++ b/src/video_core/renderer_opengl/gl_shader_util.cpp @@ -8,7 +8,7 @@ #include "common/logging/log.h" #include "video_core/renderer_opengl/gl_shader_util.h" -namespace GLShader { +namespace OpenGL { GLuint LoadShader(const char* source, GLenum type) { const char* debug_type; @@ -95,4 +95,4 @@ GLuint LoadProgram(bool separable_program, const std::vector& shaders) { return program_id; } -} // namespace GLShader +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_shader_util.h b/src/video_core/renderer_opengl/gl_shader_util.h index 92d0fc534..9f0cf5c1e 100644 --- a/src/video_core/renderer_opengl/gl_shader_util.h +++ b/src/video_core/renderer_opengl/gl_shader_util.h @@ -7,7 +7,7 @@ #include #include -namespace GLShader { +namespace OpenGL { /** * 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& shaders); -} // namespace GLShader +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 6cf4894bb..250b8b4aa 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -7,6 +7,8 @@ #include "common/logging/log.h" #include "video_core/renderer_opengl/gl_state.h" +namespace OpenGL { + OpenGLState OpenGLState::cur_state; OpenGLState::OpenGLState() { @@ -411,3 +413,5 @@ OpenGLState& OpenGLState::ResetFramebuffer(GLuint handle) { } return *this; } + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 1cf9b8d36..b1842a820 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -7,6 +7,8 @@ #include #include +namespace OpenGL { + namespace TextureUnits { struct TextureUnit { @@ -164,3 +166,5 @@ public: private: static OpenGLState cur_state; }; + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_stream_buffer.cpp b/src/video_core/renderer_opengl/gl_stream_buffer.cpp index 9def54630..736cfa9c4 100644 --- a/src/video_core/renderer_opengl/gl_stream_buffer.cpp +++ b/src/video_core/renderer_opengl/gl_stream_buffer.cpp @@ -9,6 +9,8 @@ #include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_stream_buffer.h" +namespace OpenGL { + OGLStreamBuffer::OGLStreamBuffer(GLenum target, GLsizeiptr size, bool array_buffer_for_amd, bool prefer_coherent) : gl_target(target), buffer_size(size) { @@ -98,3 +100,5 @@ void OGLStreamBuffer::Unmap(GLsizeiptr size) { buffer_pos += size; } + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_stream_buffer.h b/src/video_core/renderer_opengl/gl_stream_buffer.h index e1ccec743..6b6044832 100644 --- a/src/video_core/renderer_opengl/gl_stream_buffer.h +++ b/src/video_core/renderer_opengl/gl_stream_buffer.h @@ -9,6 +9,8 @@ #include "common/common_types.h" #include "video_core/renderer_opengl/gl_resource_manager.h" +namespace OpenGL { + class OGLStreamBuffer : private NonCopyable { public: explicit OGLStreamBuffer(GLenum target, GLsizeiptr size, bool array_buffer_for_amd, @@ -43,3 +45,5 @@ private: GLsizeiptr mapped_size = 0; u8* mapped_ptr = nullptr; }; + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index b3c83ca78..ee6e4045c 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -24,6 +24,8 @@ #include "video_core/renderer_opengl/renderer_opengl.h" #include "video_core/video_core.h" +namespace OpenGL { + static const char vertex_shader[] = R"( #version 150 core @@ -535,3 +537,5 @@ Core::System::ResultStatus RendererOpenGL::Init() { /// Shutdown the renderer void RendererOpenGL::ShutDown() {} + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index 47cc9aaa9..87b45529b 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -13,7 +13,7 @@ #include "video_core/renderer_opengl/gl_resource_manager.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 struct TextureInfo { @@ -78,3 +78,5 @@ private: GLuint attrib_position; GLuint attrib_tex_coord; }; + +} // namespace OpenGL diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 4c39c0b52..f8b636de4 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -27,7 +27,7 @@ std::atomic g_renderer_bg_color_update_requested; Core::System::ResultStatus Init(EmuWindow& emu_window) { Pica::Init(); - g_renderer = std::make_unique(emu_window); + g_renderer = std::make_unique(emu_window); Core::System::ResultStatus result = g_renderer->Init(); if (result != Core::System::ResultStatus::Success) {