61 #include <ACG/GL/acg_glew.hh> 62 #include <ACG/GL/AntiAliasing.hh> 63 #include <ACG/ShaderUtils/GLSLShader.hh> 64 #include <ACG/GL/ScreenQuad.hh> 66 #include <ACG/GL/ShaderCache.hh> 71 #define MSAA_SCREENQUAD_SHADER "ScreenQuad/screenquad.glsl" 72 #define MSAA_NEAREST_SHADER "MSAA/sample_nearest.glsl" 73 #define MSAA_NEAREST_DEPTH_SHADER "MSAA/sample_nearest_and_depth.glsl" 74 #define MSAA_LINEAR_SHADER "MSAA/sample_linear.glsl" 85 #ifdef GL_ARB_texture_multisample 88 MSFilterWeights::MSFilterWeights(
int _numSamples) : numSamples_(_numSamples) {
90 weights_.resize(_numSamples);
91 float sumWeights = 0.0f;
95 Vec2f texelCenter(0.5f, 0.5f);
99 glGetIntegerv(GL_SAMPLES, &fboSamples);
102 for (
int i = 0; i < _numSamples; ++i) {
106 glGetMultisamplefv(GL_SAMPLE_POSITION, i, val);
108 val[0] = val[1] = 0.5f;
110 Vec2f samplePosition(val[0], val[1]);
113 float sampleDist = (samplePosition - texelCenter).norm();
116 weights_[i] = 1.0f - sampleDist;
118 sumWeights += weights_[i];
123 for (
int i = 0; i < _numSamples; ++i)
124 weights_[i] /= sumWeights;
129 void MSFilterWeights::asTextureBuffer( TextureBuffer& out ) {
131 out.setBufferData(numSamples_ * 4, &weights_[0], GL_R32F, GL_STATIC_DRAW);
142 MSTextureSampler::MSTextureSampler() : shaderNearest_(0), shaderNearestDepth_(0), shaderLinear_(0) {
146 MSTextureSampler::~MSTextureSampler() {
147 delete shaderNearest_;
148 delete shaderLinear_;
149 delete shaderNearestDepth_;
152 MSTextureSampler& MSTextureSampler::instance() {
153 static MSTextureSampler singleton;
159 void MSTextureSampler::init() {
163 if (!shaderNearestDepth_)
164 shaderNearestDepth_ =
GLSL::loadProgram(MSAA_SCREENQUAD_SHADER, MSAA_NEAREST_DEPTH_SHADER);
172 void MSTextureSampler::filterMSAATexture_Nearest( GLuint _texture,
int _samples,
const float* _weights ) {
174 MSTextureSampler& sampler = instance();
177 if (!sampler.shaderNearest_)
197 glActiveTexture(GL_TEXTURE0);
198 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _texture);
201 ScreenQuad::draw(shader);
208 void MSTextureSampler::filterMSAATexture_Nearest( GLuint _texture, GLuint _depthTexture,
int _samples,
const float* _weights ) {
210 MSTextureSampler& sampler = instance();
213 if (!sampler.shaderNearestDepth_)
234 glActiveTexture(GL_TEXTURE1);
235 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _depthTexture);
239 glActiveTexture(GL_TEXTURE0);
240 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _texture);
243 ScreenQuad::draw(shader);
250 void MSTextureSampler::filterMSAATexture_Linear( GLuint _texture,
int _samples,
const float* _weights ) {
252 MSTextureSampler& sampler = instance();
255 if (!sampler.shaderLinear_)
275 glActiveTexture(GL_TEXTURE0);
276 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _texture);
279 ScreenQuad::draw(shader);
289 #endif // GL_ARB_texture_multisample static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
GLSL::PtrProgram loadProgram(const char *vertexShaderFile, const char *tessControlShaderFile, const char *tessEvaluationShaderFile, const char *geometryShaderFile, const char *fragmentShaderFile, const GLSL::StringList *macros, bool verbose)
void use()
Enables the program object for using.
VectorT< float, 2 > Vec2f
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
Namespace providing different geometric functions concerning angles.
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
void disable()
Resets to standard rendering pipeline.