1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #define GL_GLEXT_PROTOTYPES
23 #include "VTKViewer_PolyDataMapper.h"
24 #include "VTKViewer_MarkerUtils.h"
26 #include <utilities.h>
30 #include <vtkCellArray.h>
31 #include <vtkXMLImageDataReader.h>
32 #include <vtkImageData.h>
33 #include <vtkObjectFactory.h>
34 #include <vtkPointData.h>
35 #include <vtkPolyData.h>
36 #include <vtkProperty.h>
37 #include <vtkRenderer.h>
38 #include <vtkSmartPointer.h>
39 #include <vtkTimerLog.h>
40 #include <vtkWindow.h>
41 #include <vtkRenderWindow.h>
42 #include <vtkCommand.h>
43 #include <vtkCellData.h>
46 # ifndef GLX_GLXEXT_LEGACY
47 # define GLX_GLXEXT_LEGACY
55 #ifndef VTK_IMPLEMENT_MESA_CXX
56 vtkStandardNewMacro(VTKViewer_PolyDataMapper);
59 // some definitions for what the polydata has in it
60 #define VTK_PDPSM_COLORS 0x0001
61 #define VTK_PDPSM_CELL_COLORS 0x0002
62 #define VTK_PDPSM_POINT_TYPE_FLOAT 0x0004
63 #define VTK_PDPSM_POINT_TYPE_DOUBLE 0x0008
64 #define VTK_PDPSM_NORMAL_TYPE_FLOAT 0x0010
65 #define VTK_PDPSM_NORMAL_TYPE_DOUBLE 0x0020
66 #define VTK_PDPSM_OPAQUE_COLORS 0x0040
72 #define APIENTRYP APIENTRY *
75 #ifndef GL_ARB_shader_objects
76 typedef char GLcharARB;
79 #ifndef GL_VERTEX_PROGRAM_POINT_SIZE_ARB
80 #define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
83 #ifndef GL_VERTEX_SHADER_ARB
84 #define GL_VERTEX_SHADER_ARB 0x8B31
87 #ifndef GL_FRAGMENT_SHADER_ARB
88 #define GL_FRAGMENT_SHADER_ARB 0x8B30
91 #ifndef GL_ARB_point_sprite
92 #define GL_POINT_SPRITE_ARB 0x8861
93 #define GL_COORD_REPLACE_ARB 0x8862
96 #ifndef GL_ARB_vertex_buffer_object
97 typedef ptrdiff_t GLsizeiptrARB;
99 #define GL_ARRAY_BUFFER_ARB 0x8892
100 #define GL_STATIC_DRAW_ARB 0x88E4
102 typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length);
103 typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType);
104 typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
105 typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
106 typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
107 typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
108 typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj);
109 typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void);
110 typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj);
111 typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj);
112 typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj);
113 typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name);
114 typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
115 typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index);
116 typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index);
119 typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj);
120 typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj);
121 typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB program);
122 typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) ( GLhandleARB program, const GLcharARB *name );
123 typedef void (APIENTRYP PFNGLGETSHADERIVARBPROC) (GLuint shader, GLenum pname, GLint *params);
124 typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLuint program, GLenum pname, GLint *params);
125 typedef void (APIENTRYP PFNGLGETSHADERINFOLOGARBPROC) (GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog);
126 typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
127 typedef void (APIENTRYP PFNGLGENVERTEXARRAYSARBPROC) (GLsizei n, GLuint *arrays);
128 typedef void (APIENTRYP PFNGLBINDVERTEXARRAYARBPROC) (GLuint array);
129 typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0);
132 typedef GLfloat TBall;
135 static PFNGLSHADERSOURCEARBPROC vglShaderSourceARB = NULL;
136 static PFNGLCREATESHADEROBJECTARBPROC vglCreateShaderObjectARB = NULL;
137 static PFNGLCOMPILESHADERARBPROC vglCompileShaderARB = NULL;
138 static PFNGLCREATEPROGRAMOBJECTARBPROC vglCreateProgramObjectARB = NULL;
139 static PFNGLATTACHOBJECTARBPROC vglAttachObjectARB = NULL;
140 static PFNGLLINKPROGRAMARBPROC vglLinkProgramARB = NULL;
141 static PFNGLUSEPROGRAMOBJECTARBPROC vglUseProgramObjectARB = NULL;
143 static PFNGLGENBUFFERSARBPROC vglGenBuffersARB = NULL;
144 static PFNGLBINDBUFFERARBPROC vglBindBufferARB = NULL;
145 static PFNGLBUFFERDATAARBPROC vglBufferDataARB = NULL;
146 static PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB = NULL;
147 static PFNGLGETATTRIBLOCATIONARBPROC vglGetAttribLocationARB = NULL;
148 static PFNGLVERTEXATTRIBPOINTERARBPROC vglVertexAttribPointerARB = NULL;
149 static PFNGLENABLEVERTEXATTRIBARRAYARBPROC vglEnableVertexAttribArrayARB = NULL;
150 static PFNGLDISABLEVERTEXATTRIBARRAYARBPROC vglDisableVertexAttribArrayARB = NULL;
153 static PFNGLDETACHOBJECTARBPROC vglDetachObjectARB = NULL;
154 static PFNGLDELETEOBJECTARBPROC vglDeleteObjectARB = NULL;
155 static PFNGLVALIDATEPROGRAMARBPROC vglValidateProgramARB = NULL;
156 static PFNGLGETSHADERIVARBPROC vglGetShaderivARB = NULL;
157 static PFNGLGETPROGRAMIVARBPROC vglGetProgramivARB = NULL;
158 static PFNGLGETSHADERINFOLOGARBPROC vglGetShaderInfoLogARB = NULL;
160 static PFNGLUNIFORMMATRIX4FVARBPROC vglUniformMatrix4fvARB = NULL;
161 static PFNGLGENVERTEXARRAYSARBPROC vglGenVertexArraysARB = NULL;
162 static PFNGLBINDVERTEXARRAYARBPROC vglBindVertexArrayARB = NULL;
163 static PFNGLUNIFORM1IARBPROC vglUniform1iARB = NULL;
164 static PFNGLGETUNIFORMLOCATIONARBPROC vglGetUniformLocationARB = NULL;
168 #define GL_GetProcAddress( x ) glXGetProcAddressARB( (const GLubyte*)x )
170 #define GL_GetProcAddress( x ) wglGetProcAddress( (const LPCSTR)x )
179 // ----------------------------------------------- Special Textures -----------------------------------
180 // texture id for balls drawing
181 #define BallTextureId 0
183 bool InitializeBufferExtensions()
185 vglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)GL_GetProcAddress( "glShaderSourceARB" );
186 if( !vglShaderSourceARB )
189 vglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)GL_GetProcAddress( "glCreateShaderObjectARB" );
190 if( !vglCreateShaderObjectARB )
193 vglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)GL_GetProcAddress( "glCompileShaderARB" );
194 if( !vglCompileShaderARB )
197 vglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)GL_GetProcAddress( "glCreateProgramObjectARB" );
198 if( !vglCreateProgramObjectARB )
201 vglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)GL_GetProcAddress( "glAttachObjectARB" );
202 if( !vglAttachObjectARB )
205 vglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)GL_GetProcAddress( "glLinkProgramARB" );
206 if( !vglLinkProgramARB )
209 vglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)GL_GetProcAddress( "glUseProgramObjectARB" );
210 if( !vglUseProgramObjectARB )
213 vglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GL_GetProcAddress( "glGenBuffersARB" );
214 if( !vglGenBuffersARB )
217 vglBindBufferARB = (PFNGLBINDBUFFERARBPROC)GL_GetProcAddress( "glBindBufferARB" );
218 if( !vglBindBufferARB )
221 vglBufferDataARB = (PFNGLBUFFERDATAARBPROC)GL_GetProcAddress( "glBufferDataARB" );
222 if( !vglBufferDataARB )
225 vglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GL_GetProcAddress( "glDeleteBuffersARB" );
226 if( !vglDeleteBuffersARB )
229 vglGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)GL_GetProcAddress( "glGetAttribLocation" );
230 if( !vglGetAttribLocationARB )
233 vglVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC)GL_GetProcAddress( "glVertexAttribPointer" );
234 if( !vglVertexAttribPointerARB )
237 vglEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)GL_GetProcAddress( "glEnableVertexAttribArray" );
238 if(!vglEnableVertexAttribArrayARB)
241 vglDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)GL_GetProcAddress( "glDisableVertexAttribArray" );
243 if(!vglDisableVertexAttribArrayARB)
247 vglDetachObjectARB = (PFNGLDETACHOBJECTARBPROC)GL_GetProcAddress( "glDetachObjectARB" );
248 if( !vglDetachObjectARB )
251 vglDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)GL_GetProcAddress( "glDeleteObjectARB" );
252 if( !vglDeleteObjectARB )
255 vglValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC)GL_GetProcAddress( "glValidateProgramARB" );
256 if ( !vglValidateProgramARB )
259 vglGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)GL_GetProcAddress( "glGetUniformLocationARB" );
260 if( !vglGetUniformLocationARB )
263 vglGetShaderivARB = (PFNGLGETSHADERIVPROC)GL_GetProcAddress( "glGetShaderiv" );
264 if( !vglGetShaderivARB )
267 vglGetProgramivARB = (PFNGLGETPROGRAMIVPROC)GL_GetProcAddress( "glGetProgramiv" );
268 if( !vglGetProgramivARB )
271 vglGetShaderInfoLogARB = (PFNGLGETSHADERINFOLOGPROC)GL_GetProcAddress( "glGetShaderInfoLog" );
272 if( !vglGetShaderInfoLogARB )
275 vglUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC)GL_GetProcAddress( "glUniformMatrix4fv" );
276 if( !vglUniformMatrix4fvARB )
279 vglGenVertexArraysARB = (PFNGLGENVERTEXARRAYSARBPROC)GL_GetProcAddress( "glGenVertexArrays" );
280 if( !vglGenVertexArraysARB )
283 vglBindVertexArrayARB = (PFNGLBINDVERTEXARRAYARBPROC)GL_GetProcAddress( "glBindVertexArray" );
284 if( !vglBindVertexArrayARB )
287 vglUniform1iARB = (PFNGLUNIFORM1IARBPROC)GL_GetProcAddress( "glUniform1i" );
288 if( !vglUniform1iARB )
295 //-----------------------------------------------------------------------------
296 char* readFromFile( std::string fileName )
298 FILE* file = fopen( fileName.c_str(), "r" );
300 char* content = NULL;
305 fseek( file, 0, SEEK_END );
306 count = ftell( file );
311 content = ( char* )malloc( sizeof( char ) * ( count + 1 ) );
312 count = fread( content, sizeof( char ), count, file );
313 content[ count ] = '\0';
321 static bool IsBufferExtensionsInitialized = InitializeBufferExtensions();
323 //-----------------------------------------------------------------------------
324 VTKViewer_PolyDataMapper::VTKViewer_PolyDataMapper()
326 Q_INIT_RESOURCE( VTKViewer );
328 this->ExtensionsInitialized = ES_None;
330 this->PointSpriteTexture = 0;
332 this->MarkerEnabled = false;
333 this->MarkerType = VTK::MT_NONE;
334 this->MarkerScale = VTK::MS_NONE;
336 this->BallEnabled = false;
337 this->BallScale = 1.0;
338 this->PointProgram = 0;
340 this->VertexShader = 0;
341 this->FragmentShader = 0;
345 //-----------------------------------------------------------------------------
346 VTKViewer_PolyDataMapper::~VTKViewer_PolyDataMapper()
348 if( PointSpriteTexture > 0 )
349 glDeleteTextures( 1, &PointSpriteTexture );
352 vglDetachObjectARB( this->PointProgram, this->VertexShader );
353 vglDetachObjectARB( this->PointProgram, this->FragmentShader );
355 vglDeleteObjectARB( this->VertexShader );
356 vglDeleteObjectARB( this->FragmentShader );
360 //-----------------------------------------------------------------------------
361 int VTKViewer_PolyDataMapper::InitShader()
364 const GLubyte *version = glGetString(GL_VERSION);
367 this->PointProgram = vglCreateProgramObjectARB();
368 if (this->PointProgram == 0)
370 MESSAGE("Can't create opengl program.");
374 std::string fileName;
376 GLint linked, compileStatus, validateStatus;
378 // Create vertex shader.
379 fileName = std::string( getenv( "GUI_ROOT_DIR") ) +
380 "/share/salome/resources/gui/Vertex_Shader_ARB.glsl";
382 shaderContent = readFromFile( fileName );
384 this->VertexShader = vglCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
385 vglShaderSourceARB( this->VertexShader, 1, (const GLcharARB**)&shaderContent, NULL );
386 vglCompileShaderARB( this->VertexShader );
388 free( shaderContent );
390 vglGetShaderivARB( this->VertexShader, GL_COMPILE_STATUS, &compileStatus );
\r
391 if (compileStatus != GL_TRUE)
\r
396 vglGetShaderInfoLogARB( this->VertexShader, 1024, &size, info );
397 std::cout << info << std::endl;
399 MESSAGE( "Can't compile vertex shader." );
403 // Create fragment shader.
404 fileName = std::string( getenv( "GUI_ROOT_DIR") ) +
405 "/share/salome/resources/gui/Fragment_Shader_ARB.glsl";
407 shaderContent = readFromFile( fileName );
409 this->FragmentShader = vglCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
410 vglShaderSourceARB( this->FragmentShader, 1, (const GLcharARB**)&shaderContent, NULL );
411 vglCompileShaderARB( this->FragmentShader );
413 free( shaderContent );
415 vglGetShaderivARB( this->FragmentShader, GL_COMPILE_STATUS, &compileStatus );
\r
416 if (compileStatus != GL_TRUE)
\r
418 MESSAGE( "Can't compile fragment shader." );
423 vglAttachObjectARB( this->PointProgram, this->VertexShader );
424 vglAttachObjectARB( this->PointProgram, this->FragmentShader );
425 vglLinkProgramARB( this->PointProgram );
427 vglGetProgramivARB( this->PointProgram, GL_LINK_STATUS, &linked );
430 MESSAGE("Can't link program.");
434 vglValidateProgramARB( this->PointProgram );
\r
435 vglGetProgramivARB( this->PointProgram, GL_VALIDATE_STATUS, &validateStatus );
437 if (validateStatus != GL_TRUE)
\r
439 MESSAGE( "Shader program is not validate." );
\r
443 // Get uniform locations.
444 vglUseProgramObjectARB( this->PointProgram );
446 this->myLocations.ModelViewProjection = vglGetUniformLocationARB( this->PointProgram, "uModelViewProjectionMatrix" );
447 this->myLocations.GeneralPointSize = vglGetUniformLocationARB( this->PointProgram, "uGeneralPointSize" );
448 this->myLocations.PointSprite = vglGetUniformLocationARB( this->PointProgram, "uPointSprite" );
450 vglUseProgramObjectARB( 0 );
452 vglGenVertexArraysARB(1, &this->VertexArrayObject);
454 std::string fileName = std::string( getenv( "GUI_ROOT_DIR") ) +
455 "/share/salome/resources/gui/Vertex_Program_ARB.txt";
457 char* shader = readFromFile( fileName );
459 GLhandleARB VertexShader = vglCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
460 vglShaderSourceARB( VertexShader, 1, (const GLcharARB**)&shader, NULL );
461 vglCompileShaderARB( VertexShader );
463 this->PointProgram = vglCreateProgramObjectARB();
464 vglAttachObjectARB( this->PointProgram, VertexShader );
466 vglLinkProgramARB( this->PointProgram );
474 //-----------------------------------------------------------------------------
475 void VTKViewer_PolyDataMapper::SetMarkerEnabled( bool theMarkerEnabled )
477 if( this->MarkerEnabled == theMarkerEnabled )
480 this->MarkerEnabled = theMarkerEnabled;
484 //-----------------------------------------------------------------------------
485 // Definition of structures and fuctions used in SetBallEnabled() method
488 //----------------------------------------------------------------------------
489 vtkSmartPointer<vtkImageData> MakeTexture( const char* theMainTexture, const char* theAlphaTexture ) {
490 if( !theMainTexture || !theAlphaTexture )
493 vtkXMLImageDataReader* aMainReader = vtkXMLImageDataReader::New();
494 vtkXMLImageDataReader* anAlphaReader = vtkXMLImageDataReader::New();
496 aMainReader->SetFileName( theMainTexture );
497 anAlphaReader->SetFileName( theAlphaTexture );
499 aMainReader->Update();
500 anAlphaReader->Update();
502 vtkImageData* aMainImageData = aMainReader->GetOutput();
503 vtkImageData* anAlphaImageData = anAlphaReader->GetOutput();
505 int* aMainImageSize = aMainImageData->GetDimensions();
506 int* anAlphaImageSize = anAlphaImageData->GetDimensions();
507 if(aMainImageSize[0] != anAlphaImageSize[0] || aMainImageSize[1] != anAlphaImageSize[1])
510 vtkSmartPointer<vtkImageData> aCompositeImageData = vtkImageData::New();
511 aCompositeImageData->Delete();
513 int aNbCompositeComponents = 4;
514 aCompositeImageData->SetDimensions(aMainImageSize);
515 aCompositeImageData->AllocateScalars( VTK_UNSIGNED_CHAR, aNbCompositeComponents );
517 unsigned char* aMainDataPtr = (unsigned char*)aMainImageData->GetScalarPointer();
518 unsigned char* anAlphaDataPtr = (unsigned char*)anAlphaImageData->GetScalarPointer();
519 unsigned char *aCompositeDataPtr = (unsigned char * )aCompositeImageData->GetScalarPointer();
521 int aNbMainComponents = aMainImageData->GetNumberOfScalarComponents();
522 int aNbAlphaComponents = anAlphaImageData->GetNumberOfScalarComponents();
523 int aCompositeSize = aMainImageSize[0] * aMainImageSize[1] * aNbCompositeComponents;
525 int aMainId = 0, anAlphaId = 0, aCompositeId = 0;
526 for(; aCompositeId < aCompositeSize;) {
527 aCompositeDataPtr[aCompositeId] = aMainDataPtr[aMainId];
528 aCompositeDataPtr[aCompositeId + 1] = aMainDataPtr[aMainId + 1];
529 aCompositeDataPtr[aCompositeId + 2] = aMainDataPtr[aMainId + 2];
530 aCompositeDataPtr[aCompositeId + 3] = anAlphaDataPtr[anAlphaId];
532 aMainId += aNbMainComponents;
533 anAlphaId += aNbAlphaComponents;
534 aCompositeId += aNbCompositeComponents;
536 aMainReader->Delete();
537 anAlphaReader->Delete();
538 return aCompositeImageData;
542 //-----------------------------------------------------------------------------
543 bool VTKViewer_PolyDataMapper::GetBallEnabled()
545 return this->BallEnabled;
547 //-----------------------------------------------------------------------------
548 void VTKViewer_PolyDataMapper::SetBallEnabled( bool theBallEnabled )
550 if( this->BallEnabled == theBallEnabled )
553 this->BallEnabled = theBallEnabled;
555 if(!this->BallEnabled) {
556 this->ImageData = NULL;
559 if(this->BallEnabled) {
560 if(this->SpecialTextures.find(BallTextureId) == SpecialTextures.end()){
561 QString aMainTexture = getenv( "GUI_ROOT_DIR" );
562 aMainTexture.append("/share/salome/resources/gui/sprite_texture.vti");
564 QString anAlphaTexture = getenv( "GUI_ROOT_DIR" );
565 anAlphaTexture.append( "/share/salome/resources/gui/sprite_alpha.vti" );
566 vtkSmartPointer<vtkImageData> aTextureValue = VTK::MakeTexture( aMainTexture.toLatin1().constData(), anAlphaTexture.toLatin1().constData() );
567 this->SpecialTextures[BallTextureId] = aTextureValue;
569 this->ImageData = this->SpecialTextures[BallTextureId];
574 //-----------------------------------------------------------------------------
575 double VTKViewer_PolyDataMapper::GetBallScale()
577 return this->BallScale;
579 //-----------------------------------------------------------------------------
580 void VTKViewer_PolyDataMapper::SetBallScale( double theBallScale )
582 if( this->BallScale == theBallScale )
584 this->BallScale = theBallScale;
587 //-----------------------------------------------------------------------------
588 void VTKViewer_PolyDataMapper::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
590 if( this->MarkerType == theMarkerType && this->MarkerScale == theMarkerScale )
593 this->MarkerType = theMarkerType;
594 this->MarkerScale = theMarkerScale;
596 if( this->MarkerType == VTK::MT_NONE || this->MarkerType == VTK::MT_USER ) {
597 this->ImageData = NULL;
602 int aMarkerType = (int)this->MarkerType;
603 int aMarkerScale = (int)this->MarkerScale;
605 int anId = (int)VTK::MS_70 * aMarkerType + aMarkerScale;
607 if( this->StandardTextures.find( anId ) == this->StandardTextures.end() )
609 QString aFileName = QString( ":/textures/texture%1.dat" ).arg( aMarkerType );
610 VTK::MarkerTexture aMarkerTexture;
611 if( VTK::LoadTextureData( aFileName, theMarkerScale, aMarkerTexture ) )
612 this->StandardTextures[ anId ] = VTK::MakeVTKImage( aMarkerTexture );
615 this->ImageData = this->StandardTextures[ anId ];
619 //-----------------------------------------------------------------------------
620 void VTKViewer_PolyDataMapper::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
622 if( this->MarkerType == VTK::MT_USER && this->MarkerId == theMarkerId )
625 this->MarkerType = VTK::MT_USER;
626 this->MarkerId = theMarkerId;
628 if( this->CustomTextures.find( theMarkerId ) == this->CustomTextures.end() )
629 this->CustomTextures[ theMarkerId ] = VTK::MakeVTKImage( theMarkerTexture );
631 this->ImageData = this->CustomTextures[ theMarkerId ];
635 //-----------------------------------------------------------------------------
636 VTK::MarkerType VTKViewer_PolyDataMapper::GetMarkerType()
638 return this->MarkerType;
641 //-----------------------------------------------------------------------------
642 VTK::MarkerScale VTKViewer_PolyDataMapper::GetMarkerScale()
644 return this->MarkerScale;
647 //-----------------------------------------------------------------------------
648 int VTKViewer_PolyDataMapper::GetMarkerTexture()
650 return this->MarkerId;
653 //-----------------------------------------------------------------------------
654 int VTKViewer_PolyDataMapper::InitExtensions()
658 std::ostringstream strm;
659 glGetIntegerv(GL_NUM_EXTENSIONS, &n);
660 for (int i = 0; i < n; i++)
662 const char *exti = (const char *)glGetStringi(GL_EXTENSIONS, i);
665 std::string s = strm.str();
666 const char* ext = s.c_str();
668 const char* ext = (const char*)glGetString( GL_EXTENSIONS );
670 if( !IsBufferExtensionsInitialized || !ext ||
671 strstr( ext, "GL_ARB_point_sprite" ) == NULL ||
672 strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL ||
673 strstr( ext, "GL_ARB_shader_objects") == NULL )
675 MESSAGE("Initializing ARB extensions failed");
679 return this->InitShader();
682 //-----------------------------------------------------------------------------
683 void VTKViewer_PolyDataMapper::InitPointSprites()
685 glEnable( GL_POINT_SPRITE_ARB );
686 glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
688 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT );
690 glDepthFunc( GL_LEQUAL );
691 glEnable( GL_DEPTH_TEST );
693 glEnable( GL_ALPHA_TEST );
694 if(!this->BallEnabled) {
695 glAlphaFunc( GL_GREATER, 0.0 );
698 glAlphaFunc( GL_GREATER, 0.5 );
701 glDisable( GL_LIGHTING );
703 glDisable( GL_COLOR_MATERIAL );
706 //-----------------------------------------------------------------------------
707 void VTKViewer_PolyDataMapper::CleanupPointSprites()
711 glDisable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
712 glDisable( GL_POINT_SPRITE_ARB );
715 //-----------------------------------------------------------------------------
716 void VTKViewer_PolyDataMapper::InitTextures()
718 if( !this->ImageData.GetPointer() )
721 glEnable( GL_TEXTURE_2D );
722 if( this->PointSpriteTexture == 0 ) {
723 glGenTextures( 1, &this->PointSpriteTexture );
726 glActiveTexture( GL_TEXTURE0 );
728 glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture );
729 glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
730 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
731 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
733 if(this->BallEnabled) {
734 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
735 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
737 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
738 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
741 int* aSize = this->ImageData->GetDimensions();
742 unsigned char* dataPtr = (unsigned char*)this->ImageData->GetScalarPointer();
743 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aSize[0], aSize[1], 0,
744 GL_RGBA, GL_UNSIGNED_BYTE, dataPtr );
748 vglUniform1iARB( this->myLocations.PointSprite, GL_TEXTURE0 );
752 //-----------------------------------------------------------------------------
753 void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act )
755 bool isUsePointSprites = (this->MarkerEnabled && this->MarkerType != VTK::MT_NONE) ||
757 if( isUsePointSprites )
759 if( this->ExtensionsInitialized != ES_Ok )
760 this->ExtensionsInitialized = this->InitExtensions();
761 this->InitPointSprites();
762 this->InitTextures();
765 if(!this->BallEnabled || this->ExtensionsInitialized != ES_Ok) {
766 MAPPER_SUPERCLASS::RenderPiece( ren, act );
767 if( isUsePointSprites )
768 this->CleanupPointSprites();
769 glBindTexture( GL_TEXTURE_2D, 0 );
772 vtkPolyData *input= this->GetInput();
775 // make sure that we've been properly initialized
777 if (ren->GetRenderWindow()->CheckAbortStatus())
782 vtkErrorMacro(<< "No input!");
787 this->InvokeEvent(vtkCommand::StartEvent,NULL);
789 this->InvokeEvent(vtkCommand::EndEvent,NULL);
790 numPts = input->GetNumberOfPoints();
795 vtkDebugMacro(<< "No points!");
799 // make sure our window is current
800 ren->GetRenderWindow()->MakeCurrent();
803 vglUseProgramObjectARB( this->PointProgram );
807 // if something has changed regenerate colors and display lists
811 if ( this->GetMTime() > this->BuildTime ||
812 input->GetMTime() > this->BuildTime ||
813 act->GetProperty()->GetMTime() > this->BuildTime ||
814 ren->GetRenderWindow() != this->LastWindow)
816 // sets this->Colors as side effect
817 this->MapScalars( act->GetProperty()->GetOpacity() );
819 if (!this->ImmediateModeRendering &&
820 !this->GetGlobalImmediateModeRendering())
822 this->ReleaseGraphicsResources(ren->GetRenderWindow());
823 this->LastWindow = ren->GetRenderWindow();
825 // get a unique display list id
826 this->ListId = glGenLists(1);
827 glNewList(this->ListId,GL_COMPILE);
829 noAbort = this->Draw(ren,act);
832 // Time the actual drawing
833 this->Timer->StartTimer();
834 glCallList(this->ListId);
835 this->Timer->StopTimer();
839 this->ReleaseGraphicsResources(ren->GetRenderWindow());
840 this->LastWindow = ren->GetRenderWindow();
843 this->BuildTime.Modified();
845 // if nothing changed but we are using display lists, draw it
848 if (!this->ImmediateModeRendering &&
849 !this->GetGlobalImmediateModeRendering())
851 // Time the actual drawing
852 this->Timer->StartTimer();
853 glCallList(this->ListId);
854 this->Timer->StopTimer();
858 // if we are in immediate mode rendering we always
859 // want to draw the primitives here
860 if (this->ImmediateModeRendering ||
861 this->GetGlobalImmediateModeRendering())
863 // sets this->Colors as side effect
864 this->MapScalars( act->GetProperty()->GetOpacity() );
866 // Time the actual drawing
867 this->Timer->StartTimer();
869 this->Timer->StopTimer();
872 this->TimeToDraw = (float)this->Timer->GetElapsedTime();
874 // If the timer is not accurate enough, set it to a small
875 // time so that it is not zero
876 if ( this->TimeToDraw == 0.0 )
877 this->TimeToDraw = 0.0001;
879 //this->RenderPieceStart(ren, act);
880 this->RenderPieceDraw(ren, act);
881 // this->RenderEdges(ren,act);
882 //this->RenderPieceFinish(ren, act);
884 vglUseProgramObjectARB( 0 );
885 this->CleanupPointSprites();
886 glBindTexture( GL_TEXTURE_2D, 0 );
890 //-----------------------------------------------------------------------------
891 // Definition of structures and fuctions used in Draw() method
894 //-----------------------------------------------------------------------------
901 //-----------------------------------------------------------------------------
902 struct TColorFunctorBase
906 TColorFunctorBase( vtkProperty* theProperty )
908 myAlpha = theProperty->GetOpacity();
913 get( TVertex& theVertex, vtkIdType thePointId, vtkIdType theCellId ) = 0;
916 //-----------------------------------------------------------------------------
917 struct TPropertyColor : TColorFunctorBase
921 TPropertyColor( vtkProperty* theProperty ):
922 TColorFunctorBase( theProperty )
924 theProperty->GetColor( myColor );
929 get( TVertex& theVertex, vtkIdType thePointId, vtkIdType theCellId )
931 theVertex.r = myColor[0];
932 theVertex.g = myColor[1];
933 theVertex.b = myColor[2];
934 theVertex.a = myAlpha;
938 //-----------------------------------------------------------------------------
939 struct TColors2Color : TColorFunctorBase
941 vtkUnsignedCharArray* myColors;
943 TColors2Color( vtkProperty* theProperty,
944 vtkUnsignedCharArray* theColors ):
945 TColorFunctorBase( theProperty ),
946 myColors( theColors )
951 get( TVertex& theVertex, vtkIdType thePointId, vtkIdType theCellId )
953 vtkIdType aTupleId = GetTupleId( thePointId, theCellId );
954 unsigned char* aColor = myColors->GetPointer( aTupleId << 2 );
956 theVertex.r = int( aColor[0] ) / 255.0;
957 theVertex.g = int( aColor[1] ) / 255.0;
958 theVertex.b = int( aColor[2] ) / 255.0;
959 theVertex.a = myAlpha;
964 GetTupleId( vtkIdType thePointId, vtkIdType theCellId ) = 0;
967 //-----------------------------------------------------------------------------
968 struct TPointColors2Color : TColors2Color
970 TPointColors2Color( vtkProperty* theProperty,
971 vtkUnsignedCharArray* theColors ):
972 TColors2Color( theProperty, theColors )
977 GetTupleId( vtkIdType thePointId, vtkIdType theCellId )
983 //-----------------------------------------------------------------------------
984 struct TCellColors2Color : TColors2Color
986 TCellColors2Color( vtkProperty* theProperty,
987 vtkUnsignedCharArray* theColors ):
988 TColors2Color( theProperty, theColors )
993 GetTupleId( vtkIdType thePointId, vtkIdType theCellId )
999 //-----------------------------------------------------------------------------
1000 template < class TCoordinates >
1001 void DrawPoints( TCoordinates* theStartPoints,
1002 vtkCellArray* theCells,
1003 TColorFunctorBase* theColorFunctor,
1004 TVertex* theVertexArr,
1005 vtkIdType &theCellId,
1006 vtkIdType &theVertexId,
1008 vtkDataArray* theDiamArray,
1009 double theBallScale )
1011 vtkIdType* ptIds = theCells->GetPointer();
1012 vtkIdType* endPtIds = ptIds + theCells->GetNumberOfConnectivityEntries();
1014 bool mapBalls = false;
1015 if(theBallArr && theDiamArray) {
1019 while ( ptIds < endPtIds ) {
1020 vtkIdType nPts = *ptIds;
1023 while ( nPts > 0 ) {
1024 TVertex& aVertex = theVertexArr[ theVertexId ];
1025 vtkIdType aPointId = *ptIds;
1027 TCoordinates* anOffsetPoints = theStartPoints + 3 * aPointId;
1028 aVertex.vx = anOffsetPoints[0];
1029 aVertex.vy = anOffsetPoints[1];
1030 aVertex.vz = anOffsetPoints[2];
1032 theColorFunctor->get( aVertex, aPointId, theCellId );
1040 theBallArr[theCellId] = (TBall)theDiamArray->GetTuple(theCellId)[0]*theBallScale;
1047 //-----------------------------------------------------------------------------
1048 template < class TCoordinates >
1049 void DrawCellsPoints( vtkPolyData* theInput,
1050 vtkPoints* thePoints,
1051 TColorFunctorBase* theColorFunctor,
1052 TVertex* theVertexArr,
1054 double theBallScale )
1056 vtkIdType aCellId = 0, aVertexId = 0;
1058 TCoordinates* aStartPoints = (TCoordinates*)thePoints->GetVoidPointer(0);
1059 vtkDataArray* aDiams = theInput->GetCellData() ? theInput->GetCellData()->GetScalars() : 0;
1061 if ( vtkCellArray* aCellArray = theInput->GetVerts() ) {
1062 DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId, theBallArr, aDiams, theBallScale );
1065 if ( vtkCellArray* aCellArray = theInput->GetLines() )
1066 DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId, theBallArr, aDiams, theBallScale );
1068 if ( vtkCellArray* aCellArray = theInput->GetPolys() )
1069 DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId, theBallArr, aDiams, theBallScale );
1071 if ( vtkCellArray* aCellArray = theInput->GetStrips() )
1072 DrawPoints( aStartPoints, aCellArray, theColorFunctor, theVertexArr, aCellId, aVertexId, theBallArr, aDiams, theBallScale );
1077 //-----------------------------------------------------------------------------
1078 int VTKViewer_PolyDataMapper::Draw( vtkRenderer* ren, vtkActor* act )
1081 if( (!this->MarkerEnabled || this->MarkerType == VTK::MT_NONE || !this->ImageData.GetPointer()) && !this->BallEnabled)
1082 return MAPPER_SUPERCLASS::Draw( ren, act );
1084 InternalDraw( ren, act );
1089 //-----------------------------------------------------------------------------
1090 void VTKViewer_PolyDataMapper::RenderPieceDraw( vtkRenderer* ren, vtkActor* act ) {
1092 if( (!this->MarkerEnabled || this->MarkerType == VTK::MT_NONE || !this->ImageData.GetPointer()) && !this->BallEnabled) {
1093 MAPPER_SUPERCLASS::RenderPieceDraw( ren, act );
1096 InternalDraw( ren, act );
1101 #include <vtkCamera.h>
1102 #include <vtkOpenGLCamera.h>
1103 #include <vtkOpenGLActor.h>
1104 #include <vtkMatrix4x4.h>
1105 void SetUniformMatrix (const GLint theLocation,
1106 vtkMatrix4x4* theMatrix)
1109 for (int i = 0; i < 16; ++i)
1111 data[i] = theMatrix->Element[i / 4][i % 4];
1114 vglUniformMatrix4fvARB(theLocation, 1, GL_FALSE, data);
1118 void VTKViewer_PolyDataMapper::InternalDraw(vtkRenderer* ren, vtkActor* act ) {
1119 vtkUnsignedCharArray* colors = NULL;
1120 vtkPolyData* input = this->GetInput();
1122 int cellScalars = 0;
1123 vtkProperty* prop = act->GetProperty();
1125 points = input->GetPoints();
1129 if(!this->BallEnabled) {
1130 colors = this->Colors;
1131 if ( (this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA ||
1132 this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA ||
1133 !input->GetPointData()->GetScalars() )
1134 && this->ScalarMode != VTK_SCALAR_MODE_USE_POINT_FIELD_DATA )
1140 vtkIdType aTotalConnectivitySize = 0;
1141 vtkIdType aNbCells = 0;
1143 if ( vtkCellArray* aCellArray = input->GetVerts() ) {
1144 aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells();
1145 aNbCells += aCellArray->GetNumberOfCells();
1148 if ( vtkCellArray* aCellArray = input->GetLines() ) {
1149 aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells();
1150 aNbCells += aCellArray->GetNumberOfCells();
1153 if ( vtkCellArray* aCellArray = input->GetPolys() ) {
1154 aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells();
1155 aNbCells += aCellArray->GetNumberOfCells();
1158 if ( vtkCellArray* aCellArray = input->GetStrips() ) {
1159 aTotalConnectivitySize += aCellArray->GetNumberOfConnectivityEntries() - aCellArray->GetNumberOfCells();
1160 aNbCells += aCellArray->GetNumberOfCells();
1163 if ( aTotalConnectivitySize > 0 ) {
1164 VTK::TVertex* aVertexArr = new VTK::TVertex[ aTotalConnectivitySize ];
1166 TBall* aBallArray = 0;
1168 if(this->BallEnabled) {
1169 aBallArray = new TBall[aNbCells];
1172 int* aSize = this->ImageData->GetDimensions();
1173 //glPointSize( std::max( aSize[0], aSize[1] ) );
1175 int aMode = 0; // to remove
1177 VTK::TColorFunctorBase* aColorFunctor = NULL;
1178 if( colors && aMode != 1 ) {
1180 aColorFunctor = new VTK::TCellColors2Color( prop, colors );
1182 aColorFunctor = new VTK::TPointColors2Color( prop, colors );
1184 aColorFunctor = new VTK::TPropertyColor( prop );
1186 if ( points->GetDataType() == VTK_FLOAT )
1187 VTK::DrawCellsPoints< float >( input, points, aColorFunctor, aVertexArr, aBallArray, GetBallScale() );
1189 VTK::DrawCellsPoints< double >( input, points, aColorFunctor, aVertexArr, aBallArray, GetBallScale() );
1191 delete aColorFunctor;
1194 if( this->ExtensionsInitialized == ES_Ok ) {
1196 vglUseProgramObjectARB( this->PointProgram );
1198 vtkOpenGLCamera *cam = (vtkOpenGLCamera *)(ren->GetActiveCamera());
1201 vtkMatrix3x3 *norms;
1203 cam->GetKeyMatrices(ren,wcvc,norms,vcdc,wcdc);
1204 if (!act->GetIsIdentity())
1207 vtkMatrix3x3 *anorms;
1208 ((vtkOpenGLActor *)act)->GetKeyMatrices( mcwc, anorms );
1209 vtkMatrix4x4::Multiply4x4( mcwc, wcdc, this->TempMatrix4 );
1210 SetUniformMatrix( this->myLocations.ModelViewProjection, this->TempMatrix4 );
1214 SetUniformMatrix( this->myLocations.ModelViewProjection, wcdc );
1217 vglUniform1iARB( this->myLocations.GeneralPointSize, std::max( aSize[0], aSize[1] ) );
1219 GLuint aBufferObjectID, aDiamsID = 0;
1221 vglBindVertexArrayARB( this->VertexArrayObject );
1222 vglGenBuffersARB( 1, &aBufferObjectID );
1223 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
1225 int anArrayObjectSize = sizeof( VTK::TVertex ) * aTotalConnectivitySize;
1226 vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB );
1228 delete [] aVertexArr;
1231 GLint colorAttrib = vglGetAttribLocationARB( this->PointProgram, "Color" );
1232 GLint vertexAttrib = vglGetAttribLocationARB( this->PointProgram, "Vertex" );
1233 GLint diamAttrib = vglGetAttribLocationARB( this->PointProgram, "Diameter" );
1235 GLsizei vertexSize = sizeof(VTK::TVertex);
1237 vglVertexAttribPointerARB( colorAttrib, 4, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)0 );
1238 vglEnableVertexAttribArrayARB( colorAttrib );
1240 vglVertexAttribPointerARB( vertexAttrib, 3, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)(sizeof(GLfloat) * 4) );
1241 vglEnableVertexAttribArrayARB( vertexAttrib );
1243 if(this->BallEnabled) {
1244 // Don't use uniform variable.
1245 vglUniform1iARB( this->myLocations.GeneralPointSize, -1 );
1246 vglGenBuffersARB( 1, &aDiamsID);
1247 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID);
1249 int aDiamsSize = sizeof(TBall)*aNbCells;
1250 vglBufferDataARB( GL_ARRAY_BUFFER_ARB, aDiamsSize, aBallArray, GL_STATIC_DRAW_ARB);
1252 delete [] aBallArray;
1254 vglVertexAttribPointerARB( diamAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0 );
1255 vglEnableVertexAttribArrayARB( diamAttrib );
1258 glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize );
1260 if( this->BallEnabled ) {
1261 vglDisableVertexAttribArrayARB( diamAttrib );
1262 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
1263 vglDeleteBuffersARB( 1, &aDiamsID );
1266 vglDisableVertexAttribArrayARB( colorAttrib );
1267 vglDisableVertexAttribArrayARB( vertexAttrib );
1268 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
1269 vglDeleteBuffersARB( 1, &aBufferObjectID );
1270 vglBindVertexArrayARB( 0 );
1272 vglUseProgramObjectARB( 0 );
1274 GLuint aBufferObjectID, aDiamsID = 0;
1275 GLint attribute_diams = -1;
1277 vglGenBuffersARB( 1, &aBufferObjectID );
1278 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
1280 int anArrayObjectSize = sizeof( VTK::TVertex ) * aTotalConnectivitySize;
1281 vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB );
1283 delete [] aVertexArr;
1285 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
1286 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
1288 glColorPointer( 4, GL_FLOAT, sizeof(VTK::TVertex), (void*)0 );
1289 glVertexPointer( 3, GL_FLOAT, sizeof(VTK::TVertex), (void*)(4*sizeof(GLfloat)) );
1291 glEnableClientState( GL_VERTEX_ARRAY );
1292 glEnableClientState( GL_COLOR_ARRAY );
1294 if(this->BallEnabled) {
1295 vglGenBuffersARB( 2, &aDiamsID);
1296 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID);
1298 int aDiamsSize = sizeof(TBall)*aNbCells;
1299 vglBufferDataARB( GL_ARRAY_BUFFER_ARB, aDiamsSize, aBallArray, GL_STATIC_DRAW_ARB);
1301 delete [] aBallArray;
1302 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
1303 vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID );
1305 attribute_diams = vglGetAttribLocationARB(this->PointProgram, "diameter");
1306 vglEnableVertexAttribArrayARB(attribute_diams);
1307 vglBindBufferARB(GL_ARRAY_BUFFER_ARB, aDiamsID);
1308 vglVertexAttribPointerARB(
1309 attribute_diams, // attribute
1310 1, // number of elements per vertex, here (diameter)
1311 GL_FLOAT, // the type of each element
1312 GL_FALSE, // take our values as-is
1313 0, // no extra data between each position
1314 0 // offset of first element
1318 glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize );
1320 glDisableClientState( GL_COLOR_ARRAY );
1321 glDisableClientState( GL_VERTEX_ARRAY );
1322 vglDeleteBuffersARB( 1, &aBufferObjectID );
1324 if(this->BallEnabled) {
1325 vglDisableVertexAttribArrayARB(attribute_diams);
1326 vglDeleteBuffersARB( 2, &aDiamsID );
1330 } else { // there are no extensions
1331 glColorPointer( 4, GL_FLOAT, sizeof(VTK::TVertex), aVertexArr );
1332 glVertexPointer( 3, GL_FLOAT, sizeof(VTK::TVertex),
1333 (void*)((GLfloat*)((void*)(aVertexArr)) + 4));
1335 glEnableClientState( GL_VERTEX_ARRAY );
1336 glEnableClientState( GL_COLOR_ARRAY );
1338 glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize );
1340 glDisableClientState( GL_COLOR_ARRAY );
1341 glDisableClientState( GL_VERTEX_ARRAY );
1343 delete [] aVertexArr;
1348 this->UpdateProgress(1.0);