Salome HOME
Merge branch 'V9_2_2_BR'
[modules/gui.git] / src / VTKViewer / VTKViewer_PolyDataMapper.cxx
index 8071540037eae583e63a350f81af3887cded6407..1e91624cb1971b085e77232e80c9966399fc6f92 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -98,6 +98,21 @@ typedef GLfloat TBall;
 #define BallTextureId 0 
 
 
+
+void MessageCallback( GLenum source,
+                      GLenum type,
+                      GLuint id,
+                      GLenum severity,
+                      GLsizei length,
+                      const GLcharARB* message,
+                      const void* userParam )
+{
+  fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
+           ( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
+            type, severity, message );
+}
+
+
 //-----------------------------------------------------------------------------
 VTKViewer_PolyDataMapper::VTKViewer_PolyDataMapper()
 {
@@ -120,6 +135,11 @@ VTKViewer_PolyDataMapper::VTKViewer_PolyDataMapper()
 #endif
 
   this->OpenGLHelper.Init();
+
+  // For debug purposes only
+  // glEnable              ( GL_DEBUG_OUTPUT );
+  // glDebugMessageCallback( (GLDEBUGPROC) MessageCallback, 0 );
+
 }
 
 //-----------------------------------------------------------------------------
@@ -142,6 +162,8 @@ int VTKViewer_PolyDataMapper::InitShader()
     return false;
 
   // Get uniform locations.
+  GLint current_program;
+  glGetIntegerv( GL_CURRENT_PROGRAM, &current_program );
   this->OpenGLHelper.vglUseProgramObjectARB( this->PointProgram );
 
   this->myLocations.ModelViewProjection = this->OpenGLHelper.vglGetUniformLocationARB( this->PointProgram, "uModelViewProjectionMatrix" );
@@ -149,7 +171,7 @@ int VTKViewer_PolyDataMapper::InitShader()
   this->myLocations.GeneralPointSize    = this->OpenGLHelper.vglGetUniformLocationARB( this->PointProgram, "uGeneralPointSize" );
   this->myLocations.PointSprite         = this->OpenGLHelper.vglGetUniformLocationARB( this->PointProgram, "uPointSprite" );
 
-  this->OpenGLHelper.vglUseProgramObjectARB( 0 );
+  this->OpenGLHelper.vglUseProgramObjectARB( current_program );
 
   this->OpenGLHelper.vglGenVertexArraysARB(1, &this->VertexArrayObject);
 #else
@@ -265,7 +287,7 @@ void VTKViewer_PolyDataMapper::SetBallEnabled( bool theBallEnabled )
       
       QString anAlphaTexture = getenv( "GUI_ROOT_DIR" );
       anAlphaTexture.append( "/share/salome/resources/gui/sprite_alpha.vti" );
-      vtkSmartPointer<vtkImageData> aTextureValue = VTK::MakeTexture( aMainTexture.toLatin1().constData(), anAlphaTexture.toLatin1().constData() );
+      vtkSmartPointer<vtkImageData> aTextureValue = VTK::MakeTexture( aMainTexture.toUtf8().constData(), anAlphaTexture.toUtf8().constData() );
       this->SpecialTextures[BallTextureId] = aTextureValue;
     }
     this->ImageData = this->SpecialTextures[BallTextureId];
@@ -361,7 +383,7 @@ int VTKViewer_PolyDataMapper::InitExtensions()
   glGetIntegerv(GL_NUM_EXTENSIONS, &n);
   for (int i = 0; i < n; i++)
     {
-      const char *exti = (const char *)glGetStringi(GL_EXTENSIONS, i);
+      const char *exti = (const char *)this->OpenGLHelper.vglGetStringiARB(GL_EXTENSIONS, i);
       strm<< exti <<" ";
     }
   std::string s = strm.str();
@@ -425,7 +447,7 @@ void VTKViewer_PolyDataMapper::InitTextures()
     glGenTextures( 1, &this->PointSpriteTexture );
   }
 #ifdef VTK_OPENGL2
-  glActiveTexture( GL_TEXTURE0 );
+  this->OpenGLHelper.vglActiveTextureARB( GL_TEXTURE0 );
 #endif
   glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture );
   glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
@@ -501,7 +523,8 @@ void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act )
     // make sure our window is current
     ren->GetRenderWindow()->MakeCurrent();
 
-
+    GLint current_program;
+    glGetIntegerv( GL_CURRENT_PROGRAM, &current_program );
     this->OpenGLHelper.vglUseProgramObjectARB( this->PointProgram );
 
 #ifndef VTK_OPENGL2
@@ -583,7 +606,7 @@ void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act )
     //    this->RenderEdges(ren,act);
     //this->RenderPieceFinish(ren, act);
 #endif    
-    this->OpenGLHelper.vglUseProgramObjectARB( 0 );
+    this->OpenGLHelper.vglUseProgramObjectARB( current_program );
     this->CleanupPointSprites();
     glBindTexture( GL_TEXTURE_2D, 0 );
   }  
@@ -884,6 +907,8 @@ void VTKViewer_PolyDataMapper::InternalDraw(vtkRenderer* ren, vtkActor* act ) {
 
       if( this->ExtensionsInitialized == ES_Ok ) {
 #ifdef VTK_OPENGL2
+       GLint current_program;
+       glGetIntegerv( GL_CURRENT_PROGRAM, &current_program );
         this->OpenGLHelper.vglUseProgramObjectARB( this->PointProgram );
 
         vtkOpenGLCamera *cam = (vtkOpenGLCamera *)(ren->GetActiveCamera());
@@ -962,7 +987,7 @@ void VTKViewer_PolyDataMapper::InternalDraw(vtkRenderer* ren, vtkActor* act ) {
        this->OpenGLHelper.vglDeleteBuffersARB( 1, &aBufferObjectID );
        this->OpenGLHelper.vglBindVertexArrayARB( 0 );
 
-       this->OpenGLHelper.vglUseProgramObjectARB( 0 );
+       this->OpenGLHelper.vglUseProgramObjectARB( current_program );
 #else
        GLuint aBufferObjectID, aDiamsID = 0;
        GLint attribute_diams = -1;