xbmc
ShaderGL.h
1 /*
2  * Copyright (C) 2019 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 "ShaderTextureGL.h"
12 #include "cores/RetroPlayer/shaders/IShader.h"
13 #include "cores/RetroPlayer/shaders/gl/ShaderTypesGL.h"
14 #include "guilib/TextureGL.h"
15 #include "rendering/gl/GLShader.h"
16 
17 #include <array>
18 #include <stdint.h>
19 
20 namespace KODI
21 {
22 namespace RETRO
23 {
24 
25 class CRenderContext;
26 
27 }
28 
29 namespace SHADER
30 {
31 class CShaderGL : public IShader
32 {
33 public:
35  ~CShaderGL() override = default;
36 
37  bool CreateVertexBuffer(unsigned vertCount, unsigned vertSize) override;
38 
39  // implementation of IShader
40  bool Create(const std::string& shaderSource,
41  const std::string& shaderPath,
42  ShaderParameterMap shaderParameters,
43  IShaderSampler* sampler,
44  ShaderLutVec luts,
45  float2 viewPortSize,
46  unsigned frameCountMod = 0) override;
47  void Render(IShaderTexture* source, IShaderTexture* target) override;
48  void SetSizes(const float2& prevSize, const float2& nextSize) override;
49  void PrepareParameters(CPoint dest[4], bool isLastPass, uint64_t frameCount) override;
50  void UpdateMVP() override;
51  bool CreateInputBuffer() override;
52  void UpdateInputBuffer(uint64_t frameCount);
53  void GetUniformLocs();
54 
55 protected:
56  void SetShaderParameters();
57 
58 private:
59  struct uniformInputs
60  {
61  float2 video_size;
62  float2 texture_size;
63  float2 output_size;
64  GLint frame_count;
65  GLfloat frame_direction;
66  };
67 
68  // Currently loaded shader's source code
69  std::string m_shaderSource;
70 
71  // Currently loaded shader's relative path
72  std::string m_shaderPath;
73 
74  // Array of shader parameters
75  ShaderParameterMap m_shaderParameters;
76 
77  // Look-up textures that the shader uses
78  ShaderLutVec m_luts; // todo: back to DX maybe
79 
80  // Resolution of the input of the shader
81  float2 m_inputSize;
82 
83  // Resolution of the output of the shader
84  float2 m_outputSize;
85 
86  // Resolution of the viewport/window
87  float2 m_viewportSize;
88 
89  // Resolution of the texture that holds the input
90  //float2 m_textureSize;
91 
92  GLuint m_shaderProgram = 0;
93 
94  // Projection matrix
95  std::array<std::array<GLfloat, 4>, 4> m_MVP;
96 
97  float m_VertexCoords[4][3];
98  float m_colors[4][3];
99  float m_TexCoords[4][2];
100  unsigned int m_indices[2][3];
101 
102  // Value to modulo (%) frame count with
103  // Unused if 0
104  unsigned m_frameCountMod = 0;
105 
106  GLint m_FrameDirectionLoc = -1;
107  GLint m_FrameCountLoc = -1;
108  GLint m_OutputSizeLoc = -1;
109  GLint m_TextureSizeLoc = -1;
110  GLint m_InputSizeLoc = -1;
111  GLint m_MVPMatrixLoc = -1;
112 
113 #ifndef HAS_GLES
114  GLuint VAO = 0;
115 #endif
116  GLuint EBO = 0;
117  GLuint VBO[3] = {};
118 
119 private:
120  uniformInputs GetInputData(uint64_t frameCount = 0);
121 };
122 } // namespace SHADER
123 } // namespace KODI
Definition: ShaderGL.h:31
Definition: AudioDecoder.h:18
Definition: RenderContext.h:43
Definition: IShader.h:25
Definition: IShaderTexture.h:15
Definition: ShaderTypes.h:108
Definition: IShaderSampler.h:15