1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00:49 +03:00

Compare commits

..

20 Commits

Author SHA1 Message Date
abv
baa6e38e70 0027871: Possible memory leak in viewers in virtual windows mode
Command checktrend is modified to avoid performing check for lists containing less than 5 items, as estimations based on short lists often lead to false positives.
2019-03-03 08:14:43 +03:00
mnv
2a33274558 0029076: Visualization - implement element shrinking Shader
Aspect_IS_HOLLOW now an alias to Aspect_IS_EMPTY and Aspect_IS_HIDDENLINE does not implicitly enables mesh edges,
so that Graphic3d_AspectFillArea3d::SetDrawEdges() should be set independently.

OpenGl_ShaderManager now provides built-in GLSL programs for drawing mesh edges
in single pass (and on OpenGL ES which does not provide glPolygonMode()).

Graphic3d_RenderingParams::ToEnableAlphaToCoverage is now enabled by default
and properly handled at TKOpenGl level - enables coverage for Graphic3d_AlphaMode_Mask primitives.

OpenGl_PrimitiveArray now uses GLSL programs instead of glPolygonMode() by default,
which can be managed by OpenGl_Caps::usePolygonMode flag (desktop OpenGL only).
glPolygonMode() is also used as fallback regardless OpenGl_Caps::usePolygonMode flag
when GLSL programs are not supported (Geometry Shaders are required)
or stipple line style is required (not implemented within Face GLSL).

vaspects command has been extended by -setInterior -setDrawEdges -setEdgeColor -setEdgeType -setEdgeWidth
arguments replacing vsetinteriorstyle/vsetedgetype/vunsetedgetype commands.
vaspects now accepts arguments without "set" prefix.
ViewerTest::ParseColor() now parses RGBA color.

Redundant command BUC60738 has been removed.
AIS_ColorScale - fixed usage of uninitialized FillArea aspects.
2019-02-22 16:23:35 +03:00
jfa
4efe27fc4e 0030510: Application Framework - add missing NULL check within TDataStd_RealArray::ChangeArray() 2019-02-21 18:47:04 +03:00
kgv
ea298f59e4 0030384: Visualization - Won't display line with dot and dash style on Android
Fix misprint leading to double semicolon in GLSL code.
2019-02-21 18:44:37 +03:00
apn
78d5ea7a71 0030498: Warnings of building documentation
Fix warning 'Reached end of file while still insided a (nested) comment in Markdown' for old versions of doxygen
2019-02-18 14:59:32 +03:00
kgv
e084dbbc20 0030476: Visualization, Path Tracing - Adaptive Screen Sampling leads to unstable results
OpenGl_View::runPathtrace() has been extended with alternative multi-pass
Adaptive Screen Sampling mode, not relying on atomic floating point operations.
Although atomic operations on floats allows single-pass rendering,
such operations leads to instability in case of different calculation order.
Atomic float operations are also currently supported only by single GPU vendor.

Fixed GLSL compilation on Intel drivers (follow ARB_shader_image_load_store
specs rather than EXT_shader_image_load_store).

Graphic3d_RenderingParams::AdaptiveScreenSamplingAtomic option has been added
to activate 1-pass Adaptive Screen Sampling mode when supported by hardware.

vfps command has been extended with -duration argument allowing to limit command execution time.
vactivate command has been extended with -noUpdate argument.
2019-02-15 17:16:12 +03:00
kgv
66d1cdc65d 0030483: Visualization, Path Tracing - make Tile Size configurable
OpenGl_TileSampler has been refactored to better describe its logic:
- Offset image now defines tile index instead of offset to tile origin.
- Added 2D array defining the number of times to sample tile for straight-forward debugging.

Graphic3d_RenderingParams has been extended with property
RayTracingTileSize for testing various tile configurations.
Default behavior is the following:
- Target number of tiles (e.g. upper limit per frame): 256
- Tile size: 32x32.

OpenGl_View::runPathtrace() has been split into two methods per rendering stage.
OpenGl_Texture::Init() now returns FALSE immediately on 0 input dimensions.

Added Image_PixMapTypedData template class allowing to work with image data of known pixel format.
2019-02-15 17:14:19 +03:00
kgv
e607bd3e6b 0028488: VIS - fix compilation with VTK 8.2
Occurrences of removed method vtkDataArray::InsertNextTupleValue() have been replaced by InsertNextTypedTuple().
Fixed misprint in vtkTypeMacro usage for class IVtkTools_ShapeObject.
Patch #0030452 (SelectMgr_ViewerSelector::Deactivate() raises exception when called twice) has been propagated to IVtkOCC_ViewerSelector.
2019-02-15 15:52:14 +03:00
kgv
1ccc1371b9 0030486: Visualization - Rubber-band selection does not work with disabled overlap detection
SelectMgr_RectangularFrustum::Overlaps() now treats degenerated polygon as point instead of returning FALSE.
2019-02-13 17:07:17 +03:00
kgv
5ac0f98974 0030477: Visualization - crash in AIS_Manipulator::ObjectTransformation after using V3d_View::SetProj(V3d_Zpos) 2019-02-13 17:06:30 +03:00
kgv
2bda8346dc 0030488: Visualization, Ray Tracing - empty error message on GLSL program compilation
OpenGl_ShaderObject::LoadAndCompile() - added method combining Load() and Compile() with optional error logging.
OpenGl_ShaderProgram::Link() now logs failures by default.
2019-02-13 17:03:47 +03:00
kgv
92435cd0ff 0030478: Foundation Classes, NCollection_Array2 - provide Resize/Move methods consistent to NCollection_Array1 2019-02-12 18:54:34 +03:00
kgv
597fde688e 0030494: Coding Rules - eliminate declaration of OpenGl_Workspace::IsCullingEnabled() 2019-02-12 18:46:37 +03:00
abv
458ff6a680 0030129: With newest doxygen 1.8.14 generation of overview gives warnings
Doxygen configuration scripts are corrected to avoid '\n' symbols in the end of the @figure alias that caused multiple warning messages.
Other Doxygen warnings in Markdown files are eliminated.
In CMake builds the format of Doxygen warnings is set to use the style recognized by Visual Studio when compiler is MSVC.
2019-02-12 18:45:40 +03:00
nds
a7ced2a456 0030480: Visualization - Clear of Select3D_SensitiveGroup does not update internal container 2019-02-07 11:04:59 +03:00
bugmaster
ab9f6cabdc 0028936: Draw freezes while making a 3d representation
Adding testing case
2019-02-06 16:18:00 +03:00
kgv
95c882e9d4 0030329: Move BRepMesh_IncAllocator to NCollection package
NCollection_IncAllocator has been extended with optional mutex allocation (disabled by default).
2019-02-04 17:48:14 +03:00
kgv
976627e601 0030474: Visualization - fallback font is ignored for missing font alias within Font_FontMgr::FindFont() 2019-02-04 16:39:53 +03:00
kgv
d918208af6 0030469: Visualization - Draw crashes when 3D view is minimized
OpenGl_View::Redraw() - avoid rendering into window of zero size (leading to FPE and other issues).
2019-02-04 16:26:23 +03:00
kgv
98ae54f728 0030366: Coding Rules - GeometryTest_API2dCommands.cxx seems to be excess 2019-02-04 15:06:57 +03:00
129 changed files with 3947 additions and 3191 deletions

View File

@@ -89,6 +89,14 @@ file (APPEND ${OCCT_CONFIG_FOR_DOXYGEN} "\nEXTERNAL_SEARCH = NO")
# Formula options
file (APPEND ${OCCT_CONFIG_FOR_DOXYGEN} "\nMATHJAX_RELPATH = ${3RDPARTY_MATHJAX_RELATIVE_PATH}")
# If MSVC is used as build system, change warning format to the one recognized by MSVC
if (MSVC)
file (APPEND ${OCCT_CONFIG_FOR_DOXYGEN} "\nWARN_FORMAT = \"$file($line): $text\"")
endif()
# Avoid Doxygen parsing messages in the build log
file (APPEND ${OCCT_CONFIG_FOR_DOXYGEN} "\nQUIET = YES")
# Copy index file to provide fast access to HTML documentation
file(COPY "${OCCT_OVERVIEW_RESOURCE_DIR}/index.html" DESTINATION "${OCCT_GENERATED_OVERVIEW_DIR}")

View File

@@ -1091,7 +1091,7 @@ The following environment variables have become redundant:
* *CSF_UnitsLexicon* and *CSF_UnitsDefinition* are no more used. Units definition (*UnitsAPI/Lexi_Expr.dat* and *UnitsAPI/Units.dat*) is now embedded into source code.
* *CSF_XSMessage* and *CSF_XHMessage* are now optional.
English messages (XSMessage/*XSTEP.us* and SHMessage/*SHAPE.us*) are now embedded into source code
English messages (XSMessage/\*XSTEP.us* and SHMessage/\*SHAPE.us*) are now embedded into source code
and automatically loaded when environment variables are not set.
* *CSF_ShadersDirectory* is not required any more, though it still can be used to load custom shaders.
Mandatory GLSL resources are now embedded into source code.
@@ -1678,3 +1678,10 @@ Standard_Boolean meshing_new()
Some public methods of the class BRepFilletAPI_MakeChamfer are released from excess arguments:
- method Add for symmetric chamfer now takes only 2 arguments: distance and edge;
- method GetDistAngle now takes only 3 arguments: index of contour, distance and angle.
@subsection upgrade_740_interiorstyles Interior styles
* *Aspect_IS_HOLLOW* is now an alias to *Aspect_IS_EMPTY* and does not implicitly enables drawing mesh edges anymore.
Specify Graphic3d_AspectFillArea3d::SetDrawEdges(true) with Graphic3d_AspectFillArea3d::SetInteriorStyle(Aspect_IS_EMPTY) to get previous behavior of Aspect_IS_HOLLOW style.
* *Aspect_IS_HIDDENLINE* does not implicitly enables drawing mesh edges anymore.
Specify Graphic3d_AspectFillArea3d::SetDrawEdges(true) with Graphic3d_AspectFillArea3d::SetInteriorStyle(Aspect_IS_HIDDENLINE) to get previous behavior of Aspect_IS_HIDDENLINE style.

View File

@@ -16,7 +16,6 @@ WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = \\$file:\$line: \$text\
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.md *.dox
RECURSIVE = YES
@@ -56,6 +55,6 @@ USE_MATHJAX = YES
MATHJAX_FORMAT = HTML-CSS
# Define alias for inserting images in uniform way (both HTML and PDF)
ALIASES += figure{1}="\image html \1 \n"
ALIASES += figure{2}="\image html \1 \2 \n"
ALIASES += figure{3}="\image html \1 \2 \n"
ALIASES += figure{1}="\image html \1"
ALIASES += figure{2}="\image html \1 \2"
ALIASES += figure{3}="\image html \1 \2"

View File

@@ -16,7 +16,6 @@ WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = \\$file:\$line: \$text\
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.md *.dox
RECURSIVE = YES
@@ -49,6 +48,6 @@ LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
# Define alias for inserting images in uniform way (both HTML and PDF)
ALIASES += figure{1}="\image latex \1 \n"
ALIASES += figure{2}="\image latex \1 \2 \n"
ALIASES += figure{3}="\image latex \1 \2 width=\3 \n"
ALIASES += figure{1}="\image latex \1"
ALIASES += figure{2}="\image latex \1 \2"
ALIASES += figure{3}="\image latex \1 \2 width=\3"

View File

@@ -178,10 +178,10 @@ if (!Interface_Static::SetRVal ("read.maxprecision.val",0.1))
Default value is 1.
<h4>read.stdsameparameter.mode</h4>
defines the using of *BRepLib::SameParameter*. Its possible values are:
* 0 (Off) -- *BRepLib::SameParameter* is not called,
* 1 (On) -- *BRepLib::SameParameter* is called.
*BRepLib::SameParameter* is used through *ShapeFix_Edge::SameParameter*. It ensures that the resulting edge will have the lowest tolerance taking pcurves either unmodified from the IGES file or modified by *BRepLib::SameParameter*.
defines the using of *BRepLib\::SameParameter*. Its possible values are:
* 0 (Off) -- *BRepLib\::SameParameter* is not called,
* 1 (On) -- *BRepLib\::SameParameter* is called.
*BRepLib\::SameParameter* is used through *ShapeFix_Edge\::SameParameter*. It ensures that the resulting edge will have the lowest tolerance taking pcurves either unmodified from the IGES file or modified by *BRepLib\::SameParameter*.
Read this parameter with:
~~~~~
Standard_Integer mv = Interface_Static::IVal("read.stdsameparameter.mode");
@@ -202,7 +202,7 @@ The processor also decides to re-compute either the 3D or the 2D curve even if
* the number of sub-curves in the 2D curve is different from the number of sub-curves in the 3D curve. This can be either due to different numbers of sub-curves given in the IGES file or because of splitting of curves during translation.
* 3D or 2D curve is a Circular Arc (entity type 100) starting and ending in the same point (note that this case is incorrect according to the IGES standard).
The parameter *read.surfacecurve.mode* defines which curve (3D or 2D) is used for re-computing the other one:
The parameter *read.surfacecurve.mode* defines which curve (3D or 2D) is used for re-computing the other one:
* *Default(0)* use the preference flag value in the entity's Parameter Data section. The flag values are:
* 0: no preference given,
* 1: use 2D for 142 entities and 3D for 141 entities,
@@ -400,12 +400,12 @@ reader.PrintTransferInfo (failsonly, mode);
~~~~~
displays the messages that appeared during the last invocation of *Transfer* or *TransferRoots*.
If *failsonly* is *IFSelect_FailOnly*, only fail messages will be output, if it is *IFSelect_FailAndWarn*, all messages will be output. Parameter “mode” can have *IFSelect_xxx* values where *xxx* can be:
* *GeneralCount* -- gives general statistics on the transfer (number of translated IGES entities, number of fails and warnings, etc)
* *CountByItem* -- gives the number of IGES entities with their types per message.
* *ListByItem* -- gives the number of IGES entities with their type and DE numbers per message.
* *ResultCount* -- gives the number of resulting OCCT shapes per type.
* *Mapping* -- gives mapping between roots of the IGES file and the resulting OCCT shape per IGES and OCCT type.
If *failsonly* is *IFSelect_FailOnly*, only fail messages will be output, if it is *IFSelect_FailAndWarn*, all messages will be output. Parameter “mode” can have *IFSelect_xxx* values where *xxx* can be:
* *GeneralCount* -- gives general statistics on the transfer (number of translated IGES entities, number of fails and warnings, etc)
* *CountByItem* -- gives the number of IGES entities with their types per message.
* *ListByItem* -- gives the number of IGES entities with their type and DE numbers per message.
* *ResultCount* -- gives the number of resulting OCCT shapes per type.
* *Mapping* -- gives mapping between roots of the IGES file and the resulting OCCT shape per IGES and OCCT type.
@subsection occt_iges_2_4 Mapping of IGES entities to Open CASCADE Technology shapes

View File

@@ -1793,12 +1793,11 @@ Create facet attributes.
Handle(Graphic3d_AspectFillArea3d) aFaceAspect = new Graphic3d_AspectFillArea3d();
Graphic3d_MaterialAspect aBrassMaterial (Graphic3d_NOM_BRASS);
Graphic3d_MaterialAspect aGoldMaterial (Graphic3d_NOM_GOLD);
aFaceAspect->SetInteriorStyle (Aspect_IS_SOLID);
aFaceAspect->SetInteriorStyle (Aspect_IS_SOLID_WIREFRAME);
aFaceAspect->SetInteriorColor (aMyColor);
aFaceAspect->SetDistinguishOn ();
aFaceAspect->SetFrontMaterial (aGoldMaterial);
aFaceAspect->SetBackMaterial (aBrassMaterial);
aFaceAspect->SetEdgeOn();
~~~~~
Create text attributes.

View File

@@ -14,9 +14,9 @@ Requirements for building sample:
* Android NDK r9d or newer
* Apache Ant 1.9.4 or higher
* OCCT compiled under Android platform and placed in directories:
* occt/libs/armeabi-v7a/*.so and occt/inc/*.hxx (libraries and include files of OCCT install)
* android/assets/opencascade/shared/Shaders/* (Shaders folder of OCCT install: /share/opencascade/resources/Shaders)
* 3rdparty/include/freetype2/*, 3rdparty/include/FreeImage.h and 3rdparty/libs/armeabi-v7a/libFreeImage.so and 3rdparty/libs/armeabi-v7a/libfreetype.so
* occt/libs/armeabi-v7a/\*.so and occt/inc/\*.hxx (libraries and include files of OCCT install)
* android/assets/opencascade/shared/Shaders/\* (Shaders folder of OCCT install: /share/opencascade/resources/Shaders)
* 3rdparty/include/freetype2/\*, 3rdparty/include/FreeImage.h and 3rdparty/libs/armeabi-v7a/libFreeImage.so and 3rdparty/libs/armeabi-v7a/libfreetype.so
It is also possible to to correct OCCT.pri file an get resources from another tree of directories.

View File

@@ -107,6 +107,10 @@ AIS_ColorScale::AIS_ColorScale()
myTextHeight (20)
{
SetDisplayMode (0);
myDrawer->SetupOwnShadingAspect();
myDrawer->ShadingAspect()->Aspect()->SetShadingModel (Graphic3d_TOSM_UNLIT);
myDrawer->ShadingAspect()->Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque);
myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (Quantity_NOC_WHITE);
}
//=======================================================================
@@ -458,15 +462,6 @@ void AIS_ColorScale::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
const Standard_Integer aBarTop = myYPos + myHeight - aTitleOffset - aBarYOffset;
const Standard_Integer aBarHeight = aBarTop - aBarBottom;
// draw title
if (!myTitle.IsEmpty())
{
drawText (Prs3d_Root::CurrentGroup (thePrs), myTitle,
myXPos + mySpacing,
aBarTop + aBarYOffset,
Graphic3d_VTA_BOTTOM);
}
TColStd_SequenceOfExtendedString aLabels;
if (myLabelType == Aspect_TOCSD_USER)
{
@@ -496,11 +491,27 @@ void AIS_ColorScale::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
aColorBreadth += aTextWidth;
}
// draw title
Handle(Graphic3d_Group) aLabelsGroup;
if (!myTitle.IsEmpty()
|| !aLabels.IsEmpty())
{
aLabelsGroup = thePrs->NewGroup();
aLabelsGroup->SetGroupPrimitivesAspect (myDrawer->TextAspect()->Aspect());
}
if (!myTitle.IsEmpty())
{
drawText (aLabelsGroup, myTitle,
myXPos + mySpacing,
aBarTop + aBarYOffset,
Graphic3d_VTA_BOTTOM);
}
// draw colors
drawColorBar (thePrs, aBarBottom, aBarHeight, aTextWidth, aColorBreadth);
// draw Labels
drawLabels (thePrs, aLabels, aBarBottom, aBarHeight, aTextWidth, aColorBreadth);
drawLabels (aLabelsGroup, aLabels, aBarBottom, aBarHeight, aTextWidth, aColorBreadth);
}
//=======================================================================
@@ -627,7 +638,8 @@ void AIS_ColorScale::drawColorBar (const Handle(Prs3d_Presentation)& thePrs,
}
}
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePrs);
Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
aGroup->SetGroupPrimitivesAspect (myDrawer->ShadingAspect()->Aspect());
aGroup->AddPrimitiveArray (aTriangles);
const Quantity_Color aFgColor (hasOwnColor ? myDrawer->Color() : Quantity_NOC_WHITE);
@@ -642,7 +654,7 @@ void AIS_ColorScale::drawColorBar (const Handle(Prs3d_Presentation)& thePrs,
//function : drawLabels
//purpose :
//=======================================================================
void AIS_ColorScale::drawLabels (const Handle(Prs3d_Presentation)& thePrs,
void AIS_ColorScale::drawLabels (const Handle(Graphic3d_Group)& theGroup,
const TColStd_SequenceOfExtendedString& theLabels,
const Standard_Integer theBarBottom,
const Standard_Integer theBarHeight,
@@ -716,14 +728,14 @@ void AIS_ColorScale::drawLabels (const Handle(Prs3d_Presentation)& thePrs,
Standard_Integer aPos2 = aNbLabels - 1 - i2;
if (aFilter && !(aPos1 % aFilter))
{
drawText (Prs3d_Root::CurrentGroup (thePrs), theLabels.Value (i1 + 1),
drawText (theGroup, theLabels.Value (i1 + 1),
anXLeft, anYBottom + Standard_Integer(i1 * aStepY + anAscent),
Graphic3d_VTA_CENTER);
aLast1 = i1;
}
if (aFilter && !(aPos2 % aFilter))
{
drawText (Prs3d_Root::CurrentGroup (thePrs), theLabels.Value (i2 + 1),
drawText (theGroup, theLabels.Value (i2 + 1),
anXLeft, anYBottom + Standard_Integer(i2 * aStepY + anAscent),
Graphic3d_VTA_CENTER);
aLast2 = i2;
@@ -746,7 +758,7 @@ void AIS_ColorScale::drawLabels (const Handle(Prs3d_Presentation)& thePrs,
if (i0 != -1)
{
drawText (Prs3d_Root::CurrentGroup (thePrs), theLabels.Value (i0 + 1),
drawText (theGroup, theLabels.Value (i0 + 1),
anXLeft, anYBottom + Standard_Integer(i0 * aStepY + anAscent),
Graphic3d_VTA_CENTER);
}
@@ -769,8 +781,8 @@ void AIS_ColorScale::drawFrame (const Handle(Prs3d_Presentation)& thePrs,
aPrim->AddVertex (theX, theY, 0.0);
Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d (theColor, Aspect_TOL_SOLID, 1.0);
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (thePrs);
aGroup->SetPrimitivesAspect (anAspect);
Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
aGroup->SetGroupPrimitivesAspect (anAspect);
aGroup->AddPrimitiveArray (aPrim);
}
@@ -784,7 +796,6 @@ void AIS_ColorScale::drawText (const Handle(Graphic3d_Group)& theGroup,
const Graphic3d_VerticalTextAlignment theVertAlignment)
{
const Handle(Prs3d_TextAspect)& anAspect = myDrawer->TextAspect();
theGroup->SetPrimitivesAspect (anAspect->Aspect());
theGroup->Text (theText,
gp_Ax2 (gp_Pnt (theX, theY, 0.0), gp::DZ()),
anAspect->Height(),

View File

@@ -406,7 +406,7 @@ private:
Standard_Integer computeMaxLabelWidth (const TColStd_SequenceOfExtendedString& theLabels) const;
//! Draw labels.
void drawLabels (const Handle(Prs3d_Presentation)& thePrs,
void drawLabels (const Handle(Graphic3d_Group)& theGroup,
const TColStd_SequenceOfExtendedString& theLabels,
const Standard_Integer theBarBottom,
const Standard_Integer theBarHeight,

View File

@@ -493,6 +493,7 @@ Standard_Boolean AIS_Manipulator::ObjectTransformation (const Standard_Integer t
const gp_Lin aLine (myStartPosition.Location(), myAxes[myCurrentIndex].Position().Direction());
Extrema_ExtElC anExtrema (anInputLine, aLine, Precision::Angular());
if (!anExtrema.IsDone()
|| anExtrema.IsParallel()
|| anExtrema.NbExt() != 1)
{
// translation cannot be done co-directed with camera
@@ -538,7 +539,9 @@ Standard_Boolean AIS_Manipulator::ObjectTransformation (const Standard_Integer t
const gp_Pnt aPosLoc = myStartPosition.Location();
const gp_Ax1 aCurrAxis = getAx1FromAx2Dir (myStartPosition, myCurrentIndex);
IntAna_IntConicQuad aIntersector (anInputLine, gp_Pln (aPosLoc, aCurrAxis.Direction()), Precision::Angular(), Precision::Intersection());
if (!aIntersector.IsDone() || aIntersector.NbPoints() < 1)
if (!aIntersector.IsDone()
|| aIntersector.IsParallel()
|| aIntersector.NbPoints() < 1)
{
return Standard_False;
}

View File

@@ -350,77 +350,12 @@ bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
const Quantity_Color& theColor) const
{
bool toRecompute = false;
if (!theDrawer->HasOwnShadingAspect())
toRecompute = theDrawer->SetupOwnShadingAspect() || toRecompute;
toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
if (theDrawer->SetupOwnPointAspect())
{
toRecompute = true;
theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
if (theDrawer->HasLink())
{
*theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
}
}
if (!theDrawer->HasOwnLineAspect())
{
toRecompute = true;
theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
}
}
if (!theDrawer->HasOwnWireAspect())
{
toRecompute = true;
theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
}
}
if (!theDrawer->HasOwnPointAspect())
{
toRecompute = true;
theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
}
}
if (!theDrawer->HasOwnFreeBoundaryAspect())
{
toRecompute = true;
theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
}
}
if (!theDrawer->HasOwnUnFreeBoundaryAspect())
{
toRecompute = true;
theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
}
}
if (!theDrawer->HasOwnSeenLineAspect())
{
toRecompute = true;
theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
}
}
if (!theDrawer->HasOwnFaceBoundaryAspect())
{
toRecompute = true;
theDrawer->SetFaceBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->FaceBoundaryAspect()->Aspect() = *theDrawer->Link()->FaceBoundaryAspect()->Aspect();
}
}
// override color
@@ -614,61 +549,7 @@ void AIS_Shape::UnsetColor()
bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
const Standard_Real theLineWidth) const
{
bool toRecompute = false;
if (!theDrawer->HasOwnLineAspect())
{
toRecompute = true;
theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
}
}
if (!theDrawer->HasOwnWireAspect())
{
toRecompute = true;
theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
}
}
if (!theDrawer->HasOwnFreeBoundaryAspect())
{
toRecompute = true;
theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
}
}
if (!theDrawer->HasOwnUnFreeBoundaryAspect())
{
toRecompute = true;
theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
}
}
if (!theDrawer->HasOwnSeenLineAspect())
{
toRecompute = true;
theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
}
}
if (!theDrawer->HasOwnFaceBoundaryAspect())
{
toRecompute = true;
theDrawer->SetFaceBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
if (theDrawer->HasLink())
{
*theDrawer->FaceBoundaryAspect()->Aspect() = *theDrawer->Link()->FaceBoundaryAspect()->Aspect();
}
}
bool toRecompute = theDrawer->SetOwnLineAspects();
// override width
theDrawer->LineAspect()->SetWidth (theLineWidth);
@@ -758,14 +639,7 @@ void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)& theDrawer,
{
const Quantity_Color aColor = theDrawer->ShadingAspect()->Material (myCurrentFacingModel).Color();
const Standard_Real aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
if (!theDrawer->HasOwnShadingAspect())
{
theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
if (theDrawer->HasLink())
{
*theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
}
}
theDrawer->SetupOwnShadingAspect();
theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
if (theToKeepColor)
@@ -889,15 +763,7 @@ void AIS_Shape::UnsetMaterial()
void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
const Standard_Real theValue) const
{
if (!theDrawer->HasOwnShadingAspect())
{
theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
if (theDrawer->HasLink())
{
*theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
}
}
theDrawer->SetupOwnShadingAspect();
// override transparency
theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
}

View File

@@ -51,7 +51,7 @@
//! To generate texture coordinates, appropriate shading attribute should be set before computing presentation in AIS_Shaded display mode:
//! @code
//! Handle(AIS_Shape) aPrs = new AIS_Shape();
//! aPrs->Attributes()->SetShadingAspect (new Prs3d_ShadingAspect());
//! aPrs->Attributes()->SetupOwnShadingAspect();
//! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
//! aPrs->Attributes()->ShadingAspect()->Aspect()->SetTextureMap (new Graphic3d_Texture2Dmanual (Graphic3d_NOT_2D_ALUMINUM));
//! @endcode

View File

@@ -16,23 +16,17 @@
#ifndef _Aspect_InteriorStyle_HeaderFile
#define _Aspect_InteriorStyle_HeaderFile
//! Definition of interior types for primitive
//! faces.
//!
//! IS_EMPTY no interior.
//! IS_HOLLOW display the boundaries of the surface.
//! IS_HATCH display hatched with a hatch style.
//! IS_SOLID display the interior entirely filled.
//! IS_HIDDENLINE display in hidden lines removed.
//! IS_POINT display only vertices.
//! Interior types for primitive faces.
enum Aspect_InteriorStyle
{
Aspect_IS_EMPTY,
Aspect_IS_HOLLOW,
Aspect_IS_HATCH,
Aspect_IS_SOLID,
Aspect_IS_HIDDENLINE,
Aspect_IS_POINT
Aspect_IS_EMPTY = -1, //!< no interior
Aspect_IS_SOLID = 0, //!< normally filled surface interior
Aspect_IS_HATCH, //!< hatched surface interior
Aspect_IS_HIDDENLINE, //!< interior is filled with viewer background color
Aspect_IS_POINT, //!< display only vertices of surface (obsolete)
// obsolete aliases
Aspect_IS_HOLLOW = Aspect_IS_EMPTY, //!< transparent surface interior
};
#endif // _Aspect_InteriorStyle_HeaderFile

View File

@@ -18,7 +18,6 @@
#include <IMeshData_Edge.hxx>
#include <OSD_Parallel.hxx>
#include <BRepMesh_GeomTool.hxx>
#include <BRepMesh_IncAllocator.hxx>
namespace
{

View File

@@ -1,50 +0,0 @@
// Created on: 2016-06-20
// Created by: Oleg AGASHIN
// Copyright (c) 2016 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _BRepMesh_IncAllocator_HeaderFile
#define _BRepMesh_IncAllocator_HeaderFile
#include <NCollection_IncAllocator.hxx>
#include <Standard_Mutex.hxx>
//! Extension for NCollection_IncAllocator implementing simple thread safety
//! by introduction of Mutex. Intended for use in couple with BRepMeshData
//! entities in order to prevent data races while building data model in
//! parallel mode. Note that this allocator is supposed for use by collections
//! which allocate memory by huge blocks at arbitrary moment, thus it should
//! not introduce significant performance slow down.
class BRepMesh_IncAllocator : public NCollection_IncAllocator
{
public:
//! Constructor
BRepMesh_IncAllocator(const size_t theBlockSize = DefaultBlockSize)
: NCollection_IncAllocator(theBlockSize)
{
}
//! Allocate memory with given size. Returns NULL on failure
virtual void* Allocate(const size_t size) Standard_OVERRIDE
{
Standard_Mutex::Sentry aSentry(myMutex);
return NCollection_IncAllocator::Allocate(size);
}
DEFINE_STANDARD_RTTI_INLINE(BRepMesh_IncAllocator, NCollection_IncAllocator)
private:
Standard_Mutex myMutex;
};
#endif

View File

@@ -46,7 +46,6 @@ BRepMesh_FactoryError.hxx
BRepMesh_FastDiscret.hxx
BRepMesh_GeomTool.cxx
BRepMesh_GeomTool.hxx
BRepMesh_IncAllocator.hxx
BRepMesh_IncrementalMesh.cxx
BRepMesh_IncrementalMesh.hxx
BRepMesh_MeshAlgoFactory.cxx

View File

@@ -14,11 +14,12 @@
// commercial license or contractual agreement.
#include <BRepMeshData_Model.hxx>
#include <BRepMeshData_Face.hxx>
#include <BRepMeshData_Edge.hxx>
#include <BRepMesh_IncAllocator.hxx>
#include <BRepMesh_OrientedEdge.hxx>
#include <BRepMesh_Vertex.hxx>
#include <NCollection_IncAllocator.hxx>
//=======================================================================
// Function: Constructor
@@ -27,10 +28,11 @@
BRepMeshData_Model::BRepMeshData_Model (const TopoDS_Shape& theShape)
: IMeshData_Model (theShape),
myMaxSize (0.),
myAllocator (new BRepMesh_IncAllocator(IMeshData::MEMORY_BLOCK_SIZE_HUGE)),
myAllocator (new NCollection_IncAllocator (IMeshData::MEMORY_BLOCK_SIZE_HUGE)),
myDFaces (256, myAllocator),
myDEdges (256, myAllocator)
{
myAllocator->SetThreadSafe();
}
//=======================================================================

View File

@@ -2731,13 +2731,14 @@ proc _checkpoint {coord_x coord_y rd_ch gr_ch bl_ch} {
# the check fails and procedure raises error with specified message.
#
# Otherwise the procedure returns false meaning that more iterations are needed.
# Note that false is returned in any case if length of listval is less than 3.
# Note that analysis is peformed only if listval contains at least 5 values,
# thus false is returned unconditionally for shorter lists.
#
# See example of use to check memory leaks in bugs/caf/bug23489
#
proc checktrend {listval delta tolerance message} {
set nbval [llength $listval]
if { $nbval < 3} {
if { $nbval < 5} {
return 0
}

View File

@@ -702,20 +702,25 @@ Handle(Font_SystemFont) Font_FontMgr::FindFont (const TCollection_AsciiString& t
}
// Trying to use font names mapping
Handle(Font_FontAliasSequence) anAliases;
const Standard_Boolean hasAliases = myFontAliases.Find (aFontName, anAliases)
&& !anAliases.IsNull()
&& !anAliases->IsEmpty();
if (!hasAliases
&& aFont.IsNull())
for (int aPass = 0; aPass < 2; ++aPass)
{
anAliases = myFallbackAlias;
}
Handle(Font_FontAliasSequence) anAliases;
if (aPass == 0)
{
myFontAliases.Find (aFontName, anAliases);
}
else
{
anAliases = myFallbackAlias;
}
bool isAliasUsed = false, isBestAlias = false;
if (!anAliases.IsNull()
&& !anAliases->IsEmpty())
{
if (anAliases.IsNull()
|| anAliases->IsEmpty())
{
continue;
}
bool isAliasUsed = false, isBestAlias = false;
for (Font_FontAliasSequence::Iterator anAliasIter (*anAliases); anAliasIter.More(); anAliasIter.Next())
{
const Font_FontAlias& anAlias = anAliasIter.Value();
@@ -737,24 +742,29 @@ Handle(Font_SystemFont) Font_FontMgr::FindFont (const TCollection_AsciiString& t
}
else if (anAlias.FontAspect == Font_FontAspect_UNDEFINED
&& (theFontAspect == Font_FontAspect_UNDEFINED
|| aFont2->HasFontAspect (theFontAspect)))
|| aFont2->HasFontAspect (theFontAspect)))
{
isBestAlias = true;
break;
}
}
}
if (hasAliases)
if (aPass == 0)
{
if (isAliasUsed && myToTraceAliases)
{
Message::DefaultMessenger()->Send (TCollection_AsciiString("Font_FontMgr, using font alias '") + aFont->FontName() + "'"
" instead of requested '" + theFontName +"'", Message_Trace);
" instead of requested '" + theFontName +"'", Message_Trace);
}
if (isBestAlias)
{
return aFont;
}
else if (!aFont.IsNull())
{
break;
}
}
}

View File

@@ -1,6 +1,5 @@
GeometryTest.cxx
GeometryTest.hxx
GeometryTest_API2dCommands.cxx
GeometryTest_APICommands.cxx
GeometryTest_ConstraintCommands.cxx
GeometryTest_ContinuityCommands.cxx

View File

@@ -14,9 +14,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
// modified by mps (dec 96) ajout de ContinuityCommands
// jpi 09/06/97 utilisation des commandes de GeomliteTest
#include <GeometryTest.hxx>
#include <GeomliteTest.hxx>
#include <Standard_Boolean.hxx>
@@ -34,10 +31,6 @@ void GeometryTest::AllCommands(Draw_Interpretor& theCommands)
GeometryTest::FairCurveCommands(theCommands);
GeometryTest::SurfaceCommands(theCommands);
GeometryTest::ConstraintCommands(theCommands);
// See bug #0030366
// GeometryTest::API2dCommands(theCommands);
GeometryTest::APICommands(theCommands);
GeometryTest::ContinuityCommands(theCommands);
GeometryTest::TestProjCommands(theCommands);

View File

@@ -50,15 +50,8 @@ public:
//! defines cosntrained curves commands.
Standard_EXPORT static void ConstraintCommands (Draw_Interpretor& I);
//! defines commands to test the Geom2dAPI
//! - Intersection
//! - Extrema
//! - Projection
//! - Approximation, interpolation
Standard_EXPORT static void API2dCommands (Draw_Interpretor& I);
//! defines commands to test the Geom2dAPI
//! defines commands to test the GeomAPI
//! - Intersection
//! - Extrema
//! - Projection
@@ -76,27 +69,6 @@ public:
//! defines commands to test projection of geometric objects
Standard_EXPORT static void TestProjCommands (Draw_Interpretor& I);
protected:
private:
};
#endif // _GeometryTest_HeaderFile

View File

@@ -1,287 +0,0 @@
// Created on: 1995-01-11
// Created by: Remi LEQUETTE
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <GeometryTest.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <DrawTrSurf.hxx>
#include <Draw_Appli.hxx>
#include <DrawTrSurf_Curve2d.hxx>
#include <Geom2dAPI_ProjectPointOnCurve.hxx>
#include <Geom2dAPI_ExtremaCurveCurve.hxx>
#include <Geom2dAPI_PointsToBSpline.hxx>
#include <Geom2dAPI_InterCurveCurve.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <gp_Pnt.hxx>
#include <Draw_Marker2D.hxx>
#include <Draw_Color.hxx>
#include <Draw_MarkerShape.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <GeomAbs_Shape.hxx>
#include <stdio.h>
#ifdef _WIN32
Standard_IMPORT Draw_Viewer dout;
#endif
//=======================================================================
//function : proj
//purpose :
//=======================================================================
static Standard_Integer proj (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if ( n < 4) return 1;
gp_Pnt2d P(Draw::Atof(a[2]),Draw::Atof(a[3]));
char name[100];
Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
if (GC.IsNull())
return 1;
Geom2dAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(),
GC->LastParameter());
for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
gp_Pnt2d P1 = proj.Point(i);
Handle(Geom2d_Line) L = new Geom2d_Line(P,gp_Vec2d(P,P1));
Handle(Geom2d_TrimmedCurve) CT =
new Geom2d_TrimmedCurve(L, 0., P.Distance(P1));
Sprintf(name,"%s%d","ext_",i);
char* temp = name; // portage WNT
DrawTrSurf::Set(temp, CT);
di << name << " ";
}
return 0;
}
//=======================================================================
//function : appro
//purpose :
//=======================================================================
static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const char** a)
{
// Approximation et interpolation 2d
// 2dappro
// - affiche la tolerance
// 2dappro tol
// - change la tolerance
// 2dappro result nbpoint
// - saisie interactive
// 2dappro result nbpoint curve
// - calcule des points sur la courbe
// 2dappro result nbpoint x1 y1 x2 y2 ..
// - tableau de points
// 2dappro result nbpoint x1 dx y1 y2 ..
// - tableau de points (x1,y1) (x1+dx,y2) ... avec x = t
static Standard_Real Tol2d = 1.e-6;
if (n < 3) {
if (n == 2)
Tol2d = Draw::Atof(a[1]);
di << "Tolerance for 2d approx : "<< Tol2d << "\n";
return 0;
}
Standard_Integer i, Nb = Draw::Atoi(a[2]);
Standard_Boolean hasPoints = Standard_True;
TColgp_Array1OfPnt2d Points(1, Nb);
TColStd_Array1OfReal YValues(1,Nb);
Standard_Real X0=0,DX=0;
Handle(Draw_Marker2D) mark;
if (n == 3) {
// saisie interactive
Standard_Integer id,XX,YY,b;
dout.Select(id,XX,YY,b);
Standard_Real zoom = dout.Zoom(id);
Points(1) = gp_Pnt2d( ((Standard_Real)XX)/zoom,
((Standard_Real)YY)/zoom );
mark = new Draw_Marker2D( Points(1), Draw_X, Draw_vert);
dout << mark;
for (Standard_Integer j = 2; j<=Nb; j++) {
dout.Select(id,XX,YY,b);
Points(j) = gp_Pnt2d( ((Standard_Real)XX)/zoom,
((Standard_Real)YY)/zoom );
mark = new Draw_Marker2D( Points(j), Draw_X, Draw_vert);
dout << mark;
}
}
else {
if ( n == 4) {
// points sur courbe
Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[3]);
if ( GC.IsNull())
return 1;
Standard_Real U, U1, U2;
U1 = GC->FirstParameter();
U2 = GC->LastParameter();
Standard_Real Delta = ( U2 - U1) / (Nb-1);
for ( i = 1 ; i <= Nb; i++) {
U = U1 + (i-1) * Delta;
Points(i) = GC->Value(U);
}
}
else {
// test points ou ordonnees
hasPoints = Standard_False;
Standard_Integer nc = n - 3;
if (nc == 2 * Nb) {
// points
nc = 3;
for (i = 1; i <= Nb; i++) {
Points(i).SetCoord(Draw::Atof(a[nc]),Draw::Atof(a[nc+1]));
nc += 2;
}
}
else if (nc - 2 == Nb) {
// YValues
nc = 5;
X0 = Draw::Atof(a[3]);
DX = Draw::Atof(a[4]);
for (i = 1; i <= Nb; i++) {
YValues(i) = Draw::Atof(a[nc]);
Points(i).SetCoord(X0+(i-1)*DX,YValues(i));
nc++;
}
}
else
return 1;
}
// display the points
for ( i = 1 ; i <= Nb; i++) {
mark = new Draw_Marker2D( Points(i), Draw_X, Draw_vert);
dout << mark;
}
}
dout.Flush();
Standard_Integer Dmin = 3;
Standard_Integer Dmax = 8;
Handle(Geom2d_BSplineCurve) TheCurve;
if (hasPoints)
TheCurve = Geom2dAPI_PointsToBSpline(Points,Dmin,Dmax,GeomAbs_C2,Tol2d);
else
TheCurve = Geom2dAPI_PointsToBSpline(YValues,X0,DX,Dmin,Dmax,GeomAbs_C2,Tol2d);
DrawTrSurf::Set(a[1], TheCurve);
di << a[1];
return 0;
}
//=======================================================================
//function : intersect
//purpose :
//=======================================================================
static Standard_Integer intersect(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
{
if( n < 2)
return 1;
Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]);
if ( C1.IsNull())
return 1;
Standard_Real Tol = 0.001;
Geom2dAPI_InterCurveCurve Intersector;
Handle(Geom2d_Curve) C2;
if ( n == 3) {
C2 = DrawTrSurf::GetCurve2d(a[2]);
if ( C2.IsNull())
return 1;
Intersector.Init(C1,C2,Tol);
}
else {
Intersector.Init(C1, Tol);
}
Standard_Integer i;
for ( i = 1; i <= Intersector.NbPoints(); i++) {
gp_Pnt2d P = Intersector.Point(i);
Handle(Draw_Marker2D) mark = new Draw_Marker2D( P, Draw_X, Draw_vert);
dout << mark;
}
dout.Flush();
Handle(Geom2d_Curve) S1,S2;
Handle(DrawTrSurf_Curve2d) CD;
if ( n == 3) {
for ( i = 1; i <= Intersector.NbSegments(); i++) {
Intersector.Segment(i,S1,S2);
CD = new DrawTrSurf_Curve2d(S1, Draw_bleu, 30);
dout << CD;
CD = new DrawTrSurf_Curve2d(S2, Draw_violet, 30);
dout << CD;
}
}
dout.Flush();
return 0;
}
void GeometryTest::API2dCommands(Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) return;
const char *g;
done = Standard_True;
g = "GEOMETRY curves and surfaces analysis";
theCommands.Add("2dproj", "proj curve x y",__FILE__, proj,g);
g = "GEOMETRY approximations";
theCommands.Add("2dapprox", "2dapprox result nbpoint [curve] [[x] y [x] y...]",__FILE__,
appro,g);
theCommands.Add("2dinterpole", "2dinterpole result nbpoint [curve] [[x] y [x] y ...]",__FILE__,
appro,g);
g = "GEOMETRY curves and surfaces analysis";
g = "GEOMETRY intersections";
theCommands.Add("2dintersect", "intersect curve curve",__FILE__,
intersect,g);
}

View File

@@ -32,6 +32,7 @@ Graphic3d_AspectFillArea3d::Graphic3d_AspectFillArea3d()
myEdgeType (Aspect_TOL_SOLID),
myEdgeWidth (1.0f),
myHatchStyle (Handle(Graphic3d_HatchStyle)()),
myToSkipFirstEdge (false),
myToDistinguishMaterials (false),
myToDrawEdges (false),
myToSuppressBackFaces (true),
@@ -63,6 +64,7 @@ Graphic3d_AspectFillArea3d::Graphic3d_AspectFillArea3d (const Aspect_InteriorSty
myEdgeType (theEdgeLineType),
myEdgeWidth ((float )theEdgeLineWidth),
myHatchStyle (Handle(Graphic3d_HatchStyle)()),
myToSkipFirstEdge (false),
myToDistinguishMaterials (false),
myToDrawEdges (false),
myToSuppressBackFaces (true),

View File

@@ -255,19 +255,26 @@ public:
public:
//! Returns true if edges should be drawn (false by default).
bool ToDrawEdges() const { return myToDrawEdges; }
bool ToDrawEdges() const { return myToDrawEdges && myEdgeType != Aspect_TOL_EMPTY; }
//! Set if edges should be drawn or not.
void SetDrawEdges (bool theToDraw) { myToDrawEdges = theToDraw; }
void SetDrawEdges (bool theToDraw)
{
myToDrawEdges = theToDraw;
if (myEdgeType == Aspect_TOL_EMPTY)
{
myEdgeType = Aspect_TOL_SOLID;
}
}
//! Returns true if edges should be drawn.
bool Edge() const { return myToDrawEdges; }
bool Edge() const { return ToDrawEdges(); }
//! The edges of FillAreas are drawn.
void SetEdgeOn() { myToDrawEdges = true; }
void SetEdgeOn() { SetDrawEdges (true); }
//! The edges of FillAreas are not drawn.
void SetEdgeOff() { myToDrawEdges = false; }
void SetEdgeOff() { SetDrawEdges (false); }
//! Return color of edges.
const Quantity_Color& EdgeColor() const { return myEdgeColor.GetRGB(); }
@@ -278,6 +285,9 @@ public:
//! Modifies the color of the edge of the face
void SetEdgeColor (const Quantity_Color& theColor) { myEdgeColor.SetRGB (theColor); }
//! Modifies the color of the edge of the face
void SetEdgeColor (const Quantity_ColorRGBA& theColor) { myEdgeColor = theColor; }
//! Return edges line type.
Aspect_TypeOfLine EdgeLineType() const { return myEdgeType; }
@@ -298,6 +308,18 @@ public:
myEdgeWidth = (float )theWidth;
}
//! Returns TRUE if drawing element edges should discard first edge in triangle; FALSE by default.
//! Graphics hardware works mostly with triangles, so that wireframe presentation will draw triangle edges by default.
//! This flag allows rendering wireframe presentation of quad-only array split into triangles.
//! For this, quads should be split in specific order, so that the quad diagonal (to be NOT rendered) goes first:
//! 1------2
//! / / Triangle #1: 2-0-1; Triangle #2: 0-2-3
//! 0------3
bool ToSkipFirstEdge() const { return myToSkipFirstEdge; }
//! Set skip first triangle edge flag for drawing wireframe presentation of quads array split into triangles.
void SetSkipFirstEdge (bool theToSkipFirstEdge) { myToSkipFirstEdge = theToSkipFirstEdge; }
public:
//! Returns the hatch type used when InteriorStyle is IS_HATCH
@@ -370,6 +392,7 @@ protected:
Handle(Graphic3d_HatchStyle) myHatchStyle;
Graphic3d_PolygonOffset myPolygonOffset;
bool myToSkipFirstEdge;
bool myToDistinguishMaterials;
bool myToDrawEdges;
bool myToSuppressBackFaces;

View File

@@ -94,11 +94,12 @@ public:
Graphic3d_RenderingParams()
: Method (Graphic3d_RM_RASTERIZATION),
TransparencyMethod (Graphic3d_RTM_BLEND_UNORDERED),
LineFeather (1.0f),
OitDepthFactor (0.0f),
NbMsaaSamples (0),
RenderResolutionScale (1.0f),
ToEnableDepthPrepass (Standard_False),
ToEnableAlphaToCoverage (Standard_False),
ToEnableAlphaToCoverage (Standard_True),
// ray tracing parameters
IsGlobalIlluminationEnabled (Standard_False),
RaytracingDepth (THE_DEFAULT_DEPTH),
@@ -109,10 +110,12 @@ public:
UseEnvironmentMapBackground (Standard_False),
CoherentPathTracingMode (Standard_False),
AdaptiveScreenSampling (Standard_False),
AdaptiveScreenSamplingAtomic(Standard_False),
ShowSamplingTiles (Standard_False),
TwoSidedBsdfModels (Standard_False),
RadianceClampingValue (30.0),
RebuildRayTracingShaders (Standard_False),
RayTracingTileSize (32),
NbRayTracingTiles (16 * 16),
CameraApertureRadius (0.0f),
CameraFocalPlaneDist (1.0f),
@@ -166,12 +169,14 @@ public:
Graphic3d_RenderingMode Method; //!< specifies rendering mode, Graphic3d_RM_RASTERIZATION by default
Graphic3d_RenderTransparentMethod TransparencyMethod; //!< specifies rendering method for transparent graphics
Standard_ShortReal LineFeather; //!< line feater width in pixels (> 0.0), 1.0 by default;
//! high values produce blurred results, small values produce sharp (aliased) edges
Standard_ShortReal OitDepthFactor; //!< scalar factor [0-1] controlling influence of depth of a fragment to its final coverage
Standard_Integer NbMsaaSamples; //!< number of MSAA samples (should be within 0..GL_MAX_SAMPLES, power-of-two number), 0 by default
Standard_ShortReal RenderResolutionScale; //!< rendering resolution scale factor, 1 by default;
//! incompatible with MSAA (e.g. NbMsaaSamples should be set to 0)
Standard_Boolean ToEnableDepthPrepass; //!< enables/disables depth pre-pass, False by default
Standard_Boolean ToEnableAlphaToCoverage; //!< enables/disables alpha to coverage, False by default
Standard_Boolean ToEnableAlphaToCoverage; //!< enables/disables alpha to coverage, True by default
Standard_Boolean IsGlobalIlluminationEnabled; //!< enables/disables global illumination effects (path tracing)
Standard_Integer SamplesPerPixel; //!< number of samples per pixel (SPP)
@@ -183,11 +188,15 @@ public:
Standard_Boolean UseEnvironmentMapBackground; //!< enables/disables environment map background
Standard_Boolean CoherentPathTracingMode; //!< enables/disables 'coherent' tracing mode (single RNG seed within 16x16 image blocks)
Standard_Boolean AdaptiveScreenSampling; //!< enables/disables adaptive screen sampling mode for path tracing, FALSE by default
Standard_Boolean AdaptiveScreenSamplingAtomic;//!< enables/disables usage of atomic float operations within adaptive screen sampling, FALSE by default
Standard_Boolean ShowSamplingTiles; //!< enables/disables debug mode for adaptive screen sampling, FALSE by default
Standard_Boolean TwoSidedBsdfModels; //!< forces path tracing to use two-sided versions of original one-sided scattering models
Standard_ShortReal RadianceClampingValue; //!< maximum radiance value used for clamping radiance estimation.
Standard_Boolean RebuildRayTracingShaders; //!< forces rebuilding ray tracing shaders at the next frame
Standard_Integer NbRayTracingTiles; //!< total number of screen tiles used in adaptive sampling mode (PT only)
Standard_Integer RayTracingTileSize; //!< screen tile size, 32 by default (adaptive sampling mode of path tracing);
Standard_Integer NbRayTracingTiles; //!< maximum number of screen tiles per frame, 256 by default (adaptive sampling mode of path tracing);
//! this parameter limits the number of tiles to be rendered per redraw, increasing Viewer interactivity,
//! but also increasing the time for achieving a good quality; -1 means no limit
Standard_ShortReal CameraApertureRadius; //!< aperture radius of perspective camera used for depth-of-field, 0.0 by default (no DOF) (path tracing only)
Standard_ShortReal CameraFocalPlaneDist; //!< focal distance of perspective camera used for depth-of field, 1.0 by default (path tracing only)
FrustumCulling FrustumCullingState; //!< state of frustum culling optimization; FrustumCulling_On by default

View File

@@ -28,9 +28,11 @@ enum Graphic3d_TypeOfLimit
Graphic3d_TypeOfLimit_HasRayTracing, //!< indicates whether ray tracing is supported
Graphic3d_TypeOfLimit_HasRayTracingTextures, //!< indicates whether ray tracing textures are supported
Graphic3d_TypeOfLimit_HasRayTracingAdaptiveSampling, //!< indicates whether adaptive screen sampling is supported
Graphic3d_TypeOfLimit_HasRayTracingAdaptiveSamplingAtomic,//!< indicates whether optimized adaptive screen sampling is supported (hardware supports atomic float operations)
Graphic3d_TypeOfLimit_HasBlendedOit, //!< indicates whether necessary GL extensions for Weighted, Blended OIT available (without MSAA).
Graphic3d_TypeOfLimit_HasBlendedOitMsaa, //!< indicates whether necessary GL extensions for Weighted, Blended OIT available (with MSAA).
Graphic3d_TypeOfLimit_HasFlatShading, //!< indicates whether Flat shading (Graphic3d_TOSM_FACET) is supported
Graphic3d_TypeOfLimit_HasMeshEdges, //!< indicates whether advanced mesh edges presentation is supported
Graphic3d_TypeOfLimit_IsWorkaroundFBO, //!< indicates whether workaround for Intel driver problem with empty FBO for images with big width is applyed.
Graphic3d_TypeOfLimit_NB //!< number of elements in this enumeration
};

View File

@@ -193,10 +193,12 @@ void IVtkOCC_ViewerSelector::Activate (const Handle(SelectMgr_Selection)& theSel
aSelEntIter.Value()->SetActiveForSelection();
}
theSelection->SetSelectionState (SelectMgr_SOS_Activated);
myTolerances.Add (theSelection->Sensitivity());
myToUpdateTolerance = Standard_True;
if (theSelection->GetSelectionState() != SelectMgr_SOS_Activated)
{
theSelection->SetSelectionState (SelectMgr_SOS_Activated);
myTolerances.Add (theSelection->Sensitivity());
myToUpdateTolerance = Standard_True;
}
}
//============================================================================
@@ -210,8 +212,10 @@ void IVtkOCC_ViewerSelector::Deactivate (const Handle(SelectMgr_Selection)& theS
aSelEntIter.Value()->ResetSelectionActiveStatus();
}
theSelection->SetSelectionState (SelectMgr_SOS_Deactivated);
myTolerances.Decrement (theSelection->Sensitivity());
myToUpdateTolerance = Standard_True;
if (theSelection->GetSelectionState() == SelectMgr_SOS_Activated)
{
theSelection->SetSelectionState (SelectMgr_SOS_Deactivated);
myTolerances.Decrement (theSelection->Sensitivity());
myToUpdateTolerance = Standard_True;
}
}

View File

@@ -50,7 +50,7 @@ class IVtkTools_ShapeDataSource;
class Standard_EXPORT IVtkTools_ShapeObject : public vtkDataObject
{
public:
vtkTypeMacro (IVtkTools_ShapeObject, vtkObject)
vtkTypeMacro (IVtkTools_ShapeObject, vtkDataObject)
static IVtkTools_ShapeObject* New();

View File

@@ -22,7 +22,6 @@
#include <vtkCellData.h>
#include <vtkDoubleArray.h>
#include <vtkIdList.h>
#include <vtkIdTypeArray.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#ifdef _MSC_VER
@@ -80,10 +79,7 @@ void IVtkVTK_ShapeData::InsertVertex (const IVtk_IdType theShapeID,
{
vtkIdType aPointIdVTK = thePointId;
myPolyData->InsertNextCell (VTK_VERTEX, 1, &aPointIdVTK);
const vtkIdType aShapeIDVTK = theShapeID;
mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
const vtkIdType aType = theMeshType;
myMeshTypes->InsertNextTupleValue (&aType);
insertNextSubShapeId (theShapeID, theMeshType);
}
//================================================================
@@ -97,10 +93,7 @@ void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
{
vtkIdType aPoints[2] = { thePointId1, thePointId2 };
myPolyData->InsertNextCell (VTK_LINE, 2, aPoints);
const vtkIdType aShapeIDVTK = theShapeID;
mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
const vtkIdType aType = theMeshType;
myMeshTypes->InsertNextTupleValue (&aType);
insertNextSubShapeId (theShapeID, theMeshType);
}
//================================================================
@@ -124,10 +117,7 @@ void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
}
myPolyData->InsertNextCell (VTK_POLY_LINE, anIdList);
const vtkIdType aShapeIDVTK = theShapeID;
mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
const vtkIdType aType = theMeshType;
myMeshTypes->InsertNextTupleValue (&aType);
insertNextSubShapeId (theShapeID, theMeshType);
}
}
@@ -143,8 +133,5 @@ void IVtkVTK_ShapeData::InsertTriangle (const IVtk_IdType theShapeID,
{
vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
myPolyData->InsertNextCell (VTK_TRIANGLE, 3, aPoints);
const vtkIdType aShapeIDVTK = theShapeID;
mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
const vtkIdType aType = theMeshType;
myMeshTypes->InsertNextTupleValue (&aType);
insertNextSubShapeId (theShapeID, theMeshType);
}

View File

@@ -24,6 +24,7 @@
#endif
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkIdTypeArray.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
@@ -105,6 +106,23 @@ public: //! @name Specific methods
vtkPolyData* getVtkPolyData() const
{ return myPolyData; }
private:
//! Wrapper over vtkGenericDataArray::InsertNextTypedTuple().
void insertNextSubShapeId (IVtk_IdType theShapeID,
IVtk_MeshType theMeshType)
{
const vtkIdType aShapeIDVTK = theShapeID;
const vtkIdType aType = theMeshType;
#if (VTK_MAJOR_VERSION > 7) || (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION >= 1)
mySubShapeIDs->InsertNextTypedTuple (&aShapeIDVTK);
myMeshTypes->InsertNextTypedTuple (&aType);
#else
mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
myMeshTypes->InsertNextTupleValue (&aType);
#endif
}
private:
vtkSmartPointer< vtkPolyData > myPolyData; //!< Shape geometry as vtkPolyData
vtkSmartPointer< vtkIdTypeArray > mySubShapeIDs; //!< Array of sub-shapes ids

View File

@@ -7,5 +7,6 @@ Image_Format.hxx
Image_PixMap.cxx
Image_PixMap.hxx
Image_PixMapData.hxx
Image_PixMapTypedData.hxx
Image_VideoRecorder.cxx
Image_VideoRecorder.hxx

View File

@@ -38,7 +38,7 @@ public:
}
//! Initializer.
void Init (const Handle(NCollection_BaseAllocator)& theAlloc,
bool Init (const Handle(NCollection_BaseAllocator)& theAlloc,
const Standard_Size theSizeBPP,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
@@ -59,6 +59,16 @@ public:
Allocate (mySize);
}
SetTopDown (TopToDown == 1);
return !IsEmpty();
}
//! Reset all values to zeros.
void ZeroData()
{
if (myData != NULL)
{
memset (myData, 0, mySize);
}
}
//! @return data pointer to requested row (first column).

View File

@@ -0,0 +1,64 @@
// Copyright (c) 2019 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Image_PixMapTypedData_Header
#define _Image_PixMapTypedData_Header
#include <Image_PixMapData.hxx>
//! Structure to manage image buffer with predefined pixel type.
template<typename PixelType_t>
class Image_PixMapTypedData : public Image_PixMapData
{
public:
//! Empty constructor.
Image_PixMapTypedData() {}
//! Initializer.
bool Init (const Handle(NCollection_BaseAllocator)& theAlloc,
Standard_Size theSizeX,
Standard_Size theSizeY,
Standard_Size theSizeRowBytes = 0,
Standard_Byte* theDataPtr = 0)
{
const Standard_Size aSizeBPP = sizeof(PixelType_t);
return Image_PixMapData::Init (theAlloc, aSizeBPP, theSizeX, theSizeY, theSizeRowBytes, theDataPtr);
}
//! Reset all values to specified one.
void Init (const PixelType_t& theValue)
{
for (Standard_Size aRowIter = 0; aRowIter < SizeY; ++aRowIter)
{
for (Standard_Size aColIter = 0; aColIter < SizeX; ++aColIter)
{
ChangeValue (aRowIter, aColIter) = theValue;
}
}
}
//! @return data pointer to requested row (first column).
const PixelType_t* Row (Standard_Size theRow) const { return (const PixelType_t* )Image_PixMapData::Row (theRow); }
//! @return data pointer to requested row (first column).
PixelType_t* ChangeRow (Standard_Size theRow) { return (PixelType_t* )Image_PixMapData::ChangeRow (theRow); }
//! @return data pointer to requested position.
const PixelType_t& Value (Standard_Size theRow, Standard_Size theCol) const { return *(const PixelType_t* )Image_PixMapData::Value (theRow, theCol); }
//! @return data pointer to requested position.
PixelType_t& ChangeValue (Standard_Size theRow, Standard_Size theCol) { return *(PixelType_t* )Image_PixMapData::ChangeValue (theRow, theCol); }
};
#endif // _Image_PixMapTypedData_Header

View File

@@ -27,8 +27,11 @@
* Purpose: The class Array2 represents bi-dimensional arrays
* of fixed size known at run time.
* The ranges of indices are user defined.
*
* Warning: Programs clients of such class must be independant
*
* Class allocates one 1D array storing full data (all Rows and Columns)
* and extra 1D array storing pointers to each Row.
*
* Warning: Programs clients of such class must be independent
* of the range of the first element. Then, a C++ for
* loop must be written like this
*
@@ -85,6 +88,20 @@ public:
public:
// ---------- PUBLIC METHODS ------------
//! Empty constructor; should be used with caution.
//! @sa methods Resize() and Move().
NCollection_Array2()
: myLowerRow (1),
myUpperRow (0),
myLowerCol (1),
myUpperCol (0),
myData (NULL),
myStart (NULL),
myDeletable(false)
{
//
}
//! Constructor
NCollection_Array2(const Standard_Integer theRowLower,
const Standard_Integer theRowUpper,
@@ -109,6 +126,23 @@ public:
*this = theOther;
}
#ifndef OCCT_NO_RVALUE_REFERENCE
//! Move constructor
NCollection_Array2 (NCollection_Array2&& theOther)
: myLowerRow (theOther.myLowerRow),
myUpperRow (theOther.myUpperRow),
myLowerCol (theOther.myLowerRow),
myUpperCol (theOther.myUpperCol),
myData (theOther.myData),
myStart (theOther.myStart),
myDeletable(theOther.myDeletable)
{
theOther.myStart = NULL;
theOther.myData = NULL;
theOther.myDeletable = false;
}
#endif
//! C array-based constructor
NCollection_Array2(const TheItemType& theBegin,
const Standard_Integer theRowLower,
@@ -138,15 +172,19 @@ public:
{ return Length(); }
//! Length (number of items)
Standard_Integer Length (void) const
{ return RowLength() * ColLength(); }
{ return NbRows() * NbColumns(); }
//! Returns number of rows
Standard_Integer NbRows() const { return myUpperRow - myLowerRow + 1; }
//! Returns number of columns
Standard_Integer NbColumns() const { return myUpperCol - myLowerCol + 1; }
//! Returns length of the row, i.e. number of columns
Standard_Integer RowLength (void) const
{ return (myUpperCol-myLowerCol+1); }
Standard_Integer RowLength() const { return NbColumns(); }
//! Returns length of the column, i.e. number of rows
Standard_Integer ColLength (void) const
{ return (myUpperRow-myLowerRow+1); }
Standard_Integer ColLength() const { return NbRows(); }
//! LowerRow
Standard_Integer LowerRow (void) const
@@ -179,12 +217,53 @@ public:
return *this;
}
//! Move assignment.
//! This array will borrow all the data from theOther.
//! The moved object will be left unitialized and should not be used anymore.
NCollection_Array2& Move (NCollection_Array2& theOther)
{
if (&theOther == this)
{
return *this;
}
if (myDeletable)
{
delete[] myStart;
}
if (myData != NULL)
{
delete[] &(myData[myLowerRow]);
}
myLowerRow = theOther.myLowerRow;
myUpperRow = theOther.myUpperRow;
myLowerCol = theOther.myLowerRow;
myUpperCol = theOther.myUpperCol;
myData = theOther.myData;
myStart = theOther.myStart;
myDeletable = theOther.myDeletable;
theOther.myStart = NULL;
theOther.myData = NULL;
theOther.myDeletable = Standard_False;
return *this;
}
//! Assignment operator
NCollection_Array2& operator= (const NCollection_Array2& theOther)
{
return Assign (theOther);
}
#ifndef OCCT_NO_RVALUE_REFERENCE
//! Move assignment operator; @sa Move()
NCollection_Array2& operator= (NCollection_Array2&& theOther)
{
return Move (theOther);
}
#endif
//! Constant value access
const TheItemType& Value (const Standard_Integer theRow,
const Standard_Integer theCol) const
@@ -222,12 +301,86 @@ public:
theCol < myLowerCol || theCol > myUpperCol, "NCollection_Array2::SetValue");
myData[theRow][theCol] = theItem;
}
//! Resizes the array to specified bounds.
//! No re-allocation will be done if length of array does not change,
//! but existing values will not be discarded if theToCopyData set to FALSE.
//! @param theRowLower new lower Row of array
//! @param theRowUpper new upper Row of array
//! @param theColLower new lower Column of array
//! @param theColUpper new upper Column of array
//! @param theToCopyData flag to copy existing data into new array
void Resize (Standard_Integer theRowLower,
Standard_Integer theRowUpper,
Standard_Integer theColLower,
Standard_Integer theColUpper,
Standard_Boolean theToCopyData)
{
Standard_RangeError_Raise_if (theRowUpper < theRowLower
|| theColUpper < theColLower, "NCollection_Array2::Resize");
const Standard_Integer anOldNbRows = NbRows();
const Standard_Integer anOldNbCols = NbColumns();
const Standard_Integer aLowerRowOld = myLowerRow;
const Standard_Integer aLowerColOld = myLowerCol;
const Standard_Integer aNewNbRows = theRowUpper - theRowLower + 1;
const Standard_Integer aNewNbCols = theColUpper - theColLower + 1;
TheItemType* aStartOld = myStart;
TheItemType** aTableOld = myData != NULL ? myData + aLowerRowOld : NULL;
myLowerRow = theRowLower;
myUpperRow = theRowUpper;
myLowerCol = theColLower;
myUpperCol = theColUpper;
if (aNewNbRows == anOldNbRows
&& aNewNbCols == anOldNbCols)
{
if (myLowerCol != aLowerColOld)
{
fillIndexTable (aTableOld);
}
myData = aTableOld - myLowerRow;
return;
}
if (myDeletable
&& !theToCopyData)
{
delete[] aStartOld;
}
delete[] aTableOld;
Allocate();
if (!theToCopyData)
{
myDeletable = Standard_True;
return;
}
const Standard_Integer aNbRowsToCopy = Min (anOldNbRows, aNewNbRows);
const Standard_Integer aNbColsToCopy = Min (anOldNbCols, aNewNbCols);
for (Standard_Integer aRowIter = 0; aRowIter < aNbRowsToCopy; ++aRowIter)
{
for (Standard_Integer aColIter = 0; aColIter < aNbColsToCopy; ++aColIter)
{
myStart[size_t(aRowIter) * size_t(aNewNbCols) + size_t(aColIter)] = aStartOld[size_t(aRowIter) * size_t(anOldNbCols) + size_t(aColIter)];
}
}
if (myDeletable)
{
delete[] aStartOld;
}
myDeletable = Standard_True;
}
//! Destructor - releases the memory
~NCollection_Array2 (void)
{
if (myDeletable) delete [] myStart;
delete [] &(myData[myLowerRow]);
if (myData != NULL)
{
delete[] &(myData[myLowerRow]);
}
}
private:
@@ -236,28 +389,37 @@ public:
//! Allocate memory for the array, set up indirection table
void Allocate (void)
{
const Standard_Integer iRowSize = myUpperCol - myLowerCol + 1;
const Standard_Integer iColSize = myUpperRow - myLowerRow + 1;
Standard_RangeError_Raise_if (iRowSize <= 0 || iColSize <= 0, "NCollection_Array2::Allocate");
if (myDeletable) {
const Standard_Integer aNbRows = NbRows();
const Standard_Integer aNbCols = NbColumns();
Standard_RangeError_Raise_if (aNbRows <= 0 || aNbCols <= 0, "NCollection_Array2::Allocate");
if (myDeletable)
{
// allocation of the data in the array
myStart = new TheItemType[iRowSize * iColSize];
myStart = new TheItemType[size_t(aNbRows) * size_t(aNbCols)];
Standard_OutOfMemory_Raise_if (!myStart, "NCollection_Array2 : Allocation failed");
}
// else myStart is set to the beginning of the given array
TheItemType** pTable = new TheItemType* [iColSize];
Standard_OutOfMemory_Raise_if (!pTable, "NCollection_Array2 : Allocation failed");
// Items of pTable point to the '0'th items in the rows of the array
TheItemType* pRow = myStart - myLowerCol;
for (Standard_Integer i = 0; i < iColSize; i++)
TheItemType** pTable = new TheItemType* [aNbRows];
Standard_OutOfMemory_Raise_if (!pTable, "NCollection_Array2 : Allocation failed");
fillIndexTable (pTable);
}
//! Fill index table for accessing array elements.
void fillIndexTable (TheItemType** theTable)
{
// Items of table point to the 0th items in the rows of the array
TheItemType* aRow = myStart - myLowerCol;
const Standard_Integer aNbRows = NbRows();
const Standard_Size aNbCols = NbColumns();
for (Standard_Integer aRowIter = 0; aRowIter < aNbRows; ++aRowIter)
{
pTable[i] = pRow;
pRow += iRowSize;
theTable[aRowIter] = aRow;
aRow += aNbCols;
}
// Set myData to the '0'th row pointer of the pTable
myData = pTable - myLowerRow;
// Set myData to the 0th row pointer of the table
myData = theTable - myLowerRow;
}
protected:

View File

@@ -177,7 +177,8 @@ Standard_EXPORT void IncAllocator_PrintAlive()
//purpose : Constructor
//=======================================================================
NCollection_IncAllocator::NCollection_IncAllocator (const size_t theBlockSize)
NCollection_IncAllocator::NCollection_IncAllocator (size_t theBlockSize)
: myMutex (NULL)
{
#ifdef ALLOC_TRACK_USAGE
printf ("\n..NCollection_IncAllocator: Created (%x)\n",this);
@@ -207,6 +208,7 @@ NCollection_IncAllocator::NCollection_IncAllocator (const size_t theBlockSize)
NCollection_IncAllocator::~NCollection_IncAllocator ()
{
delete myMutex;
#ifdef OCCT_DEBUG
if (IS_DEBUG)
Debug_Destroy(this);
@@ -215,6 +217,24 @@ NCollection_IncAllocator::~NCollection_IncAllocator ()
free (myFirstBlock);
}
//=======================================================================
//function : SetThreadSafe
//purpose :
//=======================================================================
void NCollection_IncAllocator::SetThreadSafe (bool theIsThreadSafe)
{
if (myMutex == NULL
&& theIsThreadSafe)
{
myMutex = new Standard_Mutex();
}
else if (!theIsThreadSafe)
{
delete myMutex;
myMutex = NULL;
}
}
//=======================================================================
//function : Allocate
//purpose : allocate a memory
@@ -226,6 +246,7 @@ void * NCollection_IncAllocator::Allocate (const size_t aSize)
aligned_t * aResult = NULL;
const size_t cSize = aSize ? IMEM_SIZE(aSize) : 0;
Standard_Mutex::Sentry aLock (myMutex);
if (cSize > mySize) {
/* If the requested size exceeds normal allocation size, allocate
a separate block and place it as the head of the list */
@@ -286,10 +307,12 @@ void * NCollection_IncAllocator::Reallocate (void * theAddress,
// Check that the dummy parameters are OK
if (theAddress == NULL || oldSize == 0)
return Allocate (newSize);
const size_t cOldSize = IMEM_SIZE(oldSize);
const size_t cNewSize = newSize ? IMEM_SIZE(newSize) : 0;
aligned_t * anAddress = (aligned_t *) theAddress;
Standard_Mutex::Sentry aLock (myMutex);
// We check only the LAST allocation to do the real extension/contraction
if (anAddress + cOldSize == myFirstBlock -> p_free_space) {
myFirstBlock -> p_free_space = anAddress;
@@ -372,6 +395,7 @@ void NCollection_IncAllocator::Clean ()
void NCollection_IncAllocator::Reset (const Standard_Boolean doReleaseMem)
{
Standard_Mutex::Sentry aLock (myMutex);
if (doReleaseMem)
Clean();
else {

View File

@@ -18,20 +18,26 @@
#include <NCollection_BaseAllocator.hxx>
class Standard_Mutex;
/**
* Class NCollection_IncAllocator - incremental memory allocator. This class
* allocates memory on request returning the pointer to an allocated
* block. This memory is never returned to the system until the allocator is
* destroyed.
*
*
* By comparison with the standard new() and malloc() calls, this method is
* faster and consumes very small additional memory to maintain the heap.
*
*
* All pointers returned by Allocate() are aligned to the size of the data
* type "aligned_t". To modify the size of memory blocks requested from the
* OS, use the parameter of the constructor (measured in bytes); if this
* parameter is smaller than 25 bytes on 32bit or 49 bytes on 64bit, the
* block size will be the default 24 kbytes
*
* Note that this allocator is most suitable for single-threaded algorithms
* (consider creating dedicated allocators per working thread),
* and thread-safety of allocations is DISABLED by default (see SetThreadSafe()).
*/
class NCollection_IncAllocator : public NCollection_BaseAllocator
{
@@ -41,8 +47,13 @@ class NCollection_IncAllocator : public NCollection_BaseAllocator
// ---------- PUBLIC METHODS ----------
//! Constructor
Standard_EXPORT NCollection_IncAllocator (const size_t theBlockSize = DefaultBlockSize);
//! Constructor.
//! Note that this constructor does NOT setup mutex for using allocator concurrently from different threads,
//! see SetThreadSafe() method.
Standard_EXPORT NCollection_IncAllocator (size_t theBlockSize = DefaultBlockSize);
//! Setup mutex for thread-safe allocations.
Standard_EXPORT void SetThreadSafe (bool theIsThreadSafe = true);
//! Allocate memory with given size. Returns NULL on failure
Standard_EXPORT virtual void* Allocate (const size_t size) Standard_OVERRIDE;
@@ -105,6 +116,7 @@ class NCollection_IncAllocator : public NCollection_BaseAllocator
};
protected:
// --------- PROTECTED FIELDS ---------
Standard_Mutex* myMutex;
IBlock * myFirstBlock;
size_t mySize;
size_t myMemSize;

View File

@@ -32,8 +32,6 @@
#include <Image_PixMap.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_AspectFace, OpenGl_Element)
namespace
{
//! Initialize default material in this way for backward compatibility.
@@ -68,7 +66,6 @@ OpenGl_AspectFace::OpenGl_AspectFace()
THE_DEFAULT_MATERIAL, THE_DEFAULT_MATERIAL)),
myShadingModel (Graphic3d_TOSM_UNLIT)
{
myAspectEdge = new OpenGl_AspectLine();
myAspect->SetShadingModel (myShadingModel);
myAspect->SetHatchStyle (Handle(Graphic3d_HatchStyle)());
}
@@ -80,8 +77,6 @@ OpenGl_AspectFace::OpenGl_AspectFace()
OpenGl_AspectFace::OpenGl_AspectFace (const Handle(Graphic3d_AspectFillArea3d)& theAspect)
: myShadingModel (Graphic3d_TOSM_DEFAULT)
{
myAspectEdge = new OpenGl_AspectLine();
SetAspect (theAspect);
}
@@ -102,9 +97,9 @@ void OpenGl_AspectFace::SetAspect (const Handle(Graphic3d_AspectFillArea3d)& the
? theAspect->ShadingModel()
: Graphic3d_TOSM_UNLIT;
myAspectEdge->Aspect()->SetColor (theAspect->EdgeColor());
myAspectEdge->Aspect()->SetType (theAspect->EdgeLineType());
myAspectEdge->Aspect()->SetWidth (theAspect->EdgeWidth());
myAspectEdge.Aspect()->SetColor (theAspect->EdgeColor());
myAspectEdge.Aspect()->SetType (theAspect->EdgeLineType());
myAspectEdge.Aspect()->SetWidth (theAspect->EdgeWidth());
// update texture binding
myResources.UpdateTexturesRediness (myAspect->TextureSet());

View File

@@ -28,7 +28,7 @@ class OpenGl_Texture;
//! The element holding Graphic3d_AspectFillArea3d.
class OpenGl_AspectFace : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_AspectFace, OpenGl_Element)
public:
//! Empty constructor.
@@ -44,10 +44,10 @@ public:
Standard_EXPORT void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
//! Set edge aspect.
void SetAspectEdge (const Handle(OpenGl_AspectLine)& theAspectEdge) { myAspectEdge = theAspectEdge; }
void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge) { myAspectEdge = *theAspectEdge; }
//! @return edge aspect.
const Handle(OpenGl_AspectLine)& AspectEdge() const { return myAspectEdge; }
const OpenGl_AspectLine* AspectEdge() const { return &myAspectEdge; }
//! Returns Shading Model.
Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
@@ -140,7 +140,7 @@ protected:
} myResources;
Handle(Graphic3d_AspectFillArea3d) myAspect;
Handle(OpenGl_AspectLine) myAspectEdge;
OpenGl_AspectLine myAspectEdge;
Graphic3d_TypeOfShadingModel myShadingModel;
public:

View File

@@ -21,8 +21,6 @@
#include <OpenGl_ShaderProgram.hxx>
#include <OpenGl_Workspace.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_AspectLine, OpenGl_Element)
namespace
{
static const TCollection_AsciiString THE_EMPTY_KEY;

View File

@@ -26,7 +26,6 @@ class OpenGl_ShaderProgram;
//! The element holding Graphic3d_AspectLine3d.
class OpenGl_AspectLine : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_AspectLine, OpenGl_Element)
public:
//! Empty constructor.

View File

@@ -27,8 +27,6 @@
#include <NCollection_Vec4.hxx>
#include <TColStd_HArray1OfByte.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_AspectMarker, OpenGl_Element)
namespace
{
static const TCollection_AsciiString THE_EMPTY_KEY;

View File

@@ -29,7 +29,6 @@ class OpenGl_ShaderProgram;
//! The element holding Graphic3d_AspectMarker3d.
class OpenGl_AspectMarker : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_AspectMarker, OpenGl_Element)
public:
//! Empty constructor.

View File

@@ -21,8 +21,6 @@
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_ShaderProgram.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_AspectText, OpenGl_Element)
namespace
{
static const TCollection_AsciiString THE_EMPTY_KEY;

View File

@@ -28,7 +28,7 @@ class OpenGl_ShaderProgram;
//! Text representation parameters
class OpenGl_AspectText : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_AspectText, OpenGl_Element)
public:
//! Empty constructor.

View File

@@ -96,10 +96,10 @@ void OpenGl_BVHTreeSelector::SetViewportSize (Standard_Integer theViewportWidth,
Standard_Integer theViewportHeight,
Standard_Real theResolutionRatio)
{
myViewportHeight = theViewportHeight;
myViewportWidth = theViewportWidth;
myPixelSize = Max (theResolutionRatio / theViewportHeight,
theResolutionRatio / theViewportWidth);
myViewportHeight = theViewportHeight > 0 ? theViewportHeight : 1;
myViewportWidth = theViewportWidth > 0 ? theViewportWidth : 1;
myPixelSize = Max (theResolutionRatio / myViewportHeight,
theResolutionRatio / myViewportWidth);
}
// =======================================================================

View File

@@ -21,8 +21,6 @@
#include <OpenGl_View.hxx>
#include <Graphic3d_TextureParams.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_BackgroundArray, OpenGl_PrimitiveArray)
// =======================================================================
// method : Constructor
// purpose :
@@ -339,7 +337,7 @@ Standard_Boolean OpenGl_BackgroundArray::createTextureArray (const Handle(OpenGl
// Get texture parameters
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
const Handle(OpenGl_AspectFace)& anAspectFace = theWorkspace->AspectFace();
const OpenGl_AspectFace* anAspectFace = theWorkspace->AspectFace();
GLfloat aTextureWidth = (GLfloat )anAspectFace->TextureSet (aCtx)->First()->SizeX();
GLfloat aTextureHeight = (GLfloat )anAspectFace->TextureSet (aCtx)->First()->SizeY();

View File

@@ -28,7 +28,6 @@
//! gradient or texture background rendering.
class OpenGl_BackgroundArray : public OpenGl_PrimitiveArray
{
DEFINE_STANDARD_RTTIEXT(OpenGl_BackgroundArray, OpenGl_PrimitiveArray)
public:
//! Main constructor.

View File

@@ -72,7 +72,7 @@ namespace
aContext->ModelWorldState.SetCurrent (OpenGl_Mat4::Map (*thePlane->Orientation()->mat));
aContext->ApplyModelViewMatrix();
thePlane->Primitives()->Render (theWorkspace);
thePlane->Primitives().Render (theWorkspace);
aContext->ModelWorldState.Pop();
aContext->ApplyModelViewMatrix();
@@ -104,11 +104,11 @@ namespace
theStencilSentry.Init();
// check if capping plane should be rendered within current pass (only opaque / only transparent)
const Handle(OpenGl_AspectFace) anObjAspectFace = aRenderPlane->ToUseObjectProperties() ? aGroupIter.Value()->AspectFace() : NULL;
thePlane->Update (aContext, !anObjAspectFace.IsNull() ? anObjAspectFace->Aspect() : Handle(Graphic3d_AspectFillArea3d)());
const OpenGl_AspectFace* anObjAspectFace = aRenderPlane->ToUseObjectProperties() ? aGroupIter.Value()->AspectFace() : NULL;
thePlane->Update (aContext, anObjAspectFace != NULL ? anObjAspectFace->Aspect() : Handle(Graphic3d_AspectFillArea3d)());
theWorkspace->SetAspectFace (thePlane->AspectFace());
theWorkspace->SetRenderFilter (aPrevFilter);
if (!theWorkspace->ShouldRender (thePlane->Primitives()))
if (!theWorkspace->ShouldRender (&thePlane->Primitives()))
{
continue;
}
@@ -124,7 +124,7 @@ namespace
const bool aColorMaskBack = aContext->SetColorMask (false);
// override aspects, disable culling
theWorkspace->SetAspectFace (theWorkspace->NoneCulling());
theWorkspace->SetAspectFace (&theWorkspace->NoneCulling());
theWorkspace->ApplyAspectFace();
// evaluate number of pair faces
@@ -156,7 +156,7 @@ namespace
}
// override material, cull back faces
theWorkspace->SetAspectFace (theWorkspace->FrontCulling());
theWorkspace->SetAspectFace (&theWorkspace->FrontCulling());
theWorkspace->ApplyAspectFace();
// enable all clip plane except the rendered one
@@ -207,7 +207,7 @@ void OpenGl_CappingAlgo::RenderCapping (const Handle(OpenGl_Workspace)& theWorks
}
// remember current aspect face defined in workspace
const Handle(OpenGl_AspectFace)& aFaceAsp = theWorkspace->AspectFace();
const OpenGl_AspectFace* aFaceAsp = theWorkspace->AspectFace();
// only filled primitives should be rendered
const Standard_Integer aPrevFilter = theWorkspace->RenderFilter();

View File

@@ -63,7 +63,7 @@ namespace
// purpose :
// =======================================================================
OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d_ClipPlane)& thePlane)
: myPrimitives (new OpenGl_PrimitiveArray(NULL)),
: myPrimitives (NULL),
myOrientation (OpenGl_IdentityMatrix),
myAspect (NULL),
myPlaneRoot (thePlane),
@@ -82,7 +82,7 @@ OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d
if (anAttribs->Init (12, anAttribInfo, 3))
{
memcpy (anAttribs->ChangeData(), THE_CAPPING_PLN_VERTS, sizeof(THE_CAPPING_PLN_VERTS));
myPrimitives->InitBuffers (NULL, Graphic3d_TOPA_TRIANGLES, NULL, anAttribs, NULL);
myPrimitives.InitBuffers (NULL, Graphic3d_TOPA_TRIANGLES, NULL, anAttribs, NULL);
}
}
@@ -113,7 +113,7 @@ void OpenGl_CappingPlaneResource::Update (const Handle(OpenGl_Context)& ,
void OpenGl_CappingPlaneResource::Release (OpenGl_Context* theContext)
{
OpenGl_Element::Destroy (theContext, myAspect);
myPrimitives->Release (theContext);
myPrimitives.Release (theContext);
myEquationMod = (unsigned int )-1;
myAspectMod = (unsigned int )-1;
}
@@ -124,7 +124,7 @@ void OpenGl_CappingPlaneResource::Release (OpenGl_Context* theContext)
// =======================================================================
void OpenGl_CappingPlaneResource::updateAspect (const Handle(Graphic3d_AspectFillArea3d)& theObjAspect)
{
if (myAspect.IsNull())
if (myAspect == NULL)
{
myAspect = new OpenGl_AspectFace();
myAspectMod = myPlaneRoot->MCountAspect() - 1; // mark out of sync

View File

@@ -61,13 +61,13 @@ public:
const Handle(Graphic3d_ClipPlane)& Plane() const { return myPlaneRoot; }
//! @return aspect face for rendering capping surface.
inline const Handle(OpenGl_AspectFace)& AspectFace() const { return myAspect; }
inline const OpenGl_AspectFace* AspectFace() const { return myAspect; }
//! @return evaluated orientation matrix to transform infinite plane.
inline const OpenGl_Matrix* Orientation() const { return &myOrientation; }
//! @return primitive array of vertices to render infinite plane.
inline const Handle(OpenGl_PrimitiveArray)& Primitives() const { return myPrimitives; }
inline const OpenGl_PrimitiveArray& Primitives() const { return myPrimitives; }
private:
@@ -79,9 +79,9 @@ private:
private:
Handle(OpenGl_PrimitiveArray) myPrimitives; //!< vertices and texture coordinates for rendering
OpenGl_PrimitiveArray myPrimitives; //!< vertices and texture coordinates for rendering
OpenGl_Matrix myOrientation; //!< plane transformation matrix.
Handle(OpenGl_AspectFace) myAspect; //!< capping face aspect.
OpenGl_AspectFace* myAspect; //!< capping face aspect.
Handle(Graphic3d_ClipPlane) myPlaneRoot; //!< parent clipping plane structure.
Handle(Graphic3d_AspectFillArea3d) myFillAreaAspect; //!< own capping aspect
unsigned int myEquationMod; //!< modification counter for plane equation.

View File

@@ -28,11 +28,11 @@ OpenGl_Caps::OpenGl_Caps()
: vboDisable (Standard_False),
pntSpritesDisable (Standard_False),
keepArrayData (Standard_False),
#if !defined(GL_ES_VERSION_2_0)
ffpEnable (Standard_False),
usePolygonMode (Standard_False),
#if !defined(GL_ES_VERSION_2_0)
useSystemBuffer (Standard_False),
#else
ffpEnable (Standard_False),
useSystemBuffer (Standard_True),
#endif
swapInterval (1),

View File

@@ -30,7 +30,8 @@ public: //! @name flags to disable particular functionality, should be used only
Standard_Boolean vboDisable; //!< flag permits VBO usage, will significantly affect performance (OFF by default)
Standard_Boolean pntSpritesDisable; //!< flag permits Point Sprites usage, will significantly affect performance (OFF by default)
Standard_Boolean keepArrayData; //!< Disables freeing CPU memory after building VBOs (OFF by default)
Standard_Boolean ffpEnable; //!< Enables FFP (fixed-function pipeline), do not use built-in GLSL programs (ON by default on desktop OpenGL and OFF on OpenGL ES)
Standard_Boolean ffpEnable; //!< Enables FFP (fixed-function pipeline), do not use built-in GLSL programs (OFF by default)
Standard_Boolean usePolygonMode; //!< Enables Polygon Mode instead of built-in GLSL programs (OFF by default; unsupported on OpenGL ES)
Standard_Boolean useSystemBuffer; //!< Enables usage of system backbuffer for blitting (OFF by default on desktop OpenGL and ON on OpenGL ES for testing)
Standard_Integer swapInterval; //!< controls swap interval - 0 for VSync off and 1 for VSync on, 1 by default

View File

@@ -125,6 +125,7 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
hasFloatBuffer (OpenGl_FeatureNotAvailable),
hasHalfFloatBuffer (OpenGl_FeatureNotAvailable),
hasSampleVariables (OpenGl_FeatureNotAvailable),
hasGeometryStage (OpenGl_FeatureNotAvailable),
arbDrawBuffers (Standard_False),
arbNPTW (Standard_False),
arbTexRG (Standard_False),
@@ -172,6 +173,7 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
myHasRayTracing (Standard_False),
myHasRayTracingTextures (Standard_False),
myHasRayTracingAdaptiveSampling (Standard_False),
myHasRayTracingAdaptiveSamplingAtomic (Standard_False),
myFrameStats (new OpenGl_FrameStats()),
#if !defined(GL_ES_VERSION_2_0)
myPointSpriteOrig (GL_UPPER_LEFT),
@@ -192,6 +194,7 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
myResolution (Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION),
myResolutionRatio (1.0f),
myLineWidthScale (1.0f),
myLineFeather (1.0f),
myRenderScale (1.0f),
myRenderScaleInv (1.0f)
{
@@ -1421,6 +1424,12 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
// dFdx/dFdy are completely broken on tested Adreno devices with versions below OpenGl ES 3.1
hasFlatShading = OpenGl_FeatureNotAvailable;
}
hasGeometryStage = IsGlGreaterEqual (3, 2)
? OpenGl_FeatureInCore
: (CheckExtension ("GL_EXT_geometry_shader") && CheckExtension ("GL_EXT_shader_io_blocks")
? OpenGl_FeatureInExtensions
: OpenGl_FeatureNotAvailable);
#else
myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP;
@@ -1445,6 +1454,10 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
CheckExtension ("GL_ARB_color_buffer_float") ? OpenGl_FeatureInExtensions
: OpenGl_FeatureNotAvailable;
hasGeometryStage = IsGlGreaterEqual (3, 2)
? OpenGl_FeatureInCore
: OpenGl_FeatureNotAvailable;
hasSampleVariables = IsGlGreaterEqual (4, 0) ? OpenGl_FeatureInCore :
arbSampleShading ? OpenGl_FeatureInExtensions
: OpenGl_FeatureNotAvailable;
@@ -2516,8 +2529,9 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
// check whether adaptive screen sampling in ray tracing mode is supported
myHasRayTracingAdaptiveSampling = myHasRayTracing
&& has44
&& CheckExtension ("GL_NV_shader_atomic_float");
&& has44;
myHasRayTracingAdaptiveSamplingAtomic = myHasRayTracingAdaptiveSampling
&& CheckExtension ("GL_NV_shader_atomic_float");
if (!has32)
{
@@ -3165,7 +3179,7 @@ Handle(OpenGl_FrameBuffer) OpenGl_Context::SetDefaultFrameBuffer (const Handle(O
// function : SetShadingMaterial
// purpose :
// =======================================================================
void OpenGl_Context::SetShadingMaterial (const Handle(OpenGl_AspectFace)& theAspect,
void OpenGl_Context::SetShadingMaterial (const OpenGl_AspectFace* theAspect,
const Handle(Graphic3d_PresentationAttributes)& theHighlight)
{
const Handle(Graphic3d_AspectFillArea3d)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull())
@@ -3211,9 +3225,18 @@ void OpenGl_Context::SetShadingMaterial (const Handle(OpenGl_AspectFace)& theAsp
// do not update material properties in case of zero reflection mode,
// because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway.
const OpenGl_MaterialState& aMatState = myShaderManager->MaterialState();
const float anAlphaCutoff = anAspect->AlphaMode() == Graphic3d_AlphaMode_Mask
? anAspect->AlphaCutoff()
: ShortRealLast();
float anAlphaCutoff = anAspect->AlphaMode() == Graphic3d_AlphaMode_Mask
? anAspect->AlphaCutoff()
: ShortRealLast();
if (anAspect->ToDrawEdges())
{
if (anAspect->InteriorStyle() == Aspect_IS_EMPTY
|| (anAspect->InteriorStyle() == Aspect_IS_SOLID
&& anAspect->EdgeColorRGBA().Alpha() < 1.0f))
{
anAlphaCutoff = 0.285f;
}
}
if (theAspect->ShadingModel() == Graphic3d_TOSM_UNLIT)
{
if (anAlphaCutoff == aMatState.AlphaCutoff())
@@ -3237,7 +3260,7 @@ void OpenGl_Context::SetShadingMaterial (const Handle(OpenGl_AspectFace)& theAsp
// function : CheckIsTransparent
// purpose :
// =======================================================================
Standard_Boolean OpenGl_Context::CheckIsTransparent (const Handle(OpenGl_AspectFace)& theAspect,
Standard_Boolean OpenGl_Context::CheckIsTransparent (const OpenGl_AspectFace* theAspect,
const Handle(Graphic3d_PresentationAttributes)& theHighlight,
Standard_ShortReal& theAlphaFront,
Standard_ShortReal& theAlphaBack)
@@ -3770,14 +3793,15 @@ bool OpenGl_Context::SetColorMask (bool theToWriteColor)
// =======================================================================
bool OpenGl_Context::SetSampleAlphaToCoverage (bool theToEnable)
{
if (myAlphaToCoverage == theToEnable)
bool toEnable = myAllowAlphaToCov && theToEnable;
if (myAlphaToCoverage == toEnable)
{
return myAlphaToCoverage;
}
if (core15fwd != NULL)
{
if (theToEnable)
if (toEnable)
{
//core15fwd->core15fwd->glSampleCoverage (1.0f, GL_FALSE);
core15fwd->glEnable (GL_SAMPLE_ALPHA_TO_COVERAGE);
@@ -3789,6 +3813,6 @@ bool OpenGl_Context::SetSampleAlphaToCoverage (bool theToEnable)
}
const bool anOldValue = myAlphaToCoverage;
myAlphaToCoverage = theToEnable;
myAlphaToCoverage = toEnable;
return anOldValue;
}

View File

@@ -503,6 +503,9 @@ public:
//! @return TRUE if adaptive screen sampling in ray tracing mode is supported
Standard_Boolean HasRayTracingAdaptiveSampling() const { return myHasRayTracingAdaptiveSampling; }
//! @return TRUE if atomic adaptive screen sampling in ray tracing mode is supported
Standard_Boolean HasRayTracingAdaptiveSamplingAtomic() const { return myHasRayTracingAdaptiveSamplingAtomic; }
//! Returns true if VBO is supported and permitted.
inline bool ToUseVbo() const
{
@@ -659,6 +662,12 @@ public: //! @name methods to alter or retrieve current state
//! Enable/disable writing into color buffer (wrapper for glColorMask).
Standard_EXPORT bool SetColorMask (bool theToWriteColor);
//! Return TRUE if GL_SAMPLE_ALPHA_TO_COVERAGE usage is allowed.
bool AllowSampleAlphaToCoverage() const { return myAllowAlphaToCov; }
//! Allow GL_SAMPLE_ALPHA_TO_COVERAGE usage.
void SetAllowSampleAlphaToCoverage (bool theToEnable) { myAllowAlphaToCov = theToEnable; }
//! Return GL_SAMPLE_ALPHA_TO_COVERAGE state.
bool SampleAlphaToCoverage() const { return myAlphaToCoverage; }
@@ -696,17 +705,17 @@ public: //! @name methods to alter or retrieve current state
Standard_EXPORT Standard_Boolean BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram);
//! Setup current shading material.
Standard_EXPORT void SetShadingMaterial (const Handle(OpenGl_AspectFace)& theAspect,
Standard_EXPORT void SetShadingMaterial (const OpenGl_AspectFace* theAspect,
const Handle(Graphic3d_PresentationAttributes)& theHighlight);
//! Checks if transparency is required for the given aspect and highlight style.
Standard_EXPORT static Standard_Boolean CheckIsTransparent (const Handle(OpenGl_AspectFace)& theAspect,
Standard_EXPORT static Standard_Boolean CheckIsTransparent (const OpenGl_AspectFace* theAspect,
const Handle(Graphic3d_PresentationAttributes)& theHighlight,
Standard_ShortReal& theAlphaFront,
Standard_ShortReal& theAlphaBack);
//! Checks if transparency is required for the given aspect and highlight style.
static Standard_Boolean CheckIsTransparent (const Handle(OpenGl_AspectFace)& theAspect,
static Standard_Boolean CheckIsTransparent (const OpenGl_AspectFace* theAspect,
const Handle(Graphic3d_PresentationAttributes)& theHighlight)
{
Standard_ShortReal anAlphaFront = 1.0f, anAlphaBack = 1.0f;
@@ -774,6 +783,9 @@ public: //! @name methods to alter or retrieve current state
//! Rendering scale factor (inverted value).
Standard_ShortReal RenderScaleInv() const { return myRenderScaleInv; }
//! Return scale factor for line width.
Standard_ShortReal LineWidthScale() const { return myLineWidthScale; }
//! Set resolution ratio.
//! Note that this method rounds @theRatio to nearest integer.
void SetResolution (unsigned int theResolution,
@@ -794,6 +806,12 @@ public: //! @name methods to alter or retrieve current state
myLineWidthScale = Max (1.0f, std::floor (theRatio + 0.5f));
}
//! Return line feater width in pixels.
Standard_ShortReal LineFeather() const { return myLineFeather; }
//! Set line feater width.
void SetLineFeather(Standard_ShortReal theValue) { myLineFeather = theValue; }
//! Return Graphics Driver's vendor.
const TCollection_AsciiString& Vendor() const { return myVendor; }
@@ -845,6 +863,7 @@ public: //! @name extensions
OpenGl_FeatureFlag hasFloatBuffer; //!< Complex flag indicating support of float color buffer format (desktop OpenGL 3.0, GL_ARB_color_buffer_float, GL_EXT_color_buffer_float)
OpenGl_FeatureFlag hasHalfFloatBuffer; //!< Complex flag indicating support of half-float color buffer format (desktop OpenGL 3.0, GL_ARB_color_buffer_float, GL_EXT_color_buffer_half_float)
OpenGl_FeatureFlag hasSampleVariables; //!< Complex flag indicating support of MSAA variables in GLSL shader (desktop OpenGL 4.0, GL_ARB_sample_shading)
OpenGl_FeatureFlag hasGeometryStage; //!< Complex flag indicating support of Geometry shader (desktop OpenGL 3.2, OpenGL ES 3.2, GL_EXT_geometry_shader)
Standard_Boolean arbDrawBuffers; //!< GL_ARB_draw_buffers
Standard_Boolean arbNPTW; //!< GL_ARB_texture_non_power_of_two
Standard_Boolean arbTexRG; //!< GL_ARB_texture_rg
@@ -928,9 +947,10 @@ private: // context info
Standard_Boolean myIsGlNormalizeEnabled; //!< GL_NORMALIZE flag
//!< Used to tell OpenGl that normals should be normalized
Standard_Boolean myHasRayTracing; //! indicates whether ray tracing mode is supported
Standard_Boolean myHasRayTracingTextures; //! indicates whether textures in ray tracing mode are supported
Standard_Boolean myHasRayTracingAdaptiveSampling; //! indicates whether adaptive screen sampling in ray tracing mode is supported
Standard_Boolean myHasRayTracing; //! indicates whether ray tracing mode is supported
Standard_Boolean myHasRayTracingTextures; //! indicates whether textures in ray tracing mode are supported
Standard_Boolean myHasRayTracingAdaptiveSampling; //! indicates whether adaptive screen sampling in ray tracing mode is supported
Standard_Boolean myHasRayTracingAdaptiveSamplingAtomic; //! indicates whether atomic adaptive screen sampling in ray tracing mode is supported
Handle(OpenGl_ShaderManager) myShaderManager; //! support object for managing shader programs
@@ -954,6 +974,7 @@ private: //! @name fields tracking current state
myDrawBuffers; //!< current draw buffers
unsigned int myDefaultVao; //!< default Vertex Array Object
Standard_Boolean myColorMask; //!< flag indicating writing into color buffer is enabled or disabled (glColorMask)
Standard_Boolean myAllowAlphaToCov; //!< flag allowing GL_SAMPLE_ALPHA_TO_COVERAGE usage
Standard_Boolean myAlphaToCoverage; //!< flag indicating GL_SAMPLE_ALPHA_TO_COVERAGE state
Standard_Boolean myIsGlDebugCtx; //!< debug context initialization state
TCollection_AsciiString myVendor; //!< Graphics Driver's vendor
@@ -962,6 +983,7 @@ private: //! @name fields tracking current state
Standard_ShortReal myResolutionRatio; //!< scaling factor for parameters like text size
//! to be properly displayed on device (screen / printer)
Standard_ShortReal myLineWidthScale; //!< scaling factor for line width
Standard_ShortReal myLineFeather; //!< line feater width in pixels
Standard_ShortReal myRenderScale; //!< scaling factor for rendering resolution
Standard_ShortReal myRenderScaleInv; //!< scaling factor for rendering resolution (inverted value)
OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates)

View File

@@ -15,8 +15,6 @@
#include <OpenGl_Element.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Element, Standard_Transient)
// =======================================================================
// function : OpenGl_Element
// purpose :

View File

@@ -23,9 +23,8 @@ class OpenGl_Workspace;
class OpenGl_Context;
//! Base interface for drawable elements.
class OpenGl_Element : public Standard_Transient
class OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_Element, Standard_Transient)
public:
Standard_EXPORT OpenGl_Element();
@@ -41,14 +40,18 @@ public:
//! Pointer to the context is used because this method might be called
//! when the context is already being destroyed and usage of a handle
//! would be unsafe
template <typename theResource_t>
static void Destroy (OpenGl_Context* theContext,
Handle(OpenGl_Element)& theElement)
theResource_t*& theElement)
{
if (theElement.IsNull())
if (theElement == NULL)
{
return;
}
theElement->Release (theContext);
OpenGl_Element* anElement = theElement;
delete anElement;
theElement = NULL;
}

View File

@@ -22,8 +22,6 @@
#include <gp_Ax2.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Flipper, OpenGl_Element)
// =======================================================================
// function : Constructor
// purpose :

View File

@@ -27,7 +27,6 @@ class gp_Ax2;
//! Originally, this element serves for need of flipping the 3D text of dimension presentations.
class OpenGl_Flipper : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_Flipper, OpenGl_Element)
public:
//! Construct rendering element to flip model-view matrix

View File

@@ -161,6 +161,8 @@ void OpenGl_FrameStats::updateStatistics (const Handle(Graphic3d_CView)& theView
aMemFbos += estimatedDataSize (aView->myRaytraceVisualErrorTexture[1]);
aMemFbos += estimatedDataSize (aView->myRaytraceTileOffsetsTexture[0]);
aMemFbos += estimatedDataSize (aView->myRaytraceTileOffsetsTexture[1]);
aMemFbos += estimatedDataSize (aView->myRaytraceTileSamplesTexture[0]);
aMemFbos += estimatedDataSize (aView->myRaytraceTileSamplesTexture[1]);
}
{
// Ray Tracing geometry
@@ -203,10 +205,9 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId,
for (OpenGl_Structure::GroupIterator aGroupIter (aStruct->Groups()); aGroupIter.More(); aGroupIter.Next())
{
const OpenGl_Group* aGroup = aGroupIter.Value();
for (OpenGl_ElementNodes::Iterator anElemIterator (aGroup->GetElements()); anElemIterator.More(); anElemIterator.Next())
for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next)
{
Handle(OpenGl_PrimitiveArray) aPrim = Handle(OpenGl_PrimitiveArray)::DownCast (anElemIterator.Value());
if (!aPrim.IsNull())
if (const OpenGl_PrimitiveArray* aPrim = dynamic_cast<const OpenGl_PrimitiveArray*> (aNodeIter->elem))
{
myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += estimatedDataSize (aPrim->AttributesVbo());
myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += estimatedDataSize (aPrim->IndexVbo());
@@ -226,10 +227,9 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId,
for (OpenGl_Structure::GroupIterator aGroupIter (aStruct->Groups()); aGroupIter.More(); aGroupIter.Next())
{
const OpenGl_Group* aGroup = aGroupIter.Value();
for (OpenGl_ElementNodes::Iterator anElemIterator (aGroup->GetElements()); anElemIterator.More(); anElemIterator.Next())
for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next)
{
Handle(OpenGl_PrimitiveArray) aPrim = Handle(OpenGl_PrimitiveArray)::DownCast (anElemIterator.Value());
if (!aPrim.IsNull())
if (const OpenGl_PrimitiveArray* aPrim = dynamic_cast<const OpenGl_PrimitiveArray*> (aNodeIter->elem))
{
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
if (theToCountMem)
@@ -313,8 +313,9 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId,
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled];
}
}
else if (!Handle(OpenGl_Text)::DownCast(anElemIterator.Value()).IsNull())
else if (const OpenGl_Text* aText = dynamic_cast<const OpenGl_Text*> (aNodeIter->elem))
{
(void )aText;
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled];
}

View File

@@ -19,8 +19,6 @@
#include <Graphic3d_ArrayOfTriangles.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_FrameStatsPrs, OpenGl_Element)
namespace
{
//! Auxiliary structure defining vertex with two attributes.
@@ -52,11 +50,7 @@ OpenGl_FrameStatsPrs::OpenGl_FrameStatsPrs()
myChartIndices (new OpenGl_IndexBuffer()),
myChartLines (new OpenGl_VertexBuffer())
{
myCountersText = new OpenGl_Text();
myTextAspect = new OpenGl_AspectText();
myChartLabels[0] = new OpenGl_Text();
myChartLabels[1] = new OpenGl_Text();
myChartLabels[2] = new OpenGl_Text();
//
}
// =======================================================================
@@ -74,10 +68,10 @@ OpenGl_FrameStatsPrs::~OpenGl_FrameStatsPrs()
// =======================================================================
void OpenGl_FrameStatsPrs::Release (OpenGl_Context* theCtx)
{
myCountersText->Release (theCtx);
myChartLabels[0]->Release (theCtx);
myChartLabels[1]->Release (theCtx);
myChartLabels[2]->Release (theCtx);
myCountersText.Release (theCtx);
myChartLabels[0].Release (theCtx);
myChartLabels[1].Release (theCtx);
myChartLabels[2].Release (theCtx);
myChartVertices->Release (theCtx);
myChartIndices->Release (theCtx);
myChartLines->Release (theCtx);
@@ -94,7 +88,7 @@ void OpenGl_FrameStatsPrs::Update (const Handle(OpenGl_Workspace)& theWorkspace)
const Graphic3d_RenderingParams& aRendParams = theWorkspace->View()->RenderingParams();
myCountersTrsfPers = theWorkspace->View()->RenderingParams().StatsPosition;
myChartTrsfPers = theWorkspace->View()->RenderingParams().ChartPosition;
myTextAspect->SetAspect (aRendParams.StatsTextAspect);
myTextAspect.SetAspect (aRendParams.StatsTextAspect);
// adjust text alignment depending on corner
OpenGl_TextParam aParams;
@@ -117,21 +111,21 @@ void OpenGl_FrameStatsPrs::Update (const Handle(OpenGl_Workspace)& theWorkspace)
{
aParams.VAlign = Graphic3d_VTA_BOTTOM;
}
if (aParams.Height != myCountersText->FormatParams().Height
|| aParams.HAlign != myCountersText->FormatParams().HAlign
|| aParams.VAlign != myCountersText->FormatParams().VAlign)
if (aParams.Height != myCountersText.FormatParams().Height
|| aParams.HAlign != myCountersText.FormatParams().HAlign
|| aParams.VAlign != myCountersText.FormatParams().VAlign)
{
myCountersText->Release (aCtx.operator->());
myCountersText.Release (aCtx.operator->());
}
if (!aStats->IsFrameUpdated (myStatsPrev)
&& !myCountersText->Text().IsEmpty())
&& !myCountersText.Text().IsEmpty())
{
return;
}
TCollection_AsciiString aText = aStats->FormatStats (aRendParams.CollectedStats);
myCountersText->Init (aCtx, aText.ToCString(), OpenGl_Vec3 (0.0f, 0.0f, 0.0f), aParams);
myCountersText.Init (aCtx, aText.ToCString(), OpenGl_Vec3 (0.0f, 0.0f, 0.0f), aParams);
updateChart (theWorkspace);
}
@@ -347,9 +341,9 @@ void OpenGl_FrameStatsPrs::updateChart (const Handle(OpenGl_Workspace)& theWorks
const float aLabX = aParams.HAlign == Graphic3d_HTA_RIGHT
? float(anOffset.x())
: float(anOffset.x() + aCharSize.x());
myChartLabels[0]->Init (aCtx, aLabels[isTopDown ? 0 : 2].ToCString(), OpenGl_Vec3 (aLabX, float(anOffset.y()), 0.0f), aParams);
myChartLabels[1]->Init (aCtx, aLabels[isTopDown ? 1 : 1].ToCString(), OpenGl_Vec3 (aLabX, float(anOffset.y() - aBinSize.y() / 2), 0.0f), aParams);
myChartLabels[2]->Init (aCtx, aLabels[isTopDown ? 2 : 0].ToCString(), OpenGl_Vec3 (aLabX, float(anOffset.y() - aBinSize.y()), 0.0f), aParams);
myChartLabels[0].Init (aCtx, aLabels[isTopDown ? 0 : 2].ToCString(), OpenGl_Vec3 (aLabX, float(anOffset.y()), 0.0f), aParams);
myChartLabels[1].Init (aCtx, aLabels[isTopDown ? 1 : 1].ToCString(), OpenGl_Vec3 (aLabX, float(anOffset.y() - aBinSize.y() / 2), 0.0f), aParams);
myChartLabels[2].Init (aCtx, aLabels[isTopDown ? 2 : 0].ToCString(), OpenGl_Vec3 (aLabX, float(anOffset.y() - aBinSize.y()), 0.0f), aParams);
}
}
@@ -367,8 +361,7 @@ void OpenGl_FrameStatsPrs::Render (const Handle(OpenGl_Workspace)& theWorkspace)
glDepthMask (GL_FALSE);
}
const Handle(OpenGl_AspectText)& aTextAspectBack = theWorkspace->AspectText();
theWorkspace->SetAspectText (myTextAspect);
const OpenGl_AspectText* aTextAspectBack = theWorkspace->SetAspectText (&myTextAspect);
aCtx->ModelWorldState.Push();
aCtx->ModelWorldState.ChangeCurrent().InitIdentity();
@@ -383,7 +376,7 @@ void OpenGl_FrameStatsPrs::Render (const Handle(OpenGl_Workspace)& theWorkspace)
aCtx->VirtualViewport()[2], aCtx->VirtualViewport()[3]);
}
aCtx->ApplyModelViewMatrix();
myCountersText->Render (theWorkspace);
myCountersText.Render (theWorkspace);
aCtx->WorldViewState.Pop();
}
@@ -426,9 +419,9 @@ void OpenGl_FrameStatsPrs::Render (const Handle(OpenGl_Workspace)& theWorkspace)
myChartLines->unbindAttribute (aCtx, Graphic3d_TOA_COLOR);
myChartLines->unbindAttribute (aCtx, Graphic3d_TOA_POS);
myChartLabels[0]->Render (theWorkspace);
myChartLabels[1]->Render (theWorkspace);
myChartLabels[2]->Render (theWorkspace);
myChartLabels[0].Render (theWorkspace);
myChartLabels[1].Render (theWorkspace);
myChartLabels[2].Render (theWorkspace);
aCtx->WorldViewState.Pop();
}

View File

@@ -25,7 +25,6 @@ class OpenGl_VertexBuffer;
//! Element rendering frame statistics.
class OpenGl_FrameStatsPrs : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_FrameStatsPrs, OpenGl_Element)
public:
//! Default constructor.
@@ -44,7 +43,7 @@ public:
Standard_EXPORT void Update (const Handle(OpenGl_Workspace)& theWorkspace);
//! Assign text aspect.
void SetTextAspect (const Handle(Graphic3d_AspectText3d)& theAspect) { myTextAspect->SetAspect (theAspect); }
void SetTextAspect (const Handle(Graphic3d_AspectText3d)& theAspect) { myTextAspect.SetAspect (theAspect); }
protected:
@@ -55,14 +54,14 @@ protected:
Handle(OpenGl_FrameStats) myStatsPrev; //!< currently displayed stats
Handle(Graphic3d_TransformPers) myCountersTrsfPers; //!< transformation persistence for counters presentation
Handle(OpenGl_Text) myCountersText; //!< counters presentation
Handle(OpenGl_AspectText) myTextAspect; //!< text aspect
OpenGl_Text myCountersText; //!< counters presentation
OpenGl_AspectText myTextAspect; //!< text aspect
Handle(Graphic3d_TransformPers) myChartTrsfPers; //!< transformation persistence for chart presentation
Handle(Graphic3d_ArrayOfTriangles) myChartArray; //!< array of chart triangles
Handle(OpenGl_VertexBuffer) myChartVertices; //!< VBO with chart triangles
Handle(OpenGl_IndexBuffer) myChartIndices; //!< VBO with chart triangle indexes
Handle(OpenGl_VertexBuffer) myChartLines; //!< array of chart lines
Handle(OpenGl_Text) myChartLabels[3]; //!< chart labels
OpenGl_Text myChartLabels[3]; //!< chart labels
};

View File

@@ -32,8 +32,6 @@
#include <string.h>
#endif
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraduatedTrihedron, OpenGl_Element)
namespace
{
static const OpenGl_TextParam THE_LABEL_PARAMS =
@@ -51,11 +49,7 @@ OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron()
myMax (100.0f, 100.0f, 100.0f),
myIsInitialized (Standard_False)
{
myGridLineAspect = new OpenGl_AspectLine();
myLabelValues = new OpenGl_Text();
myAspectLabels = new OpenGl_AspectText();
myAspectValues = new OpenGl_AspectText();
//
}
// =======================================================================
@@ -86,7 +80,7 @@ void OpenGl_GraduatedTrihedron::Release (OpenGl_Context* theCtx)
myAxes[0].Release (theCtx);
myAxes[1].Release (theCtx);
myAxes[2].Release (theCtx);
myLabelValues->Release (theCtx);
myLabelValues.Release (theCtx);
}
// =======================================================================
@@ -98,7 +92,7 @@ void OpenGl_GraduatedTrihedron::initGlResources (const Handle(OpenGl_Context)& t
myAxes[0].Release (theCtx.operator->());
myAxes[1].Release (theCtx.operator->());
myAxes[2].Release (theCtx.operator->());
myLabelValues->Release (theCtx.operator->());
myLabelValues.Release (theCtx.operator->());
// Initialize text label parameters for x, y, and z axes
myAxes[0] = Axis (myData.XAxisAspect(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f));
@@ -111,19 +105,19 @@ void OpenGl_GraduatedTrihedron::initGlResources (const Handle(OpenGl_Context)& t
myAxes[2].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f));
for (Standard_Integer anIt = 0; anIt < 3; ++anIt)
{
myAxes[anIt].Label->SetFontSize (theCtx, myData.NamesSize());
myAxes[anIt].Label.SetFontSize (theCtx, myData.NamesSize());
}
myLabelValues->SetFontSize (theCtx, myData.ValuesSize());
myLabelValues.SetFontSize (theCtx, myData.ValuesSize());
myAspectLabels->Aspect()->SetTextFontAspect (myData.NamesFontAspect());
myAspectLabels->Aspect()->SetFont (myData.NamesFont());
myAspectLabels.Aspect()->SetTextFontAspect (myData.NamesFontAspect());
myAspectLabels.Aspect()->SetFont (myData.NamesFont());
myAspectValues->Aspect()->SetTextFontAspect (myData.ValuesFontAspect());
myAspectValues->Aspect()->SetFont (myData.ValuesFont());
myAspectValues.Aspect()->SetTextFontAspect (myData.ValuesFontAspect());
myAspectValues.Aspect()->SetFont (myData.ValuesFont());
// Grid aspect
myGridLineAspect->Aspect()->SetColor (myData.GridColor());
myGridLineAspect.Aspect()->SetColor (myData.GridColor());
}
// =======================================================================
@@ -332,7 +326,7 @@ Standard_ExtCharacter OpenGl_GraduatedTrihedron::getGridAxes (const Standard_Sho
// function : renderLine
// purpose :
// =======================================================================
void OpenGl_GraduatedTrihedron::renderLine (const Handle(OpenGl_PrimitiveArray)& theLine,
void OpenGl_GraduatedTrihedron::renderLine (const OpenGl_PrimitiveArray& theLine,
const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Mat4& theMat,
const Standard_ShortReal theXt,
@@ -344,7 +338,7 @@ void OpenGl_GraduatedTrihedron::renderLine (const Handle(OpenGl_PrimitiveArray)&
Graphic3d_TransformUtils::Translate (aMat, theXt, theYt, theZt);
aContext->WorldViewState.SetCurrent (aMat);
aContext->ApplyWorldViewMatrix();
theLine->Render (theWorkspace);
theLine.Render (theWorkspace);
}
// =======================================================================
@@ -391,7 +385,7 @@ void OpenGl_GraduatedTrihedron::renderGridPlane (const Handle(OpenGl_Workspace)&
Graphic3d_TransformUtils::Translate (aMat, aStepVec.x(), aStepVec.y(), aStepVec.z());
aContext->WorldViewState.SetCurrent (aMat);
aContext->ApplyWorldViewMatrix();
anAxis.Line->Render (theWorkspace);
anAxis.Line.Render (theWorkspace);
}
}
}
@@ -406,7 +400,7 @@ void OpenGl_GraduatedTrihedron::renderAxis (const Handle(OpenGl_Workspace)& theW
{
const Axis& anAxis = myAxes[theIndex];
theWorkspace->SetAspectLine (anAxis.LineAspect);
theWorkspace->SetAspectLine (&anAxis.LineAspect);
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
// Reset transformations
@@ -428,7 +422,7 @@ void OpenGl_GraduatedTrihedron::renderAxis (const Handle(OpenGl_Workspace)& theW
aContext->ModelWorldState.SetCurrent (aTransMode.Compute (theWorkspace->View()->Camera(), aProjection, aWorldView, aWidth, aHeight));
aContext->ApplyModelViewMatrix();
anAxis.Arrow->Render (theWorkspace);
anAxis.Arrow.Render (theWorkspace);
// Get current Model-View and Projection states
OpenGl_Mat4 aModelMat;
@@ -463,7 +457,7 @@ void OpenGl_GraduatedTrihedron::renderAxis (const Handle(OpenGl_Workspace)& theW
aContext->WorldViewState.SetCurrent (aModelMat);
aContext->ApplyWorldViewMatrix();
anAxis.Line->Render (theWorkspace);
anAxis.Line.Render (theWorkspace);
}
// =======================================================================
@@ -493,7 +487,7 @@ void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Worksp
if (aCurAspect.ToDrawTickmarks() && aCurAspect.TickmarksNumber() > 0)
{
theWorkspace->SetAspectLine (myGridLineAspect);
theWorkspace->SetAspectLine (&myGridLineAspect);
OpenGl_Mat4 aModelMat (theMat);
@@ -506,7 +500,7 @@ void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Worksp
OpenGl_Vec3 aStepVec = anAxis.Direction * aStep;
for (Standard_Integer anIter = 0; anIter <= aCurAspect.TickmarksNumber(); ++anIter)
{
anAxis.Tickmark->Render (theWorkspace);
anAxis.Tickmark.Render (theWorkspace);
Graphic3d_TransformUtils::Translate (aModelMat, aStepVec.x(), aStepVec.y(), aStepVec.z());
aContext->WorldViewState.SetCurrent (aModelMat);
aContext->ApplyWorldViewMatrix();
@@ -523,24 +517,24 @@ void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Worksp
OpenGl_Vec3 aMiddle (theGridAxes.Ticks[theIndex] + aSizeVec * theGridAxes.Axes[theIndex] * 0.5f + aDir * (Standard_ShortReal)(theDpix * anOffset));
myAspectLabels->Aspect()->SetColor (anAxis.NameColor);
theWorkspace->SetAspectText (myAspectLabels);
anAxis.Label->SetPosition (aMiddle);
anAxis.Label->Render (theWorkspace);
myAspectLabels.Aspect()->SetColor (anAxis.NameColor);
theWorkspace->SetAspectText (&myAspectLabels);
anAxis.Label.SetPosition (aMiddle);
anAxis.Label.Render (theWorkspace);
}
if (aCurAspect.ToDrawValues() && aCurAspect.TickmarksNumber() > 0)
{
myAspectValues->Aspect()->SetColor (anAxis.LineAspect->Aspect()->Color());
theWorkspace->SetAspectText (myAspectValues);
myAspectValues.Aspect()->SetColor (anAxis.LineAspect.Aspect()->Color());
theWorkspace->SetAspectText (&myAspectValues);
Standard_Real anOffset = aCurAspect.ValuesOffset() + aCurAspect.TickmarksLength();
for (Standard_Integer anIt = 0; anIt <= aCurAspect.TickmarksNumber(); ++anIt)
{
sprintf (aTextValue, "%g", theGridAxes.Ticks[theIndex].GetData()[theIndex] + anIt * aStep);
OpenGl_Vec3 aPos (theGridAxes.Ticks[theIndex] + anAxis.Direction* (Standard_ShortReal) (anIt * aStep) + aDir * (Standard_ShortReal) (theDpix * anOffset));
myLabelValues->Init (theWorkspace->GetGlContext(), aTextValue, aPos);
myLabelValues->Render (theWorkspace);
myLabelValues.Init (theWorkspace->GetGlContext(), aTextValue, aPos);
myLabelValues.Render (theWorkspace);
}
}
}
@@ -565,9 +559,9 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorks
if (myData.CubicAxesCallback)
{
myData.CubicAxesCallback (myData.PtrView);
if (!myAxes[0].Line->IsInitialized()
|| !myAxes[1].Line->IsInitialized()
|| !myAxes[2].Line->IsInitialized()
if (!myAxes[0].Line.IsInitialized()
|| !myAxes[1].Line.IsInitialized()
|| !myAxes[2].Line.IsInitialized()
|| OpenGl_Vec3 (anOldMin - myMin).Modulus() > Precision::Confusion()
|| OpenGl_Vec3 (anOldMax - myMax).Modulus() > Precision::Confusion())
{
@@ -611,8 +605,8 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorks
Standard_ExtCharacter anAxesState = getGridAxes (aCorners, aGridAxes);
// Remember current aspects
const Handle(OpenGl_AspectLine)& anOldAspectLine = theWorkspace->AspectLine();
const Handle(OpenGl_AspectText)& anOldAspectText = theWorkspace->AspectText();
const OpenGl_AspectLine* anOldAspectLine = theWorkspace->AspectLine();
const OpenGl_AspectText* anOldAspectText = theWorkspace->AspectText();
OpenGl_Mat4 aModelMatrix;
aModelMatrix.Convert (aContext->WorldViewState.Current());
@@ -624,7 +618,7 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorks
if (myData.ToDrawGrid())
{
theWorkspace->SetAspectLine (myGridLineAspect);
theWorkspace->SetAspectLine (&myGridLineAspect);
// render grid edges
if (anAxesState & XOO_XYO)
@@ -720,14 +714,13 @@ void OpenGl_GraduatedTrihedron::SetMinMax (const OpenGl_Vec3& theMin, const Open
OpenGl_GraduatedTrihedron::Axis::Axis (const Graphic3d_AxisAspect& theAspect,
const OpenGl_Vec3& theDirection)
: Direction (theDirection),
Label (new OpenGl_Text(NCollection_String ((Standard_Utf16Char* )theAspect.Name().ToExtString()).ToCString(), theDirection, THE_LABEL_PARAMS)),
Tickmark (new OpenGl_PrimitiveArray (NULL)),
Line (new OpenGl_PrimitiveArray (NULL)),
Arrow (new OpenGl_PrimitiveArray (NULL))
Label (NCollection_String ((Standard_Utf16Char* )theAspect.Name().ToExtString()).ToCString(), theDirection, THE_LABEL_PARAMS),
Tickmark (NULL),
Line (NULL),
Arrow (NULL)
{
NameColor = theAspect.NameColor();
LineAspect = new OpenGl_AspectLine();
LineAspect->Aspect()->SetColor (theAspect.Color());
LineAspect.Aspect()->SetColor (theAspect.Color());
}
// =======================================================================
@@ -750,9 +743,9 @@ OpenGl_GraduatedTrihedron::Axis& OpenGl_GraduatedTrihedron::Axis::operator= (con
LineAspect = theOther.LineAspect;
Label = theOther.Label;
Line ->InitBuffers (NULL, Graphic3d_TOPA_SEGMENTS, theOther.Line->Indices(), theOther.Line->Attributes(), theOther.Line->Bounds());
Tickmark->InitBuffers (NULL, Graphic3d_TOPA_SEGMENTS, theOther.Tickmark->Indices(), theOther.Tickmark->Attributes(), theOther.Tickmark->Bounds());
Arrow ->InitBuffers (NULL, Graphic3d_TOPA_POLYLINES, theOther.Arrow->Indices(), theOther.Arrow->Attributes(), theOther.Arrow->Bounds());
Line .InitBuffers (NULL, Graphic3d_TOPA_SEGMENTS, theOther.Line.Indices(), theOther.Line.Attributes(), theOther.Line.Bounds());
Tickmark.InitBuffers (NULL, Graphic3d_TOPA_SEGMENTS, theOther.Tickmark.Indices(), theOther.Tickmark.Attributes(), theOther.Tickmark.Bounds());
Arrow .InitBuffers (NULL, Graphic3d_TOPA_POLYLINES, theOther.Arrow.Indices(), theOther.Arrow.Attributes(), theOther.Arrow.Bounds());
return *this;
}
@@ -787,8 +780,8 @@ void OpenGl_GraduatedTrihedron::Axis::InitArrow (const Handle(OpenGl_Context)& t
anArray->AddVertex (aPoint3);
anArray->AddVertex (aPoint1);
Arrow->InitBuffers (theContext, Graphic3d_TOPA_POLYLINES,
anArray->Indices(), anArray->Attributes(), anArray->Bounds());
Arrow.InitBuffers (theContext, Graphic3d_TOPA_POLYLINES,
anArray->Indices(), anArray->Attributes(), anArray->Bounds());
}
// =======================================================================
@@ -802,8 +795,8 @@ void OpenGl_GraduatedTrihedron::Axis::InitTickmark (const Handle(OpenGl_Context)
Handle(Graphic3d_ArrayOfSegments) anArray = new Graphic3d_ArrayOfSegments (2);
anArray->AddVertex (0.0f, 0.0f, 0.0f);
anArray->AddVertex (theDir);
Tickmark->InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS,
anArray->Indices(), anArray->Attributes(), anArray->Bounds());
Tickmark.InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS,
anArray->Indices(), anArray->Attributes(), anArray->Bounds());
}
@@ -819,8 +812,8 @@ void OpenGl_GraduatedTrihedron::Axis::InitLine (const Handle(OpenGl_Context)& th
anArray->AddVertex (0.0f, 0.0f, 0.0f);
anArray->AddVertex (theDir);
Line->InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS,
anArray->Indices(), anArray->Attributes(), anArray->Bounds());
Line.InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS,
anArray->Indices(), anArray->Attributes(), anArray->Bounds());
}
// =======================================================================
@@ -829,8 +822,8 @@ void OpenGl_GraduatedTrihedron::Axis::InitLine (const Handle(OpenGl_Context)& th
// =======================================================================
void OpenGl_GraduatedTrihedron::Axis::Release (OpenGl_Context* theCtx)
{
Label ->Release (theCtx);
Tickmark->Release (theCtx);
Line ->Release (theCtx);
Arrow ->Release (theCtx);
Label .Release (theCtx);
Tickmark.Release (theCtx);
Line .Release (theCtx);
Arrow .Release (theCtx);
}

View File

@@ -34,7 +34,6 @@ class OpenGl_View;
//! @sa Graphic3d_GraduatedTrihedron
class OpenGl_GraduatedTrihedron : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_GraduatedTrihedron, OpenGl_Element)
public:
DEFINE_STANDARD_ALLOC
@@ -71,11 +70,11 @@ private:
OpenGl_Vec3 Direction;
Quantity_Color NameColor;
Handle(OpenGl_AspectLine) LineAspect;
mutable Handle(OpenGl_Text) Label;
mutable Handle(OpenGl_PrimitiveArray) Tickmark;
mutable Handle(OpenGl_PrimitiveArray) Line;
mutable Handle(OpenGl_PrimitiveArray) Arrow;
OpenGl_AspectLine LineAspect;
mutable OpenGl_Text Label;
mutable OpenGl_PrimitiveArray Tickmark;
mutable OpenGl_PrimitiveArray Line;
mutable OpenGl_PrimitiveArray Arrow;
public:
@@ -166,7 +165,7 @@ private:
//! @param thaTx the X for vector of translation
//! @param thaTy the Y for vector of translation
//! @param thaTz the Z for vector of translation
void renderLine (const Handle(OpenGl_PrimitiveArray)& theLine,
void renderLine (const OpenGl_PrimitiveArray& theLine,
const Handle(OpenGl_Workspace)& theWorkspace,
const OpenGl_Mat4& theMat,
const Standard_ShortReal theXt,
@@ -216,13 +215,13 @@ protected:
mutable Axis myAxes[3]; //!< Axes for trihedron
mutable Graphic3d_GraduatedTrihedron myData;
mutable Handle(OpenGl_AspectLine) myGridLineAspect; //!< Color grid properties
mutable OpenGl_AspectLine myGridLineAspect; //!< Color grid properties
protected: //! @name Labels properties
mutable Handle(OpenGl_Text) myLabelValues;
mutable Handle(OpenGl_AspectText) myAspectLabels;
mutable Handle(OpenGl_AspectText) myAspectValues;
mutable OpenGl_Text myLabelValues;
mutable OpenGl_AspectText myAspectLabels;
mutable OpenGl_AspectText myAspectValues;
private:

View File

@@ -451,6 +451,8 @@ Standard_Integer OpenGl_GraphicDriver::InquireLimit (const Graphic3d_TypeOfLimit
return (!aCtx.IsNull() && aCtx->HasRayTracingTextures()) ? 1 : 0;
case Graphic3d_TypeOfLimit_HasRayTracingAdaptiveSampling:
return (!aCtx.IsNull() && aCtx->HasRayTracingAdaptiveSampling()) ? 1 : 0;
case Graphic3d_TypeOfLimit_HasRayTracingAdaptiveSamplingAtomic:
return (!aCtx.IsNull() && aCtx->HasRayTracingAdaptiveSamplingAtomic()) ? 1 : 0;
case Graphic3d_TypeOfLimit_HasBlendedOit:
return (!aCtx.IsNull()
&& aCtx->hasDrawBuffers != OpenGl_FeatureNotAvailable
@@ -463,6 +465,8 @@ Standard_Integer OpenGl_GraphicDriver::InquireLimit (const Graphic3d_TypeOfLimit
return !aCtx.IsNull() && aCtx->hasFlatShading != OpenGl_FeatureNotAvailable ? 1 : 0;
case Graphic3d_TypeOfLimit_IsWorkaroundFBO:
return !aCtx.IsNull() && aCtx->MaxTextureSize() != aCtx->MaxDumpSizeX() ? 1 : 0;
case Graphic3d_TypeOfLimit_HasMeshEdges:
return !aCtx.IsNull() && aCtx->hasGeometryStage != OpenGl_FeatureNotAvailable ? 1 : 0;
case Graphic3d_TypeOfLimit_NB:
return 0;
}
@@ -560,8 +564,8 @@ void OpenGl_GraphicDriver::TextSize (const Handle(Graphic3d_CView)& theView,
const Standard_ShortReal aHeight = (theHeight < 2.0f) ? DefaultTextHeight() : theHeight;
OpenGl_TextParam aTextParam;
aTextParam.Height = (int )aHeight;
Handle(OpenGl_AspectText) aTextAspect = new OpenGl_AspectText();
aTextAspect->Aspect()->SetSpace (0.3);
OpenGl_AspectText aTextAspect;
aTextAspect.Aspect()->SetSpace (0.3);
TCollection_ExtendedString anExtText = theText;
NCollection_String aText (anExtText.ToExtString());
OpenGl_Text::StringSize(aCtx, aText, aTextAspect, aTextParam, theView->RenderingParams().Resolution, theWidth, theAscent, theDescent);

View File

@@ -40,7 +40,7 @@ namespace
//! should be rendered or not.
//! @return True if element passes the check and renders,
static bool renderFiltered (const Handle(OpenGl_Workspace)& theWorkspace,
const Handle(OpenGl_Element)& theElement)
OpenGl_Element* theElement)
{
if (!theWorkspace->ShouldRender (theElement))
{
@@ -58,6 +58,12 @@ namespace
// =======================================================================
OpenGl_Group::OpenGl_Group (const Handle(Graphic3d_Structure)& theStruct)
: Graphic3d_Group (theStruct),
myAspectLine(NULL),
myAspectFace(NULL),
myAspectMarker(NULL),
myAspectText(NULL),
myFirst(NULL),
myLast(NULL),
myIsRaytracable (Standard_False)
{
Handle(OpenGl_Structure) aStruct = Handle(OpenGl_Structure)::DownCast (myStructure->CStructure());
@@ -87,7 +93,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d
return;
}
if (myAspectLine.IsNull())
if (myAspectLine == NULL)
{
myAspectLine = new OpenGl_AspectLine (theAspect);
}
@@ -104,7 +110,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d
// =======================================================================
void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspect)
{
if (myAspectLine.IsNull())
if (myAspectLine == NULL)
{
SetGroupPrimitivesAspect (theAspect);
return;
@@ -114,7 +120,7 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& th
return;
}
Handle(OpenGl_AspectLine) anAspectLine = new OpenGl_AspectLine (theAspect);
OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine (theAspect);
AddElement (anAspectLine);
Update();
}
@@ -130,7 +136,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillAr
return;
}
if (myAspectFace.IsNull())
if (myAspectFace == NULL)
{
myAspectFace = new OpenGl_AspectFace (theAspect);
}
@@ -157,7 +163,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillAr
// =======================================================================
void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect)
{
if (myAspectFace.IsNull())
if (myAspectFace == NULL)
{
SetGroupPrimitivesAspect (theAspect);
return;
@@ -167,7 +173,7 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)
return;
}
Handle(OpenGl_AspectFace) anAspectFace = new OpenGl_AspectFace (theAspect);
OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace (theAspect);
AddElement (anAspectFace);
Update();
}
@@ -183,7 +189,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker
return;
}
if (myAspectMarker.IsNull())
if (myAspectMarker == NULL)
{
myAspectMarker = new OpenGl_AspectMarker (theAspMarker);
}
@@ -200,7 +206,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker
// =======================================================================
void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
{
if (myAspectMarker.IsNull())
if (myAspectMarker == NULL)
{
SetGroupPrimitivesAspect (theAspMarker);
return;
@@ -210,7 +216,7 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)&
return;
}
Handle(OpenGl_AspectMarker) anAspectMarker = new OpenGl_AspectMarker (theAspMarker);
OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker (theAspMarker);
AddElement (anAspectMarker);
Update();
}
@@ -226,7 +232,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d
return;
}
if (myAspectText.IsNull())
if (myAspectText == NULL)
{
myAspectText = new OpenGl_AspectText (theAspText);
}
@@ -243,7 +249,7 @@ void OpenGl_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d
// =======================================================================
void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
{
if (myAspectText.IsNull())
if (myAspectText == NULL)
{
SetGroupPrimitivesAspect (theAspText);
return;
@@ -253,7 +259,7 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& th
return;
}
Handle(OpenGl_AspectText) anAspectText = new OpenGl_AspectText (theAspText);
OpenGl_AspectText* anAspectText = new OpenGl_AspectText (theAspText);
AddElement (anAspectText);
Update();
}
@@ -264,25 +270,25 @@ void OpenGl_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& th
// =======================================================================
void OpenGl_Group::SynchronizeAspects()
{
if (!myAspectFace.IsNull())
if (myAspectFace != NULL)
{
myAspectFace->SynchronizeAspects();
}
if (!myAspectLine.IsNull())
if (myAspectLine != NULL)
{
myAspectLine->SynchronizeAspects();
}
if (!myAspectMarker.IsNull())
if (myAspectMarker != NULL)
{
myAspectMarker->SynchronizeAspects();
}
if (!myAspectText.IsNull())
if (myAspectText != NULL)
{
myAspectText->SynchronizeAspects();
}
for (OpenGl_ElementNodes::Iterator anElemIterator(myElements); anElemIterator.More(); anElemIterator.Next())
for (OpenGl_ElementNode* aNode = myFirst; aNode != NULL; aNode = aNode->next)
{
anElemIterator.ChangeValue()->SynchronizeAspects();
aNode->elem->SynchronizeAspects();
}
}
@@ -305,7 +311,7 @@ void OpenGl_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theTy
OpenGl_Structure* aStruct = GlStruct();
const OpenGl_GraphicDriver* aDriver = aStruct->GlDriver();
Handle(OpenGl_PrimitiveArray) anArray = new OpenGl_PrimitiveArray (aDriver, theType, theIndices, theAttribs, theBounds);
OpenGl_PrimitiveArray* anArray = new OpenGl_PrimitiveArray (aDriver, theType, theIndices, theAttribs, theBounds);
AddElement (anArray);
Graphic3d_Group::AddPrimitiveArray (theType, theIndices, theAttribs, theBounds, theToEvalMinMax);
@@ -335,7 +341,7 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf,
aParams.HAlign = theHta;
aParams.VAlign = theVta;
const OpenGl_Vec3 aPoint (thePoint.X(), thePoint.Y(), thePoint.Z());
Handle(OpenGl_Text) aText = new OpenGl_Text (theTextUtf, aPoint, aParams);
OpenGl_Text* aText = new OpenGl_Text (theTextUtf, aPoint, aParams);
AddElement (aText);
Graphic3d_Group::Text (theTextUtf, thePoint, theHeight, theAngle,
theTp, theHta, theVta, theToEvalMinMax);
@@ -367,7 +373,7 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf,
aParams.HAlign = theHTA;
aParams.VAlign = theVTA;
Handle(OpenGl_Text) aText = new OpenGl_Text (theTextUtf, theOrientation, aParams, theHasOwnAnchor != Standard_False);
OpenGl_Text* aText = new OpenGl_Text (theTextUtf, theOrientation, aParams, theHasOwnAnchor != Standard_False);
AddElement (aText);
@@ -390,7 +396,7 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf,
void OpenGl_Group::SetFlippingOptions (const Standard_Boolean theIsEnabled,
const gp_Ax2& theRefPlane)
{
Handle(OpenGl_Flipper) aFlipper = new OpenGl_Flipper (theRefPlane);
OpenGl_Flipper* aFlipper = new OpenGl_Flipper (theRefPlane);
aFlipper->SetOptions (theIsEnabled);
AddElement (aFlipper);
}
@@ -401,7 +407,7 @@ void OpenGl_Group::SetFlippingOptions (const Standard_Boolean theIsEnabled,
// =======================================================================
void OpenGl_Group::SetStencilTestOptions (const Standard_Boolean theIsEnabled)
{
Handle(OpenGl_StencilTest) aStencilTest = new OpenGl_StencilTest();
OpenGl_StencilTest* aStencilTest = new OpenGl_StencilTest();
aStencilTest->SetOptions (theIsEnabled);
AddElement (aStencilTest);
}
@@ -410,11 +416,16 @@ void OpenGl_Group::SetStencilTestOptions (const Standard_Boolean theIsEnabled)
// function : AddElement
// purpose :
// =======================================================================
void OpenGl_Group::AddElement (Handle(OpenGl_Element) theElem)
void OpenGl_Group::AddElement (OpenGl_Element* theElem)
{
myElements.Append (theElem);
OpenGl_ElementNode *aNode = new OpenGl_ElementNode();
if (OpenGl_Raytrace::IsRaytracedElement (theElem))
aNode->elem = theElem;
aNode->next = NULL;
(myLast? myLast->next : myFirst) = aNode;
myLast = aNode;
if (OpenGl_Raytrace::IsRaytracedElement (aNode))
{
myIsRaytracable = Standard_True;
@@ -435,19 +446,19 @@ void OpenGl_Group::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
// Setup aspects
theWorkspace->SetAllowFaceCulling (myIsClosed
&& !theWorkspace->GetGlContext()->Clipping().IsClippingOrCappingOn());
const Handle(OpenGl_AspectLine)& aBackAspectLine = theWorkspace->AspectLine();
const Handle(OpenGl_AspectFace)& aBackAspectFace = theWorkspace->AspectFace();
const Handle(OpenGl_AspectMarker)& aBackAspectMarker = theWorkspace->AspectMarker();
const Handle(OpenGl_AspectText)& aBackAspectText = theWorkspace->AspectText();
const bool isLineSet = !myAspectLine.IsNull() && renderFiltered (theWorkspace, myAspectLine);
const bool isFaceSet = !myAspectFace.IsNull() && renderFiltered (theWorkspace, myAspectFace);
const bool isMarkerSet = !myAspectMarker.IsNull() && renderFiltered (theWorkspace, myAspectMarker);
const bool isTextSet = !myAspectText.IsNull() && renderFiltered (theWorkspace, myAspectText);
const OpenGl_AspectLine* aBackAspectLine = theWorkspace->AspectLine();
const OpenGl_AspectFace* aBackAspectFace = theWorkspace->AspectFace();
const OpenGl_AspectMarker* aBackAspectMarker = theWorkspace->AspectMarker();
const OpenGl_AspectText* aBackAspectText = theWorkspace->AspectText();
const bool isLineSet = myAspectLine && renderFiltered (theWorkspace, myAspectLine);
const bool isFaceSet = myAspectFace && renderFiltered (theWorkspace, myAspectFace);
const bool isMarkerSet = myAspectMarker && renderFiltered (theWorkspace, myAspectMarker);
const bool isTextSet = myAspectText && renderFiltered (theWorkspace, myAspectText);
// Render group elements
for (OpenGl_ElementNodes::Iterator anElemIterator(myElements); anElemIterator.More(); anElemIterator.Next())
for (OpenGl_ElementNode* aNodeIter = myFirst; aNodeIter != NULL; aNodeIter = aNodeIter->next)
{
renderFiltered (theWorkspace, anElemIterator.Value());
renderFiltered (theWorkspace, aNodeIter->elem);
}
// Restore aspects
@@ -488,11 +499,14 @@ void OpenGl_Group::Clear (const Standard_Boolean theToUpdateStructureMgr)
void OpenGl_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
{
// Delete elements
for (OpenGl_ElementNodes::Iterator anElemIterator(myElements); anElemIterator.More(); anElemIterator.Next())
while (myFirst != NULL)
{
OpenGl_Element::Destroy (theGlCtx.operator->(), anElemIterator.ChangeValue());
OpenGl_ElementNode* aNext = myFirst->next;
OpenGl_Element::Destroy (theGlCtx.operator->(), myFirst->elem);
delete myFirst;
myFirst = aNext;
}
myElements.Clear();
myLast = NULL;
OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectLine);
OpenGl_Element::Destroy (theGlCtx.operator->(), myAspectFace);

View File

@@ -29,7 +29,12 @@
class OpenGl_Group;
class OpenGl_Structure;
typedef NCollection_List<Handle(OpenGl_Element)> OpenGl_ElementNodes;
struct OpenGl_ElementNode
{
OpenGl_Element* elem;
OpenGl_ElementNode* next;
DEFINE_STANDARD_ALLOC
};
//! Implementation of low-level graphic group.
class OpenGl_Group : public Graphic3d_Group
@@ -45,9 +50,9 @@ public:
//! Return line aspect.
virtual Handle(Graphic3d_AspectLine3d) LineAspect() const Standard_OVERRIDE
{
return !myAspectLine.IsNull()
? myAspectLine->Aspect()
: Handle(Graphic3d_AspectLine3d)();
return myAspectLine != NULL
? myAspectLine->Aspect()
: Handle(Graphic3d_AspectLine3d)();
}
//! Update line aspect.
@@ -59,9 +64,9 @@ public:
//! Return marker aspect.
virtual Handle(Graphic3d_AspectMarker3d) MarkerAspect() const Standard_OVERRIDE
{
return !myAspectMarker.IsNull()
? myAspectMarker->Aspect()
: Handle(Graphic3d_AspectMarker3d)();
return myAspectMarker != NULL
? myAspectMarker->Aspect()
: Handle(Graphic3d_AspectMarker3d)();
}
//! Update marker aspect.
@@ -73,7 +78,7 @@ public:
//! Return fill area aspect.
virtual Handle(Graphic3d_AspectFillArea3d) FillAreaAspect() const Standard_OVERRIDE
{
return !myAspectFace.IsNull()
return myAspectFace != NULL
? myAspectFace->Aspect()
: Handle(Graphic3d_AspectFillArea3d)();
}
@@ -87,7 +92,7 @@ public:
//! Return marker aspect.
virtual Handle(Graphic3d_AspectText3d) TextAspect() const Standard_OVERRIDE
{
return !myAspectText.IsNull()
return myAspectText != NULL
? myAspectText->Aspect()
: Handle(Graphic3d_AspectText3d)();
}
@@ -140,16 +145,16 @@ public:
OpenGl_Structure* GlStruct() const { return (OpenGl_Structure* )(myStructure->CStructure().operator->()); }
Standard_EXPORT void AddElement (Handle(OpenGl_Element) theElem);
Standard_EXPORT void AddElement (OpenGl_Element* theElem);
Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
//! Returns OpenGl elements of the group
const OpenGl_ElementNodes& GetElements() const { return myElements; }
//! Returns first OpenGL element node of the group.
const OpenGl_ElementNode* FirstNode() const { return myFirst; }
//! Returns OpenGL face aspect.
const Handle(OpenGl_AspectFace)& AspectFace() const { return myAspectFace; }
const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
//! Is the group ray-tracable (contains ray-tracable elements)?
Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
@@ -160,12 +165,13 @@ protected:
protected:
Handle(OpenGl_AspectLine) myAspectLine;
Handle(OpenGl_AspectFace) myAspectFace;
Handle(OpenGl_AspectMarker) myAspectMarker;
Handle(OpenGl_AspectText) myAspectText;
OpenGl_AspectLine* myAspectLine;
OpenGl_AspectFace* myAspectFace;
OpenGl_AspectMarker* myAspectMarker;
OpenGl_AspectText* myAspectText;
OpenGl_ElementNodes myElements;
OpenGl_ElementNode* myFirst;
OpenGl_ElementNode* myLast;
Standard_Boolean myIsRaytracable;

View File

@@ -109,7 +109,11 @@ int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* t
}
#if !defined(GL_ES_VERSION_2_0)
if (theStyle->HatchType() != 0)
if (theGlCtx->core11 == NULL)
{
return 0;
}
else if (theStyle->HatchType() != 0)
{
theGlCtx->core11->glCallList ((GLuint)aGpuListId);
@@ -146,7 +150,11 @@ bool OpenGl_LineAttributes::SetEnabled (const OpenGl_Context* theGlCtx,
const bool anOldIsEnabled = myIsEnabled;
#if !defined(GL_ES_VERSION_2_0)
if (theToEnable)
if (theGlCtx->core11 == NULL)
{
return 0;
}
else if (theToEnable)
{
if (myTypeOfHatch != 0)
{

View File

@@ -50,6 +50,9 @@ public:
//! Alpha cutoff value.
float AlphaCutoff() const { return myAlphaCutoff; }
//! Return TRUE if alpha test should be enabled.
bool HasAlphaCutoff() const { return myAlphaCutoff <= 1.0f; }
//! Distinguish front/back flag.
bool ToDistinguish() const { return myToDistinguish; }

View File

@@ -13,13 +13,12 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_AspectFace.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <OpenGl_IndexBuffer.hxx>
#include <OpenGl_PointSprite.hxx>
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_Sampler.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_ShaderProgram.hxx>
@@ -29,8 +28,6 @@
#include <Graphic3d_TextureParams.hxx>
#include <NCollection_AlignedAllocator.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_PrimitiveArray, OpenGl_Element)
namespace
{
//! Convert data type to GL info
@@ -505,13 +502,10 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo
return;
}
const Handle(OpenGl_AspectLine) anAspectLineOld = theWorkspace->AspectLine();
theWorkspace->SetAspectLine (theWorkspace->AspectFace()->AspectEdge());
const Handle(OpenGl_AspectLine)& anAspect = theWorkspace->ApplyAspectLine();
const OpenGl_AspectLine* anAspectLineOld = theWorkspace->SetAspectLine (theWorkspace->AspectFace()->AspectEdge());
const OpenGl_AspectLine* anAspect = theWorkspace->ApplyAspectLine();
#if !defined(GL_ES_VERSION_2_0)
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
const Standard_Integer aPolyModeOld = aGlContext->SetPolygonMode (GL_LINE);
#endif
if (aGlContext->core20fwd != NULL)
@@ -585,6 +579,9 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo
// restore line context
theWorkspace->SetAspectLine (anAspectLineOld);
#if !defined(GL_ES_VERSION_2_0)
aGlContext->SetPolygonMode (aPolyModeOld);
#endif
}
// =======================================================================
@@ -593,8 +590,8 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo
// =======================================================================
void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const
{
const Handle(OpenGl_AspectMarker)& anAspectMarker = theWorkspace->ApplyAspectMarker();
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
const OpenGl_AspectMarker* anAspectMarker = theWorkspace->ApplyAspectMarker();
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
const GLenum aDrawMode = !aCtx->ActiveProgram().IsNull()
&& aCtx->ActiveProgram()->HasTessellationStage()
? GL_PATCHES
@@ -770,9 +767,9 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
return;
}
const Handle(OpenGl_AspectFace)& anAspectFace = theWorkspace->ApplyAspectFace();
const Handle(OpenGl_AspectLine)& anAspectLine = theWorkspace->ApplyAspectLine();
const Handle(OpenGl_AspectMarker)& anAspectMarker = myDrawMode == GL_POINTS
const OpenGl_AspectFace* anAspectFace = theWorkspace->ApplyAspectFace();
const OpenGl_AspectLine* anAspectLine = theWorkspace->ApplyAspectLine();
const OpenGl_AspectMarker* anAspectMarker = myDrawMode == GL_POINTS
? theWorkspace->ApplyAspectMarker()
: theWorkspace->AspectMarker();
@@ -806,9 +803,34 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
// Temporarily disable environment mapping
Handle(OpenGl_TextureSet) aTextureBack;
bool toDrawArray = true;
int toDrawInteriorEdges = 0; // 0 - no edges, 1 - glsl edges, 2 - polygonMode
if (myDrawMode > GL_LINE_STRIP)
{
toDrawArray = anAspectFace->Aspect()->InteriorStyle() != Aspect_IS_EMPTY;
if (anAspectFace->Aspect()->ToDrawEdges())
{
toDrawInteriorEdges = 1;
toDrawArray = true;
#if !defined(GL_ES_VERSION_2_0)
if (anAspectFace->Aspect()->EdgeLineType() != Aspect_TOL_SOLID
|| aCtx->hasGeometryStage == OpenGl_FeatureNotAvailable
|| aCtx->caps->usePolygonMode)
{
toDrawInteriorEdges = 2;
if (anAspectFace->Aspect()->InteriorStyle() == Aspect_IS_EMPTY)
{
if (anAspectFace->Aspect()->EdgeLineType() != Aspect_TOL_SOLID)
{
toDrawArray = false;
}
else
{
aCtx->SetPolygonMode (GL_LINE);
}
}
}
#endif
}
}
else if (myDrawMode <= GL_LINE_STRIP)
{
@@ -872,10 +894,16 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
const Standard_Boolean toEnableEnvMap = (!aTextures.IsNull() && (aTextures == theWorkspace->EnvironmentTexture()));
aCtx->ShaderManager()->BindFaceProgram (aTextures,
aShadingModel,
anAspectFace->Aspect()->AlphaMode(),
aCtx->ShaderManager()->MaterialState().HasAlphaCutoff() ? Graphic3d_AlphaMode_Mask : Graphic3d_AlphaMode_Opaque,
toDrawInteriorEdges == 1 ? anAspectFace->Aspect()->InteriorStyle() : Aspect_IS_SOLID,
hasVertColor,
toEnableEnvMap,
toDrawInteriorEdges == 1,
anAspectFace->ShaderProgramRes (aCtx));
if (toDrawInteriorEdges == 1)
{
aCtx->ShaderManager()->PushInteriorState (aCtx->ActiveProgram(), anAspectFace->Aspect());
}
break;
}
}
@@ -931,24 +959,21 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
{
aCtx->BindTextures (aTextureBack);
}
else
#if !defined(GL_ES_VERSION_2_0)
else if (toDrawInteriorEdges == 2)
{
if (anAspectFace->Aspect()->ToDrawEdges()
|| anAspectFace->Aspect()->InteriorStyle() == Aspect_IS_HIDDENLINE)
if (anAspectFace->Aspect()->InteriorStyle() == Aspect_IS_HOLLOW
&& anAspectFace->Aspect()->EdgeLineType() == Aspect_TOL_SOLID)
{
aCtx->SetPolygonMode (GL_FILL);
}
else
{
const OpenGl_Vec4& anEdgeColor = theWorkspace->EdgeColor();
drawEdges (anEdgeColor, theWorkspace);
// restore OpenGL polygon mode if needed
#if !defined(GL_ES_VERSION_2_0)
if (anAspectFace->Aspect()->InteriorStyle() >= Aspect_IS_HATCH)
{
glPolygonMode (GL_FRONT_AND_BACK,
anAspectFace->Aspect()->InteriorStyle() == Aspect_IS_POINT ? GL_POINT : GL_FILL);
}
#endif
}
}
#endif
}
// =======================================================================
@@ -1046,7 +1071,7 @@ Standard_Boolean OpenGl_PrimitiveArray::processIndices (const Handle(OpenGl_Cont
return Standard_True;
}
if (myAttribs->NbElements > IntegerLast()/*std::numeric_limits<GLushort>::max()*/)
if (myAttribs->NbElements > std::numeric_limits<GLushort>::max())
{
Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (new NCollection_AlignedAllocator (16));
if (!anAttribs->Init (myIndices->NbElements, myAttribs->AttributesArray(), myAttribs->NbAttributes))

View File

@@ -31,7 +31,6 @@ class OpenGl_GraphicDriver;
//! Class for rendering of arbitrary primitive array.
class OpenGl_PrimitiveArray : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_PrimitiveArray, OpenGl_Element)
public:
//! OpenGL does not provide a constant for "none" draw mode.
//! So we define our own one that does not conflict with GL constants and utilizes common GL invalid value.

View File

@@ -593,10 +593,21 @@ namespace OpenGl_Raytrace
// function : IsRaytracedElement
// purpose : Checks to see if the element contains ray-trace geometry
// =======================================================================
Standard_Boolean IsRaytracedElement (const Handle(OpenGl_Element) theElement)
Standard_Boolean IsRaytracedElement (const OpenGl_ElementNode* theNode)
{
Handle(OpenGl_PrimitiveArray) anArray = Handle(OpenGl_PrimitiveArray)::DownCast (theElement);
return !anArray.IsNull()
OpenGl_PrimitiveArray* anArray = dynamic_cast<OpenGl_PrimitiveArray*> (theNode->elem);
return anArray != NULL
&& anArray->DrawMode() >= GL_TRIANGLES;
}
// =======================================================================
// function : IsRaytracedElement
// purpose : Checks to see if the element contains ray-trace geometry
// =======================================================================
Standard_Boolean IsRaytracedElement (const OpenGl_Element* theElement)
{
const OpenGl_PrimitiveArray* anArray = dynamic_cast<const OpenGl_PrimitiveArray*> (theElement);
return anArray != NULL
&& anArray->DrawMode() >= GL_TRIANGLES;
}
@@ -606,9 +617,9 @@ namespace OpenGl_Raytrace
// =======================================================================
Standard_Boolean IsRaytracedGroup (const OpenGl_Group* theGroup)
{
for (OpenGl_ElementNodes::Iterator anElemIterator (theGroup->GetElements()); anElemIterator.More(); anElemIterator.Next())
for (const OpenGl_ElementNode* aNode = theGroup->FirstNode(); aNode != NULL; aNode = aNode->next)
{
if (IsRaytracedElement (anElemIterator.Value()))
if (IsRaytracedElement (aNode))
{
return Standard_True;
}

View File

@@ -36,7 +36,10 @@ namespace OpenGl_Raytrace
Standard_Boolean IsRaytracedGroup (const OpenGl_Group* theGroup);
//! Checks to see if the element contains ray-trace geometry.
Standard_Boolean IsRaytracedElement (const Handle(OpenGl_Element) theElement);
Standard_Boolean IsRaytracedElement (const OpenGl_ElementNode* theNode);
//! Checks to see if the element contains ray-trace geometry.
Standard_Boolean IsRaytracedElement (const OpenGl_Element* theElement);
}
//! Stores properties of surface material.

View File

@@ -23,20 +23,22 @@
//! Standard GLSL program combination bits.
enum OpenGl_ProgramOptions
{
OpenGl_PO_Point = 0x001, //!< point marker
OpenGl_PO_VertColor = 0x002, //!< per-vertex color
OpenGl_PO_TextureRGB = 0x004, //!< handle RGB texturing
OpenGl_PO_TextureA = 0x008, //!< handle Alpha texturing
OpenGl_PO_TextureEnv = 0x010, //!< handle environment map
OpenGl_PO_StippleLine = 0x020, //!< stipple line
OpenGl_PO_ClipPlanes1 = 0x040, //!< handle 1 clipping plane
OpenGl_PO_ClipPlanes2 = 0x080, //!< handle 2 clipping planes
//OpenGl_PO_ClipPlanes3 = OpenGl_PO_ClipPlanes1|OpenGl_PO_ClipPlanes2, //!< handle 3 clipping planes - not implemented
OpenGl_PO_ClipPlanesN = 0x100, //!< handle N clipping planes
OpenGl_PO_ClipChains = 0x200, //!< handle chains of clipping planes
OpenGl_PO_AlphaTest = 0x400, //!< discard fragment by alpha test (defined by cutoff value)
OpenGl_PO_WriteOit = 0x800, //!< write coverage buffer for Blended Order-Independent Transparency
OpenGl_PO_NB = 0x1000 //!< overall number of combinations
OpenGl_PO_Point = 0x0001, //!< point marker
OpenGl_PO_VertColor = 0x0002, //!< per-vertex color
OpenGl_PO_TextureRGB = 0x0004, //!< handle RGB texturing
OpenGl_PO_TextureA = 0x0008, //!< handle Alpha texturing
OpenGl_PO_TextureEnv = 0x0010, //!< handle environment map
OpenGl_PO_StippleLine = 0x0020, //!< stipple line
OpenGl_PO_ClipPlanes1 = 0x0040, //!< handle 1 clipping plane
OpenGl_PO_ClipPlanes2 = 0x0080, //!< handle 2 clipping planes
OpenGl_PO_ClipPlanesN = OpenGl_PO_ClipPlanes1|OpenGl_PO_ClipPlanes2, //!< handle N clipping planes
OpenGl_PO_ClipChains = 0x0100, //!< handle chains of clipping planes
OpenGl_PO_MeshEdges = 0x0200, //!< draw mesh edges (wireframe)
OpenGl_PO_AlphaTest = 0x0400, //!< discard fragment by alpha test (defined by cutoff value)
OpenGl_PO_WriteOit = 0x0800, //!< write coverage buffer for Blended Order-Independent Transparency
//
OpenGl_PO_NB = 0x1000, //!< overall number of combinations
OpenGl_PO_NeedsGeomShader = OpenGl_PO_MeshEdges,
};
//! Alias to programs array of predefined length

View File

@@ -281,6 +281,19 @@ EOL" {"
EOL" discard;"
EOL" }";
//! Modify color for Wireframe presentation.
const char THE_FRAG_WIREFRAME_COLOR[] =
EOL"vec4 getFinalColor(void)"
EOL"{"
EOL" float aDistance = min (min (EdgeDistance[0], EdgeDistance[1]), EdgeDistance[2]);"
EOL" bool isHollow = occWireframeColor.a < 0.0;"
EOL" float aMixVal = smoothstep (occLineWidth - occLineFeather * 0.5, occLineWidth + occLineFeather * 0.5, aDistance);"
EOL" vec4 aMixColor = isHollow"
EOL" ? vec4 (getColor().rgb, 1.0 - aMixVal)" // edges only (of interior color)
EOL" : mix (occWireframeColor, getColor(), aMixVal);" // interior + edges
EOL" return aMixColor;"
EOL"}";
#if !defined(GL_ES_VERSION_2_0)
static const GLfloat THE_DEFAULT_AMBIENT[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
@@ -1130,6 +1143,7 @@ void OpenGl_ShaderManager::PushMaterialState (const Handle(OpenGl_ShaderProgram)
return;
}
myContext->SetSampleAlphaToCoverage (false);
if (myMaterialState.AlphaCutoff() < ShortRealLast())
{
glAlphaFunc (GL_GEQUAL, myMaterialState.AlphaCutoff());
@@ -1158,6 +1172,7 @@ void OpenGl_ShaderManager::PushMaterialState (const Handle(OpenGl_ShaderProgram)
return;
}
myContext->SetSampleAlphaToCoverage (myMaterialState.HasAlphaCutoff());
theProgram->SetUniform (myContext,
theProgram->GetStateLocation (OpenGl_OCCT_ALPHA_CUTOFF),
myMaterialState.AlphaCutoff());
@@ -1168,15 +1183,12 @@ void OpenGl_ShaderManager::PushMaterialState (const Handle(OpenGl_ShaderProgram)
theProgram->GetStateLocation (OpenGl_OCCT_DISTINGUISH_MODE),
myMaterialState.ToDistinguish() ? 1 : 0);
const GLint aLocFront = theProgram->GetStateLocation (OpenGl_OCCT_FRONT_MATERIAL);
if (aLocFront != OpenGl_ShaderProgram::INVALID_LOCATION)
if (const OpenGl_ShaderUniformLocation aLocFront = theProgram->GetStateLocation (OpenGl_OCCT_FRONT_MATERIAL))
{
theProgram->SetUniform (myContext, aLocFront, OpenGl_Material::NbOfVec4(),
aFrontMat.Packed());
}
const GLint aLocBack = theProgram->GetStateLocation (OpenGl_OCCT_BACK_MATERIAL);
if (aLocBack != OpenGl_ShaderProgram::INVALID_LOCATION)
if (const OpenGl_ShaderUniformLocation aLocBack = theProgram->GetStateLocation (OpenGl_OCCT_BACK_MATERIAL))
{
theProgram->SetUniform (myContext, aLocBack, OpenGl_Material::NbOfVec4(),
aBackMat.Packed());
@@ -1212,6 +1224,45 @@ void OpenGl_ShaderManager::PushOitState (const Handle(OpenGl_ShaderProgram)& the
}
}
// =======================================================================
// function : PushInteriorState
// purpose :
// =======================================================================
void OpenGl_ShaderManager::PushInteriorState (const Handle(OpenGl_ShaderProgram)& theProgram,
const Handle(Graphic3d_AspectFillArea3d)& theAspect) const
{
if (theProgram.IsNull()
|| !theProgram->IsValid())
{
return;
}
if (const OpenGl_ShaderUniformLocation aLocViewPort = theProgram->GetStateLocation (OpenGl_OCCT_VIEWPORT))
{
theProgram->SetUniform (myContext, aLocViewPort, OpenGl_Vec4 ((float )myContext->Viewport()[0], (float )myContext->Viewport()[1], (float )myContext->Viewport()[2], (float )myContext->Viewport()[3]));
}
if (const OpenGl_ShaderUniformLocation aLocLineWidth = theProgram->GetStateLocation (OpenGl_OCCT_LINE_WIDTH))
{
theProgram->SetUniform (myContext, aLocLineWidth, theAspect->EdgeWidth() * myContext->LineWidthScale());
theProgram->SetUniform (myContext, theProgram->GetStateLocation (OpenGl_OCCT_LINE_FEATHER), myContext->LineFeather() * myContext->LineWidthScale());
}
if (const OpenGl_ShaderUniformLocation aLocWireframeColor = theProgram->GetStateLocation (OpenGl_OCCT_WIREFRAME_COLOR))
{
if (theAspect->InteriorStyle() == Aspect_IS_HOLLOW)
{
theProgram->SetUniform (myContext, aLocWireframeColor, OpenGl_Vec4 (-1.0f, -1.0f, -1.0f, -1.0f));
}
else
{
theProgram->SetUniform (myContext, aLocWireframeColor, theAspect->EdgeColorRGBA());
}
}
if (const OpenGl_ShaderUniformLocation aLocQuadModeState = theProgram->GetStateLocation (OpenGl_OCCT_QUAD_MODE_STATE))
{
theProgram->SetUniform (myContext, aLocQuadModeState, theAspect->ToSkipFirstEdge() ? 1 : 0);
}
}
// =======================================================================
// function : PushState
// purpose : Pushes state of OCCT graphics parameters to the program
@@ -1264,19 +1315,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFont()
EOL"}";
Handle(Graphic3d_ShaderProgram) aProgramSrc = new Graphic3d_ShaderProgram();
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core32 != NULL)
{
aProgramSrc->SetHeader ("#version 150");
}
#else
if (myContext->IsGlGreaterEqual (3, 1))
{
// prefer "100 es" on OpenGL ES 3.0 devices
// and "300 es" on newer devices (3.1+)
aProgramSrc->SetHeader ("#version 300 es");
}
#endif
defaultGlslVersion (aProgramSrc, 0);
aProgramSrc->SetNbLightsMax (0);
aProgramSrc->SetNbClipPlanesMax (0);
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts));
@@ -1482,6 +1521,164 @@ namespace
}
// =======================================================================
// function : defaultGlslVersion
// purpose :
// =======================================================================
int OpenGl_ShaderManager::defaultGlslVersion (const Handle(Graphic3d_ShaderProgram)& theProgram,
int theBits,
bool theUsesDerivates) const
{
int aBits = theBits;
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core32 != NULL)
{
theProgram->SetHeader ("#version 150");
}
else
{
if ((theBits & OpenGl_PO_StippleLine) != 0)
{
if (myContext->IsGlGreaterEqual (3, 0))
{
theProgram->SetHeader ("#version 130");
}
else if (myContext->CheckExtension ("GL_EXT_gpu_shader4"))
{
theProgram->SetHeader ("#extension GL_EXT_gpu_shader4 : enable");
}
else
{
aBits = aBits & ~OpenGl_PO_StippleLine;
}
}
}
(void )theUsesDerivates;
#else
// prefer "100 es" on OpenGL ES 3.0- devices (save the features unavailable before "300 es")
// and "300 es" on OpenGL ES 3.1+ devices
if (myContext->IsGlGreaterEqual (3, 1))
{
if ((theBits & OpenGl_PO_NeedsGeomShader) != 0)
{
theProgram->SetHeader (myContext->hasGeometryStage != OpenGl_FeatureInExtensions ? "#version 320 es" : "#version 310 es");
}
else
{
theProgram->SetHeader ("#version 300 es");
}
}
else
{
if ((theBits & OpenGl_PO_WriteOit) != 0
|| (theBits & OpenGl_PO_StippleLine) != 0)
{
if (myContext->IsGlGreaterEqual (3, 0))
{
theProgram->SetHeader ("#version 300 es");
}
else
{
aBits = aBits & ~OpenGl_PO_WriteOit;
aBits = aBits & ~OpenGl_PO_StippleLine;
}
}
if (theUsesDerivates)
{
if (myContext->IsGlGreaterEqual (3, 0))
{
theProgram->SetHeader ("#version 300 es");
}
else if (myContext->oesStdDerivatives)
{
theProgram->SetHeader ("#extension GL_OES_standard_derivatives : enable");
}
}
}
#endif
return aBits;
}
// =======================================================================
// function : prepareGeomMainSrc
// purpose :
// =======================================================================
TCollection_AsciiString OpenGl_ShaderManager::prepareGeomMainSrc (OpenGl_ShaderObject::ShaderVariableList& theUnifoms,
OpenGl_ShaderObject::ShaderVariableList& theStageInOuts,
Standard_Integer theBits)
{
if ((theBits & OpenGl_PO_NeedsGeomShader) == 0)
{
return TCollection_AsciiString();
}
TCollection_AsciiString aSrcMainGeom =
EOL"void main()"
EOL"{";
if ((theBits & OpenGl_PO_MeshEdges) != 0)
{
theUnifoms.Append (OpenGl_ShaderObject::ShaderVariable ("vec4 occViewport", Graphic3d_TOS_GEOMETRY));
theUnifoms.Append (OpenGl_ShaderObject::ShaderVariable ("bool occIsQuadMode", Graphic3d_TOS_GEOMETRY));
theUnifoms.Append (OpenGl_ShaderObject::ShaderVariable ("float occLineWidth", Graphic3d_TOS_GEOMETRY));
theUnifoms.Append (OpenGl_ShaderObject::ShaderVariable ("float occLineWidth", Graphic3d_TOS_FRAGMENT));
theUnifoms.Append (OpenGl_ShaderObject::ShaderVariable ("float occLineFeather", Graphic3d_TOS_FRAGMENT));
theUnifoms.Append (OpenGl_ShaderObject::ShaderVariable ("vec4 occWireframeColor", Graphic3d_TOS_FRAGMENT));
theStageInOuts.Append(OpenGl_ShaderObject::ShaderVariable ("vec3 EdgeDistance", Graphic3d_TOS_GEOMETRY | Graphic3d_TOS_FRAGMENT));
aSrcMainGeom = TCollection_AsciiString()
+ EOL"vec3 ViewPortTransform (vec4 theVec)"
EOL"{"
EOL" vec3 aWinCoord = theVec.xyz / theVec.w;"
EOL" aWinCoord = aWinCoord * 0.5 + 0.5;"
EOL" aWinCoord.xy = aWinCoord.xy * occViewport.zw + occViewport.xy;"
EOL" return aWinCoord;"
EOL"}"
+ aSrcMainGeom
+ EOL" vec3 aSideA = ViewPortTransform (gl_in[2].gl_Position) - ViewPortTransform (gl_in[1].gl_Position);"
EOL" vec3 aSideB = ViewPortTransform (gl_in[2].gl_Position) - ViewPortTransform (gl_in[0].gl_Position);"
EOL" vec3 aSideC = ViewPortTransform (gl_in[1].gl_Position) - ViewPortTransform (gl_in[0].gl_Position);"
EOL" float aQuadArea = abs (aSideB.x * aSideC.y - aSideB.y * aSideC.x);"
EOL" vec3 aLenABC = vec3 (length (aSideA), length (aSideB), length (aSideC));"
EOL" vec3 aHeightABC = vec3 (aQuadArea) / aLenABC;"
EOL" aHeightABC = max (aHeightABC, vec3 (10.0 * occLineWidth));" // avoid shrunk presentation disappearing at distance
EOL" float aQuadModeHeightC = occIsQuadMode ? occLineWidth + 1.0 : 0.0;";
}
for (Standard_Integer aVertIter = 0; aVertIter < 3; ++aVertIter)
{
const TCollection_AsciiString aVertIndex (aVertIter);
// pass variables from Vertex shader to Fragment shader through Geometry shader
for (OpenGl_ShaderObject::ShaderVariableList::Iterator aVarListIter (theStageInOuts); aVarListIter.More(); aVarListIter.Next())
{
if (aVarListIter.Value().Stages == (Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT))
{
const TCollection_AsciiString aVarName = aVarListIter.Value().Name.Token (" ", 2);
aSrcMainGeom += TCollection_AsciiString()
+ EOL" geomOut." + aVarName + " = geomIn[" + aVertIndex + "]." + aVarName + ";";
}
}
if ((theBits & OpenGl_PO_MeshEdges) != 0)
{
switch (aVertIter)
{
case 0: aSrcMainGeom += EOL" EdgeDistance = vec3 (aHeightABC[0], 0.0, aQuadModeHeightC);"; break;
case 1: aSrcMainGeom += EOL" EdgeDistance = vec3 (0.0, aHeightABC[1], aQuadModeHeightC);"; break;
case 2: aSrcMainGeom += EOL" EdgeDistance = vec3 (0.0, 0.0, aHeightABC[2]);"; break;
}
}
aSrcMainGeom += TCollection_AsciiString()
+ EOL" gl_Position = gl_in[" + aVertIndex + "].gl_Position;"
EOL" EmitVertex();";
}
aSrcMainGeom +=
EOL" EndPrimitive();"
EOL"}";
return aSrcMainGeom;
}
// =======================================================================
// function : prepareStdProgramUnlit
// purpose :
@@ -1490,11 +1687,12 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
const Standard_Integer theBits)
{
Handle(Graphic3d_ShaderProgram) aProgramSrc = new Graphic3d_ShaderProgram();
TCollection_AsciiString aSrcVert, aSrcVertExtraMain, aSrcVertExtraFunc, aSrcGetAlpha;
TCollection_AsciiString aSrcFrag, aSrcFragExtraMain, aSrcFragWriteOit;
TCollection_AsciiString aSrcVert, aSrcVertExtraMain, aSrcVertExtraFunc, aSrcGetAlpha, aSrcVertEndMain;
TCollection_AsciiString aSrcFrag, aSrcFragExtraMain;
TCollection_AsciiString aSrcFragGetColor = EOL"vec4 getColor(void) { return occColor; }";
TCollection_AsciiString aSrcFragMainGetColor = EOL" occSetFragColor (getColor());";
TCollection_AsciiString aSrcFragMainGetColor = EOL" occSetFragColor (getFinalColor());";
OpenGl_ShaderObject::ShaderVariableList aUniforms, aStageInOuts;
if ((theBits & OpenGl_PO_Point) != 0)
{
#if defined(GL_ES_VERSION_2_0)
@@ -1578,7 +1776,14 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
EOL" PositionWorld = occModelWorldMatrix * occVertex;"
EOL" Position = occWorldViewMatrix * PositionWorld;";
if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
if ((theBits & OpenGl_PO_ClipPlanesN) == OpenGl_PO_ClipPlanesN)
{
aNbClipPlanes = Graphic3d_ShaderProgram::THE_MAX_CLIP_PLANES_DEFAULT;
aSrcFragExtraMain += (theBits & OpenGl_PO_ClipChains) != 0
? THE_FRAG_CLIP_CHAINS_N
: THE_FRAG_CLIP_PLANES_N;
}
else if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
{
aNbClipPlanes = 1;
aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_1;
@@ -1590,53 +1795,20 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
? THE_FRAG_CLIP_CHAINS_2
: THE_FRAG_CLIP_PLANES_2;
}
else
{
aNbClipPlanes = Graphic3d_ShaderProgram::THE_MAX_CLIP_PLANES_DEFAULT;
aSrcFragExtraMain += (theBits & OpenGl_PO_ClipChains) != 0
? THE_FRAG_CLIP_CHAINS_N
: THE_FRAG_CLIP_PLANES_N;
}
}
if ((theBits & OpenGl_PO_WriteOit) != 0)
{
aProgramSrc->SetNbFragmentOutputs (2);
aProgramSrc->SetWeightOitOutput (true);
#if defined(GL_ES_VERSION_2_0)
if (myContext->IsGlGreaterEqual (3, 0))
{
aProgramSrc->SetHeader ("#version 300 es");
}
#endif
}
TCollection_AsciiString aSrcVertEndMain;
if ((theBits & OpenGl_PO_StippleLine) != 0)
{
bool hasGlslBitOps = false;
#if defined(GL_ES_VERSION_2_0)
if (myContext->IsGlGreaterEqual (3, 0))
const Standard_Integer aBits = defaultGlslVersion (aProgramSrc, theBits);
if ((aBits & OpenGl_PO_StippleLine) != 0)
{
aProgramSrc->SetHeader ("#version 300 es");
hasGlslBitOps = true;
}
#else
if (myContext->IsGlGreaterEqual (3, 0))
{
aProgramSrc->SetHeader ("#version 130");
hasGlslBitOps = true;
}
else if(myContext->CheckExtension("GL_EXT_gpu_shader4"))
{
aProgramSrc->SetHeader ("#extension GL_EXT_gpu_shader4 : enable");
hasGlslBitOps = true;
}
#endif
if (hasGlslBitOps)
{
aUniforms.Append (OpenGl_ShaderObject::ShaderVariable ("int uPattern;", Graphic3d_TOS_FRAGMENT));
aUniforms.Append (OpenGl_ShaderObject::ShaderVariable ("float uFactor;", Graphic3d_TOS_FRAGMENT));
aUniforms.Append (OpenGl_ShaderObject::ShaderVariable ("int uPattern", Graphic3d_TOS_FRAGMENT));
aUniforms.Append (OpenGl_ShaderObject::ShaderVariable ("float uFactor", Graphic3d_TOS_FRAGMENT));
aStageInOuts.Append (OpenGl_ShaderObject::ShaderVariable ("vec2 ScreenSpaceCoord", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertEndMain =
EOL" ScreenSpaceCoord = gl_Position.xy / gl_Position.w;";
@@ -1645,7 +1817,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
EOL" float aRotatePoint = gl_FragCoord.x * sin (anAngle) + gl_FragCoord.y * cos (anAngle);"
EOL" uint aBit = uint (floor (aRotatePoint / uFactor + 0.5)) & 15U;"
EOL" if ((uint (uPattern) & (1U << aBit)) == 0U) discard;"
EOL" vec4 aColor = getColor();"
EOL" vec4 aColor = getFinalColor();"
EOL" if (aColor.a <= 0.1) discard;"
EOL" occSetFragColor (aColor);";
}
@@ -1664,6 +1836,11 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
+ aSrcVertEndMain
+ EOL"}";
TCollection_AsciiString aSrcGeom = prepareGeomMainSrc (aUniforms, aStageInOuts, theBits);
aSrcFragGetColor += (theBits & OpenGl_PO_MeshEdges) != 0
? THE_FRAG_WIREFRAME_COLOR
: EOL"#define getFinalColor getColor";
aSrcFrag =
aSrcFragGetColor
+ aSrcGetAlpha
@@ -1671,28 +1848,16 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramUnlit (Handle(OpenGl_Sha
EOL"{"
+ aSrcFragExtraMain
+ aSrcFragMainGetColor
+ aSrcFragWriteOit
+ EOL"}";
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core32 != NULL)
{
aProgramSrc->SetHeader ("#version 150");
}
#else
if (myContext->IsGlGreaterEqual (3, 1))
{
// prefer "100 es" on OpenGL ES 3.0 devices
// and "300 es" on newer devices (3.1+)
aProgramSrc->SetHeader ("#version 300 es");
}
#endif
defaultGlslVersion (aProgramSrc, theBits);
aProgramSrc->SetNbLightsMax (0);
aProgramSrc->SetNbClipPlanesMax (aNbClipPlanes);
aProgramSrc->SetAlphaTest ((theBits & OpenGl_PO_AlphaTest) != 0);
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcFrag, Graphic3d_TOS_FRAGMENT, aUniforms, aStageInOuts));
const Standard_Integer aNbGeomInputVerts = !aSrcGeom.IsEmpty() ? 3 : 0;
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts, "", "", aNbGeomInputVerts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcGeom, Graphic3d_TOS_GEOMETRY, aUniforms, aStageInOuts, "geomIn", "geomOut", aNbGeomInputVerts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcFrag, Graphic3d_TOS_FRAGMENT, aUniforms, aStageInOuts, "", "", aNbGeomInputVerts));
TCollection_AsciiString aKey;
if (!Create (aProgramSrc, aKey, theProgram))
{
@@ -1881,7 +2046,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramGouraud (Handle(OpenGl_S
{
Handle(Graphic3d_ShaderProgram) aProgramSrc = new Graphic3d_ShaderProgram();
TCollection_AsciiString aSrcVert, aSrcVertColor, aSrcVertExtraMain;
TCollection_AsciiString aSrcFrag, aSrcFragExtraMain, aSrcFragWriteOit;
TCollection_AsciiString aSrcFrag, aSrcFragExtraMain;
TCollection_AsciiString aSrcFragGetColor = EOL"vec4 getColor(void) { return gl_FrontFacing ? FrontColor : BackColor; }";
OpenGl_ShaderObject::ShaderVariableList aUniforms, aStageInOuts;
@@ -1934,7 +2099,14 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramGouraud (Handle(OpenGl_S
EOL" PositionWorld = aPositionWorld;"
EOL" Position = aPosition;";
if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
if ((theBits & OpenGl_PO_ClipPlanesN) == OpenGl_PO_ClipPlanesN)
{
aNbClipPlanes = Graphic3d_ShaderProgram::THE_MAX_CLIP_PLANES_DEFAULT;
aSrcFragExtraMain += (theBits & OpenGl_PO_ClipChains) != 0
? THE_FRAG_CLIP_CHAINS_N
: THE_FRAG_CLIP_PLANES_N;
}
else if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
{
aNbClipPlanes = 1;
aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_1;
@@ -1946,24 +2118,11 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramGouraud (Handle(OpenGl_S
? THE_FRAG_CLIP_CHAINS_2
: THE_FRAG_CLIP_PLANES_2;
}
else
{
aNbClipPlanes = Graphic3d_ShaderProgram::THE_MAX_CLIP_PLANES_DEFAULT;
aSrcFragExtraMain += (theBits & OpenGl_PO_ClipChains) != 0
? THE_FRAG_CLIP_CHAINS_N
: THE_FRAG_CLIP_PLANES_N;
}
}
if ((theBits & OpenGl_PO_WriteOit) != 0)
{
aProgramSrc->SetNbFragmentOutputs (2);
aProgramSrc->SetWeightOitOutput (true);
#if defined(GL_ES_VERSION_2_0)
if (myContext->IsGlGreaterEqual (3, 0))
{
aProgramSrc->SetHeader ("#version 300 es");
}
#endif
}
aStageInOuts.Append (OpenGl_ShaderObject::ShaderVariable ("vec4 FrontColor", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
@@ -1988,33 +2147,27 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramGouraud (Handle(OpenGl_S
+ EOL" gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;"
EOL"}";
TCollection_AsciiString aSrcGeom = prepareGeomMainSrc (aUniforms, aStageInOuts, theBits);
aSrcFragGetColor += (theBits & OpenGl_PO_MeshEdges) != 0
? THE_FRAG_WIREFRAME_COLOR
: EOL"#define getFinalColor getColor";
aSrcFrag = TCollection_AsciiString()
+ aSrcFragGetColor
+ EOL"void main()"
EOL"{"
+ aSrcFragExtraMain
+ EOL" occSetFragColor (getColor());"
+ aSrcFragWriteOit
+ EOL" occSetFragColor (getFinalColor());"
+ EOL"}";
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core32 != NULL)
{
aProgramSrc->SetHeader ("#version 150");
}
#else
if (myContext->IsGlGreaterEqual (3, 1))
{
// prefer "100 es" on OpenGL ES 3.0 devices
// and "300 es" on newer devices (3.1+)
aProgramSrc->SetHeader ("#version 300 es");
}
#endif
defaultGlslVersion (aProgramSrc, theBits);
aProgramSrc->SetNbLightsMax (aNbLights);
aProgramSrc->SetNbClipPlanesMax (aNbClipPlanes);
aProgramSrc->SetAlphaTest ((theBits & OpenGl_PO_AlphaTest) != 0);
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcFrag, Graphic3d_TOS_FRAGMENT, aUniforms, aStageInOuts));
const Standard_Integer aNbGeomInputVerts = !aSrcGeom.IsEmpty() ? 3 : 0;
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts, "", "", aNbGeomInputVerts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcGeom, Graphic3d_TOS_GEOMETRY, aUniforms, aStageInOuts, "geomIn", "geomOut", aNbGeomInputVerts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcFrag, Graphic3d_TOS_FRAGMENT, aUniforms, aStageInOuts, "", "", aNbGeomInputVerts));
TCollection_AsciiString aKey;
if (!Create (aProgramSrc, aKey, theProgram))
{
@@ -2052,10 +2205,9 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong (Handle(OpenGl_Sha
"Warning: applied workaround for flat shading normal computation using dFdx/dFdy on Adreno");
}
#endif
Handle(Graphic3d_ShaderProgram) aProgramSrc = new Graphic3d_ShaderProgram();
TCollection_AsciiString aSrcVert, aSrcVertExtraFunc, aSrcVertExtraMain;
TCollection_AsciiString aSrcFrag, aSrcFragExtraOut, aSrcFragGetVertColor, aSrcFragExtraMain, aSrcFragWriteOit;
TCollection_AsciiString aSrcFrag, aSrcFragExtraOut, aSrcFragGetVertColor, aSrcFragExtraMain;
TCollection_AsciiString aSrcFragGetColor = EOL"vec4 getColor(void) { return " thePhongCompLight "; }";
OpenGl_ShaderObject::ShaderVariableList aUniforms, aStageInOuts;
if ((theBits & OpenGl_PO_Point) != 0)
@@ -2103,7 +2255,14 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong (Handle(OpenGl_Sha
int aNbClipPlanes = 0;
if ((theBits & OpenGl_PO_ClipPlanesN) != 0)
{
if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
if ((theBits & OpenGl_PO_ClipPlanesN) == OpenGl_PO_ClipPlanesN)
{
aNbClipPlanes = Graphic3d_ShaderProgram::THE_MAX_CLIP_PLANES_DEFAULT;
aSrcFragExtraMain += (theBits & OpenGl_PO_ClipChains) != 0
? THE_FRAG_CLIP_CHAINS_N
: THE_FRAG_CLIP_PLANES_N;
}
else if ((theBits & OpenGl_PO_ClipPlanes1) != 0)
{
aNbClipPlanes = 1;
aSrcFragExtraMain += THE_FRAG_CLIP_PLANES_1;
@@ -2115,13 +2274,6 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong (Handle(OpenGl_Sha
? THE_FRAG_CLIP_CHAINS_2
: THE_FRAG_CLIP_PLANES_2;
}
else
{
aNbClipPlanes = Graphic3d_ShaderProgram::THE_MAX_CLIP_PLANES_DEFAULT;
aSrcFragExtraMain += (theBits & OpenGl_PO_ClipChains) != 0
? THE_FRAG_CLIP_CHAINS_N
: THE_FRAG_CLIP_PLANES_N;
}
}
if ((theBits & OpenGl_PO_WriteOit) != 0)
{
@@ -2158,6 +2310,11 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong (Handle(OpenGl_Sha
+ EOL" gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;"
EOL"}";
TCollection_AsciiString aSrcGeom = prepareGeomMainSrc (aUniforms, aStageInOuts, theBits);
aSrcFragGetColor += (theBits & OpenGl_PO_MeshEdges) != 0
? THE_FRAG_WIREFRAME_COLOR
: EOL"#define getFinalColor getColor";
Standard_Integer aNbLights = 0;
const TCollection_AsciiString aLights = stdComputeLighting (aNbLights, (theBits & OpenGl_PO_VertColor) != 0);
aSrcFrag = TCollection_AsciiString()
@@ -2170,39 +2327,17 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramPhong (Handle(OpenGl_Sha
EOL"void main()"
EOL"{"
+ aSrcFragExtraMain
+ EOL" occSetFragColor (getColor());"
+ aSrcFragWriteOit
+ EOL" occSetFragColor (getFinalColor());"
+ EOL"}";
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core32 != NULL)
{
aProgramSrc->SetHeader ("#version 150");
}
#else
if (myContext->IsGlGreaterEqual (3, 1))
{
// prefer "100 es" on OpenGL ES 3.0 devices
// and "300 es" on newer devices (3.1+)
aProgramSrc->SetHeader ("#version 300 es");
}
else if (isFlatNormal)
{
if (myContext->IsGlGreaterEqual (3, 0))
{
aProgramSrc->SetHeader ("#version 300 es");
}
else if (myContext->oesStdDerivatives)
{
aProgramSrc->SetHeader ("#extension GL_OES_standard_derivatives : enable");
}
}
#endif
defaultGlslVersion (aProgramSrc, theBits, isFlatNormal);
aProgramSrc->SetNbLightsMax (aNbLights);
aProgramSrc->SetNbClipPlanesMax (aNbClipPlanes);
aProgramSrc->SetAlphaTest ((theBits & OpenGl_PO_AlphaTest) != 0);
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcFrag, Graphic3d_TOS_FRAGMENT, aUniforms, aStageInOuts));
const Standard_Integer aNbGeomInputVerts = !aSrcGeom.IsEmpty() ? 3 : 0;
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts, "", "", aNbGeomInputVerts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcGeom, Graphic3d_TOS_GEOMETRY, aUniforms, aStageInOuts, "geomIn", "geomOut", aNbGeomInputVerts));
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcFrag, Graphic3d_TOS_FRAGMENT, aUniforms, aStageInOuts, "", "", aNbGeomInputVerts));
TCollection_AsciiString aKey;
if (!Create (aProgramSrc, aKey, theProgram))
{
@@ -2379,20 +2514,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramStereo (Handle(OpenGl_Sh
}
}
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core32 != NULL)
{
aProgramSrc->SetHeader ("#version 150");
}
#else
if (myContext->IsGlGreaterEqual (3, 1))
{
// prefer "100 es" on OpenGL ES 3.0 devices
// and "300 es" on newer devices (3.1+)
aProgramSrc->SetHeader ("#version 300 es");
}
#endif
defaultGlslVersion (aProgramSrc, 0);
aProgramSrc->SetNbLightsMax (0);
aProgramSrc->SetNbClipPlanesMax (0);
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts));
@@ -2437,20 +2559,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramBoundBox()
EOL" occSetFragColor (occColor);"
EOL"}";
#if !defined(GL_ES_VERSION_2_0)
if (myContext->core32 != NULL)
{
aProgramSrc->SetHeader ("#version 150");
}
#else
if (myContext->IsGlGreaterEqual (3, 1))
{
// prefer "100 es" on OpenGL ES 3.0 devices
// and "300 es" on newer devices (3.1+)
aProgramSrc->SetHeader ("#version 300 es");
}
#endif
defaultGlslVersion (aProgramSrc, 0);
aProgramSrc->SetNbLightsMax (0);
aProgramSrc->SetNbClipPlanesMax (0);
aProgramSrc->AttachShader (OpenGl_ShaderObject::CreateFromSource (aSrcVert, Graphic3d_TOS_VERTEX, aUniforms, aStageInOuts));

View File

@@ -84,10 +84,23 @@ public:
//! Bind program for filled primitives rendering
Standard_Boolean BindFaceProgram (const Handle(OpenGl_TextureSet)& theTextures,
const Graphic3d_TypeOfShadingModel theShadingModel,
const Graphic3d_AlphaMode theAlphaMode,
const Standard_Boolean theHasVertColor,
const Standard_Boolean theEnableEnvMap,
Graphic3d_TypeOfShadingModel theShadingModel,
Graphic3d_AlphaMode theAlphaMode,
Standard_Boolean theHasVertColor,
Standard_Boolean theEnableEnvMap,
const Handle(OpenGl_ShaderProgram)& theCustomProgram)
{
return BindFaceProgram (theTextures, theShadingModel, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, theEnableEnvMap, false, theCustomProgram);
}
//! Bind program for filled primitives rendering
Standard_Boolean BindFaceProgram (const Handle(OpenGl_TextureSet)& theTextures,
Graphic3d_TypeOfShadingModel theShadingModel,
Graphic3d_AlphaMode theAlphaMode,
Aspect_InteriorStyle theInteriorStyle,
Standard_Boolean theHasVertColor,
Standard_Boolean theEnableEnvMap,
Standard_Boolean theEnableMeshEdges,
const Handle(OpenGl_ShaderProgram)& theCustomProgram)
{
if (!theCustomProgram.IsNull()
@@ -100,7 +113,7 @@ public:
&& (theTextures.IsNull() || theTextures->IsModulate())
? theShadingModel
: Graphic3d_TOSM_UNLIT;
const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, theHasVertColor, theEnableEnvMap);
const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, theInteriorStyle, theHasVertColor, theEnableEnvMap, theEnableMeshEdges);
Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (aShadeModelOnFace, aBits);
return bindProgramWithState (aProgram);
}
@@ -119,7 +132,7 @@ public:
return bindProgramWithState (theCustomProgram);
}
Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, theHasVertColor, false);
Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, false, false);
if (theLineType != Aspect_TOL_SOLID)
{
aBits |= OpenGl_PO_StippleLine;
@@ -142,7 +155,7 @@ public:
return bindProgramWithState (theCustomProgram);
}
const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, theHasVertColor, false) | OpenGl_PO_Point;
const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, false, false) | OpenGl_PO_Point;
Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (theShadingModel, aBits);
return bindProgramWithState (aProgram);
}
@@ -301,6 +314,12 @@ public:
//! Pushes current state of material to specified program.
void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
public:
//! Setup interior style line edges variables.
Standard_EXPORT void PushInteriorState (const Handle(OpenGl_ShaderProgram)& theProgram,
const Handle(Graphic3d_AspectFillArea3d)& theAspect) const;
public:
//! Returns state of OIT uniforms.
@@ -411,12 +430,43 @@ public:
protected:
//! Define clipping planes program bits.
Standard_Integer getClipPlaneBits() const
{
const Standard_Integer aNbPlanes = myContext->Clipping().NbClippingOrCappingOn();
if (aNbPlanes <= 0)
{
return 0;
}
Standard_Integer aBits = 0;
if (myContext->Clipping().HasClippingChains())
{
aBits |= OpenGl_PO_ClipChains;
}
if (aNbPlanes == 1)
{
aBits |= OpenGl_PO_ClipPlanes1;
}
else if (aNbPlanes == 2)
{
aBits |= OpenGl_PO_ClipPlanes2;
}
else
{
aBits |= OpenGl_PO_ClipPlanesN;
}
return aBits;
}
//! Define program bits.
Standard_Integer getProgramBits (const Handle(OpenGl_TextureSet)& theTextures,
Graphic3d_AlphaMode theAlphaMode,
Aspect_InteriorStyle theInteriorStyle,
Standard_Boolean theHasVertColor,
Standard_Boolean theEnableEnvMap)
Standard_Boolean theEnableEnvMap,
Standard_Boolean theEnableMeshEdges) const
{
Standard_Integer aBits = 0;
if (theAlphaMode == Graphic3d_AlphaMode_Mask)
@@ -424,22 +474,14 @@ protected:
aBits |= OpenGl_PO_AlphaTest;
}
const Standard_Integer aNbPlanes = myContext->Clipping().NbClippingOrCappingOn();
if (aNbPlanes > 0)
aBits |= getClipPlaneBits();
if (theEnableMeshEdges
&& myContext->hasGeometryStage != OpenGl_FeatureNotAvailable)
{
aBits |= OpenGl_PO_ClipPlanesN;
if (myContext->Clipping().HasClippingChains())
aBits |= OpenGl_PO_MeshEdges;
if (theInteriorStyle == Aspect_IS_HOLLOW)
{
aBits |= OpenGl_PO_ClipChains;
}
if (aNbPlanes == 1)
{
aBits |= OpenGl_PO_ClipPlanes1;
}
else if (aNbPlanes == 2)
{
aBits |= OpenGl_PO_ClipPlanes2;
aBits |= OpenGl_PO_AlphaTest;
}
}
@@ -454,7 +496,8 @@ protected:
{
aBits |= theTextures->First()->IsAlpha() ? OpenGl_PO_TextureA : OpenGl_PO_TextureRGB;
}
if (theHasVertColor)
if (theHasVertColor
&& theInteriorStyle != Aspect_IS_HIDDENLINE)
{
aBits |= OpenGl_PO_VertColor;
}
@@ -555,6 +598,16 @@ protected:
//! Prepare standard GLSL program for bounding box.
Standard_EXPORT Standard_Boolean prepareStdProgramBoundBox();
//! Prepare GLSL version header.
Standard_EXPORT Standard_Integer defaultGlslVersion (const Handle(Graphic3d_ShaderProgram)& theProgram,
Standard_Integer theBits,
bool theUsesDerivates = false) const;
//! Prepare GLSL source for geometry shader according to parameters.
Standard_EXPORT TCollection_AsciiString prepareGeomMainSrc (OpenGl_ShaderObject::ShaderVariableList& theUnifoms,
OpenGl_ShaderObject::ShaderVariableList& theStageInOuts,
Standard_Integer theBits);
protected:
//! Packed properties of light source

View File

@@ -14,11 +14,13 @@
// commercial license or contractual agreement.
#include <Graphic3d_ShaderObject.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_ShaderObject.hxx>
#include <OSD_Path.hxx>
#include <Standard_Assert.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#ifdef _WIN32
#include <malloc.h> // for alloca()
@@ -26,6 +28,24 @@
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_ShaderObject,OpenGl_Resource)
//! Puts line numbers to the output of GLSL program source code.
static TCollection_AsciiString putLineNumbers (const TCollection_AsciiString& theSource)
{
std::stringstream aStream;
theSource.Print (aStream);
std::string aLine;
Standard_Integer aLineNumber = 1;
TCollection_AsciiString aResultSource;
while (std::getline (aStream, aLine))
{
TCollection_AsciiString anAsciiString = TCollection_AsciiString (aLine.c_str());
anAsciiString.Prepend (TCollection_AsciiString ("\n") + TCollection_AsciiString (aLineNumber) + ": ");
aResultSource += anAsciiString;
aLineNumber++;
}
return aResultSource;
}
// =======================================================================
// function : CreateFromSource
// purpose :
@@ -38,6 +58,11 @@ Handle(Graphic3d_ShaderObject) OpenGl_ShaderObject::CreateFromSource (TCollectio
const TCollection_AsciiString& theOutName,
Standard_Integer theNbGeomInputVerts)
{
if (theSource.IsEmpty())
{
return Handle(Graphic3d_ShaderObject)();
}
TCollection_AsciiString aSrcUniforms, aSrcInOuts, aSrcInStructs, aSrcOutStructs;
for (ShaderVariableList::Iterator anUniformIter (theUniforms); anUniformIter.More(); anUniformIter.Next())
{
@@ -70,12 +95,15 @@ Handle(Graphic3d_ShaderObject) OpenGl_ShaderObject::CreateFromSource (TCollectio
const Standard_Boolean hasGeomStage = theNbGeomInputVerts > 0
&& aStageLower < Graphic3d_TOS_GEOMETRY
&& aStageUpper >= Graphic3d_TOS_GEOMETRY;
const Standard_Boolean isAllStagesVar = aStageLower == Graphic3d_TOS_VERTEX
&& aStageUpper == Graphic3d_TOS_FRAGMENT;
if (hasGeomStage
|| !theInName.IsEmpty()
|| !theOutName.IsEmpty())
{
if (aSrcInStructs.IsEmpty()
&& aSrcOutStructs.IsEmpty())
&& aSrcOutStructs.IsEmpty()
&& isAllStagesVar)
{
if (theType == aStageLower)
{
@@ -93,8 +121,9 @@ Handle(Graphic3d_ShaderObject) OpenGl_ShaderObject::CreateFromSource (TCollectio
}
}
if (!aSrcInStructs.IsEmpty()
|| !aSrcOutStructs.IsEmpty())
if (isAllStagesVar
&& (!aSrcInStructs.IsEmpty()
|| !aSrcOutStructs.IsEmpty()))
{
if (!aSrcInStructs.IsEmpty())
{
@@ -118,6 +147,12 @@ Handle(Graphic3d_ShaderObject) OpenGl_ShaderObject::CreateFromSource (TCollectio
}
}
if (theType == Graphic3d_TOS_GEOMETRY)
{
aSrcUniforms.Prepend (TCollection_AsciiString()
+ "\nlayout (triangles) in;"
"\nlayout (triangle_strip, max_vertices = " + theNbGeomInputVerts + ") out;");
}
if (!aSrcInStructs.IsEmpty()
&& theType == Graphic3d_TOS_GEOMETRY)
{
@@ -133,10 +168,10 @@ Handle(Graphic3d_ShaderObject) OpenGl_ShaderObject::CreateFromSource (TCollectio
}
aSrcInStructs += ";";
}
else if (!aSrcOutStructs.IsEmpty())
if (!aSrcOutStructs.IsEmpty())
{
aSrcOutStructs += "\n}";
if (!theInName.IsEmpty())
if (!theOutName.IsEmpty())
{
aSrcOutStructs += " ";
aSrcOutStructs += theOutName;
@@ -168,6 +203,63 @@ OpenGl_ShaderObject::~OpenGl_ShaderObject()
Release (NULL);
}
// =======================================================================
// function : LoadAndCompile
// purpose :
// =======================================================================
Standard_Boolean OpenGl_ShaderObject::LoadAndCompile (const Handle(OpenGl_Context)& theCtx,
const TCollection_AsciiString& theSource,
bool theIsVerbose,
bool theToPrintSource)
{
if (!theIsVerbose)
{
return LoadSource (theCtx, theSource)
&& Compile (theCtx);
}
if (!LoadSource (theCtx, theSource))
{
if (theToPrintSource)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, theSource);
}
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, "Error! Failed to set shader source");
Release (theCtx.operator->());
return false;
}
if (!Compile (theCtx))
{
if (theToPrintSource)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, putLineNumbers (theSource));
}
TCollection_AsciiString aLog;
FetchInfoLog (theCtx, aLog);
if (aLog.IsEmpty())
{
aLog = "Compilation log is empty.";
}
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Failed to compile shader object. Compilation log:\n") + aLog);
Release (theCtx.operator->());
return false;
}
else if (theCtx->caps->glslWarnings)
{
TCollection_AsciiString aLog;
FetchInfoLog (theCtx, aLog);
if (!aLog.IsEmpty()
&& !aLog.IsEqual ("No errors.\n"))
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_LOW,
TCollection_AsciiString ("Shader compilation log:\n") + aLog);
}
}
return true;
}
// =======================================================================
// function : LoadSource
// purpose : Loads shader source code

View File

@@ -85,6 +85,16 @@ public:
//! Compiles the shader object.
Standard_EXPORT Standard_Boolean Compile (const Handle(OpenGl_Context)& theCtx);
//! Wrapper for compiling shader object with verbose printing on error.
//! @param theCtx bound OpenGL context
//! @param theSource source code to load
//! @param theIsVerbose flag to print log on error
//! @param theToPrintSource flag to print source code on error
Standard_EXPORT Standard_Boolean LoadAndCompile (const Handle(OpenGl_Context)& theCtx,
const TCollection_AsciiString& theSource,
bool theIsVerbose = true,
bool theToPrintSource = true);
//! Fetches information log of the last compile operation.
Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
TCollection_AsciiString& theLog);

View File

@@ -75,7 +75,13 @@ Standard_CString OpenGl_ShaderProgram::PredefinedKeywords[] =
"occOitDepthFactor", // OpenGl_OCCT_OIT_DEPTH_FACTOR
"occTexTrsf2d", // OpenGl_OCCT_TEXTURE_TRSF2D
"occPointSize" // OpenGl_OCCT_POINT_SIZE
"occPointSize", // OpenGl_OCCT_POINT_SIZE
"occViewport", // OpenGl_OCCT_VIEWPORT
"occLineWidth", // OpenGl_OCCT_LINE_WIDTH
"occLineFeather", // OpenGl_OCCT_LINE_FEATHER
"occWireframeColor", // OpenGl_OCCT_WIREFRAME_COLOR
"occIsQuadMode", // OpenGl_OCCT_QUAD_MODE_STATE
};
namespace
@@ -159,28 +165,6 @@ OpenGl_ShaderProgram::OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram
myHasTessShader (false)
{
memset (myCurrentState, 0, sizeof (myCurrentState));
for (GLint aVar = 0; aVar < OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES; ++aVar)
{
myStateLocations[aVar] = INVALID_LOCATION;
}
}
//! Puts line numbers to the output of GLSL program source code.
static TCollection_AsciiString putLineNumbers (const TCollection_AsciiString& theSource)
{
std::stringstream aStream;
theSource.Print (aStream);
std::string aLine;
Standard_Integer aLineNumber = 1;
TCollection_AsciiString aResultSource;
while (std::getline (aStream, aLine))
{
TCollection_AsciiString anAsciiString = TCollection_AsciiString (aLine.c_str());
anAsciiString.Prepend (TCollection_AsciiString ("\n") + TCollection_AsciiString (aLineNumber) + ": ");
aResultSource += anAsciiString;
aLineNumber++;
}
return aResultSource;
}
// =======================================================================
@@ -209,13 +193,12 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)&
// detect the minimum GLSL version required for defined Shader Objects
#if defined(GL_ES_VERSION_2_0)
if (myHasTessShader
|| (aShaderMask & Graphic3d_TOS_GEOMETRY) != 0)
if (myHasTessShader)
{
if (!theCtx->IsGlGreaterEqual (3, 2))
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
"Error! Geometry and Tessellation shaders require OpenGL ES 3.2+");
"Error! Tessellation shader requires OpenGL ES 3.2+");
return false;
}
else if (aHeaderVer.IsEmpty())
@@ -223,6 +206,34 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)&
aHeaderVer = "#version 320 es";
}
}
else if ((aShaderMask & Graphic3d_TOS_GEOMETRY) != 0)
{
switch (theCtx->hasGeometryStage)
{
case OpenGl_FeatureNotAvailable:
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
"Error! Geometry shader requires OpenGL ES 3.2+ or GL_EXT_geometry_shader");
return false;
}
case OpenGl_FeatureInExtensions:
{
if (aHeaderVer.IsEmpty())
{
aHeaderVer = "#version 310 es";
}
break;
}
case OpenGl_FeatureInCore:
{
if (aHeaderVer.IsEmpty())
{
aHeaderVer = "#version 320 es";
}
break;
}
}
}
else if ((aShaderMask & Graphic3d_TOS_COMPUTE) != 0)
{
if (!theCtx->IsGlGreaterEqual (3, 1))
@@ -349,6 +360,13 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)&
}
#endif
}
#if defined(GL_ES_VERSION_2_0)
if (theCtx->hasGeometryStage == OpenGl_FeatureInExtensions)
{
anExtensions += "#extension GL_EXT_geometry_shader : enable\n"
"#extension GL_EXT_shader_io_blocks : enable\n";
}
#endif
TCollection_AsciiString aPrecisionHeader;
if (anIter.Value()->Type() == Graphic3d_TOS_FRAGMENT)
@@ -389,40 +407,11 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)&
+ Shaders_Declarations_glsl // common declarations (global constants and Vertex Shader inputs)
+ Shaders_DeclarationsImpl_glsl
+ anIter.Value()->Source(); // the source code itself (defining main() function)
if (!aShader->LoadSource (theCtx, aSource))
if (!aShader->LoadAndCompile (theCtx, aSource))
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aSource);
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, "Error! Failed to set shader source");
aShader->Release (theCtx.operator->());
return Standard_False;
}
if (!aShader->Compile (theCtx))
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, putLineNumbers (aSource));
TCollection_AsciiString aLog;
aShader->FetchInfoLog (theCtx, aLog);
if (aLog.IsEmpty())
{
aLog = "Compilation log is empty.";
}
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_ExtendedString ("Failed to compile shader object. Compilation log:\n") + aLog);
aShader->Release (theCtx.operator->());
return Standard_False;
}
else if (theCtx->caps->glslWarnings)
{
TCollection_AsciiString aLog;
aShader->FetchInfoLog (theCtx, aLog);
if (!aLog.IsEmpty()
&& !aLog.IsEqual ("No errors.\n"))
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_LOW,
TCollection_ExtendedString ("Shader compilation log:\n") + aLog);
}
}
if (theCtx->caps->glslDumpLevel)
{
TCollection_AsciiString aShaderTypeMsg;
@@ -475,44 +464,19 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)&
if (!Link (theCtx))
{
TCollection_AsciiString aLog;
FetchInfoLog (theCtx, aLog);
if (aLog.IsEmpty())
{
aLog = "Linker log is empty.";
}
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_ExtendedString ("Failed to link program object! Linker log:\n") + aLog);
return Standard_False;
}
else if (theCtx->caps->glslWarnings)
{
TCollection_AsciiString aLog;
FetchInfoLog (theCtx, aLog);
if (!aLog.IsEmpty()
&& !aLog.IsEqual ("No errors.\n"))
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_LOW,
TCollection_ExtendedString ("GLSL linker log:\n") + aLog);
}
}
// set uniform defaults
const Handle(OpenGl_ShaderProgram)& anOldProgram = theCtx->ActiveProgram();
theCtx->core20fwd->glUseProgram (myProgramID);
if (const OpenGl_ShaderUniformLocation aLocTexEnable = GetStateLocation (OpenGl_OCCT_TEXTURE_ENABLE))
{
const GLint aLocTexEnable = GetStateLocation (OpenGl_OCCT_TEXTURE_ENABLE);
if (aLocTexEnable != INVALID_LOCATION)
{
SetUniform (theCtx, aLocTexEnable, 0); // Off
}
SetUniform (theCtx, aLocTexEnable, 0); // Off
}
if (const OpenGl_ShaderUniformLocation aLocSampler = GetUniformLocation (theCtx, "occActiveSampler"))
{
const GLint aLocSampler = GetUniformLocation (theCtx, "occActiveSampler");
if (aLocSampler != INVALID_LOCATION)
{
SetUniform (theCtx, aLocSampler, GLint(Graphic3d_TextureUnit_0));
}
SetUniform (theCtx, aLocSampler, GLint(Graphic3d_TextureUnit_0));
}
const TCollection_AsciiString aSamplerNamePrefix ("occSampler");
@@ -520,8 +484,7 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)&
for (GLint aUnitIter = 0; aUnitIter < aNbUnitsMax; ++aUnitIter)
{
const TCollection_AsciiString aName = aSamplerNamePrefix + aUnitIter;
const GLint aLocSampler = GetUniformLocation (theCtx, aName.ToCString());
if (aLocSampler != INVALID_LOCATION)
if (const OpenGl_ShaderUniformLocation aLocSampler = GetUniformLocation (theCtx, aName.ToCString()))
{
SetUniform (theCtx, aLocSampler, aUnitIter);
}
@@ -603,7 +566,7 @@ Standard_Boolean OpenGl_ShaderProgram::DetachShader (const Handle(OpenGl_Context
// function : Link
// purpose : Links the program object
// =======================================================================
Standard_Boolean OpenGl_ShaderProgram::Link (const Handle(OpenGl_Context)& theCtx)
Standard_Boolean OpenGl_ShaderProgram::link (const Handle(OpenGl_Context)& theCtx)
{
if (myProgramID == NO_PROGRAM)
{
@@ -625,6 +588,44 @@ Standard_Boolean OpenGl_ShaderProgram::Link (const Handle(OpenGl_Context)& theCt
return Standard_True;
}
// =======================================================================
// function : Link
// purpose :
// =======================================================================
Standard_Boolean OpenGl_ShaderProgram::Link (const Handle(OpenGl_Context)& theCtx,
bool theIsVerbose)
{
if (!theIsVerbose)
{
return link (theCtx);
}
if (!link (theCtx))
{
TCollection_AsciiString aLog;
FetchInfoLog (theCtx, aLog);
if (aLog.IsEmpty())
{
aLog = "Linker log is empty.";
}
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
TCollection_AsciiString ("Failed to link program object! Linker log:\n") + aLog);
return false;
}
else if (theCtx->caps->glslWarnings)
{
TCollection_AsciiString aLog;
FetchInfoLog (theCtx, aLog);
if (!aLog.IsEmpty()
&& !aLog.IsEqual ("No errors.\n"))
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_LOW,
TCollection_AsciiString ("GLSL linker log:\n") + aLog);
}
}
return true;
}
// =======================================================================
// function : FetchInfoLog
// purpose : Fetches information log of the last link operation
@@ -673,12 +674,12 @@ Standard_Boolean OpenGl_ShaderProgram::ApplyVariables(const Handle(OpenGl_Contex
// function : GetUniformLocation
// purpose : Returns location (index) of the specific uniform variable
// =======================================================================
GLint OpenGl_ShaderProgram::GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
const GLchar* theName) const
OpenGl_ShaderUniformLocation OpenGl_ShaderProgram::GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
const GLchar* theName) const
{
return myProgramID != NO_PROGRAM
? theCtx->core20fwd->glGetUniformLocation (myProgramID, theName)
: INVALID_LOCATION;
return OpenGl_ShaderUniformLocation (myProgramID != NO_PROGRAM
? theCtx->core20fwd->glGetUniformLocation (myProgramID, theName)
: INVALID_LOCATION);
}
// =======================================================================
@@ -693,19 +694,6 @@ GLint OpenGl_ShaderProgram::GetAttributeLocation (const Handle(OpenGl_Context)&
: INVALID_LOCATION;
}
// =======================================================================
// function : GetStateLocation
// purpose : Returns location of the OCCT state uniform variable
// =======================================================================
GLint OpenGl_ShaderProgram::GetStateLocation (const GLuint theVariable) const
{
if (theVariable < OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES)
{
return myStateLocations[theVariable];
}
return INVALID_LOCATION;
}
// =======================================================================
// function : GetUniform
// purpose : Returns the value of the integer uniform variable

View File

@@ -75,6 +75,13 @@ enum OpenGl_StateVariable
OpenGl_OCCT_TEXTURE_TRSF2D,
OpenGl_OCCT_POINT_SIZE,
// Wireframe state
OpenGl_OCCT_VIEWPORT,
OpenGl_OCCT_LINE_WIDTH,
OpenGl_OCCT_LINE_FEATHER,
OpenGl_OCCT_WIREFRAME_COLOR,
OpenGl_OCCT_QUAD_MODE_STATE,
// DON'T MODIFY THIS ITEM (insert new items before it)
OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES
};
@@ -133,6 +140,34 @@ enum OpenGl_UniformStateType
OpenGl_UniformStateType_NB
};
//! Simple class represents GLSL program variable location.
class OpenGl_ShaderUniformLocation
{
public:
//! Invalid location of uniform/attribute variable.
static const GLint INVALID_LOCATION = -1;
public:
//! Construct an invalid location.
OpenGl_ShaderUniformLocation() : myLocation (INVALID_LOCATION) {}
//! Constructor with initialization.
explicit OpenGl_ShaderUniformLocation (GLint theLocation) : myLocation (theLocation) {}
//! Note you may safely put invalid location in functions like glUniform* - the data passed in will be silently ignored.
//! @return true if location is not equal to -1.
bool IsValid() const { return myLocation != INVALID_LOCATION; }
//! Return TRUE for non-invalid location.
operator bool() const { return myLocation != INVALID_LOCATION; }
//! Convert operators help silently put object to GL functions like glUniform*.
operator GLint() const { return myLocation; }
private:
GLint myLocation;
};
//! Wrapper for OpenGL program object.
class OpenGl_ShaderProgram : public OpenGl_NamedResource
{
@@ -150,6 +185,12 @@ public:
//! List of pre-defined OCCT state uniform variables.
static Standard_CString PredefinedKeywords[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
//! Wrapper for compiling shader object with verbose printing on error.
Standard_EXPORT static bool compileShaderVerbose (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_ShaderObject)& theShader,
const TCollection_AsciiString& theSource,
bool theToPrintSource = true);
//! Creates uninitialized shader program.
//!
//! WARNING! This constructor is not intended to be called anywhere but from OpenGl_ShaderManager::Create().
@@ -194,7 +235,10 @@ public:
const Graphic3d_ShaderObjectList& theShaders);
//! Links the program object.
Standard_EXPORT Standard_Boolean Link (const Handle(OpenGl_Context)& theCtx);
//! @param theCtx bound OpenGL context
//! @param theIsVerbose flag to print log on error
Standard_EXPORT Standard_Boolean Link (const Handle(OpenGl_Context)& theCtx,
bool theIsVerbose = true);
//! Fetches information log of the last link operation.
Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
@@ -261,15 +305,15 @@ private:
public:
//! Returns location of the specific uniform variable.
Standard_EXPORT GLint GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
const GLchar* theName) const;
Standard_EXPORT OpenGl_ShaderUniformLocation GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
const GLchar* theName) const;
//! Returns index of the generic vertex attribute by variable name.
Standard_EXPORT GLint GetAttributeLocation (const Handle(OpenGl_Context)& theCtx,
const GLchar* theName) const;
//! Returns location of the OCCT state uniform variable.
Standard_EXPORT GLint GetStateLocation (const GLuint theVariable) const;
const OpenGl_ShaderUniformLocation& GetStateLocation (OpenGl_StateVariable theVariable) const { return myStateLocations[theVariable]; }
public:
@@ -573,6 +617,9 @@ protected:
return --myShareCount == 0;
}
//! Links the program object.
Standard_EXPORT Standard_Boolean link (const Handle(OpenGl_Context)& theCtx);
protected:
GLuint myProgramID; //!< Handle of OpenGL shader program
@@ -591,7 +638,7 @@ protected:
Standard_Size myCurrentState[OpenGl_UniformStateType_NB]; //!< defines last modification for variables of each state type
//! Stores locations of OCCT state uniform variables.
GLint myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
OpenGl_ShaderUniformLocation myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
};

View File

@@ -16,8 +16,6 @@
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_StencilTest.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_StencilTest, OpenGl_Element)
OpenGl_StencilTest::OpenGl_StencilTest()
{
//

View File

@@ -20,7 +20,6 @@
class OpenGl_StencilTest : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_StencilTest, OpenGl_Element)
public:
//! Default constructor

View File

@@ -460,10 +460,10 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con
aCtx->ApplyModelViewMatrix();
// remember aspects
const Handle(OpenGl_AspectLine)& aPrevAspectLine = theWorkspace->AspectLine();
const Handle(OpenGl_AspectFace)& aPrevAspectFace = theWorkspace->AspectFace();
const Handle(OpenGl_AspectMarker)& aPrevAspectMarker = theWorkspace->AspectMarker();
const Handle(OpenGl_AspectText)& aPrevAspectText = theWorkspace->AspectText();
const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->AspectLine();
const OpenGl_AspectFace* aPrevAspectFace = theWorkspace->AspectFace();
const OpenGl_AspectMarker* aPrevAspectMarker = theWorkspace->AspectMarker();
const OpenGl_AspectText* aPrevAspectText = theWorkspace->AspectText();
// Apply correction for mirror transform
if (myIsMirrored)

View File

@@ -29,8 +29,6 @@
#include <Graphic3d_TransformUtils.hxx>
#include <TCollection_HAsciiString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Text, OpenGl_Element)
namespace
{
static const GLdouble THE_IDENTITY_MATRIX[16] =
@@ -289,7 +287,7 @@ void OpenGl_Text::Release (OpenGl_Context* theCtx)
// =======================================================================
void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx,
const NCollection_String& theText,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const OpenGl_TextParam& theParams,
const unsigned int theResolution,
Standard_ShortReal& theWidth,
@@ -355,10 +353,10 @@ void OpenGl_Text::StringSize (const Handle(OpenGl_Context)& theCtx,
// =======================================================================
void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
{
theWorkspace->SetAspectFace (theWorkspace->FontFaceAspect());
theWorkspace->SetAspectFace (&theWorkspace->FontFaceAspect());
theWorkspace->ApplyAspectFace();
const Handle(OpenGl_AspectText)& aTextAspect = theWorkspace->ApplyAspectText();
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
const OpenGl_AspectText* aTextAspect = theWorkspace->ApplyAspectText();
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
const Handle(OpenGl_TextureSet) aPrevTexture = aCtx->BindTextures (Handle(OpenGl_TextureSet)());
// Bind custom shader program or generate default version
@@ -369,7 +367,7 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
// use highlight color or colors from aspect
render (aCtx,
aTextAspect,
*aTextAspect,
theWorkspace->TextColor(),
theWorkspace->TextSubtitleColor(),
aCtx->Resolution());
@@ -392,13 +390,25 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
// purpose :
// =======================================================================
void OpenGl_Text::Render (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const unsigned int theResolution) const
{
const bool anAlphaToCoverageOld = theCtx->SetSampleAlphaToCoverage (false);
#if !defined(GL_ES_VERSION_2_0)
const Standard_Integer aPrevPolygonMode = theCtx->SetPolygonMode (GL_FILL);
const bool aPrevHatchingMode = theCtx->SetPolygonHatchEnabled (false);
#endif
render (theCtx, theTextAspect,
theTextAspect->Aspect()->ColorRGBA(),
theTextAspect->Aspect()->ColorSubTitleRGBA(),
theTextAspect.Aspect()->ColorRGBA(),
theTextAspect.Aspect()->ColorSubTitleRGBA(),
theResolution);
#if !defined(GL_ES_VERSION_2_0)
theCtx->SetPolygonMode (aPrevPolygonMode);
theCtx->SetPolygonHatchEnabled (aPrevHatchingMode);
#endif
theCtx->SetSampleAlphaToCoverage (anAlphaToCoverageOld);
}
// =======================================================================
@@ -406,7 +416,7 @@ void OpenGl_Text::Render (const Handle(OpenGl_Context)& theCtx,
// purpose :
// =======================================================================
void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec3 theDVec) const
{
OpenGl_Mat4d aModViewMat;
@@ -424,7 +434,7 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
{
Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.f);
Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, 1.f, -1.f, 1.f);
Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect->Aspect()->GetTextAngle(), 0.f, 0.f, 1.f);
Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Aspect()->GetTextAngle(), 0.f, 0.f, 1.f);
}
else
{
@@ -466,10 +476,10 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
else
{
Graphic3d_TransformUtils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect->Aspect()->GetTextAngle(), 0.0, 0.0, 1.0);
Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Aspect()->GetTextAngle(), 0.0, 0.0, 1.0);
}
if (!theTextAspect->Aspect()->GetTextZoomable())
if (!theTextAspect.Aspect()->GetTextZoomable())
{
Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight);
}
@@ -506,7 +516,7 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
// purpose :
// =======================================================================
void OpenGl_Text::drawText (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect) const
const OpenGl_AspectText& theTextAspect) const
{
(void )theTextAspect;
if (myVertsVbo.Length() != myTextures.Length()
@@ -537,14 +547,14 @@ void OpenGl_Text::drawText (const Handle(OpenGl_Context)& theCtx,
// function : FontKey
// purpose :
// =======================================================================
TCollection_AsciiString OpenGl_Text::FontKey (const Handle(OpenGl_AspectText)& theAspect,
TCollection_AsciiString OpenGl_Text::FontKey (const OpenGl_AspectText& theAspect,
const Standard_Integer theHeight,
const unsigned int theResolution)
{
const Font_FontAspect anAspect = theAspect->Aspect()->GetTextFontAspect() != Font_FA_Undefined
? theAspect->Aspect()->GetTextFontAspect()
const Font_FontAspect anAspect = theAspect.Aspect()->GetTextFontAspect() != Font_FA_Undefined
? theAspect.Aspect()->GetTextFontAspect()
: Font_FA_Regular;
return theAspect->Aspect()->Font()
return theAspect.Aspect()->Font()
+ TCollection_AsciiString(":") + Standard_Integer(anAspect)
+ TCollection_AsciiString(":") + Standard_Integer(theResolution)
+ TCollection_AsciiString(":") + theHeight;
@@ -555,7 +565,7 @@ TCollection_AsciiString OpenGl_Text::FontKey (const Handle(OpenGl_AspectText)& t
// purpose :
// =======================================================================
Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theAspect,
const OpenGl_AspectText& theAspect,
const Standard_Integer theHeight,
const unsigned int theResolution,
const TCollection_AsciiString theKey)
@@ -569,9 +579,9 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
if (!theCtx->GetResource (theKey, aFont))
{
Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
const TCollection_AsciiString& aFontName = theAspect->Aspect()->Font();
Font_FontAspect anAspect = theAspect->Aspect()->GetTextFontAspect() != Font_FA_Undefined
? theAspect->Aspect()->GetTextFontAspect()
const TCollection_AsciiString& aFontName = theAspect.Aspect()->Font();
Font_FontAspect anAspect = theAspect.Aspect()->GetTextFontAspect() != Font_FA_Undefined
? theAspect.Aspect()->GetTextFontAspect()
: Font_FA_Regular;
Handle(Font_FTFont) aFontFt;
if (Handle(Font_SystemFont) aRequestedFont = aFontMgr->FindFont (aFontName, anAspect))
@@ -585,7 +595,7 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
{
TCollection_ExtendedString aMsg;
aMsg += "Font '";
aMsg += theAspect->Aspect()->Font();
aMsg += theAspect.Aspect()->Font();
aMsg += "' - initialization of GL resources has failed!";
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
aFontFt.Nullify();
@@ -597,7 +607,7 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
{
TCollection_ExtendedString aMsg;
aMsg += "Font '";
aMsg += theAspect->Aspect()->Font();
aMsg += theAspect.Aspect()->Font();
aMsg += "' is broken or has incompatible format! File path: ";
aMsg += aRequestedFont->FontPathAny (anAspect);
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
@@ -609,7 +619,7 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
{
TCollection_ExtendedString aMsg;
aMsg += "Font '";
aMsg += theAspect->Aspect()->Font();
aMsg += theAspect.Aspect()->Font();
aMsg += "' is not found in the system!";
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
aFont = new OpenGl_Font (aFontFt, theKey);
@@ -625,7 +635,7 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
// purpose :
// =======================================================================
void OpenGl_Text::drawRect (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec4& theColorSubs) const
{
Handle(OpenGl_ShaderProgram) aPrevProgram = theCtx->ActiveProgram();
@@ -676,7 +686,7 @@ void OpenGl_Text::drawRect (const Handle(OpenGl_Context)& theCtx,
// purpose :
// =======================================================================
void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec4& theColorText,
const OpenGl_Vec4& theColorSubs,
const unsigned int theResolution) const
@@ -749,7 +759,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
myWinX, myWinY, myWinZ);
// compute scale factor for constant text height
if (theTextAspect->Aspect()->GetTextZoomable())
if (theTextAspect.Aspect()->GetTextZoomable())
{
myExportHeight = aPointSize;
}
@@ -773,14 +783,11 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
{
glDisable (GL_LIGHTING);
}
const Standard_Integer aPrevPolygonMode = theCtx->SetPolygonMode (GL_FILL);
const bool aPrevHatchingMode = theCtx->SetPolygonHatchEnabled (false);
#endif
// setup depth test
const bool hasDepthTest = !myIs2d
&& theTextAspect->Aspect()->Style() != Aspect_TOST_ANNOTATION;
&& theTextAspect.Aspect()->Style() != Aspect_TOST_ANNOTATION;
if (!hasDepthTest)
{
glDisable (GL_DEPTH_TEST);
@@ -808,10 +815,9 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
// setup blending
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
const bool anAlphaToCoverageOld = theCtx->SetSampleAlphaToCoverage (false);
// extra drawings
switch (theTextAspect->Aspect()->DisplayType())
switch (theTextAspect.Aspect()->DisplayType())
{
case Aspect_TODT_BLEND:
{
@@ -874,7 +880,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
}
#endif
if (theTextAspect->Aspect()->DisplayType() == Aspect_TODT_DIMENSION)
if (theTextAspect.Aspect()->DisplayType() == Aspect_TODT_DIMENSION)
{
glDisable (GL_BLEND);
if (!myIs2d)
@@ -906,11 +912,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
glDisable (GL_STENCIL_TEST);
#if !defined(GL_ES_VERSION_2_0)
glDisable (GL_COLOR_LOGIC_OP);
theCtx->SetPolygonMode (aPrevPolygonMode);
theCtx->SetPolygonHatchEnabled (aPrevHatchingMode);
#endif
theCtx->SetSampleAlphaToCoverage (anAlphaToCoverageOld);
// model view matrix was modified
theCtx->WorldViewState.Pop();

View File

@@ -33,7 +33,7 @@
//! Text rendering
class OpenGl_Text : public OpenGl_Element
{
DEFINE_STANDARD_RTTIEXT(OpenGl_Text, OpenGl_Element)
public:
//! Main constructor
@@ -83,13 +83,13 @@ public: //! @name methods for compatibility with layers
Standard_EXPORT OpenGl_Text();
//! Create key for shared resource
Standard_EXPORT static TCollection_AsciiString FontKey (const Handle(OpenGl_AspectText)& theAspect,
Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
const Standard_Integer theHeight,
const unsigned int theResolution);
//! Find shared resource for specified font or initialize new one
Standard_EXPORT static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theAspect,
const OpenGl_AspectText& theAspect,
const Standard_Integer theHeight,
const unsigned int theResolution,
const TCollection_AsciiString theKey);
@@ -97,7 +97,7 @@ public: //! @name methods for compatibility with layers
//! Compute text width
Standard_EXPORT static void StringSize (const Handle(OpenGl_Context)& theCtx,
const NCollection_String& theText,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const OpenGl_TextParam& theParams,
const unsigned int theResolution,
Standard_ShortReal& theWidth,
@@ -112,8 +112,8 @@ public: //! @name methods for compatibility with layers
//! Perform rendering
Standard_EXPORT void Render (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect,
const unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
const OpenGl_AspectText& theTextAspect,
const unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
protected:
@@ -127,21 +127,21 @@ private:
//! Setup matrix.
void setupMatrix (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec3 theDVec) const;
//! Draw arrays of vertices.
void drawText (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect) const;
const OpenGl_AspectText& theTextAspect) const;
//! Draw rectangle from bounding text box.
void drawRect (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec4& theColorSubs) const;
//! Main rendering code
void render (const Handle(OpenGl_Context)& theCtx,
const Handle(OpenGl_AspectText)& theTextAspect,
const OpenGl_AspectText& theTextAspect,
const OpenGl_Vec4& theColorText,
const OpenGl_Vec4& theColorSubs,
const unsigned int theResolution) const;

View File

@@ -405,6 +405,15 @@ bool OpenGl_Texture::Init (const Handle(OpenGl_Context)& theCtx,
const Graphic3d_TypeOfTexture theType,
const Image_PixMap* theImage)
{
if (theSizeX < 1
|| theSizeY < 1)
{
theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
"Error: texture of 0 size cannot be created.");
Release (theCtx.operator->());
return false;
}
#if !defined(GL_ES_VERSION_2_0)
const GLenum aTarget = theType == Graphic3d_TOT_1D
? GL_TEXTURE_1D

View File

@@ -15,24 +15,21 @@
#include <OpenGl_Context.hxx>
#include <OpenGl_TileSampler.hxx>
#include <Graphic3d_RenderingParams.hxx>
#include <TCollection_ExtendedString.hxx>
namespace
{
//! Scale factor for estimating visual error.
static const float THE_SCALE_FACTOR = 1.0f / 1e6f;
}
// define to debug algorithm values
//#define RAY_TRACE_PRINT_DEBUG_INFO
//=======================================================================
//function : OpenGl_TileSampler
//purpose :
//=======================================================================
OpenGl_TileSampler::OpenGl_TileSampler()
: mySample (0),
mySizeX (0),
mySizeY (0),
myTilesX (0),
myTilesY (0)
: myLastSample (0),
myScaleFactor(1.0f),
myTileSize (0),
myViewSize (0, 0)
{
mySampler.initFaure();
}
@@ -41,156 +38,292 @@ OpenGl_TileSampler::OpenGl_TileSampler()
//function : GrabVarianceMap
//purpose :
//=======================================================================
void OpenGl_TileSampler::GrabVarianceMap (const Handle(OpenGl_Context)& theContext)
{
#if !defined(GL_ES_VERSION_2_0)
std::vector<GLint> aRawData (NbTiles(), 0);
theContext->core11fwd->glGetTexImage (GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_INT, &aRawData.front());
const GLenum anErr = theContext->core11fwd->glGetError();
if (anErr != GL_NO_ERROR)
{
theContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_MEDIUM,
"Error! Failed to fetch visual error map from the GPU");
}
else
{
for (int aTileIdx = 0, aNbTiles = NbTiles(); aTileIdx < aNbTiles; ++aTileIdx)
{
myVarianceMap[aTileIdx] = aRawData[aTileIdx] * THE_SCALE_FACTOR;
}
for (int aX = 0; aX < myTilesX; ++aX)
{
for (int aY = 0; aY < myTilesY; ++aY)
{
ChangeTile (aX, aY) *= 1.0f / TileArea (aX, aY); // average error over the tile
if (aY > 0)
{
ChangeTile (aX, aY) += Tile (aX, aY - 1);
}
}
}
myMarginalMap.resize (myTilesX); // build marginal distribution
for (int aX = 0; aX < myTilesX; ++aX)
{
myMarginalMap[aX] = Tile (aX, myTilesY - 1);
if (aX > 0)
myMarginalMap[aX] += myMarginalMap[aX - 1];
}
}
#else
// glGetTexImage() is unavailable on OpenGL ES, FBO + glReadPixels() can be used instead
(void )theContext;
#endif
}
//=======================================================================
//function : Sample
//purpose :
//=======================================================================
void OpenGl_TileSampler::Sample (int& theOffsetX,
int& theOffsetY)
{
int aX = 0;
int aY = 0;
const float aKsiX = mySampler.sample (0, mySample) * myMarginalMap.back();
for (; aX < myTilesX - 1; ++aX)
{
if (aKsiX <= myMarginalMap[aX])
{
break;
}
}
const float aKsiY = mySampler.sample (1, mySample) * Tile (aX, myTilesY - 1);
for (; aY < myTilesY - 1; ++aY)
{
if (aKsiY <= Tile (aX, aY))
{
break;
}
}
theOffsetX = aX * TileSize();
theOffsetY = aY * TileSize();
++mySample;
}
//=======================================================================
//function : SetSize
//purpose :
//=======================================================================
void OpenGl_TileSampler::SetSize (const int theSizeX,
const int theSizeY)
{
if (mySizeX == theSizeX
&& mySizeY == theSizeY)
{
return;
}
mySizeX = theSizeX;
mySizeY = theSizeY;
myTilesX = static_cast<int> (ceilf (static_cast<float> (mySizeX) / TileSize()));
myTilesY = static_cast<int> (ceilf (static_cast<float> (mySizeY) / TileSize()));
myVarianceMap.resize (myTilesX * myTilesY);
}
//=======================================================================
//function : Upload
//purpose :
//=======================================================================
void OpenGl_TileSampler::Upload (const Handle(OpenGl_Context)& theContext,
const Handle(OpenGl_Texture)& theTexture,
const int theNbTilesX,
const int theNbTilesY,
const bool theAdaptive)
void OpenGl_TileSampler::GrabVarianceMap (const Handle(OpenGl_Context)& theContext,
const Handle(OpenGl_Texture)& theTexture)
{
if (theTexture.IsNull())
{
return;
}
const int aNbTilesX = theAdaptive ? theNbTilesX : myTilesX;
const int aNbTilesY = theAdaptive ? theNbTilesY : myTilesY;
Standard_ASSERT_RAISE (aNbTilesX * aNbTilesY > 0,
"Error! Number of sampling tiles should be positive");
std::vector<GLint> aData (aNbTilesX * aNbTilesY * 2);
for (int aX = 0; aX < aNbTilesX; ++aX)
myVarianceRaw.Init (0);
#if !defined(GL_ES_VERSION_2_0)
theTexture->Bind (theContext);
theContext->core11fwd->glPixelStorei (GL_PACK_ALIGNMENT, 1);
theContext->core11fwd->glPixelStorei (GL_PACK_ROW_LENGTH, 0);
theContext->core11fwd->glGetTexImage (GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_INT, myVarianceRaw.ChangeData());
const GLenum anErr = theContext->core11fwd->glGetError();
theTexture->Unbind (theContext);
if (anErr != GL_NO_ERROR)
{
for (int aY = 0; aY < aNbTilesY; ++aY)
theContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_MEDIUM,
"Error! Failed to fetch visual error map from the GPU");
return;
}
#else
// glGetTexImage() is unavailable on OpenGL ES, FBO + glReadPixels() can be used instead
(void )theContext;
#endif
const float aFactor = 1.0f / myScaleFactor;
for (Standard_Size aColIter = 0; aColIter < myVarianceMap.SizeX; ++aColIter)
{
for (Standard_Size aRowIter = 0; aRowIter < myVarianceMap.SizeY; ++aRowIter)
{
if (!theAdaptive)
const int aRawValue = myVarianceRaw.Value (aRowIter, aColIter);
Standard_RangeError_Raise_if (aRawValue < 0, "Internal Error: signed integer overflow within OpenGl_TileSampler");
float& aTile = myVarianceMap.ChangeValue (aRowIter, aColIter);
aTile = aFactor * float(aRawValue);
aTile *= 1.0f / tileArea ((int )aColIter, (int )aRowIter); // average error over the tile
if (aRowIter != 0)
{
aData[(aY * aNbTilesX + aX) * 2 + 0] = aX * TileSize();
aData[(aY * aNbTilesX + aX) * 2 + 1] = aY * TileSize();
}
else
{
Sample (aData[(aY * aNbTilesX + aX) * 2 + 0],
aData[(aY * aNbTilesX + aX) * 2 + 1]);
aTile += myVarianceMap.Value (aRowIter - 1, aColIter);
}
}
}
theTexture->Bind (theContext);
theContext->core11fwd->glTexImage2D (GL_TEXTURE_2D, 0, GL_RG32I, aNbTilesX, aNbTilesY, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, &aData.front());
if (theContext->core11fwd->glGetError() != GL_NO_ERROR)
// build marginal distribution
for (Standard_Size aX = 0; aX < myVarianceMap.SizeX; ++aX)
{
theContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_MEDIUM,
"Error! Failed to upload tile offset map on the GPU");
myMarginalMap[aX] = myVarianceMap.Value (myVarianceMap.SizeY - 1, aX);
if (aX != 0)
{
myMarginalMap[aX] += myMarginalMap[aX - 1];
}
}
#ifdef RAY_TRACE_PRINT_DEBUG_INFO
dumpMap (std::cerr, myVarianceRaw, "OpenGl_TileSampler, Variance map");
#endif
}
//=======================================================================
//function : dumpMap
//purpose :
//=======================================================================
void OpenGl_TileSampler::dumpMap (std::ostream& theStream,
const Image_PixMapTypedData<int>& theMap,
const char* theTitle) const
{
theStream << theTitle << " " << theMap.SizeX << "x" << theMap.SizeY << " (tile " << myTileSize << "x" << myTileSize << ")" << ":\n";
for (Standard_Size aRowIter = 0; aRowIter < theMap.SizeY; ++aRowIter)
{
for (Standard_Size aColIter = 0; aColIter < theMap.SizeX; ++aColIter)
{
theStream << " [" << theMap.Value (aRowIter, aColIter) << "]";
}
theStream << "\n";
}
}
//=======================================================================
//function : nextTileToSample
//purpose :
//=======================================================================
Graphic3d_Vec2i OpenGl_TileSampler::nextTileToSample()
{
Graphic3d_Vec2i aTile (0, 0);
const float aKsiX = mySampler.sample (0, myLastSample) * myMarginalMap.back();
for (; (size_t )aTile.x() < myMarginalMap.size() - 1; ++aTile.x())
{
if (aKsiX <= myMarginalMap[aTile.x()])
{
break;
}
}
const float aKsiY = mySampler.sample (1, myLastSample) * myVarianceMap.Value (myVarianceMap.SizeY - 1, aTile.x());
for (; (size_t )aTile.y() < myVarianceMap.SizeY - 1; ++aTile.y())
{
if (aKsiY <= myVarianceMap.Value (aTile.y(), aTile.x()))
{
break;
}
}
++myLastSample;
return aTile;
}
//=======================================================================
//function : SetSize
//purpose :
//=======================================================================
void OpenGl_TileSampler::SetSize (const Graphic3d_RenderingParams& theParams,
const Graphic3d_Vec2i& theSize)
{
if (theSize.x() <= 0
|| theSize.y() <= 0)
{
return;
}
myViewSize = theSize;
const int aTileSize = Max (theParams.RayTracingTileSize, 1);
const int aNbTilesX = Max (1, static_cast<int> (ceilf (static_cast<float> (theSize.x()) / aTileSize)));
const int aNbTilesY = Max (1, static_cast<int> (ceilf (static_cast<float> (theSize.y()) / aTileSize)));
if (myTileSize != aTileSize
|| (int )myTiles.SizeX != aNbTilesX
|| (int )myTiles.SizeY != aNbTilesY)
{
myTileSize = aTileSize;
myScaleFactor = 1.0e6f * (1024.0f / float(myTileSize * myTileSize));
Handle(NCollection_BaseAllocator) anAlloc = NCollection_BaseAllocator::CommonBaseAllocator();
myTiles.SetTopDown (true);
myTiles.Init (anAlloc, aNbTilesX, aNbTilesY);
myTiles.Init (1);
myTileSamples.SetTopDown (true);
myTileSamples.Init (myTiles.Allocator(), aNbTilesX, aNbTilesY);
myTileSamples.Init (1);
myVarianceMap.SetTopDown (true);
myVarianceMap.Init (myTiles.Allocator(), myTiles.SizeX, myTiles.SizeY);
myVarianceMap.Init (0.0f);
myVarianceRaw.SetTopDown (true);
myVarianceRaw.Init (myTiles.Allocator(), myTiles.SizeX, myTiles.SizeY);
myVarianceRaw.Init (0);
myOffsets.SetTopDown (true);
myOffsets.Init (myTiles.Allocator(), myTiles.SizeX, myTiles.SizeY);
myOffsets.Init (Graphic3d_Vec2i (-1, -1));
myMarginalMap.resize (myTiles.SizeX);
myMarginalMap.assign (myMarginalMap.size(), 0.0f);
}
// calculate a size of compact offsets texture optimal for rendering reduced number of tiles
Standard_Integer aNbShunkTilesX = (int )myTiles.SizeX, aNbShunkTilesY = (int )myTiles.SizeY;
if (theParams.NbRayTracingTiles > 0)
{
aNbShunkTilesX = 8;
aNbShunkTilesY = 8;
for (Standard_Integer anIdx = 0; aNbShunkTilesX * aNbShunkTilesY < theParams.NbRayTracingTiles; ++anIdx)
{
(anIdx % 2 == 0 ? aNbShunkTilesX : aNbShunkTilesY) <<= 1;
}
}
if ((int )myOffsetsShrunk.SizeX != aNbShunkTilesX
|| (int )myOffsetsShrunk.SizeY != aNbShunkTilesY)
{
myOffsetsShrunk.SetTopDown (true);
myOffsetsShrunk.Init (myTiles.Allocator(), aNbShunkTilesX, aNbShunkTilesY);
myOffsetsShrunk.Init (Graphic3d_Vec2i (-1, -1));
}
}
//=======================================================================
//function : upload
//purpose :
//=======================================================================
bool OpenGl_TileSampler::upload (const Handle(OpenGl_Context)& theContext,
const Handle(OpenGl_Texture)& theSamplesTexture,
const Handle(OpenGl_Texture)& theOffsetsTexture,
const bool theAdaptive)
{
if (myTiles.IsEmpty())
{
return false;
}
// Fill in myTiles map with a number of passes (samples) per tile.
// By default, all tiles receive 1 sample, but basing on visual error level (myVarianceMap),
// this amount is re-distributed from tiles having smallest error take 0 samples to tiles having larger error.
// This redistribution is smoothed by Halton sampler.
//
// myOffsets map is filled as redirection of currently rendered tile to another one
// so that tiles having smallest error level have 0 tiles redirected from,
// while tiles with great error level might be rendered more than 1.
// This map is used within single-pass rendering method requiring atomic float operation support from hardware.
myTiles.Init (0);
Image_PixMapTypedData<Graphic3d_Vec2i>& anOffsets = theAdaptive ? myOffsetsShrunk : myOffsets;
anOffsets.Init (Graphic3d_Vec2i (-1, -1));
for (Standard_Size aRowIter = 0; aRowIter < anOffsets.SizeY; ++aRowIter)
{
for (Standard_Size aColIter = 0; aColIter < anOffsets.SizeX; ++aColIter)
{
Graphic3d_Vec2i& aRedirectTile = anOffsets.ChangeValue (aRowIter, aColIter);
aRedirectTile = theAdaptive ? nextTileToSample() : Graphic3d_Vec2i ((int )aColIter, (int )aRowIter);
myTiles.ChangeValue (aRedirectTile.y(), aRedirectTile.x()) += 1;
}
}
#ifdef RAY_TRACE_PRINT_DEBUG_INFO
dumpMap (std::cerr, myTiles, "OpenGl_TileSampler, Samples");
#endif
// Fill in myTileSamples map from myTiles with an actual number of Samples per Tile as multiple of Tile Area
// (e.g. tile that should be rendered ones will have amount of samples equal to its are 4x4=16).
// This map is used for discarding tile fragments having <=0 of samples left within multi-pass rendering.
myTileSamples.Init (0);
for (Standard_Size aRowIter = 0; aRowIter < myTiles.SizeY; ++aRowIter)
{
for (Standard_Size aColIter = 0; aColIter < myTiles.SizeX; ++aColIter)
{
myTileSamples.ChangeValue (aRowIter, aColIter) = tileArea ((int )aColIter, (int )aRowIter) * myTiles.Value (aRowIter, aColIter);
}
}
bool hasErrors = false;
if (!theSamplesTexture.IsNull())
{
theSamplesTexture->Bind (theContext);
theContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
#if !defined(GL_ES_VERSION_2_0)
theContext->core11fwd->glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
#endif
if (theSamplesTexture->SizeX() == (int )myTileSamples.SizeX
&& theSamplesTexture->SizeY() == (int )myTileSamples.SizeY)
{
theContext->core11fwd->glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, (int )myTileSamples.SizeX, (int )myTileSamples.SizeY, GL_RED_INTEGER, GL_INT, myTileSamples.Data());
if (theContext->core11fwd->glGetError() != GL_NO_ERROR)
{
hasErrors = true;
theContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_MEDIUM,
"Error! Failed to upload tile samples map on the GPU");
}
}
else
{
hasErrors = true;
}
theSamplesTexture->Unbind (theContext);
}
if (!theOffsetsTexture.IsNull())
{
if (theOffsetsTexture->SizeX() != (int )anOffsets.SizeX
|| theOffsetsTexture->SizeY() != (int )anOffsets.SizeY
|| !theOffsetsTexture->IsValid())
{
theOffsetsTexture->Release (theContext.operator->());
if (!theOffsetsTexture->Init (theContext, GL_RG32I, GL_RG_INTEGER, GL_INT,
(int )anOffsets.SizeX, (int )anOffsets.SizeY, Graphic3d_TOT_2D))
{
hasErrors = true;
}
}
if (theOffsetsTexture->IsValid())
{
theOffsetsTexture->Bind (theContext);
theContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
#if !defined(GL_ES_VERSION_2_0)
theContext->core11fwd->glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
#endif
theContext->core11fwd->glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, (int )anOffsets.SizeX, (int )anOffsets.SizeY, GL_RG_INTEGER, GL_INT, anOffsets.Data());
if (theContext->core11fwd->glGetError() != GL_NO_ERROR)
{
hasErrors = true;
theContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_MEDIUM,
"Error! Failed to upload tile offset map on the GPU");
}
theOffsetsTexture->Unbind (theContext);
}
}
return !hasErrors;
}

View File

@@ -19,8 +19,12 @@
#include <OpenGl_Texture.hxx>
#include <OpenGl_HaltonSampler.hxx>
#include <Image_PixMapTypedData.hxx>
#include <vector>
class Graphic3d_RenderingParams;
//! Tool object used for sampling screen tiles according to estimated pixel variance (used in path tracing engine).
//! To improve GPU thread coherency, rendering window is split into pixel blocks or tiles. The important feature of
//! this approach is that it is possible to keep the same number of tiles for any screen resolution (e.g. 256 tiles
@@ -30,87 +34,126 @@
//! final final image is the same for both cases.
class OpenGl_TileSampler
{
public:
//! Size of individual tile in pixels.
static int TileSize() { return 32; }
public:
//! Creates new tile sampler.
Standard_EXPORT OpenGl_TileSampler();
//! Returns width of ray-tracing viewport.
int SizeX() const { return mySizeX; }
//! Size of individual tile in pixels.
Graphic3d_Vec2i TileSize() const { return Graphic3d_Vec2i (myTileSize, myTileSize); }
//! Returns height of ray-tracing viewport.
int SizeY() const { return mySizeY; }
//! Scale factor for quantization of visual error (float) into signed integer.
float VarianceScaleFactor() const { return myScaleFactor; }
//! Returns number of tiles in X dimension.
int NbTilesX() const { return myTilesX; }
int NbTilesX() const { return (int)myTiles.SizeX; }
//! Returns number of tiles in Y dimension.
int NbTilesY() const { return myTilesY; }
int NbTilesY() const { return (int)myTiles.SizeY; }
//! Returns total number of tiles in viewport.
int NbTiles() const { return myTilesX * myTilesY; }
int NbTiles() const { return int(myTiles.SizeX * myTiles.SizeY); }
//! Specifies size of ray-tracing viewport.
Standard_EXPORT void SetSize (const int theSizeX,
const int theSizeY);
//! Returns ray-tracing viewport.
const Graphic3d_Vec2i& ViewSize() const { return myViewSize; }
//! Returns number of pixels in the given tile.
int TileArea (const int theX,
const int theY) const
//! Number of tiles within offsets texture.
Graphic3d_Vec2i NbOffsetTiles (bool theAdaptive) const
{
return Min (TileSize(), mySizeX - theX * TileSize())
* Min (TileSize(), mySizeY - theY * TileSize());
return theAdaptive
? Graphic3d_Vec2i ((int )myOffsetsShrunk.SizeX, (int )myOffsetsShrunk.SizeY)
: Graphic3d_Vec2i ((int )myOffsets.SizeX, (int )myOffsets.SizeY);
}
//! Maximum number of tiles within offsets texture.
Graphic3d_Vec2i NbOffsetTilesMax() const { return NbOffsetTiles (true).cwiseMax (NbOffsetTiles (false)); }
//! Viewport for rendering using offsets texture.
Graphic3d_Vec2i OffsetTilesViewport (bool theAdaptive) const { return NbOffsetTiles (theAdaptive) * myTileSize; }
//! Maximum viewport for rendering using offsets texture.
Graphic3d_Vec2i OffsetTilesViewportMax() const { return NbOffsetTilesMax() * myTileSize; }
//! Return maximum number of samples per tile.
int MaxTileSamples() const
{
int aNbSamples = 0;
for (Standard_Size aRowIter = 0; aRowIter < myTiles.SizeY; ++aRowIter)
{
for (Standard_Size aColIter = 0; aColIter < myTiles.SizeX; ++aColIter)
{
aNbSamples = Max (aNbSamples, myTiles.Value (aRowIter, aColIter));
}
}
return aNbSamples;
}
//! Specifies size of ray-tracing viewport and recomputes tile size.
Standard_EXPORT void SetSize (const Graphic3d_RenderingParams& theParams,
const Graphic3d_Vec2i& theSize);
//! Fetches current error estimation from the GPU and
//! builds 2D discrete distribution for tile sampling.
Standard_EXPORT void GrabVarianceMap (const Handle(OpenGl_Context)& theContext);
Standard_EXPORT void GrabVarianceMap (const Handle(OpenGl_Context)& theContext,
const Handle(OpenGl_Texture)& theTexture);
//! Samples tile location according to estimated error.
Standard_EXPORT void Sample (int& theOffsetX,
int& theOffsetY);
//! Resets (restart) tile sampler to initial state.
void Reset() { myLastSample = 0; }
//! Resets tile sampler to initial state.
void Reset() { mySample = 0; }
//! Uploads tile samples to the given OpenGL texture.
bool UploadSamples (const Handle(OpenGl_Context)& theContext,
const Handle(OpenGl_Texture)& theSamplesTexture,
const bool theAdaptive)
{
return upload (theContext, theSamplesTexture, Handle(OpenGl_Texture)(), theAdaptive);
}
//! Uploads offsets of sampled tiles to the given OpenGL texture.
Standard_EXPORT void Upload (const Handle(OpenGl_Context)& theContext,
const Handle(OpenGl_Texture)& theTexture,
const int theNbTilesX,
const int theNbTilesY,
const bool theAdaptive);
protected:
//! Returns tile value (estimated error).
float Tile (const int theX,
const int theY) const
bool UploadOffsets (const Handle(OpenGl_Context)& theContext,
const Handle(OpenGl_Texture)& theOffsetsTexture,
const bool theAdaptive)
{
return myVarianceMap[theY * myTilesX + theX];
}
//! Returns tile value (estimated error).
float& ChangeTile (const int theX,
const int theY)
{
return myVarianceMap[theY * myTilesX + theX];
return upload (theContext, Handle(OpenGl_Texture)(), theOffsetsTexture, theAdaptive);
}
protected:
std::vector<float> myVarianceMap; //!< Estimation of visual error per tile
std::vector<float> myMarginalMap; //!< Marginal distribution of 2D error map
OpenGl_HaltonSampler mySampler; //!< Halton sequence generator
int mySample; //!< Index of generated sample
int mySizeX; //!< Width of ray-tracing viewport
int mySizeY; //!< Height of ray-tracing viewport
int myTilesX; //!< Number of tiles in X dimension
int myTilesY; //!< Number of tiles in Y dimension
//! Returns number of pixels in the given tile.
int tileArea (int theX, int theY) const
{
const int aSizeX = Min (myTileSize, myViewSize.x() - theX * myTileSize);
const int aSizeY = Min (myTileSize, myViewSize.y() - theY * myTileSize);
return aSizeX * aSizeY;
}
//! Samples tile location according to estimated error.
Standard_EXPORT Graphic3d_Vec2i nextTileToSample();
//! Uploads offsets of sampled tiles to the given OpenGL texture.
Standard_EXPORT bool upload (const Handle(OpenGl_Context)& theContext,
const Handle(OpenGl_Texture)& theSamplesTexture,
const Handle(OpenGl_Texture)& theOffsetsTexture,
const bool theAdaptive);
//! Auxiliary method for dumping 2D image map into stream (e.g. for debugging).
Standard_EXPORT void dumpMap (std::ostream& theStream,
const Image_PixMapTypedData<int>& theMap,
const char* theTitle) const;
protected:
Image_PixMapTypedData<unsigned int> myTiles; //!< number of samples per tile (initially all 1)
Image_PixMapTypedData<unsigned int> myTileSamples; //!< number of samples for all pixels within the tile (initially equals to Tile area)
Image_PixMapTypedData<float> myVarianceMap; //!< Estimation of visual error per tile
Image_PixMapTypedData<int> myVarianceRaw; //!< Estimation of visual error per tile (raw data)
Image_PixMapTypedData<Graphic3d_Vec2i> myOffsets; //!< 2D array of tiles redirecting to another tile
Image_PixMapTypedData<Graphic3d_Vec2i> myOffsetsShrunk; //!< 2D array of tiles redirecting to another tile (shrunk)
std::vector<float> myMarginalMap; //!< Marginal distribution of 2D error map
OpenGl_HaltonSampler mySampler; //!< Halton sequence generator
unsigned int myLastSample; //!< Index of generated sample
float myScaleFactor; //!< scale factor for quantization of visual error (float) into signed integer
int myTileSize; //!< tile size
Graphic3d_Vec2i myViewSize; //!< ray-tracing viewport
};

View File

@@ -110,9 +110,6 @@ OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
myRaytraceFBO1[1] = new OpenGl_FrameBuffer();
myRaytraceFBO2[0] = new OpenGl_FrameBuffer();
myRaytraceFBO2[1] = new OpenGl_FrameBuffer();
myGraduatedTrihedron = new OpenGl_GraduatedTrihedron();
myFrameStatsPrs = new OpenGl_FrameStatsPrs();
}
// =======================================================================
@@ -133,8 +130,8 @@ OpenGl_View::~OpenGl_View()
// =======================================================================
void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
{
myGraduatedTrihedron->Release (theCtx.operator->());
myFrameStatsPrs->Release (theCtx.operator->());
myGraduatedTrihedron.Release (theCtx.operator->());
myFrameStatsPrs.Release (theCtx.operator->());
if (!myTextureEnv.IsNull())
{
@@ -146,15 +143,15 @@ void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
myTextureEnv.Nullify();
}
if (!myTextureParams.IsNull())
if (myTextureParams != NULL)
{
myTextureParams->Release (theCtx.operator->());
}
if (!myBgGradientArray.IsNull())
if (myBgGradientArray != NULL)
{
myBgGradientArray->Release (theCtx.operator->());
}
if (!myBgTextureArray.IsNull())
if (myBgTextureArray != NULL)
{
myBgTextureArray->Release (theCtx.operator->());
}
@@ -336,7 +333,7 @@ void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron&
myGTrihedronData = theTrihedronData;
myGTrihedronData.PtrView = this;
myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback;
myGraduatedTrihedron->SetValues (myGTrihedronData);
myGraduatedTrihedron.SetValues (myGTrihedronData);
myToShowGradTrihedron = true;
}
@@ -347,7 +344,7 @@ void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron&
void OpenGl_View::GraduatedTrihedronErase()
{
myGTrihedronData.PtrView = NULL;
myGraduatedTrihedron->Release (myWorkspace->GetGlContext().operator->());
myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->());
myToShowGradTrihedron = false;
}
@@ -357,7 +354,7 @@ void OpenGl_View::GraduatedTrihedronErase()
// =======================================================================
void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
{
myGraduatedTrihedron->SetMinMax (theMin, theMax);
myGraduatedTrihedron.SetMinMax (theMin, theMax);
}
// =======================================================================

View File

@@ -297,7 +297,7 @@ public:
const Quantity_ColorRGBA& BackgroundColor() const { return myBgColor; }
//! Change graduated trihedron.
const Handle(OpenGl_GraduatedTrihedron)& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
const Handle(Graphic3d_TextureEnv)& theTexture);
@@ -486,8 +486,8 @@ protected:
//! Is needed for selection of overlapping objects and storage of the current view volume
OpenGl_BVHTreeSelector myBVHSelector;
Handle(OpenGl_GraduatedTrihedron) myGraduatedTrihedron;
Handle(OpenGl_FrameStatsPrs) myFrameStatsPrs;
OpenGl_GraduatedTrihedron myGraduatedTrihedron;
OpenGl_FrameStatsPrs myFrameStatsPrs;
Handle(OpenGl_TextureSet) myTextureEnv;
@@ -520,9 +520,9 @@ protected: //! @name Rendering properties
protected: //! @name Background parameters
Handle(OpenGl_AspectFace) myTextureParams; //!< Stores texture and its parameters for textured background
Handle(OpenGl_BackgroundArray) myBgGradientArray; //!< Primitive array for gradient background
Handle(OpenGl_BackgroundArray) myBgTextureArray; //!< Primitive array for texture background
OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background
OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background
OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background
protected: //! @name data types related to ray-tracing
@@ -592,7 +592,10 @@ protected: //! @name data types related to ray-tracing
// images used by ISS mode
OpenGl_RT_uRenderImage,
OpenGl_RT_uTilesImage,
OpenGl_RT_uOffsetImage,
OpenGl_RT_uTileSize,
OpenGl_RT_uVarianceScaleFactor,
// maximum radiance value
OpenGl_RT_uMaxRadiance,
@@ -603,12 +606,10 @@ protected: //! @name data types related to ray-tracing
//! Defines OpenGL image samplers.
enum ShaderImageNames
{
OpenGl_RT_OutputImageLft = 0,
OpenGl_RT_OutputImageRgh = 1,
OpenGl_RT_VisualErrorImageLft = 2,
OpenGl_RT_VisualErrorImageRgh = 3,
OpenGl_RT_TileOffsetsImageLft = 4,
OpenGl_RT_TileOffsetsImageRgh = 5
OpenGl_RT_OutputImage = 0,
OpenGl_RT_VisualErrorImage = 1,
OpenGl_RT_TileOffsetsImage = 2,
OpenGl_RT_TileSamplesImage = 3
};
//! Tool class for management of shader sources.
@@ -692,17 +693,14 @@ protected: //! @name data types related to ray-tracing
//! Enables/disables adaptive screen sampling for path tracing.
Standard_Boolean AdaptiveScreenSampling;
//! Enables/disables 1-pass atomic mode for AdaptiveScreenSampling.
Standard_Boolean AdaptiveScreenSamplingAtomic;
//! Enables/disables environment map for background.
Standard_Boolean UseEnvMapForBackground;
//! Maximum radiance value used for clamping radiance estimation.
Standard_ShortReal RadianceClampingValue;
//! Number of tiles in X dimension (in adaptive sampling mode).
Standard_Integer NbTilesX;
//! Number of tiles in Y dimension (in adaptive sampling mode).
Standard_Integer NbTilesY;
//! Enables/disables depth-of-field effect (path tracing, perspective camera).
Standard_Boolean DepthOfField;
@@ -719,10 +717,9 @@ protected: //! @name data types related to ray-tracing
UseBindlessTextures (Standard_False),
TwoSidedBsdfModels (Standard_False),
AdaptiveScreenSampling (Standard_False),
AdaptiveScreenSamplingAtomic (Standard_False),
UseEnvMapForBackground (Standard_False),
RadianceClampingValue (30.0),
NbTilesX (16),
NbTilesY (16),
DepthOfField (Standard_False),
ToneMappingMethod (Graphic3d_ToneMappingMethod_Disabled) { }
};
@@ -776,11 +773,11 @@ protected: //! @name methods related to ray-tracing
const Handle(OpenGl_Context)& theGlContext);
//! Creates ray-tracing material properties.
OpenGl_RaytraceMaterial convertMaterial (const Handle(OpenGl_AspectFace)& theAspect,
OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect,
const Handle(OpenGl_Context)& theGlContext);
//! Adds OpenGL primitive array to ray-traced scene geometry.
Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const Handle(OpenGl_PrimitiveArray)& theArray,
Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
const Standard_Integer theMatID,
const OpenGl_Mat4* theTrans);
@@ -789,7 +786,7 @@ protected: //! @name methods related to ray-tracing
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const Handle(OpenGl_PrimitiveArray)& theArray);
const OpenGl_PrimitiveArray& theArray);
//! Adds OpenGL triangle array to ray-traced scene geometry.
Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
@@ -854,7 +851,9 @@ protected: //! @name methods related to ray-tracing
const Handle(OpenGl_ShaderObject)& theFragShader);
//! Initializes OpenGL/GLSL shader programs.
Standard_Boolean initRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
Standard_Boolean initRaytraceResources (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const Handle(OpenGl_Context)& theGlContext);
//! Releases OpenGL/GLSL shader programs.
void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext,
@@ -884,7 +883,8 @@ protected: //! @name methods related to ray-tracing
const int theWinSizeY);
//! Binds ray-trace textures to corresponding texture units.
void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext,
int theStereoView);
//! Unbinds ray-trace textures from corresponding texture unit.
void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
@@ -914,9 +914,13 @@ protected: //! @name methods related to ray-tracing
Standard_Boolean runPathtrace (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theReadDrawFbo,
const Handle(OpenGl_Context)& theGlContext);
//! Runs path tracing (global illumination) kernel.
Standard_Boolean runPathtraceOut (Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theReadDrawFbo,
const Handle(OpenGl_Context)& theGlContext);
//! Redraws the window using OpenGL/GLSL ray-tracing or path tracing.
Standard_Boolean raytrace (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
@@ -1010,6 +1014,9 @@ protected: //! @name fields related to ray-tracing
//! Texture containing offsets of sampled screen tiles (2 textures are used in stereo mode).
//! Used if adaptive screen sampling is activated.
Handle(OpenGl_Texture) myRaytraceTileOffsetsTexture[2];
//! Texture containing amount of extra per-tile samples (2 textures are used in stereo mode).
//! Used if adaptive screen sampling is activated.
Handle(OpenGl_Texture) myRaytraceTileSamplesTexture[2];
//! Vertex buffer (VBO) for drawing dummy quad.
OpenGl_VertexBuffer myRaytraceScreenQuad;

View File

@@ -144,10 +144,11 @@ Standard_Boolean OpenGl_View::updateRaytraceGeometry (const RaytraceUpdateMode
for (OpenGl_Structure::GroupIterator aGroupIter (aStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
{
// Extract OpenGL elements from the group (primitives arrays)
for (OpenGl_ElementNodes::Iterator anElemIterator (aGroupIter.Value()->GetElements()); anElemIterator.More(); anElemIterator.Next())
for (const OpenGl_ElementNode* aNode = aGroupIter.Value()->FirstNode(); aNode != NULL; aNode = aNode->next)
{
Handle(OpenGl_PrimitiveArray) aPrimArray = Handle(OpenGl_PrimitiveArray)::DownCast (anElemIterator.Value());
if (!aPrimArray.IsNull())
OpenGl_PrimitiveArray* aPrimArray = dynamic_cast<OpenGl_PrimitiveArray*> (aNode->elem);
if (aPrimArray != NULL)
{
anArrayIDs.insert (aPrimArray->GetUID());
}
@@ -343,7 +344,7 @@ void buildTextureTransform (const Handle(Graphic3d_TextureParams)& theParams, BV
// function : convertMaterial
// purpose : Creates ray-tracing material properties
// =======================================================================
OpenGl_RaytraceMaterial OpenGl_View::convertMaterial (const Handle(OpenGl_AspectFace)& theAspect,
OpenGl_RaytraceMaterial OpenGl_View::convertMaterial (const OpenGl_AspectFace* theAspect,
const Handle(OpenGl_Context)& theGlContext)
{
OpenGl_RaytraceMaterial theMaterial;
@@ -508,7 +509,7 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure*
{
// Get group material
OpenGl_RaytraceMaterial aGroupMaterial;
if (!aGroupIter.Value()->AspectFace().IsNull())
if (aGroupIter.Value()->AspectFace() != NULL)
{
aGroupMaterial = convertMaterial (
aGroupIter.Value()->AspectFace(), theGlContext);
@@ -518,14 +519,14 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure*
// Use group material if available, otherwise use structure material
myRaytraceGeometry.Materials.push_back (
!aGroupIter.Value()->AspectFace().IsNull() ? aGroupMaterial : theStructMat);
aGroupIter.Value()->AspectFace() != NULL ? aGroupMaterial : theStructMat);
// Add OpenGL elements from group (extract primitives arrays and aspects)
for (OpenGl_ElementNodes::Iterator anElemIterator (aGroupIter.Value()->GetElements()); anElemIterator.More(); anElemIterator.Next())
for (const OpenGl_ElementNode* aNode = aGroupIter.Value()->FirstNode(); aNode != NULL; aNode = aNode->next)
{
Handle(OpenGl_AspectFace) anAspect = Handle(OpenGl_AspectFace)::DownCast (anElemIterator.Value());
OpenGl_AspectFace* anAspect = dynamic_cast<OpenGl_AspectFace*> (aNode->elem);
if (!anAspect.IsNull())
if (anAspect != NULL)
{
aMatID = static_cast<Standard_Integer> (myRaytraceGeometry.Materials.size());
@@ -535,9 +536,9 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure*
}
else
{
Handle(OpenGl_PrimitiveArray) aPrimArray = Handle(OpenGl_PrimitiveArray)::DownCast (anElemIterator.Value());
OpenGl_PrimitiveArray* aPrimArray = dynamic_cast<OpenGl_PrimitiveArray*> (aNode->elem);
if (!aPrimArray.IsNull())
if (aPrimArray != NULL)
{
std::map<Standard_Size, OpenGl_TriangleSet*>::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray->GetUID());
@@ -584,7 +585,7 @@ Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure*
// function : addRaytracePrimitiveArray
// purpose : Adds OpenGL primitive array to ray-traced scene geometry
// =======================================================================
Handle(OpenGl_TriangleSet) OpenGl_View::addRaytracePrimitiveArray (const Handle(OpenGl_PrimitiveArray)& theArray,
Handle(OpenGl_TriangleSet) OpenGl_View::addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
const Standard_Integer theMaterial,
const OpenGl_Mat4* theTransform)
{
@@ -704,7 +705,7 @@ Handle(OpenGl_TriangleSet) OpenGl_View::addRaytracePrimitiveArray (const Handle(
{
const Standard_Integer aVertNum = aBounds->Bounds[aBound];
if (!addRaytraceVertexIndices (*aSet, theMaterial, aVertNum, aBoundStart, theArray))
if (!addRaytraceVertexIndices (*aSet, theMaterial, aVertNum, aBoundStart, *theArray))
{
aSet.Nullify();
return Handle(OpenGl_TriangleSet)();
@@ -717,7 +718,7 @@ Handle(OpenGl_TriangleSet) OpenGl_View::addRaytracePrimitiveArray (const Handle(
{
const Standard_Integer aVertNum = !anIndices.IsNull() ? anIndices->NbElements : anAttribs->NbElements;
if (!addRaytraceVertexIndices (*aSet, theMaterial, aVertNum, 0, theArray))
if (!addRaytraceVertexIndices (*aSet, theMaterial, aVertNum, 0, *theArray))
{
aSet.Nullify();
return Handle(OpenGl_TriangleSet)();
@@ -741,17 +742,17 @@ Standard_Boolean OpenGl_View::addRaytraceVertexIndices (OpenGl_TriangleSet&
const Standard_Integer theMatID,
const Standard_Integer theCount,
const Standard_Integer theOffset,
const Handle(OpenGl_PrimitiveArray)& theArray)
const OpenGl_PrimitiveArray& theArray)
{
switch (theArray->DrawMode())
switch (theArray.DrawMode())
{
case GL_TRIANGLES: return addRaytraceTriangleArray (theSet, theMatID, theCount, theOffset, theArray->Indices());
case GL_TRIANGLE_FAN: return addRaytraceTriangleFanArray (theSet, theMatID, theCount, theOffset, theArray->Indices());
case GL_TRIANGLE_STRIP: return addRaytraceTriangleStripArray (theSet, theMatID, theCount, theOffset, theArray->Indices());
case GL_TRIANGLES: return addRaytraceTriangleArray (theSet, theMatID, theCount, theOffset, theArray.Indices());
case GL_TRIANGLE_FAN: return addRaytraceTriangleFanArray (theSet, theMatID, theCount, theOffset, theArray.Indices());
case GL_TRIANGLE_STRIP: return addRaytraceTriangleStripArray (theSet, theMatID, theCount, theOffset, theArray.Indices());
#if !defined(GL_ES_VERSION_2_0)
case GL_QUAD_STRIP: return addRaytraceQuadrangleStripArray (theSet, theMatID, theCount, theOffset, theArray->Indices());
case GL_QUADS: return addRaytraceQuadrangleArray (theSet, theMatID, theCount, theOffset, theArray->Indices());
case GL_POLYGON: return addRaytracePolygonArray (theSet, theMatID, theCount, theOffset, theArray->Indices());
case GL_QUAD_STRIP: return addRaytraceQuadrangleStripArray (theSet, theMatID, theCount, theOffset, theArray.Indices());
case GL_QUADS: return addRaytraceQuadrangleArray (theSet, theMatID, theCount, theOffset, theArray.Indices());
case GL_POLYGON: return addRaytracePolygonArray (theSet, theMatID, theCount, theOffset, theArray.Indices());
#endif
}
@@ -1135,11 +1136,14 @@ TCollection_AsciiString OpenGl_View::generateShaderPrefix (const Handle(OpenGl_C
if (myRaytraceParameters.AdaptiveScreenSampling) // adaptive screen sampling requested
{
// to activate the feature we need OpenGL 4.4 and GL_NV_shader_atomic_float extension
if (theGlContext->IsGlGreaterEqual (4, 4) && theGlContext->CheckExtension ("GL_NV_shader_atomic_float"))
if (theGlContext->IsGlGreaterEqual (4, 4))
{
aPrefixString += TCollection_AsciiString ("\n#define ADAPTIVE_SAMPLING") +
TCollection_AsciiString ("\n#define BLOCK_SIZE ") + TCollection_AsciiString (OpenGl_TileSampler::TileSize());
aPrefixString += TCollection_AsciiString ("\n#define ADAPTIVE_SAMPLING");
if (myRaytraceParameters.AdaptiveScreenSamplingAtomic
&& theGlContext->CheckExtension ("GL_NV_shader_atomic_float"))
{
aPrefixString += TCollection_AsciiString ("\n#define ADAPTIVE_SAMPLING_ATOMIC");
}
}
}
@@ -1327,7 +1331,9 @@ Handle(OpenGl_ShaderProgram) OpenGl_View::initProgram (const Handle(OpenGl_Conte
// function : initRaytraceResources
// purpose : Initializes OpenGL/GLSL shader programs
// =======================================================================
Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context)& theGlContext)
Standard_Boolean OpenGl_View::initRaytraceResources (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const Handle(OpenGl_Context)& theGlContext)
{
if (myRaytraceInitStatus == OpenGl_RT_FAIL)
{
@@ -1371,46 +1377,25 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
}
}
Standard_Integer aNbTilesX = 8;
Standard_Integer aNbTilesY = 8;
for (Standard_Integer anIdx = 0; aNbTilesX * aNbTilesY < myRenderParams.NbRayTracingTiles; ++anIdx)
{
(anIdx % 2 == 0 ? aNbTilesX : aNbTilesY) <<= 1;
}
if (myRenderParams.RaytracingDepth != myRaytraceParameters.NbBounces
|| myRenderParams.IsTransparentShadowEnabled != myRaytraceParameters.TransparentShadows
|| myRenderParams.IsGlobalIlluminationEnabled != myRaytraceParameters.GlobalIllumination
|| myRenderParams.TwoSidedBsdfModels != myRaytraceParameters.TwoSidedBsdfModels
|| myRaytraceGeometry.HasTextures() != myRaytraceParameters.UseBindlessTextures
|| aNbTilesX != myRaytraceParameters.NbTilesX
|| aNbTilesY != myRaytraceParameters.NbTilesY)
|| myRaytraceGeometry.HasTextures() != myRaytraceParameters.UseBindlessTextures)
{
myRaytraceParameters.NbBounces = myRenderParams.RaytracingDepth;
myRaytraceParameters.TransparentShadows = myRenderParams.IsTransparentShadowEnabled;
myRaytraceParameters.GlobalIllumination = myRenderParams.IsGlobalIlluminationEnabled;
myRaytraceParameters.TwoSidedBsdfModels = myRenderParams.TwoSidedBsdfModels;
myRaytraceParameters.UseBindlessTextures = myRaytraceGeometry.HasTextures();
#ifdef RAY_TRACE_PRINT_INFO
if (aNbTilesX != myRaytraceParameters.NbTilesX
|| aNbTilesY != myRaytraceParameters.NbTilesY)
{
std::cout << "Number of tiles X: " << aNbTilesX << "\n";
std::cout << "Number of tiles Y: " << aNbTilesY << "\n";
}
#endif
myRaytraceParameters.NbTilesX = aNbTilesX;
myRaytraceParameters.NbTilesY = aNbTilesY;
aToRebuildShaders = Standard_True;
}
if (myRenderParams.AdaptiveScreenSampling != myRaytraceParameters.AdaptiveScreenSampling)
if (myRenderParams.AdaptiveScreenSampling != myRaytraceParameters.AdaptiveScreenSampling
|| myRenderParams.AdaptiveScreenSamplingAtomic != myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{
myRaytraceParameters.AdaptiveScreenSampling = myRenderParams.AdaptiveScreenSampling;
myRaytraceParameters.AdaptiveScreenSampling = myRenderParams.AdaptiveScreenSampling;
myRaytraceParameters.AdaptiveScreenSamplingAtomic = myRenderParams.AdaptiveScreenSamplingAtomic;
if (myRenderParams.AdaptiveScreenSampling) // adaptive sampling was requested
{
if (!theGlContext->HasRayTracingAdaptiveSampling())
@@ -1418,12 +1403,21 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
// disable the feature if it is not supported
myRaytraceParameters.AdaptiveScreenSampling = myRenderParams.AdaptiveScreenSampling = Standard_False;
theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_LOW,
"Adaptive sampling not supported (OpenGL 4.4 or GL_NV_shader_atomic_float is missing)");
"Adaptive sampling is not supported (OpenGL 4.4 is missing)");
}
else if (myRaytraceParameters.AdaptiveScreenSamplingAtomic
&& !theGlContext->HasRayTracingAdaptiveSamplingAtomic())
{
// disable the feature if it is not supported
myRaytraceParameters.AdaptiveScreenSamplingAtomic = myRenderParams.AdaptiveScreenSamplingAtomic = Standard_False;
theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_LOW,
"Atomic adaptive sampling is not supported (GL_NV_shader_atomic_float is missing)");
}
}
aToRebuildShaders = Standard_True;
}
myTileSampler.SetSize (myRenderParams, myRaytraceParameters.AdaptiveScreenSampling ? Graphic3d_Vec2i (theSizeX, theSizeY) : Graphic3d_Vec2i (0, 0));
const bool toEnableDof = !myCamera->IsOrthographic() && myRaytraceParameters.GlobalIllumination;
if (myRaytraceParameters.DepthOfField != toEnableDof)
@@ -1456,27 +1450,10 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
myPostFSAAShaderSource.SetPrefix (aPrefixString);
myOutImageShaderSource.SetPrefix (aPrefixString);
if (!myRaytraceShader->LoadSource (theGlContext, myRaytraceShaderSource.Source())
|| !myPostFSAAShader->LoadSource (theGlContext, myPostFSAAShaderSource.Source())
|| !myOutImageShader->LoadSource (theGlContext, myOutImageShaderSource.Source()))
if (!myRaytraceShader->LoadAndCompile (theGlContext, myRaytraceShaderSource.Source())
|| !myPostFSAAShader->LoadAndCompile (theGlContext, myPostFSAAShaderSource.Source())
|| !myOutImageShader->LoadAndCompile (theGlContext, myOutImageShaderSource.Source()))
{
return safeFailBack ("Failed to load source into ray-tracing fragment shaders", theGlContext);
}
TCollection_AsciiString aLog;
if (!myRaytraceShader->Compile (theGlContext)
|| !myPostFSAAShader->Compile (theGlContext)
|| !myOutImageShader->Compile (theGlContext))
{
#ifdef RAY_TRACE_PRINT_INFO
myRaytraceShader->FetchInfoLog (theGlContext, aLog);
if (!aLog.IsEmpty())
{
std::cout << "Failed to compile ray-tracing shader: " << aLog << "\n";
}
#endif
return safeFailBack ("Failed to compile ray-tracing fragment shaders", theGlContext);
}
@@ -1488,14 +1465,6 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
|| !myPostFSAAProgram->Link (theGlContext)
|| !myOutImageProgram->Link (theGlContext))
{
#ifdef RAY_TRACE_PRINT_INFO
myRaytraceProgram->FetchInfoLog (theGlContext, aLog);
if (!aLog.IsEmpty())
{
std::cout << "Failed to compile ray-tracing shader: " << aLog << "\n";
}
#endif
return safeFailBack ("Failed to initialize vertex attributes for ray-tracing program", theGlContext);
}
}
@@ -1771,8 +1740,14 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
myUniformLocations[anIndex][OpenGl_RT_uRenderImage] =
aShaderProgram->GetUniformLocation (theGlContext, "uRenderImage");
myUniformLocations[anIndex][OpenGl_RT_uTilesImage] =
aShaderProgram->GetUniformLocation (theGlContext, "uTilesImage");
myUniformLocations[anIndex][OpenGl_RT_uOffsetImage] =
aShaderProgram->GetUniformLocation (theGlContext, "uOffsetImage");
myUniformLocations[anIndex][OpenGl_RT_uTileSize] =
aShaderProgram->GetUniformLocation (theGlContext, "uTileSize");
myUniformLocations[anIndex][OpenGl_RT_uVarianceScaleFactor] =
aShaderProgram->GetUniformLocation (theGlContext, "uVarianceScaleFactor");
myUniformLocations[anIndex][OpenGl_RT_uBackColorTop] =
aShaderProgram->GetUniformLocation (theGlContext, "uBackColorTop");
@@ -1855,6 +1830,8 @@ void OpenGl_View::releaseRaytraceResources (const Handle(OpenGl_Context)& theGlC
nullifyResource (theGlContext, myRaytraceTileOffsetsTexture[1]);
nullifyResource (theGlContext, myRaytraceVisualErrorTexture[0]);
nullifyResource (theGlContext, myRaytraceVisualErrorTexture[1]);
nullifyResource (theGlContext, myRaytraceTileSamplesTexture[0]);
nullifyResource (theGlContext, myRaytraceTileSamplesTexture[1]);
nullifyResource (theGlContext, mySceneNodeInfoTexture);
nullifyResource (theGlContext, mySceneMinPointTexture);
@@ -1899,107 +1876,91 @@ Standard_Boolean OpenGl_View::updateRaytraceBuffers (const Standard_Integer
if (myRaytraceParameters.AdaptiveScreenSampling)
{
const Standard_Integer aSizeX = std::max (myRaytraceParameters.NbTilesX * 64, theSizeX);
const Standard_Integer aSizeY = std::max (myRaytraceParameters.NbTilesY * 64, theSizeY);
myRaytraceFBO1[0]->InitLazy (theGlContext, aSizeX, aSizeY, GL_RGBA32F, myFboDepthFormat);
myRaytraceFBO2[0]->InitLazy (theGlContext, aSizeX, aSizeY, GL_RGBA32F, myFboDepthFormat);
Graphic3d_Vec2i aMaxViewport = myTileSampler.OffsetTilesViewportMax().cwiseMax (Graphic3d_Vec2i (theSizeX, theSizeY));
myRaytraceFBO1[0]->InitLazy (theGlContext, aMaxViewport.x(), aMaxViewport.y(), GL_RGBA32F, myFboDepthFormat);
myRaytraceFBO2[0]->InitLazy (theGlContext, aMaxViewport.x(), aMaxViewport.y(), GL_RGBA32F, myFboDepthFormat);
if (myRaytraceFBO1[1]->IsValid()) // second FBO not needed
{
myRaytraceFBO1[1]->Release (theGlContext.operator->());
myRaytraceFBO2[1]->Release (theGlContext.operator->());
}
}
else // non-adaptive mode
for (int aViewIter = 0; aViewIter < 2; ++aViewIter)
{
if (myRaytraceFBO1[0]->GetSizeX() != theSizeX
|| myRaytraceFBO1[0]->GetSizeY() != theSizeY)
if (myRaytraceTileOffsetsTexture[aViewIter].IsNull())
{
myAccumFrames = 0; // accumulation should be restarted
myRaytraceOutputTexture[aViewIter] = new OpenGl_Texture();
myRaytraceVisualErrorTexture[aViewIter] = new OpenGl_Texture();
myRaytraceTileSamplesTexture[aViewIter] = new OpenGl_Texture();
myRaytraceTileOffsetsTexture[aViewIter] = new OpenGl_Texture();
}
myRaytraceFBO1[0]->InitLazy (theGlContext, theSizeX, theSizeY, GL_RGBA32F, myFboDepthFormat);
myRaytraceFBO2[0]->InitLazy (theGlContext, theSizeX, theSizeY, GL_RGBA32F, myFboDepthFormat);
// Init second set of buffers for stereographic rendering
if (myCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
{
myRaytraceFBO1[1]->InitLazy (theGlContext, theSizeX, theSizeY, GL_RGBA32F, myFboDepthFormat);
myRaytraceFBO2[1]->InitLazy (theGlContext, theSizeX, theSizeY, GL_RGBA32F, myFboDepthFormat);
}
else if (myRaytraceFBO1[1]->IsValid()) // second FBO not needed
if (aViewIter == 1
&& myCamera->ProjectionType() != Graphic3d_Camera::Projection_Stereo)
{
myRaytraceFBO1[1]->Release (theGlContext.operator->());
myRaytraceFBO2[1]->Release (theGlContext.operator->());
}
}
myTileSampler.SetSize (theSizeX, theSizeY);
if (myRaytraceTileOffsetsTexture[0].IsNull()
|| myRaytraceTileOffsetsTexture[1].IsNull())
{
myRaytraceOutputTexture[0] = new OpenGl_Texture();
myRaytraceOutputTexture[1] = new OpenGl_Texture();
myRaytraceTileOffsetsTexture[0] = new OpenGl_Texture();
myRaytraceTileOffsetsTexture[1] = new OpenGl_Texture();
myRaytraceVisualErrorTexture[0] = new OpenGl_Texture();
myRaytraceVisualErrorTexture[1] = new OpenGl_Texture();
}
if (myRaytraceOutputTexture[0]->SizeX() / 3 != theSizeX
|| myRaytraceOutputTexture[0]->SizeY() / 2 != theSizeY)
{
myAccumFrames = 0;
// Due to limitations of OpenGL image load-store extension
// atomic operations are supported only for single-channel
// images, so we define GL_R32F image. It is used as array
// of 6D floating point vectors:
// 0 - R color channel
// 1 - G color channel
// 2 - B color channel
// 3 - hit time transformed into OpenGL NDC space
// 4 - luminance accumulated for odd samples only
myRaytraceOutputTexture[0]->InitRectangle (theGlContext,
theSizeX * 3, theSizeY * 2, OpenGl_TextureFormat::Create<GLfloat, 1>());
// workaround for some NVIDIA drivers
myRaytraceVisualErrorTexture[0]->Release (theGlContext.operator->());
myRaytraceTileOffsetsTexture[0]->Release (theGlContext.operator->());
myRaytraceVisualErrorTexture[0]->Init (theGlContext,
GL_R32I, GL_RED_INTEGER, GL_INT, myTileSampler.NbTilesX(), myTileSampler.NbTilesY(), Graphic3d_TOT_2D);
myRaytraceTileOffsetsTexture[0]->Init (theGlContext,
GL_RG32I, GL_RG_INTEGER, GL_INT, myTileSampler.NbTilesX(), myTileSampler.NbTilesY(), Graphic3d_TOT_2D);
}
if (myCamera->ProjectionType() == Graphic3d_Camera::Projection_Stereo)
{
if (myRaytraceOutputTexture[1]->SizeX() / 3 != theSizeX
|| myRaytraceOutputTexture[1]->SizeY() / 2 != theSizeY)
{
myRaytraceOutputTexture[1]->InitRectangle (theGlContext,
theSizeX * 3, theSizeY * 2, OpenGl_TextureFormat::Create<GLfloat, 1>());
myRaytraceOutputTexture[1]->Release (theGlContext.operator->());
myRaytraceVisualErrorTexture[1]->Release (theGlContext.operator->());
myRaytraceTileOffsetsTexture[1]->Release (theGlContext.operator->());
continue;
}
myRaytraceVisualErrorTexture[1]->Init (theGlContext,
GL_R32I, GL_RED_INTEGER, GL_INT, myTileSampler.NbTilesX(), myTileSampler.NbTilesY(), Graphic3d_TOT_2D);
if (myRaytraceParameters.AdaptiveScreenSampling)
{
if (myRaytraceOutputTexture[aViewIter]->SizeX() / 3 == theSizeX
&& myRaytraceOutputTexture[aViewIter]->SizeY() / 2 == theSizeY
&& myRaytraceVisualErrorTexture[aViewIter]->SizeX() == myTileSampler.NbTilesX()
&& myRaytraceVisualErrorTexture[aViewIter]->SizeY() == myTileSampler.NbTilesY())
{
if (myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{
continue; // offsets texture is dynamically resized
}
else if (myRaytraceTileSamplesTexture[aViewIter]->SizeX() == myTileSampler.NbTilesX()
&& myRaytraceTileSamplesTexture[aViewIter]->SizeY() == myTileSampler.NbTilesY())
{
continue;
}
}
myRaytraceTileOffsetsTexture[1]->Init (theGlContext,
GL_RG32I, GL_RG_INTEGER, GL_INT, myTileSampler.NbTilesX(), myTileSampler.NbTilesY(), Graphic3d_TOT_2D);
myAccumFrames = 0;
// Due to limitations of OpenGL image load-store extension
// atomic operations are supported only for single-channel
// images, so we define GL_R32F image. It is used as array
// of 6D floating point vectors:
// 0 - R color channel
// 1 - G color channel
// 2 - B color channel
// 3 - hit time transformed into OpenGL NDC space
// 4 - luminance accumulated for odd samples only
myRaytraceOutputTexture[aViewIter]->InitRectangle (theGlContext, theSizeX * 3, theSizeY * 2, OpenGl_TextureFormat::Create<GLfloat, 1>());
// workaround for some NVIDIA drivers
myRaytraceVisualErrorTexture[aViewIter]->Release (theGlContext.operator->());
myRaytraceTileSamplesTexture[aViewIter]->Release (theGlContext.operator->());
myRaytraceVisualErrorTexture[aViewIter]->Init (theGlContext, GL_R32I, GL_RED_INTEGER, GL_INT,
myTileSampler.NbTilesX(), myTileSampler.NbTilesY(), Graphic3d_TOT_2D);
if (!myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{
myRaytraceTileSamplesTexture[aViewIter]->Init (theGlContext, GL_R32I, GL_RED_INTEGER, GL_INT,
myTileSampler.NbTilesX(), myTileSampler.NbTilesY(), Graphic3d_TOT_2D);
}
}
else // non-adaptive mode
{
if (myRaytraceFBO1[aViewIter]->GetSizeX() != theSizeX
|| myRaytraceFBO1[aViewIter]->GetSizeY() != theSizeY)
{
myAccumFrames = 0; // accumulation should be restarted
}
myRaytraceFBO1[aViewIter]->InitLazy (theGlContext, theSizeX, theSizeY, GL_RGBA32F, myFboDepthFormat);
myRaytraceFBO2[aViewIter]->InitLazy (theGlContext, theSizeX, theSizeY, GL_RGBA32F, myFboDepthFormat);
}
}
else
{
myRaytraceOutputTexture[1]->Release (theGlContext.operator->());
}
return Standard_True;
}
@@ -2679,7 +2640,7 @@ Standard_Boolean OpenGl_View::setUniformState (const Standard_Integer the
}
// Set background colors (only gradient background supported)
if (!myBgGradientArray.IsNull() && myBgGradientArray->IsDefined())
if (myBgGradientArray != NULL && myBgGradientArray->IsDefined())
{
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uBackColorTop], myBgGradientArray->GradientColor (0));
@@ -2745,25 +2706,30 @@ Standard_Boolean OpenGl_View::setUniformState (const Standard_Integer the
// function : bindRaytraceTextures
// purpose : Binds ray-trace textures to corresponding texture units
// =======================================================================
void OpenGl_View::bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext)
void OpenGl_View::bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext,
int theStereoView)
{
if (myRaytraceParameters.AdaptiveScreenSampling)
if (myRaytraceParameters.AdaptiveScreenSampling
&& myRaytraceParameters.GlobalIllumination)
{
#if !defined(GL_ES_VERSION_2_0)
theGlContext->core42->glBindImageTexture (OpenGl_RT_OutputImageLft,
myRaytraceOutputTexture[0]->TextureId(), 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32F);
theGlContext->core42->glBindImageTexture (OpenGl_RT_OutputImageRgh,
myRaytraceOutputTexture[1]->TextureId(), 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32F);
theGlContext->core42->glBindImageTexture (OpenGl_RT_VisualErrorImageLft,
myRaytraceVisualErrorTexture[0]->TextureId(), 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32I);
theGlContext->core42->glBindImageTexture (OpenGl_RT_VisualErrorImageRgh,
myRaytraceVisualErrorTexture[1]->TextureId(), 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32I);
theGlContext->core42->glBindImageTexture (OpenGl_RT_TileOffsetsImageLft,
myRaytraceTileOffsetsTexture[0]->TextureId(), 0, GL_TRUE, 0, GL_READ_ONLY, GL_RG32I);
theGlContext->core42->glBindImageTexture (OpenGl_RT_TileOffsetsImageRgh,
myRaytraceTileOffsetsTexture[1]->TextureId(), 0, GL_TRUE, 0, GL_READ_ONLY, GL_RG32I);
#endif
theGlContext->core42->glBindImageTexture (OpenGl_RT_OutputImage,
myRaytraceOutputTexture[theStereoView]->TextureId(), 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32F);
theGlContext->core42->glBindImageTexture (OpenGl_RT_VisualErrorImage,
myRaytraceVisualErrorTexture[theStereoView]->TextureId(), 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32I);
if (myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{
theGlContext->core42->glBindImageTexture (OpenGl_RT_TileOffsetsImage,
myRaytraceTileOffsetsTexture[theStereoView]->TextureId(), 0, GL_TRUE, 0, GL_READ_ONLY, GL_RG32I);
}
else
{
theGlContext->core42->glBindImageTexture (OpenGl_RT_TileSamplesImage,
myRaytraceTileSamplesTexture[theStereoView]->TextureId(), 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32I);
}
#else
(void )theStereoView;
#endif
}
if (!myTextureEnv.IsNull()
@@ -2825,7 +2791,8 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
if (myRaytraceParameters.GlobalIllumination) // path tracing
{
aResult &= runPathtrace (theSizeX, theSizeY, theProjection, theReadDrawFbo, theGlContext);
aResult &= runPathtrace (theSizeX, theSizeY, theProjection, theGlContext);
aResult &= runPathtraceOut (theProjection, theReadDrawFbo, theGlContext);
}
else // Whitted-style ray-tracing
{
@@ -2847,13 +2814,9 @@ Standard_Boolean OpenGl_View::runRaytrace (const Standard_Integer theSize
{
Standard_Boolean aResult = Standard_True;
bindRaytraceTextures (theGlContext);
Handle(OpenGl_FrameBuffer) aRenderImageFramebuffer;
Handle(OpenGl_FrameBuffer) aDepthSourceFramebuffer;
// Choose proper set of frame buffers for stereo rendering
const Standard_Integer aFBOIdx (theProjection == Graphic3d_Camera::Projection_MonoRightEye);
const Standard_Integer aFBOIdx = (theProjection == Graphic3d_Camera::Projection_MonoRightEye) ? 1 : 0;
bindRaytraceTextures (theGlContext, aFBOIdx);
if (myRenderParams.IsAntialiasingEnabled) // if second FSAA pass is used
{
@@ -2923,8 +2886,8 @@ Standard_Boolean OpenGl_View::runRaytrace (const Standard_Integer theSize
aFramebuffer->ColorTexture()->Bind (theGlContext, OpenGl_RT_FsaaInputTexture);
}
aRenderImageFramebuffer = myRaytraceFBO2[aFBOIdx];
aDepthSourceFramebuffer = myRaytraceFBO1[aFBOIdx];
const Handle(OpenGl_FrameBuffer)& aRenderImageFramebuffer = myRaytraceFBO2[aFBOIdx];
const Handle(OpenGl_FrameBuffer)& aDepthSourceFramebuffer = myRaytraceFBO1[aFBOIdx];
glEnable (GL_DEPTH_TEST);
@@ -2964,11 +2927,8 @@ Standard_Boolean OpenGl_View::runRaytrace (const Standard_Integer theSize
Standard_Boolean OpenGl_View::runPathtrace (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theReadDrawFbo,
const Handle(OpenGl_Context)& theGlContext)
{
Standard_Boolean aResult = Standard_True;
if (myToUpdateEnvironmentMap) // check whether the map was changed
{
myAccumFrames = myToUpdateEnvironmentMap = 0;
@@ -2977,15 +2937,13 @@ Standard_Boolean OpenGl_View::runPathtrace (const Standard_Integer
if (myRenderParams.CameraApertureRadius != myPrevCameraApertureRadius
|| myRenderParams.CameraFocalPlaneDist != myPrevCameraFocalPlaneDist)
{
myPrevCameraApertureRadius = myRenderParams.CameraApertureRadius;
myPrevCameraFocalPlaneDist = myRenderParams.CameraFocalPlaneDist;
myAccumFrames = 0;
}
// Choose proper set of frame buffers for stereo rendering
const Standard_Integer aFBOIdx (theProjection == Graphic3d_Camera::Projection_MonoRightEye);
const Standard_Integer aFBOIdx = (theProjection == Graphic3d_Camera::Projection_MonoRightEye) ? 1 : 0;
if (myRaytraceParameters.AdaptiveScreenSampling)
{
@@ -2994,106 +2952,120 @@ Standard_Boolean OpenGl_View::runPathtrace (const Standard_Integer
myTileSampler.Reset(); // reset tile sampler to its initial state
// Adaptive sampling is starting at the second frame
myTileSampler.Upload (theGlContext,
myRaytraceTileOffsetsTexture[aFBOIdx],
myRaytraceParameters.NbTilesX,
myRaytraceParameters.NbTilesY,
false);
}
}
if (myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{
myTileSampler.UploadOffsets (theGlContext, myRaytraceTileOffsetsTexture[aFBOIdx], false);
}
else
{
myTileSampler.UploadSamples (theGlContext, myRaytraceTileSamplesTexture[aFBOIdx], false);
}
bindRaytraceTextures (theGlContext);
Handle(OpenGl_FrameBuffer) aRenderImageFramebuffer;
Handle(OpenGl_FrameBuffer) aDepthSourceFramebuffer;
Handle(OpenGl_FrameBuffer) anAccumImageFramebuffer;
const Standard_Integer anImageId = (aFBOIdx != 0)
? OpenGl_RT_OutputImageRgh
: OpenGl_RT_OutputImageLft;
const Standard_Integer anErrorId = (aFBOIdx != 0)
? OpenGl_RT_VisualErrorImageRgh
: OpenGl_RT_VisualErrorImageLft;
const Standard_Integer anOffsetId = (aFBOIdx != 0)
? OpenGl_RT_TileOffsetsImageRgh
: OpenGl_RT_TileOffsetsImageLft;
aRenderImageFramebuffer = myAccumFrames % 2 ? myRaytraceFBO1[aFBOIdx] : myRaytraceFBO2[aFBOIdx];
anAccumImageFramebuffer = myAccumFrames % 2 ? myRaytraceFBO2[aFBOIdx] : myRaytraceFBO1[aFBOIdx];
aDepthSourceFramebuffer = aRenderImageFramebuffer;
anAccumImageFramebuffer->ColorTexture()->Bind (theGlContext, OpenGl_RT_PrevAccumTexture);
aRenderImageFramebuffer->BindBuffer (theGlContext);
if (myAccumFrames == 0)
{
myRNG.SetSeed(); // start RNG from beginning
}
// Clear adaptive screen sampling images
if (myRaytraceParameters.AdaptiveScreenSampling)
{
#if !defined(GL_ES_VERSION_2_0)
if (myAccumFrames == 0 || (myAccumFrames == 1 && myCamera->IsStereo()))
{
#if !defined(GL_ES_VERSION_2_0)
theGlContext->core44->glClearTexImage (myRaytraceOutputTexture[aFBOIdx]->TextureId(), 0, GL_RED, GL_FLOAT, NULL);
#endif
}
// Clear adaptive screen sampling images
#if !defined(GL_ES_VERSION_2_0)
theGlContext->core44->glClearTexImage (myRaytraceVisualErrorTexture[aFBOIdx]->TextureId(), 0, GL_RED_INTEGER, GL_INT, NULL);
#endif
}
// Set frame accumulation weight
myRaytraceProgram->SetUniform (theGlContext,
myUniformLocations[0][OpenGl_RT_uAccumSamples], myAccumFrames);
bindRaytraceTextures (theGlContext, aFBOIdx);
// Set random number generator seed
myRaytraceProgram->SetUniform (theGlContext,
myUniformLocations[0][OpenGl_RT_uFrameRndSeed], static_cast<Standard_Integer> (myRNG.NextInt() >> 2));
const Handle(OpenGl_FrameBuffer)& anAccumImageFramebuffer = myAccumFrames % 2 ? myRaytraceFBO2[aFBOIdx] : myRaytraceFBO1[aFBOIdx];
anAccumImageFramebuffer->ColorTexture()->Bind (theGlContext, OpenGl_RT_PrevAccumTexture);
// Set frame accumulation weight
myRaytraceProgram->SetUniform (theGlContext, myUniformLocations[0][OpenGl_RT_uAccumSamples], myAccumFrames);
// Set image uniforms for render program
myRaytraceProgram->SetUniform (theGlContext,
myUniformLocations[0][OpenGl_RT_uRenderImage], anImageId);
myRaytraceProgram->SetUniform (theGlContext,
myUniformLocations[0][OpenGl_RT_uOffsetImage], anOffsetId);
glDisable (GL_DEPTH_TEST);
if (myRaytraceParameters.AdaptiveScreenSampling
&& ((myAccumFrames > 0 && !myCamera->IsStereo()) || myAccumFrames > 1))
if (myRaytraceParameters.AdaptiveScreenSampling)
{
glViewport (0,
0,
myTileSampler.TileSize() * myRaytraceParameters.NbTilesX,
myTileSampler.TileSize() * myRaytraceParameters.NbTilesY);
myRaytraceProgram->SetUniform (theGlContext, myUniformLocations[0][OpenGl_RT_uRenderImage], OpenGl_RT_OutputImage);
myRaytraceProgram->SetUniform (theGlContext, myUniformLocations[0][OpenGl_RT_uTilesImage], OpenGl_RT_TileSamplesImage);
myRaytraceProgram->SetUniform (theGlContext, myUniformLocations[0][OpenGl_RT_uOffsetImage], OpenGl_RT_TileOffsetsImage);
myRaytraceProgram->SetUniform (theGlContext, myUniformLocations[0][OpenGl_RT_uTileSize], myTileSampler.TileSize());
}
const Handle(OpenGl_FrameBuffer)& aRenderImageFramebuffer = myAccumFrames % 2 ? myRaytraceFBO1[aFBOIdx] : myRaytraceFBO2[aFBOIdx];
aRenderImageFramebuffer->BindBuffer (theGlContext);
if (myRaytraceParameters.AdaptiveScreenSampling
&& myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{
// extend viewport here, so that tiles at boundaries (cut tile size by target rendering viewport)
// redirected to inner tiles (full tile size) are drawn entirely
const Graphic3d_Vec2i anOffsetViewport = myTileSampler.OffsetTilesViewport (myAccumFrames > 1); // shrunk offsets texture will be uploaded since 3rd frame
glViewport (0, 0, anOffsetViewport.x(), anOffsetViewport.y());
}
// Generate for the given RNG seed
theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
glDisable (GL_DEPTH_TEST);
// Adaptive Screen Sampling computes the same overall amount of samples per frame redraw as normal Path Tracing,
// but distributes them unequally across pixels (grouped in tiles), so that some pixels do not receive new samples at all.
//
// Offsets map (redirecting currently rendered tile to another tile) allows performing Adaptive Screen Sampling in single pass,
// but current implementation relies on atomic float operations (AdaptiveScreenSamplingAtomic) for this.
// So that when atomic floats are not supported by GPU, multi-pass rendering is used instead.
//
// Single-pass rendering is more optimal due to smaller amount of draw calls,
// memory synchronization barriers, discarding most of the fragments and bad parallelization in case of very small amount of tiles requiring more samples.
// However, atomic operations on float values still produces different result (close, but not bit exact) making non-regression testing not robust.
// It should be possible following single-pass rendering approach but using extra accumulation buffer and resolving pass as possible improvement.
const int aNbPasses = myRaytraceParameters.AdaptiveScreenSampling
&& !myRaytraceParameters.AdaptiveScreenSamplingAtomic
? myTileSampler.MaxTileSamples()
: 1;
if (myAccumFrames == 0)
{
myRNG.SetSeed(); // start RNG from beginning
}
for (int aPassIter = 0; aPassIter < aNbPasses; ++aPassIter)
{
myRaytraceProgram->SetUniform (theGlContext, myUniformLocations[0][OpenGl_RT_uFrameRndSeed], static_cast<Standard_Integer> (myRNG.NextInt() >> 2));
theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
if (myRaytraceParameters.AdaptiveScreenSampling)
{
#if !defined(GL_ES_VERSION_2_0)
theGlContext->core44->glMemoryBarrier (GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
#endif
}
}
aRenderImageFramebuffer->UnbindBuffer (theGlContext);
if (myRaytraceParameters.AdaptiveScreenSampling
&& ((myAccumFrames > 0 && !myCamera->IsStereo()) || myAccumFrames > 1))
&& myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{
glViewport (0,
0,
theSizeX,
theSizeY);
glViewport (0, 0, theSizeX, theSizeY);
}
return true;
}
// =======================================================================
// function : runPathtraceOut
// purpose :
// =======================================================================
Standard_Boolean OpenGl_View::runPathtraceOut (const Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theReadDrawFbo,
const Handle(OpenGl_Context)& theGlContext)
{
// Output accumulated path traced image
theGlContext->BindProgram (myOutImageProgram);
// Choose proper set of frame buffers for stereo rendering
const Standard_Integer aFBOIdx = (theProjection == Graphic3d_Camera::Projection_MonoRightEye) ? 1 : 0;
if (myRaytraceParameters.AdaptiveScreenSampling)
{
// Set uniforms for display program
myOutImageProgram->SetUniform (theGlContext, "uRenderImage", anImageId);
myOutImageProgram->SetUniform (theGlContext, "uRenderImage", OpenGl_RT_OutputImage);
myOutImageProgram->SetUniform (theGlContext, "uAccumFrames", myAccumFrames);
myOutImageProgram->SetUniform (theGlContext, "uVarianceImage", anErrorId);
myOutImageProgram->SetUniform (theGlContext, "uVarianceImage", OpenGl_RT_VisualErrorImage);
myOutImageProgram->SetUniform (theGlContext, "uDebugAdaptive", myRenderParams.ShowSamplingTiles ? 1 : 0);
myOutImageProgram->SetUniform (theGlContext, "uTileSize", myTileSampler.TileSize());
myOutImageProgram->SetUniform (theGlContext, "uVarianceScaleFactor", myTileSampler.VarianceScaleFactor());
}
if (myRaytraceParameters.GlobalIllumination)
@@ -3113,40 +3085,33 @@ Standard_Boolean OpenGl_View::runPathtrace (const Standard_Integer
{
theReadDrawFbo->BindBuffer (theGlContext);
}
else
{
aRenderImageFramebuffer->UnbindBuffer (theGlContext);
}
const Handle(OpenGl_FrameBuffer)& aRenderImageFramebuffer = myAccumFrames % 2 ? myRaytraceFBO1[aFBOIdx] : myRaytraceFBO2[aFBOIdx];
aRenderImageFramebuffer->ColorTexture()->Bind (theGlContext, OpenGl_RT_PrevAccumTexture);
glEnable (GL_DEPTH_TEST);
// Copy accumulated image with correct depth values
glEnable (GL_DEPTH_TEST);
theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
aRenderImageFramebuffer->ColorTexture()->Unbind (theGlContext, OpenGl_RT_PrevAccumTexture);
if (myRaytraceParameters.AdaptiveScreenSampling)
{
myRaytraceVisualErrorTexture[aFBOIdx]->Bind (theGlContext);
// Download visual error map from the GPU and build
// adjusted tile offsets for optimal image sampling
myTileSampler.GrabVarianceMap (theGlContext);
myTileSampler.Upload (theGlContext,
myRaytraceTileOffsetsTexture[aFBOIdx],
myRaytraceParameters.NbTilesX,
myRaytraceParameters.NbTilesY,
myAccumFrames > 0);
// Download visual error map from the GPU and build adjusted tile offsets for optimal image sampling
myTileSampler.GrabVarianceMap (theGlContext, myRaytraceVisualErrorTexture[aFBOIdx]);
if (myRaytraceParameters.AdaptiveScreenSamplingAtomic)
{
myTileSampler.UploadOffsets (theGlContext, myRaytraceTileOffsetsTexture[aFBOIdx], myAccumFrames != 0);
}
else
{
myTileSampler.UploadSamples (theGlContext, myRaytraceTileSamplesTexture[aFBOIdx], myAccumFrames != 0);
}
}
unbindRaytraceTextures (theGlContext);
theGlContext->BindProgram (NULL);
return aResult;
return true;
}
// =======================================================================
@@ -3159,7 +3124,7 @@ Standard_Boolean OpenGl_View::raytrace (const Standard_Integer theSizeX,
OpenGl_FrameBuffer* theReadDrawFbo,
const Handle(OpenGl_Context)& theGlContext)
{
if (!initRaytraceResources (theGlContext))
if (!initRaytraceResources (theSizeX, theSizeY, theGlContext))
{
return Standard_False;
}

View File

@@ -125,9 +125,7 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
{
aCtx->core11fwd->glDisable (GL_BLEND);
const Handle(OpenGl_AspectFace) anOldAspectFace = theWorkspace->AspectFace();
theWorkspace->SetAspectFace (myTextureParams);
const OpenGl_AspectFace* anOldAspectFace = theWorkspace->SetAspectFace (myTextureParams);
myBgTextureArray->Render (theWorkspace);
theWorkspace->SetAspectFace (anOldAspectFace);
}
@@ -169,6 +167,7 @@ void OpenGl_View::Redraw()
Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType();
Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
aCtx->FrameStats()->FrameStart (myWorkspace->View(), false);
aCtx->SetLineFeather (myRenderParams.LineFeather);
// release pending GL resources
aCtx->ReleaseDelayed();
@@ -181,10 +180,19 @@ void OpenGl_View::Redraw()
&& !aCtx->caps->buffersNoSwap
&& aFrameBuffer == NULL;
Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
const Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
const Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
const Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
const Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
if (aSizeX < 1
|| aSizeY < 1
|| aRendSizeX < 1
|| aRendSizeY < 1)
{
myBackBufferRestored = Standard_False;
myIsImmediateDrawn = Standard_False;
return;
}
// determine multisampling parameters
Standard_Integer aNbSamples = !myToDisableMSAA && aSizeX == aRendSizeX
@@ -871,7 +879,9 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
// ==================================
const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
aContext->SetSampleAlphaToCoverage (myRenderParams.ToEnableAlphaToCoverage);
aContext->SetAllowSampleAlphaToCoverage (myRenderParams.ToEnableAlphaToCoverage
&& theOutputFBO != NULL
&& theOutputFBO->NbSamples() != 0);
#if !defined(GL_ES_VERSION_2_0)
// Disable current clipping planes
@@ -1036,6 +1046,7 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
}
myWorkspace->ResetAppliedAspect();
aContext->SetAllowSampleAlphaToCoverage (false);
aContext->SetSampleAlphaToCoverage (false);
// reset FFP state for safety
@@ -1085,15 +1096,16 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
if (!toRenderGL)
{
toRenderGL = !initRaytraceResources (aCtx) ||
!updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx);
const Standard_Integer aSizeX = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeX() : myWindow->Width();
const Standard_Integer aSizeY = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeY() : myWindow->Height();
toRenderGL = !initRaytraceResources (aSizeX, aSizeY, aCtx)
|| !updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx);
toRenderGL |= !myIsRaytraceDataValid; // if no ray-trace data use OpenGL
if (!toRenderGL)
{
const Standard_Integer aSizeX = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeX() : myWindow->Width();
const Standard_Integer aSizeY = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeY() : myWindow->Height();
myOpenGlFBO ->InitLazy (aCtx, aSizeX, aSizeY, myFboColorFormat, myFboDepthFormat, 0);
if (theReadDrawFbo != NULL)
@@ -1163,7 +1175,7 @@ void OpenGl_View::renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace)
{
if (myToShowGradTrihedron)
{
myGraduatedTrihedron->Render (theWorkspace);
myGraduatedTrihedron.Render (theWorkspace);
}
}
@@ -1176,8 +1188,8 @@ void OpenGl_View::renderFrameStats()
if (myRenderParams.ToShowStats
&& myRenderParams.CollectedStats != Graphic3d_RenderingParams::PerfCounters_NONE)
{
myFrameStatsPrs->Update (myWorkspace);
myFrameStatsPrs->Render (myWorkspace);
myFrameStatsPrs.Update (myWorkspace);
myFrameStatsPrs.Render (myWorkspace);
}
}

View File

@@ -123,25 +123,16 @@ OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Wi
myNbSkippedTranspElems (0),
myRenderFilter (OpenGl_RenderFilter_Empty),
//
myAspectLineSet (&myDefaultAspectLine),
myAspectFaceSet (&myDefaultAspectFace),
myAspectMarkerSet (&myDefaultAspectMarker),
myAspectTextSet (&myDefaultAspectText),
//
ViewMatrix_applied (&myDefaultMatrix),
StructureMatrix_applied (&myDefaultMatrix),
myToAllowFaceCulling (false),
myModelViewMatrix (myDefaultMatrix)
{
myDefaultAspectLine = new OpenGl_AspectLine();
myDefaultAspectFace = new OpenGl_AspectFace();
myDefaultAspectMarker = new OpenGl_AspectMarker();
myDefaultAspectText = new OpenGl_AspectText();
myNoneCulling = new OpenGl_AspectFace();
myFrontCulling = new OpenGl_AspectFace();
myFontFaceAspect = new OpenGl_AspectFace();
myAspectLineSet = myDefaultAspectLine;
myAspectFaceSet = myDefaultAspectFace;
myAspectMarkerSet = myDefaultAspectMarker;
myAspectTextSet = myDefaultAspectText;
if (!myGlContext.IsNull() && myGlContext->MakeCurrent())
{
myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
@@ -164,16 +155,16 @@ OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Wi
#endif
}
myFontFaceAspect->Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Mask, 0.285f);
myFontFaceAspect->Aspect()->SetShadingModel (Graphic3d_TOSM_UNLIT);
myFontFaceAspect.Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Blend, 0.285f);
myFontFaceAspect.Aspect()->SetShadingModel (Graphic3d_TOSM_UNLIT);
myNoneCulling->Aspect()->SetSuppressBackFaces (false);
myNoneCulling->Aspect()->SetDrawEdges (false);
myNoneCulling->Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque);
myNoneCulling .Aspect()->SetSuppressBackFaces (false);
myNoneCulling .Aspect()->SetDrawEdges (false);
myNoneCulling .Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque);
myFrontCulling->Aspect()->SetSuppressBackFaces (true);
myFrontCulling->Aspect()->SetDrawEdges (false);
myFrontCulling->Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque);
myFrontCulling.Aspect()->SetSuppressBackFaces (true);
myFrontCulling.Aspect()->SetDrawEdges (false);
myFrontCulling.Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque);
}
// =======================================================================
@@ -202,6 +193,14 @@ Standard_Boolean OpenGl_Workspace::Activate()
{
myGlContext->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
}
#if !defined(GL_ES_VERSION_2_0)
// font GLSL program has embedded discard, while FFP needs alpha test
myFontFaceAspect.Aspect()->SetAlphaMode ((!myGlContext->caps->ffpEnable && myGlContext->core11 != NULL)
? Graphic3d_AlphaMode_Blend
: Graphic3d_AlphaMode_Mask,
0.285f);
#endif
return Standard_True;
}
@@ -215,12 +214,12 @@ void OpenGl_Workspace::ResetAppliedAspect()
myHighlightStyle.Nullify();
myToAllowFaceCulling = false;
myAspectLineSet = myDefaultAspectLine;
myAspectFaceSet = myDefaultAspectFace;
myAspectLineSet = &myDefaultAspectLine;
myAspectFaceSet = &myDefaultAspectFace;
myAspectFaceApplied.Nullify();
myAspectMarkerSet = myDefaultAspectMarker;
myAspectMarkerSet = &myDefaultAspectMarker;
myAspectMarkerApplied.Nullify();
myAspectTextSet = myDefaultAspectText;
myAspectTextSet = &myDefaultAspectText;
myGlContext->SetPolygonOffset (Graphic3d_PolygonOffset());
ApplyAspectLine();
@@ -228,8 +227,8 @@ void OpenGl_Workspace::ResetAppliedAspect()
ApplyAspectMarker();
ApplyAspectText();
myGlContext->SetTypeOfLine (myDefaultAspectLine->Aspect()->Type());
myGlContext->SetLineWidth (myDefaultAspectLine->Aspect()->Width());
myGlContext->SetTypeOfLine (myDefaultAspectLine.Aspect()->Type());
myGlContext->SetLineWidth (myDefaultAspectLine.Aspect()->Width());
}
// =======================================================================
@@ -238,9 +237,9 @@ void OpenGl_Workspace::ResetAppliedAspect()
// =======================================================================
Graphic3d_PolygonOffset OpenGl_Workspace::SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset)
{
Graphic3d_PolygonOffset aPrev = myDefaultAspectFace->Aspect()->PolygonOffset();
myDefaultAspectFace->Aspect()->SetPolygonOffset (theOffset);
if (myAspectFaceApplied == myDefaultAspectFace->Aspect()
Graphic3d_PolygonOffset aPrev = myDefaultAspectFace.Aspect()->PolygonOffset();
myDefaultAspectFace.Aspect()->SetPolygonOffset (theOffset);
if (myAspectFaceApplied == myDefaultAspectFace.Aspect()
|| myAspectFaceApplied.IsNull()
|| (myAspectFaceApplied->PolygonOffset().Mode & Aspect_POM_None) == Aspect_POM_None)
{
@@ -253,43 +252,51 @@ Graphic3d_PolygonOffset OpenGl_Workspace::SetDefaultPolygonOffset (const Graphic
// function : SetAspectLine
// purpose :
// =======================================================================
void OpenGl_Workspace::SetAspectLine (const Handle(OpenGl_AspectLine)& theAspect)
const OpenGl_AspectLine* OpenGl_Workspace::SetAspectLine (const OpenGl_AspectLine* theAspect)
{
const OpenGl_AspectLine* aPrevAspectLine = myAspectLineSet;
myAspectLineSet = theAspect;
return aPrevAspectLine;
}
// =======================================================================
// function : SetAspectFace
// purpose :
// =======================================================================
void OpenGl_Workspace::SetAspectFace (const Handle(OpenGl_AspectFace)& theAspect)
const OpenGl_AspectFace * OpenGl_Workspace::SetAspectFace (const OpenGl_AspectFace* theAspect)
{
const OpenGl_AspectFace* aPrevAspectFace = myAspectFaceSet;
myAspectFaceSet = theAspect;
return aPrevAspectFace;
}
// =======================================================================
// function : SetAspectMarker
// purpose :
// =======================================================================
void OpenGl_Workspace::SetAspectMarker (const Handle(OpenGl_AspectMarker)& theAspect)
const OpenGl_AspectMarker* OpenGl_Workspace::SetAspectMarker (const OpenGl_AspectMarker* theAspect)
{
const OpenGl_AspectMarker* aPrevAspectMarker = myAspectMarkerSet;
myAspectMarkerSet = theAspect;
return aPrevAspectMarker;
}
// =======================================================================
// function : SetAspectText
// purpose :
// =======================================================================
void OpenGl_Workspace::SetAspectText (const Handle(OpenGl_AspectText)& theAspect)
const OpenGl_AspectText * OpenGl_Workspace::SetAspectText (const OpenGl_AspectText* theAspect)
{
const OpenGl_AspectText* aPrevAspectText = myAspectTextSet;
myAspectTextSet = theAspect;
return aPrevAspectText;
}
// =======================================================================
// function : ApplyAspectFace
// purpose :
// =======================================================================
const Handle(OpenGl_AspectFace)& OpenGl_Workspace::ApplyAspectFace()
const OpenGl_AspectFace* OpenGl_Workspace::ApplyAspectFace()
{
if (myView->BackfacingModel() == Graphic3d_TOBM_AUTOMATIC)
{
@@ -317,60 +324,38 @@ const Handle(OpenGl_AspectFace)& OpenGl_Workspace::ApplyAspectFace()
}
myAspectFaceAppliedWithHL = myHighlightStyle;
#if !defined(GL_ES_VERSION_2_0)
const Aspect_InteriorStyle anIntstyle = myAspectFaceSet->Aspect()->InteriorStyle();
if (myAspectFaceApplied.IsNull()
|| myAspectFaceApplied->InteriorStyle() != anIntstyle)
{
switch (anIntstyle)
{
case Aspect_IS_EMPTY:
case Aspect_IS_HOLLOW:
{
myGlContext->SetPolygonMode (GL_LINE);
break;
}
case Aspect_IS_HATCH:
{
myGlContext->SetPolygonMode (GL_FILL);
myGlContext->SetPolygonHatchEnabled (true);
break;
}
case Aspect_IS_SOLID:
case Aspect_IS_HIDDENLINE:
{
myGlContext->SetPolygonMode (GL_FILL);
myGlContext->SetPolygonHatchEnabled (false);
break;
}
case Aspect_IS_POINT:
{
myGlContext->SetPolygonMode (GL_POINT);
break;
}
}
}
if (anIntstyle == Aspect_IS_HATCH)
{
myGlContext->SetPolygonHatchStyle (myAspectFaceSet->Aspect()->HatchStyle());
}
#endif
// Aspect_POM_None means: do not change current settings
if ((myAspectFaceSet->Aspect()->PolygonOffset().Mode & Aspect_POM_None) != Aspect_POM_None)
{
myGlContext->SetPolygonOffset (myAspectFaceSet->Aspect()->PolygonOffset());
}
const Aspect_InteriorStyle anIntstyle = myAspectFaceSet->Aspect()->InteriorStyle();
if (myAspectFaceApplied.IsNull()
|| myAspectFaceApplied->InteriorStyle() != anIntstyle)
{
#if !defined(GL_ES_VERSION_2_0)
myGlContext->SetPolygonMode (anIntstyle == Aspect_IS_POINT ? GL_POINT : GL_FILL);
myGlContext->SetPolygonHatchEnabled (anIntstyle == Aspect_IS_HATCH);
#endif
}
#if !defined(GL_ES_VERSION_2_0)
if (anIntstyle == Aspect_IS_HATCH)
{
myGlContext->SetPolygonHatchStyle (myAspectFaceSet->Aspect()->HatchStyle());
}
#endif
// Case of hidden line
if (myAspectFaceSet->Aspect()->InteriorStyle() == Aspect_IS_HIDDENLINE)
if (anIntstyle == Aspect_IS_HIDDENLINE)
{
// copy all values including line edge aspect
*myAspectFaceHl.Aspect() = *myAspectFaceSet->Aspect();
myAspectFaceHl.SetAspectEdge (myAspectFaceSet->AspectEdge());
myAspectFaceHl.Aspect()->SetShadingModel (Graphic3d_TOSM_UNLIT);
myAspectFaceHl.Aspect()->SetInteriorColor (myView->BackgroundColor().GetRGB());
myAspectFaceHl.Aspect()->SetDistinguish (false);
myAspectFaceHl.SetNoLighting();
myAspectFaceSet = &myAspectFaceHl;
}
@@ -396,7 +381,7 @@ const Handle(OpenGl_AspectFace)& OpenGl_Workspace::ApplyAspectFace()
// function : ApplyAspectMarker
// purpose :
// =======================================================================
const Handle(OpenGl_AspectMarker)& OpenGl_Workspace::ApplyAspectMarker()
const OpenGl_AspectMarker* OpenGl_Workspace::ApplyAspectMarker()
{
if (myAspectMarkerSet->Aspect() != myAspectMarkerApplied)
{
@@ -487,7 +472,7 @@ Standard_Boolean OpenGl_Workspace::BufferDump (const Handle(OpenGl_FrameBuffer)&
// function : ShouldRender
// purpose :
// =======================================================================
bool OpenGl_Workspace::ShouldRender (const Handle(OpenGl_Element)& theElement)
bool OpenGl_Workspace::ShouldRender (const OpenGl_Element* theElement)
{
// render only non-raytracable elements when RayTracing is enabled
if ((myRenderFilter & OpenGl_RenderFilter_NonRaytraceableOnly) != 0)
@@ -523,7 +508,7 @@ bool OpenGl_Workspace::ShouldRender (const Handle(OpenGl_Element)& theElement)
{
if (!theElement->IsFillDrawMode())
{
if (Handle(OpenGl_AspectFace)::DownCast(theElement).IsNull())
if (dynamic_cast<const OpenGl_AspectFace*> (theElement) == NULL)
{
return false;
}

View File

@@ -83,9 +83,6 @@ public:
//! @return true if depth writing is enabled.
Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; }
//! @return true if frustum culling algorithm is enabled
Standard_EXPORT Standard_Boolean IsCullingEnabled() const;
//! Configure default polygon offset parameters.
//! Return previous settings.
Standard_EXPORT Graphic3d_PolygonOffset SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset);
@@ -163,44 +160,44 @@ public:
}
//! Currently set line aspect (can differ from applied).
const Handle(OpenGl_AspectLine)& AspectLine() const { return myAspectLineSet; }
const OpenGl_AspectLine* AspectLine() const { return myAspectLineSet; }
//! Currently set face aspect (can differ from applied).
const Handle(OpenGl_AspectFace)& AspectFace() const { return myAspectFaceSet; }
const OpenGl_AspectFace* AspectFace() const { return myAspectFaceSet; }
//! Currently set marker aspect (can differ from applied).
const Handle(OpenGl_AspectMarker)& AspectMarker() const { return myAspectMarkerSet; }
const OpenGl_AspectMarker* AspectMarker() const { return myAspectMarkerSet; }
//! Currently set text aspect (can differ from applied).
const Handle(OpenGl_AspectText)& AspectText() const { return myAspectTextSet; }
const OpenGl_AspectText* AspectText() const { return myAspectTextSet; }
//! Assign new line aspect (will be applied within ApplyAspectLine()).
Standard_EXPORT void SetAspectLine (const Handle(OpenGl_AspectLine)& theAspect);
Standard_EXPORT const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
//! Assign new face aspect (will be applied within ApplyAspectFace()).
Standard_EXPORT void SetAspectFace (const Handle(OpenGl_AspectFace)& theAspect);
Standard_EXPORT const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
//! Assign new marker aspect (will be applied within ApplyAspectMarker()).
Standard_EXPORT void SetAspectMarker (const Handle(OpenGl_AspectMarker)& theAspect);
Standard_EXPORT const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
//! Assign new text aspect (will be applied within ApplyAspectText()).
Standard_EXPORT void SetAspectText (const Handle(OpenGl_AspectText)& theAspect);
Standard_EXPORT const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
//! Apply line aspect.
//! @return aspect set by SetAspectLine()
const Handle(OpenGl_AspectLine)& ApplyAspectLine() { return myAspectLineSet; }
const OpenGl_AspectLine* ApplyAspectLine() { return myAspectLineSet; }
//! Apply face aspect.
//! @return aspect set by SetAspectFace()
Standard_EXPORT const Handle(OpenGl_AspectFace)& ApplyAspectFace();
Standard_EXPORT const OpenGl_AspectFace* ApplyAspectFace();
//! Apply marker aspect.
//! @return aspect set by SetAspectMarker()
Standard_EXPORT const Handle(OpenGl_AspectMarker)& ApplyAspectMarker();
Standard_EXPORT const OpenGl_AspectMarker* ApplyAspectMarker();
//! Apply text aspect.
//! @return aspect set by SetAspectText()
const Handle(OpenGl_AspectText)& ApplyAspectText() { return myAspectTextSet; }
const OpenGl_AspectText* ApplyAspectText() { return myAspectTextSet; }
//! Clear the applied aspect state to default values.
void ResetAppliedAspect();
@@ -216,7 +213,7 @@ public:
//! Checks whether the element can be rendered or not.
//! @param theElement [in] the element to check
//! @return True if element can be rendered
bool ShouldRender (const Handle(OpenGl_Element)& theElement);
bool ShouldRender (const OpenGl_Element* theElement);
//! Return the number of skipped transparent elements within active OpenGl_RenderFilter_OpaqueOnly filter.
//! @sa OpenGl_LayerList::Render()
@@ -233,13 +230,13 @@ public:
inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
//! Returns face aspect for textured font rendering.
const Handle(OpenGl_AspectFace)& FontFaceAspect() const { return myFontFaceAspect; }
const OpenGl_AspectFace& FontFaceAspect() const { return myFontFaceAspect; }
//! Returns face aspect for none culling mode.
const Handle(OpenGl_AspectFace)& NoneCulling() const { return myNoneCulling; }
const OpenGl_AspectFace& NoneCulling() const { return myNoneCulling; }
//! Returns face aspect for front face culling mode.
const Handle(OpenGl_AspectFace)& FrontCulling() const { return myFrontCulling; }
const OpenGl_AspectFace& FrontCulling() const { return myFrontCulling; }
//! Sets a new environment texture.
void SetEnvironmentTexture (const Handle(OpenGl_TextureSet)& theTexture) { myEnvironmentTexture = theTexture; }
@@ -254,26 +251,26 @@ protected: //! @name protected fields
Handle(OpenGl_Context) myGlContext;
Standard_Boolean myUseZBuffer;
Standard_Boolean myUseDepthWrite;
Handle(OpenGl_AspectFace) myNoneCulling;
Handle(OpenGl_AspectFace) myFrontCulling;
Handle(OpenGl_AspectFace) myFontFaceAspect;
OpenGl_AspectFace myNoneCulling;
OpenGl_AspectFace myFrontCulling;
OpenGl_AspectFace myFontFaceAspect;
protected: //! @name fields related to status
Standard_Integer myNbSkippedTranspElems; //!< counter of skipped transparent elements for OpenGl_LayerList two rendering passes method
Standard_Integer myRenderFilter; //!< active filter for skipping rendering of elements by some criteria (multiple render passes)
Handle(OpenGl_AspectLine) myDefaultAspectLine;
Handle(OpenGl_AspectFace) myDefaultAspectFace;
Handle(OpenGl_AspectMarker) myDefaultAspectMarker;
Handle(OpenGl_AspectText) myDefaultAspectText;
OpenGl_AspectLine myDefaultAspectLine;
OpenGl_AspectFace myDefaultAspectFace;
OpenGl_AspectMarker myDefaultAspectMarker;
OpenGl_AspectText myDefaultAspectText;
Handle(OpenGl_AspectLine) myAspectLineSet;
Handle(OpenGl_AspectFace) myAspectFaceSet;
const OpenGl_AspectLine* myAspectLineSet;
const OpenGl_AspectFace* myAspectFaceSet;
Handle(Graphic3d_AspectFillArea3d) myAspectFaceApplied;
Handle(OpenGl_AspectMarker) myAspectMarkerSet;
const OpenGl_AspectMarker* myAspectMarkerSet;
Handle(Graphic3d_AspectMarker3d) myAspectMarkerApplied;
Handle(OpenGl_AspectText) myAspectTextSet;
const OpenGl_AspectText* myAspectTextSet;
Handle(Graphic3d_PresentationAttributes) myAspectFaceAppliedWithHL;
const OpenGl_Matrix* ViewMatrix_applied;

View File

@@ -29,6 +29,19 @@
IMPLEMENT_STANDARD_RTTIEXT(Prs3d_Drawer, Graphic3d_PresentationAttributes)
namespace
{
static const Quantity_NameOfColor THE_DEF_COLOR_FreeBoundary = Quantity_NOC_GREEN;
static const Quantity_NameOfColor THE_DEF_COLOR_UnFreeBoundary = Quantity_NOC_YELLOW;
static const Quantity_NameOfColor THE_DEF_COLOR_FaceBoundary = Quantity_NOC_BLACK;
static const Quantity_NameOfColor THE_DEF_COLOR_Wire = Quantity_NOC_RED;
static const Quantity_NameOfColor THE_DEF_COLOR_Line = Quantity_NOC_YELLOW;
static const Quantity_NameOfColor THE_DEF_COLOR_SeenLine = Quantity_NOC_YELLOW;
static const Quantity_NameOfColor THE_DEF_COLOR_HiddenLine = Quantity_NOC_YELLOW;
static const Quantity_NameOfColor THE_DEF_COLOR_Vector = Quantity_NOC_SKYBLUE;
static const Quantity_NameOfColor THE_DEF_COLOR_Section = Quantity_NOC_ORANGE;
}
// =======================================================================
// function : Prs3d_Drawer
// purpose :
@@ -270,7 +283,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::FreeBoundaryAspect()
}
if (myFreeBoundaryAspect.IsNull())
{
myFreeBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_GREEN, Aspect_TOL_SOLID, 1.0);
myFreeBoundaryAspect = new Prs3d_LineAspect (THE_DEF_COLOR_FreeBoundary, Aspect_TOL_SOLID, 1.0);
}
}
return myFreeBoundaryAspect;
@@ -313,7 +326,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::UnFreeBoundaryAspect()
}
if (myUnFreeBoundaryAspect.IsNull())
{
myUnFreeBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_YELLOW, Aspect_TOL_SOLID, 1.0);
myUnFreeBoundaryAspect = new Prs3d_LineAspect (THE_DEF_COLOR_UnFreeBoundary, Aspect_TOL_SOLID, 1.0);
}
}
return myUnFreeBoundaryAspect;
@@ -356,7 +369,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::FaceBoundaryAspect()
}
if (myFaceBoundaryAspect.IsNull())
{
myFaceBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0);
myFaceBoundaryAspect = new Prs3d_LineAspect (THE_DEF_COLOR_FaceBoundary, Aspect_TOL_SOLID, 1.0);
}
}
return myFaceBoundaryAspect;
@@ -539,7 +552,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::WireAspect()
}
if (myWireAspect.IsNull())
{
myWireAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
myWireAspect = new Prs3d_LineAspect (THE_DEF_COLOR_Wire, Aspect_TOL_SOLID, 1.0);
}
}
return myWireAspect;
@@ -588,6 +601,30 @@ const Handle(Prs3d_PointAspect)& Prs3d_Drawer::PointAspect()
return myPointAspect;
}
// =======================================================================
// function : SetupOwnPointAspect
// purpose :
// =======================================================================
Standard_Boolean Prs3d_Drawer::SetupOwnPointAspect (const Handle(Prs3d_Drawer)& theDefaults)
{
if (myHasOwnPointAspect)
{
return Standard_False;
}
myPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
if (!theDefaults.IsNull() && theDefaults != this)
{
*myPointAspect->Aspect() = *theDefaults->PointAspect()->Aspect();
}
else if (!myLink.IsNull())
{
*myPointAspect->Aspect() = *myLink->PointAspect()->Aspect();
}
myHasOwnPointAspect = Standard_True;
return Standard_True;
}
// =======================================================================
// function : SetPointAspect
// purpose :
@@ -614,7 +651,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::LineAspect()
}
if (myLineAspect.IsNull())
{
myLineAspect = new Prs3d_LineAspect (Quantity_NOC_YELLOW, Aspect_TOL_SOLID, 1.0);
myLineAspect = new Prs3d_LineAspect (THE_DEF_COLOR_Line, Aspect_TOL_SOLID, 1.0);
}
}
return myLineAspect;
@@ -684,6 +721,30 @@ const Handle(Prs3d_ShadingAspect)& Prs3d_Drawer::ShadingAspect()
return myShadingAspect;
}
// =======================================================================
// function : SetupOwnShadingAspect
// purpose :
// =======================================================================
Standard_Boolean Prs3d_Drawer::SetupOwnShadingAspect (const Handle(Prs3d_Drawer)& theDefaults)
{
if (myHasOwnShadingAspect)
{
return Standard_False;
}
myShadingAspect = new Prs3d_ShadingAspect();
if (!theDefaults.IsNull() && theDefaults != this)
{
*myShadingAspect->Aspect() = *theDefaults->ShadingAspect()->Aspect();
}
else if (!myLink.IsNull())
{
*myShadingAspect->Aspect() = *myLink->ShadingAspect()->Aspect();
}
myHasOwnShadingAspect = Standard_True;
return Standard_True;
}
// =======================================================================
// function : SetShadingAspect
// purpose :
@@ -742,7 +803,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::SeenLineAspect()
}
if (mySeenLineAspect.IsNull())
{
mySeenLineAspect = new Prs3d_LineAspect (Quantity_NOC_YELLOW, Aspect_TOL_SOLID, 1.0);
mySeenLineAspect = new Prs3d_LineAspect (THE_DEF_COLOR_SeenLine, Aspect_TOL_SOLID, 1.0);
}
}
return mySeenLineAspect;
@@ -817,7 +878,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::HiddenLineAspect()
}
if (myHiddenLineAspect.IsNull())
{
myHiddenLineAspect = new Prs3d_LineAspect (Quantity_NOC_YELLOW, Aspect_TOL_DASH, 1.0);
myHiddenLineAspect = new Prs3d_LineAspect (THE_DEF_COLOR_HiddenLine, Aspect_TOL_DASH, 1.0);
}
}
return myHiddenLineAspect;
@@ -871,7 +932,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::VectorAspect()
}
if (myVectorAspect.IsNull())
{
myVectorAspect = new Prs3d_LineAspect (Quantity_NOC_SKYBLUE, Aspect_TOL_SOLID, 1.0);
myVectorAspect = new Prs3d_LineAspect (THE_DEF_COLOR_Vector, Aspect_TOL_SOLID, 1.0);
}
}
return myVectorAspect;
@@ -966,7 +1027,7 @@ const Handle(Prs3d_LineAspect)& Prs3d_Drawer::SectionAspect()
}
if (mySectionAspect.IsNull())
{
mySectionAspect = new Prs3d_LineAspect (Quantity_NOC_ORANGE, Aspect_TOL_SOLID, 1.0);
mySectionAspect = new Prs3d_LineAspect (THE_DEF_COLOR_Section, Aspect_TOL_SOLID, 1.0);
}
}
return mySectionAspect;
@@ -1059,17 +1120,156 @@ void Prs3d_Drawer::ClearLocalAttributes()
myTypeOfHLR = Prs3d_TOH_NotSet;
}
//! Copy line aspect defaults from the Link.
inline void copyLineAspect (const Handle(Prs3d_Drawer)& theLink,
Handle(Prs3d_LineAspect)& theAspect,
const Handle(Prs3d_LineAspect)& theBaseAspect)
// =======================================================================
// function : SetOwnLineAspects
// purpose :
// =======================================================================
Standard_Boolean Prs3d_Drawer::SetOwnLineAspects (const Handle(Prs3d_Drawer)& theDefaults)
{
Handle(Prs3d_LineAspect) aBaseAspect = theBaseAspect;
if (!theLink.IsNull())
bool isUpdateNeeded = false;
const Handle(Prs3d_Drawer)& aLink = (!theDefaults.IsNull() && theDefaults != this) ? theDefaults : myLink;
if (!myHasOwnUIsoAspect)
{
theAspect = new Prs3d_LineAspect (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0);
*theAspect->Aspect() = *aBaseAspect->Aspect();
isUpdateNeeded = true;
myUIsoAspect = new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 1.0, 1);
if (!aLink.IsNull())
{
*myUIsoAspect->Aspect() = *aLink->UIsoAspect()->Aspect();
myUIsoAspect->SetNumber (aLink->UIsoAspect()->Number());
}
myHasOwnUIsoAspect = true;
}
if (!myHasOwnVIsoAspect)
{
isUpdateNeeded = true;
myVIsoAspect = new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 1.0, 1);
if (!aLink.IsNull())
{
*myVIsoAspect->Aspect() = *aLink->VIsoAspect()->Aspect();
myUIsoAspect->SetNumber (aLink->VIsoAspect()->Number());
}
myHasOwnVIsoAspect = true;
}
if (!myHasOwnWireAspect)
{
isUpdateNeeded = true;
myWireAspect = new Prs3d_LineAspect (THE_DEF_COLOR_Wire, Aspect_TOL_SOLID, 1.0);
myHasOwnWireAspect = true;
if (!aLink.IsNull())
{
*myWireAspect->Aspect() = *aLink->WireAspect()->Aspect();
}
}
if (!myHasOwnLineAspect)
{
isUpdateNeeded = true;
myLineAspect = new Prs3d_LineAspect (THE_DEF_COLOR_Line, Aspect_TOL_SOLID, 1.0);
myHasOwnLineAspect = true;
if (!aLink.IsNull())
{
*myLineAspect->Aspect() = *aLink->LineAspect()->Aspect();
}
}
if (!myHasOwnSeenLineAspect)
{
isUpdateNeeded = true;
mySeenLineAspect = new Prs3d_LineAspect (THE_DEF_COLOR_SeenLine, Aspect_TOL_SOLID, 1.0);
myHasOwnSeenLineAspect = true;
if (!aLink.IsNull())
{
*mySeenLineAspect->Aspect() = *aLink->SeenLineAspect()->Aspect();
}
}
if (!myHasOwnHiddenLineAspect)
{
isUpdateNeeded = true;
myHiddenLineAspect = new Prs3d_LineAspect (THE_DEF_COLOR_HiddenLine, Aspect_TOL_DASH, 1.0);
myHasOwnHiddenLineAspect = true;
if (!aLink.IsNull())
{
*myHiddenLineAspect->Aspect() = *aLink->HiddenLineAspect()->Aspect();
}
}
if (!myHasOwnFreeBoundaryAspect)
{
isUpdateNeeded = true;
myFreeBoundaryAspect = new Prs3d_LineAspect (THE_DEF_COLOR_FreeBoundary, Aspect_TOL_SOLID, 1.0);
myHasOwnFreeBoundaryAspect = true;
if (!aLink.IsNull())
{
*myFreeBoundaryAspect->Aspect() = *aLink->FreeBoundaryAspect()->Aspect();
}
}
if (!myHasOwnUnFreeBoundaryAspect)
{
isUpdateNeeded = true;
myUnFreeBoundaryAspect = new Prs3d_LineAspect (THE_DEF_COLOR_UnFreeBoundary, Aspect_TOL_SOLID, 1.0);
myHasOwnUnFreeBoundaryAspect = true;
if (!aLink.IsNull())
{
*myUnFreeBoundaryAspect->Aspect() = *aLink->UnFreeBoundaryAspect()->Aspect();
}
}
if (!myHasOwnFaceBoundaryAspect)
{
isUpdateNeeded = true;
myFaceBoundaryAspect = new Prs3d_LineAspect (THE_DEF_COLOR_FaceBoundary, Aspect_TOL_SOLID, 1.0);
myHasOwnFaceBoundaryAspect = true;
if (!aLink.IsNull())
{
*myFaceBoundaryAspect->Aspect() = *aLink->FaceBoundaryAspect()->Aspect();
}
}
return isUpdateNeeded;
}
// =======================================================================
// function : SetOwnDatumAspects
// purpose :
// =======================================================================
Standard_Boolean Prs3d_Drawer::SetOwnDatumAspects (const Handle(Prs3d_Drawer)& theDefaults)
{
bool isUpdateNeeded = false;
const Handle(Prs3d_Drawer)& aLink = (!theDefaults.IsNull() && theDefaults != this) ? theDefaults : myLink;
if (!myHasOwnVectorAspect)
{
isUpdateNeeded = true;
myVectorAspect = new Prs3d_LineAspect (THE_DEF_COLOR_Vector, Aspect_TOL_SOLID, 1.0);
myHasOwnVectorAspect = true;
if (!aLink.IsNull())
{
*myVectorAspect->Aspect() = *aLink->VectorAspect()->Aspect();
}
}
if (!myHasOwnSectionAspect)
{
isUpdateNeeded = true;
mySectionAspect = new Prs3d_LineAspect (THE_DEF_COLOR_Section, Aspect_TOL_SOLID, 1.0);
myHasOwnSectionAspect = true;
if (!aLink.IsNull())
{
*mySectionAspect->Aspect() = *aLink->SectionAspect()->Aspect();
}
}
if (!myHasOwnPlaneAspect)
{
isUpdateNeeded = true;
myPlaneAspect = new Prs3d_PlaneAspect();
myHasOwnPlaneAspect = true;
}
if (!myHasOwnArrowAspect)
{
isUpdateNeeded = true;
myArrowAspect = new Prs3d_ArrowAspect();
myHasOwnArrowAspect = true;
}
if (!myHasOwnDatumAspect)
{
isUpdateNeeded = true;
myDatumAspect = new Prs3d_DatumAspect();
myHasOwnDatumAspect = true;
}
return isUpdateNeeded;
}
//! Assign the shader program.
@@ -1100,103 +1300,8 @@ bool Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP
{
if (theToOverrideDefaults)
{
if (!myHasOwnUIsoAspect)
{
isUpdateNeeded = true;
Handle(Prs3d_IsoAspect) anAspect = UIsoAspect();
if (!myLink.IsNull())
{
myUIsoAspect = new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 1.0, 1);
*myUIsoAspect->Aspect() = *anAspect->Aspect();
myUIsoAspect->SetNumber (anAspect->Number());
}
myHasOwnUIsoAspect = true;
}
if (!myHasOwnVIsoAspect)
{
isUpdateNeeded = true;
Handle(Prs3d_IsoAspect) anAspect = VIsoAspect();
if (!myLink.IsNull())
{
myVIsoAspect = new Prs3d_IsoAspect (Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 1.0, 1);
*myVIsoAspect->Aspect() = *anAspect->Aspect();
myUIsoAspect->SetNumber (anAspect->Number());
}
myHasOwnVIsoAspect = true;
}
if (!myHasOwnWireAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, myWireAspect, WireAspect());
myHasOwnWireAspect = true;
}
if (!myHasOwnLineAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, myLineAspect, LineAspect());
myHasOwnLineAspect = true;
}
if (!myHasOwnSeenLineAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, mySeenLineAspect, SeenLineAspect());
myHasOwnSeenLineAspect = true;
}
if (!myHasOwnHiddenLineAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, myHiddenLineAspect, HiddenLineAspect());
myHasOwnHiddenLineAspect = true;
}
if (!myHasOwnVectorAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, myVectorAspect, VectorAspect());
myHasOwnVectorAspect = true;
}
if (!myHasOwnSectionAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, mySectionAspect, SectionAspect());
myHasOwnSectionAspect = true;
}
if (!myHasOwnFreeBoundaryAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, myFreeBoundaryAspect, FreeBoundaryAspect());
myHasOwnFreeBoundaryAspect = true;
}
if (!myHasOwnUnFreeBoundaryAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, myUnFreeBoundaryAspect, UnFreeBoundaryAspect());
myHasOwnUnFreeBoundaryAspect = true;
}
if (!myHasOwnFaceBoundaryAspect)
{
isUpdateNeeded = true;
copyLineAspect (myLink, myFaceBoundaryAspect, FaceBoundaryAspect());
myHasOwnFaceBoundaryAspect = true;
}
if (!myHasOwnPlaneAspect)
{
isUpdateNeeded = true;
myPlaneAspect = new Prs3d_PlaneAspect();
myHasOwnPlaneAspect = true;
}
if (!myHasOwnArrowAspect)
{
isUpdateNeeded = true;
myArrowAspect = new Prs3d_ArrowAspect();
myHasOwnArrowAspect = true;
}
if (!myHasOwnDatumAspect)
{
isUpdateNeeded = true;
myDatumAspect = new Prs3d_DatumAspect();
myHasOwnDatumAspect = true;
}
isUpdateNeeded = SetOwnLineAspects() || isUpdateNeeded;
isUpdateNeeded = SetOwnDatumAspects() || isUpdateNeeded;
}
setAspectProgram (theProgram, myHasOwnUIsoAspect, myUIsoAspect);
@@ -1245,15 +1350,9 @@ bool Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP
case Graphic3d_ASPECT_MARKER:
{
if (theToOverrideDefaults
&& !myHasOwnPointAspect)
&& SetupOwnPointAspect())
{
isUpdateNeeded = true;
myPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0);
myHasOwnPointAspect = true;
if (!myLink.IsNull())
{
*myPointAspect->Aspect() = *myLink->PointAspect()->Aspect();
}
}
setAspectProgram (theProgram, myHasOwnPointAspect, myPointAspect);
@@ -1262,15 +1361,9 @@ bool Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP
case Graphic3d_ASPECT_FILL_AREA:
{
if (theToOverrideDefaults
&& !myHasOwnShadingAspect)
&& SetupOwnShadingAspect())
{
isUpdateNeeded = true;
myShadingAspect = new Prs3d_ShadingAspect();
myHasOwnShadingAspect = true;
if (!myLink.IsNull())
{
*myShadingAspect->Aspect() = *myLink->ShadingAspect()->Aspect();
}
}
setAspectProgram (theProgram, myHasOwnShadingAspect, myShadingAspect);
return isUpdateNeeded;
@@ -1289,15 +1382,9 @@ bool Prs3d_Drawer::SetShadingModel (Graphic3d_TypeOfShadingModel theModel,
bool isUpdateNeeded = false;
if (theToOverrideDefaults
&& !myHasOwnShadingAspect)
&& SetupOwnShadingAspect())
{
isUpdateNeeded = true;
myShadingAspect = new Prs3d_ShadingAspect();
myHasOwnShadingAspect = true;
if (!myLink.IsNull())
{
*myShadingAspect->Aspect() = *myLink->ShadingAspect()->Aspect();
}
}
if (!myShadingAspect.IsNull()

View File

@@ -439,6 +439,10 @@ public:
//! point aspect that overrides the one in the link.
Standard_Boolean HasOwnPointAspect() const { return myHasOwnPointAspect; }
//! Sets own point aspect.
//! Returns FALSE if the drawer already has its own attribute for point aspect.
Standard_EXPORT Standard_Boolean SetupOwnPointAspect (const Handle(Prs3d_Drawer)& theDefaults = Handle(Prs3d_Drawer)());
//! Returns settings for line aspects.
//! These settings can be edited. The default values are:
//! Color: Quantity_NOC_YELLOW
@@ -457,6 +461,14 @@ public:
//! line aspect that overrides the one in the link.
Standard_Boolean HasOwnLineAspect() const { return myHasOwnLineAspect; }
//! Sets own line aspects.
//! Returns FALSE if own line aspect are already set.
Standard_EXPORT Standard_Boolean SetOwnLineAspects (const Handle(Prs3d_Drawer)& theDefaults = Handle(Prs3d_Drawer)());
//! Sets own line aspects for datums.
//! Returns FALSE if own line for datums are already set.
Standard_EXPORT Standard_Boolean SetOwnDatumAspects (const Handle(Prs3d_Drawer)& theDefaults = Handle(Prs3d_Drawer)());
//! Returns settings for text aspect.
//! These settings can be edited. The default value is:
//! - Color: Quantity_NOC_YELLOW
@@ -487,6 +499,10 @@ public:
//! shading aspect that overrides the one in the link.
Standard_Boolean HasOwnShadingAspect() const { return myHasOwnShadingAspect; }
//! Sets own shading aspect.
//! Returns FALSE if the drawer already has its own attribute for shading aspect.
Standard_EXPORT Standard_Boolean SetupOwnShadingAspect (const Handle(Prs3d_Drawer)& theDefaults = Handle(Prs3d_Drawer)());
//! Returns settings for seen line aspects.
//! These settings can be edited. The default values are:
//! Color: Quantity_NOC_YELLOW

View File

@@ -3,7 +3,6 @@ QABugs.hxx
QABugs_1.cxx
QABugs_2.cxx
QABugs_3.cxx
QABugs_4.cxx
QABugs_5.cxx
QABugs_6.cxx
QABugs_7.cxx

View File

@@ -19,7 +19,6 @@ void QABugs::Commands(Draw_Interpretor& theCommands) {
QABugs::Commands_1(theCommands);
QABugs::Commands_2(theCommands);
QABugs::Commands_3(theCommands);
QABugs::Commands_4(theCommands);
QABugs::Commands_5(theCommands);
QABugs::Commands_6(theCommands);
QABugs::Commands_7(theCommands);

View File

@@ -40,9 +40,7 @@ public:
Standard_EXPORT static void Commands_2 (Draw_Interpretor& DI);
Standard_EXPORT static void Commands_3 (Draw_Interpretor& DI);
Standard_EXPORT static void Commands_4 (Draw_Interpretor& DI);
Standard_EXPORT static void Commands_5 (Draw_Interpretor& DI);
Standard_EXPORT static void Commands_6 (Draw_Interpretor& DI);

View File

@@ -1,77 +0,0 @@
// Created on: 2002-03-19
// Created by: QA Admin
// Copyright (c) 2002-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <QABugs.hxx>
#include <Draw_Interpretor.hxx>
#include <DBRep.hxx>
#include <DrawTrSurf.hxx>
#include <AIS_InteractiveContext.hxx>
#include <ViewerTest.hxx>
#include <AIS_Shape.hxx>
#include <TopoDS_Shape.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_ShadingAspect.hxx>
//#include <AcisData_AcisModel.hxx>
#include <TopTools_HSequenceOfShape.hxx>
static Standard_Integer BUC60738 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** argv)
{
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if(aContext.IsNull()) {
di << "use 'vinit' command before " << argv[0] << "\n";
return -1;
}
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(-40,0,0),20).Shape();
Handle(AIS_Shape) theAISShape = new AIS_Shape(theSphere);
//display mode = Shading
theAISShape->SetDisplayMode(1);
//get the drawer
Handle(Prs3d_Drawer) theDrawer = theAISShape->Attributes();
Handle(Prs3d_ShadingAspect) theShadingAspect = theDrawer->ShadingAspect();
Handle(Graphic3d_AspectFillArea3d) theAspectFillArea3d = theShadingAspect->Aspect();
//allow to display the edges
theAspectFillArea3d->SetEdgeOn();
//set the style to Dash
//but the style is not set to dash : it is always solid
theAspectFillArea3d->SetEdgeLineType (Aspect_TOL_DASH);
theAspectFillArea3d->SetEdgeColor(Quantity_Color(Quantity_NOC_GREEN));
theAspectFillArea3d->SetInteriorStyle(Aspect_IS_EMPTY);
theShadingAspect->SetAspect(theAspectFillArea3d);
theDrawer->SetShadingAspect(theShadingAspect);
theAISShape->SetAttributes(theDrawer);
aContext->Display (theAISShape, Standard_True);
return 0;
}
void QABugs::Commands_4(Draw_Interpretor& theCommands) {
const char *group = "QABugs";
theCommands.Add("BUC60738","BUC60738",__FILE__,BUC60738,group);
return;
}

Some files were not shown because too many files have changed in this diff Show More