libdonut  2.3.2
Application framework for cross-platform game development in C++20
Shader2D.hpp
Go to the documentation of this file.
1 #ifndef DONUT_GRAPHICS_SHADER_2D_HPP
2 #define DONUT_GRAPHICS_SHADER_2D_HPP
3 
7 
8 namespace donut::graphics {
9 
10 class Renderer; // Forward declaration, to avoid a circular include of Renderer.hpp.
11 
21  .faceCullingMode = FaceCullingMode::IGNORE,
22  .alphaMode = AlphaMode::USE_ALPHA_BLENDING,
23  };
24 };
25 
29 class Shader2D {
30 public:
36 
41  static const char* const FRAGMENT_SHADER_SOURCE_CODE_PLAIN;
42 
48  static const char* const FRAGMENT_SHADER_SOURCE_CODE_ALPHA;
49 
58  static Shader2D* const PLAIN;
59 
68  static Shader2D* const ALPHA;
69 
74 
79 
84 
89 
94  ShaderParameter viewProjectionMatrix{program, "viewProjectionMatrix"};
95 
100 
113  Shader2D(const ShaderProgramOptions& programOptions, const Shader2DOptions& options = {})
114  : options(options)
115  , program(programOptions) {}
116 
117 private:
118  friend Renderer;
119 
120  static void createSharedShaders();
121  static void destroySharedShaders() noexcept;
122 };
123 
124 } // namespace donut::graphics
125 
126 #endif
ShaderProgram specialized for rendering TexturedQuad instances in 2D.
Definition: Shader2D.hpp:29
static const char *const FRAGMENT_SHADER_SOURCE_CODE_PLAIN
Pointer to a statically allocated string containing the GLSL source code for a plain fragment shader.
Definition: Shader2D.hpp:41
ShaderParameter viewMatrix
Identifier for the uniform shader variable for the view matrix.
Definition: Shader2D.hpp:88
static Shader2D *const PLAIN
Pointer to the statically allocated storage for the built-in plain shader.
Definition: Shader2D.hpp:58
ShaderParameter viewProjectionMatrix
Identifier for the uniform shader variable for the combined view-projection matrix.
Definition: Shader2D.hpp:94
ShaderParameter projectionMatrix
Identifier for the uniform shader variable for the projection matrix.
Definition: Shader2D.hpp:83
static Shader2D *const ALPHA
Pointer to the statically allocated storage for the built-in alpha shader.
Definition: Shader2D.hpp:68
Shader2DOptions options
Shader configuration that was supplied in the constructor.
Definition: Shader2D.hpp:73
ShaderProgram program
Shader program.
Definition: Shader2D.hpp:78
ShaderParameter textureUnit
Identifier for the uniform shader variable for the main texture unit.
Definition: Shader2D.hpp:99
Shader2D(const ShaderProgramOptions &programOptions, const Shader2DOptions &options={})
Compile and link a 2D shader program.
Definition: Shader2D.hpp:113
static const char *const VERTEX_SHADER_SOURCE_CODE_INSTANCED_TEXTURED_QUAD
Pointer to a statically allocated string containing the GLSL source code for a plain vertex shader.
Definition: Shader2D.hpp:35
static const char *const FRAGMENT_SHADER_SOURCE_CODE_ALPHA
Pointer to a statically allocated string containing the GLSL source code for a fragment shader that i...
Definition: Shader2D.hpp:48
Identifier for a uniform shader variable inside a ShaderProgram.
Definition: ShaderParameter.hpp:17
Compiled and linked GPU shader program.
Definition: ShaderProgram.hpp:46
Definition: Buffer.hpp:7
@ IGNORE
Ignore the depth buffer.
@ USE_ALPHA_BLENDING
Blend the old and new pixel colors depending on the alpha value of the new pixel according to the sta...
Configuration options for a Shader2D.
Definition: Shader2D.hpp:15
ShaderConfiguration configuration
Shader configuration options, see ShaderConfiguration.
Definition: Shader2D.hpp:19
Base configuration options for a shader.
Definition: ShaderConfiguration.hpp:299
DepthBufferMode depthBufferMode
How to treat the depth buffer for each pixel being rendered.
Definition: ShaderConfiguration.hpp:305
Configuration options for a ShaderProgram.
Definition: ShaderProgram.hpp:23