1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISU_OpenGLPointSpriteMapper.hxx
27 #ifndef VISU_OpenGLPointSpriteMapper_HeaderFile
28 #define VISU_OpenGLPointSpriteMapper_HeaderFile
31 # pragma warning ( disable : 4275 )
40 #include <vtkSmartPointer.h>
41 #include <vtkConfigure.h>
43 #include "VTKViewer.h"
49 class vtkXMLImageDataReader;
51 #ifndef VTK_IMPLEMENT_MESA_CXX
52 #include <vtkOpenGLPolyDataMapper.h>
53 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
55 #include <vtkMesaPolyDataMapper.h>
56 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
59 #ifndef GL_ARB_shader_objects
60 typedef GLuint GLhandleARB;
63 #include "VISUPipeline.hxx"
65 //----------------------------------------------------------------------------
66 //! OpenGL Point Sprites PolyData Mapper.
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.
75 class VISU_PIPELINE_EXPORT VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS
78 //! The Point Sprites rendering mode.
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
86 enum RenderModes { Accumulate = 0, Occlude };
88 enum PrimitiveTypes { PointSprite = 0, OpenGLPoint, GeomSphere };
90 static VISU_OpenGLPointSpriteMapper *New();
91 vtkTypeRevisionMacro(VISU_OpenGLPointSpriteMapper,MAPPER_SUPERCLASS);
93 //! Set the initial point size to be used.
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.
100 //! Get the initial point size to be used.
101 vtkGetMacro(DefaultPointSize, float);
103 //! Set Average Cell Size.
105 SetAverageCellSize(float theSize);
107 //! Get Average Cell Size.
108 vtkGetMacro(AverageCellSize, float);
110 //! Set the Render Mode for the mapper.
111 vtkSetMacro(RenderMode, int);
113 //! Get the Render Mode for the mapper.
114 vtkGetMacro(RenderMode, int);
116 //! Implement superclass render method.
117 virtual void RenderPiece(vtkRenderer *ren, vtkActor *a);
119 //! Release any graphics resources that are being consumed by this mapper.
120 void ReleaseGraphicsResources(vtkWindow *);
122 //! Draw method for OpenGL.
123 virtual int Draw(vtkRenderer *ren, vtkActor *a);
125 //! Return the maximum point size supported by the graphics hardware.
126 static float GetMaximumSupportedSize();
128 //! Set usage of #vtkOpenGLPolyDataMapper.
130 * This flags prevents using of the VISU_OpenGLPointSpriteMapper
131 * (#vtkOpenGLPolyDataMapper is using instead).
133 vtkSetMacro(UseOpenGLMapper, bool);
135 //! Get usage of #vtkOpenGLPolyDataMapper.
136 vtkGetMacro(UseOpenGLMapper, bool);
138 //! Set usage of Point Sprites.
139 vtkSetMacro(UsePointSprites, bool);
141 //! Get usage of Point Sprites.
142 vtkGetMacro(UsePointSprites, bool);
144 //! Set usage of textures for Point Sprites.
145 /*! Works only if usage of Point Sprites is turned on. */
146 vtkSetMacro(UseTextures, bool);
148 //! Get usage of textures for Point Sprites.
149 vtkGetMacro(UseTextures, bool);
151 //! Set usage of vertex shader.
152 /*! Works only if usage of Point Sprites is turned on. */
153 vtkSetMacro(UseShader, bool);
155 //! Get usage of vertex shader.
156 vtkGetMacro(UseShader, bool);
158 //! Point Sprite drawing mode
160 * 0 - Results - different colors, different sizes.
161 * 1 - Geometry - fixed color, fixed size.
162 * 2 - Outside - different colors, fixed size.
164 vtkGetMacro(PointSpriteMode, int);
165 void SetPointSpriteMode( int );
167 //! Get the Primitive type
168 vtkGetMacro(PrimitiveType, int);
170 //! Set the Primitive type
171 void SetPrimitiveType( int );
173 //! Set Point Sprite Clamp.
174 void SetPointSpriteClamp( float );
176 //! Get Point Sprite Clamp.
177 vtkGetMacro(PointSpriteClamp, float);
179 //! Set Point Sprite Const Size.
180 void SetPointSpriteSize( float );
182 //! Get Point Sprite Const Size.
183 vtkGetMacro(PointSpriteSize, float);
185 //! Set Point Sprite Minimum Size.
186 void SetPointSpriteMinSize( float );
188 //! Get Point Sprite Minimum Size.
189 vtkGetMacro(PointSpriteMinSize, float);
191 //! Set Point Sprite Maximum Size.
192 void SetPointSpriteMaxSize( float );
194 //! Get Point Sprite Maximum Size.
195 vtkGetMacro(PointSpriteMaxSize, float);
197 //! Set Point Sprite Magnification.
198 void SetPointSpriteMagnification( float );
200 //! Get Point Sprite Magnification.
201 vtkGetMacro(PointSpriteMagnification, float);
203 //! Set Point Sprite AlphaThreshold.
204 void SetPointSpriteAlphaThreshold( float );
206 //! Get Point Sprite AlphaThreshold.
207 vtkGetMacro(PointSpriteAlphaThreshold, float);
209 //! Set Point Sprite Opacity
210 vtkSetMacro(PointSpriteOpacity, float);
212 //! Get Point Sprite Opacity
213 vtkGetMacro(PointSpriteOpacity, float);
215 //! Set ImageData for Point Sprite Texture.
216 void SetImageData(vtkImageData* theImageData);
218 //! Get ImageData for Point Sprite Texture.
219 vtkImageData* GetImageData();
222 VISU_OpenGLPointSpriteMapper();
223 ~VISU_OpenGLPointSpriteMapper();
225 //! Initializing OpenGL extensions.
226 bool InitExtensions();
228 //! Activate Point Sprites.
229 void InitPointSprites();
231 //! Deactivate Point Sprites.
232 void CleanupPointSprites();
234 //! Initializing textures for Point Sprites.
237 //! Initializing of the Vertex Shader.
240 //! Set Vertex Shader variable.
241 void SetShaderVariable( const char* variable, float value );
243 //! Getting information about Vertex Shader compiling and linking.
244 void PrintInfoLog( GLhandleARB );
247 bool UseOpenGLMapper;
249 bool UsePointSprites;
255 vtkIdType TotalCells;
256 int ExtensionsInitialized;
257 float DefaultPointSize;
259 GLhandleARB VertexProgram;
265 float PointSpriteClamp;
266 float PointSpriteSize;
267 float PointSpriteMinSize;
268 float PointSpriteMaxSize;
269 float PointSpriteMagnification;
271 GLuint PointSpriteTexture;
272 float PointSpriteAlphaThreshold;
273 float PointSpriteOpacity;
275 float AverageCellSize;
277 vtkSmartPointer<vtkImageData> ImageData;