7d3e64ef |
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 | { |
ca3c13d1 |
28 | #if !defined(GL_ES_VERSION_2_0) |
4e1523ef |
29 | if (theCtx->core11 != NULL) |
30 | { |
31 | bindFixed (theCtx, theAttribute, theNbComp, theDataType, theStride, theOffset); |
32 | } |
ca3c13d1 |
33 | #endif |
7d3e64ef |
34 | return; |
35 | } |
36 | |
37 | theCtx->core20fwd->glEnableVertexAttribArray (theAttribute); |
8625ef7e |
38 | theCtx->core20fwd->glVertexAttribPointer (theAttribute, theNbComp, theDataType, theDataType != GL_FLOAT, theStride, theOffset); |
7d3e64ef |
39 | } |
40 | |
ca3c13d1 |
41 | #if !defined(GL_ES_VERSION_2_0) |
7d3e64ef |
42 | // ======================================================================= |
43 | // function : bindFixed |
44 | // purpose : |
45 | // ======================================================================= |
46 | inline void OpenGl_VertexBuffer::bindFixed (const Handle(OpenGl_Context)& theCtx, |
47 | const Graphic3d_TypeOfAttribute theMode, |
48 | const GLint theNbComp, |
49 | const GLenum theDataType, |
50 | const GLsizei theStride, |
51 | const GLvoid* theOffset) |
52 | { |
53 | switch (theMode) |
54 | { |
55 | case Graphic3d_TOA_POS: |
56 | { |
57 | theCtx->core11->glEnableClientState (GL_VERTEX_ARRAY); |
58 | theCtx->core11->glVertexPointer (theNbComp, theDataType, theStride, theOffset); |
59 | return; |
60 | } |
61 | case Graphic3d_TOA_NORM: |
62 | { |
63 | theCtx->core11->glEnableClientState (GL_NORMAL_ARRAY); |
64 | theCtx->core11->glNormalPointer (theDataType, theStride, theOffset); |
65 | return; |
66 | } |
67 | case Graphic3d_TOA_UV: |
68 | { |
69 | theCtx->core11->glEnableClientState (GL_TEXTURE_COORD_ARRAY); |
70 | theCtx->core11->glTexCoordPointer (theNbComp, theDataType, theStride, theOffset); |
71 | return; |
72 | } |
73 | case Graphic3d_TOA_COLOR: |
74 | { |
75 | theCtx->core11->glEnableClientState (GL_COLOR_ARRAY); |
76 | theCtx->core11->glColorPointer (theNbComp, theDataType, theStride, theOffset); |
77 | theCtx->core11->glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); |
78 | theCtx->core11fwd->glEnable (GL_COLOR_MATERIAL); |
79 | return; |
80 | } |
81 | case Graphic3d_TOA_CUSTOM: |
82 | { |
83 | return; |
84 | } |
85 | } |
86 | } |
ca3c13d1 |
87 | #endif |
7d3e64ef |
88 | |
89 | // ======================================================================= |
90 | // function : unbindAttribute |
91 | // purpose : |
92 | // ======================================================================= |
93 | inline void OpenGl_VertexBuffer::unbindAttribute (const Handle(OpenGl_Context)& theCtx, |
94 | const Graphic3d_TypeOfAttribute theAttribute) |
95 | { |
96 | if (theCtx->ActiveProgram().IsNull()) |
97 | { |
ca3c13d1 |
98 | #if !defined(GL_ES_VERSION_2_0) |
4e1523ef |
99 | if (theCtx->core11 != NULL) |
100 | { |
101 | unbindFixed (theCtx, theAttribute); |
102 | } |
ca3c13d1 |
103 | #endif |
7d3e64ef |
104 | return; |
105 | } |
106 | |
107 | theCtx->core20fwd->glDisableVertexAttribArray (theAttribute); |
108 | } |
109 | |
ca3c13d1 |
110 | #if !defined(GL_ES_VERSION_2_0) |
7d3e64ef |
111 | // ======================================================================= |
4e1523ef |
112 | // function : unbindFixed |
7d3e64ef |
113 | // purpose : |
114 | // ======================================================================= |
115 | inline void OpenGl_VertexBuffer::unbindFixed (const Handle(OpenGl_Context)& theCtx, |
116 | const Graphic3d_TypeOfAttribute theMode) |
117 | { |
118 | switch (theMode) |
119 | { |
120 | case Graphic3d_TOA_POS: theCtx->core11->glDisableClientState (GL_VERTEX_ARRAY); return; |
121 | case Graphic3d_TOA_NORM: theCtx->core11->glDisableClientState (GL_NORMAL_ARRAY); return; |
122 | case Graphic3d_TOA_UV: theCtx->core11->glDisableClientState (GL_TEXTURE_COORD_ARRAY); return; |
8613985b |
123 | case Graphic3d_TOA_COLOR: unbindFixedColor (theCtx); return; |
7d3e64ef |
124 | case Graphic3d_TOA_CUSTOM: |
125 | { |
126 | return; |
127 | } |
128 | } |
129 | } |
ca3c13d1 |
130 | #endif |