]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 #include "VTKViewer.h"
41
42 class vtkCellArray;
43 class vtkPoints;
44 class vtkProperty;
45 class vtkRenderWindow;
46 class vtkOpenGLRenderer;
47 class vtkOpenGLTexture;
48 class vtkBMPReader;
49 class vtkImageData;
50 class vtkFloatArray;
51 class vtkXMLImageDataReader;
52
53 #ifndef VTK_IMPLEMENT_MESA_CXX
54 #include <vtkOpenGLPolyDataMapper.h>
55 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
56 #else
57 #include <vtkMesaPolyDataMapper.h>
58 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
59 #endif
60
61 #ifndef GL_ARB_shader_objects
62 typedef GLuint GLhandleARB;
63 #endif
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_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   void ShallowCopy(vtkAbstractMapper*);
94
95   //! Set the initial point size to be used.
96   /*!
97    * This value forms the base upon which the distance attenuation acts.
98    * Usually the pointsize is set to the maximum supported by the graphics
99    * card for sprite display, then the quadratic factors are adjusted to
100    * bring the size down.
101    */
102   vtkSetMacro(DefaultPointSize, float);
103
104   //! Get the initial point size to be used.
105   vtkGetMacro(DefaultPointSize, float);
106
107   //! Set Average Cell Size.
108   vtkSetMacro(AverageCellSize, float);
109
110   //! Get Average Cell Size.
111   vtkGetMacro(AverageCellSize, float);
112
113   //! Set the Render Mode for the mapper.
114   vtkSetMacro(RenderMode, int);
115
116   //! Get the Render Mode for the mapper.
117   vtkGetMacro(RenderMode, int);
118
119   //! Implement superclass render method.
120   virtual void RenderPiece(vtkRenderer *ren, vtkActor *a);
121
122   //! Release any graphics resources that are being consumed by this mapper.
123   void ReleaseGraphicsResources(vtkWindow *);
124
125   //! Draw method for OpenGL.
126   virtual int Draw(vtkRenderer *ren, vtkActor *a);
127
128   //! Return the maximum point size supported by the graphics hardware.
129   static float GetMaximumSupportedSize();
130
131   //! Set usage of #vtkOpenGLPolyDataMapper.
132   /*!
133    * This flags prevents using of the VISU_OpenGLPointSpriteMapper
134    * (#vtkOpenGLPolyDataMapper is using instead).
135    */
136   vtkSetMacro(UseOpenGLMapper, bool);
137
138   //! Get usage of #vtkOpenGLPolyDataMapper.
139   vtkGetMacro(UseOpenGLMapper, bool);
140
141   //! Set usage of Point Sprites.
142   vtkSetMacro(UsePointSprites, bool);
143
144   //! Get usage of Point Sprites.
145   vtkGetMacro(UsePointSprites, bool);
146
147   //! Set usage of textures for Point Sprites.
148   /*! Works only if usage of Point Sprites is turned on. */
149   vtkSetMacro(UseTextures, bool);
150
151   //! Get usage of textures for Point Sprites.
152   vtkGetMacro(UseTextures, bool);
153
154   //! Set usage of vertex shader.
155   /*! Works only if usage of Point Sprites is turned on. */
156   vtkSetMacro(UseShader, bool);
157
158   //! Get usage of vertex shader.
159   vtkGetMacro(UseShader, bool);
160
161   //! Point Sprite drawing mode
162   /*!
163    * 0 - Results  - different colors, different sizes.
164    * 1 - Geometry - fixed color, fixed size.
165    * 2 - Outside  - different colors, fixed size.
166    */
167   vtkGetMacro(PointSpriteMode, int);
168   void SetPointSpriteMode( int );
169
170   //! Get the Primitive type
171   vtkGetMacro(PrimitiveType, int);
172
173   //! Set the Primitive type
174   void SetPrimitiveType( int );
175
176   //! Set Point Sprite Clamp.
177   void SetPointSpriteClamp( float );
178
179   //! Get Point Sprite Clamp.
180   vtkGetMacro(PointSpriteClamp, float);
181
182   //! Set Point Sprite Const Size.
183   void SetPointSpriteSize( float );
184
185   //! Get Point Sprite Const Size.
186   vtkGetMacro(PointSpriteSize, float);
187
188   //! Set Point Sprite Minimum Size.
189   void SetPointSpriteMinSize( float );
190
191   //! Get Point Sprite Minimum Size.
192   vtkGetMacro(PointSpriteMinSize, float);
193
194   //! Set Point Sprite Maximum Size.
195   void SetPointSpriteMaxSize( float );
196
197   //! Get Point Sprite Maximum Size.
198   vtkGetMacro(PointSpriteMaxSize, float);
199
200   //! Set Point Sprite Magnification.
201   void SetPointSpriteMagnification( float );
202
203   //! Get Point Sprite Magnification.
204   vtkGetMacro(PointSpriteMagnification, float);
205
206   //! Set Point Sprite AlphaThreshold.
207   void SetPointSpriteAlphaThreshold( float );
208
209   //! Get Point Sprite AlphaThreshold.
210   vtkGetMacro(PointSpriteAlphaThreshold, float);
211
212   //! Set ImageData for Point Sprite Texture.
213   void SetImageData(vtkImageData* theImageData);
214
215   //! Get ImageData for Point Sprite Texture.
216   vtkImageData* GetImageData();
217
218 protected:
219   VISU_OpenGLPointSpriteMapper();
220   ~VISU_OpenGLPointSpriteMapper();
221
222   //! Internal method of the Point Sprites drawing.
223   void              DrawPoints(vtkPoints *p,
224                                vtkUnsignedCharArray *c,
225                                vtkFloatArray *alpha,
226                                vtkIdType &cellNum,
227                                int &noAbort,
228                                vtkCellArray *ca,
229                                vtkRenderer *ren,
230                                vtkActor *act);
231
232   //! Initializing OpenGL extensions.
233   bool              InitExtensions();
234
235   //! Activate Point Sprites.
236   void              InitPointSprites();
237
238   //! Deactivate Point Sprites.
239   void              CleanupPointSprites();
240
241   //! Initializing textures for Point Sprites.
242   void              InitTextures();
243
244   //! Initializing of the Vertex Shader.
245   void              InitShader();
246
247   //! Set Vertex Shader variable.
248   void              SetShaderVariable( const char* variable, float value );
249
250   //! Getting information about Vertex Shader compiling and linking.
251   void              PrintInfoLog( GLhandleARB );
252
253 private:
254   bool              UseOpenGLMapper;
255
256   bool              UsePointSprites;
257   bool              UseTextures;
258   bool              UseShader;
259
260   int               RenderMode;
261   int               ListId;
262   vtkIdType         TotalCells;
263   int               ExtensionsInitialized;
264   float             DefaultPointSize;
265
266   GLhandleARB       VertexProgram;
267
268   int               PrimitiveType;
269
270   int               PointSpriteMode;
271
272   float             PointSpriteClamp;
273   float             PointSpriteSize;
274   float             PointSpriteMinSize;
275   float             PointSpriteMaxSize;
276   float             PointSpriteMagnification;
277
278   GLuint            PointSpriteTexture;
279   float             PointSpriteAlphaThreshold;
280
281   float             AverageCellSize;
282
283   vtkSmartPointer<vtkImageData> ImageData;
284   vtkPolyDataMapper* TempMapper;
285 };
286
287 #endif