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 #ifndef VTKViewer_POLYDATAMAPPER_H
21 #define VTKViewer_POLYDATAMAPPER_H
23 #include "VTKViewer.h"
24 #include "VTKViewer_MarkerDef.h"
33 #include <OpenGL/gl.h>
38 #include <vtkSmartPointer.h>
42 #ifndef VTK_IMPLEMENT_MESA_CXX
43 #include <vtkOpenGLPolyDataMapper.h>
44 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
46 #include <vtkMesaPolyDataMapper.h>
47 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
50 #include "VTKViewer_OpenGLHelper.h"
52 //----------------------------------------------------------------------------
53 //! OpenGL Point Sprites PolyData Mapper.
55 * VTKViewer_PolyDataMapper is a class that maps polygonal data
56 * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
57 * to the rendering/graphics hardware/software. It is now possible to set a
58 * memory limit for the pipeline in the mapper. If the total estimated memory
59 * usage of the pipeline is larger than this limit, the mapper will divide
60 * the data into pieces and render each in a for loop.
62 class VTKVIEWER_EXPORT VTKViewer_PolyDataMapper : public MAPPER_SUPERCLASS
65 enum ExtensionsState { ES_None = 0, ES_Error, ES_Ok };
68 static VTKViewer_PolyDataMapper* New();
69 vtkTypeMacro( VTKViewer_PolyDataMapper, MAPPER_SUPERCLASS );
71 //! Set point marker enabled
72 void SetMarkerEnabled( bool );
74 //! Set point ball enabled
75 void SetBallEnabled( bool );
77 bool GetBallEnabled( );
79 //! Set ball scale factor
80 void SetBallScale( double );
82 double GetBallScale( );
84 //! Set standard point marker
85 void SetMarkerStd( VTK::MarkerType, VTK::MarkerScale );
87 //! Set custom point marker
88 void SetMarkerTexture( int, VTK::MarkerTexture );
90 //! Get type of the point marker
91 VTK::MarkerType GetMarkerType();
93 //! Get scale of the point marker
94 VTK::MarkerScale GetMarkerScale();
96 //! Get texture identifier of the point marker
97 int GetMarkerTexture();
99 //! Implement superclass render method.
100 virtual void RenderPiece( vtkRenderer*, vtkActor* );
101 //! Draw method for OpenGL.
103 virtual int Draw( vtkRenderer*, vtkActor* );
105 virtual void RenderPieceDraw( vtkRenderer*, vtkActor* );
109 VTKViewer_PolyDataMapper();
110 ~VTKViewer_PolyDataMapper();
112 //! Initializing OpenGL extensions.
113 int InitExtensions();
115 //! Activate Point Sprites.
116 void InitPointSprites();
118 //! Deactivate Point Sprites.
119 void CleanupPointSprites();
121 //! Initializing textures for Point Sprites.
124 //! Initializing of the Vertex Shader.
127 void InternalDraw(vtkRenderer*, vtkActor*);
130 int ExtensionsInitialized;
132 GLuint PointSpriteTexture;
134 vtkSmartPointer<vtkImageData> ImageData;
136 VTKViewer_OpenGLHelper OpenGLHelper;
137 GLhandleARB PointProgram;
139 GLhandleARB VertexShader;
140 GLhandleARB FragmentShader;
141 GLuint VertexArrayObject;
145 static const GLint INVALID_LOCATION = -1;
147 GLint ModelViewProjection;
149 GLint GeneralPointSize;
153 : ModelViewProjection (INVALID_LOCATION),
154 Projection (INVALID_LOCATION),
155 GeneralPointSize (INVALID_LOCATION),
156 PointSprite (INVALID_LOCATION)
165 VTK::MarkerType MarkerType;
166 VTK::MarkerScale MarkerScale;
169 typedef std::map< int, vtkSmartPointer<vtkImageData> > ImageDataMap;
170 ImageDataMap StandardTextures;
171 ImageDataMap CustomTextures;
172 ImageDataMap SpecialTextures; //special predefined textures, used to draw point sprites.