Graphic3d_AlphaMode.hxx
+Graphic3d_ArrayFlags.hxx
Graphic3d_ArrayOfPoints.hxx
Graphic3d_ArrayOfPolygons.hxx
Graphic3d_ArrayOfPolylines.hxx
Graphic3d_BoundBuffer.hxx
Graphic3d_BSDF.cxx
Graphic3d_BSDF.hxx
+Graphic3d_Buffer.cxx
Graphic3d_Buffer.hxx
Graphic3d_BufferType.hxx
Graphic3d_Camera.cxx
--- /dev/null
+// Copyright (c) 2018 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _Graphic3d_ArrayFlags_HeaderFile
+#define _Graphic3d_ArrayFlags_HeaderFile
+
+//! Bitmask for primitive array creation.
+typedef Standard_Integer Graphic3d_ArrayFlags;
+
+//! Graphic3d_ArrayFlags bitmask values.
+enum
+{
+ Graphic3d_ArrayFlags_None = 0x00, //!< no flags
+ Graphic3d_ArrayFlags_VertexNormal = 0x01, //!< per-vertex normal attribute
+ Graphic3d_ArrayFlags_VertexColor = 0x02, //!< per-vertex color attribute
+ Graphic3d_ArrayFlags_VertexTexel = 0x04, //!< per-vertex texel coordinates (UV) attribute
+ Graphic3d_ArrayFlags_BoundColor = 0x10,
+};
+
+#endif // _Graphic3d_ArrayFlags_HeaderFile
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 (Graphic3d_TOPA_POINTS).
//! The array must be filled using the AddVertex(Point) method.
+ //! @param theMaxVertexs maximum number of points
+ //! @param theArrayFlags array flags
+ Graphic3d_ArrayOfPoints (Standard_Integer theMaxVertexs,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0, theArrayFlags) {}
+
+ //! Creates an array of points (Graphic3d_TOPA_POINTS).
+ //! The array must be filled using the AddVertex(Point) method.
+ //! @param theMaxVertexs maximum number of points
//! @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) {}
+ Graphic3d_ArrayOfPoints (Standard_Integer theMaxVertexs,
+ Standard_Boolean theHasVColors = Standard_False,
+ Standard_Boolean theHasVNormals = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0,
+ (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None)
+ | (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None)) {}
};
DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolygons, Graphic3d_ArrayOfPrimitives)
public:
- //! Creates an array of polygons, a polygon can be filled as:
+ //! Creates an array of polygons (Graphic3d_TOPA_POLYGONS), a polygon can be filled as:
//! 1) Creating a single polygon defined with his vertexes, i.e:
//! @code
//! myArray = Graphic3d_ArrayOfPolygons (7);
//! @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 theArrayFlags array flags
+ Graphic3d_ArrayOfPolygons (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxBounds,
+ Standard_Integer theMaxEdges,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges, theArrayFlags) {}
+
+ //! Creates an array of polygons (Graphic3d_TOPA_POLYGONS):
+ //! @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 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) {}
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges,
+ (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None)
+ | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None)
+ | (theHasBColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)
+ | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)) {}
};
DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolylines, Graphic3d_ArrayOfPrimitives)
public:
- //! Creates an array of polylines, a polyline can be filled as:
+ //! Creates an array of polylines (Graphic3d_TOPA_POLYLINES), a polyline can be filled as:
//! 1) Creating a single polyline defined with his vertexes, i.e:
//! @code
//! myArray = Graphic3d_ArrayOfPolylines (7);
//! @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 theArrayFlags array flags
+ Graphic3d_ArrayOfPolylines (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxBounds,
+ Standard_Integer theMaxEdges,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges, theArrayFlags) {}
+
+ //! Creates an array of polylines (Graphic3d_TOPA_POLYLINES).
+ //! @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) {}
+ Graphic3d_ArrayOfPolylines (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxBounds = 0,
+ Standard_Integer theMaxEdges = 0,
+ Standard_Boolean theHasVColors = Standard_False,
+ Standard_Boolean theHasBColors = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges,
+ (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None)
+ | (theHasBColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)) {}
};
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ArrayOfPolygons, Graphic3d_ArrayOfPrimitives)
// =======================================================================
-// function : Graphic3d_ArrayOfPrimitives
+// function : init
// purpose :
// =======================================================================
-Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOfPrimitiveArray theType,
- 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)
-: myType (theType),
- myMaxBounds (0),
- myMaxVertexs (0),
- myMaxEdges (0),
- myVNor (0),
- myVTex (0),
- myVCol (0)
+void Graphic3d_ArrayOfPrimitives::init (Graphic3d_TypeOfPrimitiveArray theType,
+ Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxBounds,
+ Standard_Integer theMaxEdges,
+ Graphic3d_ArrayFlags theArrayOptions)
{
+ myType = theType;
+ myVNor = 0;
+ myVTex = 0;
+ myVCol = 0;
+ myAttribs.Nullify();
+ myIndices.Nullify();
+ myBounds.Nullify();
+
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
myAttribs = new Graphic3d_Buffer (anAlloc);
if (theMaxVertexs < 1)
anAttribs[aNbAttribs].Id = Graphic3d_TOA_POS;
anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC3;
++aNbAttribs;
- if (theHasVNormals)
+ if ((theArrayOptions & Graphic3d_ArrayFlags_VertexNormal) != 0)
{
anAttribs[aNbAttribs].Id = Graphic3d_TOA_NORM;
anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC3;
++aNbAttribs;
}
- if (theHasVTexels)
+ if ((theArrayOptions & Graphic3d_ArrayFlags_VertexTexel) != 0)
{
anAttribs[aNbAttribs].Id = Graphic3d_TOA_UV;
anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC2;
++aNbAttribs;
}
- if (theHasVColors)
+ if ((theArrayOptions & Graphic3d_ArrayFlags_VertexColor) != 0)
{
anAttribs[aNbAttribs].Id = Graphic3d_TOA_COLOR;
anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC4UB;
myIndices.Nullify();
return;
}
- memset (myAttribs->ChangeData (0), 0, size_t(myAttribs->Stride) * size_t(myAttribs->NbElements));
+ myAttribs->NbElements = 0;
+ memset (myAttribs->ChangeData (0), 0, size_t(myAttribs->Stride) * size_t(myAttribs->NbMaxElements()));
if (theMaxBounds > 0)
{
myBounds = new Graphic3d_BoundBuffer (anAlloc);
- if (!myBounds->Init (theMaxBounds, theHasFColors))
+ if (!myBounds->Init (theMaxBounds, (theArrayOptions & Graphic3d_ArrayFlags_BoundColor) != 0))
{
myAttribs.Nullify();
myIndices.Nullify();
}
}
}
-
- myAttribs->NbElements = 0;
- myMaxVertexs = theMaxVertexs;
- myMaxBounds = theMaxBounds;
- myMaxEdges = theMaxEdges;
}
// =======================================================================
// =======================================================================
Standard_Integer Graphic3d_ArrayOfPrimitives::AddBound (const Standard_Integer theEdgeNumber)
{
- if (myBounds.IsNull())
- {
- return 0;
- }
- Standard_Integer anIndex = myBounds->NbBounds;
- if (anIndex >= myMaxBounds)
- {
- throw Standard_OutOfRange("TOO many BOUNDS");
- }
-
- myBounds->Bounds[anIndex] = theEdgeNumber;
- myBounds->NbBounds = ++anIndex;
- return anIndex;
+ Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->NbBounds >= myBounds->NbMaxBounds, "TOO many BOUND");
+ myBounds->Bounds[myBounds->NbBounds] = theEdgeNumber;
+ return ++myBounds->NbBounds;
}
// =======================================================================
const Standard_Real theG,
const Standard_Real theB)
{
- if (myBounds.IsNull())
- {
- return 0;
- }
- Standard_Integer anIndex = myBounds->NbBounds;
- if (anIndex >= myMaxBounds)
- {
- throw Standard_OutOfRange("TOO many BOUND");
- }
-
- myBounds->Bounds[anIndex] = theEdgeNumber;
- myBounds->NbBounds = ++anIndex;
- SetBoundColor (anIndex, theR, theG, theB);
- return anIndex;
+ Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->NbBounds >= myBounds->NbMaxBounds, "TOO many BOUND");
+ myBounds->Bounds[myBounds->NbBounds] = theEdgeNumber;
+ ++myBounds->NbBounds;
+ SetBoundColor (myBounds->NbBounds, theR, theG, theB);
+ return myBounds->NbBounds;
}
// =======================================================================
// =======================================================================
Standard_Integer Graphic3d_ArrayOfPrimitives::AddEdge (const Standard_Integer theVertexIndex)
{
- if (myIndices.IsNull())
- {
- return 0;
- }
-
- Standard_Integer anIndex = myIndices->NbElements;
- if (anIndex >= myMaxEdges)
- {
- throw Standard_OutOfRange("TOO many EDGE");
- }
-
- Standard_Integer aVertIndex = theVertexIndex - 1;
- if (theVertexIndex <= 0
- || aVertIndex >= myMaxVertexs)
- {
- throw Standard_OutOfRange("BAD EDGE vertex index");
- }
-
- myIndices->SetIndex (anIndex, aVertIndex);
- myIndices->NbElements = ++anIndex;
- return anIndex;
+ Standard_OutOfRange_Raise_if (myIndices.IsNull() || myIndices->NbElements >= myIndices->NbMaxElements(), "TOO many EDGE");
+ Standard_OutOfRange_Raise_if (theVertexIndex < 1 || theVertexIndex > myAttribs->NbElements, "BAD VERTEX index");
+ const Standard_Integer aVertIndex = theVertexIndex - 1;
+ myIndices->SetIndex (myIndices->NbElements, aVertIndex);
+ return ++myIndices->NbElements;
}
// =======================================================================
#define _Graphic3d_ArrayOfPrimitives_HeaderFile
#include <Graphic3d_BoundBuffer.hxx>
+#include <Graphic3d_ArrayFlags.hxx>
#include <Graphic3d_Buffer.hxx>
#include <Graphic3d_IndexBuffer.hxx>
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
//! 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)
Standard_Boolean HasVertexTexels() const { return myVTex != 0; }
//! Returns the number of defined vertex
- Standard_Integer VertexNumber() const { return !myAttribs.IsNull() ? myAttribs->NbElements : -1; }
+ Standard_Integer VertexNumber() const { return myAttribs->NbElements; }
//! Returns the number of allocated vertex
- Standard_Integer VertexNumberAllocated() const { return myMaxVertexs; }
+ Standard_Integer VertexNumberAllocated() const { return myAttribs->NbMaxElements(); }
//! Returns the number of total items according to the array type.
Standard_EXPORT Standard_Integer ItemNumber() const;
//! @return the actual vertex number.
Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ)
{
- if (myAttribs.IsNull())
- {
- return 0;
- }
const Standard_Integer anIndex = myAttribs->NbElements + 1;
SetVertice (anIndex, theX, theY, theZ);
return anIndex;
Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ,
const Standard_ShortReal theNX, const Standard_ShortReal theNY, const Standard_ShortReal theNZ)
{
- if (myAttribs.IsNull())
- {
- return 0;
- }
const Standard_Integer anIndex = myAttribs->NbElements + 1;
SetVertice (anIndex, theX, theY, theZ);
SetVertexNormal (anIndex, theNX, theNY, theNZ);
Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ,
const Standard_ShortReal theTX, const Standard_ShortReal theTY)
{
- if (myAttribs.IsNull())
- {
- return 0;
- }
const Standard_Integer anIndex = myAttribs->NbElements + 1;
SetVertice (anIndex, theX, theY, theZ);
SetVertexTexel (anIndex, theTX, theTY);
const Standard_ShortReal theNX, const Standard_ShortReal theNY, const Standard_ShortReal theNZ,
const Standard_ShortReal theTX, const Standard_ShortReal theTY)
{
- if (myAttribs.IsNull())
- {
- return 0;
- }
const Standard_Integer anIndex = myAttribs->NbElements + 1;
SetVertice (anIndex, theX, theY, theZ);
SetVertexNormal(anIndex, theNX, theNY, theNZ);
//! Change the vertice of rank theIndex in the array.
void SetVertice (const Standard_Integer theIndex, const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ)
{
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theIndex < 1
- || theIndex > myMaxVertexs)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
Graphic3d_Vec3& aVec = myAttribs->ChangeValue<Graphic3d_Vec3> (theIndex - 1);
aVec.x() = theX;
aVec.y() = theY;
//! Change the vertex color of rank theIndex in the array.
void SetVertexColor (const Standard_Integer theIndex, const Standard_Real theR, const Standard_Real theG, const Standard_Real theB)
{
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theIndex < 1
- || theIndex > myMaxVertexs)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
if (myVCol != 0)
{
Graphic3d_Vec4ub *aColorPtr =
void SetVertexColor (const Standard_Integer theIndex,
const Graphic3d_Vec4ub& theColor)
{
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theIndex < 1
- || theIndex > myMaxVertexs)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
if (myVCol != 0)
{
Graphic3d_Vec4ub *aColorPtr =
//! @endcode
void SetVertexColor (const Standard_Integer theIndex, const Standard_Integer theColor32)
{
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theIndex < 1
- || theIndex > myMaxVertexs)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
if (myVCol != 0)
{
*reinterpret_cast<Standard_Integer* >(myAttribs->changeValue (theIndex - 1) + size_t(myVCol)) = theColor32;
//! Change the vertex normal of rank theIndex in the array.
void SetVertexNormal (const Standard_Integer theIndex, const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ)
{
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theIndex < 1
- || theIndex > myMaxVertexs)
- {
- throw Standard_OutOfRange("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
if (myVNor != 0)
{
Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3* >(myAttribs->changeValue (theIndex - 1) + size_t(myVNor));
//! Change the vertex texel of rank theIndex in the array.
void SetVertexTexel (const Standard_Integer theIndex, const Standard_Real theTX, const Standard_Real theTY)
{
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theIndex < 1
- || theIndex > myMaxVertexs)
- {
- throw Standard_OutOfRange("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
if (myVTex != 0)
{
Graphic3d_Vec2& aVec = *reinterpret_cast<Graphic3d_Vec2* >(myAttribs->changeValue (theIndex - 1) + size_t(myVTex));
void Vertice (const Standard_Integer theRank, Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const
{
theX = theY = theZ = 0.0;
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theRank < 1
- || theRank > myAttribs->NbElements)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
const Graphic3d_Vec3& aVec = myAttribs->Value<Graphic3d_Vec3> (theRank - 1);
theX = Standard_Real(aVec.x());
theY = Standard_Real(aVec.y());
void VertexColor (const Standard_Integer theIndex,
Graphic3d_Vec4ub& theColor) const
{
- if (myAttribs.IsNull()
- || myVCol == 0)
- {
- throw Standard_OutOfRange ("Primitive array does not define color attribute");
- }
-
- if (theIndex < 1
- || theIndex > myAttribs->NbElements)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (myVCol == 0 || theIndex < 1 || theIndex > myAttribs->NbElements, "BAD VERTEX index");
theColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(myAttribs->value (theIndex - 1) + size_t(myVCol));
}
void VertexColor (const Standard_Integer theRank, Standard_Real& theR, Standard_Real& theG, Standard_Real& theB) const
{
theR = theG = theB = 0.0;
- if (myAttribs.IsNull()
- || myVCol == 0)
+ Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
+ if (myVCol == 0)
{
return;
}
- else if (theRank < 1
- || theRank > myAttribs->NbElements)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
const Graphic3d_Vec4ub& aColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(myAttribs->value (theRank - 1) + size_t(myVCol));
theR = Standard_Real(aColor.r()) / 255.0;
theG = Standard_Real(aColor.g()) / 255.0;
//! Returns the vertex color values at rank theRank from the vertex table if defined.
void VertexColor (const Standard_Integer theRank, Standard_Integer& theColor) const
{
+ Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
if (myVCol != 0)
{
theColor = *reinterpret_cast<const Standard_Integer* >(myAttribs->value (theRank - 1) + size_t(myVCol));
void VertexNormal (const Standard_Integer theRank, Standard_Real& theNX, Standard_Real& theNY, Standard_Real& theNZ) const
{
theNX = theNY = theNZ = 0.0;
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theRank < 1
- || theRank > myAttribs->NbElements)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
if (myVNor != 0)
{
const Graphic3d_Vec3& aVec = *reinterpret_cast<const Graphic3d_Vec3* >(myAttribs->value (theRank - 1) + size_t(myVNor));
void VertexTexel (const Standard_Integer theRank, Standard_Real& theTX, Standard_Real& theTY) const
{
theTX = theTY = 0.0;
- if (myAttribs.IsNull())
- {
- return;
- }
- else if (theRank < 1
- || theRank > myAttribs->NbElements)
- {
- throw Standard_OutOfRange ("BAD VERTEX index");
- }
-
+ Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
if (myVTex != 0)
{
const Graphic3d_Vec2& aVec = *reinterpret_cast<const Graphic3d_Vec2* >(myAttribs->value (theRank - 1) + size_t(myVTex));
Standard_Integer EdgeNumber() const { return !myIndices.IsNull() ? myIndices->NbElements : -1; }
//! Returns the number of allocated edges
- Standard_Integer EdgeNumberAllocated() const { return myMaxEdges; }
+ Standard_Integer EdgeNumberAllocated() const { return !myIndices.IsNull() ? myIndices->NbMaxElements() : 0; }
//! Returns the vertex index at rank theRank in the range [1,EdgeNumber()]
Standard_Integer Edge (const Standard_Integer theRank) const
{
- if (myIndices.IsNull()
- || theRank <= 0
- || theRank > myIndices->NbElements)
- {
- throw Standard_OutOfRange ("BAD EDGE index");
- }
+ Standard_OutOfRange_Raise_if (myIndices.IsNull() || theRank < 1 || theRank > myIndices->NbElements, "BAD EDGE index");
return Standard_Integer(myIndices->Index (theRank - 1) + 1);
}
Standard_Integer BoundNumber() const { return !myBounds.IsNull() ? myBounds->NbBounds : -1; }
//! Returns the number of allocated bounds
- Standard_Integer BoundNumberAllocated() const { return myMaxBounds; }
+ Standard_Integer BoundNumberAllocated() const { return !myBounds.IsNull() ? myBounds->NbMaxBounds : 0; }
//! Returns the edge number at rank theRank.
Standard_Integer Bound (const Standard_Integer theRank) const
{
- if (myBounds.IsNull()
- || theRank <= 0
- || theRank > myBounds->NbBounds)
- {
- throw Standard_OutOfRange ("BAD BOUND index");
- }
+ Standard_OutOfRange_Raise_if (myBounds.IsNull() || theRank < 1 || theRank > myBounds->NbBounds, "BAD BOUND index");
return myBounds->Bounds[theRank - 1];
}
//! Returns the bound color values at rank theRank from the bound table if defined.
void BoundColor (const Standard_Integer theRank, Standard_Real& theR, Standard_Real& theG, Standard_Real& theB) const
{
- if (myBounds.IsNull()
- || myBounds->Colors == NULL
- || theRank <= 0
- || theRank > myBounds->NbBounds)
- {
- throw Standard_OutOfRange (" BAD BOUND index");
- }
-
+ Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->Colors == NULL || theRank < 1 || theRank > myBounds->NbBounds, "BAD BOUND index");
const Graphic3d_Vec4& aVec = myBounds->Colors[theRank - 1];
theR = Standard_Real(aVec.r());
theG = Standard_Real(aVec.g());
{
return;
}
- else if (theIndex < 1
- || theIndex > myMaxBounds)
- {
- throw Standard_OutOfRange("BAD BOUND index");
- }
-
+ Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->Colors == NULL || theIndex < 1 || theIndex > myBounds->NbMaxBounds, "BAD BOUND index");
Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1];
aVec.r() = Standard_ShortReal (theR);
aVec.g() = Standard_ShortReal (theG);
protected: //! @name protected constructors
- //! Warning
- //! You must use a coherent set of AddVertex() methods according to the theHasVNormals,theHasVColors,theHasVTexels,theHasBColors.
- //! User is responsible of confuse vertex and bad normal orientation.
- //! You must use AddBound() method only if the theMaxBounds constructor parameter is > 0.
- //! You must use AddEdge() method only if the theMaxEdges constructor parameter is > 0.
- Standard_EXPORT Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOfPrimitiveArray theType,
- const Standard_Integer theMaxVertexs,
- const Standard_Integer theMaxBounds,
- const Standard_Integer theMaxEdges,
- const Standard_Boolean theHasVNormals,
- const Standard_Boolean theHasVColors,
- const Standard_Boolean theHasBColors,
- const Standard_Boolean theHasVTexels);
+ //! Main constructor.
+ //! @param theType type of primitive
+ //! @param theMaxVertexs length of vertex attributes buffer to be allocated (maximum number of vertexes, @sa ::AddVertex())
+ //! @param theMaxBounds length of bounds buffer to be allocated (maximum number of bounds, @sa ::AddBound())
+ //! @param theMaxEdges length of edges (index) buffer to be allocated (maximum number of indexes @sa ::AddEdge())
+ //! @param theArrayFlags array flags
+ Graphic3d_ArrayOfPrimitives (Graphic3d_TypeOfPrimitiveArray theType,
+ Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxBounds,
+ Standard_Integer theMaxEdges,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : myType (Graphic3d_TOPA_UNDEFINED), myVNor (0), myVTex (0), myVCol (0)
+ {
+ init (theType, theMaxVertexs, theMaxBounds, theMaxEdges, theArrayFlags);
+ }
+
+ //! Array constructor.
+ Standard_EXPORT void init (Graphic3d_TypeOfPrimitiveArray theType,
+ Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxBounds,
+ Standard_Integer theMaxEdges,
+ Graphic3d_ArrayFlags theArrayFlags);
private: //! @name private fields
Handle(Graphic3d_Buffer) myAttribs;
Handle(Graphic3d_BoundBuffer) myBounds;
Graphic3d_TypeOfPrimitiveArray myType;
- Standard_Integer myMaxBounds;
- Standard_Integer myMaxVertexs;
- Standard_Integer myMaxEdges;
Standard_Byte myVNor;
Standard_Byte myVTex;
Standard_Byte myVCol;
DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangleStrips, Graphic3d_ArrayOfPrimitives)
public:
- //! Creates an array of quadrangle strips, a polygon can be filled as:
+ //! Creates an array of quadrangle strips (Graphic3d_TOPA_QUADRANGLESTRIPS), a polygon can be filled as:
//! 1) Creating a single strip defined with his vertexes, i.e:
//! @code
//! myArray = Graphic3d_ArrayOfQuadrangleStrips (7);
//! ....
//! myArray->AddVertex (x8, y8, z8);
//! @endcode
+ //! The number of quadrangle really drawn is: VertexNumber()/2 - Min(1, BoundNumber()).
//! @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) {}
+ //! @param theArrayFlags array flags
+ Graphic3d_ArrayOfQuadrangleStrips (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxStrips,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theArrayFlags) {}
+
+ //! Creates an array of quadrangle strips (Graphic3d_TOPA_QUADRANGLESTRIPS).
+ //! @param theMaxVertexs defines the maximum allowed vertex number in the array
+ //! @param theMaxStrips defines the maximum allowed strip number in the array
+ Graphic3d_ArrayOfQuadrangleStrips (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxStrips = 0,
+ Standard_Boolean theHasVNormals = Standard_False,
+ Standard_Boolean theHasVColors = Standard_False,
+ Standard_Boolean theHasSColors = Standard_False,
+ Standard_Boolean theHasVTexels = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0,
+ (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None)
+ | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None)
+ | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)
+ | (theHasSColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)) {}
+
+
};
DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfQuadrangles, Graphic3d_ArrayOfPrimitives)
public:
- //! Creates an array of quadrangles, a quadrangle can be filled as:
+ //! Creates an array of quadrangles (Graphic3d_TOPA_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 (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);
+ //! myArray->AddEdges (1, 2, 3, 4);
+ //! myArray->AddEdges (3, 4, 5, 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) {}
+ //! @param theArrayFlags array flags
+ Graphic3d_ArrayOfQuadrangles (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxEdges,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges, theArrayFlags) {}
+
+ //! Creates an array of quadrangles (Graphic3d_TOPA_QUADRANGLES).
+ //! @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 (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxEdges = 0,
+ Standard_Boolean theHasVNormals = Standard_False,
+ Standard_Boolean theHasVColors = Standard_False,
+ Standard_Boolean theHasVTexels = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges,
+ (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None)
+ | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None)
+ | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)) {}
};
DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfSegments, Graphic3d_ArrayOfPrimitives)
public:
- //! Creates an array of segments, a segment can be filled as:
+ //! Creates an array of segments (Graphic3d_TOPA_SEGMENTS), a segment can be filled as:
//! 1) Creating a set of segments defined with his vertexes, i.e:
//! @code
//! myArray = Graphic3d_ArrayOfSegments (4);
//! @endcode
//! 2) Creating a set of indexed segments defined with his vertex and edges, i.e:
//! @code
- //! myArray = Graphic3d_ArrayOfSegments (4, 0, 8);
+ //! myArray = Graphic3d_ArrayOfSegments (4, 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);
+ //! myArray->AddEdges (1, 2);
+ //! myArray->AddEdges (3, 4);
+ //! myArray->AddEdges (2, 4);
+ //! myArray->AddEdges (1, 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 theArrayFlags array flags
+ Graphic3d_ArrayOfSegments (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxEdges,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, theArrayFlags) {}
+
+ //! Creates an array of segments (Graphic3d_TOPA_SEGMENTS).
+ //! @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) {}
+ Graphic3d_ArrayOfSegments (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxEdges = 0,
+ Standard_Boolean theHasVColors = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None) {}
+
};
DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleFans, Graphic3d_ArrayOfPrimitives)
public:
- //! Creates an array of triangle fans, a polygon can be filled as:
+ //! Creates an array of triangle fans (Graphic3d_TOPA_TRIANGLEFANS), a polygon can be filled as:
//! 1) Creating a single fan defined with his vertexes, i.e:
//! @code
//! myArray = Graphic3d_ArrayOfTriangleFans (7);
//! ....
//! myArray->AddVertex (x8, y8, z8);
//! @endcode
+ //! The number of triangle really drawn is: VertexNumber() - 2 * Min(1, BoundNumber())
//! @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) {}
+ //! @param theArrayFlags array flags
+ Graphic3d_ArrayOfTriangleFans (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxFans,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0, theArrayFlags) {}
+
+ //! Creates an array of triangle fans (Graphic3d_TOPA_TRIANGLEFANS).
+ //! @param theMaxVertexs defines the maximum allowed vertex number in the array
+ //! @param theMaxFans defines the maximum allowed fan number in the array
+ Graphic3d_ArrayOfTriangleFans (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxFans = 0,
+ Standard_Boolean theHasVNormals = Standard_False,
+ Standard_Boolean theHasVColors = Standard_False,
+ Standard_Boolean theHasBColors = Standard_False,
+ Standard_Boolean theHasVTexels = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0,
+ (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None)
+ | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None)
+ | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)
+ | (theHasBColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)) {}
};
DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangleStrips, Graphic3d_ArrayOfPrimitives)
public:
- //! Creates an array of triangle strips, a polygon can be filled as:
+ //! Creates an array of triangle strips (Graphic3d_TOPA_TRIANGLESTRIPS), a polygon can be filled as:
//! 1) Creating a single strip defined with his vertexes, i.e:
//! @code
//! myArray = Graphic3d_ArrayOfTriangleStrips (7);
//! @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 theArrayFlags array flags
+ Graphic3d_ArrayOfTriangleStrips (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxStrips,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theArrayFlags) {}
+
+ //! Creates an array of triangle strips (Graphic3d_TOPA_TRIANGLESTRIPS).
+ //! @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) {}
+ Graphic3d_ArrayOfTriangleStrips (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxStrips = 0,
+ Standard_Boolean theHasVNormals = Standard_False,
+ Standard_Boolean theHasVColors = Standard_False,
+ Standard_Boolean theHasBColors = Standard_False,
+ Standard_Boolean theHasVTexels = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0,
+ (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None)
+ | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None)
+ | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)
+ | (theHasBColors ? Graphic3d_ArrayFlags_BoundColor : Graphic3d_ArrayFlags_None)) {}
};
DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfTriangles, Graphic3d_ArrayOfPrimitives)
public:
- //! Creates an array of triangles, a triangle can be filled as:
+ //! Creates an array of triangles (Graphic3d_TOPA_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 (x4, y4, z4);
- //! myArray->AddEdge (1);
- //! myArray->AddEdge (2);
- //! myArray->AddEdge (3);
- //! myArray->AddEdge (2);
- //! myArray->AddEdge (3);
- //! myArray->AddEdge (4);
+ //! myArray->AddEdges (1, 2, 3);
+ //! myArray->AddEdges (2, 3, 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 theArrayFlags array flags
+ Graphic3d_ArrayOfTriangles (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxEdges,
+ Graphic3d_ArrayFlags theArrayFlags)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges, theArrayFlags) {}
+
+ //! Creates an array of triangles (Graphic3d_TOPA_TRIANGLES).
+ //! @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) {}
+ Graphic3d_ArrayOfTriangles (Standard_Integer theMaxVertexs,
+ Standard_Integer theMaxEdges = 0,
+ Standard_Boolean theHasVNormals = Standard_False,
+ Standard_Boolean theHasVColors = Standard_False,
+ Standard_Boolean theHasVTexels = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges,
+ (theHasVNormals ? Graphic3d_ArrayFlags_VertexNormal : Graphic3d_ArrayFlags_None)
+ | (theHasVColors ? Graphic3d_ArrayFlags_VertexColor : Graphic3d_ArrayFlags_None)
+ | (theHasVTexels ? Graphic3d_ArrayFlags_VertexTexel : Graphic3d_ArrayFlags_None)) {}
};
//! Bounds buffer.
class Graphic3d_BoundBuffer : public NCollection_Buffer
{
+ DEFINE_STANDARD_RTTIEXT(Graphic3d_BoundBuffer, NCollection_Buffer)
public:
//! Empty constructor.
: NCollection_Buffer (theAlloc),
Colors (NULL),
Bounds (NULL),
- NbBounds (0) {}
+ NbBounds (0),
+ NbMaxBounds (0) {}
//! Allocates new empty array
bool Init (const Standard_Integer theNbBounds,
Colors = NULL;
Bounds = NULL;
NbBounds = 0;
+ NbMaxBounds = 0;
Free();
if (theNbBounds < 1)
{
}
NbBounds = theNbBounds;
+ NbMaxBounds = theNbBounds;
Colors = theHasColors ? reinterpret_cast<Graphic3d_Vec4* >(myData) : NULL;
Bounds = reinterpret_cast<Standard_Integer* >(theHasColors ? (myData + aColorsSize) : myData);
return true;
public:
- Graphic3d_Vec4* Colors; //!< pointer to facet color values
- Standard_Integer* Bounds; //!< pointer to bounds array
- Standard_Integer NbBounds; //!< number of bounds
-
-public:
-
- DEFINE_STANDARD_RTTI_INLINE(Graphic3d_BoundBuffer,NCollection_Buffer) // Type definition
+ Graphic3d_Vec4* Colors; //!< pointer to facet color values
+ Standard_Integer* Bounds; //!< pointer to bounds array
+ Standard_Integer NbBounds; //!< number of bounds
+ Standard_Integer NbMaxBounds; //!< number of allocated bounds
};
--- /dev/null
+// Copyright (c) 2018 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 <Graphic3d_Buffer.hxx>
+#include <Graphic3d_IndexBuffer.hxx>
+#include <Graphic3d_BoundBuffer.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Buffer, NCollection_Buffer)
+IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_IndexBuffer, Graphic3d_Buffer)
+IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_BoundBuffer, NCollection_Buffer)
//! Buffer of vertex attributes.
class Graphic3d_Buffer : public NCollection_Buffer
{
+ DEFINE_STANDARD_RTTIEXT(Graphic3d_Buffer, NCollection_Buffer)
public:
//! Empty constructor.
//
}
+ //! Return number of initially allocated elements which can fit into this buffer,
+ //! while NbElements can be overwritten to smaller value.
+ Standard_Integer NbMaxElements() const { return Standard_Integer(mySize / size_t(Stride)); }
+
//! @return array of attributes definitions
const Graphic3d_Attribute* AttributesArray() const
{
public:
- Standard_Integer Stride; //!< the distance to the attributes of the next vertex
- Standard_Integer NbElements; //!< number of the elements
+ Standard_Integer Stride; //!< the distance to the attributes of the next vertex within interleaved array
+ Standard_Integer NbElements; //!< number of the elements (@sa NbMaxElements() specifying the number of initially allocated number of elements)
Standard_Integer NbAttributes; //!< number of vertex attributes
-public:
-
- DEFINE_STANDARD_RTTI_INLINE(Graphic3d_Buffer,NCollection_Buffer) // Type definition
-
};
DEFINE_STANDARD_HANDLE(Graphic3d_Buffer, NCollection_Buffer)
//! Index buffer.
class Graphic3d_IndexBuffer : public Graphic3d_Buffer
{
+ DEFINE_STANDARD_RTTIEXT(Graphic3d_IndexBuffer, Graphic3d_Buffer)
public:
//! Empty constructor.
}
}
-public:
-
- DEFINE_STANDARD_RTTI_INLINE(Graphic3d_IndexBuffer,Graphic3d_Buffer) // Type definition
};
{
const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp);
- if (aDataType == GL_NONE)
- {
- continue;
- }
- else if (anAttrib.Id == Graphic3d_TOA_POS)
+ if (anAttrib.Id == Graphic3d_TOA_POS
+ && aDataType != GL_NONE)
{
TheBaseClass::bindAttribute (theGlCtx, Graphic3d_TOA_POS, aNbComp, aDataType, Stride, anOffset);
break;
{
const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp);
- if (aDataType == GL_NONE)
+ if (aDataType != GL_NONE)
{
- continue;
+ TheBaseClass::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset);
}
-
- TheBaseClass::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset);
anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType);
}
}
}
}
-public:
+private:
Graphic3d_Attribute Attribs[NbAttributes];
Standard_Integer Stride;
Standard_EXPORT Standard_Boolean buildVBO (const Handle(OpenGl_Context)& theCtx,
const Standard_Boolean theToKeepData) const;
+ //! Release GL memory.
Standard_EXPORT void clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const;
private:
// Parsing array description
Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0;
- Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels;
- hasVColors = hasNormals = hasBColors = hasTexels = Standard_False;
+ Graphic3d_ArrayFlags anArrayFlags = Graphic3d_ArrayFlags_None;
Standard_Integer anArgIndex = 0;
Standard_Integer anArgsCount = myArrayDescription->Length();
{
// vertex has a normal or normal with color or texel
if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount))
- hasNormals = Standard_True;
+ {
+ anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexNormal;
+ }
// vertex has a color
if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
- hasVColors = Standard_True;
+ {
+ anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
+ }
// vertex has a texel
if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount))
- hasTexels = Standard_True;
+ {
+ anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexTexel;
+ }
aVertexNum++;
}
{
// bound has color
if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount))
- hasBColors = Standard_True;
+ {
+ anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_BoundColor;
+ }
aBoundNum++;
}
anArray = new Graphic3d_ArrayOfPoints (aVertexNum);
}
else if (anArrayType == "segments")
- anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors);
+ anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, anArrayFlags);
else if (anArrayType == "polylines")
- anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum,
- hasVColors, hasBColors);
+ anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
else if (anArrayType == "triangles")
- anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
- hasVColors, hasTexels);
+ anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, anArrayFlags);
else if (anArrayType == "trianglefans")
- anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
- hasNormals, hasVColors,
- hasBColors, hasTexels);
+ anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum, anArrayFlags);
else if (anArrayType == "trianglestrips")
- anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum,
- hasNormals, hasVColors,
- hasBColors, hasTexels);
+ anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum, anArrayFlags);
else if (anArrayType == "quads")
- anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum,
- hasNormals, hasVColors,
- hasTexels);
+ anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum, anArrayFlags);
else if (anArrayType == "quadstrips")
- anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum,
- hasNormals, hasVColors,
- hasBColors, hasTexels);
+ anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum, anArrayFlags);
else if (anArrayType == "polygons")
- anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum,
- hasNormals, hasVColors, hasBColors,
- hasTexels);
+ anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
anArgIndex = 1;
while (anArgIndex < anArgsCount)