Beatmup
rendering_programs.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "../gpu/program.h"
21 #include "../geometry.h"
22 #include <map>
23 
24 namespace Beatmup {
25  namespace GL {
26 
27  /**
28  Handles a collection of common rendering programs of predefined types and shared operations among these
29  programs.
30  Programs compilation and linking is done in a deferred fashion, so that the first rendering pass would
31  usually take much more time, but no time is spent on initializing programs that will never be used.
32  */
34  public:
35  /**
36  Standard rendering operations
37  */
38  enum class Operation {
39  BLEND, //!< default blending of a single image
40  MASKED_BLEND, //!< blending an image through a pixelwise mask
41  MASKED_8BIT_BLEND, //!< blending an image through a 8 bit pixelwise mask
42  SHAPED_BLEND, //!< shaping an image
43  BLEND_EXT, //!< default blending using a texture extension
44  MASKED_BLEND_EXT, //!< blending an image through a pixelwise mask (texture extension)
45  MASKED_8BIT_BLEND_EXT, //!< blending an image through a 8 bit pixelwise mask (texture extension)
46  SHAPED_BLEND_EXT, //!< shaping an image (texture extension)
47  };
48 
49  static const char
50  *VERTEX_COORD_ATTRIB_NAME, //!< vertex coordinate attribute name in vertex shaders
51  *TEXTURE_COORD_ATTRIB_NAME, //!< texture coordinate attribute name in vertex shaders
52 
53  *VERTICAL_FLIP_ID, //!< Vertical flipping variable name in vertex shader
54  *MODELVIEW_MATRIX_ID, //!< Modelview matrix (mapping input geometry to output) shader variable name in vertex shader
55  *TEXTURE_COORDINATES_ID, //!< Texture coordinates shader variable name in vertex shader
56 
57  *DECLARE_TEXTURE_COORDINATES_IN_FRAG; //!< Declaring texture coordinates in fragment shader.
58 
59 
60 
61  /**
62  \brief Select and enable a common program.
63  If the selected program is not yet ready, it is linked and complied.
64  \param[in,out] gpu A graphic pipeline instance
65  \param[in,out] program The selected common program to use
66  */
67  void enableProgram(GraphicPipeline* gpu, Operation program);
68 
69 
70  /**
71  \return the currently used rendering program.
72  */
74 
75 
76  /**
77  \brief Binds a mask to a masked rendering program.
78  Throws an exception when a mask is about to be bound to a non-masked rendering program.
79  \param[in,out] gpu A graphic pipeline instance
80  \param[in,out] mask The mask bitmap
81  */
82  void bindMask(GraphicPipeline* gpu, AbstractBitmap& mask);
83 
84 
85  /**
86  Performs the blending operation
87  \param[in] onScreen If `true`, the rendering is performed on a screen, not into a bitmap.
88  */
89  void blend(bool onScreen);
90 
91  /**
92  Fills background with a repeated texture taking 1 pixel of this texture per 1 pixel of the output
93  \param[in,out] gpu A graphic pipeline instance
94  \param[in] content The texture
95  \param[in] output Target texture handler or null if onscreen rendering
96  */
98 
99 
100  /**
101  \return default blending vertex shader to be used in a user-defined single-image blending program.
102  */
103  const VertexShader& getDefaultVertexShader(const GraphicPipeline* gpu) const;
104 
107 
108  private:
109  class Backend;
113  bool maskSetUp;
114 
116  std::map<Operation, RenderingProgram> programs;
117 
118  Program& getProgram(const GraphicPipeline* gpu, Operation program);
119  };
120  }
121 }
A very basic class for any image.
Regular OpenGL program.
Definition: program.h:229
Handles a collection of common rendering programs of predefined types and shared operations among the...
static const char * TEXTURE_COORD_ATTRIB_NAME
texture coordinate attribute name in vertex shaders
void paveBackground(GraphicPipeline *gpu, TextureHandler &content, GL::TextureHandler *output)
Fills background with a repeated texture taking 1 pixel of this texture per 1 pixel of the output.
Program & getProgram(const GraphicPipeline *gpu, Operation program)
std::map< Operation, RenderingProgram > programs
void enableProgram(GraphicPipeline *gpu, Operation program)
Select and enable a common program.
static const char * TEXTURE_COORDINATES_ID
Texture coordinates shader variable name in vertex shader.
Operation
Standard rendering operations.
@ MASKED_BLEND_EXT
blending an image through a pixelwise mask (texture extension)
@ MASKED_8BIT_BLEND_EXT
blending an image through a 8 bit pixelwise mask (texture extension)
@ BLEND_EXT
default blending using a texture extension
@ MASKED_8BIT_BLEND
blending an image through a 8 bit pixelwise mask
@ MASKED_BLEND
blending an image through a pixelwise mask
@ SHAPED_BLEND_EXT
shaping an image (texture extension)
@ BLEND
default blending of a single image
static const char * VERTEX_COORD_ATTRIB_NAME
vertex coordinate attribute name in vertex shaders
static const char * VERTICAL_FLIP_ID
Vertical flipping variable name in vertex shader.
const VertexShader & getDefaultVertexShader(const GraphicPipeline *gpu) const
static const char * DECLARE_TEXTURE_COORDINATES_IN_FRAG
Declaring texture coordinates in fragment shader.
static const char * MODELVIEW_MATRIX_ID
Modelview matrix (mapping input geometry to output) shader variable name in vertex shader.
void blend(bool onScreen)
Performs the blending operation.
RenderingPrograms(GraphicPipeline *gpu)
void bindMask(GraphicPipeline *gpu, AbstractBitmap &mask)
Binds a mask to a masked rendering program.
GLSL vertex shader.
Definition: program.h:93
Internal low-level GPU control API.
Definition: pipeline.h:33
std::string content