1 // Created on: 2000-06-16
2 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Graphic3d_ArrayOfPrimitives_HeaderFile
16 #define _Graphic3d_ArrayOfPrimitives_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_Type.hxx>
21 #include <Graphic3d_IndexBuffer.hxx>
22 #include <Graphic3d_Buffer.hxx>
23 #include <Graphic3d_BoundBuffer.hxx>
24 #include <Graphic3d_TypeOfPrimitiveArray.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Byte.hxx>
27 #include <MMgt_TShared.hxx>
28 #include <Standard_Boolean.hxx>
29 #include <Standard_Real.hxx>
30 #include <Standard_ShortReal.hxx>
31 #include <Standard_CString.hxx>
32 class Standard_OutOfRange;
33 class Graphic3d_InitialisationError;
34 class Graphic3d_Group;
41 class Graphic3d_ArrayOfPrimitives;
42 DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPrimitives, MMgt_TShared)
44 //! This class furnish services to defined and fill an
45 //! array of primitives compatible with the use of
46 //! the OPENGl glDrawArrays() or glDrawElements() functions.
47 //! NOTE that the main goal of this kind of primitive
48 //! is to avoid multiple copies of datas between
49 //! each layer of the software.
50 //! So the array datas exist only one time and the use
51 //! of SetXxxxxx() methods enable to change dynamically
52 //! the aspect of this primitive.
55 //! 1) Decrease strongly the loading time.
56 //! 2) Decrease strongly the display time using optimized Opengl
58 //! 3) Enable to change dynamically the components of the primitive
59 //! (vertice,normal,color,texture coordinates).
60 //! 4) Add true triangle and quadrangle strips or fans capabilities.
61 class Graphic3d_ArrayOfPrimitives : public MMgt_TShared
67 Standard_EXPORT void Destroy();
68 ~Graphic3d_ArrayOfPrimitives()
73 //! Adds a vertice in the array.
74 //! returns the actual vertex number.
75 Standard_Integer AddVertex (const gp_Pnt& aVertice);
76 Standard_Integer AddVertex (const Graphic3d_Vec3& theVertex);
78 //! Adds a vertice in the array.
79 //! returns the actual vertex number.
80 Standard_Integer AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Real Z);
82 //! Adds a vertice in the array.
83 //! returns the actual vertex number.
84 Standard_EXPORT Standard_Integer AddVertex (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z);
86 //! Adds a vertice and vertex color in the vertex array.
87 //! returns the actual vertex number.
88 //! Warning: <aColor> is ignored when the <hasVColors>
89 //! constructor parameter is FALSE
90 Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const Quantity_Color& aColor);
92 //! Adds a vertice and vertex color in the vertex array.
93 //! returns the actual vertex number.
94 //! Warning: <aColor> is ignored when the <hasVColors>
95 //! constructor parameter is FALSE
96 //! aColor = Alpha << 24 + Blue << 16 + Green << 8 + Red
97 //! On all architecture proccers type (x86 or SPARC) you can
98 //! use this byte order.
99 Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const Standard_Integer aColor);
101 //! Adds a vertice and vertex color in the vertex array.
102 //! returns the actual vertex number.
103 //! Warning: <theColor> is ignored when the <hasVColors>
104 //! constructor parameter is FALSE
105 Standard_Integer AddVertex (const gp_Pnt& theVertex,
106 const Graphic3d_Vec4ub& theColor);
108 //! Adds a vertice and vertex normal in the vertex array.
109 //! returns the actual vertex number.
110 //! Warning: <aNormal> is ignored when the <hasVNormals>
111 //! constructor parameter is FALSE.
112 Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Dir& aNormal);
114 //! Adds a vertice and vertex normal in the vertex array.
115 //! returns the actual vertex number.
116 //! Warning: <aNormal> is ignored when the <hasVNormals>
117 //! constructor parameter is FALSE.
118 Standard_Integer AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ);
120 //! Adds a vertice and vertex normal in the vertex array.
121 //! returns the actual vertex number.
122 //! Warning: <aNormal> is ignored when the <hasVNormals>
123 //! constructor parameter is FALSE.
124 Standard_EXPORT Standard_Integer AddVertex (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z, const Standard_ShortReal NX, const Standard_ShortReal NY, const Standard_ShortReal NZ);
126 //! Adds a vertice,vertex normal and color in the vertex array.
127 //! returns the actual vertex number.
128 //! Warning: <aNormal> is ignored when the <hasVNormals>
129 //! constructor parameter is FALSE.
130 //! <aColor> is ignored when the <hasVColors>
131 //! constructor parameter is FALSE
132 Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Dir& aNormal, const Quantity_Color& aColor);
134 //! Adds a vertice,vertex normal and color in the vertex array.
135 //! returns the actual vertex number.
136 //! Warning: <aNormal> is ignored when the <hasVNormals>
137 //! constructor parameter is FALSE.
138 //! <aColor> is ignored when the <hasVColors>
139 //! constructor parameter is FALSE
140 //! aColor = Alpha << 24 + Blue << 16 + Green << 8 + Red
141 //! On all architecture proccers type (x86 or SPARC) you can
142 //! use this byte order.
143 Standard_EXPORT Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Dir& aNormal, const Standard_Integer aColor);
145 //! Adds a vertice and vertex texture in the vertex array.
146 //! returns the actual vertex number.
147 //! <aTexel> is ignored when the <hasVTexels>
148 //! constructor parameter is FALSE.
149 Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Pnt2d& aTexel);
151 //! Adds a vertice and vertex texture coordinates in the vertex array.
152 //! returns the actual vertex number.
153 //! <aTexel> is ignored when the <hasVTexels>
154 //! constructor parameter is FALSE.
155 Standard_Integer AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real TX, const Standard_Real TY);
157 //! Adds a vertice and vertex texture coordinates in the vertex array.
158 //! returns the actual vertex number.
159 //! <aTexel> is ignored when the <hasVTexels>
160 //! constructor parameter is FALSE.
161 Standard_EXPORT Standard_Integer AddVertex (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z, const Standard_ShortReal TX, const Standard_ShortReal TY);
163 //! Adds a vertice,vertex normal and texture in the vertex array.
164 //! returns the actual vertex number.
165 //! Warning: <aNormal> is ignored when the <hasVNormals>
166 //! constructor parameter is FALSE.
167 //! <aTexel> is ignored when the <hasVTexels>
168 //! constructor parameter is FALSE.
169 Standard_Integer AddVertex (const gp_Pnt& aVertice, const gp_Dir& aNormal, const gp_Pnt2d& aTexel);
171 //! Adds a vertice,vertex normal and texture in the vertex array.
172 //! returns the actual vertex number.
173 //! Warning: <aNormal> is ignored when the <hasVNormals>
174 //! constructor parameter is FALSE.
175 //! <aTexel> is ignored when the <hasVTexels>
176 //! constructor parameter is FALSE.
177 Standard_Integer AddVertex (const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ, const Standard_Real TX, const Standard_Real TY);
179 //! Adds a vertice,vertex normal and texture in the vertex array.
180 //! returns the actual vertex number.
181 //! Warning: <aNormal> is ignored when the <hasVNormals>
182 //! constructor parameter is FALSE.
183 //! <aTexel> is ignored when the <hasVTexels>
184 //! constructor parameter is FALSE.
185 Standard_EXPORT Standard_Integer AddVertex (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z, const Standard_ShortReal NX, const Standard_ShortReal NY, const Standard_ShortReal NZ, const Standard_ShortReal TX, const Standard_ShortReal TY);
187 //! Adds a bound of length <edgeNumber> in the bound array
188 //! returns the actual bounds number.
189 Standard_EXPORT Standard_Integer AddBound (const Standard_Integer edgeNumber);
191 //! Adds a bound of length <edgeNumber> and bound color
192 //! <aBColor> in the bound array.
193 //! returns the actual bounds number.
194 //! Warning: <aBColor> is ignored when the <hasBColors>
195 //! constructor parameter is FALSE
196 Standard_EXPORT Standard_Integer AddBound (const Standard_Integer edgeNumber, const Quantity_Color& aBColor);
198 //! Adds a bound of length <edgeNumber> and bound color
199 //! coordinates in the bound array.
200 //! returns the actual bounds number.
201 //! Warning: <R,G,B> are ignored when the <hasBColors>
202 //! constructor parameter is FALSE
203 Standard_EXPORT Standard_Integer AddBound (const Standard_Integer edgeNumber, const Standard_Real R, const Standard_Real G, const Standard_Real B);
205 //! Adds an edge in the range [1,VertexNumber()] in the array.
206 //! Returns the actual edges number.
207 Standard_EXPORT Standard_Integer AddEdge (const Standard_Integer vertexIndex);
209 //! Change the vertice of rank <anIndex> in the array.
210 Standard_EXPORT void SetVertice (const Standard_Integer anIndex, const gp_Pnt& aVertice);
212 //! Change the vertice of rank <anIndex> in the array.
213 void SetVertice (const Standard_Integer anIndex, const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z);
215 //! Change the vertex color of rank <anIndex> in the array.
216 Standard_EXPORT void SetVertexColor (const Standard_Integer anIndex, const Quantity_Color& aColor);
218 //! Change the vertex color of rank <anIndex> in the array.
219 void SetVertexColor (const Standard_Integer anIndex, const Standard_Real R, const Standard_Real G, const Standard_Real B);
221 //! Change the vertex color of rank <theIndex> in the array.
222 void SetVertexColor (const Standard_Integer theIndex,
223 const Graphic3d_Vec4ub& theColor);
225 //! Change the vertex color of rank <anIndex> in the array.
226 //! aColor = Alpha << 24 + Blue << 16 + Green << 8 + Red
227 //! On all architecture proccers type (x86 or SPARC) you can
228 //! use this byte order.
229 Standard_EXPORT void SetVertexColor (const Standard_Integer anIndex, const Standard_Integer aColor);
231 //! Change the vertex normal of rank <anIndex> in the array.
232 Standard_EXPORT void SetVertexNormal (const Standard_Integer anIndex, const gp_Dir& aNormal);
234 //! Change the vertex normal of rank <anIndex> in the array.
235 void SetVertexNormal (const Standard_Integer anIndex, const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ);
237 //! Change the vertex texel of rank <anIndex> in the array.
238 Standard_EXPORT void SetVertexTexel (const Standard_Integer anIndex, const gp_Pnt2d& aTexel);
240 //! Change the vertex texel of rank <anIndex> in the array.
241 void SetVertexTexel (const Standard_Integer anIndex, const Standard_Real TX, const Standard_Real TY);
243 //! Change the bound color of rank <anIndex> in the array.
244 Standard_EXPORT void SetBoundColor (const Standard_Integer anIndex, const Quantity_Color& aColor);
246 //! Change the bound color of rank <anIndex> in the array.
247 void SetBoundColor (const Standard_Integer anIndex, const Standard_Real R, const Standard_Real G, const Standard_Real B);
249 //! Returns optional index buffer.
250 const Handle(Graphic3d_IndexBuffer)& Indices() const;
252 //! Returns vertex attributes buffer (colors, normals, texture coordinates).
253 const Handle(Graphic3d_Buffer)& Attributes() const;
255 //! Returns optional bounds buffer.
256 const Handle(Graphic3d_BoundBuffer)& Bounds() const;
258 //! Returns the type of this primitive
259 Graphic3d_TypeOfPrimitiveArray Type() const;
261 //! Returns the string type of this primitive
262 Standard_EXPORT Standard_CString StringType() const;
264 //! Returns TRUE when vertex normals array is defined.
265 Standard_Boolean HasVertexNormals() const;
267 //! Returns TRUE when vertex colors array is defined.
268 Standard_Boolean HasVertexColors() const;
270 //! Returns TRUE when vertex texels array is defined.
271 Standard_Boolean HasVertexTexels() const;
273 //! Returns the number of defined vertex
274 Standard_Integer VertexNumber() const;
276 //! Returns the vertice at rank <aRank>
277 //! from the vertex table if defined.
278 Standard_EXPORT gp_Pnt Vertice (const Standard_Integer aRank) const;
280 //! Returns the vertice coordinates at rank <aRank>
281 //! from the vertex table if defined.
282 void Vertice (const Standard_Integer aRank, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const;
284 //! Returns the vertex color at rank <aRank>
285 //! from the vertex table if defined.
286 Standard_EXPORT Quantity_Color VertexColor (const Standard_Integer aRank) const;
288 //! Returns the vertex color values at rank <aRank>
289 //! from the vertex table if defined.
290 void VertexColor (const Standard_Integer aRank, Standard_Real& R, Standard_Real& G, Standard_Real& B) const;
292 //! Returns the vertex color values at rank <aRank>
293 //! from the vertex table if defined.
294 void VertexColor (const Standard_Integer aRank, Standard_Integer& aColor) const;
296 //! Returns the vertex normal at rank <aRank>
297 //! from the vertex table if defined.
298 Standard_EXPORT gp_Dir VertexNormal (const Standard_Integer aRank) const;
300 //! Returns the vertex normal coordinates at rank <aRank>
301 //! from the vertex table if defined.
302 void VertexNormal (const Standard_Integer aRank, Standard_Real& NX, Standard_Real& NY, Standard_Real& NZ) const;
304 //! Returns the vertex texture at rank <aRank>
305 //! from the vertex table if defined.
306 Standard_EXPORT gp_Pnt2d VertexTexel (const Standard_Integer aRank) const;
308 //! Returns the vertex texture coordinates at rank <aRank>
309 //! from the vertex table if defined.
310 void VertexTexel (const Standard_Integer aRank, Standard_Real& TX, Standard_Real& TY) const;
312 //! Returns the number of defined edges
313 Standard_Integer EdgeNumber() const;
315 //! Returns the vertex index at rank <aRank>
316 //! in the range [1,VertexNumber()]
317 Standard_Integer Edge (const Standard_Integer aRank) const;
319 //! Returns TRUE when bound colors array is defined.
320 Standard_Boolean HasBoundColors() const;
322 //! Returns the number of defined bounds
323 Standard_Integer BoundNumber() const;
325 //! Returns the edge number at rank <aRank>.
326 Standard_Integer Bound (const Standard_Integer aRank) const;
328 //! Returns the bound color at rank <aRank>
329 //! from the bound table if defined.
330 Standard_EXPORT Quantity_Color BoundColor (const Standard_Integer aRank) const;
332 //! Returns the bound color values at rank <aRank>
333 //! from the bound table if defined.
334 Standard_EXPORT void BoundColor (const Standard_Integer aRank, Standard_Real& R, Standard_Real& G, Standard_Real& B) const;
336 //! Returns the number of total items according to
338 Standard_EXPORT Standard_Integer ItemNumber() const;
340 //! Returns TRUE only when the contains of this array is
342 Standard_EXPORT Standard_Boolean IsValid();
344 friend class Graphic3d_Group;
347 DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPrimitives,MMgt_TShared)
353 //! You must use a coherent set of AddVertex() methods according to the
354 //! <hasVNormals>,<hasVColors>,<hasVTexels>,<hasBColors>
355 //! User is responsible of confuse vertex and bad normal orientation.
356 //! You must use AddBound() method only if the <maxBounds>
357 //! constructor parameter is > 0.
358 //! You must use AddEdge() method only if the <maxEdges>
359 //! constructor parameter is > 0.
360 Standard_EXPORT Graphic3d_ArrayOfPrimitives(const Graphic3d_TypeOfPrimitiveArray aType, const Standard_Integer maxVertexs, const Standard_Integer maxBounds, const Standard_Integer maxEdges, const Standard_Boolean hasVNormals, const Standard_Boolean hasVColors, const Standard_Boolean hasBColors, const Standard_Boolean hasTexels);
367 Standard_EXPORT void ComputeVNormals (const Standard_Integer fromIndex, const Standard_Integer toIndex);
369 Handle(Graphic3d_IndexBuffer) myIndices;
370 Handle(Graphic3d_Buffer) myAttribs;
371 Handle(Graphic3d_BoundBuffer) myBounds;
372 Graphic3d_TypeOfPrimitiveArray myType;
373 Standard_Integer myMaxBounds;
374 Standard_Integer myMaxVertexs;
375 Standard_Integer myMaxEdges;
376 Standard_Byte myVNor;
377 Standard_Byte myVTex;
378 Standard_Byte myVCol;
384 #include <Graphic3d_ArrayOfPrimitives.lxx>
390 #endif // _Graphic3d_ArrayOfPrimitives_HeaderFile