From: ouv Date: Tue, 27 Sep 2005 08:27:07 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: BR-D5-38-2003_D2005-12-10~132 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d80a645ac198734b1ba2c380823a551d29332f23;p=modules%2Fvisu.git *** empty log message *** --- diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx index 75c74663..67267890 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx @@ -35,8 +35,6 @@ #include #include #include -#include -#include #include #include #include @@ -120,7 +118,7 @@ VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper() this->ExtensionsOK = 0; this->AlphaChannelArray = NULL; this->SizeChannelArray = NULL; - this->DefaultPointSize = 50.0; + this->DefaultPointSize = 30.0; this->QuadraticPointDistanceAttenuation[0] = 1.0; this->QuadraticPointDistanceAttenuation[1] = 0.0; this->QuadraticPointDistanceAttenuation[2] = 0.0; @@ -131,6 +129,10 @@ VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper() this->OpenGLLibrary = 0; #endif + this->UsePointSprites = true; + this->UseTextures = true; + this->UseShader = true; + this->PointSpriteClamp = 100.0; this->PointSpriteSize = 0.0; this->PointSpriteMinSize = 15.0; @@ -394,25 +396,28 @@ void VISU_OpenGLPointSpriteMapper::InitExtensions() */ #ifdef GL_ARB_shader_objects - //if( !VISU_OpenGLPointSpriteMapper::VertexProgram ) + if( this->UseShader ) { - this->OpenGLLibrary = dlopen( "libGL.so", RTLD_LAZY ); - VISU_OpenGLPointSpriteMapper::VertexProgram = this->InitShader(); - } + //if( !VISU_OpenGLPointSpriteMapper::VertexProgram ) + { + this->OpenGLLibrary = dlopen( "libGL.so", RTLD_LAZY ); + VISU_OpenGLPointSpriteMapper::VertexProgram = this->InitShader(); + } - PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = - (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glUseProgramObjectARB" ); - glUseProgramObjectARB( VISU_OpenGLPointSpriteMapper::VertexProgram ); - - this->SetShaderVariable( "attrib1", 1.0 ); - this->SetShaderVariable( "attrib2", 1.0 ); - this->SetShaderVariable( "attrib3", 1.0 ); - this->SetShaderVariable( "clamp", this->PointSpriteClamp ); - this->SetShaderVariable( "geomSize", this->PointSpriteSize ); - this->SetShaderVariable( "minSize", this->PointSpriteMinSize ); - this->SetShaderVariable( "attrib4", 1.0 ); - this->SetShaderVariable( "maxSize", this->PointSpriteMaxSize ); - this->SetShaderVariable( "magnification", this->PointSpriteMagnification ); + PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = + (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glUseProgramObjectARB" ); + glUseProgramObjectARB( VISU_OpenGLPointSpriteMapper::VertexProgram ); + + this->SetShaderVariable( "attrib1", 1.0 ); + this->SetShaderVariable( "attrib2", 1.0 ); + this->SetShaderVariable( "attrib3", 1.0 ); + this->SetShaderVariable( "clamp", this->PointSpriteClamp ); + this->SetShaderVariable( "geomSize", this->PointSpriteSize ); + this->SetShaderVariable( "minSize", this->PointSpriteMinSize ); + this->SetShaderVariable( "attrib4", 1.0 ); + this->SetShaderVariable( "maxSize", this->PointSpriteMaxSize ); + this->SetShaderVariable( "magnification", this->PointSpriteMagnification ); + } #endif this->ExtensionsOK = 1; @@ -441,121 +446,39 @@ void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) vtkIdType numPts; vtkPolyData *input= this->GetInput(); - vtkPlaneCollection *clipPlanes; - vtkPlane *plane; - int i, numClipPlanes; - double planeEquation[4]; // // make sure that we've been properly initialized // if (ren->GetRenderWindow()->CheckAbortStatus()) - { return; - } if ( input == NULL ) - { + { vtkErrorMacro(<< "No input!"); return; - } + } else - { + { this->InvokeEvent(vtkCommand::StartEvent,NULL); input->Update(); this->InvokeEvent(vtkCommand::EndEvent,NULL); numPts = input->GetNumberOfPoints(); - } + } if (numPts == 0) - { + { vtkDebugMacro(<< "No points!"); return; - } + } if ( this->LookupTable == NULL ) - { this->CreateDefaultLookupTable(); - } // make sure our window is current ren->GetRenderWindow()->MakeCurrent(); - // setup clippingplanes - clipPlanes = this->ClippingPlanes; - if (clipPlanes == NULL) - { - numClipPlanes = 0; - } - else - { - numClipPlanes = clipPlanes->GetNumberOfItems(); - if (numClipPlanes > 6) - { - vtkErrorMacro(<< "OpenGL guarantees at most 6 additional clipping planes"); - } - } - - for (i = 0; i < numClipPlanes; i++) - { - glEnable((GLenum)(GL_CLIP_PLANE0+i)); - } - - if ( clipPlanes ) - { - vtkMatrix4x4 *actorMatrix = vtkMatrix4x4::New(); - act->GetMatrix( actorMatrix ); - actorMatrix->Invert(); - - float origin[4], normal[3], point[4]; - - for (i = 0; i < numClipPlanes; i++) - { - plane = (vtkPlane *)clipPlanes->GetItemAsObject(i); - - plane->GetOrigin(origin); - plane->GetNormal(normal); - - point[0] = origin[0] + normal[0]; - point[1] = origin[1] + normal[1]; - point[2] = origin[2] + normal[2]; - - origin[3] = point[3] = 1.0; - - actorMatrix->MultiplyPoint( origin, origin ); - actorMatrix->MultiplyPoint( point, point ); - - if ( origin[3] != 1.0 ) - { - origin[0] /= origin[3]; - origin[1] /= origin[3]; - origin[2] /= origin[3]; - } - - if ( point[3] != 1.0 ) - { - point[0] /= point[3]; - point[1] /= point[3]; - point[2] /= point[3]; - } - - normal[0] = point[0] - origin[0]; - normal[1] = point[1] - origin[1]; - normal[2] = point[2] - origin[2]; - - planeEquation[0] = normal[0]; - planeEquation[1] = normal[1]; - planeEquation[2] = normal[2]; - planeEquation[3] = -(planeEquation[0]*origin[0]+ - planeEquation[1]*origin[1]+ - planeEquation[2]*origin[2]); - glClipPlane((GLenum)(GL_CLIP_PLANE0+i),planeEquation); - } - - actorMatrix->Delete(); - } - // For vertex coloring, this sets this->Colors as side effect. // Color arrays are cached. If nothing has changed, // then the scalars do not have to be regenerted. @@ -563,7 +486,8 @@ void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) this->MapScalars(this->ActorOpacity); // Initializing the texture for Point Sprites - this->InitTexture(); + if( this->UseTextures ) + this->InitTextures(); // // if something has changed regenerate colors and display lists @@ -574,10 +498,10 @@ void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) input->GetMTime() > this->BuildTime || act->GetProperty()->GetMTime() > this->BuildTime || ren->GetRenderWindow() != this->LastWindow) - { + { if (!this->ImmediateModeRendering && !this->GetGlobalImmediateModeRendering()) - { + { this->ReleaseGraphicsResources(ren->GetRenderWindow()); this->LastWindow = ren->GetRenderWindow(); @@ -592,56 +516,45 @@ void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) this->Timer->StartTimer(); glCallList(this->ListId); this->Timer->StopTimer(); - } + } else - { + { this->ReleaseGraphicsResources(ren->GetRenderWindow()); this->LastWindow = ren->GetRenderWindow(); - } + } if (noAbort) - { this->BuildTime.Modified(); - } - } + } // if nothing changed but we are using display lists, draw it else - { + { if (!this->ImmediateModeRendering && !this->GetGlobalImmediateModeRendering()) - { + { // Time the actual drawing this->Timer->StartTimer(); glCallList(this->ListId); this->Timer->StopTimer(); - } } + } // if we are in immediate mode rendering we always // want to draw the primitives here if (this->ImmediateModeRendering || this->GetGlobalImmediateModeRendering()) - { + { // Time the actual drawing this->Timer->StartTimer(); this->Draw(ren,act); 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 // time so that it is not zero if ( this->TimeToDraw == 0.0 ) - { this->TimeToDraw = 0.0001; - } - - for (i = 0; i < numClipPlanes; i++) - { - glDisable((GLenum)(GL_CLIP_PLANE0+i)); - } } //----------------------------------------------------------------------------- float VISU_OpenGLPointSpriteMapper::GetMaximumSupportedSize() @@ -652,7 +565,7 @@ float VISU_OpenGLPointSpriteMapper::GetMaximumSupportedSize() return maximumSupportedSize; } //----------------------------------------------------------------------------- -void VISU_OpenGLPointSpriteMapper::InitSprites() +void VISU_OpenGLPointSpriteMapper::InitPointSprites() { glEnable( GL_POINT_SPRITE_ARB ); glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB ); @@ -709,7 +622,7 @@ void VISU_OpenGLPointSpriteMapper::InitSprites() */ } //----------------------------------------------------------------------------- -void VISU_OpenGLPointSpriteMapper::CleanupSprites() +void VISU_OpenGLPointSpriteMapper::CleanupPointSprites() { // Set GL params back to normal to stop other vtkMappers diusplaying wrongly glEnable( GL_BLEND ); @@ -741,9 +654,9 @@ VISU_OpenGLPointSpriteMapper //----------------------------------------------------------------------------- -void VISU_OpenGLPointSpriteMapper::InitTexture() +void VISU_OpenGLPointSpriteMapper::InitTextures() { - //cout << "VISU_OpenGLPointSpriteMapper::InitTexture " << this->GetImageData() << endl; + //cout << "VISU_OpenGLPointSpriteMapper::InitTextures " << this->GetImageData() << endl; if( !this->GetImageData() ) return; @@ -757,7 +670,7 @@ void VISU_OpenGLPointSpriteMapper::InitTexture() glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aSize[0], aSize[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, dataPtr ); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glEnable( GL_TEXTURE_2D ); glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture ); @@ -775,8 +688,8 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, { //cout << "VISU_OpenGLPointSpriteMapper::DrawPoints" << endl; - this->InitSprites(); - //this->InitTexture(); + if( this->UsePointSprites ) + this->InitPointSprites(); glPointSize( this->DefaultPointSize ); @@ -828,26 +741,8 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, glDisableClientState(GL_VERTEX_ARRAY); #endif - /* - glBegin( GL_POINTS ); - - vtkIdType *pts = 0; - vtkIdType npts = 0; - unsigned short count = 0; - for( cells->InitTraversal(); cells->GetNextCell( npts, pts ); count++ ) - { - if (colors) - { - unsigned char *col = colors->GetPointer(pts[0]<< 2); - glColor4ubv(col); - } - - glVertex3fv(p->GetPoint(pts[0])); - - } - glEnd(); - */ - this->CleanupSprites(); + if( this->UsePointSprites ) + this->CleanupPointSprites(); } //----------------------------------------------------------------------------- @@ -939,7 +834,7 @@ int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *aren, vtkActor *act) void VISU_OpenGLPointSpriteMapper::ReleaseGraphicsResources(vtkWindow *win) { this->Superclass::ReleaseGraphicsResources(win); - /* + if (this->ListId && win) { win->MakeCurrent(); @@ -947,7 +842,6 @@ void VISU_OpenGLPointSpriteMapper::ReleaseGraphicsResources(vtkWindow *win) this->ListId = 0; } this->LastWindow = NULL; - */ } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::PrintSelf(ostream& os, vtkIndent indent) diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx index 3916ea45..ac975c68 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx @@ -133,14 +133,24 @@ public: // Draw method for OpenGL. virtual int Draw(vtkRenderer *ren, vtkActor *a); - // Description: - // Initializing texture for Point Sprites - void InitTexture(); - // Description: // Return the maximum point size supported by the graphics hardware. float GetMaximumSupportedSize(); + // Set/Get usage of Point Sprites + vtkSetMacro(UsePointSprites, bool); + vtkGetMacro(UsePointSprites, bool); + + // Set/Get usage of textures for Point Sprites + // (only if usage of Point Sprites is turned on) + vtkSetMacro(UseTextures, bool); + vtkGetMacro(UseTextures, bool); + + // Set/Get usage of vertex shader + // (only if usage of Point Sprites is turned on) + vtkSetMacro(UseShader, bool); + vtkGetMacro(UseShader, bool); + // Description: // Point Sprite size parameters vtkGetMacro(PointSpriteClamp, float); @@ -174,10 +184,20 @@ protected: vtkCellArray *ca, vtkRenderer *ren); + // Initializing OpenGL extensions void InitExtensions(); - void InitSprites(); - void CleanupSprites(); + // Activate/deactivate Point Sprites + void InitPointSprites(); + void CleanupPointSprites(); + + // Initializing textures for Point Sprites + void InitTextures(); + + bool UsePointSprites; + bool UseTextures; + bool UseShader; + vtkIdType TotalCells;