From dd35b4b18a69c02c3a22ba1a72504fbff69cfec0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 21 Aug 2018 04:18:27 -0400 Subject: [PATCH] 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. --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 4 ++++ src/video_core/renderer_opengl/gl_rasterizer.h | 8 ++++++-- .../renderer_opengl/gl_rasterizer_cache.cpp | 4 ++++ src/video_core/renderer_opengl/gl_rasterizer_cache.h | 4 ++++ src/video_core/renderer_opengl/gl_resource_manager.h | 4 ++++ .../renderer_opengl/gl_shader_decompiler.cpp | 4 ++-- .../renderer_opengl/gl_shader_decompiler.h | 4 ++-- src/video_core/renderer_opengl/gl_shader_gen.cpp | 4 ++-- src/video_core/renderer_opengl/gl_shader_gen.h | 12 ++++++------ src/video_core/renderer_opengl/gl_shader_manager.cpp | 4 ++-- src/video_core/renderer_opengl/gl_shader_manager.h | 4 ++-- src/video_core/renderer_opengl/gl_shader_util.cpp | 4 ++-- src/video_core/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 ++++ src/video_core/renderer_opengl/gl_stream_buffer.cpp | 4 ++++ src/video_core/renderer_opengl/gl_stream_buffer.h | 4 ++++ src/video_core/renderer_opengl/maxwell_to_gl.h | 3 +++ src/video_core/renderer_opengl/renderer_opengl.cpp | 4 ++++ src/video_core/renderer_opengl/renderer_opengl.h | 4 ++++ src/video_core/video_core.cpp | 2 +- 21 files changed, 70 insertions(+), 23 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 35056d9bd..c67eabe65 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/renderer_opengl.h" #include "video_core/video_core.h" +namespace OpenGL { + using Maxwell = Tegra::Engines::Maxwell3D::Regs; using PixelFormat = SurfaceParams::PixelFormat; using SurfaceType = SurfaceParams::SurfaceType; @@ -874,3 +876,5 @@ void RasterizerOpenGL::SyncLogicOpState() { state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation); } + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index f40e70bf4..59b727de0 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -22,12 +22,14 @@ #include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_stream_buffer.h" -struct ScreenInfo; - namespace Core::Frontend { class EmuWindow; } +namespace OpenGL { + +struct ScreenInfo; + class RasterizerOpenGL : public VideoCore::RasterizerInterface { public: explicit RasterizerOpenGL(Core::Frontend::EmuWindow& renderer, ScreenInfo& info); @@ -184,3 +186,5 @@ private: enum class AccelDraw { Disabled, Arrays, Indexed }; AccelDraw accelerate_draw = AccelDraw::Disabled; }; + +} // 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 817fa07a8..b1769c99b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -19,6 +19,8 @@ #include "video_core/textures/decoders.h" #include "video_core/utils.h" +namespace OpenGL { + using SurfaceType = SurfaceParams::SurfaceType; using PixelFormat = SurfaceParams::PixelFormat; using ComponentType = SurfaceParams::ComponentType; @@ -967,3 +969,5 @@ void RasterizerCacheOpenGL::UpdatePagesCachedCount(Tegra::GPUVAddr addr, u64 siz 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 907e7d606..f273152a2 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -16,6 +16,8 @@ #include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/textures/texture.h" +namespace OpenGL { + class CachedSurface; using Surface = std::shared_ptr; using SurfaceSurfaceRect_Tuple = std::tuple>; @@ -759,3 +761,5 @@ private: OGLFramebuffer read_framebuffer; OGLFramebuffer draw_framebuffer; }; + +} // 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 0fed93ca5..3bc1b83b5 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h @@ -10,6 +10,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; @@ -331,3 +333,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 5b976b636..f1e00c93c 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -15,7 +15,7 @@ #include "video_core/renderer_opengl/gl_rasterizer.h" #include "video_core/renderer_opengl/gl_shader_decompiler.h" -namespace GLShader::Decompiler { +namespace OpenGL::GLShader::Decompiler { using Tegra::Shader::Attribute; using Tegra::Shader::Instruction; @@ -2176,4 +2176,4 @@ boost::optional DecompileProgram(const ProgramCode& program_code, return boost::none; } -} // namespace GLShader::Decompiler +} // namespace OpenGL::GLShader::Decompiler diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.h b/src/video_core/renderer_opengl/gl_shader_decompiler.h index df6769462..b20cc4bfa 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.h +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.h @@ -12,7 +12,7 @@ #include "video_core/engines/maxwell_3d.h" #include "video_core/renderer_opengl/gl_shader_gen.h" -namespace GLShader::Decompiler { +namespace OpenGL::GLShader::Decompiler { using Tegra::Engines::Maxwell3D; @@ -22,4 +22,4 @@ boost::optional DecompileProgram(const ProgramCode& program_code, Maxwell3D::Regs::ShaderStage stage, const std::string& suffix); -} // namespace GLShader::Decompiler +} // namespace OpenGL::GLShader::Decompiler diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 01c7b9720..0677317bc 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -7,7 +7,7 @@ #include "video_core/renderer_opengl/gl_shader_decompiler.h" #include "video_core/renderer_opengl/gl_shader_gen.h" -namespace GLShader { +namespace OpenGL::GLShader { using Tegra::Engines::Maxwell3D; @@ -103,4 +103,4 @@ void main() { return {out, program.second}; } -} // namespace GLShader +} // namespace OpenGL::GLShader diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h index 4729ce0fc..2c636b7f3 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.h +++ b/src/video_core/renderer_opengl/gl_shader_gen.h @@ -12,7 +12,7 @@ #include "common/common_types.h" #include "common/hash.h" -namespace GLShader { +namespace OpenGL::GLShader { constexpr size_t MAX_PROGRAM_CODE_LENGTH{0x1000}; @@ -191,20 +191,20 @@ ProgramResult GenerateVertexShader(const ShaderSetup& setup, const MaxwellVSConf */ ProgramResult GenerateFragmentShader(const ShaderSetup& setup, const MaxwellFSConfig& config); -} // namespace GLShader +} // namespace OpenGL::GLShader namespace std { template <> -struct hash { - size_t operator()(const GLShader::MaxwellVSConfig& k) const { +struct hash { + size_t operator()(const OpenGL::GLShader::MaxwellVSConfig& k) const { return k.Hash(); } }; template <> -struct hash { - size_t operator()(const GLShader::MaxwellFSConfig& k) const { +struct hash { + size_t operator()(const OpenGL::GLShader::MaxwellFSConfig& 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 f0886caac..8960afef5 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp @@ -7,7 +7,7 @@ #include "video_core/engines/maxwell_3d.h" #include "video_core/renderer_opengl/gl_shader_manager.h" -namespace GLShader { +namespace OpenGL::GLShader { namespace Impl { static void SetShaderUniformBlockBinding(GLuint shader, const char* name, @@ -49,4 +49,4 @@ void MaxwellUniformData::SetFromRegs(const Maxwell3D::State::ShaderStageInfo& sh instance_id[0] = state.current_instance; } -} // namespace GLShader +} // namespace OpenGL::GLShader diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index 75fa73605..0e7085776 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h @@ -12,7 +12,7 @@ #include "video_core/renderer_opengl/gl_shader_gen.h" #include "video_core/renderer_opengl/maxwell_to_gl.h" -namespace GLShader { +namespace OpenGL::GLShader { /// Number of OpenGL texture samplers that can be used in the fragment shader static constexpr size_t NumTextureSamplers = 32; @@ -171,4 +171,4 @@ private: OGLPipeline pipeline; }; -} // namespace GLShader +} // namespace OpenGL::GLShader diff --git a/src/video_core/renderer_opengl/gl_shader_util.cpp b/src/video_core/renderer_opengl/gl_shader_util.cpp index 3c087d638..5781d9d16 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::GLShader { GLuint LoadShader(const char* source, GLenum type) { const char* debug_type; @@ -47,4 +47,4 @@ GLuint LoadShader(const char* source, GLenum type) { return shader_id; } -} // namespace GLShader +} // namespace OpenGL::GLShader diff --git a/src/video_core/renderer_opengl/gl_shader_util.h b/src/video_core/renderer_opengl/gl_shader_util.h index 0e4d782e2..285594f50 100644 --- a/src/video_core/renderer_opengl/gl_shader_util.h +++ b/src/video_core/renderer_opengl/gl_shader_util.h @@ -10,7 +10,7 @@ #include "common/assert.h" #include "common/logging/log.h" -namespace GLShader { +namespace OpenGL::GLShader { /** * Utility function to log the source code of a list of shaders. @@ -89,4 +89,4 @@ GLuint LoadProgram(bool separable_program, T... shaders) { return program_id; } -} // namespace GLShader +} // namespace OpenGL::GLShader diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 13399ceb8..e1a887d67 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() { @@ -338,3 +340,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 219b65a8a..22b0b1e41 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -9,6 +9,8 @@ #include "video_core/engines/maxwell_3d.h" +namespace OpenGL { + using Regs = Tegra::Engines::Maxwell3D::Regs; namespace TextureUnits { @@ -163,3 +165,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 03a8ed8b7..e565afcee 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 prefer_coherent) : gl_target(target), buffer_size(size) { gl_buffer.Create(); @@ -97,3 +99,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 3b0cdf6bc..ae7961bd7 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 prefer_coherent = false); @@ -42,3 +44,5 @@ private: GLsizeiptr mapped_size = 0; u8* mapped_ptr = nullptr; }; + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h index 0d55b3e17..0343759a6 100644 --- a/src/video_core/renderer_opengl/maxwell_to_gl.h +++ b/src/video_core/renderer_opengl/maxwell_to_gl.h @@ -10,6 +10,8 @@ #include "common/logging/log.h" #include "video_core/engines/maxwell_3d.h" +namespace OpenGL { + using GLvec2 = std::array; using GLvec3 = std::array; using GLvec4 = std::array; @@ -360,3 +362,4 @@ inline GLenum LogicOp(Maxwell::LogicOperation operation) { } } // namespace MaxwellToGL +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index eef13dddc..73d6419b4 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -20,6 +20,8 @@ #include "video_core/renderer_opengl/renderer_opengl.h" #include "video_core/utils.h" +namespace OpenGL { + static const char vertex_shader[] = R"( #version 150 core @@ -476,3 +478,5 @@ bool 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 7ae103f04..961467a62 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -16,6 +16,8 @@ namespace Core::Frontend { class EmuWindow; } +namespace OpenGL { + /// Structure used for storing information about the textures for the Switch screen struct TextureInfo { OGLTexture resource; @@ -98,3 +100,5 @@ private: Tegra::FramebufferConfig::TransformFlags framebuffer_transform_flags; MathUtil::Rectangle framebuffer_crop_rect; }; + +} // namespace OpenGL diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 6780d1c16..07e3a7d24 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -10,7 +10,7 @@ namespace VideoCore { std::unique_ptr CreateRenderer(Core::Frontend::EmuWindow& emu_window) { - return std::make_unique(emu_window); + return std::make_unique(emu_window); } } // namespace VideoCore