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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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>
43 class vtkRenderWindow;
44 class vtkOpenGLRenderer;
45 class vtkOpenGLTexture;
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 //----------------------------------------------------------------------------
64 //! OpenGL Point Sprites PolyData Mapper.
66 * VISU_OpenGLPointSpriteMapper is a class that maps polygonal data
67 * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
68 * to the rendering/graphics hardware/software. It is now possible to set a
69 * memory limit for the pipeline in the mapper. If the total estimated memory
70 * usage of the pipeline is larger than this limit, the mapper will divide
71 * the data into pieces and render each in a for loop.
73 class VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS
76 //! The Point Sprites rendering mode.
78 * Accumulate : Uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), and no depth testing
79 * so that points are accumulated. Suitable for Galaxy plots.
80 * Occlude : No blending. Particles are solid spheres and depth testing is
81 * used as usual. Suitable for most particle simulations without the need
84 enum RenderModes { Accumulate = 0, Occlude };
86 enum PrimitiveTypes { PointSprite = 0, OpenGLPoint, GeomSphere };
88 static VISU_OpenGLPointSpriteMapper *New();
89 vtkTypeRevisionMacro(VISU_OpenGLPointSpriteMapper,MAPPER_SUPERCLASS);
91 void ShallowCopy(vtkAbstractMapper*);
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 vtkSetMacro(DefaultPointSize, float);
102 //! Get the initial point size to be used.
103 vtkGetMacro(DefaultPointSize, float);
105 //! Set Average Cell Size.
106 vtkSetMacro(AverageCellSize, float);
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 ImageData for Point Sprite Texture.
211 void SetImageData(vtkImageData* theImageData);
213 //! Get ImageData for Point Sprite Texture.
214 vtkImageData* GetImageData();
217 VISU_OpenGLPointSpriteMapper();
218 ~VISU_OpenGLPointSpriteMapper();
220 //! Internal method of the Point Sprites drawing.
221 void DrawPoints(vtkPoints *p,
222 vtkUnsignedCharArray *c,
223 vtkFloatArray *alpha,
230 //! Initializing OpenGL extensions.
231 bool InitExtensions();
233 //! Activate Point Sprites.
234 void InitPointSprites();
236 //! Deactivate Point Sprites.
237 void CleanupPointSprites();
239 //! Initializing textures for Point Sprites.
242 //! Initializing of the Vertex Shader.
245 //! Set Vertex Shader variable.
246 void SetShaderVariable( const char* variable, float value );
248 //! Getting information about Vertex Shader compiling and linking.
249 void PrintInfoLog( GLhandleARB );
252 bool UseOpenGLMapper;
254 bool UsePointSprites;
260 vtkIdType TotalCells;
261 int ExtensionsInitialized;
262 float DefaultPointSize;
264 GLhandleARB VertexProgram;
270 float PointSpriteClamp;
271 float PointSpriteSize;
272 float PointSpriteMinSize;
273 float PointSpriteMaxSize;
274 float PointSpriteMagnification;
276 GLuint PointSpriteTexture;
277 float PointSpriteAlphaThreshold;
279 float AverageCellSize;
281 vtkSmartPointer<vtkImageData> ImageData;
282 vtkPolyDataMapper* TempMapper;