Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / PIPELINE / VISU_OpenGLPointSpriteMapper.hxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 // File:    VISU_OpenGLPointSpriteMapper.hxx
25 // Author:  
26 // Module : VISU
27
28 #ifndef VISU_OpenGLPointSpriteMapper_HeaderFile
29 #define VISU_OpenGLPointSpriteMapper_HeaderFile
30
31 #if defined(_MSC_VER)
32 # pragma warning ( disable : 4275 )
33 #endif
34
35 #include <GL/gl.h>
36
37 #include <vtkSmartPointer.h>
38 #include <vtkConfigure.h>
39
40 class vtkCellArray;
41 class vtkPoints;
42 class vtkProperty;
43 class vtkRenderWindow;
44 class vtkOpenGLRenderer;
45 class vtkOpenGLTexture;
46 class vtkBMPReader;
47 class vtkImageData;
48 class vtkFloatArray;
49 class vtkXMLImageDataReader;
50
51 #ifndef VTK_IMPLEMENT_MESA_CXX
52 #include <vtkOpenGLPolyDataMapper.h>
53 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
54 #else
55 #include <vtkMesaPolyDataMapper.h>
56 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
57 #endif
58
59 #ifndef GL_ARB_shader_objects
60 typedef GLuint GLhandleARB;
61 #endif
62
63 //----------------------------------------------------------------------------
64 //! OpenGL Point Sprites PolyData Mapper.
65 /*!
66  * VISU_OpenGLPointSpriteMapper is a class that maps polygonal data 
67  * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
68  * to the rendering/graphics hardware/software. It is now possible to set a 
69  * memory limit for the pipeline in the mapper. If the total estimated memory 
70  * usage of the pipeline is larger than this limit, the mapper will divide 
71  * the data into pieces and render each in a for loop.
72  */
73 class VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS
74 {
75 public:
76   //! The Point Sprites rendering mode.
77   /*!
78    * Accumulate : Uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), and no depth testing
79    * so that points are accumulated. Suitable for Galaxy plots.
80    * Occlude : No blending. Particles are solid spheres and depth testing is
81    * used as usual. Suitable for most particle simulations without the need
82    * for opacity.
83    */
84   enum RenderModes { Accumulate = 0, Occlude };
85
86   enum PrimitiveTypes { PointSprite = 0, OpenGLPoint, GeomSphere };
87
88   static VISU_OpenGLPointSpriteMapper *New();
89   vtkTypeRevisionMacro(VISU_OpenGLPointSpriteMapper,MAPPER_SUPERCLASS);
90
91   void ShallowCopy(vtkAbstractMapper*);
92
93   //! Set the initial point size to be used.
94   /*!
95    * This value forms the base upon which the distance attenuation acts.
96    * Usually the pointsize is set to the maximum supported by the graphics
97    * card for sprite display, then the quadratic factors are adjusted to
98    * bring the size down.
99    */
100   vtkSetMacro(DefaultPointSize, float);
101
102   //! Get the initial point size to be used.
103   vtkGetMacro(DefaultPointSize, float);
104
105   //! Set Average Cell Size.
106   vtkSetMacro(AverageCellSize, float);
107
108   //! Get Average Cell Size.
109   vtkGetMacro(AverageCellSize, float);
110
111   //! Set the Render Mode for the mapper.
112   vtkSetMacro(RenderMode, int);
113
114   //! Get the Render Mode for the mapper.
115   vtkGetMacro(RenderMode, int);
116
117   //! Implement superclass render method.
118   virtual void RenderPiece(vtkRenderer *ren, vtkActor *a);
119
120   //! Release any graphics resources that are being consumed by this mapper.
121   void ReleaseGraphicsResources(vtkWindow *);
122
123   //! Draw method for OpenGL.
124   virtual int Draw(vtkRenderer *ren, vtkActor *a);
125
126   //! Return the maximum point size supported by the graphics hardware.
127   static float GetMaximumSupportedSize();
128
129   //! Set usage of #vtkOpenGLPolyDataMapper.
130   /*!
131    * This flags prevents using of the VISU_OpenGLPointSpriteMapper
132    * (#vtkOpenGLPolyDataMapper is using instead).
133    */
134   vtkSetMacro(UseOpenGLMapper, bool);
135
136   //! Get usage of #vtkOpenGLPolyDataMapper.
137   vtkGetMacro(UseOpenGLMapper, bool);
138
139   //! Set usage of Point Sprites.
140   vtkSetMacro(UsePointSprites, bool);
141
142   //! Get usage of Point Sprites.
143   vtkGetMacro(UsePointSprites, bool);
144
145   //! Set usage of textures for Point Sprites.
146   /*! Works only if usage of Point Sprites is turned on. */
147   vtkSetMacro(UseTextures, bool);
148
149   //! Get usage of textures for Point Sprites.
150   vtkGetMacro(UseTextures, bool);
151
152   //! Set usage of vertex shader.
153   /*! Works only if usage of Point Sprites is turned on. */
154   vtkSetMacro(UseShader, bool);
155
156   //! Get usage of vertex shader.
157   vtkGetMacro(UseShader, bool);
158
159   //! Point Sprite drawing mode
160   /*!
161    * 0 - Results  - different colors, different sizes.
162    * 1 - Geometry - fixed color, fixed size.
163    * 2 - Outside  - different colors, fixed size.
164    */
165   vtkGetMacro(PointSpriteMode, int);
166   void SetPointSpriteMode( int );
167
168   //! Get the Primitive type
169   vtkGetMacro(PrimitiveType, int);
170
171   //! Set the Primitive type
172   void SetPrimitiveType( int );
173
174   //! Set Point Sprite Clamp.
175   void SetPointSpriteClamp( float );
176
177   //! Get Point Sprite Clamp.
178   vtkGetMacro(PointSpriteClamp, float);
179
180   //! Set Point Sprite Const Size.
181   void SetPointSpriteSize( float );
182
183   //! Get Point Sprite Const Size.
184   vtkGetMacro(PointSpriteSize, float);
185
186   //! Set Point Sprite Minimum Size.
187   void SetPointSpriteMinSize( float );
188
189   //! Get Point Sprite Minimum Size.
190   vtkGetMacro(PointSpriteMinSize, float);
191
192   //! Set Point Sprite Maximum Size.
193   void SetPointSpriteMaxSize( float );
194
195   //! Get Point Sprite Maximum Size.
196   vtkGetMacro(PointSpriteMaxSize, float);
197
198   //! Set Point Sprite Magnification.
199   void SetPointSpriteMagnification( float );
200
201   //! Get Point Sprite Magnification.
202   vtkGetMacro(PointSpriteMagnification, float);
203
204   //! Set Point Sprite AlphaThreshold.
205   void SetPointSpriteAlphaThreshold( float );
206
207   //! Get Point Sprite AlphaThreshold.
208   vtkGetMacro(PointSpriteAlphaThreshold, float);
209
210   //! Set ImageData for Point Sprite Texture.
211   void SetImageData(vtkImageData* theImageData);
212
213   //! Get ImageData for Point Sprite Texture.
214   vtkImageData* GetImageData();
215
216 protected:
217   VISU_OpenGLPointSpriteMapper();
218   ~VISU_OpenGLPointSpriteMapper();
219
220   //! Internal method of the Point Sprites drawing.
221   void              DrawPoints(vtkPoints *p,
222                                vtkUnsignedCharArray *c,
223                                vtkFloatArray *alpha,
224                                vtkIdType &cellNum,
225                                int &noAbort,
226                                vtkCellArray *ca,
227                                vtkRenderer *ren,
228                                vtkActor *act);
229
230   //! Initializing OpenGL extensions.
231   bool              InitExtensions();
232
233   //! Activate Point Sprites.
234   void              InitPointSprites();
235
236   //! Deactivate Point Sprites.
237   void              CleanupPointSprites();
238
239   //! Initializing textures for Point Sprites.
240   void              InitTextures();
241
242   //! Initializing of the Vertex Shader.
243   void              InitShader();
244
245   //! Set Vertex Shader variable.
246   void              SetShaderVariable( const char* variable, float value );
247
248   //! Getting information about Vertex Shader compiling and linking.
249   void              PrintInfoLog( GLhandleARB );
250
251 private:
252   bool              UseOpenGLMapper;
253
254   bool              UsePointSprites;
255   bool              UseTextures;
256   bool              UseShader;
257
258   int               RenderMode;
259   int               ListId;
260   vtkIdType         TotalCells;
261   int               ExtensionsInitialized;
262   float             DefaultPointSize;
263
264   GLhandleARB       VertexProgram;
265
266   int               PrimitiveType;
267
268   int               PointSpriteMode;
269
270   float             PointSpriteClamp;
271   float             PointSpriteSize;
272   float             PointSpriteMinSize;
273   float             PointSpriteMaxSize;
274   float             PointSpriteMagnification;
275
276   GLuint            PointSpriteTexture;
277   float             PointSpriteAlphaThreshold;
278
279   float             AverageCellSize;
280
281   vtkSmartPointer<vtkImageData> ImageData;
282   vtkPolyDataMapper* TempMapper;
283 };
284
285 #endif