From 8e0a2b19abcf8d04cc56c8aab24e28e2dcbf2dae Mon Sep 17 00:00:00 2001 From: kgv Date: Fri, 1 Sep 2017 17:45:49 +0300 Subject: [PATCH] 0029074: Visualization, TKOpenGl - support Geometry Shader definition Graphic3d_TypeOfShaderObject enumeration has been extended by Geometry shader object type. OpenGl_ShaderProgram::Initialize() processes new shader object types when supported by OpenGL version. Declarations.glsl has been fixed so that occFragColor is defined only for Fragment Shader object only (by handling new FRAGMENT_SHADER macros). Improved documentation of Graphic3d_ArrayOfPrimitives class. vshader Draw Harness command has been extended to support definition of Shader Object types other than Vertex and Fragment shader. --- src/Graphic3d/FILES | 9 - src/Graphic3d/Graphic3d_ArrayOfPoints.cxx | 25 -- src/Graphic3d/Graphic3d_ArrayOfPoints.hxx | 47 +-- src/Graphic3d/Graphic3d_ArrayOfPolygons.cxx | 29 -- src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx | 193 ++++------ src/Graphic3d/Graphic3d_ArrayOfPolylines.cxx | 27 -- src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx | 180 ++++------ src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx | 58 ++- src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx | 49 ++- .../Graphic3d_ArrayOfQuadrangleStrips.cxx | 28 -- .../Graphic3d_ArrayOfQuadrangleStrips.hxx | 93 ++--- .../Graphic3d_ArrayOfQuadrangles.cxx | 28 -- .../Graphic3d_ArrayOfQuadrangles.hxx | 112 ++---- src/Graphic3d/Graphic3d_ArrayOfSegments.cxx | 25 -- src/Graphic3d/Graphic3d_ArrayOfSegments.hxx | 95 ++--- .../Graphic3d_ArrayOfTriangleFans.cxx | 28 -- .../Graphic3d_ArrayOfTriangleFans.hxx | 89 ++--- .../Graphic3d_ArrayOfTriangleStrips.cxx | 28 -- .../Graphic3d_ArrayOfTriangleStrips.hxx | 115 ++---- src/Graphic3d/Graphic3d_ArrayOfTriangles.cxx | 27 -- src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx | 109 ++---- .../Graphic3d_TypeOfPrimitiveArray.hxx | 33 +- .../Graphic3d_TypeOfShaderObject.hxx | 12 +- src/OpenGl/OpenGl_CappingAlgo.cxx | 3 +- src/OpenGl/OpenGl_GlFunctions.hxx | 13 + src/OpenGl/OpenGl_LayerList.cxx | 6 +- src/OpenGl/OpenGl_PrimitiveArray.cxx | 101 ++++-- src/OpenGl/OpenGl_PrimitiveArray.hxx | 19 +- src/OpenGl/OpenGl_ShaderProgram.cxx | 186 +++++++--- src/OpenGl/OpenGl_ShaderProgram.hxx | 4 + src/Prs3d/Prs3d_Drawer.cxx | 29 +- src/Prs3d/Prs3d_Drawer.hxx | 3 +- src/Shaders/Declarations.glsl | 28 +- src/Shaders/Shaders_Declarations_glsl.pxx | 28 +- src/ViewerTest/ViewerTest_OpenGlCommands.cxx | 333 ++++++++++++------ tests/v3d/glsl/begin | 3 - tests/v3d/glsl/geom1 | 55 +++ tests/v3d/glsl/gouraud_dir1 | 3 + tests/v3d/glsl/gouraud_dir2 | 5 +- tests/v3d/glsl/gouraud_pos1 | 4 + tests/v3d/glsl/gouraud_spot1 | 4 + tests/v3d/glsl/light_off | 3 +- tests/v3d/glsl/phong_box | 3 +- tests/v3d/glsl/phong_couple | 3 +- tests/v3d/glsl/phong_dir1 | 3 + tests/v3d/glsl/phong_dir2 | 3 + tests/v3d/glsl/phong_fuse | 3 +- tests/v3d/glsl/phong_fuse2 | 3 +- tests/v3d/glsl/phong_plastic | 3 +- tests/v3d/glsl/phong_pos1 | 4 + tests/v3d/glsl/phong_sides | 3 +- tests/v3d/glsl/phong_spot1 | 4 + tests/v3d/glsl/phong_views | 3 +- tests/v3d/glsl/rendscale | 1 + tests/v3d/glsl/stereo | 3 +- tests/v3d/glsl/stipple_line | 2 + tests/v3d/glsl/tess1 | 75 ++++ tests/v3d/glsl/texture_multi1 | 4 +- tests/v3d/glsl/texture_trsf | 4 + tests/v3d/glsl/tiles | 1 + 60 files changed, 1187 insertions(+), 1207 deletions(-) delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfPoints.cxx delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfPolygons.cxx delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfPolylines.cxx delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.cxx delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfQuadrangles.cxx delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfSegments.cxx delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfTriangleFans.cxx delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.cxx delete mode 100644 src/Graphic3d/Graphic3d_ArrayOfTriangles.cxx delete mode 100644 tests/v3d/glsl/begin create mode 100644 tests/v3d/glsl/geom1 create mode 100644 tests/v3d/glsl/tess1 diff --git a/src/Graphic3d/FILES b/src/Graphic3d/FILES index 7ab013e31c..f75d834b29 100755 --- a/src/Graphic3d/FILES +++ b/src/Graphic3d/FILES @@ -1,22 +1,13 @@ -Graphic3d_ArrayOfPoints.cxx Graphic3d_ArrayOfPoints.hxx -Graphic3d_ArrayOfPolygons.cxx Graphic3d_ArrayOfPolygons.hxx -Graphic3d_ArrayOfPolylines.cxx Graphic3d_ArrayOfPolylines.hxx Graphic3d_ArrayOfPrimitives.cxx Graphic3d_ArrayOfPrimitives.hxx -Graphic3d_ArrayOfQuadrangles.cxx Graphic3d_ArrayOfQuadrangles.hxx -Graphic3d_ArrayOfQuadrangleStrips.cxx Graphic3d_ArrayOfQuadrangleStrips.hxx -Graphic3d_ArrayOfSegments.cxx Graphic3d_ArrayOfSegments.hxx -Graphic3d_ArrayOfTriangleFans.cxx Graphic3d_ArrayOfTriangleFans.hxx -Graphic3d_ArrayOfTriangles.cxx Graphic3d_ArrayOfTriangles.hxx -Graphic3d_ArrayOfTriangleStrips.cxx Graphic3d_ArrayOfTriangleStrips.hxx Graphic3d_AspectFillArea3d.cxx Graphic3d_AspectFillArea3d.hxx diff --git a/src/Graphic3d/Graphic3d_ArrayOfPoints.cxx b/src/Graphic3d/Graphic3d_ArrayOfPoints.cxx deleted file mode 100644 index 53a09ba794..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfPoints.cxx +++ /dev/null @@ -1,25 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPoints,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfPoints::Graphic3d_ArrayOfPoints (const Standard_Integer theMaxVertexs, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasVNormals) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0, theHasVNormals, theHasVColors, Standard_False, Standard_False) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfPoints.hxx b/src/Graphic3d/Graphic3d_ArrayOfPoints.hxx index a5ce78e4eb..99c5ae0b88 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPoints.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPoints.hxx @@ -15,52 +15,25 @@ #ifndef _Graphic3d_ArrayOfPoints_HeaderFile #define _Graphic3d_ArrayOfPoints_HeaderFile -#include -#include - #include -#include -#include - - -class Graphic3d_ArrayOfPoints; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPoints, Graphic3d_ArrayOfPrimitives) -//! Contains points array definition +//! Contains points array definition. class Graphic3d_ArrayOfPoints : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPoints, Graphic3d_ArrayOfPrimitives) public: - - //! Creates an array of points, - //! a single pixel point is drawn at each vertex. + //! Creates an array of points, a single pixel point is drawn at each vertex. //! The array must be filled using the AddVertex(Point) method. - //! When is TRUE , you must use only AddVertex(Point,Color) method. - //! When is TRUE , you must use only AddVertex(Point,Normal) method. - Standard_EXPORT Graphic3d_ArrayOfPoints(const Standard_Integer maxVertexs, const Standard_Boolean hasVColors = Standard_False, const Standard_Boolean hasVNormals = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPoints,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + //! @param theHasVColors when TRUE, AddVertex(Point,Color) should be used for specifying vertex color + //! @param theHasVNormals when TRUE, AddVertex(Point,Normal) should be used for specifying vertex normal + Graphic3d_ArrayOfPoints (const Standard_Integer theMaxVertexs, + const Standard_Boolean theHasVColors = Standard_False, + const Standard_Boolean theHasVNormals = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0, theHasVNormals, theHasVColors, Standard_False, Standard_False) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPoints, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfPoints_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfPolygons.cxx b/src/Graphic3d/Graphic3d_ArrayOfPolygons.cxx deleted file mode 100644 index 7874f79dbb..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfPolygons.cxx +++ /dev/null @@ -1,29 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolygons,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfPolygons::Graphic3d_ArrayOfPolygons (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxBounds, - const Standard_Integer theMaxEdges, - const Standard_Boolean theHasVNormals, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasFColors, - const Standard_Boolean theHasVTexels) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges, theHasVNormals, theHasVColors, theHasFColors, theHasVTexels) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx b/src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx index 8ca1c13520..7459670e84 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx @@ -15,130 +15,91 @@ #ifndef _Graphic3d_ArrayOfPolygons_HeaderFile #define _Graphic3d_ArrayOfPolygons_HeaderFile -#include -#include - #include -#include -#include - - -class Graphic3d_ArrayOfPolygons; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPolygons, Graphic3d_ArrayOfPrimitives) -//! Contains polygons array definition +//! Contains polygons array definition. +//! WARNING! Polygon primitives might be unsupported by graphics library. +//! Triangulation should be used instead of quads for better compatibility. class Graphic3d_ArrayOfPolygons : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolygons, Graphic3d_ArrayOfPrimitives) public: - - //! Creates an array of polygons, - //! a polygon can be filled as: - //! 1) creating a single polygon defined with his vertexs. - //! i.e: - //! myArray = Graphic3d_ArrayOfPolygons(7) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x7,y7,z7) - //! 2) creating separate polygons defined with a predefined - //! number of bounds and the number of vertex per bound. - //! i.e: - //! myArray = Graphic3d_ArrayOfPolygons(7,2) - //! myArray->AddBound(4) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddBound(3) - //! myArray->AddVertex(x5,y5,z5) - //! .... - //! myArray->AddVertex(x7,y7,z7) - //! 3) creating a single indexed polygon defined with his vertex - //! ans edges. - //! i.e: - //! myArray = Graphic3d_ArrayOfPolygons(4,0,6) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(4) - //! 4) creating separate polygons defined with a predefined - //! number of bounds and the number of edges per bound. - //! i.e: - //! myArray = Graphic3d_ArrayOfPolygons(6,4,14) - //! myArray->AddBound(3) - //! myArray->AddVertex(x1,y1,z1) - //! myArray->AddVertex(x2,y2,z2) - //! myArray->AddVertex(x3,y3,z3) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddBound(3) - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddVertex(x5,y5,z5) - //! myArray->AddVertex(x6,y6,z6) - //! myArray->AddEdge(4) - //! myArray->AddEdge(5) - //! myArray->AddEdge(6) - //! myArray->AddBound(4) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddEdge(5) - //! myArray->AddEdge(6) - //! myArray->AddBound(4) - //! myArray->AddEdge(1) - //! myArray->AddEdge(3) - //! myArray->AddEdge(5) - //! myArray->AddEdge(4) - //! defined the maximun allowed vertex number in the array. - //! defined the maximun allowed bound number in the array. - //! defined the maximun allowed edge number in the array. - //! Warning: - //! When is TRUE , you must use one of - //! AddVertex(Point,Normal) - //! or AddVertex(Point,Normal,Color) - //! or AddVertex(Point,Normal,Texel) methods. - //! When is TRUE , you must use one of - //! AddVertex(Point,Color) - //! or AddVertex(Point,Normal,Color) methods. - //! When is TRUE , you must use one of - //! AddVertex(Point,Texel) - //! or AddVertex(Point,Normal,Texel) methods. - //! When is TRUE , must be > 0 and - //! you must use the - //! AddBound(number,Color) method. - //! Warning: - //! the user is responsible about the orientation of the polygon - //! depending of the order of the created vertex or edges and this - //! orientation must be coherent with the vertex normal optionnaly - //! given at each vertex (See the Orientate() methods). - Standard_EXPORT Graphic3d_ArrayOfPolygons(const Standard_Integer maxVertexs, const Standard_Integer maxBounds = 0, const Standard_Integer maxEdges = 0, const Standard_Boolean hasVNormals = Standard_False, const Standard_Boolean hasVColors = Standard_False, const Standard_Boolean hasBColors = Standard_False, const Standard_Boolean hasTexels = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolygons,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + //! Creates an array of polygons, a polygon can be filled as: + //! 1) Creating a single polygon defined with his vertexes, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfPolygons (7); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x7, y7, z7); + //! @endcode + //! 2) Creating separate polygons defined with a predefined number of bounds and the number of vertex per bound, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfPolygons (7, 2); + //! myArray->AddBound (4); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddBound (3); + //! myArray->AddVertex (x5, y5, z5); + //! .... + //! myArray->AddVertex (x7, y7, z7); + //! @endcode + //! 3) Creating a single indexed polygon defined with his vertex ans edges, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfPolygons (4, 0, 6); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (4); + //! @endcode + //! 4) Creating separate polygons defined with a predefined number of bounds and the number of edges per bound, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfPolygons (6, 4, 14); + //! myArray->AddBound (3); + //! myArray->AddVertex (x1, y1, z1); + //! myArray->AddVertex (x2, y2, z2); + //! myArray->AddVertex (x3, y3, z3); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddBound (3); + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddVertex (x5, y5, z5); + //! myArray->AddVertex (x6, y6, z6); + //! myArray->AddEdge (4); + //! myArray->AddEdge (5); + //! myArray->AddEdge (6); + //! myArray->AddBound (4); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddEdge (5); + //! myArray->AddEdge (6); + //! myArray->AddBound (4); + //! myArray->AddEdge (1); + //! myArray->AddEdge (3); + //! myArray->AddEdge (5); + //! myArray->AddEdge (4); + //! @endcode + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxBounds defines the maximum allowed bound number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array + Graphic3d_ArrayOfPolygons (const Standard_Integer theMaxVertexs, + const Standard_Integer theMaxBounds = 0, + const Standard_Integer theMaxEdges = 0, + const Standard_Boolean theHasVNormals = Standard_False, + const Standard_Boolean theHasVColors = Standard_False, + const Standard_Boolean theHasBColors = Standard_False, + const Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPolygons, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfPolygons_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfPolylines.cxx b/src/Graphic3d/Graphic3d_ArrayOfPolylines.cxx deleted file mode 100644 index e18d09749b..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfPolylines.cxx +++ /dev/null @@ -1,27 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolylines,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfPolylines::Graphic3d_ArrayOfPolylines (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxBounds, - const Standard_Integer theMaxEdges, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasFColors) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges, Standard_False, theHasVColors, theHasFColors, Standard_False) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx b/src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx index f95cd759c2..e7aed22903 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx @@ -15,119 +15,89 @@ #ifndef _Graphic3d_ArrayOfPolylines_HeaderFile #define _Graphic3d_ArrayOfPolylines_HeaderFile -#include -#include - #include -#include -#include - - -class Graphic3d_ArrayOfPolylines; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPolylines, Graphic3d_ArrayOfPrimitives) -//! Contains polylines array definition +//! Contains polylines array definition. class Graphic3d_ArrayOfPolylines : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolylines, Graphic3d_ArrayOfPrimitives) public: - - //! Creates an array of polylines, - //! a polyline can be filled as: - //! 1) creating a single polyline defined with his vertexs. - //! i.e: - //! myArray = Graphic3d_ArrayOfPolylines(7) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x7,y7,z7) - //! 2) creating separate polylines defined with a predefined - //! number of bounds and the number of vertex per bound. - //! i.e: - //! myArray = Graphic3d_ArrayOfPolylines(7,2) - //! myArray->AddBound(4) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddBound(3) - //! myArray->AddVertex(x5,y5,z5) - //! .... - //! myArray->AddVertex(x7,y7,z7) - //! 3) creating a single indexed polyline defined with his vertex - //! ans edges. - //! i.e: - //! myArray = Graphic3d_ArrayOfPolylines(4,0,6) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(4) - //! 4) creating separate polylines defined with a predefined - //! number of bounds and the number of edges per bound. - //! i.e: - //! myArray = Graphic3d_ArrayOfPolylines(6,4,14) - //! myArray->AddBound(3) - //! myArray->AddVertex(x1,y1,z1) - //! myArray->AddVertex(x2,y2,z2) - //! myArray->AddVertex(x3,y3,z3) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddBound(3) - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddVertex(x5,y5,z5) - //! myArray->AddVertex(x6,y6,z6) - //! myArray->AddEdge(4) - //! myArray->AddEdge(5) - //! myArray->AddEdge(6) - //! myArray->AddBound(4) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddEdge(5) - //! myArray->AddEdge(6) - //! myArray->AddBound(4) - //! myArray->AddEdge(1) - //! myArray->AddEdge(3) - //! myArray->AddEdge(5) - //! myArray->AddEdge(4) - //! - //! defined the maximun allowed vertex number in the array. - //! defined the maximun allowed bound number in the array. - //! defined the maximun allowed edge number in the array. - //! Warning: - //! When is TRUE , you must use one of - //! AddVertex(Point,Color) - //! or AddVertex(Point,Normal,Color) methods. - //! When is TRUE , must be > 0 and - //! you must use the - //! AddBound(number,Color) method. - Standard_EXPORT Graphic3d_ArrayOfPolylines(const Standard_Integer maxVertexs, const Standard_Integer maxBounds = 0, const Standard_Integer maxEdges = 0, const Standard_Boolean hasVColors = Standard_False, const Standard_Boolean hasBColors = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolylines,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + //! Creates an array of polylines, a polyline can be filled as: + //! 1) Creating a single polyline defined with his vertexes, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfPolylines (7); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x7, y7, z7); + //! @endcode + //! 2) Creating separate polylines defined with a predefined number of bounds and the number of vertex per bound, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfPolylines (7, 2); + //! myArray->AddBound (4); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddBound (3); + //! myArray->AddVertex (x5, y5, z5); + //! .... + //! myArray->AddVertex (x7, y7, z7); + //! @endcode + //! 3) Creating a single indexed polyline defined with his vertex and edges, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfPolylines (4, 0, 6); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (4); + //! @endcode + //! 4) creating separate polylines defined with a predefined number of bounds and the number of edges per bound, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfPolylines (6, 4, 14); + //! myArray->AddBound (3); + //! myArray->AddVertex (x1, y1, z1); + //! myArray->AddVertex (x2, y2, z2); + //! myArray->AddVertex (x3, y3, z3); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddBound (3); + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddVertex (x5, y5, z5); + //! myArray->AddVertex (x6, y6, z6); + //! myArray->AddEdge (4); + //! myArray->AddEdge (5); + //! myArray->AddEdge (6); + //! myArray->AddBound (4); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddEdge (5); + //! myArray->AddEdge (6); + //! myArray->AddBound (4); + //! myArray->AddEdge (1); + //! myArray->AddEdge (3); + //! myArray->AddEdge (5); + //! myArray->AddEdge (4); + //! @endcode + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxBounds defines the maximum allowed bound number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array + //! @param theHasVColors when TRUE AddVertex(Point,Color) or AddVertex(Point,Normal,Color) should be used to specify per-vertex color values + //! @param theHasBColors when TRUE AddBound(number,Color) should be used to specify sub-group color + Graphic3d_ArrayOfPolylines (const Standard_Integer theMaxVertexs, + const Standard_Integer theMaxBounds = 0, + const Standard_Integer theMaxEdges = 0, + const Standard_Boolean theHasVColors = Standard_False, + const Standard_Boolean theHasBColors = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges, Standard_False, theHasVColors, theHasBColors, Standard_False) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPolylines, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfPolylines_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx index fb4a3a9d38..2e9ccce9e2 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx @@ -14,6 +14,16 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include @@ -22,6 +32,16 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPrimitives, Standard_Transient) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPoints, Graphic3d_ArrayOfPrimitives) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfSegments, Graphic3d_ArrayOfPrimitives) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolylines, Graphic3d_ArrayOfPrimitives) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangles, Graphic3d_ArrayOfPrimitives) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleStrips, Graphic3d_ArrayOfPrimitives) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleFans, Graphic3d_ArrayOfPrimitives) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangles, Graphic3d_ArrayOfPrimitives) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangleStrips, Graphic3d_ArrayOfPrimitives) +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolygons, Graphic3d_ArrayOfPrimitives) + // ======================================================================= // function : Graphic3d_ArrayOfPrimitives // purpose : @@ -246,14 +266,18 @@ Standard_CString Graphic3d_ArrayOfPrimitives::StringType() const switch (myType) { case Graphic3d_TOPA_POINTS: return "ArrayOfPoints"; - case Graphic3d_TOPA_POLYLINES: return "ArrayOfPolylines"; case Graphic3d_TOPA_SEGMENTS: return "ArrayOfSegments"; - case Graphic3d_TOPA_POLYGONS: return "ArrayOfPolygons"; + case Graphic3d_TOPA_POLYLINES: return "ArrayOfPolylines"; case Graphic3d_TOPA_TRIANGLES: return "ArrayOfTriangles"; - case Graphic3d_TOPA_QUADRANGLES: return "ArrayOfQuadrangles"; case Graphic3d_TOPA_TRIANGLESTRIPS: return "ArrayOfTriangleStrips"; - case Graphic3d_TOPA_QUADRANGLESTRIPS: return "ArrayOfQuadrangleStrips"; case Graphic3d_TOPA_TRIANGLEFANS: return "ArrayOfTriangleFans"; + case Graphic3d_TOPA_LINES_ADJACENCY: return "ArrayOfLinesAdjacency"; + case Graphic3d_TOPA_LINE_STRIP_ADJACENCY: return "ArrayOfLineStripAdjacency"; + case Graphic3d_TOPA_TRIANGLES_ADJACENCY: return "ArrayOfTrianglesAdjacency"; + case Graphic3d_TOPA_TRIANGLE_STRIP_ADJACENCY: return "ArrayOfTriangleStripAdjacency"; + case Graphic3d_TOPA_QUADRANGLES: return "ArrayOfQuadrangles"; + case Graphic3d_TOPA_QUADRANGLESTRIPS: return "ArrayOfQuadrangleStrips"; + case Graphic3d_TOPA_POLYGONS: return "ArrayOfPolygons"; case Graphic3d_TOPA_UNDEFINED: return "UndefinedArray"; } return "UndefinedArray"; @@ -293,6 +317,18 @@ Standard_Integer Graphic3d_ArrayOfPrimitives::ItemNumber() const case Graphic3d_TOPA_TRIANGLEFANS: return !myBounds.IsNull() ? myAttribs->NbElements - 2 * myBounds->NbBounds : myAttribs->NbElements - 2; + case Graphic3d_TOPA_LINES_ADJACENCY: return myIndices.IsNull() || myIndices->NbElements < 1 + ? myAttribs->NbElements / 4 + : myIndices->NbElements / 4; + case Graphic3d_TOPA_LINE_STRIP_ADJACENCY: return !myBounds.IsNull() + ? myAttribs->NbElements - 4 * myBounds->NbBounds + : myAttribs->NbElements - 4; + case Graphic3d_TOPA_TRIANGLES_ADJACENCY: return myIndices.IsNull() || myIndices->NbElements < 1 + ? myAttribs->NbElements / 6 + : myIndices->NbElements / 6; + case Graphic3d_TOPA_TRIANGLE_STRIP_ADJACENCY: return !myBounds.IsNull() + ? myAttribs->NbElements - 4 * myBounds->NbBounds + : myAttribs->NbElements - 4; case Graphic3d_TOPA_UNDEFINED: return -1; } return -1; @@ -407,6 +443,20 @@ Standard_Boolean Graphic3d_ArrayOfPrimitives::IsValid() return Standard_False; } break; + case Graphic3d_TOPA_LINES_ADJACENCY: + case Graphic3d_TOPA_LINE_STRIP_ADJACENCY: + if (nvertexs < 4) + { + return Standard_False; + } + break; + case Graphic3d_TOPA_TRIANGLES_ADJACENCY: + case Graphic3d_TOPA_TRIANGLE_STRIP_ADJACENCY: + if (nvertexs < 6) + { + return Standard_False; + } + break; case Graphic3d_TOPA_UNDEFINED: default: return Standard_False; diff --git a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx index 6478f1797c..9d78df553c 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx @@ -24,28 +24,41 @@ #include #include -class Quantity_Color; - class Graphic3d_ArrayOfPrimitives; DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPrimitives, Standard_Transient) -//! This class furnish services to defined and fill an -//! array of primitives compatible with the use of -//! the OPENGl glDrawArrays() or glDrawElements() functions. -//! NOTE that the main goal of this kind of primitive -//! is to avoid multiple copies of datas between -//! each layer of the software. -//! So the array datas exist only one time and the use -//! of SetXxxxxx() methods enable to change dynamically -//! the aspect of this primitive. +//! This class furnish services to defined and fill an array of primitives +//! which can be passed directly to graphics rendering API. +//! +//! The basic interface consists of the following parts: +//! 1) Specifying primitive type. +//! WARNING! Particular primitive types might be unsupported by specific hardware/graphics API (like quads and polygons). +//! It is always preferred using one of basic types having maximum compatibility: +//! Point, Triangle (or Triangle strip), Segment aka Lines (or Polyline aka Line Strip). +//! Primitive strip types can be used to reduce memory usage as alternative to Indexed arrays. +//! 2) Vertex array. +//! - Specifying the (maximum) number of vertexes within array. +//! - Specifying the vertex attributes, complementary to mandatory vertex Position (normal, color, UV texture coordinates). +//! - Defining vertex values by using various versions of AddVertex() or SetVertex*() methods. +//! 3) Index array (optional). +//! - Specifying the (maximum) number of indexes (edges). +//! - Defining index values by using AddEdge() method; the index value should be within number of defined Vertexes. //! -//! Advantages are : -//! 1) Decrease strongly the loading time. -//! 2) Decrease strongly the display time using optimized Opengl -//! primitives. -//! 3) Enable to change dynamically the components of the primitive -//! (vertice,normal,color,texture coordinates). -//! 4) Add true triangle and quadrangle strips or fans capabilities. +//! Indexed array allows sharing vertex data across Primitives and thus reducing memory usage, +//! since index size is much smaller then size of vertex with all its attributes. +//! It is a preferred way for defining primitive array and main alternative to Primitive Strips for optimal memory usage, +//! although it is also possible (but unusual) defining Indexed Primitive Strip. +//! Note that it is NOT possible sharing Vertex Attributes partially (e.g. share Position, but have different Normals); +//! in such cases Vertex should be entirely duplicated with all Attributes. +//! 4) Bounds array (optional). +//! - Specifying the (maximum) number of bounds. +//! - Defining bounds using AddBound() methods. +//! +//! Bounds allow splitting Primitive Array into sub-groups. +//! This is useful only in two cases - for specifying per-group color and for restarting Primitive Strips. +//! WARNING! Bounds within Primitive Array break rendering batches into parts (additional for loops), +//! affecting rendering performance negatively (increasing CPU load). + class Graphic3d_ArrayOfPrimitives : public Standard_Transient { DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPrimitives, Standard_Transient) diff --git a/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.cxx b/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.cxx deleted file mode 100644 index bd954e71e7..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.cxx +++ /dev/null @@ -1,28 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangleStrips,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfQuadrangleStrips::Graphic3d_ArrayOfQuadrangleStrips (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxStrips, - const Standard_Boolean theHasVNormals, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasSColors, - const Standard_Boolean theHasVTexels) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasSColors, theHasVTexels) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx b/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx index c53cadadc8..8f6fbac071 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx @@ -15,72 +15,49 @@ #ifndef _Graphic3d_ArrayOfQuadrangleStrips_HeaderFile #define _Graphic3d_ArrayOfQuadrangleStrips_HeaderFile -#include -#include - #include -#include -#include - - -class Graphic3d_ArrayOfQuadrangleStrips; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfQuadrangleStrips, Graphic3d_ArrayOfPrimitives) -//! Contains quadrangles strip array definition +//! Contains quadrangles strip array definition. +//! WARNING! Quadrangle primitives might be unsupported by graphics library. +//! Triangulation should be used instead of quads for better compatibility. class Graphic3d_ArrayOfQuadrangleStrips : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangleStrips, Graphic3d_ArrayOfPrimitives) public: - - //! Creates an array of quadrangle strips, - //! a polygon can be filled as: - //! 1) creating a single strip defined with his vertexs. - //! i.e: - //! myArray = Graphic3d_ArrayOfQuadrangleStrips(7) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x7,y7,z7) - //! 2) creating separate strips defined with a predefined - //! number of strips and the number of vertex per strip. - //! i.e: - //! myArray = Graphic3d_ArrayOfQuadrangleStrips(8,2) - //! myArray->AddBound(4) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddBound(4) - //! myArray->AddVertex(x5,y5,z5) - //! .... - //! myArray->AddVertex(x8,y8,z8) - //! - //! defined the maximun allowed vertex number in the array. - //! defined the maximun allowed strip number in the array. - //! The number of quadrangle really drawn is : - //! VertexNumber()/2-Min(1,BoundNumber()) - Standard_EXPORT Graphic3d_ArrayOfQuadrangleStrips(const Standard_Integer maxVertexs, const Standard_Integer maxStrips = 0, const Standard_Boolean hasVNormals = Standard_False, const Standard_Boolean hasVColors = Standard_False, const Standard_Boolean hasSColors = Standard_False, const Standard_Boolean hasTexels = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangleStrips,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + //! Creates an array of quadrangle strips, a polygon can be filled as: + //! 1) Creating a single strip defined with his vertexes, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfQuadrangleStrips (7); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x7, y7, z7); + //! @endcode + //! 2) Creating separate strips defined with a predefined number of strips and the number of vertex per strip, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfQuadrangleStrips (8, 2); + //! myArray->AddBound (4); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddBound (4); + //! myArray->AddVertex (x5, y5, z5); + //! .... + //! myArray->AddVertex (x8, y8, z8); + //! @endcode + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxStrips defines the maximum allowed strip number in the array + //! The number of quadrangle really drawn is: VertexNumber()/2 - Min(1, BoundNumber()). + Graphic3d_ArrayOfQuadrangleStrips (const Standard_Integer theMaxVertexs, + const Standard_Integer theMaxStrips = 0, + const Standard_Boolean theHasVNormals = Standard_False, + const Standard_Boolean theHasVColors = Standard_False, + const Standard_Boolean theHasSColors = Standard_False, + const Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasSColors, theHasVTexels) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfQuadrangleStrips, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfQuadrangleStrips_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.cxx b/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.cxx deleted file mode 100644 index 1e01c228fc..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.cxx +++ /dev/null @@ -1,28 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangles,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfQuadrangles::Graphic3d_ArrayOfQuadrangles (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxEdges, - const Standard_Boolean theHasVNormals, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasVTexels) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx b/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx index 8fa4004610..eb6671b454 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx @@ -15,90 +15,50 @@ #ifndef _Graphic3d_ArrayOfQuadrangles_HeaderFile #define _Graphic3d_ArrayOfQuadrangles_HeaderFile -#include -#include - #include -#include -#include -class Standard_OutOfRange; - - -class Graphic3d_ArrayOfQuadrangles; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfQuadrangles, Graphic3d_ArrayOfPrimitives) -//! Contains quatrangles array definition +//! Contains quadrangles array definition. +//! WARNING! Quadrangle primitives might be unsupported by graphics library. +//! Triangulation should be used instead of quads for better compatibility. class Graphic3d_ArrayOfQuadrangles : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangles, Graphic3d_ArrayOfPrimitives) public: - - //! Creates an array of quadrangles, - //! a quadrangle can be filled as: - //! 1) creating a set of quadrangles defined with his vertexs. - //! i.e: - //! myArray = Graphic3d_ArrayOfQuadrangles(8) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x8,y8,z8) - //! 3) creating a set of indexed quadrangles defined with his vertex - //! ans edges. - //! i.e: - //! myArray = Graphic3d_ArrayOfQuadrangles(6,8) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x6,y6,z6) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddEdge(4) - //! myArray->AddEdge(3) - //! myArray->AddEdge(4) - //! myArray->AddEdge(5) - //! myArray->AddEdge(6) - //! - //! defined the maximun allowed vertex number in the array. - //! defined the maximun allowed edge number in the array. - //! Warning: - //! When is TRUE , you must use one of - //! AddVertex(Point,Normal) - //! or AddVertex(Point,Normal,Color) - //! or AddVertex(Point,Normal,Texel) methods. - //! When is TRUE , you must use one of - //! AddVertex(Point,Color) - //! or AddVertex(Point,Normal,Color) methods. - //! When is TRUE , you must use one of - //! AddVertex(Point,Texel) - //! or AddVertex(Point,Normal,Texel) methods. - //! Warning: - //! the user is responsible about the orientation of the quadrangle - //! depending of the order of the created vertex or edges and this - //! orientation must be coherent with the vertex normal optionnaly - //! given at each vertex (See the Orientate() methods). - Standard_EXPORT Graphic3d_ArrayOfQuadrangles(const Standard_Integer maxVertexs, const Standard_Integer maxEdges = 0, const Standard_Boolean hasVNormals = Standard_False, const Standard_Boolean hasVColors = Standard_False, const Standard_Boolean hasTexels = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangles,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + //! Creates an array of quadrangles, a quadrangle can be filled as: + //! 1) Creating a set of quadrangles defined with his vertexes, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfQuadrangles (8); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x8, y8, z8); + //! @endcode + //! 2) Creating a set of indexed quadrangles defined with his vertex ans edges, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfQuadrangles (6, 8); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x6, y6, z6); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddEdge (4); + //! myArray->AddEdge (3); + //! myArray->AddEdge (4); + //! myArray->AddEdge (5); + //! myArray->AddEdge (6); + //! @endcode + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array (for indexed array) + Graphic3d_ArrayOfQuadrangles (const Standard_Integer theMaxVertexs, + const Standard_Integer theMaxEdges = 0, + const Standard_Boolean theHasVNormals = Standard_False, + const Standard_Boolean theHasVColors = Standard_False, + const Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfQuadrangles, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfQuadrangles_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfSegments.cxx b/src/Graphic3d/Graphic3d_ArrayOfSegments.cxx deleted file mode 100644 index f711238fb4..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfSegments.cxx +++ /dev/null @@ -1,25 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfSegments,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfSegments::Graphic3d_ArrayOfSegments (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxEdges, - const Standard_Boolean theHasVColors) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, Standard_False, theHasVColors, Standard_False, Standard_False) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfSegments.hxx b/src/Graphic3d/Graphic3d_ArrayOfSegments.hxx index a8b99e8dee..07750ff7fb 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfSegments.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfSegments.hxx @@ -15,76 +15,47 @@ #ifndef _Graphic3d_ArrayOfSegments_HeaderFile #define _Graphic3d_ArrayOfSegments_HeaderFile -#include -#include - #include -#include -#include - - -class Graphic3d_ArrayOfSegments; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfSegments, Graphic3d_ArrayOfPrimitives) -//! Contains segments array definition +//! Contains segments array definition. class Graphic3d_ArrayOfSegments : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfSegments, Graphic3d_ArrayOfPrimitives) public: - - //! Creates an array of segments, - //! a segment can be filled as: - //! 1) creating a set of segments defined with his vertexs. - //! i.e: - //! myArray = Graphic3d_ArrayOfSegments(4) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! 2) creating a set of indexed segments defined with his vertex - //! ans edges. - //! i.e: - //! myArray = Graphic3d_ArrayOfSegments(4,0,8) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddEdge(4) - //! myArray->AddEdge(2) - //! myArray->AddEdge(4) - //! myArray->AddEdge(1) - //! myArray->AddEdge(3) - //! - //! defined the maximun allowed vertex number in the array. - //! defined the maximun allowed edge number in the array. - //! Warning: - //! When is TRUE , you must use only - //! AddVertex(Point,Color) method - Standard_EXPORT Graphic3d_ArrayOfSegments(const Standard_Integer maxVertexs, const Standard_Integer maxEdges = 0, const Standard_Boolean hasVColors = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfSegments,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + //! Creates an array of segments, a segment can be filled as: + //! 1) Creating a set of segments defined with his vertexes, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfSegments (4); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! @endcode + //! 2) Creating a set of indexed segments defined with his vertex and edges, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfSegments (4, 0, 8); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddEdge (4); + //! myArray->AddEdge (2); + //! myArray->AddEdge (4); + //! myArray->AddEdge (1); + //! myArray->AddEdge (3); + //! @endcode + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array + //! @param theHasVColors when TRUE, AddVertex(Point,Color) should be used for specifying vertex color + Graphic3d_ArrayOfSegments (const Standard_Integer theMaxVertexs, + const Standard_Integer theMaxEdges = 0, + const Standard_Boolean theHasVColors = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, Standard_False, theHasVColors, Standard_False, Standard_False) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfSegments, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfSegments_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.cxx b/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.cxx deleted file mode 100644 index 7808e02801..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.cxx +++ /dev/null @@ -1,28 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleFans,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfTriangleFans::Graphic3d_ArrayOfTriangleFans (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxFans, - const Standard_Boolean theHasVNormals, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasFColors, - const Standard_Boolean theHasVTexels) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0, theHasVNormals, theHasVColors, theHasFColors, theHasVTexels) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx b/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx index 1feeb33c08..366d781133 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx @@ -15,72 +15,47 @@ #ifndef _Graphic3d_ArrayOfTriangleFans_HeaderFile #define _Graphic3d_ArrayOfTriangleFans_HeaderFile -#include -#include - #include -#include -#include - - -class Graphic3d_ArrayOfTriangleFans; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfTriangleFans, Graphic3d_ArrayOfPrimitives) //! Contains triangles fan array definition class Graphic3d_ArrayOfTriangleFans : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleFans, Graphic3d_ArrayOfPrimitives) public: - - //! Creates an array of triangle fans, - //! a polygon can be filled as: - //! 1) creating a single fan defined with his vertexs. - //! i.e: - //! myArray = Graphic3d_ArrayOfTriangleFans(7) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x7,y7,z7) - //! 2) creating separate fans defined with a predefined - //! number of fans and the number of vertex per fan. - //! i.e: - //! myArray = Graphic3d_ArrayOfTriangleFans(8,2) - //! myArray->AddBound(4) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddBound(4) - //! myArray->AddVertex(x5,y5,z5) - //! .... - //! myArray->AddVertex(x8,y8,z8) - //! - //! defined the maximun allowed vertex number in the array. - //! defined the maximun allowed fan number in the array. - //! The number of triangle really drawn is : - //! VertexNumber()-2*Min(1,BoundNumber()) - Standard_EXPORT Graphic3d_ArrayOfTriangleFans(const Standard_Integer maxVertexs, const Standard_Integer maxFans = 0, const Standard_Boolean hasVNormals = Standard_False, const Standard_Boolean hasVColors = Standard_False, const Standard_Boolean hasFColors = Standard_False, const Standard_Boolean hasTexels = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleFans,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + //! Creates an array of triangle fans, a polygon can be filled as: + //! 1) Creating a single fan defined with his vertexes, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfTriangleFans (7); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x7, y7, z7); + //! @endcode + //! 2) creating separate fans defined with a predefined number of fans and the number of vertex per fan, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfTriangleFans (8, 2); + //! myArray->AddBound (4); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddBound (4); + //! myArray->AddVertex (x5, y5, z5); + //! .... + //! myArray->AddVertex (x8, y8, z8); + //! @endcode + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxFans defines the maximum allowed fan number in the array + //! The number of triangle really drawn is: VertexNumber() - 2 * Min(1, BoundNumber()) + Graphic3d_ArrayOfTriangleFans (const Standard_Integer theMaxVertexs, + const Standard_Integer theMaxFans = 0, + const Standard_Boolean theHasVNormals = Standard_False, + const Standard_Boolean theHasVColors = Standard_False, + const Standard_Boolean theHasBColors = Standard_False, + const Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfTriangleFans, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfTriangleFans_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.cxx b/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.cxx deleted file mode 100644 index 058dff1ff7..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.cxx +++ /dev/null @@ -1,28 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleStrips,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfTriangleStrips::Graphic3d_ArrayOfTriangleStrips (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxStrips, - const Standard_Boolean theHasVNormals, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasSColors, - const Standard_Boolean theHasVTexels) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasSColors, theHasVTexels) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx b/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx index 617c4eabaa..e1a05e470a 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx @@ -15,91 +15,52 @@ #ifndef _Graphic3d_ArrayOfTriangleStrips_HeaderFile #define _Graphic3d_ArrayOfTriangleStrips_HeaderFile -#include -#include - #include -#include -#include - - -class Graphic3d_ArrayOfTriangleStrips; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfTriangleStrips, Graphic3d_ArrayOfPrimitives) -//! Contains triangles strip array definition +//! Contains triangles strip array definition. class Graphic3d_ArrayOfTriangleStrips : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleStrips, Graphic3d_ArrayOfPrimitives) public: - - //! Creates an array of triangle strips, - //! a polygon can be filled as: - //! 1) creating a single strip defined with his vertexs. - //! i.e: - //! myArray = Graphic3d_ArrayOfTriangleStrips(7) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x7,y7,z7) - //! 2) creating separate strips defined with a predefined - //! number of strips and the number of vertex per strip. - //! i.e: - //! myArray = Graphic3d_ArrayOfTriangleStrips(8,2) - //! myArray->AddBound(4) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddBound(4) - //! myArray->AddVertex(x5,y5,z5) - //! .... - //! myArray->AddVertex(x8,y8,z8) - //! - //! defined the maximun allowed vertex number in the array. - //! defined the maximun allowed strip number in the array. - //! The number of triangle really drawn is : - //! VertexNumber()-2*Min(1,BoundNumber()) - //! Warning: - //! When is TRUE , you must use one of - //! AddVertex(Point,Normal) - //! or AddVertex(Point,Normal,Color) - //! or AddVertex(Point,Normal,Texel) methods. - //! When is TRUE , you must use one of - //! AddVertex(Point,Color) - //! or AddVertex(Point,Normal,Color) methods. - //! When is TRUE , you must use one of - //! AddVertex(Point,Texel) - //! or AddVertex(Point,Normal,Texel) methods. - //! When is TRUE , must be > 0 and - //! you must use the - //! AddBound(number,Color) method. - //! Warning: - //! the user is responsible about the orientation of the strip - //! depending of the order of the created vertex and this - //! orientation must be coherent with the vertex normal optionnaly - //! given at each vertex (See the Orientate() methods). - Standard_EXPORT Graphic3d_ArrayOfTriangleStrips(const Standard_Integer maxVertexs, const Standard_Integer maxStrips = 0, const Standard_Boolean hasVNormals = Standard_False, const Standard_Boolean hasVColors = Standard_False, const Standard_Boolean hasSColors = Standard_False, const Standard_Boolean hasTexels = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleStrips,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + //! Creates an array of triangle strips, a polygon can be filled as: + //! 1) Creating a single strip defined with his vertexes, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfTriangleStrips (7); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x7, y7, z7); + //! @endcode + //! 2) Creating separate strips defined with a predefined number of strips and the number of vertex per strip, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfTriangleStrips (8, 2); + //! myArray->AddBound (4); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddBound (4); + //! myArray->AddVertex (x5, y5, z5); + //! .... + //! myArray->AddVertex (x8, y8, z8); + //! @endcode + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxStrips defines the maximum allowed strip number in the array; + //! the number of triangle really drawn is: VertexNumber() - 2 * Min(1, BoundNumber()) + //! @param theHasVNormals when TRUE, AddVertex(Point,Normal), AddVertex(Point,Normal,Color) or AddVertex(Point,Normal,Texel) should be used to specify vertex normal; + //! vertex normals should be specified coherent to triangle orientation (defined by order of vertexes within triangle) for proper rendering + //! @param theHasVColors when TRUE, AddVertex(Point,Color) or AddVertex(Point,Normal,Color) should be used to specify vertex color + //! @param theHasBColors when TRUE, AddBound(number,Color) should be used to specify sub-group color + //! @param theHasVTexels when TRUE, AddVertex(Point,Texel) or AddVertex(Point,Normal,Texel) should be used to specify vertex UV coordinates + Graphic3d_ArrayOfTriangleStrips (const Standard_Integer theMaxVertexs, + const Standard_Integer theMaxStrips = 0, + const Standard_Boolean theHasVNormals = Standard_False, + const Standard_Boolean theHasVColors = Standard_False, + const Standard_Boolean theHasBColors = Standard_False, + const Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfTriangleStrips, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfTriangleStrips_HeaderFile diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangles.cxx b/src/Graphic3d/Graphic3d_ArrayOfTriangles.cxx deleted file mode 100644 index da69bfa020..0000000000 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangles.cxx +++ /dev/null @@ -1,27 +0,0 @@ -// Created on: 2001-01-04 -// Copyright (c) 2001-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 -#include - -IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangles,Graphic3d_ArrayOfPrimitives) - -Graphic3d_ArrayOfTriangles::Graphic3d_ArrayOfTriangles (const Standard_Integer theMaxVertexs, - const Standard_Integer theMaxEdges, - const Standard_Boolean theHasVNormals, - const Standard_Boolean theHasVColors, - const Standard_Boolean theHasVTexels) -: Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels) -{} diff --git a/src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx b/src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx index e671fd91ab..e4035a7450 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx +++ b/src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx @@ -15,87 +15,50 @@ #ifndef _Graphic3d_ArrayOfTriangles_HeaderFile #define _Graphic3d_ArrayOfTriangles_HeaderFile -#include -#include - #include -#include -#include - - -class Graphic3d_ArrayOfTriangles; -DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfTriangles, Graphic3d_ArrayOfPrimitives) //! Contains triangles array definition class Graphic3d_ArrayOfTriangles : public Graphic3d_ArrayOfPrimitives { - + DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangles, Graphic3d_ArrayOfPrimitives) public: - - - //! Creates an array of triangles, - //! a triangle can be filled as: - //! 1) creating a set of triangles defined with his vertexs. - //! i.e: - //! myArray = Graphic3d_ArrayOfTriangles(6) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x6,y6,z6) - //! 3) creating a set of indexed triangles defined with his vertex - //! ans edges. - //! i.e: - //! myArray = Graphic3d_ArrayOfTriangles(4,6) - //! myArray->AddVertex(x1,y1,z1) - //! .... - //! myArray->AddVertex(x4,y4,z4) - //! myArray->AddEdge(1) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddEdge(2) - //! myArray->AddEdge(3) - //! myArray->AddEdge(4) - //! - //! defined the maximun allowed vertex number in the array. - //! defined the maximun allowed edge number in the array. - //! Warning: - //! When is TRUE , you must use one of - //! AddVertex(Point,Normal) - //! or AddVertex(Point,Normal,Color) - //! or AddVertex(Point,Normal,Texel) methods. - //! When is TRUE , you must use one of - //! AddVertex(Point,Color) - //! or AddVertex(Point,Normal,Color) methods. - //! When is TRUE , you must use one of - //! AddVertex(Point,Texel) - //! or AddVertex(Point,Normal,Texel) methods. - //! Warning: - //! the user is responsible about the orientation of the triangle - //! depending of the order of the created vertex or edges and this - //! orientation must be coherent with the vertex normal optionnaly - //! given at each vertex (See the Orientate() methods). - Standard_EXPORT Graphic3d_ArrayOfTriangles(const Standard_Integer maxVertexs, const Standard_Integer maxEdges = 0, const Standard_Boolean hasVNormals = Standard_False, const Standard_Boolean hasVColors = Standard_False, const Standard_Boolean hasTexels = Standard_False); - - - - - DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangles,Graphic3d_ArrayOfPrimitives) - -protected: - - - - -private: - - - + + //! Creates an array of triangles, a triangle can be filled as: + //! 1) Creating a set of triangles defined with his vertexes, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfTriangles (6); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x6, y6, z6); + //! @endcode + //! 3) Creating a set of indexed triangles defined with his vertex and edges, i.e: + //! @code + //! myArray = Graphic3d_ArrayOfTriangles (4, 6); + //! myArray->AddVertex (x1, y1, z1); + //! .... + //! myArray->AddVertex (x4, y4, z4); + //! myArray->AddEdge (1); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddEdge (2); + //! myArray->AddEdge (3); + //! myArray->AddEdge (4); + //! @endcode + //! @param theMaxVertexs defines the maximum allowed vertex number in the array + //! @param theMaxEdges defines the maximum allowed edge number in the array + //! @param theHasVNormals when TRUE, AddVertex(Point,Normal), AddVertex(Point,Normal,Color) or AddVertex(Point,Normal,Texel) should be used to specify vertex normal; + //! vertex normals should be specified coherent to triangle orientation (defined by order of vertexes within triangle) for proper rendering + //! @param theHasVColors when TRUE, AddVertex(Point,Color) or AddVertex(Point,Normal,Color) should be used to specify vertex color + //! @param theHasVTexels when TRUE, AddVertex(Point,Texel) or AddVertex(Point,Normal,Texel) should be used to specify vertex UV coordinates + Graphic3d_ArrayOfTriangles (const Standard_Integer theMaxVertexs, + const Standard_Integer theMaxEdges = 0, + const Standard_Boolean theHasVNormals = Standard_False, + const Standard_Boolean theHasVColors = Standard_False, + const Standard_Boolean theHasVTexels = Standard_False) + : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels) {} }; - - - - - +DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfTriangles, Graphic3d_ArrayOfPrimitives) #endif // _Graphic3d_ArrayOfTriangles_HeaderFile diff --git a/src/Graphic3d/Graphic3d_TypeOfPrimitiveArray.hxx b/src/Graphic3d/Graphic3d_TypeOfPrimitiveArray.hxx index b47a494556..a7b38b839d 100644 --- a/src/Graphic3d/Graphic3d_TypeOfPrimitiveArray.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfPrimitiveArray.hxx @@ -20,16 +20,29 @@ //! The type of primitive array in a group in a structure. enum Graphic3d_TypeOfPrimitiveArray { -Graphic3d_TOPA_UNDEFINED, -Graphic3d_TOPA_POINTS, -Graphic3d_TOPA_POLYLINES, -Graphic3d_TOPA_SEGMENTS, -Graphic3d_TOPA_POLYGONS, -Graphic3d_TOPA_TRIANGLES, -Graphic3d_TOPA_QUADRANGLES, -Graphic3d_TOPA_TRIANGLESTRIPS, -Graphic3d_TOPA_QUADRANGLESTRIPS, -Graphic3d_TOPA_TRIANGLEFANS + Graphic3d_TOPA_UNDEFINED, //!< undefined primitive type + // main rendering types + Graphic3d_TOPA_POINTS, //!< individual points + Graphic3d_TOPA_SEGMENTS, //!< segments array - each 2 vertexes define 1 segment + Graphic3d_TOPA_POLYLINES, //!< line strip - each new vertex in array defines segment with previous one + Graphic3d_TOPA_TRIANGLES, //!< triangle array - each 3 vertexes define 1 triangle + Graphic3d_TOPA_TRIANGLESTRIPS, //!< triangle strip - each new vertex in array defines triangle with 2 previous vertexes + Graphic3d_TOPA_TRIANGLEFANS, //!< triangle fan - each new vertex in array define triangle with the previous vertex and the very first vertex (fan center) + // rendering type with auxiliary adjacent info (can be accessed only within Geometry shader) + Graphic3d_TOPA_LINES_ADJACENCY, //!< ADVANCED - same as Graphic3d_TOPA_SEGMENTS, but each pair of vertexes defining 1 segment + //! is preceded by 1 extra vertex and followed by 1 extra vertex which are not actually rendered + Graphic3d_TOPA_LINE_STRIP_ADJACENCY, //!< ADVANCED - same as Graphic3d_TOPA_POLYLINES, but each sequence of vertexes defining 1 polyline + //! is preceded by 1 extra vertex and followed by 1 extra vertex which are not actually rendered + Graphic3d_TOPA_TRIANGLES_ADJACENCY, //!< ADVANCED - same as Graphic3d_TOPA_TRIANGLES, but each vertex defining of triangle + //! is followed by 1 extra adjacent vertex which is not actually rendered + Graphic3d_TOPA_TRIANGLE_STRIP_ADJACENCY, //!< ADVANCED - same as Graphic3d_TOPA_TRIANGLESTRIPS, but with extra adjacent vertexes + // deprecated types, unsupported by mobile hardware + Graphic3d_TOPA_QUADRANGLES, //!< DEPRECATED - triangle array should be used instead; + //! array of quads - each 4 vertexes define single quad + Graphic3d_TOPA_QUADRANGLESTRIPS, //!< DEPRECATED - triangle array should be used instead; + //! quad strip - each 2 new vertexes define a quad shared 2 more vertexes of previous quad + Graphic3d_TOPA_POLYGONS //!< DEPRECATED - triangle array should be used instead; + //! array defines a polygon }; #endif // _Graphic3d_TypeOfPrimitiveArray_HeaderFile diff --git a/src/Graphic3d/Graphic3d_TypeOfShaderObject.hxx b/src/Graphic3d/Graphic3d_TypeOfShaderObject.hxx index 44b0a9a925..20ebc17c12 100755 --- a/src/Graphic3d/Graphic3d_TypeOfShaderObject.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfShaderObject.hxx @@ -16,11 +16,17 @@ #ifndef _Graphic3d_TypeOfShaderObject_HeaderFile #define _Graphic3d_TypeOfShaderObject_HeaderFile -//! Type of the shader object (may be extended). +//! Type of the shader object. enum Graphic3d_TypeOfShaderObject { - Graphic3d_TOS_VERTEX, - Graphic3d_TOS_FRAGMENT + // rendering shaders + Graphic3d_TOS_VERTEX = 0x01, //!< vertex shader object, mandatory + Graphic3d_TOS_TESS_CONTROL = 0x02, //!< tessellation control shader object, optional + Graphic3d_TOS_TESS_EVALUATION = 0x04, //!< tessellation evaluation shader object, optional + Graphic3d_TOS_GEOMETRY = 0x08, //!< geometry shader object, optional + Graphic3d_TOS_FRAGMENT = 0x10, //!< fragment shader object, mandatory + // general-purpose compute shader + Graphic3d_TOS_COMPUTE = 0x20 //!< compute shader object, should be used as alternative to shader object types for rendering }; #endif diff --git a/src/OpenGl/OpenGl_CappingAlgo.cxx b/src/OpenGl/OpenGl_CappingAlgo.cxx index 3ba9545632..4b2a3e9352 100755 --- a/src/OpenGl/OpenGl_CappingAlgo.cxx +++ b/src/OpenGl/OpenGl_CappingAlgo.cxx @@ -230,6 +230,5 @@ Standard_Boolean OpenGl_CappingAlgoFilter::ShouldRender (const Handle(OpenGl_Wor const OpenGl_PrimitiveArray* aPArray = dynamic_cast (theGlElement); return aPArray != NULL - && aPArray->DrawMode() >= OpenGl_PrimitiveArray::THE_FILLPRIM_FROM - && aPArray->DrawMode() <= OpenGl_PrimitiveArray::THE_FILLPRIM_TO; + && aPArray->IsFillDrawMode(); } diff --git a/src/OpenGl/OpenGl_GlFunctions.hxx b/src/OpenGl/OpenGl_GlFunctions.hxx index 03e3411f37..686bbf44dd 100644 --- a/src/OpenGl/OpenGl_GlFunctions.hxx +++ b/src/OpenGl/OpenGl_GlFunctions.hxx @@ -198,6 +198,19 @@ // OpenGL ES 3.0+ or OES_texture_half_float #define GL_HALF_FLOAT 0x140B #define GL_HALF_FLOAT_OES 0x8D61 + + // OpenGL ES 3.1+ + #define GL_COMPUTE_SHADER 0x91B9 + + // OpenGL ES 3.2+ + #define GL_GEOMETRY_SHADER 0x8DD9 + #define GL_TESS_CONTROL_SHADER 0x8E88 + #define GL_TESS_EVALUATION_SHADER 0x8E87 + #define GL_LINES_ADJACENCY 0x000A + #define GL_LINE_STRIP_ADJACENCY 0x000B + #define GL_TRIANGLES_ADJACENCY 0x000C + #define GL_TRIANGLE_STRIP_ADJACENCY 0x000D + #define GL_PATCHES 0x000E #endif #if !defined(HAVE_EGL) && (defined(__ANDROID__) || defined(__QNX__) || defined(HAVE_GLES2) || defined(OCCT_UWP)) diff --git a/src/OpenGl/OpenGl_LayerList.cxx b/src/OpenGl/OpenGl_LayerList.cxx index 6a15b019d0..ccefa2ed9e 100644 --- a/src/OpenGl/OpenGl_LayerList.cxx +++ b/src/OpenGl/OpenGl_LayerList.cxx @@ -665,8 +665,7 @@ Standard_Boolean OpenGl_LayerList::OpenGl_OpaqueFilter::ShouldRender (const Hand const OpenGl_PrimitiveArray* aPArray = dynamic_cast (theGlElement); if (aPArray == NULL - || aPArray->DrawMode() < OpenGl_PrimitiveArray::THE_FILLPRIM_FROM - || aPArray->DrawMode() > OpenGl_PrimitiveArray::THE_FILLPRIM_TO) + || !aPArray->IsFillDrawMode()) { return Standard_True; } @@ -697,8 +696,7 @@ Standard_Boolean OpenGl_LayerList::OpenGl_TransparentFilter::ShouldRender (const const OpenGl_PrimitiveArray* aPArray = dynamic_cast (theGlElement); if (aPArray == NULL - || aPArray->DrawMode() < OpenGl_PrimitiveArray::THE_FILLPRIM_FROM - || aPArray->DrawMode() > OpenGl_PrimitiveArray::THE_FILLPRIM_TO) + || !aPArray->IsFillDrawMode()) { return dynamic_cast (theGlElement) != NULL; } diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 97a3e4f2b0..4fcbd4d366 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -373,8 +373,12 @@ void OpenGl_PrimitiveArray::drawArray (const Handle(OpenGl_Workspace)& theWorksp return; } - const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext(); - const bool toHilight = theWorkspace->ToHighlight(); + const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext(); + const bool toHilight = theWorkspace->ToHighlight(); + const GLenum aDrawMode = !aGlContext->ActiveProgram().IsNull() + && aGlContext->ActiveProgram()->HasTessellationStage() + ? GL_PATCHES + : myDrawMode; myVboAttribs->BindAllAttributes (aGlContext); if (theHasVertColor && toHilight) { @@ -393,14 +397,14 @@ void OpenGl_PrimitiveArray::drawArray (const Handle(OpenGl_Workspace)& theWorksp { const GLint aNbElemsInGroup = myBounds->Bounds[aGroupIter]; if (theFaceColors != NULL) aGlContext->SetColor4fv (theFaceColors[aGroupIter]); - glDrawElements (myDrawMode, aNbElemsInGroup, myVboIndices->GetDataType(), anOffset); + glDrawElements (aDrawMode, aNbElemsInGroup, myVboIndices->GetDataType(), anOffset); anOffset += aStride * aNbElemsInGroup; } } else { // draw one (or sequential) primitive by the indices - glDrawElements (myDrawMode, myVboIndices->GetElemsNb(), myVboIndices->GetDataType(), anOffset); + glDrawElements (aDrawMode, myVboIndices->GetElemsNb(), myVboIndices->GetDataType(), anOffset); } myVboIndices->Unbind (aGlContext); } @@ -411,7 +415,7 @@ void OpenGl_PrimitiveArray::drawArray (const Handle(OpenGl_Workspace)& theWorksp { const GLint aNbElemsInGroup = myBounds->Bounds[aGroupIter]; if (theFaceColors != NULL) aGlContext->SetColor4fv (theFaceColors[aGroupIter]); - glDrawArrays (myDrawMode, aFirstElem, aNbElemsInGroup); + glDrawArrays (aDrawMode, aFirstElem, aNbElemsInGroup); aFirstElem += aNbElemsInGroup; } } @@ -423,7 +427,7 @@ void OpenGl_PrimitiveArray::drawArray (const Handle(OpenGl_Workspace)& theWorksp } else { - glDrawArrays (myDrawMode, 0, myVboAttribs->GetElemsNb()); + glDrawArrays (aDrawMode, 0, myVboAttribs->GetElemsNb()); } } @@ -466,6 +470,10 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo Standard_False, anAspect->ShaderProgramRes (aGlContext)); } + const GLenum aDrawMode = !aGlContext->ActiveProgram().IsNull() + && aGlContext->ActiveProgram()->HasTessellationStage() + ? GL_PATCHES + : myDrawMode; /// OCC22236 NOTE: draw edges for all situations: /// 1) draw elements with GL_LINE style as edges from myPArray->bufferVBO[VBOEdges] indices array @@ -489,14 +497,14 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo for (Standard_Integer aGroupIter = 0; aGroupIter < myBounds->NbBounds; ++aGroupIter) { const GLint aNbElemsInGroup = myBounds->Bounds[aGroupIter]; - glDrawElements (myDrawMode, aNbElemsInGroup, myVboIndices->GetDataType(), anOffset); + glDrawElements (aDrawMode, aNbElemsInGroup, myVboIndices->GetDataType(), anOffset); anOffset += aStride * aNbElemsInGroup; } } // draw one (or sequential) primitive by the indices else { - glDrawElements (myDrawMode, myVboIndices->GetElemsNb(), myVboIndices->GetDataType(), anOffset); + glDrawElements (aDrawMode, myVboIndices->GetElemsNb(), myVboIndices->GetDataType(), anOffset); } myVboIndices->Unbind (aGlContext); } @@ -506,13 +514,13 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo for (Standard_Integer aGroupIter = 0; aGroupIter < myBounds->NbBounds; ++aGroupIter) { const GLint aNbElemsInGroup = myBounds->Bounds[aGroupIter]; - glDrawArrays (myDrawMode, aFirstElem, aNbElemsInGroup); + glDrawArrays (aDrawMode, aFirstElem, aNbElemsInGroup); aFirstElem += aNbElemsInGroup; } } else { - glDrawArrays (myDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements); + glDrawArrays (aDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements); } // unbind buffers @@ -528,8 +536,13 @@ void OpenGl_PrimitiveArray::drawEdges (const OpenGl_Vec4& theEdgeCo // ======================================================================= void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const { - const 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 + : myDrawMode; + const Handle(OpenGl_TextureSet)& aSpriteNormRes = anAspectMarker->SpriteRes (aCtx); const OpenGl_PointSprite* aSpriteNorm = !aSpriteNormRes.IsNull() ? dynamic_cast (aSpriteNormRes->First().get()) : NULL; if (aSpriteNorm != NULL @@ -549,7 +562,7 @@ void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWork aCtx->core11fwd->glEnable (GL_BLEND); aCtx->core11fwd->glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - aCtx->core11fwd->glDrawArrays (myDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements); + aCtx->core11fwd->glDrawArrays (aDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements); aCtx->core11fwd->glDisable (GL_BLEND); #if !defined(GL_ES_VERSION_2_0) @@ -564,7 +577,7 @@ void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWork else if (anAspectMarker->Aspect()->Type() == Aspect_TOM_POINT) { aCtx->SetPointSize (anAspectMarker->MarkerSize()); - aCtx->core11fwd->glDrawArrays (myDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements); + aCtx->core11fwd->glDrawArrays (aDrawMode, 0, !myVboAttribs.IsNull() ? myVboAttribs->GetElemsNb() : myAttribs->NbElements); aCtx->SetPointSize (1.0f); } #if !defined(GL_ES_VERSION_2_0) @@ -600,6 +613,7 @@ void OpenGl_PrimitiveArray::drawMarkers (const Handle(OpenGl_Workspace)& theWork OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver) : myDrawMode (DRAW_MODE_NONE), + myIsFillType(Standard_False), myIsVboInit (Standard_False) { if (theDriver != NULL) @@ -622,6 +636,7 @@ OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* myAttribs (theAttribs), myBounds (theBounds), myDrawMode (DRAW_MODE_NONE), + myIsFillType(Standard_False), myIsVboInit (Standard_False) { if (!myIndices.IsNull() @@ -876,45 +891,75 @@ void OpenGl_PrimitiveArray::setDrawMode (const Graphic3d_TypeOfPrimitiveArray th if (myAttribs.IsNull()) { myDrawMode = DRAW_MODE_NONE; + myIsFillType = false; return; } switch (theType) { case Graphic3d_TOPA_POINTS: - myDrawMode = GL_POINTS; - break; - case Graphic3d_TOPA_POLYLINES: - myDrawMode = GL_LINE_STRIP; + myDrawMode = GL_POINTS; + myIsFillType = false; break; case Graphic3d_TOPA_SEGMENTS: - myDrawMode = GL_LINES; + myDrawMode = GL_LINES; + myIsFillType = false; + break; + case Graphic3d_TOPA_POLYLINES: + myDrawMode = GL_LINE_STRIP; + myIsFillType = false; break; case Graphic3d_TOPA_TRIANGLES: - myDrawMode = GL_TRIANGLES; + myDrawMode = GL_TRIANGLES; + myIsFillType = true; break; case Graphic3d_TOPA_TRIANGLESTRIPS: - myDrawMode = GL_TRIANGLE_STRIP; + myDrawMode = GL_TRIANGLE_STRIP; + myIsFillType = true; break; case Graphic3d_TOPA_TRIANGLEFANS: - myDrawMode = GL_TRIANGLE_FAN; + myDrawMode = GL_TRIANGLE_FAN; + myIsFillType = true; break; - #if !defined(GL_ES_VERSION_2_0) - case Graphic3d_TOPA_POLYGONS: - myDrawMode = GL_POLYGON; + // + case Graphic3d_TOPA_LINES_ADJACENCY: + myDrawMode = GL_LINES_ADJACENCY; + myIsFillType = false; break; + case Graphic3d_TOPA_LINE_STRIP_ADJACENCY: + myDrawMode = GL_LINE_STRIP_ADJACENCY; + myIsFillType = false; + break; + case Graphic3d_TOPA_TRIANGLES_ADJACENCY: + myDrawMode = GL_TRIANGLES_ADJACENCY; + myIsFillType = true; + break; + case Graphic3d_TOPA_TRIANGLE_STRIP_ADJACENCY: + myDrawMode = GL_TRIANGLE_STRIP_ADJACENCY; + myIsFillType = true; + break; + // + #if !defined(GL_ES_VERSION_2_0) case Graphic3d_TOPA_QUADRANGLES: - myDrawMode = GL_QUADS; + myDrawMode = GL_QUADS; + myIsFillType = true; break; case Graphic3d_TOPA_QUADRANGLESTRIPS: - myDrawMode = GL_QUAD_STRIP; + myDrawMode = GL_QUAD_STRIP; + myIsFillType = true; break; - #else case Graphic3d_TOPA_POLYGONS: + myDrawMode = GL_POLYGON; + myIsFillType = true; + break; + #else case Graphic3d_TOPA_QUADRANGLES: case Graphic3d_TOPA_QUADRANGLESTRIPS: + case Graphic3d_TOPA_POLYGONS: #endif case Graphic3d_TOPA_UNDEFINED: + myDrawMode = DRAW_MODE_NONE; + myIsFillType = false; break; } } diff --git a/src/OpenGl/OpenGl_PrimitiveArray.hxx b/src/OpenGl/OpenGl_PrimitiveArray.hxx index fccdcb07de..5f1fa934c9 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.hxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.hxx @@ -32,22 +32,13 @@ class OpenGl_GraphicDriver; class OpenGl_PrimitiveArray : public 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 + //! 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. enum { DRAW_MODE_NONE = -1 }; -#if !defined(GL_ES_VERSION_2_0) - static const GLint THE_FILLPRIM_FROM = GL_TRIANGLES; - static const GLint THE_FILLPRIM_TO = GL_POLYGON; -#else - static const GLint THE_FILLPRIM_FROM = GL_TRIANGLES; - static const GLint THE_FILLPRIM_TO = GL_TRIANGLE_FAN; -#endif - //! Empty constructor Standard_EXPORT OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* theDriver); @@ -78,6 +69,9 @@ public: //! @return primitive type (GL_LINES, GL_TRIANGLES and others) GLint DrawMode() const { return myDrawMode; } + //! Return TRUE if primitive type generates shaded triangulation. + Standard_Boolean IsFillDrawMode() const { return myIsFillType; } + //! @return indices array const Handle(Graphic3d_IndexBuffer)& Indices() const { return myIndices; } @@ -139,7 +133,8 @@ protected: mutable Handle(Graphic3d_IndexBuffer) myIndices; mutable Handle(Graphic3d_Buffer) myAttribs; mutable Handle(Graphic3d_BoundBuffer) myBounds; - GLint myDrawMode; + GLshort myDrawMode; + mutable Standard_Boolean myIsFillType; mutable Standard_Boolean myIsVboInit; Standard_Size myUID; //!< Unique ID of primitive array. diff --git a/src/OpenGl/OpenGl_ShaderProgram.cxx b/src/OpenGl/OpenGl_ShaderProgram.cxx index 74344dd8ec..41a25bff97 100755 --- a/src/OpenGl/OpenGl_ShaderProgram.cxx +++ b/src/OpenGl/OpenGl_ShaderProgram.cxx @@ -76,6 +76,24 @@ Standard_CString OpenGl_ShaderProgram::PredefinedKeywords[] = "occPointSize" // OpenGl_OCCT_POINT_SIZE }; +namespace +{ + //! Convert Graphic3d_TypeOfShaderObject enumeration into OpenGL enumeration. + static GLenum shaderTypeToGl (Graphic3d_TypeOfShaderObject theType) + { + switch (theType) + { + case Graphic3d_TOS_VERTEX: return GL_VERTEX_SHADER; + case Graphic3d_TOS_FRAGMENT: return GL_FRAGMENT_SHADER; + case Graphic3d_TOS_GEOMETRY: return GL_GEOMETRY_SHADER; + case Graphic3d_TOS_TESS_CONTROL: return GL_TESS_CONTROL_SHADER; + case Graphic3d_TOS_TESS_EVALUATION: return GL_TESS_EVALUATION_SHADER; + case Graphic3d_TOS_COMPUTE: return GL_COMPUTE_SHADER; + } + return 0; + } +} + // ======================================================================= // function : OpenGl_VariableSetterSelector // purpose : Creates new variable setter selector @@ -130,7 +148,8 @@ OpenGl_ShaderProgram::OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram : OpenGl_NamedResource (!theProxy.IsNull() ? theProxy->GetId() : ""), myProgramID (NO_PROGRAM), myProxy (theProxy), - myShareCount(1) + myShareCount(1), + myHasTessShader (false) { memset (myCurrentState, 0, sizeof (myCurrentState)); for (GLint aVar = 0; aVar < OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES; ++aVar) @@ -146,66 +165,113 @@ OpenGl_ShaderProgram::OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)& theCtx, const Graphic3d_ShaderObjectList& theShaders) { + myHasTessShader = false; if (theCtx.IsNull() || !Create (theCtx)) { return Standard_False; } - TCollection_AsciiString aHeader = !myProxy.IsNull() && !myProxy->Header().IsEmpty() - ? (myProxy->Header() + "\n") - : TCollection_AsciiString(); - - TCollection_AsciiString aDeclarations = Shaders_Declarations_glsl; - TCollection_AsciiString aDeclImpl = Shaders_DeclarationsImpl_glsl; + TCollection_AsciiString aHeaderVer = !myProxy.IsNull() ? myProxy->Header() : TCollection_AsciiString(); + int aShaderMask = 0; + for (Graphic3d_ShaderObjectList::Iterator anIter (theShaders); anIter.More(); anIter.Next()) + { + aShaderMask |= anIter.Value()->Type(); + } + myHasTessShader = (aShaderMask & (Graphic3d_TOS_TESS_CONTROL | Graphic3d_TOS_TESS_EVALUATION)) != 0; - aDeclarations += aDeclImpl; + // 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 (!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+"); + return false; + } + else if (aHeaderVer.IsEmpty()) + { + aHeaderVer = "#version 320 es"; + } + } + else if ((aShaderMask & Graphic3d_TOS_COMPUTE) != 0) + { + if (!theCtx->IsGlGreaterEqual (3, 1)) + { + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, + "Error! Compute shaders require OpenGL ES 3.1+"); + return false; + } + else if (aHeaderVer.IsEmpty()) + { + aHeaderVer = "#version 310 es"; + } + } +#else + if ((aShaderMask & Graphic3d_TOS_COMPUTE) != 0) + { + if (!theCtx->IsGlGreaterEqual (4, 3)) + { + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, + "Error! Compute shaders require OpenGL 4.3+"); + return 0; + } + else if (aHeaderVer.IsEmpty()) + { + aHeaderVer = "#version 430"; + } + } + else if (myHasTessShader) + { + if (!theCtx->IsGlGreaterEqual (4, 0)) + { + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, + "Error! Tessellation shaders require OpenGL 4.0+"); + return 0; + } + else if (aHeaderVer.IsEmpty()) + { + aHeaderVer = "#version 400"; + } + } + else if ((aShaderMask & Graphic3d_TOS_GEOMETRY) != 0) + { + if (!theCtx->IsGlGreaterEqual (3, 2)) + { + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, + "Error! Geometry shaders require OpenGL 3.2+"); + return 0; + } + else if (aHeaderVer.IsEmpty()) + { + aHeaderVer = "#version 150"; + } + } +#endif - for (Graphic3d_ShaderObjectList::Iterator anIter (theShaders); - anIter.More(); anIter.Next()) + for (Graphic3d_ShaderObjectList::Iterator anIter (theShaders); anIter.More(); anIter.Next()) { if (!anIter.Value()->IsDone()) { const TCollection_ExtendedString aMsg = "Error! Failed to get shader source"; - theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, - GL_DEBUG_TYPE_ERROR, - 0, - GL_DEBUG_SEVERITY_HIGH, - aMsg); + theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg); return Standard_False; } - Handle(OpenGl_ShaderObject) aShader; - - // Note: Add support of other shader types here - switch (anIter.Value()->Type()) - { - case Graphic3d_TOS_VERTEX: - aShader = new OpenGl_ShaderObject (GL_VERTEX_SHADER); - break; - case Graphic3d_TOS_FRAGMENT: - aShader = new OpenGl_ShaderObject (GL_FRAGMENT_SHADER); - break; - } - - // Is unsupported shader type? - if (aShader.IsNull()) + const GLenum aShaderType = shaderTypeToGl (anIter.Value()->Type()); + if (aShaderType == 0) { - TCollection_ExtendedString aMsg = "Error! Unsupported shader type"; - theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, - GL_DEBUG_TYPE_ERROR, - 0, - GL_DEBUG_SEVERITY_HIGH, - aMsg); return Standard_False; } + Handle(OpenGl_ShaderObject) aShader = new OpenGl_ShaderObject (aShaderType); if (!aShader->Create (theCtx)) { aShader->Release (theCtx.operator->()); return Standard_False; } - TCollection_AsciiString aSource = aDeclarations + anIter.Value()->Source(); TCollection_AsciiString anExtensions = "// Enable extensions used in OCCT GLSL programs\n"; if (theCtx->hasDrawBuffers) { @@ -238,29 +304,37 @@ Standard_Boolean OpenGl_ShaderProgram::Initialize (const Handle(OpenGl_Context)& #endif } + TCollection_AsciiString aPrecisionHeader; + if (anIter.Value()->Type() == Graphic3d_TOS_FRAGMENT) + { + #if defined(GL_ES_VERSION_2_0) + aPrecisionHeader = theCtx->hasHighp + ? "precision highp float;\n" + "precision highp int;\n" + : "precision mediump float;\n" + "precision mediump int;\n"; + #endif + } + + TCollection_AsciiString aHeaderType; switch (anIter.Value()->Type()) { - case Graphic3d_TOS_VERTEX: - { - aSource = aHeader + TCollection_AsciiString ("#define VERTEX_SHADER\n") + anExtensions + aSource; - break; - } - case Graphic3d_TOS_FRAGMENT: - { - #if defined(GL_ES_VERSION_2_0) - TCollection_AsciiString aPrefix (theCtx->hasHighp - ? "precision highp float;\n" - "precision highp int;\n" - : "precision mediump float;\n" - "precision mediump int;\n"); - aSource = aHeader + anExtensions + aPrefix + aSource; - #else - aSource = aHeader + anExtensions + aSource; - #endif - break; - } + case Graphic3d_TOS_COMPUTE: { aHeaderType = "#define COMPUTE_SHADER\n"; break; } + case Graphic3d_TOS_VERTEX: { aHeaderType = "#define VERTEX_SHADER\n"; break; } + case Graphic3d_TOS_TESS_CONTROL: { aHeaderType = "#define TESS_CONTROL_SHADER\n"; break; } + case Graphic3d_TOS_TESS_EVALUATION: { aHeaderType = "#define TESS_EVALUATION_SHADER\n"; break; } + case Graphic3d_TOS_GEOMETRY: { aHeaderType = "#define GEOMETRY_SHADER\n"; break; } + case Graphic3d_TOS_FRAGMENT: { aHeaderType = "#define FRAGMENT_SHADER\n"; break; } } + const TCollection_AsciiString aSource = aHeaderVer // #version - header defining GLSL version, should be first + + (!aHeaderVer.IsEmpty() ? "\n" : "") + + anExtensions // #extension - list of enabled extensions, should be second + + aPrecisionHeader // precision - default precision qualifiers, should be before any code + + aHeaderType // auxiliary macros defining a shader stage (type) + + 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)) { theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aSource); diff --git a/src/OpenGl/OpenGl_ShaderProgram.hxx b/src/OpenGl/OpenGl_ShaderProgram.hxx index ea7dc6ca84..123d8324b7 100755 --- a/src/OpenGl/OpenGl_ShaderProgram.hxx +++ b/src/OpenGl/OpenGl_ShaderProgram.hxx @@ -210,6 +210,9 @@ public: return myProgramID; } + //! Return TRUE if program defines tessellation stage. + Standard_Boolean HasTessellationStage() const { return myHasTessShader; } + private: //! Returns index of last modification of variables of specified state type. @@ -551,6 +554,7 @@ protected: OpenGl_ShaderList myShaderObjects; //!< List of attached shader objects Handle(Graphic3d_ShaderProgram) myProxy; //!< Proxy shader program (from application layer) Standard_Integer myShareCount; //!< program users count, initialized with 1 (already shared by one user) + Standard_Boolean myHasTessShader; //!< flag indicating that program defines tessellation stage protected: diff --git a/src/Prs3d/Prs3d_Drawer.cxx b/src/Prs3d/Prs3d_Drawer.cxx index 855093d43e..291efd66cc 100644 --- a/src/Prs3d/Prs3d_Drawer.cxx +++ b/src/Prs3d/Prs3d_Drawer.cxx @@ -1089,10 +1089,11 @@ inline void setAspectProgram (const Handle(Graphic3d_ShaderProgram)& theProgram, // function : SetShaderProgram // purpose : // ======================================================================= -void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram, +bool Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram, const Graphic3d_GroupAspect theAspect, const bool theToOverrideDefaults) { + bool isUpdateNeeded = false; switch (theAspect) { case Graphic3d_ASPECT_LINE: @@ -1101,6 +1102,7 @@ void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP { if (!myHasOwnUIsoAspect) { + isUpdateNeeded = true; Handle(Prs3d_IsoAspect) anAspect = UIsoAspect(); if (!myLink.IsNull()) { @@ -1112,6 +1114,7 @@ void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP } if (!myHasOwnVIsoAspect) { + isUpdateNeeded = true; Handle(Prs3d_IsoAspect) anAspect = VIsoAspect(); if (!myLink.IsNull()) { @@ -1123,62 +1126,74 @@ void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP } 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; } @@ -1208,13 +1223,14 @@ void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP setAspectProgram (theProgram, true, myDatumAspect->LineAspect(Prs3d_DP_ZAxis)); } setAspectProgram (theProgram, myHasOwnArrowAspect, myArrowAspect); - return; + return isUpdateNeeded; } case Graphic3d_ASPECT_TEXT: { if (theToOverrideDefaults && !myHasOwnTextAspect) { + isUpdateNeeded = true; myTextAspect = new Prs3d_TextAspect(); myHasOwnTextAspect = true; if (!myLink.IsNull()) @@ -1224,13 +1240,14 @@ void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP } setAspectProgram (theProgram, myHasOwnTextAspect, myTextAspect); - return; + return isUpdateNeeded; } case Graphic3d_ASPECT_MARKER: { if (theToOverrideDefaults && !myHasOwnPointAspect) { + isUpdateNeeded = true; myPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.0); myHasOwnPointAspect = true; if (!myLink.IsNull()) @@ -1240,13 +1257,14 @@ void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP } setAspectProgram (theProgram, myHasOwnPointAspect, myPointAspect); - return; + return isUpdateNeeded; } case Graphic3d_ASPECT_FILL_AREA: { if (theToOverrideDefaults && !myHasOwnShadingAspect) { + isUpdateNeeded = true; myShadingAspect = new Prs3d_ShadingAspect(); myHasOwnShadingAspect = true; if (!myLink.IsNull()) @@ -1255,7 +1273,8 @@ void Prs3d_Drawer::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theP } } setAspectProgram (theProgram, myHasOwnShadingAspect, myShadingAspect); - return; + return isUpdateNeeded; } } + return false; } diff --git a/src/Prs3d/Prs3d_Drawer.hxx b/src/Prs3d/Prs3d_Drawer.hxx index ac1b395314..06e1d6cd80 100644 --- a/src/Prs3d/Prs3d_Drawer.hxx +++ b/src/Prs3d/Prs3d_Drawer.hxx @@ -842,7 +842,8 @@ public: //! @param theAspect the type of primitives //! @param theToOverrideDefaults if true then non-overridden attributes using defaults will be allocated and copied from the Link; //! otherwise, only already customized attributes will be changed - Standard_EXPORT void SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram, + //! @return TRUE if presentation should be recomputed after creating aspects not previously customized (if theToOverrideDefaults is also TRUE) + Standard_EXPORT bool SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram, const Graphic3d_GroupAspect theAspect, const bool theToOverrideDefaults = false); diff --git a/src/Shaders/Declarations.glsl b/src/Shaders/Declarations.glsl index efdfb2dbdf..ef704d594a 100644 --- a/src/Shaders/Declarations.glsl +++ b/src/Shaders/Declarations.glsl @@ -49,20 +49,22 @@ THE_ATTRIBUTE vec3 occNormal; THE_ATTRIBUTE vec4 occTexCoord; THE_ATTRIBUTE vec4 occVertColor; -#elif (__VERSION__ >= 130) - #ifdef OCC_ENABLE_draw_buffers - out vec4 occFragColorArray[2]; - #define occFragColor occFragColorArray[0] - #define occFragCoverage occFragColorArray[1] +#elif defined(FRAGMENT_SHADER) + #if (__VERSION__ >= 130) + #ifdef OCC_ENABLE_draw_buffers + out vec4 occFragColorArray[2]; + #define occFragColor occFragColorArray[0] + #define occFragCoverage occFragColorArray[1] + #else + out vec4 occFragColor; + #endif #else - out vec4 occFragColor; - #endif -#else - #ifdef OCC_ENABLE_draw_buffers - #define occFragColor gl_FragData[0] - #define occFragCoverage gl_FragData[1] - #else - #define occFragColor gl_FragColor + #ifdef OCC_ENABLE_draw_buffers + #define occFragColor gl_FragData[0] + #define occFragCoverage gl_FragData[1] + #else + #define occFragColor gl_FragColor + #endif #endif #endif diff --git a/src/Shaders/Shaders_Declarations_glsl.pxx b/src/Shaders/Shaders_Declarations_glsl.pxx index 488d06d8e4..ee2bba3157 100644 --- a/src/Shaders/Shaders_Declarations_glsl.pxx +++ b/src/Shaders/Shaders_Declarations_glsl.pxx @@ -52,20 +52,22 @@ static const char Shaders_Declarations_glsl[] = " THE_ATTRIBUTE vec3 occNormal;\n" " THE_ATTRIBUTE vec4 occTexCoord;\n" " THE_ATTRIBUTE vec4 occVertColor;\n" - "#elif (__VERSION__ >= 130)\n" - " #ifdef OCC_ENABLE_draw_buffers\n" - " out vec4 occFragColorArray[2];\n" - " #define occFragColor occFragColorArray[0]\n" - " #define occFragCoverage occFragColorArray[1]\n" + "#elif defined(FRAGMENT_SHADER)\n" + " #if (__VERSION__ >= 130)\n" + " #ifdef OCC_ENABLE_draw_buffers\n" + " out vec4 occFragColorArray[2];\n" + " #define occFragColor occFragColorArray[0]\n" + " #define occFragCoverage occFragColorArray[1]\n" + " #else\n" + " out vec4 occFragColor;\n" + " #endif\n" " #else\n" - " out vec4 occFragColor;\n" - " #endif\n" - "#else\n" - " #ifdef OCC_ENABLE_draw_buffers\n" - " #define occFragColor gl_FragData[0]\n" - " #define occFragCoverage gl_FragData[1]\n" - " #else\n" - " #define occFragColor gl_FragColor\n" + " #ifdef OCC_ENABLE_draw_buffers\n" + " #define occFragColor gl_FragData[0]\n" + " #define occFragCoverage gl_FragData[1]\n" + " #else\n" + " #define occFragColor gl_FragColor\n" + " #endif\n" " #endif\n" "#endif\n" "\n" diff --git a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx index 114b6ac32d..0d5e9c6885 100644 --- a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx +++ b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx @@ -532,6 +532,50 @@ static int VGlInfo (Draw_Interpretor& theDI, return 0; } +//! Parse shader type argument. +static bool parseShaderTypeArg (Graphic3d_TypeOfShaderObject& theType, + const TCollection_AsciiString& theArg) +{ + if (theArg == "-vertex" + || theArg == "-vert") + { + theType = Graphic3d_TOS_VERTEX; + } + else if (theArg == "-tessevaluation" + || theArg == "-tesseval" + || theArg == "-evaluation" + || theArg == "-eval") + { + theType = Graphic3d_TOS_TESS_EVALUATION; + } + else if (theArg == "-tesscontrol" + || theArg == "-tessctrl" + || theArg == "-control" + || theArg == "-ctrl") + { + theType = Graphic3d_TOS_TESS_CONTROL; + } + else if (theArg == "-geometry" + || theArg == "-geom") + { + theType = Graphic3d_TOS_GEOMETRY; + } + else if (theArg == "-fragment" + || theArg == "-frag") + { + theType = Graphic3d_TOS_FRAGMENT; + } + else if (theArg == "-compute" + || theArg == "-comp") + { + theType = Graphic3d_TOS_COMPUTE; + } + else + { + return false; + } + return true; +} //============================================================================== //function : VShaderProg @@ -544,150 +588,219 @@ static Standard_Integer VShaderProg (Draw_Interpretor& /*theDI*/, Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); if (aCtx.IsNull()) { - std::cerr << "Use 'vinit' command before " << theArgVec[0] << "\n"; + std::cout << "Error: no active view.\n"; return 1; } else if (theArgNb < 2) { - std::cerr << theArgVec[0] << " syntax error: lack of arguments\n"; + std::cout << "Syntax error: lack of arguments\n"; return 1; } - TCollection_AsciiString aLastArg (theArgVec[theArgNb - 1]); - aLastArg.LowerCase(); - const Standard_Boolean toTurnOff = aLastArg == "off"; - Standard_Integer anArgsNb = theArgNb - 1; - Handle(Graphic3d_ShaderProgram) aProgram; - if (!toTurnOff - && aLastArg == "phong") + bool isExplicitShaderType = false; + Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram(); + NCollection_Sequence aPrsList; + Graphic3d_GroupAspect aGroupAspect = Graphic3d_ASPECT_FILL_AREA; + bool isSetGroupAspect = false; + for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) { - const TCollection_AsciiString& aShadersRoot = Graphic3d_ShaderProgram::ShadersFolder(); - if (aShadersRoot.IsEmpty()) - { - std::cerr << "Both environment variables CSF_ShadersDirectory and CASROOT are undefined!\n" - << "At least one should be defined to load Phong program.\n"; - return 1; - } + TCollection_AsciiString anArg (theArgVec[anArgIter]); + anArg.LowerCase(); + Graphic3d_TypeOfShaderObject aShaderTypeArg = Graphic3d_TypeOfShaderObject(-1); + if (!aProgram.IsNull() + && aProgram->ShaderObjects().IsEmpty() + && (anArg == "-off" + || anArg == "off")) + { + aProgram.Nullify(); + } + else if (!aProgram.IsNull() + && aProgram->ShaderObjects().IsEmpty() + && (anArg == "-phong" + || anArg == "phong")) + { + const TCollection_AsciiString& aShadersRoot = Graphic3d_ShaderProgram::ShadersFolder(); + if (aShadersRoot.IsEmpty()) + { + std::cout << "Error: both environment variables CSF_ShadersDirectory and CASROOT are undefined!\n" + "At least one should be defined to load Phong program.\n"; + return 1; + } - const TCollection_AsciiString aSrcVert = aShadersRoot + "/PhongShading.vs"; - const TCollection_AsciiString aSrcFrag = aShadersRoot + "/PhongShading.fs"; + const TCollection_AsciiString aSrcVert = aShadersRoot + "/PhongShading.vs"; + const TCollection_AsciiString aSrcFrag = aShadersRoot + "/PhongShading.fs"; + if (!aSrcVert.IsEmpty() + && !OSD_File (aSrcVert).Exists()) + { + std::cout << "Error: PhongShading.vs is not found\n"; + return 1; + } + if (!aSrcFrag.IsEmpty() + && !OSD_File (aSrcFrag).Exists()) + { + std::cout << "Error: PhongShading.fs is not found\n"; + return 1; + } - if (!aSrcVert.IsEmpty() - && !OSD_File (aSrcVert).Exists()) - { - std::cerr << "Error: PhongShading.vs is not found\n"; - return 1; + aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, aSrcVert)); + aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, aSrcFrag)); } - if (!aSrcFrag.IsEmpty() - && !OSD_File (aSrcFrag).Exists()) + else if (aPrsList.IsEmpty() + && anArg == "*") { - std::cerr << "Error: PhongShading.fs is not found\n"; - return 1; - } - - aProgram = new Graphic3d_ShaderProgram(); - aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, aSrcVert)); - aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, aSrcFrag)); - } - if (!toTurnOff - && aProgram.IsNull()) - { - if (theArgNb < 3) - { - std::cout << "Syntax error: lack of arguments\n"; - return 1; + // } - - const TCollection_AsciiString aSrcVert = theArgVec[theArgNb - 2]; - const TCollection_AsciiString aSrcFrag = theArgVec[theArgNb - 1]; - if (aSrcVert.IsEmpty() || aSrcFrag.IsEmpty()) - { - std::cout << "Syntax error: lack of arguments\n"; - return 1; + else if (!isSetGroupAspect + && anArgIter + 1 < theArgNb + && (anArg == "-primtype" + || anArg == "-primitivetype" + || anArg == "-groupaspect" + || anArg == "-aspecttype" + || anArg == "-aspect")) + { + isSetGroupAspect = true; + TCollection_AsciiString aPrimTypeStr (theArgVec[++anArgIter]); + aPrimTypeStr.LowerCase(); + if (aPrimTypeStr == "line") + { + aGroupAspect = Graphic3d_ASPECT_LINE; + } + else if (aPrimTypeStr == "tris" + || aPrimTypeStr == "triangles" + || aPrimTypeStr == "fill" + || aPrimTypeStr == "fillarea" + || aPrimTypeStr == "shading" + || aPrimTypeStr == "shade") + { + aGroupAspect = Graphic3d_ASPECT_FILL_AREA; + } + else if (aPrimTypeStr == "text") + { + aGroupAspect = Graphic3d_ASPECT_TEXT; + } + else if (aPrimTypeStr == "marker" + || aPrimTypeStr == "point" + || aPrimTypeStr == "pnt") + { + aGroupAspect = Graphic3d_ASPECT_MARKER; + } + else + { + std::cerr << "Syntax error at '" << aPrimTypeStr << "'\n"; + return 1; + } } - - const bool isVertFile = OSD_File (aSrcVert).Exists(); - const bool isFragFile = OSD_File (aSrcFrag).Exists(); - if (!isVertFile - && aSrcVert.Search ("gl_Position") == -1) + else if (anArgIter + 1 < theArgNb + && !aProgram.IsNull() + && aProgram->Header().IsEmpty() + && (anArg == "-version" + || anArg == "-glslversion" + || anArg == "-header" + || anArg == "-glslheader")) { - std::cerr << "Error: non-existing or invalid vertex shader source\n"; - return 1; + TCollection_AsciiString aHeader (theArgVec[++anArgIter]); + if (aHeader.IsIntegerValue()) + { + aHeader = TCollection_AsciiString ("#version ") + aHeader; + } + aProgram->SetHeader (aHeader); } - if (!isFragFile - && aSrcFrag.Search ("occFragColor") == -1) + else if (!anArg.StartsWith ("-") + && GetMapOfAIS().IsBound2 (theArgVec[anArgIter])) { - std::cerr << "Error: non-existing or invalid fragment shader source\n"; - return 1; + Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (theArgVec[anArgIter])); + if (anIO.IsNull()) + { + std::cerr << "Syntax error: " << theArgVec[anArgIter] << " is not an AIS object\n"; + return 1; + } + aPrsList.Append (anIO); } - - aProgram = new Graphic3d_ShaderProgram(); - aProgram->AttachShader (isVertFile - ? Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, aSrcVert) - : Graphic3d_ShaderObject::CreateFromSource(Graphic3d_TOS_VERTEX, aSrcVert)); - aProgram->AttachShader (isFragFile - ? Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_FRAGMENT, aSrcFrag) - : Graphic3d_ShaderObject::CreateFromSource(Graphic3d_TOS_FRAGMENT, aSrcFrag)); - anArgsNb = theArgNb - 2; - } - - Handle(AIS_InteractiveObject) anIO; - if (anArgsNb <= 1 - || *theArgVec[1] == '*') - { - for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); - anIter.More(); anIter.Next()) + else if (!aProgram.IsNull() + && ((anArgIter + 1 < theArgNb && parseShaderTypeArg (aShaderTypeArg, anArg)) + || (!isExplicitShaderType && aProgram->ShaderObjects().Size() < 2))) { - anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); - if (anIO.IsNull()) + TCollection_AsciiString aShaderPath (theArgVec[anArgIter]); + if (aShaderTypeArg != Graphic3d_TypeOfShaderObject(-1)) { - continue; + aShaderPath = (theArgVec[++anArgIter]); + isExplicitShaderType = true; } - if (!anIO->Attributes()->HasOwnShadingAspect()) + const bool isSrcFile = OSD_File (aShaderPath).Exists(); + Handle(Graphic3d_ShaderObject) aShader = isSrcFile + ? Graphic3d_ShaderObject::CreateFromFile (Graphic3d_TOS_VERTEX, aShaderPath) + : Graphic3d_ShaderObject::CreateFromSource(Graphic3d_TOS_VERTEX, aShaderPath); + const TCollection_AsciiString& aShaderSrc = aShader->Source(); + + const bool hasVertPos = aShaderSrc.Search ("gl_Position") != -1; + const bool hasFragColor = aShaderSrc.Search ("occFragColor") != -1 + || aShaderSrc.Search ("gl_FragColor") != -1 + || aShaderSrc.Search ("gl_FragData") != -1; + Graphic3d_TypeOfShaderObject aShaderType = aShaderTypeArg; + if (aShaderType == Graphic3d_TypeOfShaderObject(-1)) { - Handle(Prs3d_ShadingAspect) aNewAspect = new Prs3d_ShadingAspect(); - *aNewAspect->Aspect() = *anIO->Attributes()->ShadingAspect()->Aspect(); - aNewAspect->Aspect()->SetShaderProgram (aProgram); - anIO->Attributes()->SetShadingAspect (aNewAspect); - aCtx->Redisplay (anIO, Standard_False); + if (hasVertPos + && !hasFragColor) + { + aShaderType = Graphic3d_TOS_VERTEX; + } + if (hasFragColor + && !hasVertPos) + { + aShaderType = Graphic3d_TOS_FRAGMENT; + } } - else + if (aShaderType == Graphic3d_TypeOfShaderObject(-1)) { - anIO->Attributes()->SetShaderProgram (aProgram, Graphic3d_ASPECT_FILL_AREA); - anIO->SynchronizeAspects(); + std::cerr << "Error: non-existing or invalid shader source\n"; + return 1; } + + aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromSource (aShaderType, aShaderSrc)); + } + else + { + std::cerr << "Syntax error at '" << anArg << "'\n"; + return 1; } - aCtx->UpdateCurrentViewer(); - return 0; } - for (Standard_Integer anArgIter = 1; anArgIter < anArgsNb; ++anArgIter) + ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aGlobalPrsIter (GetMapOfAIS()); + NCollection_Sequence::Iterator aPrsIter (aPrsList); + const bool isGlobalList = aPrsList.IsEmpty(); + for (;;) { - const TCollection_AsciiString aName (theArgVec[anArgIter]); - if (!GetMapOfAIS().IsBound2 (aName)) + Handle(AIS_InteractiveObject) anIO; + if (isGlobalList) { - std::cerr << "Warning: " << aName.ToCString() << " is not displayed\n"; - continue; + if (!aGlobalPrsIter.More()) + { + break; + } + anIO = Handle(AIS_InteractiveObject)::DownCast (aGlobalPrsIter.Key1()); + aGlobalPrsIter.Next(); + if (anIO.IsNull()) + { + continue; + } } - anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName)); - if (anIO.IsNull()) + else { - std::cerr << "Warning: " << aName.ToCString() << " is not an AIS object\n"; - continue; + if (!aPrsIter.More()) + { + break; + } + anIO = aPrsIter.Value(); + aPrsIter.Next(); } - if (!anIO->Attributes()->HasOwnShadingAspect()) + if (anIO->Attributes()->SetShaderProgram (aProgram, aGroupAspect, true)) { - Handle(Prs3d_ShadingAspect) aNewAspect = new Prs3d_ShadingAspect(); - *aNewAspect->Aspect() = *anIO->Attributes()->ShadingAspect()->Aspect(); - aNewAspect->Aspect()->SetShaderProgram (aProgram); - anIO->Attributes()->SetShadingAspect (aNewAspect); aCtx->Redisplay (anIO, Standard_False); } else { - anIO->Attributes()->SetShaderProgram (aProgram, Graphic3d_ASPECT_FILL_AREA); anIO->SynchronizeAspects(); } } @@ -720,10 +833,12 @@ void ViewerTest::OpenGlCommands(Draw_Interpretor& theCommands) "\n\t\t: [GL_SHADING_LANGUAGE_VERSION] [GL_EXTENSIONS]" "\n\t\t: print OpenGL info", __FILE__, VGlInfo, aGroup); - theCommands.Add("vshaderprog", - " 'vshaderprog [name] pathToVertexShader pathToFragmentShader'" - "\n\t\t: or 'vshaderprog [name] off' to disable GLSL program" - "\n\t\t: or 'vshaderprog [name] phong' to enable per-pixel lighting calculations" - "\n\t\t: * might be used to specify all displayed objects", + theCommands.Add("vshader", + "vshader name -vert VertexShader -frag FragmentShader [-geom GeometryShader]" + "\n\t\t: [-off] [-phong] [-aspect {shading|line|point|text}=shading]" + "\n\t\t: [-header VersionHeader]" + "\n\t\t: [-tessControl TessControlShader -tesseval TessEvaluationShader]" + "\n\t\t: Assign custom GLSL program to presentation aspects.", __FILE__, VShaderProg, aGroup); + theCommands.Add("vshaderprog", "Alias for vshader", __FILE__, VShaderProg, aGroup); } diff --git a/tests/v3d/glsl/begin b/tests/v3d/glsl/begin deleted file mode 100644 index 7b04e56f2d..0000000000 --- a/tests/v3d/glsl/begin +++ /dev/null @@ -1,3 +0,0 @@ -vclear -vclose ALL -vinit View1 diff --git a/tests/v3d/glsl/geom1 b/tests/v3d/glsl/geom1 new file mode 100644 index 0000000000..872bed0ca0 --- /dev/null +++ b/tests/v3d/glsl/geom1 @@ -0,0 +1,55 @@ +puts "========" +puts "0029074: Visualization, TKOpenGl - support Geometry Shader definition" +puts "========" + +pload MODELING VISUALIZATION + +set aShaderVert " +out vec4 VertColor; +void main() { + VertColor = occColor; + gl_Position = occVertex; +}" + +# define a Geometry shader drawing shrinked triangles +set aShaderGeom " +layout(triangles) in; +layout(triangle_strip, max_vertices=3) out; +in vec4 VertColor\[3\]; +out vec4 Color; +void main() { + mat4 aMat = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix; + vec3 aCenter = vec3 (0.0, 0.0, 0.0); + for (int aTriVertIter = 0; aTriVertIter < 3; ++aTriVertIter) { + aCenter += gl_in\[aTriVertIter\].gl_Position.xyz; + } + aCenter /= 3.0; + for (int aTriVertIter = 0; aTriVertIter < 3; ++aTriVertIter) { + vec3 aVec = gl_in\[aTriVertIter\].gl_Position.xyz - aCenter; + vec3 aVertRes = aCenter + normalize (aVec) * length (aVec) * 0.75; + gl_Position = aMat * vec4 (aVertRes, 1.0); + Color = VertColor\[aTriVertIter\] * 2.0; + EmitVertex(); + } + EndPrimitive(); +}" + +set aShaderFrag " +in vec4 Color; +void main() { + occFragColor = Color; +}" + +# draw a box +box b 1 2 3 +vcaps -core +vclear +vinit View1 +vaxo +vdisplay -dispMode 1 -mutable b +vfit +vrotate 0.2 0.0 0.0 +vdump $::imagedir/${::casename}_normal.png + +vshaderprog b -vert $aShaderVert -geom $aShaderGeom -frag $aShaderFrag +vdump $::imagedir/${::casename}_geom.png diff --git a/tests/v3d/glsl/gouraud_dir1 b/tests/v3d/glsl/gouraud_dir1 index 37541b0918..b8c7e0c17e 100644 --- a/tests/v3d/glsl/gouraud_dir1 +++ b/tests/v3d/glsl/gouraud_dir1 @@ -4,6 +4,9 @@ puts "Visual comparison with the reference snapshot should be performed for this puts "========" # setup viewer +vclear +vclose ALL +vinit View1 vcaps -ffp 0 vrenderparams -shadingModel vert diff --git a/tests/v3d/glsl/gouraud_dir2 b/tests/v3d/glsl/gouraud_dir2 index 72f3a41b9c..dcf0598dda 100644 --- a/tests/v3d/glsl/gouraud_dir2 +++ b/tests/v3d/glsl/gouraud_dir2 @@ -3,7 +3,10 @@ puts "Per-vertex lighting using built-in GLSL program, two directional light sou puts "Visual comparison with the reference snapshot should be performed for this test case." puts "========" -# setup viewer +# setup viewervclear +vclear +vclose ALL +vinit View1 vcaps -ffp 0 vrenderparams -shadingModel vert vlight delete 0 diff --git a/tests/v3d/glsl/gouraud_pos1 b/tests/v3d/glsl/gouraud_pos1 index 6fdb4291f9..61ae4f71bd 100644 --- a/tests/v3d/glsl/gouraud_pos1 +++ b/tests/v3d/glsl/gouraud_pos1 @@ -3,6 +3,10 @@ puts "Per-vertex lighting using built-in GLSL program, one positional light sour puts "Visual comparison with the reference snapshot should be performed for this test case." puts "========" +vclear +vclose ALL +vinit View1 + # create objects set anX 0.001 circle c 0 0 0 0.001 diff --git a/tests/v3d/glsl/gouraud_spot1 b/tests/v3d/glsl/gouraud_spot1 index 7adcf8defa..3ac356cae6 100644 --- a/tests/v3d/glsl/gouraud_spot1 +++ b/tests/v3d/glsl/gouraud_spot1 @@ -3,6 +3,10 @@ puts "Per-vertex lighting using built-in GLSL program, one spot light source." puts "Visual comparison with the reference snapshot should be performed for this test case." puts "========" +vclear +vclose ALL +vinit View1 + # create objects set anX 0.001 circle c 0 0 0 0.001 diff --git a/tests/v3d/glsl/light_off b/tests/v3d/glsl/light_off index e5a2c6b0e5..6672a2a887 100644 --- a/tests/v3d/glsl/light_off +++ b/tests/v3d/glsl/light_off @@ -6,8 +6,9 @@ puts "========" box b 1 2 3 # draw box -vinit View1 vclear +vclose ALL +vinit View1 vsetdispmode 1 vdisplay b vfit diff --git a/tests/v3d/glsl/phong_box b/tests/v3d/glsl/phong_box index be9b093afb..583c3b60d1 100644 --- a/tests/v3d/glsl/phong_box +++ b/tests/v3d/glsl/phong_box @@ -6,8 +6,9 @@ puts "========" box b 1 2 3 # draw box -vinit View1 vclear +vclose ALL +vinit View1 vsetdispmode 1 vaxo vdisplay b diff --git a/tests/v3d/glsl/phong_couple b/tests/v3d/glsl/phong_couple index 2922b1a814..f5bbf7cd4e 100644 --- a/tests/v3d/glsl/phong_couple +++ b/tests/v3d/glsl/phong_couple @@ -8,8 +8,9 @@ tclean f box b 2 0 0 1 0.5 0.25 # draw box -vinit View1 vclear +vclose ALL +vinit View1 vdefaults -absDefl 0.5 vsetdispmode 1 vaxo diff --git a/tests/v3d/glsl/phong_dir1 b/tests/v3d/glsl/phong_dir1 index d6b31b54d8..e090d83637 100644 --- a/tests/v3d/glsl/phong_dir1 +++ b/tests/v3d/glsl/phong_dir1 @@ -4,6 +4,9 @@ puts "Visual comparison with the reference snapshot should be performed for this puts "========" # setup viewer +vclear +vclose ALL +vinit View1 vcaps -ffp 0 vrenderparams -shadingModel phong diff --git a/tests/v3d/glsl/phong_dir2 b/tests/v3d/glsl/phong_dir2 index 4eb064b658..77f346f087 100644 --- a/tests/v3d/glsl/phong_dir2 +++ b/tests/v3d/glsl/phong_dir2 @@ -4,6 +4,9 @@ puts "Visual comparison with the reference snapshot should be performed for this puts "========" # setup viewer +vclear +vclose ALL +vinit View1 vcaps -ffp 0 vrenderparams -shadingModel phong vlight delete 0 diff --git a/tests/v3d/glsl/phong_fuse b/tests/v3d/glsl/phong_fuse index 6d183adb36..a2f350f42f 100644 --- a/tests/v3d/glsl/phong_fuse +++ b/tests/v3d/glsl/phong_fuse @@ -7,8 +7,9 @@ restore [locate_data_file occ/fuse.brep] f tclean f # draw box -vinit View1 vclear +vclose ALL +vinit View1 vdefaults -absDefl 0.5 vsetdispmode 1 vaxo diff --git a/tests/v3d/glsl/phong_fuse2 b/tests/v3d/glsl/phong_fuse2 index 0f465ef0d4..e81fe63ea7 100644 --- a/tests/v3d/glsl/phong_fuse2 +++ b/tests/v3d/glsl/phong_fuse2 @@ -7,8 +7,9 @@ restore [locate_data_file occ/fuse.brep] f tclean f # draw box -vinit View1 vclear +vclose ALL +vinit View1 vdefaults -absDefl 0.5 vsetdispmode 1 vaxo diff --git a/tests/v3d/glsl/phong_plastic b/tests/v3d/glsl/phong_plastic index c03aef2c8e..0a2cb6dfa9 100644 --- a/tests/v3d/glsl/phong_plastic +++ b/tests/v3d/glsl/phong_plastic @@ -6,8 +6,9 @@ puts "========" box b 1 2 3 # draw box -vinit View1 vclear +vclose ALL +vinit View1 vsetdispmode 1 vaxo vdisplay b diff --git a/tests/v3d/glsl/phong_pos1 b/tests/v3d/glsl/phong_pos1 index 687ef5a824..f8d24157bf 100644 --- a/tests/v3d/glsl/phong_pos1 +++ b/tests/v3d/glsl/phong_pos1 @@ -3,6 +3,10 @@ puts "Per-fragment lighting using built-in GLSL program, one positional light so puts "Visual comparison with the reference snapshot should be performed for this test case." puts "========" +vclear +vclose ALL +vinit View1 + # create objects set anX 0.001 circle c 0 0 0 0.001 diff --git a/tests/v3d/glsl/phong_sides b/tests/v3d/glsl/phong_sides index 6d7fe78850..3aa6794504 100644 --- a/tests/v3d/glsl/phong_sides +++ b/tests/v3d/glsl/phong_sides @@ -7,8 +7,9 @@ box b 1 2 3 explode b F # draw box -vinit View1 vclear +vclose ALL +vinit View1 vsetdispmode 1 vaxo vdisplay b_1 b_2 diff --git a/tests/v3d/glsl/phong_spot1 b/tests/v3d/glsl/phong_spot1 index d6c45f2507..6a61810325 100644 --- a/tests/v3d/glsl/phong_spot1 +++ b/tests/v3d/glsl/phong_spot1 @@ -3,6 +3,10 @@ puts "Per-fragment lighting using built-in GLSL program, one spot light source." puts "Visual comparison with the reference snapshot should be performed for this test case." puts "========" +vclear +vclose ALL +vinit View1 + # create objects set anX 0.001 circle c 0 0 0 0.001 diff --git a/tests/v3d/glsl/phong_views b/tests/v3d/glsl/phong_views index 9c4a4102ec..3b65fc9d0d 100644 --- a/tests/v3d/glsl/phong_views +++ b/tests/v3d/glsl/phong_views @@ -6,8 +6,9 @@ puts "========" box b 1 2 3 # draw box -vinit View1 vclear +vclose ALL +vinit View1 vsetdispmode 1 vaxo vdisplay b diff --git a/tests/v3d/glsl/rendscale b/tests/v3d/glsl/rendscale index f6470bf151..4ba3d39057 100644 --- a/tests/v3d/glsl/rendscale +++ b/tests/v3d/glsl/rendscale @@ -15,6 +15,7 @@ if { "$aFontFile" != "" } { box b 1 2 3 vclear +vclose ALL vinit View1 vdisplay b vfit diff --git a/tests/v3d/glsl/stereo b/tests/v3d/glsl/stereo index 2ba9754b4b..b27d0ffbf7 100644 --- a/tests/v3d/glsl/stereo +++ b/tests/v3d/glsl/stereo @@ -3,8 +3,9 @@ puts "Stereo output modes" puts "========" restore [locate_data_file occ/fuse.brep] f -vinit View1 vclear +vclose ALL +vinit View1 vsetdispmode 1 vaxo vdisplay f diff --git a/tests/v3d/glsl/stipple_line b/tests/v3d/glsl/stipple_line index 8847fbe206..e66b809a4d 100644 --- a/tests/v3d/glsl/stipple_line +++ b/tests/v3d/glsl/stipple_line @@ -1,6 +1,8 @@ restore [locate_data_file occ/fuse.brep] f vcaps -ffp 1 +vclear +vclose ALL vinit View1 vclear vsetdispmode 0 diff --git a/tests/v3d/glsl/tess1 b/tests/v3d/glsl/tess1 new file mode 100644 index 0000000000..6021fc6a07 --- /dev/null +++ b/tests/v3d/glsl/tess1 @@ -0,0 +1,75 @@ +puts "========" +puts "0029074: Visualization, TKOpenGl - support of Tessellation Shaders" +puts "========" + +pload MODELING VISUALIZATION + +set aShaderVert " +out vec4 VertColor; +void main() { + VertColor = occColor; + gl_Position = occVertex; +}" + +set aShaderTessCtrl " +layout(vertices = 3) out; +void main() { + if (gl_InvocationID == 0) { + gl_TessLevelInner\[0\] = 7.0; + gl_TessLevelOuter\[0\] = 2.0; + gl_TessLevelOuter\[1\] = 3.0; + gl_TessLevelOuter\[2\] = 7.0; + } + gl_out\[gl_InvocationID\].gl_Position = gl_in\[gl_InvocationID\].gl_Position; +}" + +set aShaderTessEval " +layout(triangles, equal_spacing, ccw) in; +void main() { + vec3 aPnt0 = gl_TessCoord.x * gl_in\[0\].gl_Position.xyz; + vec3 aPnt1 = gl_TessCoord.y * gl_in\[1\].gl_Position.xyz; + vec3 aPnt2 = gl_TessCoord.z * gl_in\[2\].gl_Position.xyz; + gl_Position = vec4 (aPnt0 + aPnt1 + aPnt2, 1.0); +}" + +set aShaderGeom " +layout(triangles) in; +layout(triangle_strip, max_vertices=3) out; +void main() { + mat4 aMat = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix; + vec3 aCenter = vec3 (0.0, 0.0, 0.0); + for (int aTriVertIter = 0; aTriVertIter < 3; ++aTriVertIter) { + aCenter += gl_in\[aTriVertIter\].gl_Position.xyz; + } + aCenter /= 3.0; + for (int aTriVertIter = 0; aTriVertIter < 3; ++aTriVertIter) { + vec3 aVec = gl_in\[aTriVertIter\].gl_Position.xyz - aCenter; + vec3 aVertRes = aCenter + normalize (aVec) * length (aVec) * 0.75; + gl_Position = aMat * vec4 (aVertRes, 1.0); + EmitVertex(); + } + EndPrimitive(); +}" + +set aShaderFrag " +void main() { + occFragColor = vec4(1.0, 0.0, 0.0, 1.0); +}" + +# draw a box +box b 1 2 3 +explode b F + +vcaps -core +vclear +vinit View1 +vaxo +vdisplay -dispMode 1 -mutable b_1 +vfit +vrotate 0.2 0.0 0.0 + +# take snapshot with built-in shader +vdump $::imagedir/${::casename}_normal.png + +vshaderprog b_1 -vert $aShaderVert -tessCtrl $aShaderTessCtrl -tessEval $aShaderTessEval -geom $aShaderGeom -frag $aShaderFrag +vdump $::imagedir/${::casename}_tess.png diff --git a/tests/v3d/glsl/texture_multi1 b/tests/v3d/glsl/texture_multi1 index 92456d8faf..85f37962e2 100644 --- a/tests/v3d/glsl/texture_multi1 +++ b/tests/v3d/glsl/texture_multi1 @@ -26,6 +26,7 @@ void main() { # draw a box box b 1 2 3 vclear +vclose ALL vinit View1 vaxo vdisplay -dispMode 1 b @@ -36,5 +37,6 @@ vrotate 0.2 0.0 0.0 vtexture b -tex0 3 -tex1 4 -tex2 5 -tex3 6 vdump $::imagedir/${::casename}_normal.png -vshaderprog b $aShaderVert $aShaderFrag +#vshaderprog b $aShaderVert $aShaderFrag +vshaderprog b -vert $aShaderVert -frag $aShaderFrag vdump $::imagedir/${::casename}_multi.png diff --git a/tests/v3d/glsl/texture_trsf b/tests/v3d/glsl/texture_trsf index cb5ec8b87a..134de5bed1 100644 --- a/tests/v3d/glsl/texture_trsf +++ b/tests/v3d/glsl/texture_trsf @@ -2,6 +2,10 @@ puts "========" puts "Texture 2D transformation (UV coordinates generation)" puts "========" +vclear +vclose ALL +vinit View1 + set aTexture [locate_data_file bug26122_texture_trsf_ref.png] pload MODELING VISUALIZATION box b 1 1 1 diff --git a/tests/v3d/glsl/tiles b/tests/v3d/glsl/tiles index 6d166984a3..ddbe000029 100644 --- a/tests/v3d/glsl/tiles +++ b/tests/v3d/glsl/tiles @@ -16,6 +16,7 @@ if { "$aFontFile" != "" } { } vclear +vclose ALL vinit View1 vraytrace 0 vsetgradientbg 180 200 255 180 180 180 2 -- 2.20.1