Merge pull request #26117 from notspiff/infoscanner_inforet_enum_class
[xbmc.git] / xbmc / rendering / gl / RenderSystemGL.h
blob2e6e72ea911e69f365e08e6d54160fa62f1cc5e3
1 /*
2 * Copyright (C) 2005-2024 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "GLShader.h"
12 #include "rendering/RenderSystem.h"
13 #include "utils/ColorUtils.h"
14 #include "utils/Map.h"
16 #include <map>
17 #include <memory>
19 #include <fmt/format.h>
21 #include "system_gl.h"
23 enum class ShaderMethodGL
25 SM_DEFAULT = 0,
26 SM_TEXTURE,
27 SM_TEXTURE_LIM,
28 SM_MULTI,
29 SM_FONTS,
30 SM_FONTS_SHADER_CLIP,
31 SM_TEXTURE_NOBLEND,
32 SM_MULTI_BLENDCOLOR,
33 SM_MAX
36 template<>
37 struct fmt::formatter<ShaderMethodGL> : fmt::formatter<std::string_view>
39 template<typename FormatContext>
40 constexpr auto format(const ShaderMethodGL& shaderMethod, FormatContext& ctx)
42 const auto it = ShaderMethodGLMap.find(shaderMethod);
43 if (it == ShaderMethodGLMap.cend())
44 throw std::range_error("no string mapping found for shader method");
46 return fmt::formatter<string_view>::format(it->second, ctx);
49 private:
50 static constexpr auto ShaderMethodGLMap = make_map<ShaderMethodGL, std::string_view>({
51 {ShaderMethodGL::SM_DEFAULT, "default"},
52 {ShaderMethodGL::SM_TEXTURE, "texture"},
53 {ShaderMethodGL::SM_TEXTURE_LIM, "texture limited"},
54 {ShaderMethodGL::SM_MULTI, "multi"},
55 {ShaderMethodGL::SM_FONTS, "fonts"},
56 {ShaderMethodGL::SM_FONTS_SHADER_CLIP, "fonts with vertex shader based clipping"},
57 {ShaderMethodGL::SM_TEXTURE_NOBLEND, "texture no blending"},
58 {ShaderMethodGL::SM_MULTI_BLENDCOLOR, "multi blend colour"},
59 });
61 static_assert(static_cast<size_t>(ShaderMethodGL::SM_MAX) == ShaderMethodGLMap.size(),
62 "ShaderMethodGLMap doesn't match the size of ShaderMethodGL, did you forget to "
63 "add/remove a mapping?");
66 class CRenderSystemGL : public CRenderSystemBase
68 public:
69 CRenderSystemGL();
70 ~CRenderSystemGL() override;
71 bool InitRenderSystem() override;
72 bool DestroyRenderSystem() override;
73 bool ResetRenderSystem(int width, int height) override;
75 bool BeginRender() override;
76 bool EndRender() override;
77 void PresentRender(bool rendered, bool videoLayer) override;
78 void InvalidateColorBuffer() override;
79 bool ClearBuffers(KODI::UTILS::COLOR::Color color) override;
80 bool IsExtSupported(const char* extension) const override;
82 void SetVSync(bool vsync);
83 void ResetVSync() { m_bVsyncInit = false; }
85 void SetViewPort(const CRect& viewPort) override;
86 void GetViewPort(CRect& viewPort) override;
88 bool ScissorsCanEffectClipping() override;
89 CRect ClipRectToScissorRect(const CRect &rect) override;
90 void SetScissors(const CRect &rect) override;
91 void ResetScissors() override;
93 void SetDepthCulling(DEPTH_CULLING culling) override;
95 void CaptureStateBlock() override;
96 void ApplyStateBlock() override;
98 void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor = 0.0f) override;
100 void SetStereoMode(RENDER_STEREO_MODE mode, RENDER_STEREO_VIEW view) override;
101 bool SupportsStereo(RENDER_STEREO_MODE mode) const override;
102 bool SupportsNPOT(bool dxt) const override;
104 void Project(float &x, float &y, float &z) override;
106 std::string GetShaderPath(const std::string &filename) override;
108 void GetGLVersion(int& major, int& minor);
109 void GetGLSLVersion(int& major, int& minor);
111 void ResetGLErrors();
113 // shaders
114 void EnableShader(ShaderMethodGL method);
115 void DisableShader();
116 GLint ShaderGetPos();
117 GLint ShaderGetCol();
118 GLint ShaderGetCoord0();
119 GLint ShaderGetCoord1();
120 GLint ShaderGetDepth();
121 GLint ShaderGetUniCol();
122 GLint ShaderGetModel();
123 GLint ShaderGetMatrix();
124 GLint ShaderGetClip();
125 GLint ShaderGetCoordStep();
127 protected:
128 virtual void SetVSyncImpl(bool enable) = 0;
129 virtual void PresentRenderImpl(bool rendered) = 0;
130 void CalculateMaxTexturesize();
131 void InitialiseShaders();
132 void ReleaseShaders();
134 bool m_bVsyncInit = false;
135 int m_width;
136 int m_height;
138 std::string m_RenderExtensions;
140 int m_glslMajor = 0;
141 int m_glslMinor = 0;
143 GLint m_viewPort[4];
145 std::map<ShaderMethodGL, std::unique_ptr<CGLShader>> m_pShader;
146 ShaderMethodGL m_method = ShaderMethodGL::SM_DEFAULT;
147 GLuint m_vertexArray = GL_NONE;