Commit 30348b3d authored by Christopher Tenter's avatar Christopher Tenter

add custom msaa resolve including multisampled depth

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20474 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 2e332185
......@@ -57,12 +57,14 @@
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/ScreenQuad.hh>
#include <ACG/GL/ShaderCache.hh>
//== DEFINES ==================================================================
// shader files
#define MSAA_SCREENQUAD_SHADER "ScreenQuad/screenquad.glsl"
#define MSAA_NEAREST_SHADER "MSAA/sample_nearest.glsl"
#define MSAA_NEAREST_DEPTH_SHADER "MSAA/sample_nearest_and_depth.glsl"
#define MSAA_LINEAR_SHADER "MSAA/sample_linear.glsl"
......@@ -131,13 +133,14 @@ void MSFilterWeights::asTextureBuffer( TextureBuffer& out ) {
//=============================================================================
MSTextureSampler::MSTextureSampler() : shaderNearest_(0), shaderLinear_(0) {
MSTextureSampler::MSTextureSampler() : shaderNearest_(0), shaderNearestDepth_(0), shaderLinear_(0) {
}
MSTextureSampler::~MSTextureSampler() {
delete shaderNearest_;
delete shaderLinear_;
delete shaderNearest_;
}
MSTextureSampler& MSTextureSampler::instance() {
......@@ -151,6 +154,9 @@ void MSTextureSampler::init() {
if (!shaderNearest_)
shaderNearest_ = GLSL::loadProgram(MSAA_SCREENQUAD_SHADER, MSAA_NEAREST_SHADER);
if (!shaderNearestDepth_)
shaderNearestDepth_ = GLSL::loadProgram(MSAA_SCREENQUAD_SHADER, MSAA_NEAREST_DEPTH_SHADER);
if (!shaderLinear_)
shaderLinear_ = GLSL::loadProgram(MSAA_SCREENQUAD_SHADER, MSAA_LINEAR_SHADER);
}
......@@ -193,6 +199,48 @@ void MSTextureSampler::filterMSAATexture_Nearest( GLuint _texture, int _samples,
//=============================================================================
void MSTextureSampler::filterMSAATexture_Nearest( GLuint _texture, GLuint _depthTexture, int _samples, const float* _weights /*= 0*/ ) {
MSTextureSampler& sampler = instance();
// load shader
if (!sampler.shaderNearestDepth_)
sampler.init();
// GLSL::Program* shader = sampler.shaderNearestDepth_;
GLSL::Program* shader = ACG::ShaderCache::getInstance()->getProgram(MSAA_SCREENQUAD_SHADER, MSAA_NEAREST_DEPTH_SHADER);
if (!shader)
return;
shader->use();
// offset and scale of screenquad
shader->setUniform("offset", Vec2f(0.0f, 0.0f));
shader->setUniform("size", Vec2f(1.0f, 1.0f));
// sample count and filter weights
shader->setUniform("numSamples", _samples);
// bind multisampled depth texture to slot 1
shader->setUniform("inputDepthTex", 1);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _depthTexture);
// bind multisampled texture to slot 0
shader->setUniform("inputTex", 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _texture);
// run texture filter
ScreenQuad::draw(shader);
shader->disable();
}
//=============================================================================
void MSTextureSampler::filterMSAATexture_Linear( GLuint _texture, int _samples, const float* _weights /*= 0*/ ) {
MSTextureSampler& sampler = instance();
......
......@@ -155,6 +155,10 @@ public:
// nearest point filtering of a MSAA texture, recommended when the target FBO has the same size as the input texture
static void filterMSAATexture_Nearest(GLuint _texture, int _samples, const float* _weights = 0);
// nearest point filtering of a MSAA texture, recommended when the target FBO has the same size as the input texture
// also resolves a multisampled depth texture into the depth target
static void filterMSAATexture_Nearest(GLuint _texture, GLuint _depthTexture, int _samples, const float* _weights = 0);
// bilinear filtering of a MSAA texture
static void filterMSAATexture_Linear(GLuint _texture, int _samples, const float* _weights = 0);
......@@ -173,6 +177,7 @@ private:
// sampling shaders for nearest and bilinear texture filtering
GLSL::Program* shaderNearest_;
GLSL::Program* shaderNearestDepth_;
GLSL::Program* shaderLinear_;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment