]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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 #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 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   //! Initializing OpenGL extensions.
221   bool              InitExtensions();
222
223   //! Activate Point Sprites.
224   void              InitPointSprites();
225
226   //! Deactivate Point Sprites.
227   void              CleanupPointSprites();
228
229   //! Initializing textures for Point Sprites.
230   void              InitTextures();
231
232   //! Initializing of the Vertex Shader.
233   void              InitShader();
234
235   //! Set Vertex Shader variable.
236   void              SetShaderVariable( const char* variable, float value );
237
238   //! Getting information about Vertex Shader compiling and linking.
239   void              PrintInfoLog( GLhandleARB );
240
241 private:
242   bool              UseOpenGLMapper;
243
244   bool              UsePointSprites;
245   bool              UseTextures;
246   bool              UseShader;
247
248   int               RenderMode;
249   int               ListId;
250   vtkIdType         TotalCells;
251   int               ExtensionsInitialized;
252   float             DefaultPointSize;
253
254   GLhandleARB       VertexProgram;
255
256   int               PrimitiveType;
257
258   int               PointSpriteMode;
259
260   float             PointSpriteClamp;
261   float             PointSpriteSize;
262   float             PointSpriteMinSize;
263   float             PointSpriteMaxSize;
264   float             PointSpriteMagnification;
265
266   GLuint            PointSpriteTexture;
267   float             PointSpriteAlphaThreshold;
268
269   float             AverageCellSize;
270
271   vtkSmartPointer<vtkImageData> ImageData;
272 };
273
274 #endif