0025442: Visualization, TKOpenGl - prevent inclusion of system header glxext.h
[occt.git] / src / OpenGl / OpenGl_VertexBuffer.lxx
1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 // =======================================================================
16 // function : bindAttribute
17 // purpose  :
18 // =======================================================================
19 inline void OpenGl_VertexBuffer::bindAttribute (const Handle(OpenGl_Context)&   theCtx,
20                                                 const Graphic3d_TypeOfAttribute theAttribute,
21                                                 const GLint                     theNbComp,
22                                                 const GLenum                    theDataType,
23                                                 const GLsizei                   theStride,
24                                                 const GLvoid*                   theOffset)
25 {
26   if (theCtx->ActiveProgram().IsNull())
27   {
28   #if !defined(GL_ES_VERSION_2_0)
29     bindFixed (theCtx, theAttribute, theNbComp, theDataType, theStride, theOffset);
30   #endif
31     return;
32   }
33
34   theCtx->core20fwd->glEnableVertexAttribArray (theAttribute);
35   theCtx->core20fwd->glVertexAttribPointer (theAttribute, theNbComp, theDataType, theDataType != GL_FLOAT, theStride, theOffset);
36 }
37
38 #if !defined(GL_ES_VERSION_2_0)
39 // =======================================================================
40 // function : bindFixed
41 // purpose  :
42 // =======================================================================
43 inline void OpenGl_VertexBuffer::bindFixed (const Handle(OpenGl_Context)&   theCtx,
44                                             const Graphic3d_TypeOfAttribute theMode,
45                                             const GLint                     theNbComp,
46                                             const GLenum                    theDataType,
47                                             const GLsizei                   theStride,
48                                             const GLvoid*                   theOffset)
49 {
50   switch (theMode)
51   {
52     case Graphic3d_TOA_POS:
53     {
54       theCtx->core11->glEnableClientState (GL_VERTEX_ARRAY);
55       theCtx->core11->glVertexPointer (theNbComp, theDataType, theStride, theOffset);
56       return;
57     }
58     case Graphic3d_TOA_NORM:
59     {
60       theCtx->core11->glEnableClientState (GL_NORMAL_ARRAY);
61       theCtx->core11->glNormalPointer (theDataType, theStride, theOffset);
62       return;
63     }
64     case Graphic3d_TOA_UV:
65     {
66       theCtx->core11->glEnableClientState (GL_TEXTURE_COORD_ARRAY);
67       theCtx->core11->glTexCoordPointer (theNbComp, theDataType, theStride, theOffset);
68       return;
69     }
70     case Graphic3d_TOA_COLOR:
71     {
72       theCtx->core11->glEnableClientState (GL_COLOR_ARRAY);
73       theCtx->core11->glColorPointer (theNbComp, theDataType, theStride, theOffset);
74       theCtx->core11->glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
75       theCtx->core11fwd->glEnable (GL_COLOR_MATERIAL);
76       return;
77     }
78     case Graphic3d_TOA_CUSTOM:
79     {
80       return;
81     }
82   }
83 }
84 #endif
85
86 // =======================================================================
87 // function : unbindAttribute
88 // purpose  :
89 // =======================================================================
90 inline void OpenGl_VertexBuffer::unbindAttribute (const Handle(OpenGl_Context)&   theCtx,
91                                                   const Graphic3d_TypeOfAttribute theAttribute)
92 {
93   if (theCtx->ActiveProgram().IsNull())
94   {
95   #if !defined(GL_ES_VERSION_2_0)
96     unbindFixed (theCtx, theAttribute);
97   #endif
98     return;
99   }
100
101   theCtx->core20fwd->glDisableVertexAttribArray (theAttribute);
102 }
103
104 #if !defined(GL_ES_VERSION_2_0)
105 // =======================================================================
106 // function : unbindAttribute
107 // purpose  :
108 // =======================================================================
109 inline void OpenGl_VertexBuffer::unbindFixed (const Handle(OpenGl_Context)&   theCtx,
110                                               const Graphic3d_TypeOfAttribute theMode)
111 {
112   switch (theMode)
113   {
114     case Graphic3d_TOA_POS:   theCtx->core11->glDisableClientState (GL_VERTEX_ARRAY);        return;
115     case Graphic3d_TOA_NORM:  theCtx->core11->glDisableClientState (GL_NORMAL_ARRAY);        return;
116     case Graphic3d_TOA_UV:    theCtx->core11->glDisableClientState (GL_TEXTURE_COORD_ARRAY); return;
117     case Graphic3d_TOA_COLOR:
118     {
119       theCtx->core11->glDisableClientState (GL_COLOR_ARRAY);
120       theCtx->core11fwd->glDisable (GL_COLOR_MATERIAL);
121       return;
122     }
123     case Graphic3d_TOA_CUSTOM:
124     {
125       return;
126     }
127   }
128 }
129 #endif