Salome HOME
Update copyright information
[modules/visu.git] / src / PIPELINE / VISU_OpenGLPointSpriteMapper.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
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 #ifdef WIN32
36 #include <windows.h>
37 #endif
38
39 #include <GL/gl.h>
40
41 #include <vtkSmartPointer.h>
42 #include <vtkConfigure.h>
43
44 #include "VTKViewer.h"
45
46 class vtkCellArray;
47 class vtkPoints;
48 class vtkProperty;
49 class vtkImageData;
50 class vtkXMLImageDataReader;
51
52 #ifndef VTK_IMPLEMENT_MESA_CXX
53 #include <vtkOpenGLPolyDataMapper.h>
54 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
55 #else
56 #include <vtkMesaPolyDataMapper.h>
57 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
58 #endif
59
60 #ifndef GL_ARB_shader_objects
61 typedef GLuint GLhandleARB;
62 #endif
63
64 #include "VISUPipeline.hxx"
65
66 //----------------------------------------------------------------------------
67 //! OpenGL Point Sprites PolyData Mapper.
68 /*!
69  * VISU_OpenGLPointSpriteMapper is a class that maps polygonal data 
70  * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
71  * to the rendering/graphics hardware/software. It is now possible to set a 
72  * memory limit for the pipeline in the mapper. If the total estimated memory 
73  * usage of the pipeline is larger than this limit, the mapper will divide 
74  * the data into pieces and render each in a for loop.
75  */
76 class VISU_PIPELINE_EXPORT VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS
77 {
78 public:
79   //! The Point Sprites rendering mode.
80   /*!
81    * Accumulate : Uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), and no depth testing
82    * so that points are accumulated. Suitable for Galaxy plots.
83    * Occlude : No blending. Particles are solid spheres and depth testing is
84    * used as usual. Suitable for most particle simulations without the need
85    * for opacity.
86    */
87   enum RenderModes { Accumulate = 0, Occlude };
88
89   enum PrimitiveTypes { PointSprite = 0, OpenGLPoint, GeomSphere };
90
91   static VISU_OpenGLPointSpriteMapper *New();
92   vtkTypeRevisionMacro(VISU_OpenGLPointSpriteMapper,MAPPER_SUPERCLASS);
93
94   //! Set the initial point size to be used.
95   /*!
96    * This value forms the base upon which the distance attenuation acts.
97    * Usually the pointsize is set to the maximum supported by the graphics
98    * card for sprite display, then the quadratic factors are adjusted to
99    * bring the size down.
100    */
101   //! Get the initial point size to be used.
102   vtkGetMacro(DefaultPointSize, float);
103
104   //! Set Average Cell Size.
105   void
106   SetAverageCellSize(float theSize);
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 Point Sprite Opacity
211   vtkSetMacro(PointSpriteOpacity, float);
212
213   //! Get Point Sprite Opacity
214   vtkGetMacro(PointSpriteOpacity, float);
215
216   //! Set ImageData for Point Sprite Texture.
217   void SetImageData(vtkImageData* theImageData);
218
219   //! Get ImageData for Point Sprite Texture.
220   vtkImageData* GetImageData();
221
222 protected:
223   VISU_OpenGLPointSpriteMapper();
224   ~VISU_OpenGLPointSpriteMapper();
225
226   //! Initializing OpenGL extensions.
227   bool              InitExtensions();
228
229   //! Activate Point Sprites.
230   void              InitPointSprites();
231
232   //! Deactivate Point Sprites.
233   void              CleanupPointSprites();
234
235   //! Initializing textures for Point Sprites.
236   void              InitTextures();
237
238   //! Initializing of the Vertex Shader.
239   void              InitShader();
240
241   //! Set Vertex Shader variable.
242   void              SetShaderVariable( const char* variable, float value );
243
244   //! Getting information about Vertex Shader compiling and linking.
245   void              PrintInfoLog( GLhandleARB );
246
247 private:
248   bool              UseOpenGLMapper;
249
250   bool              UsePointSprites;
251   bool              UseTextures;
252   bool              UseShader;
253
254   int               RenderMode;
255   int               ListId;
256   vtkIdType         TotalCells;
257   int               ExtensionsInitialized;
258   float             DefaultPointSize;
259
260   GLhandleARB       VertexProgram;
261
262   int               PrimitiveType;
263
264   int               PointSpriteMode;
265
266   float             PointSpriteClamp;
267   float             PointSpriteSize;
268   float             PointSpriteMinSize;
269   float             PointSpriteMaxSize;
270   float             PointSpriteMagnification;
271
272   GLuint            PointSpriteTexture;
273   float             PointSpriteAlphaThreshold;
274   float             PointSpriteOpacity;
275
276   float             AverageCellSize;
277
278   vtkSmartPointer<vtkImageData> ImageData;
279 };
280
281 #endif