0029517: Visualization - introduce AlphaMode property defining alpha value handling...
[occt.git] / src / Graphic3d / Graphic3d_AspectFillArea3d.hxx
CommitLineData
42cf5bc1 1// Created on: 1991-11-04
2// Created by: NW,JPB,CAL
3// Copyright (c) 1991-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Graphic3d_AspectFillArea3d_HeaderFile
18#define _Graphic3d_AspectFillArea3d_HeaderFile
19
b6472664 20#include <Aspect_AspectFillAreaDefinitionError.hxx>
21#include <Aspect_PolygonOffsetMode.hxx>
22#include <Aspect_InteriorStyle.hxx>
23#include <Aspect_TypeOfLine.hxx>
c40eb6b9 24#include <Graphic3d_AlphaMode.hxx>
640d5fe2 25#include <Graphic3d_HatchStyle.hxx>
b6472664 26#include <Graphic3d_MaterialAspect.hxx>
27#include <Graphic3d_PolygonOffset.hxx>
28#include <Graphic3d_ShaderProgram.hxx>
29#include <Graphic3d_TextureMap.hxx>
cc8cbabe 30#include <Graphic3d_TextureSet.hxx>
dc89236f 31#include <Graphic3d_TypeOfShadingModel.hxx>
42cf5bc1 32#include <Standard.hxx>
42cf5bc1 33#include <Standard_Boolean.hxx>
42cf5bc1 34#include <Standard_Integer.hxx>
35#include <Standard_ShortReal.hxx>
42cf5bc1 36#include <Standard_Real.hxx>
b6472664 37#include <Standard_Type.hxx>
38#include <Quantity_ColorRGBA.hxx>
42cf5bc1 39
b6472664 40//! This class defines graphic attributes for opaque 3d primitives (polygons, triangles, quadrilaterals).
41class Graphic3d_AspectFillArea3d : public Standard_Transient
42{
43 DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectFillArea3d, Standard_Transient)
42cf5bc1 44public:
45
b6472664 46 //! Creates a context table for fill area primitives defined with the following default values:
42cf5bc1 47 //!
b6472664 48 //! InteriorStyle : Aspect_IS_EMPTY
49 //! InteriorColor : Quantity_NOC_CYAN1
50 //! EdgeColor : Quantity_NOC_WHITE
51 //! EdgeLineType : Aspect_TOL_SOLID
52 //! EdgeWidth : 1.0
53 //! FrontMaterial : NOM_BRASS
54 //! BackMaterial : NOM_BRASS
ec7c343f 55 //! HatchStyle : Aspect_HS_SOLID
42cf5bc1 56 //!
57 //! Display of back-facing filled polygons.
b6472664 58 //! No distinction between external and internal faces of FillAreas.
42cf5bc1 59 //! The edges are not drawn.
60 //! Polygon offset parameters: mode = Aspect_POM_None, factor = 1., units = 0.
61 Standard_EXPORT Graphic3d_AspectFillArea3d();
62
b6472664 63 //! Creates a context table for fill area primitives defined with the specified values.
42cf5bc1 64 //! Display of back-facing filled polygons.
b6472664 65 //! No distinction between external and internal faces of FillAreas.
42cf5bc1 66 //! The edges are not drawn.
67 //! Polygon offset parameters: mode = Aspect_POM_None, factor = 1., units = 0.
b6472664 68 Standard_EXPORT Graphic3d_AspectFillArea3d (const Aspect_InteriorStyle theInterior,
69 const Quantity_Color& theInteriorColor,
70 const Quantity_Color& theEdgeColor,
71 const Aspect_TypeOfLine theEdgeLineType,
72 const Standard_Real theEdgeWidth,
73 const Graphic3d_MaterialAspect& theFrontMaterial,
74 const Graphic3d_MaterialAspect& theBackMaterial);
75
76 //! Return interior rendering style (Aspect_IS_EMPTY by default, which means nothing will be rendered!).
77 Aspect_InteriorStyle InteriorStyle() const { return myInteriorStyle; }
78
79 //! Modifies the interior type used for rendering
80 void SetInteriorStyle (const Aspect_InteriorStyle theStyle) { myInteriorStyle = theStyle; }
81
dc89236f 82 //! Returns shading model (Graphic3d_TOSM_DEFAULT by default, which means that Shading Model set as default for entire Viewer will be used)
83 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
84
85 //! Sets shading model
86 void SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel) { myShadingModel = theShadingModel; }
87
c40eb6b9 88 //! Returns the way how alpha value should be treated (Graphic3d_AlphaMode_BlendAuto by default, for backward compatibility).
89 Graphic3d_AlphaMode AlphaMode() const { return myAlphaMode; }
90
91 //! Returns alpha cutoff threshold, for discarding fragments within Graphic3d_AlphaMode_Mask mode (0.5 by default).
92 //! If the alpha value is greater than or equal to this value then it is rendered as fully opaque, otherwise, it is rendered as fully transparent.
93 Standard_ShortReal AlphaCutoff() const { return myAlphaCutoff; }
94
95 //! Defines the way how alpha value should be treated.
96 void SetAlphaMode (Graphic3d_AlphaMode theMode, Standard_ShortReal theAlphaCutoff = 0.5f)
97 {
98 myAlphaMode = theMode;
99 myAlphaCutoff = theAlphaCutoff;
100 }
101
b6472664 102 //! Return interior color.
103 const Quantity_Color& InteriorColor() const { return myInteriorColor.GetRGB(); }
104
105 //! Return interior color.
106 const Quantity_ColorRGBA& InteriorColorRGBA() const { return myInteriorColor; }
107
108 //! Modifies the color of the interior of the face
109 void SetInteriorColor (const Quantity_Color& theColor) { myInteriorColor.SetRGB (theColor); }
110
a71a71de 111 //! Modifies the color of the interior of the face
112 void SetInteriorColor (const Quantity_ColorRGBA& theColor) { myInteriorColor = theColor; }
113
b6472664 114 //! Return back interior color.
115 const Quantity_Color& BackInteriorColor() const { return myBackInteriorColor.GetRGB(); }
116
117 //! Return back interior color.
118 const Quantity_ColorRGBA& BackInteriorColorRGBA() const { return myBackInteriorColor; }
119
120 //! Modifies the color of the interior of the back face
121 void SetBackInteriorColor (const Quantity_Color& theColor) { myBackInteriorColor.SetRGB (theColor); }
122
a71a71de 123 //! Modifies the color of the interior of the back face
124 void SetBackInteriorColor (const Quantity_ColorRGBA& theColor) { myBackInteriorColor = theColor; }
125
b6472664 126 //! Returns the surface material of external faces
127 const Graphic3d_MaterialAspect& FrontMaterial() const { return myFrontMaterial; }
128
4e1bc39a 129 //! Returns the surface material of external faces
130 Graphic3d_MaterialAspect& ChangeFrontMaterial() { return myFrontMaterial; }
131
42cf5bc1 132 //! Modifies the surface material of external faces
b6472664 133 void SetFrontMaterial (const Graphic3d_MaterialAspect& theMaterial) { myFrontMaterial = theMaterial; }
134
135 //! Returns the surface material of internal faces
136 const Graphic3d_MaterialAspect& BackMaterial() const { return myBackMaterial; }
137
4e1bc39a 138 //! Returns the surface material of internal faces
139 Graphic3d_MaterialAspect& ChangeBackMaterial() { return myBackMaterial; }
140
b6472664 141 //! Modifies the surface material of internal faces
142 void SetBackMaterial (const Graphic3d_MaterialAspect& theMaterial) { myBackMaterial = theMaterial; }
143
144 //! Returns true if back faces should be suppressed (true by default).
145 bool ToSuppressBackFaces() const { return myToSuppressBackFaces; }
146
147 //! Assign back faces culling flag.
148 void SetSuppressBackFaces (bool theToSuppress) { myToSuppressBackFaces = theToSuppress; }
149
150 //! Returns true if back faces should be suppressed (true by default).
151 bool BackFace() const { return myToSuppressBackFaces; }
152
153 //! Allows the display of back-facing filled polygons.
154 void AllowBackFace() { myToSuppressBackFaces = false; }
155
156 //! Suppress the display of back-facing filled polygons.
42cf5bc1 157 //! A back-facing polygon is defined as a polygon whose
b6472664 158 //! vertices are in a clockwise order with respect to screen coordinates.
159 void SuppressBackFace() { myToSuppressBackFaces = true; }
160
161 //! Returns true if material properties should be distinguished for back and front faces (false by default).
162 bool Distinguish() const { return myToDistinguishMaterials; }
163
164 //! Set material distinction between front and back faces.
165 void SetDistinguish (bool toDistinguish) { myToDistinguishMaterials = toDistinguish; }
166
167 //! Allows material distinction between front and back faces.
168 void SetDistinguishOn() { myToDistinguishMaterials = true; }
169
170 //! Forbids material distinction between front and back faces.
171 void SetDistinguishOff() { myToDistinguishMaterials = false; }
172
173 //! Return shader program.
174 const Handle(Graphic3d_ShaderProgram)& ShaderProgram() const { return myProgram; }
175
176 //! Sets up OpenGL/GLSL shader program.
177 void SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram) { myProgram = theProgram; }
178
cc8cbabe 179 //! Return texture array to be mapped.
180 const Handle(Graphic3d_TextureSet)& TextureSet() const { return myTextureSet; }
181
182 //! Setup texture array to be mapped.
183 void SetTextureSet (const Handle(Graphic3d_TextureSet)& theTextures) { myTextureSet = theTextures; }
184
b6472664 185 //! Return texture to be mapped.
cc8cbabe 186 //Standard_DEPRECATED("Deprecated method, TextureSet() should be used instead")
187 Handle(Graphic3d_TextureMap) TextureMap() const
188 {
189 return !myTextureSet.IsNull() && !myTextureSet->IsEmpty()
190 ? myTextureSet->First()
191 : Handle(Graphic3d_TextureMap)();
192 }
b6472664 193
194 //! Assign texture to be mapped.
cc8cbabe 195 //! See also SetTextureMapOn() to actually activate texture mapping.
196 //Standard_DEPRECATED("Deprecated method, SetTextureSet() should be used instead")
197 Standard_EXPORT void SetTextureMap (const Handle(Graphic3d_TextureMap)& theTexture);
b6472664 198
199 //! Return true if texture mapping is enabled (false by default).
200 bool ToMapTexture() const { return myToMapTexture; }
201
202 //! Return true if texture mapping is enabled (false by default).
203 bool TextureMapState() const { return myToMapTexture; }
204
cc8cbabe 205 //! Enable or disable texture mapping (has no effect if texture is not set).
206 void SetTextureMapOn (bool theToMap) { myToMapTexture = theToMap; }
207
b6472664 208 //! Enable texture mapping (has no effect if texture is not set).
209 void SetTextureMapOn() { myToMapTexture = true; }
210
211 //! Disable texture mapping.
212 void SetTextureMapOff() { myToMapTexture = false; }
213
214 //! Returns current polygon offsets settings.
215 const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; }
216
217 //! Returns current polygon offsets settings.
218 void PolygonOffsets (Standard_Integer& theMode,
219 Standard_ShortReal& theFactor,
220 Standard_ShortReal& theUnits) const
221 {
222 theMode = myPolygonOffset.Mode;
223 theFactor = myPolygonOffset.Factor;
224 theUnits = myPolygonOffset.Units;
225 }
226
42cf5bc1 227 //! Sets up OpenGL polygon offsets mechanism.
228 //! <aMode> parameter can contain various combinations of
229 //! Aspect_PolygonOffsetMode enumeration elements (Aspect_POM_None means
230 //! that polygon offsets are not changed).
231 //! If <aMode> is different from Aspect_POM_Off and Aspect_POM_None, then <aFactor> and <aUnits>
232 //! arguments are used by graphic renderer to calculate a depth offset value:
233 //!
234 //! offset = <aFactor> * m + <aUnits> * r, where
235 //! m - maximum depth slope for the polygon currently being displayed,
236 //! r - minimum window coordinates depth resolution (implementation-specific)
237 //!
b6472664 238 //! Default settings for OCC 3D viewer: mode = Aspect_POM_Fill, factor = 1., units = 0.
42cf5bc1 239 //!
240 //! Negative offset values move polygons closer to the viewport,
241 //! while positive values shift polygons away.
242 //! Consult OpenGL reference for details (glPolygonOffset function description).
b6472664 243 void SetPolygonOffsets (const Standard_Integer theMode,
244 const Standard_ShortReal theFactor = 1.0f,
245 const Standard_ShortReal theUnits = 0.0f)
246 {
247 myPolygonOffset.Mode = (Aspect_PolygonOffsetMode )(theMode & Aspect_POM_Mask);
248 myPolygonOffset.Factor = theFactor;
249 myPolygonOffset.Units = theUnits;
250 }
251
252public:
42cf5bc1 253
b6472664 254 //! Returns true if edges should be drawn (false by default).
255 bool ToDrawEdges() const { return myToDrawEdges; }
42cf5bc1 256
b6472664 257 //! Set if edges should be drawn or not.
258 void SetDrawEdges (bool theToDraw) { myToDrawEdges = theToDraw; }
42cf5bc1 259
b6472664 260 //! Returns true if edges should be drawn.
261 bool Edge() const { return myToDrawEdges; }
42cf5bc1 262
b6472664 263 //! The edges of FillAreas are drawn.
264 void SetEdgeOn() { myToDrawEdges = true; }
42cf5bc1 265
b6472664 266 //! The edges of FillAreas are not drawn.
267 void SetEdgeOff() { myToDrawEdges = false; }
42cf5bc1 268
b6472664 269 //! Return color of edges.
270 const Quantity_Color& EdgeColor() const { return myEdgeColor.GetRGB(); }
42cf5bc1 271
b6472664 272 //! Return color of edges.
273 const Quantity_ColorRGBA& EdgeColorRGBA() const { return myEdgeColor; }
42cf5bc1 274
b6472664 275 //! Modifies the color of the edge of the face
276 void SetEdgeColor (const Quantity_Color& theColor) { myEdgeColor.SetRGB (theColor); }
42cf5bc1 277
b6472664 278 //! Return edges line type.
279 Aspect_TypeOfLine EdgeLineType() const { return myEdgeType; }
42cf5bc1 280
b6472664 281 //! Modifies the edge line type
282 void SetEdgeLineType (const Aspect_TypeOfLine theType) { myEdgeType = theType; }
42cf5bc1 283
b6472664 284 //! Return width for edges in pixels.
285 Standard_ShortReal EdgeWidth() const { return myEdgeWidth; }
42cf5bc1 286
b6472664 287 //! Modifies the edge thickness
288 //! Warning: Raises AspectFillAreaDefinitionError if the width is a negative value.
289 void SetEdgeWidth (const Standard_Real theWidth)
290 {
291 if (theWidth <= 0.0)
292 {
9775fa61 293 throw Aspect_AspectFillAreaDefinitionError("Bad value for EdgeLineWidth");
b6472664 294 }
295 myEdgeWidth = (float )theWidth;
296 }
42cf5bc1 297
b6472664 298public:
42cf5bc1 299
b6472664 300 //! Returns the hatch type used when InteriorStyle is IS_HATCH
640d5fe2 301 const Handle(Graphic3d_HatchStyle)& HatchStyle() const { return myHatchStyle; }
42cf5bc1 302
b6472664 303 //! Modifies the hatch type used when InteriorStyle is IS_HATCH
640d5fe2 304 void SetHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) { myHatchStyle = theStyle; }
305
306 //! Modifies the hatch type used when InteriorStyle is IS_HATCH
307 //! @warning This method always creates a new handle for a given hatch style
308 void SetHatchStyle (const Aspect_HatchStyle theStyle)
309 {
310 if (theStyle == Aspect_HS_SOLID)
311 {
312 myHatchStyle.Nullify();
313 return;
314 }
315
316 myHatchStyle = new Graphic3d_HatchStyle (theStyle);
317 }
42cf5bc1 318
b6472664 319 //! Returns the current values.
320 Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters")
321 void Values (Aspect_InteriorStyle& theStyle,
322 Quantity_Color& theIntColor,
323 Quantity_Color& theEdgeColor,
324 Aspect_TypeOfLine& theType,
325 Standard_Real& theWidth) const
326 {
327 theStyle = myInteriorStyle;
328 theIntColor = myInteriorColor.GetRGB();
329 theEdgeColor= myEdgeColor.GetRGB();
330 theType = myEdgeType;
331 theWidth = myEdgeWidth;
332 }
42cf5bc1 333
b6472664 334 //! Returns the current values.
335 Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters")
336 void Values (Aspect_InteriorStyle& theStyle,
337 Quantity_Color& theIntColor,
338 Quantity_Color& theBackIntColor,
339 Quantity_Color& theEdgeColor,
340 Aspect_TypeOfLine& theType,
341 Standard_Real& theWidth) const
342 {
343 theStyle = myInteriorStyle;
344 theIntColor = myInteriorColor.GetRGB();
345 theBackIntColor= myBackInteriorColor.GetRGB();
346 theEdgeColor = myEdgeColor.GetRGB();
347 theType = myEdgeType;
348 theWidth = myEdgeWidth;
349 }
42cf5bc1 350
b6472664 351protected:
352
353 Handle(Graphic3d_ShaderProgram) myProgram;
cc8cbabe 354 Handle(Graphic3d_TextureSet) myTextureSet;
b6472664 355 Graphic3d_MaterialAspect myFrontMaterial;
356 Graphic3d_MaterialAspect myBackMaterial;
357
640d5fe2 358 Quantity_ColorRGBA myInteriorColor;
359 Quantity_ColorRGBA myBackInteriorColor;
360 Quantity_ColorRGBA myEdgeColor;
361 Aspect_InteriorStyle myInteriorStyle;
dc89236f 362 Graphic3d_TypeOfShadingModel myShadingModel;
c40eb6b9 363 Graphic3d_AlphaMode myAlphaMode;
364 Standard_ShortReal myAlphaCutoff;
640d5fe2 365 Aspect_TypeOfLine myEdgeType;
366 Standard_ShortReal myEdgeWidth;
367 Handle(Graphic3d_HatchStyle) myHatchStyle;
b6472664 368
369 Graphic3d_PolygonOffset myPolygonOffset;
370 bool myToDistinguishMaterials;
371 bool myToDrawEdges;
372 bool myToSuppressBackFaces;
373 bool myToMapTexture;
374
375};
42cf5bc1 376
b6472664 377DEFINE_STANDARD_HANDLE(Graphic3d_AspectFillArea3d, Standard_Transient)
42cf5bc1 378
379#endif // _Graphic3d_AspectFillArea3d_HeaderFile