#include <stdio.h>
#include <cmath>
#include <string>
+#include <vector>
#ifndef VTK_IMPLEMENT_MESA_CXX
vtkCxxRevisionMacro(VISU_OpenGLPointSpriteMapper, "$Revision$");
#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;
this->RenderMode = VISU_OpenGLPointSpriteMapper::Accumulate;
this->XMLImageDataReader = vtkXMLImageDataReader::New();
- TextureIntensity = 0;
- TextureAlphaChannel = 0;
-
+ this->PointSpriteTexture = 0;
this->IsUsingOpenGLMapper = false;
}
//-----------------------------------------------------------------------------
// Destructor (don't call ReleaseGraphicsResources() since it is virtual
VISU_OpenGLPointSpriteMapper::~VISU_OpenGLPointSpriteMapper()
{
+ glDeleteTextures( 1, &PointSpriteTexture );
+
if (this->LastWindow)
{
this->ReleaseGraphicsResources(this->LastWindow);
char* shader = readFromFile( fileName );
- //glGenProgramsARB( 1, &shaderId );
- //glBindProgramARB( GL_VERTEX_PROGRAM_ARB, shaderId );
- //glProgramStringARB( GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen( shader ), shader );
-
#ifdef GL_ARB_shader_objects
GLhandleARB v = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
glShaderSourceARB( v, 1, (const GLcharARB**)&shader, NULL );
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 );
+ //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
}
void* libHandle = dlopen( "libGL.so", RTLD_NOW );
-
+ /*
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" );
this->LastWindow = ren->GetRenderWindow();
// Load the texture for the particle into gl
- this->ParticleTexture->Load(ren);
+ //this->ParticleTexture->Load(ren);
// get a unique display list id
this->ListId = glGenLists(1);
!this->GetGlobalImmediateModeRendering())
{
// Load the texture for the particle into gl
- this->ParticleTexture->Load(ren);
+ //this->ParticleTexture->Load(ren);
// Time the actual drawing
this->Timer->StartTimer();
this->GetGlobalImmediateModeRendering())
{
// Load the texture for the particle into gl
- this->ParticleTexture->Load(ren);
+ //this->ParticleTexture->Load(ren);
// Time the actual drawing
this->Timer->StartTimer();
this->Timer->StopTimer();
}
+ //this->Texture->Render( ren );
+
this->TimeToDraw = (float)this->Timer->GetElapsedTime();
// If the timer is not accurate enough, set it to a small
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::initSprites()
{
- glBindTexture( GL_TEXTURE_2D, TextureIntensity );
-
switch (this->RenderMode)
{
case VISU_OpenGLPointSpriteMapper::Accumulate:
}
glPointSize( CurrentPointSize );
- glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
-
- glEnable( GL_POINT_SPRITE_ARB );
- glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
-
/*
// Set Quadratic Attenuation parameters
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, this->QuadraticPointDistanceAttenuation );
void VISU_OpenGLPointSpriteMapper::cleanupSprites()
{
// Set GL params back to normal to stop other vtkMappers diusplaying wrongly
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
+ glEnable( GL_DEPTH_TEST );
+ glEnable( GL_LIGHTING );
glEnable( GL_BLEND );
-
- glDisable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
- glDisable( GL_POINT_SPRITE_ARB );
-
- glDisable( GL_TEXTURE_2D );
}
//-----------------------------------------------------------------------------
-GLuint VISU_OpenGLPointSpriteMapper::LoadTexture( vtkImageData* imageData )
+void VISU_OpenGLPointSpriteMapper::InitTexture( vtkImageData* imageData )
{
- //this->XMLImageDataReader->SetFileName( fileName );
- //vtkImageData* imageData = this->XMLImageDataReader->GetOutput();
+ //cout << "VISU_OpenGLPointSpriteMapper::InitTexture" << endl;
+
//imageData->DebugOn();
imageData->RequestExactExtentOn();
imageData->UpdateInformation();
int* size = imageData->GetDimensions();
vtkDataArray* scalars = imageData->GetPointData()->GetScalars();
- unsigned char* dataPtr = static_cast<vtkUnsignedCharArray *>(scalars)->GetPointer(0);
-
- glEnable( GL_TEXTURE_2D );
-
- GLuint texture;
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
- glGenTextures( 1, &texture );
- glBindTexture( GL_TEXTURE_2D, texture );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, dataPtr );
+ unsigned char* dataPtr = static_cast<vtkUnsignedCharArray*>(scalars)->GetPointer(0);
- return texture;
-}
-//-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::DrawTexture( GLuint texture, GLfloat x, GLfloat y, GLfloat z )
-{
- //cout << "DrawTexture : " << texture << endl;
- //glColor4f( 1.0, 1.0, 1.0, 1.0 );
-
- //glAlphaFunc( GL_GREATER, 0.95F );
- //glEnable( GL_ALPHA_TEST );
-
- //glBindTexture( GL_TEXTURE_2D, texture );
- glBegin( GL_POINTS );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
+ //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+ //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glVertex3f( x, y, z );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, dataPtr);
- glEnd();
- glFlush();
-
- //glDisable( GL_ALPHA_TEST );
- //glDisable( GL_TEXTURE_2D );
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glEnable( GL_TEXTURE_2D );
+ glEnable( GL_POINT_SPRITE_ARB );
+ glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
+ glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
+ glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture );
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx,
vtkCellArray *cells,
vtkRenderer *ren)
{
+ this->XMLImageDataReader->SetFileName( "/dn06/salome/ouv/SALOME3/TextureAlphaChannel.vti" );
+ vtkImageData* imageData = this->XMLImageDataReader->GetOutput();
+ this->InitTexture( imageData );
+
+ initSprites();
+
void *voidPoints = p->GetVoidPointer(0);
unsigned char *rgba;
float *alphadata;
// draw all the elements, use fast path if available
switch (idx)
- {
+ {
case VTK_PDPSM_POINT_TYPE_FLOAT:
//std::cout << "VTK_PDPSM_POINT_TYPE_FLOAT " << std::endl;
vtkDrawPointsMacro(float, glVertex3fv(points + 3**ptIds);, initSprites(););
vtkDrawPointsMacro(float,
glColor4ubv(rgba + 4**ptIds);
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(););
-
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;
glVertex3fv(points + 3**ptIds);, initSprites(););
break;
default:
- {
- //std::cout << "Default " << std::endl;
+ {
+ //std::cout << "Default " << std::endl;
if (idx & VTK_PDPSM_ALPHA_ARRAY)
- {
alphadata = alpha->GetPointer(0);
- }
-
- initSprites();
-
- //glEnable( GL_VERTEX_PROGRAM_ARB );
- //glBindProgramARB( GL_VERTEX_PROGRAM_ARB, shaderId );
-
- //glColor4f( 1.0, 1.0, 1.0, 1.0 );
vtkIdType *pts = 0;
vtkIdType npts = 0;
glVertex3fv(p->GetPoint(pts[0]));
- /*
- vtkXMLImageDataReader* aReader = vtkXMLImageDataReader::New();
- aReader->SetFileName( "/dn06/salome/ouv/SALOME3/TextureIntensity.vti" );
- TextureIntensity = this->LoadTexture( aReader->GetOutput() );
- aReader->Delete();
-
- aReader = vtkXMLImageDataReader::New();
- aReader->SetFileName( "/dn06/salome/ouv/SALOME3/TextureAlphaChannel.vti" );
- TextureAlphaChannel = this->LoadTexture( aReader->GetOutput() );
- aReader->Delete();
- */
- /*
- this->DrawTexture( TextureIntensity,
- p->GetPoint(pts[0])[0],
- p->GetPoint(pts[0])[1],
- p->GetPoint(pts[0])[2] );
- /*
- this->DrawTexture( TextureAlphaChannel,
- p->GetPoint(pts[0])[0],
- p->GetPoint(pts[0])[1],
- p->GetPoint(pts[0])[2] );
- */
-
- //glVertex3fv(p->GetPoint(pts[0]));
-
// check for abort condition
if (count == 10000)
- {
+ {
count = 0;
// report progress
this->UpdateProgress((double)cellNum/this->TotalCells);
if (ren->GetRenderWindow()->CheckAbortStatus())
- {
noAbort = 0;
- }
- }
- ++cellNum;
- }
- glEnd();
- //glDisable( GL_VERTEX_PROGRAM_ARB );
+ }
+ ++cellNum;
}
+
+ glEnd();
}
+ }
- cleanupSprites();
+ cleanupSprites();
}
//-----------------------------------------------------------------------------