Pyrogenesis  trunk
PostprocManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 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 color 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 initialized? 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  // Delete all allocated buffers/textures from GPU memory.
73  void Cleanup();
74 
75  // Delete existing buffers/textures and create them again, using a new screen size if needed.
76  // (the textures are also attached to the framebuffers)
77  void RecreateBuffers();
78 
79 public:
82 
83  // Create all buffers/textures in GPU memory and set default effect.
84  // @note Must be called before using in the renderer. May be called multiple times.
85  void Initialize();
86 
87  // Update the size of the screen
88  void Resize();
89 
90  // Returns a list of xml files found in shaders/effects/postproc.
91  static std::vector<CStrW> GetPostEffects();
92 
93  // Returns the name of the current effect.
94  inline const CStrW& GetPostEffect() const
95  {
96  return m_PostProcEffect;
97  }
98 
99  // Sets the current effect.
100  void SetPostEffect(const CStrW& name);
101 
102  // Clears the two color buffers and depth buffer, and redirects all rendering
103  // to our textures instead of directly to the system framebuffer.
104  // @note CPostprocManager must be initialized first
105  void CaptureRenderOutput();
106 
107  // First renders blur textures, then calls ApplyEffect for each effect pass,
108  // ping-ponging the buffers at each step.
109  // @note CPostprocManager must be initialized first
110  void ApplyPostproc();
111 
112  // Blits the final postprocessed texture to the system framebuffer. The system framebuffer
113  // is selected as the output buffer. Should be called before silhouette rendering.
114  // @note CPostprocManager must be initialized first
115  void ReleaseRenderOutput();
116 };
117 
118 
119 #endif //INCLUDED_POSTPROCMANAGER
GLuint m_BlurTex2b
Definition: PostprocManager.h:38
GLuint m_BlurTex8b
Definition: PostprocManager.h:38
GLuint m_BlurTex4b
Definition: PostprocManager.h:38
CShaderTechniquePtr m_PostProcTech
Definition: PostprocManager.h:46
GLuint m_BlurTex2a
Definition: PostprocManager.h:38
GLuint m_PongFbo
Definition: PostprocManager.h:29
void ApplyBlurGauss(GLuint inOutTex, GLuint tempTex, int inWidth, int inHeight)
Definition: PostprocManager.cpp:257
void Initialize()
Definition: PostprocManager.cpp:75
shared_ptr< CShaderTechnique > CShaderTechniquePtr
Definition: ShaderTechnique.h:113
bool m_IsInitialized
Definition: PostprocManager.h:52
static std::vector< CStrW > GetPostEffects()
Definition: PostprocManager.cpp:514
CPostprocManager()
Definition: PostprocManager.cpp:39
void ApplyEffect(CShaderTechniquePtr &shaderTech1, int pass)
Definition: PostprocManager.cpp:401
void ApplyPostproc()
Definition: PostprocManager.cpp:474
GLuint m_DepthTex
Definition: PostprocManager.h:35
int m_Width
Definition: PostprocManager.h:49
int m_Height
Definition: PostprocManager.h:49
void Resize()
Definition: PostprocManager.cpp:91
bool m_WhichBuffer
Definition: PostprocManager.h:41
GLuint m_ColorTex1
Definition: PostprocManager.h:32
void ReleaseRenderOutput()
Definition: PostprocManager.cpp:380
const CStrW & GetPostEffect() const
Definition: PostprocManager.h:94
GLuint m_BlurTex8a
Definition: PostprocManager.h:38
GLuint m_ColorTex2
Definition: PostprocManager.h:32
~CPostprocManager()
Definition: PostprocManager.cpp:46
Definition: PostprocManager.h:24
GLuint m_BloomFbo
Definition: PostprocManager.h:38
void RecreateBuffers()
Definition: PostprocManager.cpp:101
void ApplyBlurDownscale2x(GLuint inTex, GLuint outTex, int inWidth, int inHeight)
Definition: PostprocManager.cpp:198
GLuint m_PingFbo
Definition: PostprocManager.h:29
void SetPostEffect(const CStrW &name)
Definition: PostprocManager.cpp:536
GLuint m_BlurTex4a
Definition: PostprocManager.h:38
void CaptureRenderOutput()
Definition: PostprocManager.cpp:360
void Cleanup()
Definition: PostprocManager.cpp:51
void ApplyBlur()
Definition: PostprocManager.cpp:334
CStrW m_PostProcEffect
Definition: PostprocManager.h:45