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