1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 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
24 // File: VISU_OpenGLPointSpriteMapper.hxx
28 #ifndef VISU_OpenGLPointSpriteMapper_HeaderFile
29 #define VISU_OpenGLPointSpriteMapper_HeaderFile
32 # pragma warning ( disable : 4275 )
37 #include <vtkSmartPointer.h>
38 #include <vtkConfigure.h>
40 #include "VTKViewer.h"
45 class vtkRenderWindow;
46 class vtkOpenGLRenderer;
47 class vtkOpenGLTexture;
51 class vtkXMLImageDataReader;
53 #ifndef VTK_IMPLEMENT_MESA_CXX
54 #include <vtkOpenGLPolyDataMapper.h>
55 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
57 #include <vtkMesaPolyDataMapper.h>
58 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
61 #ifndef GL_ARB_shader_objects
62 typedef GLuint GLhandleARB;
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_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 void ShallowCopy(vtkAbstractMapper*);
95 //! Set the initial point size to be used.
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.
102 vtkSetMacro(DefaultPointSize, float);
104 //! Get the initial point size to be used.
105 vtkGetMacro(DefaultPointSize, float);
107 //! Set Average Cell Size.
108 vtkSetMacro(AverageCellSize, float);
110 //! Get Average Cell Size.
111 vtkGetMacro(AverageCellSize, float);
113 //! Set the Render Mode for the mapper.
114 vtkSetMacro(RenderMode, int);
116 //! Get the Render Mode for the mapper.
117 vtkGetMacro(RenderMode, int);
119 //! Implement superclass render method.
120 virtual void RenderPiece(vtkRenderer *ren, vtkActor *a);
122 //! Release any graphics resources that are being consumed by this mapper.
123 void ReleaseGraphicsResources(vtkWindow *);
125 //! Draw method for OpenGL.
126 virtual int Draw(vtkRenderer *ren, vtkActor *a);
128 //! Return the maximum point size supported by the graphics hardware.
129 static float GetMaximumSupportedSize();
131 //! Set usage of #vtkOpenGLPolyDataMapper.
133 * This flags prevents using of the VISU_OpenGLPointSpriteMapper
134 * (#vtkOpenGLPolyDataMapper is using instead).
136 vtkSetMacro(UseOpenGLMapper, bool);
138 //! Get usage of #vtkOpenGLPolyDataMapper.
139 vtkGetMacro(UseOpenGLMapper, bool);
141 //! Set usage of Point Sprites.
142 vtkSetMacro(UsePointSprites, bool);
144 //! Get usage of Point Sprites.
145 vtkGetMacro(UsePointSprites, bool);
147 //! Set usage of textures for Point Sprites.
148 /*! Works only if usage of Point Sprites is turned on. */
149 vtkSetMacro(UseTextures, bool);
151 //! Get usage of textures for Point Sprites.
152 vtkGetMacro(UseTextures, bool);
154 //! Set usage of vertex shader.
155 /*! Works only if usage of Point Sprites is turned on. */
156 vtkSetMacro(UseShader, bool);
158 //! Get usage of vertex shader.
159 vtkGetMacro(UseShader, bool);
161 //! Point Sprite drawing mode
163 * 0 - Results - different colors, different sizes.
164 * 1 - Geometry - fixed color, fixed size.
165 * 2 - Outside - different colors, fixed size.
167 vtkGetMacro(PointSpriteMode, int);
168 void SetPointSpriteMode( int );
170 //! Get the Primitive type
171 vtkGetMacro(PrimitiveType, int);
173 //! Set the Primitive type
174 void SetPrimitiveType( int );
176 //! Set Point Sprite Clamp.
177 void SetPointSpriteClamp( float );
179 //! Get Point Sprite Clamp.
180 vtkGetMacro(PointSpriteClamp, float);
182 //! Set Point Sprite Const Size.
183 void SetPointSpriteSize( float );
185 //! Get Point Sprite Const Size.
186 vtkGetMacro(PointSpriteSize, float);
188 //! Set Point Sprite Minimum Size.
189 void SetPointSpriteMinSize( float );
191 //! Get Point Sprite Minimum Size.
192 vtkGetMacro(PointSpriteMinSize, float);
194 //! Set Point Sprite Maximum Size.
195 void SetPointSpriteMaxSize( float );
197 //! Get Point Sprite Maximum Size.
198 vtkGetMacro(PointSpriteMaxSize, float);
200 //! Set Point Sprite Magnification.
201 void SetPointSpriteMagnification( float );
203 //! Get Point Sprite Magnification.
204 vtkGetMacro(PointSpriteMagnification, float);
206 //! Set Point Sprite AlphaThreshold.
207 void SetPointSpriteAlphaThreshold( float );
209 //! Get Point Sprite AlphaThreshold.
210 vtkGetMacro(PointSpriteAlphaThreshold, float);
212 //! Set ImageData for Point Sprite Texture.
213 void SetImageData(vtkImageData* theImageData);
215 //! Get ImageData for Point Sprite Texture.
216 vtkImageData* GetImageData();
219 VISU_OpenGLPointSpriteMapper();
220 ~VISU_OpenGLPointSpriteMapper();
222 //! Internal method of the Point Sprites drawing.
223 void DrawPoints(vtkPoints *p,
224 vtkUnsignedCharArray *c,
225 vtkFloatArray *alpha,
232 //! Initializing OpenGL extensions.
233 bool InitExtensions();
235 //! Activate Point Sprites.
236 void InitPointSprites();
238 //! Deactivate Point Sprites.
239 void CleanupPointSprites();
241 //! Initializing textures for Point Sprites.
244 //! Initializing of the Vertex Shader.
247 //! Set Vertex Shader variable.
248 void SetShaderVariable( const char* variable, float value );
250 //! Getting information about Vertex Shader compiling and linking.
251 void PrintInfoLog( GLhandleARB );
254 bool UseOpenGLMapper;
256 bool UsePointSprites;
262 vtkIdType TotalCells;
263 int ExtensionsInitialized;
264 float DefaultPointSize;
266 GLhandleARB VertexProgram;
272 float PointSpriteClamp;
273 float PointSpriteSize;
274 float PointSpriteMinSize;
275 float PointSpriteMaxSize;
276 float PointSpriteMagnification;
278 GLuint PointSpriteTexture;
279 float PointSpriteAlphaThreshold;
281 float AverageCellSize;
283 vtkSmartPointer<vtkImageData> ImageData;
284 vtkPolyDataMapper* TempMapper;