Salome HOME
94fa3b2311e831f6e890a9aaee400f334a2c46a6
[modules/visu.git] / src / PIPELINE / VISU_OpenGLPointSpriteMapper.hxx
1 //  Copyright (C) 2007-2008  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 //  VISU OBJECT : interactive object for VISU entities implementation
23 // File:    VISU_OpenGLPointSpriteMapper.hxx
24 // Author:  
25 // Module : VISU
26 //
27 #ifndef VISU_OpenGLPointSpriteMapper_HeaderFile
28 #define VISU_OpenGLPointSpriteMapper_HeaderFile
29
30 #if defined(_MSC_VER)
31 # pragma warning ( disable : 4275 )
32 #endif
33
34 #ifdef WIN32
35 #include <windows.h>
36 #endif
37
38 #include <GL/gl.h>
39
40 #include <vtkSmartPointer.h>
41 #include <vtkConfigure.h>
42
43 #include "VTKViewer.h"
44
45 class vtkCellArray;
46 class vtkPoints;
47 class vtkProperty;
48 class vtkImageData;
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 #include "VISUPipeline.hxx"
64
65 //----------------------------------------------------------------------------
66 //! OpenGL Point Sprites PolyData Mapper.
67 /*!
68  * VISU_OpenGLPointSpriteMapper is a class that maps polygonal data 
69  * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
70  * to the rendering/graphics hardware/software. It is now possible to set a 
71  * memory limit for the pipeline in the mapper. If the total estimated memory 
72  * usage of the pipeline is larger than this limit, the mapper will divide 
73  * the data into pieces and render each in a for loop.
74  */
75 class VISU_PIPELINE_EXPORT VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS
76 {
77 public:
78   //! The Point Sprites rendering mode.
79   /*!
80    * Accumulate : Uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), and no depth testing
81    * so that points are accumulated. Suitable for Galaxy plots.
82    * Occlude : No blending. Particles are solid spheres and depth testing is
83    * used as usual. Suitable for most particle simulations without the need
84    * for opacity.
85    */
86   enum RenderModes { Accumulate = 0, Occlude };
87
88   enum PrimitiveTypes { PointSprite = 0, OpenGLPoint, GeomSphere };
89
90   static VISU_OpenGLPointSpriteMapper *New();
91   vtkTypeRevisionMacro(VISU_OpenGLPointSpriteMapper,MAPPER_SUPERCLASS);
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   //! Get the initial point size to be used.
101   vtkGetMacro(DefaultPointSize, float);
102
103   //! Set Average Cell Size.
104   void
105   SetAverageCellSize(float theSize);
106
107   //! Get Average Cell Size.
108   vtkGetMacro(AverageCellSize, float);
109
110   //! Set the Render Mode for the mapper.
111   vtkSetMacro(RenderMode, int);
112
113   //! Get the Render Mode for the mapper.
114   vtkGetMacro(RenderMode, int);
115
116   //! Implement superclass render method.
117   virtual void RenderPiece(vtkRenderer *ren, vtkActor *a);
118
119   //! Release any graphics resources that are being consumed by this mapper.
120   void ReleaseGraphicsResources(vtkWindow *);
121
122   //! Draw method for OpenGL.
123   virtual int Draw(vtkRenderer *ren, vtkActor *a);
124
125   //! Return the maximum point size supported by the graphics hardware.
126   static float GetMaximumSupportedSize();
127
128   //! Set usage of #vtkOpenGLPolyDataMapper.
129   /*!
130    * This flags prevents using of the VISU_OpenGLPointSpriteMapper
131    * (#vtkOpenGLPolyDataMapper is using instead).
132    */
133   vtkSetMacro(UseOpenGLMapper, bool);
134
135   //! Get usage of #vtkOpenGLPolyDataMapper.
136   vtkGetMacro(UseOpenGLMapper, bool);
137
138   //! Set usage of Point Sprites.
139   vtkSetMacro(UsePointSprites, bool);
140
141   //! Get usage of Point Sprites.
142   vtkGetMacro(UsePointSprites, bool);
143
144   //! Set usage of textures for Point Sprites.
145   /*! Works only if usage of Point Sprites is turned on. */
146   vtkSetMacro(UseTextures, bool);
147
148   //! Get usage of textures for Point Sprites.
149   vtkGetMacro(UseTextures, bool);
150
151   //! Set usage of vertex shader.
152   /*! Works only if usage of Point Sprites is turned on. */
153   vtkSetMacro(UseShader, bool);
154
155   //! Get usage of vertex shader.
156   vtkGetMacro(UseShader, bool);
157
158   //! Point Sprite drawing mode
159   /*!
160    * 0 - Results  - different colors, different sizes.
161    * 1 - Geometry - fixed color, fixed size.
162    * 2 - Outside  - different colors, fixed size.
163    */
164   vtkGetMacro(PointSpriteMode, int);
165   void SetPointSpriteMode( int );
166
167   //! Get the Primitive type
168   vtkGetMacro(PrimitiveType, int);
169
170   //! Set the Primitive type
171   void SetPrimitiveType( int );
172
173   //! Set Point Sprite Clamp.
174   void SetPointSpriteClamp( float );
175
176   //! Get Point Sprite Clamp.
177   vtkGetMacro(PointSpriteClamp, float);
178
179   //! Set Point Sprite Const Size.
180   void SetPointSpriteSize( float );
181
182   //! Get Point Sprite Const Size.
183   vtkGetMacro(PointSpriteSize, float);
184
185   //! Set Point Sprite Minimum Size.
186   void SetPointSpriteMinSize( float );
187
188   //! Get Point Sprite Minimum Size.
189   vtkGetMacro(PointSpriteMinSize, float);
190
191   //! Set Point Sprite Maximum Size.
192   void SetPointSpriteMaxSize( float );
193
194   //! Get Point Sprite Maximum Size.
195   vtkGetMacro(PointSpriteMaxSize, float);
196
197   //! Set Point Sprite Magnification.
198   void SetPointSpriteMagnification( float );
199
200   //! Get Point Sprite Magnification.
201   vtkGetMacro(PointSpriteMagnification, float);
202
203   //! Set Point Sprite AlphaThreshold.
204   void SetPointSpriteAlphaThreshold( float );
205
206   //! Get Point Sprite AlphaThreshold.
207   vtkGetMacro(PointSpriteAlphaThreshold, float);
208
209   //! Set Point Sprite Opacity
210   vtkSetMacro(PointSpriteOpacity, float);
211
212   //! Get Point Sprite Opacity
213   vtkGetMacro(PointSpriteOpacity, float);
214
215   //! Set ImageData for Point Sprite Texture.
216   void SetImageData(vtkImageData* theImageData);
217
218   //! Get ImageData for Point Sprite Texture.
219   vtkImageData* GetImageData();
220
221 protected:
222   VISU_OpenGLPointSpriteMapper();
223   ~VISU_OpenGLPointSpriteMapper();
224
225   //! Initializing OpenGL extensions.
226   bool              InitExtensions();
227
228   //! Activate Point Sprites.
229   void              InitPointSprites();
230
231   //! Deactivate Point Sprites.
232   void              CleanupPointSprites();
233
234   //! Initializing textures for Point Sprites.
235   void              InitTextures();
236
237   //! Initializing of the Vertex Shader.
238   void              InitShader();
239
240   //! Set Vertex Shader variable.
241   void              SetShaderVariable( const char* variable, float value );
242
243   //! Getting information about Vertex Shader compiling and linking.
244   void              PrintInfoLog( GLhandleARB );
245
246 private:
247   bool              UseOpenGLMapper;
248
249   bool              UsePointSprites;
250   bool              UseTextures;
251   bool              UseShader;
252
253   int               RenderMode;
254   int               ListId;
255   vtkIdType         TotalCells;
256   int               ExtensionsInitialized;
257   float             DefaultPointSize;
258
259   GLhandleARB       VertexProgram;
260
261   int               PrimitiveType;
262
263   int               PointSpriteMode;
264
265   float             PointSpriteClamp;
266   float             PointSpriteSize;
267   float             PointSpriteMinSize;
268   float             PointSpriteMaxSize;
269   float             PointSpriteMagnification;
270
271   GLuint            PointSpriteTexture;
272   float             PointSpriteAlphaThreshold;
273   float             PointSpriteOpacity;
274
275   float             AverageCellSize;
276
277   vtkSmartPointer<vtkImageData> ImageData;
278 };
279
280 #endif