Commit 7de7491c authored by Sylvain Thery's avatar Sylvain Thery

update ShaderIsoLines

parent 6fa0fae0
......@@ -79,6 +79,9 @@ protected:
static std::string defines_Geom(const std::string& primitivesIn, const std::string& primitivesOut, int maxVert);
int m_nbMaxVertices;
/**
* handle of vertex shader
*/
......@@ -167,7 +170,7 @@ protected:
/**
* create the shader (attach and link shaders into program)
*/
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES, int nb_max_vertices=16);
bool create(GLint inputGeometryPrimitive=GL_TRIANGLES,GLint outputGeometryPrimitive=GL_TRIANGLES, int nb_max_vertices=-1);
/**
* get log after compiling
......@@ -270,6 +273,8 @@ public:
bool recompile();
bool changeNbMaxVertices(int nb_max_vertices);
/**
* Link the shader do it just after binding the attributes
*/
......
......@@ -35,13 +35,13 @@ void isoLine(float x)
if (in01)
{
vec4 pos01 = ModelViewProjectionMatrix * mix(POSITION_IN(0),POSITION_IN(1),b01);
if (in02)
{
// line 01 - 02
vec4 pos = mix(POSITION_IN(0),POSITION_IN(1),b01);
gl_Position = ModelViewProjectionMatrix * pos;
gl_Position = pos01;
EmitVertex();
pos = mix(POSITION_IN(0),POSITION_IN(2),b02);
vec4 pos = mix(POSITION_IN(0),POSITION_IN(2),b02);
gl_Position = ModelViewProjectionMatrix * pos;
EmitVertex();
EndPrimitive();
......@@ -49,10 +49,9 @@ void isoLine(float x)
if (in12)
{
// line 01 - 12
vec4 pos = mix(POSITION_IN(0),POSITION_IN(1),b01);
gl_Position = ModelViewProjectionMatrix * pos;
gl_Position = pos01;
EmitVertex();
pos = mix(POSITION_IN(1),POSITION_IN(2),b12);
vec4 pos = mix(POSITION_IN(1),POSITION_IN(2),b12);
gl_Position = ModelViewProjectionMatrix * pos;
EmitVertex();
EndPrimitive();
......@@ -74,16 +73,10 @@ void isoLine(float x)
void main(void)
{
float inc = (vmax-vmin)/float(vnb);
for (int i=0; i<vnb; ++i)
{
float v = vmin + float(i)*inc;
isoLine(v);
}
// isoLine(0.5);
// isoLine(0.5);
// isoLine(0.75);
}
......@@ -33,27 +33,34 @@ namespace CGoGN
namespace Utils
{
/**
* Shader to draw iso-lines on a triangles mesh.
* Iso-line are computed on a data vertex attribute (float)
*/
class ShaderIsoLines : public GLSLShader
{
protected:
// shader sources
/// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string geometryShaderText;
// uniform locations
/// uniform locations
CGoGNGLuint m_unif_colorMin;
CGoGNGLuint m_unif_colorMax;
CGoGNGLuint m_unif_vmin;
CGoGNGLuint m_unif_vmax;
CGoGNGLuint m_unif_vnb;
// colors of iso-lines
Geom::Vec4f m_colorMin;
Geom::Vec4f m_colorMax;
/// min/max of data attribute
float m_vmin;
float m_vmax;
/// number of iso-line to draw
int m_vnb;
VBO* m_vboPos;
......@@ -61,24 +68,47 @@ protected:
void getLocations();
// void restoreUniformsAttribs();
public:
/**
* constructor
* @param max number of isolines drawable per triangle (as low as possible for performance)
*/
ShaderIsoLines(int maxNbIsoPerTriangle=6);
/**
* set colors for min and max isoLine, interpolated between
// * @param colorMin color for minimum iso-line value
* @param colorMax color for maximum iso-line value
*/
void setColors(const Geom::Vec4f& colorMin, const Geom::Vec4f& colorMax);
/**
* Set min and max value of used atribute
* @param attMin minimun of attribute
* @param attMax maximun of attribute
*/
void setDataBound(float attMin, float attMax);
/**
* set the number of iso-lines (default is 32)
*/
void setNbIso(int nb);
/**
*
* set max number of isolines per triangle
* If to small risk of missing lines
* if to big performance problem
*/
void setNbMaxIsoLinePerTriangle(int nb) { changeNbMaxVertices(2*nb); }
/**
* Position attribute
*/
void setAttributePosition(VBO* vbo);
/**
* Data attribute must be float
* Data attribute for iso-lines must be of type float
*/
void setAttributeData(VBO* vbo);
};
......
......@@ -86,6 +86,8 @@ GLSLShader::GLSLShader() :
if (DEFINES_GL == NULL)
DEFINES_GL = &DEFINES_GL2;
m_nbMaxVertices = 16;
}
void GLSLShader::registerShader(void* ptr, GLSLShader* shader)
......@@ -451,6 +453,9 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti
int status;
char *info_log;
if (nb_max_vertices!=-1)
m_nbMaxVertices = nb_max_vertices;
m_geom_inputPrimitives = inputGeometryPrimitive;
m_geom_outputPrimitives = outputGeometryPrimitive;
......@@ -479,7 +484,7 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti
glProgramParameteriEXT(*m_program_object,GL_GEOMETRY_INPUT_TYPE_EXT,inputGeometryPrimitive);
glProgramParameteriEXT(*m_program_object,GL_GEOMETRY_OUTPUT_TYPE_EXT,outputGeometryPrimitive);
glProgramParameteriEXT(*m_program_object,GL_GEOMETRY_VERTICES_OUT_EXT,nb_max_vertices);
glProgramParameteriEXT(*m_program_object,GL_GEOMETRY_VERTICES_OUT_EXT,m_nbMaxVertices);
}
/*** link program object ***/
......@@ -511,6 +516,26 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti
return true;
}
bool GLSLShader::changeNbMaxVertices(int nb_max_vertices)
{
m_nbMaxVertices = nb_max_vertices;
if (*m_geom_shader_object)
{
glProgramParameteriEXT(*m_program_object,GL_GEOMETRY_VERTICES_OUT_EXT,m_nbMaxVertices);
// need to relink
return true;
}
return false;
}
bool GLSLShader::link()
{
int status;
......@@ -839,7 +864,7 @@ bool GLSLShader::recompile()
*m_uniMat_Proj = glGetUniformLocation(*m_program_object,"ProjectionMatrix");
*m_uniMat_Model = glGetUniformLocation(*m_program_object,"ModelViewMatrix");
*m_uniMat_ModelProj = glGetUniformLocation(*m_program_object,"ModelViewProjectionMatrix");
*m_uniMat_Normal = glGetUniformLocation(*m_program_object,"NormalMatrix");
*m_uniMat_Normal = glGetUniformLocation(*m_program_object,"NormalMatrix");
restoreUniformsAttribs();
......
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