Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PostprocManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_POSTPROCMANAGER
19 #define INCLUDED_POSTPROCMANAGER
20 
21 
23 
25 {
26 private:
27 
28  // Two framebuffers, that we flip between at each shader pass.
30 
31  // Unique colour textures for the framebuffers.
33 
34  // The framebuffers share a depth/stencil texture.
35  GLuint m_DepthTex;
36 
37  // A framebuffer and textures x2 for each blur level we render.
39 
40  // Indicates which of the ping-pong buffers is used for reading and which for drawing.
42 
43  // The name and shader technique we are using. "default" name means no technique is used
44  // (i.e. while we do allocate the buffers, no effects are rendered).
47 
48  // The current screen dimensions in pixels.
50 
51  // Is the postproc manager initialised? Buffers created? Default effect loaded?
53 
54  // Creates blur textures at various scales, for bloom, DOF, etc.
55  void ApplyBlur();
56 
57  // High quality GPU image scaling to half size. outTex must have exactly half the size
58  // of inTex. inWidth and inHeight are the dimensions of inTex in texels.
59  void ApplyBlurDownscale2x(GLuint inTex, GLuint outTex, int inWidth, int inHeight);
60 
61  // GPU-based Gaussian blur in two passes. inOutTex contains the input image and will be filled
62  // with the blurred image. tempTex must have the same size as inOutTex.
63  // inWidth and inHeight are the dimensions of the images in texels.
64  void ApplyBlurGauss(GLuint inOutTex, GLuint tempTex, int inWidth, int inHeight);
65 
66  // Applies a pass of a given effect to the entire current framebuffer. The shader is
67  // provided with a number of general-purpose variables, including the rendered screen so far,
68  // the depth buffer, a number of blur textures, the screen size, the zNear/zFar planes and
69  // some other parameters used by the optional bloom/HDR pass.
70  void ApplyEffect(CShaderTechniquePtr &shaderTech1, int pass);
71 
72 public:
75 
76  // Create all buffers/textures in GPU memory and set default effect.
77  void Initialize();
78 
79  // Delete all allocated buffers/textures from GPU memory.
80  void Cleanup();
81 
82  // Delete existing buffers/textures and create them again, using a new screen size if needed.
83  // (the textures are also attached to the framebuffers)
84  void RecreateBuffers();
85 
86  // Loads a new postproc effect. "default" effect does NOT load anything.
87  void LoadEffect(CStrW &name);
88 
89  // Returns a list of xml files found in shaders/effects/postproc.
90  std::vector<CStrW> GetPostEffects() const;
91 
92  // Returns the name of the current effect.
93  inline const CStrW& GetPostEffect() const
94  {
95  return m_PostProcEffect;
96  }
97 
98  // Matching setter that calls LoadEffect.
99  void SetPostEffect(CStrW name);
100 
101  // Clears the two colour buffers and depth buffer, and redirects all rendering
102  // to our textures instead of directly to the system framebuffer.
103  void CaptureRenderOutput();
104 
105  // First renders blur textures, then calls ApplyEffect for each effect pass,
106  // ping-ponging the buffers at each step.
107  void ApplyPostproc();
108 
109  // Blits the final postprocessed texture to the system framebuffer. The system framebuffer
110  // is selected as the output buffer. Should be called before silhouette rendering.
111  void ReleaseRenderOutput();
112 };
113 
114 
115 #endif //INCLUDED_POSTPROCMANAGER
CShaderTechniquePtr m_PostProcTech
void ApplyBlurGauss(GLuint inOutTex, GLuint tempTex, int inWidth, int inHeight)
shared_ptr< CShaderTechnique > CShaderTechniquePtr
std::vector< CStrW > GetPostEffects() const
void ApplyEffect(CShaderTechniquePtr &shaderTech1, int pass)
const CStrW & GetPostEffect() const
void ApplyBlurDownscale2x(GLuint inTex, GLuint outTex, int inWidth, int inHeight)
void LoadEffect(CStrW &name)
void SetPostEffect(CStrW name)