Commit 79dc9e80 authored by Thery Sylvain's avatar Thery Sylvain

add shader to draw texture & depth

parent dcf27e0e
// ShaderTextureDepth::fragmentShaderText
PRECISON;
VARYING_FRAG vec2 texCoord;
uniform sampler2D textureUnit;
uniform sampler2D textureDepthUnit;
FRAG_OUT_DEF;
void main()
{
gl_FragDepth = texture2D(textureDepthUnit,texCoord).r;
gl_FragColor = texture2D(textureUnit,texCoord);
}
\ No newline at end of file
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_TEXTURE_DEPTH__
#define __CGOGN_SHADER_TEXTURE_DEPTH__
#include "Geometry/vector_gen.h"
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Utils/textures.h"
#include "Utils/gl_def.h"
namespace CGoGN
{
namespace Utils
{
class ShaderTextureDepth : public ClippingShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
CGoGNGLuint m_unif_unit;
int m_unit;
CGoGNGLuint m_unif_depthUnit;
int m_depthUnit;
Utils::GTexture* m_tex_ptr;
VBO* m_vboPos;
VBO* m_vboTexCoord;
void restoreUniformsAttribs();
public:
ShaderTextureDepth();
/**
* choose the texture unit engine to use for this texture
*/
void setTextureUnit(GLenum texture_unit);
void setDepthTextureUnit(GLenum texture_unit);
/**
* activation of texture unit with texture id
*/
void activeTexture(CGoGNGLuint texId);
void activeDepthTexture(CGoGNGLuint texId);
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeTexCoord(VBO* vbo);
};
} // namespace Utils
} // namespace CGoGN
#endif /* __CGOGN_SHADER_SIMPLETEXTURE__ */
// ShaderTextureDepth::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec2 VertexTexCoord;
uniform mat4 ModelViewProjectionMatrix;
VARYING_VERT vec2 texCoord;
INVARIANT_POS;
void main ()
{
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
texCoord = VertexTexCoord;
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <GL/glew.h>
#include "Utils/Shaders/ShaderTextureDepth.h"
namespace CGoGN
{
namespace Utils
{
#include "shaderTextureDepth.vert"
#include "shaderTextureDepth.frag"
ShaderTextureDepth::ShaderTextureDepth()
{
m_nameVS = "ShaderTextureDepth_vs";
m_nameFS = "ShaderTextureDepth_fs";
std::string glxvert(*GLSLShader::DEFINES_GL);
glxvert.append(vertexShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
std::stringstream ss;
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
m_unif_unit = glGetUniformLocation(this->program_handler(), "textureUnit");
m_unif_depthUnit = glGetUniformLocation(this->program_handler(), "textureDepthUnit");
}
void ShaderTextureDepth::setTextureUnit(GLenum texture_unit)
{
this->bind();
int unit = texture_unit - GL_TEXTURE0;
glUniform1iARB(*m_unif_unit,unit);
m_unit = unit;
}
void ShaderTextureDepth::setDepthTextureUnit(GLenum texture_unit)
{
this->bind();
int unit = texture_unit - GL_TEXTURE0;
glUniform1iARB(*m_unif_depthUnit,unit);
m_depthUnit = unit;
}
void ShaderTextureDepth::activeTexture(CGoGNGLuint texId)
{
glActiveTexture(GL_TEXTURE0 + m_unit);
glBindTexture(GL_TEXTURE_2D, *texId);
}
void ShaderTextureDepth::activeDepthTexture(CGoGNGLuint texId)
{
glActiveTexture(GL_TEXTURE0 + m_depthUnit);
glBindTexture(GL_TEXTURE_2D, *texId);
}
unsigned int ShaderTextureDepth::setAttributePosition(VBO* vbo)
{
m_vboPos = vbo;
return bindVA_VBO("VertexPosition", vbo);
}
unsigned int ShaderTextureDepth::setAttributeTexCoord(VBO* vbo)
{
m_vboTexCoord = vbo;
return bindVA_VBO("VertexTexCoord", vbo);
}
void ShaderTextureDepth::restoreUniformsAttribs()
{
m_unif_unit = glGetUniformLocation(this->program_handler(), "textureUnit");
m_unif_depthUnit = glGetUniformLocation(this->program_handler(), "textureDepthUnit");
bindVA_VBO("VertexPosition", m_vboPos);
bindVA_VBO("VertexTexCoord", m_vboTexCoord);
this->bind();
glUniform1iARB(*m_unif_unit,m_unit);
glUniform1iARB(*m_unif_depthUnit,m_depthUnit);
this->unbind();
}
} // namespace Utils
} // namespace CGoGN
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