#define VTK_PDPSM_NORMAL_TYPE_DOUBLE 0x0020
#define VTK_PDPSM_OPAQUE_COLORS 0x0040
#define VTK_PDPSM_ALPHA_ARRAY 0x0080
-/*
-PFNGLGENPROGRAMSARBPROC glGenProgramsARB = NULL;
-PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB = NULL;
-PFNGLBINDPROGRAMARBPROC glBindProgramARB = NULL;
-PFNGLPROGRAMSTRINGARBPROC glProgramStringARB = NULL;
-PFNGLPROGRAMENVPARAMETER4FARBPROC glProgramEnvParameter4fARB = NULL;
-*/
-#ifdef GL_ARB_shader_objects
-PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;
-PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
-PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
-PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
-PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
-PFNGLLINKPROGRAMPROC glLinkProgramARB = NULL;
-PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
-PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = NULL;
-PFNGLGETINFOLOGARBPROC glGetInfoLogARB = NULL;
-#endif
#ifndef GL_ARB_point_sprite
-#define GL_POINT_SPRITE_ARB 0x8861
-#define GL_COORD_REPLACE_ARB 0x8862
+#define GL_POINT_SPRITE_ARB 0x8861
+#define GL_COORD_REPLACE_ARB 0x8862
#endif
-
-unsigned int shaderId;
+/*
+#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;
+PFNGLLINKPROGRAMPROC glLinkProgramARB = NULL;
+PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
+PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = NULL;
+PFNGLGETINFOLOGARBPROC glGetInfoLogARB = NULL;
+PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB = NULL;
+PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB = NULL;
+PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB = NULL;
+#endif
+*/
//-----------------------------------------------------------------------------
vtkCxxSetObjectMacro(VISU_OpenGLPointSpriteMapper, ParticleImage, vtkImageData);
{
this->bmpReader = vtkBMPReader::New();
}
- this->DefaultPointSize = 50.0; //-1.0;
+ this->DefaultPointSize = 30.0; //-1.0;
this->MaximumSupportedSize = 0.0;
this->QuadraticPointDistanceAttenuation[0] = 1.0;
this->QuadraticPointDistanceAttenuation[1] = 0.0;
this->RenderMode = VISU_OpenGLPointSpriteMapper::Accumulate;
+#ifdef GL_ARB_shader_objects
+ this->OpenGLLibrary = 0;
+ this->VertexShader = 0;
+ this->VertexProgram = 0;
+#endif
+
this->XMLImageDataReader = vtkXMLImageDataReader::New();
this->PointSpriteTexture = 0;
this->IsUsingOpenGLMapper = false;
}
//-----------------------------------------------------------------------------
-// Destructor (don't call ReleaseGraphicsResources() since it is virtual
VISU_OpenGLPointSpriteMapper::~VISU_OpenGLPointSpriteMapper()
{
glDeleteTextures( 1, &PointSpriteTexture );
}
//-----------------------------------------------------------------------------
#ifdef GL_ARB_shader_objects
-void printInfoLog( GLhandleARB obj )
+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;
}
#endif
//-----------------------------------------------------------------------------
-void initShader()
+void VISU_OpenGLPointSpriteMapper::InitShader()
{
+#ifdef GL_ARB_shader_objects
+ //cout << "Initializing vertex program" << endl;
+
std::string fileName = std::string( getenv( "VISU_ROOT_DIR") ) +
- "/share/salome/resources/Vertex_Program_ARB.txt";
+ "/share/salome/resources/Vertex_Program_ARB.txt";
//std::string fileName = std::string( "/dn06/salome/ouv/SALOME3/VISU_SRC/resources/Vertex_Program_ARB.txt");
-
char* shader = readFromFile( fileName );
-#ifdef GL_ARB_shader_objects
- GLhandleARB v = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
- glShaderSourceARB( v, 1, (const GLcharARB**)&shader, NULL );
- glCompileShaderARB( v );
- //printInfoLog( v );
+ 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" );
+ PFNGLLINKPROGRAMPROC glLinkProgramARB = (PFNGLLINKPROGRAMPROC)dlsym( this->OpenGLLibrary, "glLinkProgramARB" );
+ PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glUseProgramObjectARB" );
- GLhandleARB p = glCreateProgramObjectARB();
- glAttachObjectARB( p, v );
+ this->VertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
+ glShaderSourceARB( this->VertexShader, 1, (const GLcharARB**)&shader, NULL );
+ glCompileShaderARB( this->VertexShader );
+ //printInfoLog( this->VertexShader );
- glLinkProgramARB( p );
- //printInfoLog( p );
+ this->VertexProgram = glCreateProgramObjectARB();
+ glAttachObjectARB( this->VertexProgram, this->VertexShader );
- glUseProgramObjectARB( p );
-#endif
+ glLinkProgramARB( this->VertexProgram );
+ //printInfoLog( this->VertexProgram );
+
+ glUseProgramObjectARB( this->VertexProgram );
+ this->SetShaderVariable( "minSize", 15.0 );
+ this->SetShaderVariable( "maxSize", 50.0 );
+ this->SetShaderVariable( "clamp", 100.0 );
/*
cout << "Shader from " << fileName << endl;
for( int i = 0; i < strlen( shader ); i++ )
cout << "Loading vertex program... failed" << endl << endl;
*/
delete shader;
-}
-//-----------------------------------------------------------------------------
-// Name: setShaderConstants()
-// Desc:
-//-----------------------------------------------------------------------------
-void setShaderConstants()
-{
+#endif
+
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
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 );
-
- //glProgramEnvParameter4fARB( GL_VERTEX_PROGRAM_ARB, 0, 50.0f, 1.0f, 1.0f, 1.0f );
- //glProgramEnvParameter4fARB( GL_VERTEX_PROGRAM_ARB, 1, 1.0f, 1.0f, 1.0f, 1.0f );
- //glProgramEnvParameter4fARB( GL_VERTEX_PROGRAM_ARB, 2, 1.0f, 10.0f, 100.0f, 1000.0f );
}
//-----------------------------------------------------------------------------
-// Release the graphics resources used by this mapper. In this case, release
-// the display list if any.
-void VISU_OpenGLPointSpriteMapper::ReleaseGraphicsResources(vtkWindow *win)
+void VISU_OpenGLPointSpriteMapper::SetShaderVariable( const char* variable, float value )
{
- if (this->ListId && win)
- {
- win->MakeCurrent();
- glDeleteLists(this->ListId,1);
- this->ListId = 0;
- }
- this->LastWindow = NULL;
- // We actually only want to release our texture when the texture needs reloading, or when
- // we are supposed to free up resources
- if (this->ParticleTexture)
- {
- this->ParticleTexture->ReleaseGraphicsResources(win);
- }
+#ifdef GL_ARB_shader_objects
+ PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)dlsym( this->OpenGLLibrary, "glGetAttribLocationARB" );
+ PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB = (PFNGLVERTEXATTRIB1FARBPROC)dlsym( this->OpenGLLibrary, "glVertexAttrib1fARB" );
+
+ glVertexAttrib1fARB( glGetAttribLocationARB( this->VertexProgram, variable ), value );
+#endif
}
//-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::InitializeExtensions()
+void VISU_OpenGLPointSpriteMapper::InitExtensions()
{
char* ext = (char*)glGetString( GL_EXTENSIONS );
//cout << "OpenGL extensions : " << ext << endl;
return;
}
- void* libHandle = dlopen( "libGL.so", RTLD_NOW );
/*
+#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" );
- */
-#ifdef GL_ARB_shader_objects
+
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)dlsym( libHandle, "glShaderSourceARB" );
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)dlsym( libHandle, "glCreateShaderObjectARB" );
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)dlsym( libHandle, "glCompileShaderARB" );
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
+ */
- initShader();
- setShaderConstants();
+#ifdef GL_ARB_shader_objects
+ this->OpenGLLibrary = dlopen( "libGL.so", RTLD_LAZY );
+
+ this->InitShader();
+#endif
this->ExtensionsOK = 1;
this->ExtensionsInitialized = 1;
{
if( !this->ExtensionsInitialized && !this->IsUsingOpenGLMapper )
{
- this->InitializeExtensions();
+ this->InitExtensions();
act->GetProperty()->SetPointSize( 10.0f );
}
// Make sure open GL extensions are initialized
if (!this->ExtensionsInitialized)
{
- this->InitializeExtensions();
+ this->InitExtensions();
}
if (!this->ExtensionsOK)
{
return;
}
- */
vtkImageData *particlesource = NULL;
if (this->ParticleImageFileName && !this->ParticleImage)
// this->ParticleTexture->DebugOn();
// this->ParticleTexture->Update();
-
+*/
// setup clippingplanes
clipPlanes = this->ClippingPlanes;
if (clipPlanes == NULL)
glEnd(); \
}
//-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::initSprites()
+void VISU_OpenGLPointSpriteMapper::InitSprites()
{
switch (this->RenderMode)
{
if (this->MaximumSupportedSize==0.0)
{
glGetFloatv( GL_POINT_SIZE_MAX_ARB, &this->MaximumSupportedSize );
+ //cout << this->MaximumSupportedSize << endl;
}
if (this->DefaultPointSize==-1)
{
*/
}
//-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::cleanupSprites()
+void VISU_OpenGLPointSpriteMapper::CleanupSprites()
{
// Set GL params back to normal to stop other vtkMappers diusplaying wrongly
glEnable( GL_DEPTH_TEST );
vtkImageData* imageData = this->XMLImageDataReader->GetOutput();
this->InitTexture( imageData );
- initSprites();
+ InitSprites();
void *voidPoints = p->GetVoidPointer(0);
unsigned char *rgba;
{
case VTK_PDPSM_POINT_TYPE_FLOAT:
//std::cout << "VTK_PDPSM_POINT_TYPE_FLOAT " << std::endl;
- vtkDrawPointsMacro(float, glVertex3fv(points + 3**ptIds);, initSprites(););
+ vtkDrawPointsMacro(float, glVertex3fv(points + 3**ptIds);, InitSprites(););
break;
case VTK_PDPSM_POINT_TYPE_DOUBLE:
//std::cout << "VTK_PDPSM_POINT_TYPE_DOUBLE " << std::endl;
- vtkDrawPointsMacro(double, glVertex3dv(points + 3**ptIds);, initSprites(););
+ vtkDrawPointsMacro(double, glVertex3dv(points + 3**ptIds);, InitSprites(););
break;
case VTK_PDPSM_POINT_TYPE_FLOAT | VTK_PDPSM_COLORS:
//std::cout << "VTK_PDPSM_POINT_TYPE_FLOAT | VTK_PDPSM_COLORS " << std::endl;
vtkDrawPointsMacro(float,
glColor4ubv(rgba + 4**ptIds);
- glVertex3fv(points + 3**ptIds);, initSprites(););
+ glVertex3fv(points + 3**ptIds);, InitSprites(););
break;
case VTK_PDPSM_POINT_TYPE_DOUBLE | VTK_PDPSM_COLORS:
//std::cout << "VTK_PDPSM_POINT_TYPE_DOUBLE | VTK_PDPSM_COLORS " << std::endl;
vtkDrawPointsMacro(double,
glColor4ubv(rgba + 4**ptIds);
- glVertex3dv(points + 3**ptIds);, initSprites(););
+ glVertex3dv(points + 3**ptIds);, InitSprites(););
break;
case VTK_PDPSM_POINT_TYPE_FLOAT | VTK_PDPSM_COLORS | VTK_PDPSM_OPAQUE_COLORS:
//std::cout << "VTK_PDPSM_POINT_TYPE_FLOAT | VTK_PDPSM_COLORS | VTK_PDPSM_OPAQUE_COLORS " << std::endl;
vtkDrawPointsMacro(float,
glColor3ubv(rgba + 4**ptIds);
- glVertex3fv(points + 3**ptIds);, initSprites(););
+ glVertex3fv(points + 3**ptIds);, InitSprites(););
break;
default:
{
}
}
- cleanupSprites();
+ CleanupSprites();
}
//-----------------------------------------------------------------------------
return noAbort;
}
//-----------------------------------------------------------------------------
+// Release the graphics resources used by this mapper. In this case, release
+// the display list if any.
+void VISU_OpenGLPointSpriteMapper::ReleaseGraphicsResources(vtkWindow *win)
+{
+ this->Superclass::ReleaseGraphicsResources(win);
+ /*
+ if (this->ListId && win)
+ {
+ win->MakeCurrent();
+ glDeleteLists(this->ListId,1);
+ this->ListId = 0;
+ }
+ this->LastWindow = NULL;
+ // We actually only want to release our texture when the texture needs reloading, or when
+ // we are supposed to free up resources
+ if (this->ParticleTexture)
+ {
+ this->ParticleTexture->ReleaseGraphicsResources(win);
+ }
+ */
+}
+//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);