Commit a86afa8e authored by Sylvain Thery's avatar Sylvain Thery

update GLSL interface & some Geom functions

parent 63197e65
......@@ -89,6 +89,11 @@ typename VEC3::DATA_TYPE squaredDistanceLine2Point(const VEC3& A, const VEC3& B,
/**
* compute squared distance from line to line
* @param A point of first line
* @param AB vector of first line
* @param AB2 AB*AB (for optimization if call several times with AB
* @param P first point of second line
* @param Q second point of second line
* @return the squared distance
*/
template <typename VEC3>
......@@ -96,6 +101,11 @@ typename VEC3::DATA_TYPE squaredDistanceLine2Line(const VEC3& A, const VEC3& AB,
/**
* compute squared distance from line to segment
* @param A point of line
* @param AB vector of line
* @param AB2 AB*AB (for optimization if call several times with AB
* @param P first point of segment
* @param Q second point of segment
* @return the squared distance
*/
template <typename VEC3>
......@@ -103,6 +113,9 @@ typename VEC3::DATA_TYPE squaredDistanceLine2Seg(const VEC3& A, const VEC3& AB,
/**
* compute squared distance from segment to point
* @param A point of segment
* @param AB vector of segment
* @param AB2 AB*AB (for optimization if call several times with AB
* @return the squared distance
*/
template <typename VEC3>
......
......@@ -166,6 +166,10 @@ Intersection intersection2DSegmentSegment(const VEC3& PA, const VEC3& PB, const
template <typename VEC3>
Intersection intersectionSegmentPlan(const VEC3& PA, const VEC3& PB, const VEC3& PlaneP, const VEC3& NormP); //, VEC3& Inter) ;
template <typename VEC3>
Intersection intersectionSegmentPlan(const VEC3& PA, const VEC3& PB, const VEC3& PlaneP, const VEC3& NormP, VEC3& Inter) ;
template <typename VEC3>
Intersection intersectionTrianglePlan(const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, const VEC3& PlaneP, const VEC3& NormP);//, VEC3& Inter) ;
......@@ -177,6 +181,20 @@ template <typename VEC3>
Intersection intersectionTriangleHalfPlan(const VEC3& Ta, const VEC3& Tb, const VEC3& Tc,
const VEC3& P, const VEC3& DirP, const VEC3& OrientP); //, VEC3& Inter) ;
/**
* compute intersection between line and segment
* @param A point of line
* @param AB vector of line
* @param AB2 AB*AB (for optimization if call several times with AB
* @param P first point of segment
* @param Q second point of segment
* @param inter the computed intersection
* @return intersection of not
*/
template <typename VEC3>
bool interLineSeg(const VEC3& A, const VEC3& AB, typename VEC3::DATA_TYPE AB2,
const VEC3& P, const VEC3& Q, VEC3& inter);
} // namespace Geom
} // namespace CGoGN
......
......@@ -22,6 +22,8 @@
* *
*******************************************************************************/
#include "Geometry/distances.h"
namespace CGoGN
{
......@@ -487,19 +489,61 @@ Intersection intersection2DSegmentSegment(const VEC3& PA, const VEC3& PB, const
template <typename VEC3>
Intersection intersectionSegmentPlan(const VEC3& PA, const VEC3& PB, const VEC3& PlaneP, const VEC3& NormP)//, VEC3& Inter)
{
typename VEC3::DATA_TYPE panp = NormP * PA;
typename VEC3::DATA_TYPE pbnp = NormP * PB;
// typename VEC3::DATA_TYPE panp = NormP * PA;
// typename VEC3::DATA_TYPE pbnp = NormP * PB;
// if(panp == 0 || pbnp == 0)
// return VERTEX_INTERSECTION;
// else if((panp < 0 && pbnp > 0) || (panp > 0 && pbnp < 0))
// return EDGE_INTERSECTION;
// else
// return NO_INTERSECTION;
#define EPSILON 1e-12
if(panp == 0 || pbnp == 0)
typename VEC3::DATA_TYPE panp = NormP * (PA-PlaneP);
typename VEC3::DATA_TYPE pbnp = NormP * (PB-PlaneP);
if(abs(panp) < EPSILON || abs(pbnp) < EPSILON)
return VERTEX_INTERSECTION;
else if((panp < 0 && pbnp > 0) || (panp > 0 && pbnp < 0))
return EDGE_INTERSECTION;
// else if((panp < 0 && pbnp > 0) || (panp > 0 && pbnp < 0))
else if (panp*pbnp < 0)
return EDGE_INTERSECTION;
else
return NO_INTERSECTION;
#undef EPSILON
}
template <typename VEC3>
Intersection intersectionSegmentPlan(const VEC3& PA, const VEC3& PB, const VEC3& PlaneP, const VEC3& NormP, VEC3& Inter)
{
#define EPSILON 1e-12
typename VEC3::DATA_TYPE panp = NormP * (PA-PlaneP);
typename VEC3::DATA_TYPE pbnp = NormP * (PB-PlaneP);
if(abs(panp) < EPSILON)
{
Inter = PA;
return VERTEX_INTERSECTION;
}
else if(abs(pbnp) < EPSILON)
{
Inter = PB;
return VERTEX_INTERSECTION;
}
else if (panp*pbnp < 0)
{
Inter = (abs(panp)*PB + abs(pbnp)*PA)/(abs(panp)+abs(pbnp)) ;
return EDGE_INTERSECTION;
}
else
return NO_INTERSECTION;
#undef EPSILON
}
template <typename VEC3>
Intersection intersectionTrianglePlan(const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, const VEC3& PlaneP, const VEC3& NormP) //, VEC3& Inter) ;
{
......@@ -566,6 +610,35 @@ Intersection intersectionTriangleHalfPlan(const VEC3& Ta, const VEC3& Tb, const
}
}
template <typename VEC3>
bool interLineSeg(const VEC3& A, const VEC3& AB, typename VEC3::DATA_TYPE AB2,
const VEC3& P, const VEC3& Q, VEC3& inter)
{
#define EPSILON (1.0e-5)
typedef typename VEC3::DATA_TYPE T ;
T dist = Geom::distancePoint2TrianglePlane(AB-A,A,P,Q);
// std::cout << "dist "<< dist << std::endl;
if (dist>EPSILON)
return false;
VEC3 AP = P - A ;
VEC3 PQ = Q - P ;
T X = AB * PQ ;
T beta = ( AB2 * (AP*PQ) - X * (AP*AB) ) / ( X*X - AB2 * PQ.norm2() ) ;
// std::cout << "beta "<< beta << std::endl;
if ((beta<0.0) || (beta>1.0))
return false;
inter = beta*Q +(1.0-beta)*P;
return true;
#undef EPSILON
}
}
}
......@@ -178,7 +178,7 @@ protected:
* @param obj what log do you want ?
* @return the log
*/
char* getInfoLog( GLhandleARB obj );
char* getInfoLog( GLuint obj );
public:
/**
......@@ -304,7 +304,7 @@ public:
/**
* get handler of program for external use og gl functions
*/
GLhandleARB program_handler() { return *m_program_object;}
GLuint program_handler() { return *m_program_object;}
/**
* check shader validity width official GLSL syntax
......
......@@ -61,7 +61,7 @@ public:
typedef FalsePtr<GLint> CGoGNGLint;
typedef FalsePtr<GLuint> CGoGNGLuint;
typedef FalsePtr<GLhandleARB> CGoGNGLhandleARB;
typedef FalsePtr<GLuint> CGoGNGLhandleARB;
typedef FalsePtr<GLenum> CGoGNGLenum;
typedef FalsePtr<GLenum*> CGoGNGLenumTable;
......
......@@ -298,18 +298,18 @@ bool GLSLShader::loadVertexShaderSourceString( const char *vertex_shader_source
{
CGoGNerr << "ERROR - GLSLShader::loadVertexShader() - source string is empty." << CGoGNendl;
glDeleteObjectARB(*m_vertex_shader_object );
glDeleteShader(*m_vertex_shader_object );
*m_vertex_shader_object = 0;
return false;
}
glShaderSourceARB( *m_vertex_shader_object, 1, (const char**)&vertex_shader_source, NULL );
glShaderSource( *m_vertex_shader_object, 1, (const char**)&vertex_shader_source, NULL );
/*** compile shader object ***/
glCompileShaderARB( *m_vertex_shader_object );
glCompileShader( *m_vertex_shader_object );
glGetObjectParameterivARB( *m_vertex_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
glGetProgramiv( *m_vertex_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
if( !status )
{
CGoGNerr << "ERROR - GLshader::loadVertexShader() - error occured while compiling shader " << m_nameVS<< CGoGNendl;
......@@ -317,7 +317,7 @@ bool GLSLShader::loadVertexShaderSourceString( const char *vertex_shader_source
CGoGNerr << info_log << CGoGNendl;
delete [] info_log;
glDeleteObjectARB( *m_vertex_shader_object );
glDeleteShader( *m_vertex_shader_object );
*m_vertex_shader_object = 0;
return false;
......@@ -352,18 +352,18 @@ bool GLSLShader::loadFragmentShaderSourceString( const char *fragment_shader_sou
{
CGoGNerr << "ERROR - GLSLShader::loadFragmentShader() - source string is empty." << CGoGNendl;
glDeleteObjectARB( *m_fragment_shader_object );
glDeleteShader( *m_fragment_shader_object );
*m_fragment_shader_object = 0;
return false;
}
glShaderSourceARB( *m_fragment_shader_object, 1, (const char**)&fragment_shader_source, NULL );
glShaderSource( *m_fragment_shader_object, 1, (const char**)&fragment_shader_source, NULL );
/*** compile shader object ***/
glCompileShaderARB( *m_fragment_shader_object );
glCompileShader( *m_fragment_shader_object );
glGetObjectParameterivARB( *m_fragment_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
glGetProgramiv( *m_fragment_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
if( !status )
{
CGoGNerr << "ERROR - GLshader::loadFragmentShader() - error occured while compiling shader " << m_nameFS << CGoGNendl;
......@@ -371,7 +371,7 @@ bool GLSLShader::loadFragmentShaderSourceString( const char *fragment_shader_sou
CGoGNerr << info_log << CGoGNendl;
delete [] info_log;
glDeleteObjectARB( *m_fragment_shader_object );
glDeleteShader( *m_fragment_shader_object );
*m_fragment_shader_object = 0;
return false;
......@@ -405,18 +405,18 @@ bool GLSLShader::loadGeometryShaderSourceString( const char *geom_shader_source
{
CGoGNerr << "ERROR - GLSLShader::loadGeometryShader() - source string is empty." << CGoGNendl;
glDeleteObjectARB( *m_geom_shader_object );
glDeleteShader( *m_geom_shader_object );
*m_geom_shader_object = 0;
return false;
}
glShaderSourceARB( *m_geom_shader_object, 1, (const char**)&geom_shader_source, NULL );
glShaderSource( *m_geom_shader_object, 1, (const char**)&geom_shader_source, NULL );
/*** compile shader object ***/
glCompileShaderARB( *m_geom_shader_object );
glCompileShader( *m_geom_shader_object );
glGetObjectParameterivARB( *m_geom_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
glGetProgramiv( *m_geom_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
if( !status )
{
CGoGNerr << "ERROR - GLshader::loadGeometryShader() - error occured while compiling shader "<< m_nameGS << CGoGNendl;
......@@ -424,7 +424,7 @@ bool GLSLShader::loadGeometryShaderSourceString( const char *geom_shader_source
CGoGNerr << info_log << CGoGNendl;
delete [] info_log;
glDeleteObjectARB( *m_geom_shader_object );
glDeleteShader( *m_geom_shader_object );
*m_geom_shader_object = 0;
return false;
......@@ -434,16 +434,16 @@ bool GLSLShader::loadGeometryShaderSourceString( const char *geom_shader_source
return true;
}
char* GLSLShader::getInfoLog( GLhandleARB obj )
char* GLSLShader::getInfoLog( GLuint obj )
{
char *info_log;
int info_log_length;
int length;
glGetObjectParameterivARB( obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &info_log_length );
glGetProgramiv( obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &info_log_length );
info_log = new char [info_log_length];
glGetInfoLogARB( obj, info_log_length, &length, info_log );
glGetProgramInfoLog( obj, info_log_length, &length, info_log );
return info_log;
}
......@@ -467,7 +467,7 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti
}
/*** create program object ***/
m_program_object = glCreateProgramObjectARB();
m_program_object = glCreateProgram();
if( !*m_program_object )
{
......@@ -476,11 +476,11 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti
}
/*** attach shaders to program object ***/
glAttachObjectARB( *m_program_object, *m_vertex_shader_object );
glAttachObjectARB( *m_program_object, *m_fragment_shader_object );
glAttachShader( *m_program_object, *m_vertex_shader_object );
glAttachShader( *m_program_object, *m_fragment_shader_object );
if (*m_geom_shader_object)
{
glAttachObjectARB( *m_program_object, *m_geom_shader_object );
glAttachShader( *m_program_object, *m_geom_shader_object );
glProgramParameteriEXT(*m_program_object, GL_GEOMETRY_INPUT_TYPE_EXT, inputGeometryPrimitive);
glProgramParameteriEXT(*m_program_object, GL_GEOMETRY_OUTPUT_TYPE_EXT, outputGeometryPrimitive);
......@@ -488,9 +488,9 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti
}
/*** link program object ***/
glLinkProgramARB( *m_program_object );
glLinkProgram( *m_program_object );
glGetObjectParameterivARB( *m_program_object, GL_OBJECT_LINK_STATUS_ARB, &status );
glGetProgramiv( *m_program_object, GL_OBJECT_LINK_STATUS_ARB, &status );
if( !status )
{
CGoGNerr << "ERROR - GLSLShader::create() - error occured while linking shader program." << CGoGNendl;
......@@ -498,11 +498,11 @@ bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimiti
CGoGNerr << " LINK " << info_log << CGoGNendl;
delete [] info_log;
glDetachObjectARB( *m_program_object, *m_vertex_shader_object );
glDetachObjectARB( *m_program_object, *m_fragment_shader_object );
glDetachShader( *m_program_object, *m_vertex_shader_object );
glDetachShader( *m_program_object, *m_fragment_shader_object );
if (*m_geom_shader_object)
glDetachObjectARB( *m_program_object, *m_geom_shader_object );
glDeleteObjectARB( *m_program_object );
glDetachShader( *m_program_object, *m_geom_shader_object );
glDeleteShader( *m_program_object );
*m_program_object = 0;
return false;
......@@ -542,9 +542,9 @@ bool GLSLShader::link()
char *info_log;
/*** link program object ***/
glLinkProgramARB( *m_program_object );
glLinkProgram( *m_program_object );
glGetObjectParameterivARB( *m_program_object, GL_OBJECT_LINK_STATUS_ARB, &status );
glGetProgramiv( *m_program_object, GL_OBJECT_LINK_STATUS_ARB, &status );
if( !status )
{
CGoGNerr << "ERROR - GLSLShader::create() - error occured while linking shader program." << CGoGNendl;
......@@ -552,11 +552,11 @@ bool GLSLShader::link()
CGoGNerr << " LINK " << info_log << CGoGNendl;
delete [] info_log;
glDetachObjectARB( *m_program_object, *m_vertex_shader_object );
glDetachObjectARB( *m_program_object, *m_fragment_shader_object );
glDetachShader( *m_program_object, *m_vertex_shader_object );
glDetachShader( *m_program_object, *m_fragment_shader_object );
if (*m_geom_shader_object)
glDetachObjectARB( *m_program_object, *m_geom_shader_object );
glDeleteObjectARB( *m_program_object );
glDetachShader( *m_program_object, *m_geom_shader_object );
glDeleteShader( *m_program_object );
*m_program_object = 0;
return false;
......@@ -569,7 +569,7 @@ bool GLSLShader::bind() const
{
if( *m_program_object )
{
glUseProgramObjectARB( *m_program_object );
glUseProgram( *m_program_object );
return true;
}
else
......@@ -580,13 +580,18 @@ void GLSLShader::unbind() const
{
if( *m_program_object )
{
glUseProgramObjectARB( 0 );
glUseProgram( 0 );
}
}
bool GLSLShader::isBinded()
{
return ( *m_program_object && *m_program_object == glGetHandleARB(GL_PROGRAM_OBJECT_ARB) );
if (*m_program_object == 0)
return false;
GLint po;
glGetIntegerv(GL_CURRENT_PROGRAM,&po);
return ( *m_program_object == po );
}
GLSLShader::~GLSLShader()
......@@ -597,21 +602,21 @@ GLSLShader::~GLSLShader()
if( *m_vertex_shader_object )
{
glDetachObjectARB( *m_program_object, *m_vertex_shader_object );
glDeleteObjectARB( *m_vertex_shader_object );
glDetachShader( *m_program_object, *m_vertex_shader_object );
glDeleteShader( *m_vertex_shader_object );
}
if( *m_fragment_shader_object )
{
glDetachObjectARB( *m_program_object, *m_fragment_shader_object );
glDeleteObjectARB( *m_fragment_shader_object );
glDetachShader( *m_program_object, *m_fragment_shader_object );
glDeleteShader( *m_fragment_shader_object );
}
if (*m_geom_shader_object)
{
glDetachObjectARB( *m_program_object, *m_geom_shader_object );
glDeleteObjectARB( *m_geom_shader_object );
glDetachShader( *m_program_object, *m_geom_shader_object );
glDeleteShader( *m_geom_shader_object );
}
glDeleteObjectARB( *m_program_object );
glDeleteShader( *m_program_object );
}
if (m_vertex_shader_source != NULL)
......@@ -915,7 +920,7 @@ bool GLSLShader::checkShader(int shaderType)
{
GLint Result = GL_FALSE;
int InfoLogLength;
GLhandleARB id;
GLuint id;
switch(shaderType)
{
......
......@@ -305,13 +305,13 @@ void SimpleQGLV::keyPressEvent(QKeyEvent *e)
else
QWidget::keyPressEvent(e);
m_qglWidget->keyPressEvent(e); // ?
// m_qglWidget->keyPressEvent(e); // ?
}
void SimpleQGLV::keyReleaseEvent(QKeyEvent *e)
{
QWidget::keyReleaseEvent(e);
m_qglWidget->keyReleaseEvent(e);
// m_qglWidget->keyReleaseEvent(e);
}
void SimpleQGLV::glMousePosition(int& x, int& y)
......
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