From: ouv Date: Wed, 9 Nov 2005 16:34:36 +0000 (+0000) Subject: Updated loading ARB procedures X-Git-Tag: BR-D5-38-2003_D2005-24-11~58 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6078be00b24716ebcc19b73270f2a5d8bc24cf29;p=modules%2Fvisu.git Updated loading ARB procedures --- diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx index 0709a853..f9baafae 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx @@ -45,8 +45,7 @@ #include #include -#include -//#include +//#include #include @@ -70,45 +69,99 @@ vtkStandardNewMacro(VISU_OpenGLPointSpriteMapper); #define VTK_PDPSM_OPAQUE_COLORS 0x0040 #define VTK_PDPSM_ALPHA_ARRAY 0x0080 -#ifndef GL_ARB_point_sprite -#define GL_POINT_SPRITE_ARB 0x8861 -#define GL_COORD_REPLACE_ARB 0x8862 +#ifndef APIENTRY +#define APIENTRY #endif -/* -#ifdef GL_ARB_shader_objects -PFNGLGENPROGRAMSARBPROC glGenProgramsARB = NULL; -PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB = NULL; -PFNGLBINDPROGRAMARBPROC glBindProgramARB = NULL; -PFNGLPROGRAMSTRINGARBPROC glProgramStringARB = NULL; -PFNGLPROGRAMENVPARAMETER4FARBPROC glProgramEnvParameter4fARB = NULL; - -PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; -PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; -PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; -PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL; -PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL; -PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL; -PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL; -PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = NULL; -PFNGLGETINFOLOGARBPROC glGetInfoLogARB = NULL; -PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB = NULL; -PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB = NULL; -PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB = NULL; +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * #endif -*/ -#ifdef GL_ARB_shader_objects -//GLhandleARB VISU_OpenGLPointSpriteMapper::VertexProgram = 0; +#ifndef GL_OBJECT_INFO_LOG_LENGTH_ARB +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 #endif +#ifndef GL_VERTEX_SHADER_ARB +#define GL_VERTEX_SHADER_ARB 0x8B31 +#endif -struct TVertex +#ifndef GL_VERTEX_PROGRAM_POINT_SIZE_ARB +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#endif + +#ifndef GL_ARB_point_sprite +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif + +#ifndef GL_ARB_shader_objects +typedef char GLcharARB; +#endif + +#ifndef GL_ARB_vertex_buffer_object +typedef ptrdiff_t GLsizeiptrARB; + +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_STATIC_DRAW_ARB 0x88E4 +#endif + +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); + +typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); +typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); + +static PFNGLSHADERSOURCEARBPROC vglShaderSourceARB = NULL; +static PFNGLCREATESHADEROBJECTARBPROC vglCreateShaderObjectARB = NULL; +static PFNGLCOMPILESHADERARBPROC vglCompileShaderARB = NULL; +static PFNGLCREATEPROGRAMOBJECTARBPROC vglCreateProgramObjectARB = NULL; +static PFNGLATTACHOBJECTARBPROC vglAttachObjectARB = NULL; +static PFNGLLINKPROGRAMARBPROC vglLinkProgramARB = NULL; +static PFNGLUSEPROGRAMOBJECTARBPROC vglUseProgramObjectARB = NULL; +static PFNGLGETOBJECTPARAMETERIVARBPROC vglGetObjectParameterivARB = NULL; +static PFNGLGETINFOLOGARBPROC vglGetInfoLogARB = NULL; +static PFNGLGETATTRIBLOCATIONARBPROC vglGetAttribLocationARB = NULL; +static PFNGLVERTEXATTRIB1FARBPROC vglVertexAttrib1fARB = NULL; + +static PFNGLGENBUFFERSARBPROC vglGenBuffersARB = NULL; +static PFNGLBINDBUFFERARBPROC vglBindBufferARB = NULL; +static PFNGLBUFFERDATAARBPROC vglBufferDataARB = NULL; +static PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB = NULL; + +int InitializeARB() { - GLfloat r, g, b, hue; - GLfloat vx, vy, vz; - //GLfloat hue; + void* OpenGLLibrary = dlopen( "libGL.so", RTLD_LAZY ); + + vglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)dlsym( OpenGLLibrary, "glShaderSourceARB" ); + vglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)dlsym( OpenGLLibrary, "glCreateShaderObjectARB" ); + vglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)dlsym( OpenGLLibrary, "glCompileShaderARB" ); + vglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)dlsym( OpenGLLibrary, "glCreateProgramObjectARB" ); + vglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)dlsym( OpenGLLibrary, "glAttachObjectARB" ); + vglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)dlsym( OpenGLLibrary, "glLinkProgramARB" ); + vglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( OpenGLLibrary, "glUseProgramObjectARB" ); + vglGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)dlsym( OpenGLLibrary, "glGetObjectParameterivARB" ); + vglGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)dlsym( OpenGLLibrary, "glGetInfoLogARB" ); + vglGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)dlsym( OpenGLLibrary, "glGetAttribLocationARB" ); + vglVertexAttrib1fARB = (PFNGLVERTEXATTRIB1FARBPROC)dlsym( OpenGLLibrary, "glVertexAttrib1fARB" ); + + vglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)dlsym( OpenGLLibrary, "glGenBuffersARB" ); + vglBindBufferARB = (PFNGLBINDBUFFERARBPROC)dlsym( OpenGLLibrary, "glBindBufferARB" ); + vglBufferDataARB = (PFNGLBUFFERDATAARBPROC)dlsym( OpenGLLibrary, "glBufferDataARB" ); + vglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)dlsym( OpenGLLibrary, "glDeleteBuffersARB" ); }; +static int IsARBInitialized = InitializeARB(); + //----------------------------------------------------------------------------- // Construct empty object. VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper() @@ -119,17 +172,13 @@ VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper() this->ExtensionsOK = 0; this->AlphaChannelArray = NULL; this->SizeChannelArray = NULL; - this->DefaultPointSize = 1.0; + this->DefaultPointSize = 50.0; this->QuadraticPointDistanceAttenuation[0] = 1.0; this->QuadraticPointDistanceAttenuation[1] = 0.0; this->QuadraticPointDistanceAttenuation[2] = 0.0; this->RenderMode = VISU_OpenGLPointSpriteMapper::Accumulate; -#ifdef GL_ARB_shader_objects - this->OpenGLLibrary = 0; -#endif - this->UsePointSprites = true; this->UseTextures = true; this->UseShader = true; @@ -213,63 +262,41 @@ char* readFromFile( std::string fileName ) return content; } //----------------------------------------------------------------------------- -#ifdef GL_ARB_shader_objects void VISU_OpenGLPointSpriteMapper::PrintInfoLog( GLhandleARB obj ) { - PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = - (PFNGLGETOBJECTPARAMETERIVARBPROC)dlsym( this->OpenGLLibrary, "glGetObjectParameterivARB" ); - PFNGLGETINFOLOGARBPROC glGetInfoLogARB = - (PFNGLGETINFOLOGARBPROC)dlsym( this->OpenGLLibrary, "glGetInfoLogARB" ); - int infologLength = 0; int charsWritten = 0; char* infoLog; - glGetObjectParameterivARB( obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength ); + vglGetObjectParameterivARB( obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infologLength ); if( infologLength > 0 ) { infoLog = ( char* )malloc( infologLength ); - glGetInfoLogARB( obj, infologLength, &charsWritten, infoLog ); + vglGetInfoLogARB( obj, infologLength, &charsWritten, infoLog ); printf( "%s\n", infoLog ); free( infoLog ); } } -#endif //----------------------------------------------------------------------------- -#ifdef GL_ARB_shader_objects -GLhandleARB VISU_OpenGLPointSpriteMapper::InitShader() +void VISU_OpenGLPointSpriteMapper::InitShader() { //cout << "Initializing vertex program" << endl; std::string fileName = std::string( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/Vertex_Program_ARB.txt"; - //std::string fileName = std::string( "/dn06/salome/ouv/SALOME/VISU_SRC/resources/Vertex_Program_ARB.txt"); char* shader = readFromFile( fileName ); - PFNGLSHADERSOURCEARBPROC glShaderSourceARB = - (PFNGLSHADERSOURCEARBPROC)dlsym( this->OpenGLLibrary, "glShaderSourceARB" ); - PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = - (PFNGLCREATESHADEROBJECTARBPROC)dlsym( this->OpenGLLibrary, "glCreateShaderObjectARB" ); - PFNGLCOMPILESHADERARBPROC glCompileShaderARB = - (PFNGLCOMPILESHADERARBPROC)dlsym( this->OpenGLLibrary, "glCompileShaderARB" ); - PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = - (PFNGLCREATEPROGRAMOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glCreateProgramObjectARB" ); - PFNGLATTACHOBJECTARBPROC glAttachObjectARB = - (PFNGLATTACHOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glAttachObjectARB" ); - PFNGLLINKPROGRAMARBPROC glLinkProgramARB = - (PFNGLLINKPROGRAMARBPROC)dlsym( this->OpenGLLibrary, "glLinkProgramARB" ); - - GLhandleARB VertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); - glShaderSourceARB( VertexShader, 1, (const GLcharARB**)&shader, NULL ); - glCompileShaderARB( VertexShader ); + GLhandleARB VertexShader = vglCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); + vglShaderSourceARB( VertexShader, 1, (const GLcharARB**)&shader, NULL ); + vglCompileShaderARB( VertexShader ); //this->PrintInfoLog( VertexShader ); - GLhandleARB VertexProgram = glCreateProgramObjectARB(); - glAttachObjectARB( VertexProgram, VertexShader ); + myVertexProgram = vglCreateProgramObjectARB(); + vglAttachObjectARB( myVertexProgram, VertexShader ); - glLinkProgramARB( VertexProgram ); + vglLinkProgramARB( myVertexProgram ); //this->PrintInfoLog( VertexProgram ); /* cout << "Shader from " << fileName << endl; @@ -289,27 +316,16 @@ GLhandleARB VISU_OpenGLPointSpriteMapper::InitShader() glTranslatef( 0.0f, 0.0f, -4.0f ); glRotatef( 0.0f, 1.0f, 0.0f, 0.0f ); glRotatef( 0.0f, 0.0f, 1.0f, 0.0f ); - - return VertexProgram; } -#endif //----------------------------------------------------------------------------- -#ifdef GL_ARB_shader_objects void VISU_OpenGLPointSpriteMapper::SetShaderVariable( const char* variable, float value ) { - PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB = - (PFNGLGETATTRIBLOCATIONARBPROC)dlsym( this->OpenGLLibrary, "glGetAttribLocationARB" ); - PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB = - (PFNGLVERTEXATTRIB1FARBPROC)dlsym( this->OpenGLLibrary, "glVertexAttrib1fARB" ); - - //cout << VISU_OpenGLPointSpriteMapper::VertexProgram << " "; - //cout << glGetAttribLocationARB( VISU_OpenGLPointSpriteMapper::VertexProgram, variable ) << " "; + //cout << myVertexProgram << " "; + //cout << vglGetAttribLocationARB( myVertexProgram, variable ) << " "; //cout << variable << " " << value << endl; - //glVertexAttrib1fARB( glGetAttribLocationARB( VISU_OpenGLPointSpriteMapper::VertexProgram, variable ), value ); - glVertexAttrib1fARB( glGetAttribLocationARB( myVertexProgram, variable ), value ); + vglVertexAttrib1fARB( vglGetAttribLocationARB( myVertexProgram, variable ), value ); } -#endif //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPointSpriteResults( bool theResults ) { @@ -318,9 +334,7 @@ void VISU_OpenGLPointSpriteMapper::SetPointSpriteResults( bool theResults ) //cout << "SetPointSpriteResults " << this << " " << aResults << endl; this->PointSpriteResults = theResults; - //#ifdef GL_ARB_shader_objects //this->SetShaderVariable( "results", theMagnification ); - //#endif this->Modified(); } //----------------------------------------------------------------------------- @@ -376,54 +390,8 @@ void VISU_OpenGLPointSpriteMapper::InitExtensions() return; } - /* -#ifdef GL_ARB_shader_objects - void* libHandle = dlopen( "libGL.so", RTLD_LAZY ); - - glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)dlsym( libHandle, "glGenProgramsARB" ); - glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)dlsym( libHandle, "glDeleteProgramsARB" ); - glBindProgramARB = (PFNGLBINDPROGRAMARBPROC)dlsym( libHandle, "glBindProgramARB" ); - glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)dlsym( libHandle, "glProgramStringARB" ); - glProgramEnvParameter4fARB = (PFNGLPROGRAMENVPARAMETER4FARBPROC)dlsym( libHandle, "glProgramEnvParameter4fARB" ); - - glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)dlsym( libHandle, "glShaderSourceARB" ); - glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)dlsym( libHandle, "glCreateShaderObjectARB" ); - glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)dlsym( libHandle, "glCompileShaderARB" ); - glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)dlsym( libHandle, "glCreateProgramObjectARB" ); - glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)dlsym( libHandle, "glAttachObjectARB" ); - glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)dlsym( libHandle, "glLinkProgramARB" ); - glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( libHandle, "glUseProgramObjectARB" ); - glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)dlsym( libHandle, "glGetObjectParameterivARB" ); - glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)dlsym( libHandle, "glGetInfoLogARB" ); - glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)dlsym( libHandle, "glGetAttribLocationARB" ); - glEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)dlsym( libHandle, "glEnableVertexAttribArrayARB" ); - glVertexAttrib1fARB = (PFNGLVERTEXATTRIB1FARBPROC)dlsym( libHandle, "glVertexAttrib1fARB" ); -#endif - */ - -#ifdef GL_ARB_shader_objects if( this->UseShader ) - { - //if( !VISU_OpenGLPointSpriteMapper::VertexProgram ) - { - this->OpenGLLibrary = dlopen( "libGL.so", RTLD_LAZY ); - //VISU_OpenGLPointSpriteMapper::VertexProgram = this->InitShader(); - myVertexProgram = this->InitShader(); - } - - //PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = - // (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glUseProgramObjectARB" ); - //glUseProgramObjectARB( VISU_OpenGLPointSpriteMapper::VertexProgram ); - /* - this->SetShaderVariable( "results", this->PointSpriteResults ); - this->SetShaderVariable( "clamp", this->PointSpriteClamp ); - this->SetShaderVariable( "geomSize", this->PointSpriteSize ); - this->SetShaderVariable( "minSize", this->PointSpriteMinSize ); - this->SetShaderVariable( "maxSize", this->PointSpriteMaxSize ); - this->SetShaderVariable( "magnification", this->PointSpriteMagnification ); - */ - } -#endif + this->InitShader(); this->ExtensionsOK = 1; this->ExtensionsInitialized = 1; @@ -437,7 +405,7 @@ void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) if( !this->ExtensionsInitialized && !this->UseOpenGLMapper ) { this->InitExtensions(); - //act->GetProperty()->SetPointSize( 10.0f ); + act->GetProperty()->SetPointSize( 10.0f ); } if( this->UseOpenGLMapper ) @@ -568,7 +536,7 @@ float VISU_OpenGLPointSpriteMapper::GetMaximumSupportedSize() return maximumSupportedSize; } //----------------------------------------------------------------------------- -void VISU_OpenGLPointSpriteMapper::InitPointSprites( vtkRenderer* theRenderer, vtkActor* theActor ) +void VISU_OpenGLPointSpriteMapper::InitPointSprites() { glEnable( GL_POINT_SPRITE_ARB ); glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB ); @@ -582,7 +550,6 @@ void VISU_OpenGLPointSpriteMapper::InitPointSprites( vtkRenderer* theRenderer, v glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE ); - //cout << this << " THRESHOLD " << this->PointSpriteAlphaThreshold << endl; glEnable( GL_ALPHA_TEST ); glAlphaFunc( GL_GREATER, this->PointSpriteAlphaThreshold ); break; @@ -593,6 +560,9 @@ void VISU_OpenGLPointSpriteMapper::InitPointSprites( vtkRenderer* theRenderer, v glDepthFunc( GL_LEQUAL ); glEnable( GL_DEPTH_TEST ); + glEnable( GL_ALPHA_TEST ); + glAlphaFunc( GL_GREATER, this->PointSpriteAlphaThreshold ); + glDisable( GL_BLEND ); break; } @@ -607,47 +577,6 @@ void VISU_OpenGLPointSpriteMapper::InitPointSprites( vtkRenderer* theRenderer, v // Disable material properties glDisable( GL_COLOR_MATERIAL ); - /* - // Set Quadratic Attenuation parameters - PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB = - (PFNGLPOINTPARAMETERFVARBPROC)dlsym( this->OpenGLLibrary, "glPointParameterfvARB" ); - - float size = this->DefaultPointSize; - vtkCamera* cam = theRenderer->GetActiveCamera(); - size *= theActor->GetMatrix()->Determinant(); - float vp[4]; - theRenderer->GetViewport(vp); - float w, h; - w = vp[2] - vp[0]; - h = vp[3] - vp[1]; - theRenderer->NormalizedDisplayToDisplay(w, h); - size *= h/2; - float quadratic[] = {0, 0, 0}; - if(cam->GetParallelProjection()) - quadratic[0] = cam->GetParallelScale()*cam->GetParallelScale()/(size*size); - else - { - size *= 7.4*tan(cam->GetViewAngle()*3.14159/180.); - quadratic[2] = 1.0/(size*size); - } - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic ); - */ - /* - // Set Quadratic Attenuation parameters - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, this->QuadraticPointDistanceAttenuation ); - - // Set Point Fade Threshold size - // The alpha of a point is calculated to allow the fading of points - // instead of shrinking them past a defined threshold size. The threshold - // is defined by GL_POINT_FADE_THRESHOLD_SIZE_ARB and is not clamped to - // the minimum and maximum point sizes. - glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1.0f ); - glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 1.0f ); - glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, CurrentPointSize ); - - // Specify point sprite texture coordinate replacement mode for each texture unit - glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); - */ } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::CleanupPointSprites() @@ -660,14 +589,7 @@ void VISU_OpenGLPointSpriteMapper::CleanupPointSprites() glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_COLOR_MATERIAL ); - /* - // Reset Quadratic Attenuation parameters - PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB = - (PFNGLPOINTPARAMETERFVARBPROC)dlsym( this->OpenGLLibrary, "glPointParameterfvARB" ); - float quadratic[] = {1, 0, 0}; - glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic ); - */ glDisable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB ); glDisable( GL_POINT_SPRITE_ARB ); } @@ -755,10 +677,16 @@ int ComputeHue( int r, int g, int b ) h = 180 + (120*(r-g+delta)+delta)/(2*delta); } - //cout << h << endl; return h + 1; } +//----------------------------------------------------------------------------- +struct TVertex +{ + GLfloat r, g, b, hue; + GLfloat vx, vy, vz; +}; + //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, vtkPoints *p, @@ -770,44 +698,12 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, vtkRenderer *ren, vtkActor* act) { - //cout << "VISU_OpenGLPointSpriteMapper::DrawPoints" << endl; - if( this->UsePointSprites ) - this->InitPointSprites( ren, act ); - /* - cout << "XSIZE : " << ren->GetRenderWindow()->GetSize()[0] << endl; - cout << "YSIZE : " << ren->GetRenderWindow()->GetSize()[1] << endl; - - float p1[3], p2[3]; - - ren->SetViewPoint( 0.0, 0.0, 0.0 ); - ren->ViewToDisplay(); - ren->GetDisplayPoint( p1 ); - - ren->SetViewPoint( 1.0, 1.0, 1.0 ); - ren->ViewToDisplay(); - ren->GetDisplayPoint( p2 ); - - cout << p1[0] << " " << p1[1] << " " << p1[2] << endl; - cout << p2[0] << " " << p2[1] << " " << p2[2] << endl; - - float d = pow( pow( p2[0] - p1[0], 2 ) + pow( p2[1] - p1[1], 2 ), 0.5 ); - cout << "ZOOM : " << d / pow( 2, 0.5 ) << endl; - */ + this->InitPointSprites(); glPointSize( this->DefaultPointSize ); -#ifdef GL_ARB_vertex_buffer_object - PFNGLGENBUFFERSARBPROC glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)dlsym( this->OpenGLLibrary, "glGenBuffersARB" ); - PFNGLBINDBUFFERARBPROC glBindBufferARB = (PFNGLBINDBUFFERARBPROC)dlsym( this->OpenGLLibrary, "glBindBufferARB" ); - PFNGLBUFFERDATAARBPROC glBufferDataARB = (PFNGLBUFFERDATAARBPROC)dlsym( this->OpenGLLibrary, "glBufferDataARB" ); - PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)dlsym( this->OpenGLLibrary, "glDeleteBuffersARB" ); - -#ifdef GL_ARB_shader_objects - PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = - (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glUseProgramObjectARB" ); - - glUseProgramObjectARB( myVertexProgram ); + vglUseProgramObjectARB( myVertexProgram ); this->SetShaderVariable( "results", this->PointSpriteResults ); this->SetShaderVariable( "clamp", this->PointSpriteClamp ); @@ -815,7 +711,6 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, this->SetShaderVariable( "minSize", this->PointSpriteMinSize ); this->SetShaderVariable( "maxSize", this->PointSpriteMaxSize ); this->SetShaderVariable( "magnification", this->PointSpriteMagnification ); -#endif TVertex* aVertex = new TVertex[ this->TotalCells ]; @@ -856,16 +751,16 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, } GLuint aBufferObjectID = 0; - glGenBuffersARB( 1, &aBufferObjectID ); - glBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); + vglGenBuffersARB( 1, &aBufferObjectID ); + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); int nArrayObjectSize = sizeof( TVertex ) * this->TotalCells; - glBufferDataARB( GL_ARRAY_BUFFER_ARB, nArrayObjectSize, aVertex, GL_STATIC_DRAW_ARB ); + vglBufferDataARB( GL_ARRAY_BUFFER_ARB, nArrayObjectSize, aVertex, GL_STATIC_DRAW_ARB ); delete [] aVertex; - glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); - glBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); + vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); glColorPointer( 4, GL_FLOAT, sizeof(TVertex), (void*)0 ); glVertexPointer( 3, GL_FLOAT, sizeof(TVertex), (void*)(4*sizeof(GLfloat)) ); @@ -878,13 +773,9 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); - glDeleteBuffersARB( 1, &aBufferObjectID ); + vglDeleteBuffersARB( 1, &aBufferObjectID ); -#ifdef GL_ARB_shader_objects - glUseProgramObjectARB( 0 ); -#endif - -#endif + vglUseProgramObjectARB( 0 ); if( this->UsePointSprites ) this->CleanupPointSprites(); @@ -894,6 +785,8 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, // Draw method for OpenGL. int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *aren, vtkActor *act) { + //cout << "VISU_OpenGLPointSpriteMapper::Draw" << endl; + if( this->UseOpenGLMapper ) return MAPPER_SUPERCLASS::Draw( aren, act ); @@ -994,7 +887,3 @@ void VISU_OpenGLPointSpriteMapper::PrintSelf(ostream& os, vtkIndent indent) this->Superclass::PrintSelf(os,indent); } //----------------------------------------------------------------------------- - - - - diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx index 5d624624..27d31818 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx @@ -56,6 +56,10 @@ class vtkXMLImageDataReader; #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper #endif +#ifndef GL_ARB_shader_objects +typedef GLuint GLhandleARB; +#endif + class VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS { public: @@ -195,7 +199,7 @@ protected: void InitExtensions(); // Activate/deactivate Point Sprites - void InitPointSprites( vtkRenderer*, vtkActor* ); + void InitPointSprites(); void CleanupPointSprites(); // Initializing textures for Point Sprites @@ -218,15 +222,11 @@ protected: float QuadraticPointDistanceAttenuation[3]; int RenderMode; -#ifdef GL_ARB_shader_objects - GLhandleARB InitShader(); + void InitShader(); void PrintInfoLog( GLhandleARB ); void SetShaderVariable( const char* variable, float value ); - static GLhandleARB VertexProgram; - void* OpenGLLibrary; GLhandleARB myVertexProgram; -#endif bool PointSpriteResults;