2 * Copyright (C) 2005-2018 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.
12 #include "rendering/RenderSystem.h"
13 #include "utils/ColorUtils.h"
14 #include "utils/Map.h"
19 #include <fmt/format.h>
21 #include "system_gl.h"
23 enum class ShaderMethodGL
36 struct fmt::formatter
<ShaderMethodGL
> : fmt::formatter
<std::string_view
>
38 template<typename FormatContext
>
39 constexpr auto format(const ShaderMethodGL
& shaderMethod
, FormatContext
& ctx
)
41 const auto it
= ShaderMethodGLMap
.find(shaderMethod
);
42 if (it
== ShaderMethodGLMap
.cend())
43 throw std::range_error("no string mapping found for shader method");
45 return fmt::formatter
<string_view
>::format(it
->second
, ctx
);
49 static constexpr auto ShaderMethodGLMap
= make_map
<ShaderMethodGL
, std::string_view
>({
50 {ShaderMethodGL::SM_DEFAULT
, "default"},
51 {ShaderMethodGL::SM_TEXTURE
, "texture"},
52 {ShaderMethodGL::SM_TEXTURE_LIM
, "texture limited"},
53 {ShaderMethodGL::SM_MULTI
, "multi"},
54 {ShaderMethodGL::SM_FONTS
, "fonts"},
55 {ShaderMethodGL::SM_TEXTURE_NOBLEND
, "texture no blending"},
56 {ShaderMethodGL::SM_MULTI_BLENDCOLOR
, "multi blend colour"},
59 static_assert(static_cast<size_t>(ShaderMethodGL::SM_MAX
) == ShaderMethodGLMap
.size(),
60 "ShaderMethodGLMap doesn't match the size of ShaderMethodGL, did you forget to "
61 "add/remove a mapping?");
64 class CRenderSystemGL
: public CRenderSystemBase
68 ~CRenderSystemGL() override
;
69 bool InitRenderSystem() override
;
70 bool DestroyRenderSystem() override
;
71 bool ResetRenderSystem(int width
, int height
) override
;
73 bool BeginRender() override
;
74 bool EndRender() override
;
75 void PresentRender(bool rendered
, bool videoLayer
) override
;
76 bool ClearBuffers(UTILS::COLOR::Color color
) override
;
77 bool IsExtSupported(const char* extension
) const override
;
79 void SetVSync(bool vsync
);
80 void ResetVSync() { m_bVsyncInit
= false; }
82 void SetViewPort(const CRect
& viewPort
) override
;
83 void GetViewPort(CRect
& viewPort
) override
;
85 bool ScissorsCanEffectClipping() override
;
86 CRect
ClipRectToScissorRect(const CRect
&rect
) override
;
87 void SetScissors(const CRect
&rect
) override
;
88 void ResetScissors() override
;
90 void CaptureStateBlock() override
;
91 void ApplyStateBlock() override
;
93 void SetCameraPosition(const CPoint
&camera
, int screenWidth
, int screenHeight
, float stereoFactor
= 0.0f
) override
;
95 void SetStereoMode(RENDER_STEREO_MODE mode
, RENDER_STEREO_VIEW view
) override
;
96 bool SupportsStereo(RENDER_STEREO_MODE mode
) const override
;
97 bool SupportsNPOT(bool dxt
) const override
;
99 void Project(float &x
, float &y
, float &z
) override
;
101 std::string
GetShaderPath(const std::string
&filename
) override
;
103 void GetGLVersion(int& major
, int& minor
);
104 void GetGLSLVersion(int& major
, int& minor
);
106 void ResetGLErrors();
109 void EnableShader(ShaderMethodGL method
);
110 void DisableShader();
111 GLint
ShaderGetPos();
112 GLint
ShaderGetCol();
113 GLint
ShaderGetCoord0();
114 GLint
ShaderGetCoord1();
115 GLint
ShaderGetUniCol();
116 GLint
ShaderGetModel();
119 virtual void SetVSyncImpl(bool enable
) = 0;
120 virtual void PresentRenderImpl(bool rendered
) = 0;
121 void CalculateMaxTexturesize();
122 void InitialiseShaders();
123 void ReleaseShaders();
125 bool m_bVsyncInit
= false;
129 std::string m_RenderExtensions
;
136 std::map
<ShaderMethodGL
, std::unique_ptr
<CGLShader
>> m_pShader
;
137 ShaderMethodGL m_method
= ShaderMethodGL::SM_DEFAULT
;
138 GLuint m_vertexArray
= GL_NONE
;