0023630: Incorrect NULL check in OpenGl_Workspace::EnableTexture()
[occt.git] / src / OpenGl / OpenGl_PrimitiveArray.hxx
1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 #ifndef OpenGl_PrimitiveArray_Header
21 #define OpenGl_PrimitiveArray_Header
22
23 #include <OpenGl_VertexBuffer.hxx>
24
25 #include <InterfaceGraphic_Graphic3d.hxx>
26 #include <Aspect_InteriorStyle.hxx>
27
28 #include <OpenGl_Element.hxx>
29
30 struct OPENGL_SURF_PROP;
31
32 class OpenGl_PrimitiveArray : public OpenGl_Element
33 {
34 public:
35   // OpenGL does not provie a constant for "none" draw mode.
36   // So we define our own one that does not conflict with GL constants
37   // and untilizes common GL invalid value
38   enum
39   {
40     DRAW_MODE_NONE = -1
41   };
42
43   //! Default constructor
44   OpenGl_PrimitiveArray (CALL_DEF_PARRAY* thePArray);
45
46   //! Render primitives to the window
47   virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
48
49   virtual void Release (const Handle(OpenGl_Context)&   theContext);
50
51   CALL_DEF_PARRAY* PArray() const { return myPArray; }
52
53 private:
54
55   Standard_Boolean toDrawVbo() const
56   {
57     return !myVbos[VBOVertices].IsNull();
58   }
59
60   //! VBO initialization procedures
61   Standard_Boolean BuildVBO (const Handle(OpenGl_Workspace)& theWorkspace) const;
62   void clearMemoryOwn() const;
63   void clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const;
64
65   //! Main procedure to draw array
66   void DrawArray (Tint theLightingModel,
67                   const Aspect_InteriorStyle theInteriorStyle,
68                   Tint theEdgeFlag,
69                   const TEL_COLOUR* theInteriorColour,
70                   const TEL_COLOUR* theLineColour,
71                   const TEL_COLOUR* theEdgeColour,
72                   const OPENGL_SURF_PROP* theFaceProp,
73                   const Handle(OpenGl_Workspace)& theWorkspace) const;
74
75   //! Auxiliary procedures
76   void DrawEdges (const TEL_COLOUR*               theEdgeColour,
77                   const Handle(OpenGl_Workspace)& theWorkspace) const;
78
79   void DrawDegeneratesAsPoints (const TEL_COLOUR* theEdgeColour,
80                                 const float       theSkipRatio) const;
81   void DrawDegeneratesAsLines (const TEL_COLOUR*               theEdgeColour,
82                                const Handle(OpenGl_Workspace)& theWorkspace) const;
83   void DrawDegeneratesAsBBoxs (const TEL_COLOUR* theEdgeColour) const;
84
85   void DrawDegeneratesPointsAsPoints() const;
86   void DrawDegeneratesLinesAsPoints() const;
87   void DrawDegeneratesLinesAsLines (const float theSkipRatio) const;
88   void DrawDegeneratesTrianglesAsPoints() const;
89   void DrawDegeneratesTrianglesAsLines (const float theSkipRatio) const;
90   void DrawDegeneratesTrianglestripsAsPoints() const;
91   void DrawDegeneratesTrianglestripsAsLines (const float theSkipRatio) const;
92   void DrawDegeneratesQuadranglesAsPoints() const;
93   void DrawDegeneratesQuadranglesAsLines (const float theSkipRatio) const;
94   void DrawDegeneratesQuadranglestripsAsPoints() const;
95   void DrawDegeneratesQuadranglestripsAsLines (const float theSkipRatio) const;
96   void DrawDegeneratesPolygonsAsPoints() const;
97   void DrawDegeneratesPolygonsAsLines (const float theSkipRatio) const;
98
99 protected:
100
101   //! Destructor
102   virtual ~OpenGl_PrimitiveArray();
103
104 protected:
105
106   typedef enum
107   {
108     VBOEdges,
109     VBOVertices,
110     VBOVcolours,
111     VBOVnormals,
112     VBOVtexels,
113     VBOMaxType
114   } VBODataType;
115
116   mutable CALL_DEF_PARRAY*            myPArray;
117   mutable Handle(OpenGl_VertexBuffer) myVbos[VBOMaxType];
118   GLint                               myDrawMode;
119   mutable Standard_Boolean            myIsVboInit;
120
121 public:
122
123   DEFINE_STANDARD_ALLOC
124
125 };
126
127 #endif //OpenGl_PrimitiveArray_Header