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"
34 #include <vtkSmartPointer.h>
38 #ifndef VTK_IMPLEMENT_MESA_CXX
39 #include <vtkOpenGLPolyDataMapper.h>
40 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
42 #include <vtkMesaPolyDataMapper.h>
43 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
46 #include "VTKViewer_OpenGLHelper.h"
48 //----------------------------------------------------------------------------
49 //! OpenGL Point Sprites PolyData Mapper.
51 * VTKViewer_PolyDataMapper is a class that maps polygonal data
52 * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
53 * to the rendering/graphics hardware/software. It is now possible to set a
54 * memory limit for the pipeline in the mapper. If the total estimated memory
55 * usage of the pipeline is larger than this limit, the mapper will divide
56 * the data into pieces and render each in a for loop.
58 class VTKVIEWER_EXPORT VTKViewer_PolyDataMapper : public MAPPER_SUPERCLASS
61 enum ExtensionsState { ES_None = 0, ES_Error, ES_Ok };
64 static VTKViewer_PolyDataMapper* New();
65 vtkTypeMacro( VTKViewer_PolyDataMapper, MAPPER_SUPERCLASS );
67 //! Set point marker enabled
68 void SetMarkerEnabled( bool );
70 //! Set point ball enabled
71 void SetBallEnabled( bool );
73 bool GetBallEnabled( );
75 //! Set ball scale factor
76 void SetBallScale( double );
78 double GetBallScale( );
80 //! Set standard point marker
81 void SetMarkerStd( VTK::MarkerType, VTK::MarkerScale );
83 //! Set custom point marker
84 void SetMarkerTexture( int, VTK::MarkerTexture );
86 //! Get type of the point marker
87 VTK::MarkerType GetMarkerType();
89 //! Get scale of the point marker
90 VTK::MarkerScale GetMarkerScale();
92 //! Get texture identifier of the point marker
93 int GetMarkerTexture();
95 //! Implement superclass render method.
96 virtual void RenderPiece( vtkRenderer*, vtkActor* );
97 //! Draw method for OpenGL.
99 virtual int Draw( vtkRenderer*, vtkActor* );
101 virtual void RenderPieceDraw( vtkRenderer*, vtkActor* );
105 VTKViewer_PolyDataMapper();
106 ~VTKViewer_PolyDataMapper();
108 //! Initializing OpenGL extensions.
109 int InitExtensions();
111 //! Activate Point Sprites.
112 void InitPointSprites();
114 //! Deactivate Point Sprites.
115 void CleanupPointSprites();
117 //! Initializing textures for Point Sprites.
120 //! Initializing of the Vertex Shader.
123 void InternalDraw(vtkRenderer*, vtkActor*);
126 int ExtensionsInitialized;
128 GLuint PointSpriteTexture;
130 vtkSmartPointer<vtkImageData> ImageData;
132 VTKViewer_OpenGLHelper OpenGLHelper;
133 GLhandleARB PointProgram;
135 GLhandleARB VertexShader;
136 GLhandleARB FragmentShader;
137 GLuint VertexArrayObject;
141 static const GLint INVALID_LOCATION = -1;
143 GLint ModelViewProjection;
145 GLint GeneralPointSize;
149 : ModelViewProjection (INVALID_LOCATION),
150 Projection (INVALID_LOCATION),
151 GeneralPointSize (INVALID_LOCATION),
152 PointSprite (INVALID_LOCATION)
161 VTK::MarkerType MarkerType;
162 VTK::MarkerScale MarkerScale;
165 typedef std::map< int, vtkSmartPointer<vtkImageData> > ImageDataMap;
166 ImageDataMap StandardTextures;
167 ImageDataMap CustomTextures;
168 ImageDataMap SpecialTextures; //special predefined textures, used to draw point sprites.