Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AntiAliasing.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision: 18130 $ *
45  * $Author: moebius $ *
46  * $Date: 2014-02-05 10:41:16 +0100 (Wed, 05 Feb 2014) $ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // Helper classes for Anti-Aliasing of render targets
55 //
56 //=============================================================================
57 
58 
59 #ifndef ANTI_ALIASING_HH
60 #define ANTI_ALIASING_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 // GL
66 #include <ACG/GL/globjects.hh>
67 #include <ACG/GL/gl.hh>
68 
69 // C++
70 #include <vector>
71 
72 
73 //== FORWARD DECLARATIONS =====================================================
74 
75 namespace GLSL{
76  class Program;
77 }
78 
79 
80 //== NAMESPACES ===============================================================
81 
82 namespace ACG {
83 
84 
85 //== CLASS DEFINITION =========================================================
86 
87 
88 /*
89 OpenGL MSAA:
90 
91 A post-processing fragment shader has to compute colors per sample rather than per pixel for full MSAA.
92 Sample values are then weighted by filter weights to obtain a final pixel color.
93 
94 Filter weights can be computed with several methods, for example:
95  - distance based filter weights (computed with MSFilterWeights)
96  - constant filter weights: 1/numSamples
97 
98 However, a faster approach can be used where the MSAA texture is filtered onto a regular texture first,
99 followed by executing post processing shaders on that regular texture.
100 While this is not a correct MSAA implementation, it can give something close at better performance.
101 -> MSTextureSampler can be used to filter a MSAA texture onto a regular texture
102 
103 Recommended resources on implementing MSAA with render to texture:
104  http://diaryofagraphicsprogrammer.blogspot.com/2009/06/multisample-anti-aliasing.html
105  http://www.humus.name/index.php?page=3D&ID=81
106 */
107 
108 
109 #ifdef GL_ARB_texture_multisample
110 
111 class ACGDLLEXPORT MSFilterWeights
112 {
113 public:
114 
115  MSFilterWeights(int _numSamples);
116 
117  virtual ~MSFilterWeights() { }
118 
119 #if defined(GL_ARB_texture_buffer_object)
120 
121  // Initializes a texture buffer with filter weights in format GL_R32F.
122  // This can be used for reading from multisampled textures in a shader.
123  void asTextureBuffer(TextureBuffer& out);
124 
125 #endif
126 
127  // get ptr to weights as array, can be used for setUniform() for example
128  const float* asDataPtr() const {return &weights_[0];}
129 
130 
131  float operator [] (int i) const {return weights_[i];}
132 
133  float getWeight(int i) const {return weights_[i];}
134 
135  int getNumSamples() const {return numSamples_;}
136 
137 private:
138 
139  int numSamples_;
140  std::vector<float> weights_;
141 };
142 
143 #endif // GL_ARB_texture_multisample
144 
145 
146 
147 
148 //== CLASS DEFINITION =========================================================
149 
150 
151 // This class performs multisampling on MSAA textures and writes the result to the currently bound FBO.
152 
153 #ifdef GL_ARB_texture_multisample
154 
155 class ACGDLLEXPORT MSTextureSampler
156 {
157 public:
158 
159  ~MSTextureSampler();
160 
161 
162  // nearest point filtering of a MSAA texture, recommended when the target FBO has the same size as the input texture
163  static void filterMSAATexture_Nearest(GLuint _texture, int _samples, const float* _weights = 0);
164 
165  // nearest point filtering of a MSAA texture, recommended when the target FBO has the same size as the input texture
166  // also resolves a multisampled depth texture into the depth target
167  static void filterMSAATexture_Nearest(GLuint _texture, GLuint _depthTexture, int _samples, const float* _weights = 0);
168 
169  // bilinear filtering of a MSAA texture
170  static void filterMSAATexture_Linear(GLuint _texture, int _samples, const float* _weights = 0);
171 
172 private:
173 
174  MSTextureSampler();
175 
176 
177  void init();
178 
179  // singleton instance
180  static MSTextureSampler& instance();
181 
182 
183  TextureBuffer filterWeights_;
184 
185  // sampling shaders for nearest and bilinear texture filtering
186  GLSL::Program* shaderNearest_;
187  GLSL::Program* shaderNearestDepth_;
188  GLSL::Program* shaderLinear_;
189 };
190 
191 #endif // GL_ARB_texture_multisample
192 
193 
194 
195 // maybe add:
196 // - blitting of multisampled render buffers
197 // - automatic generation of MSAA variants of a post processing fragment shader
198 // - downsampling of supersampled FBOs
199 
200 //=============================================================================
201 } // namespace ACG
202 //=============================================================================
203 #endif // ANTI_ALIASING_HH defined
204 //=============================================================================
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:75
GLSL program class.
Definition: GLSLShader.hh:217