1 // Copyright (C) 2007-2010 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
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File: VISU_OpenGLPointSpriteMapper.hxx
28 #ifndef VISU_OpenGLPointSpriteMapper_HeaderFile
29 #define VISU_OpenGLPointSpriteMapper_HeaderFile
32 # pragma warning ( disable : 4275 )
41 #include <vtkSmartPointer.h>
42 #include <vtkConfigure.h>
44 #include "VTKViewer.h"
50 class vtkXMLImageDataReader;
52 #ifndef VTK_IMPLEMENT_MESA_CXX
53 #include <vtkOpenGLPolyDataMapper.h>
54 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
56 #include <vtkMesaPolyDataMapper.h>
57 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
60 #ifndef GL_ARB_shader_objects
61 typedef GLuint GLhandleARB;
64 #include "VISUPipeline.hxx"
66 //----------------------------------------------------------------------------
67 //! OpenGL Point Sprites PolyData Mapper.
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.
76 class VISU_PIPELINE_EXPORT VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS
79 //! The Point Sprites rendering mode.
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
87 enum RenderModes { Accumulate = 0, Occlude };
89 enum PrimitiveTypes { PointSprite = 0, OpenGLPoint, GeomSphere };
91 static VISU_OpenGLPointSpriteMapper *New();
92 vtkTypeRevisionMacro(VISU_OpenGLPointSpriteMapper,MAPPER_SUPERCLASS);
94 //! Set the initial point size to be used.
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.
101 //! Get the initial point size to be used.
102 vtkGetMacro(DefaultPointSize, float);
104 //! Set Average Cell Size.
106 SetAverageCellSize(float theSize);
108 //! Get Average Cell Size.
109 vtkGetMacro(AverageCellSize, float);
111 //! Set the Render Mode for the mapper.
112 vtkSetMacro(RenderMode, int);
114 //! Get the Render Mode for the mapper.
115 vtkGetMacro(RenderMode, int);
117 //! Implement superclass render method.
118 virtual void RenderPiece(vtkRenderer *ren, vtkActor *a);
120 //! Release any graphics resources that are being consumed by this mapper.
121 void ReleaseGraphicsResources(vtkWindow *);
123 //! Draw method for OpenGL.
124 virtual int Draw(vtkRenderer *ren, vtkActor *a);
126 //! Return the maximum point size supported by the graphics hardware.
127 static float GetMaximumSupportedSize();
129 //! Set usage of #vtkOpenGLPolyDataMapper.
131 * This flags prevents using of the VISU_OpenGLPointSpriteMapper
132 * (#vtkOpenGLPolyDataMapper is using instead).
134 vtkSetMacro(UseOpenGLMapper, bool);
136 //! Get usage of #vtkOpenGLPolyDataMapper.
137 vtkGetMacro(UseOpenGLMapper, bool);
139 //! Set usage of Point Sprites.
140 vtkSetMacro(UsePointSprites, bool);
142 //! Get usage of Point Sprites.
143 vtkGetMacro(UsePointSprites, bool);
145 //! Set usage of textures for Point Sprites.
146 /*! Works only if usage of Point Sprites is turned on. */
147 vtkSetMacro(UseTextures, bool);
149 //! Get usage of textures for Point Sprites.
150 vtkGetMacro(UseTextures, bool);
152 //! Set usage of vertex shader.
153 /*! Works only if usage of Point Sprites is turned on. */
154 vtkSetMacro(UseShader, bool);
156 //! Get usage of vertex shader.
157 vtkGetMacro(UseShader, bool);
159 //! Point Sprite drawing mode
161 * 0 - Results - different colors, different sizes.
162 * 1 - Geometry - fixed color, fixed size.
163 * 2 - Outside - different colors, fixed size.
165 vtkGetMacro(PointSpriteMode, int);
166 void SetPointSpriteMode( int );
168 //! Get the Primitive type
169 vtkGetMacro(PrimitiveType, int);
171 //! Set the Primitive type
172 void SetPrimitiveType( int );
174 //! Set Point Sprite Clamp.
175 void SetPointSpriteClamp( float );
177 //! Get Point Sprite Clamp.
178 vtkGetMacro(PointSpriteClamp, float);
180 //! Set Point Sprite Const Size.
181 void SetPointSpriteSize( float );
183 //! Get Point Sprite Const Size.
184 vtkGetMacro(PointSpriteSize, float);
186 //! Set Point Sprite Minimum Size.
187 void SetPointSpriteMinSize( float );
189 //! Get Point Sprite Minimum Size.
190 vtkGetMacro(PointSpriteMinSize, float);
192 //! Set Point Sprite Maximum Size.
193 void SetPointSpriteMaxSize( float );
195 //! Get Point Sprite Maximum Size.
196 vtkGetMacro(PointSpriteMaxSize, float);
198 //! Set Point Sprite Magnification.
199 void SetPointSpriteMagnification( float );
201 //! Get Point Sprite Magnification.
202 vtkGetMacro(PointSpriteMagnification, float);
204 //! Set Point Sprite AlphaThreshold.
205 void SetPointSpriteAlphaThreshold( float );
207 //! Get Point Sprite AlphaThreshold.
208 vtkGetMacro(PointSpriteAlphaThreshold, float);
210 //! Set Point Sprite Opacity
211 vtkSetMacro(PointSpriteOpacity, float);
213 //! Get Point Sprite Opacity
214 vtkGetMacro(PointSpriteOpacity, float);
216 //! Set ImageData for Point Sprite Texture.
217 void SetImageData(vtkImageData* theImageData);
219 //! Get ImageData for Point Sprite Texture.
220 vtkImageData* GetImageData();
223 VISU_OpenGLPointSpriteMapper();
224 ~VISU_OpenGLPointSpriteMapper();
226 //! Initializing OpenGL extensions.
227 bool InitExtensions();
229 //! Activate Point Sprites.
230 void InitPointSprites();
232 //! Deactivate Point Sprites.
233 void CleanupPointSprites();
235 //! Initializing textures for Point Sprites.
238 //! Initializing of the Vertex Shader.
241 //! Set Vertex Shader variable.
242 void SetShaderVariable( const char* variable, float value );
244 //! Getting information about Vertex Shader compiling and linking.
245 void PrintInfoLog( GLhandleARB );
248 bool UseOpenGLMapper;
250 bool UsePointSprites;
256 vtkIdType TotalCells;
257 int ExtensionsInitialized;
258 float DefaultPointSize;
260 GLhandleARB VertexProgram;
266 float PointSpriteClamp;
267 float PointSpriteSize;
268 float PointSpriteMinSize;
269 float PointSpriteMaxSize;
270 float PointSpriteMagnification;
272 GLuint PointSpriteTexture;
273 float PointSpriteAlphaThreshold;
274 float PointSpriteOpacity;
276 float AverageCellSize;
278 vtkSmartPointer<vtkImageData> ImageData;