Moved more shaders, moved createVAO into Shader.
This commit is contained in:
@@ -392,6 +392,62 @@ public:
|
||||
} // GlobalIlluminationReconstructionShader
|
||||
}; // GlobalIlluminationReconstructionShader
|
||||
|
||||
// ============================================================================
|
||||
class PassThroughShader : public TextureShader<PassThroughShader, 1, int, int>
|
||||
{
|
||||
public:
|
||||
PassThroughShader()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert",
|
||||
GL_FRAGMENT_SHADER, "passthrough.frag");
|
||||
assignUniforms("width", "height");
|
||||
assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED);
|
||||
} // PassThroughShader
|
||||
}; // PassThroughShader
|
||||
|
||||
// ============================================================================
|
||||
class LayerPassThroughShader : public Shader<LayerPassThroughShader, int>
|
||||
{
|
||||
private:
|
||||
GLuint m_tu_texture;
|
||||
GLuint m_vao;
|
||||
|
||||
public:
|
||||
LayerPassThroughShader()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert",
|
||||
GL_FRAGMENT_SHADER, "layertexturequad.frag");
|
||||
m_tu_texture = 0;
|
||||
assignUniforms("layer");
|
||||
assignTextureUnit(m_tu_texture, "tex");
|
||||
m_vao = createVAO();
|
||||
} // LayerPassThroughShader
|
||||
// ------------------------------------------------------------------------
|
||||
void bindVertexArray()
|
||||
{
|
||||
glBindVertexArray(m_vao);
|
||||
} // bindVertexArray
|
||||
// ------------------------------------------------------------------------
|
||||
void activateTexture()
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + m_tu_texture);
|
||||
} // activateTexture
|
||||
}; // LayerPassThroughShader
|
||||
|
||||
// ============================================================================
|
||||
class LinearizeDepthShader : public TextureShader<LinearizeDepthShader, 1,
|
||||
float, float>
|
||||
{
|
||||
public:
|
||||
LinearizeDepthShader()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert",
|
||||
GL_FRAGMENT_SHADER, "linearizedepth.frag");
|
||||
assignUniforms("zn", "zf");
|
||||
assignSamplerNames(0, "texture", ST_BILINEAR_FILTERED);
|
||||
} // LinearizeDepthShader
|
||||
}; // LinearizeDepthShader
|
||||
|
||||
// ============================================================================
|
||||
|
||||
PostProcessing::PostProcessing(IVideoDriver* video_driver)
|
||||
@@ -926,22 +982,20 @@ void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo,
|
||||
void PostProcessing::renderPassThrough(GLuint tex, unsigned width,
|
||||
unsigned height)
|
||||
{
|
||||
FullScreenShader::PassThroughShader::getInstance()->setTextureUnits(tex);
|
||||
DrawFullScreenEffect<FullScreenShader::PassThroughShader>(width, height);
|
||||
PassThroughShader::getInstance()->setTextureUnits(tex);
|
||||
DrawFullScreenEffect<PassThroughShader>(width, height);
|
||||
} // renderPassThrough
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void PostProcessing::renderTextureLayer(unsigned tex, unsigned layer)
|
||||
{
|
||||
FullScreenShader::LayerPassThroughShader::getInstance()->use();
|
||||
glBindVertexArray(FullScreenShader::LayerPassThroughShader::getInstance()->vao);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + FullScreenShader::LayerPassThroughShader
|
||||
::getInstance()->TU_texture);
|
||||
LayerPassThroughShader::getInstance()->use();
|
||||
LayerPassThroughShader::getInstance()->bindVertexArray();
|
||||
LayerPassThroughShader::getInstance()->activateTexture();
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
FullScreenShader::LayerPassThroughShader::getInstance()->setUniforms(layer);
|
||||
LayerPassThroughShader::getInstance()->setUniforms(layer);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
} // renderTextureLayer
|
||||
@@ -966,9 +1020,9 @@ void PostProcessing::renderSSAO()
|
||||
|
||||
// Generate linear depth buffer
|
||||
irr_driver->getFBO(FBO_LINEAR_DEPTH).Bind();
|
||||
FullScreenShader::LinearizeDepthShader::getInstance()
|
||||
LinearizeDepthShader::getInstance()
|
||||
->setTextureUnits(irr_driver->getDepthStencilTexture());
|
||||
DrawFullScreenEffect<FullScreenShader::LinearizeDepthShader>
|
||||
DrawFullScreenEffect<LinearizeDepthShader>
|
||||
(irr_driver->getSceneManager()->getActiveCamera()->getNearValue(),
|
||||
irr_driver->getSceneManager()->getActiveCamera()->getFarValue() );
|
||||
irr_driver->getFBO(FBO_SSAO).Bind();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/gl_headers.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/shared_gpu_objects.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
@@ -247,4 +248,23 @@ void ShaderBase::setAttribute(AttributeType type)
|
||||
}
|
||||
} // setAttribute
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GLuint ShaderBase::createVAO()
|
||||
{
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
GLuint attrib_position = glGetAttribLocation(m_program, "Position");
|
||||
GLuint attrib_texcoord = glGetAttribLocation(m_program, "Texcoord");
|
||||
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getQuadVBO());
|
||||
glEnableVertexAttribArray(attrib_position);
|
||||
glEnableVertexAttribArray(attrib_texcoord);
|
||||
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE,
|
||||
4 * sizeof(float), 0);
|
||||
glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE,
|
||||
4 * sizeof(float), (GLvoid*)(2 * sizeof(float)));
|
||||
glBindVertexArray(0);
|
||||
return vao;
|
||||
} // createVAO
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -91,6 +91,7 @@ public:
|
||||
const char **varyings,
|
||||
unsigned varyingscount);
|
||||
static void updateShaders();
|
||||
GLuint createVAO();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Activates the shader calling glUseProgram. */
|
||||
void use() { glUseProgram(m_program); }
|
||||
|
||||
@@ -443,23 +443,6 @@ namespace MeshShader
|
||||
|
||||
}
|
||||
|
||||
|
||||
static GLuint createVAO(GLuint Program)
|
||||
{
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
GLuint attrib_position = glGetAttribLocation(Program, "Position");
|
||||
GLuint attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);
|
||||
glEnableVertexAttribArray(attrib_position);
|
||||
glEnableVertexAttribArray(attrib_texcoord);
|
||||
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
||||
glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float)));
|
||||
glBindVertexArray(0);
|
||||
return vao;
|
||||
}
|
||||
|
||||
namespace FullScreenShader
|
||||
{
|
||||
|
||||
@@ -479,36 +462,6 @@ namespace FullScreenShader
|
||||
assignUniforms("direction", "col");
|
||||
}
|
||||
|
||||
PassThroughShader::PassThroughShader()
|
||||
{
|
||||
loadProgram(OBJECT,
|
||||
GL_VERTEX_SHADER, "screenquad.vert",
|
||||
GL_FRAGMENT_SHADER, "passthrough.frag");
|
||||
|
||||
assignUniforms("width", "height");
|
||||
assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED);
|
||||
}
|
||||
|
||||
LayerPassThroughShader::LayerPassThroughShader()
|
||||
{
|
||||
loadProgram(OBJECT,
|
||||
GL_VERTEX_SHADER, "screenquad.vert",
|
||||
GL_FRAGMENT_SHADER, "layertexturequad.frag");
|
||||
TU_texture = 0;
|
||||
assignUniforms("layer");
|
||||
assignTextureUnit(TU_texture, "tex");
|
||||
vao = createVAO(m_program);
|
||||
}
|
||||
|
||||
LinearizeDepthShader::LinearizeDepthShader()
|
||||
{
|
||||
loadProgram(OBJECT,
|
||||
GL_VERTEX_SHADER, "screenquad.vert",
|
||||
GL_FRAGMENT_SHADER, "linearizedepth.frag");
|
||||
assignUniforms("zn", "zf");
|
||||
|
||||
assignSamplerNames(0, "texture", ST_BILINEAR_FILTERED);
|
||||
}
|
||||
|
||||
|
||||
LightspaceBoundingBoxShader::LightspaceBoundingBoxShader()
|
||||
@@ -552,7 +505,7 @@ namespace FullScreenShader
|
||||
assignUniforms();
|
||||
|
||||
assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED);
|
||||
vao = createVAO(m_program);
|
||||
vao = createVAO();
|
||||
}
|
||||
|
||||
SSAOShader::SSAOShader()
|
||||
|
||||
@@ -88,27 +88,6 @@ public:
|
||||
SunLightShader();
|
||||
};
|
||||
|
||||
class PassThroughShader : public TextureShader<PassThroughShader, 1, int, int>
|
||||
{
|
||||
public:
|
||||
PassThroughShader();
|
||||
};
|
||||
|
||||
class LayerPassThroughShader : public Shader<LayerPassThroughShader, int>
|
||||
{
|
||||
public:
|
||||
GLuint TU_texture;
|
||||
GLuint vao;
|
||||
|
||||
LayerPassThroughShader();
|
||||
};
|
||||
|
||||
class LinearizeDepthShader : public TextureShader<LinearizeDepthShader, 1, float, float>
|
||||
{
|
||||
public:
|
||||
LinearizeDepthShader();
|
||||
};
|
||||
|
||||
class LightspaceBoundingBoxShader : public TextureShader<LightspaceBoundingBoxShader, 1,
|
||||
core::matrix4, float, float,
|
||||
float, float>
|
||||
|
||||
@@ -27,6 +27,7 @@ GLuint SharedGPUObjects::m_lighting_data_ubo;
|
||||
GLuint SharedGPUObjects::m_full_screen_quad_vao;
|
||||
GLuint SharedGPUObjects::m_ui_vao;
|
||||
GLuint SharedGPUObjects::m_quad_buffer;
|
||||
GLuint SharedGPUObjects::m_quad_vbo;
|
||||
bool SharedGPUObjects::m_has_been_initialised = false;
|
||||
|
||||
/** Initialises m_full_screen_quad_vbo.
|
||||
@@ -40,9 +41,8 @@ void SharedGPUObjects::initQuadVBO()
|
||||
1., -1., 1., 0., // UpperRight
|
||||
1., 1., 1., 1. // LowerRight
|
||||
};
|
||||
GLuint quad_vbo;
|
||||
glGenBuffers(1, &quad_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);
|
||||
glGenBuffers(1, &m_quad_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_quad_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), QUAD_VERTEX,
|
||||
GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
@@ -36,6 +36,7 @@ private:
|
||||
static GLuint m_full_screen_quad_vao;
|
||||
static GLuint m_ui_vao;
|
||||
static GLuint m_quad_buffer;
|
||||
static GLuint m_quad_vbo;
|
||||
|
||||
static void initQuadVBO();
|
||||
static void initQuadBuffer();
|
||||
@@ -108,7 +109,12 @@ public:
|
||||
assert(m_has_been_initialised);
|
||||
return m_quad_buffer;
|
||||
} // getQuadBuffer
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
static GLuint getQuadVBO()
|
||||
{
|
||||
assert(m_has_been_initialised);
|
||||
return m_quad_vbo;
|
||||
} // getQuadVBO
|
||||
}; // class SharedGPUObjecctS
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user