xbmc
RenderSystemGL.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "GLShader.h"
12 #include "rendering/RenderSystem.h"
13 #include "utils/ColorUtils.h"
14 #include "utils/Map.h"
15 
16 #include <map>
17 #include <memory>
18 
19 #include <fmt/format.h>
20 
21 #include "system_gl.h"
22 
23 enum class ShaderMethodGL
24 {
25  SM_DEFAULT = 0,
26  SM_TEXTURE,
27  SM_TEXTURE_LIM,
28  SM_MULTI,
29  SM_FONTS,
30  SM_TEXTURE_NOBLEND,
31  SM_MULTI_BLENDCOLOR,
32  SM_MAX
33 };
34 
35 template<>
36 struct fmt::formatter<ShaderMethodGL> : fmt::formatter<std::string_view>
37 {
38  template<typename FormatContext>
39  constexpr auto format(const ShaderMethodGL& shaderMethod, FormatContext& ctx)
40  {
41  const auto it = ShaderMethodGLMap.find(shaderMethod);
42  if (it == ShaderMethodGLMap.cend())
43  throw std::range_error("no string mapping found for shader method");
44 
45  return fmt::formatter<string_view>::format(it->second, ctx);
46  }
47 
48 private:
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"},
57  });
58 
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?");
62 };
63 
65 {
66 public:
68  ~CRenderSystemGL() override;
69  bool InitRenderSystem() override;
70  bool DestroyRenderSystem() override;
71  bool ResetRenderSystem(int width, int height) override;
72 
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;
78 
79  void SetVSync(bool vsync);
80  void ResetVSync() { m_bVsyncInit = false; }
81 
82  void SetViewPort(const CRect& viewPort) override;
83  void GetViewPort(CRect& viewPort) override;
84 
85  bool ScissorsCanEffectClipping() override;
86  CRect ClipRectToScissorRect(const CRect &rect) override;
87  void SetScissors(const CRect &rect) override;
88  void ResetScissors() override;
89 
90  void CaptureStateBlock() override;
91  void ApplyStateBlock() override;
92 
93  void SetCameraPosition(const CPoint &camera, int screenWidth, int screenHeight, float stereoFactor = 0.0f) override;
94 
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;
98 
99  void Project(float &x, float &y, float &z) override;
100 
101  std::string GetShaderPath(const std::string &filename) override;
102 
103  void GetGLVersion(int& major, int& minor);
104  void GetGLSLVersion(int& major, int& minor);
105 
106  void ResetGLErrors();
107 
108  // shaders
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();
117 
118 protected:
119  virtual void SetVSyncImpl(bool enable) = 0;
120  virtual void PresentRenderImpl(bool rendered) = 0;
121  void CalculateMaxTexturesize();
122  void InitialiseShaders();
123  void ReleaseShaders();
124 
125  bool m_bVsyncInit = false;
126  int m_width;
127  int m_height;
128 
129  std::string m_RenderExtensions;
130 
131  int m_glslMajor = 0;
132  int m_glslMinor = 0;
133 
134  GLint m_viewPort[4];
135 
136  std::map<ShaderMethodGL, std::unique_ptr<CGLShader>> m_pShader;
137  ShaderMethodGL m_method = ShaderMethodGL::SM_DEFAULT;
138  GLuint m_vertexArray = GL_NONE;
139 };
Definition: RenderSystemGL.h:64
Definition: RenderSystem.h:27