Cogs.Core
AttributesGL20.cpp
1#include "AttributesGL20.h"
2
3namespace Cogs
4{
5 namespace OpenGL20
6 {
7 namespace HLSL
8 {
9 const char * PositionSemantics [] = {
10 "in_POSITION0",
11 "in_POSITION1",
12 "in_POSITION2",
13 "in_POSITION3",
14 "in_POSITION4",
15 "in_POSITION5",
16 "in_POSITION6",
17 "in_POSITION7",
18 };
19
20 const char * NormalSemantics [] = {
21 "in_NORMAL0",
22 "in_NORMAL1",
23 "in_NORMAL2",
24 "in_NORMAL3",
25 "in_NORMAL4",
26 "in_NORMAL5",
27 "in_NORMAL6",
28 "in_NORMAL7",
29 };
30
31 const char * ColorSemantics [] = {
32 "in_COLOR0",
33 "in_COLOR1",
34 "in_COLOR2",
35 "in_COLOR3",
36 "in_COLOR4",
37 "in_COLOR5",
38 "in_COLOR6",
39 "in_COLOR7",
40 };
41
42 const char * TexCoordSemantics [] = {
43 "in_TEXCOORD0",
44 "in_TEXCOORD1",
45 "in_TEXCOORD2",
46 "in_TEXCOORD3",
47 "in_TEXCOORD4",
48 "in_TEXCOORD5",
49 "in_TEXCOORD6",
50 "in_TEXCOORD7",
51 };
52
53 const char * TangentSemantics [] = {
54 "in_TANGENT0",
55 "in_TANGENT1",
56 "in_TANGENT2",
57 "in_TANGENT3",
58 "in_TANGENT4",
59 "in_TANGENT5",
60 "in_TANGENT6",
61 "in_TANGENT7",
62 };
63
64 const char * VectorSemantics [] = {
65 "in_INSTANCEVECTOR0",
66 "in_INSTANCEVECTOR1",
67 "in_INSTANCEVECTOR2",
68 "in_INSTANCEVECTOR3",
69 "in_INSTANCEVECTOR4",
70 "in_INSTANCEVECTOR5",
71 "in_INSTANCEVECTOR6",
72 "in_INSTANCEVECTOR7",
73 };
74
75 const char * MatrixSemantics [] = {
76 "in_INSTANCEMATRIX0",
77 "in_INSTANCEMATRIX1",
78 "in_INSTANCEMATRIX2",
79 "in_INSTANCEMATRIX3",
80 "in_INSTANCEMATRIX4",
81 "in_INSTANCEMATRIX5",
82 "in_INSTANCEMATRIX6",
83 "in_INSTANCEMATRIX7",
84 };
85
86 const char ** Semantics [] = {
87 PositionSemantics,
88 NormalSemantics,
89 ColorSemantics,
90 TexCoordSemantics,
91 TangentSemantics,
92 VectorSemantics,
93 MatrixSemantics
94 };
95
96 STATIC_ASSERT_MAPPING(Semantics, ElementSemantic::Semantic_Size);
97 }
98
99 namespace GLSL
100 {
101 const char * PositionSemantics [] = {
102 "a_POSITION0",
103 "a_POSITION1",
104 "a_POSITION2",
105 "a_POSITION3",
106 "a_POSITION4",
107 "a_POSITION5",
108 "a_POSITION6",
109 "a_POSITION7",
110 };
111
112 const char * ColorSemantics [] = {
113 "a_COLOR0",
114 "a_COLOR1",
115 "a_COLOR2",
116 "a_COLOR3",
117 "a_COLOR4",
118 "a_COLOR5",
119 "a_COLOR6",
120 "a_COLOR7",
121 };
122
123 const char * NormalSemantics [] = {
124 "a_NORMAL0",
125 "a_NORMAL1",
126 "a_NORMAL2",
127 "a_NORMAL3",
128 "a_NORMAL4",
129 "a_NORMAL5",
130 "a_NORMAL6",
131 "a_NORMAL7",
132 };
133
134 const char * TexCoordSemantics [] = {
135 "a_TEXCOORD0",
136 "a_TEXCOORD1",
137 "a_TEXCOORD2",
138 "a_TEXCOORD3",
139 "a_TEXCOORD4",
140 "a_TEXCOORD5",
141 "a_TEXCOORD6",
142 "a_TEXCOORD7",
143 };
144
145 const char * TangentSemantics [] = {
146 "a_TANGENT0",
147 "a_TANGENT1",
148 "a_TANGENT2",
149 "a_TANGENT3",
150 "a_TANGENT4",
151 "a_TANGENT5",
152 "a_TANGENT6",
153 "a_TANGENT7",
154 };
155
156 const char * VectorSemantics [] = {
157 "a_INSTANCEVECTOR0",
158 "a_INSTANCEVECTOR1",
159 "a_INSTANCEVECTOR2",
160 "a_INSTANCEVECTOR3",
161 "a_INSTANCEVECTOR4",
162 "a_INSTANCEVECTOR5",
163 "a_INSTANCEVECTOR6",
164 "a_INSTANCEVECTOR7",
165 };
166
167 const char * MatrixSemantics [] = {
168 "a_INSTANCEMATRIX0",
169 "a_INSTANCEMATRIX1",
170 "a_INSTANCEMATRIX2",
171 "a_INSTANCEMATRIX3",
172 "a_INSTANCEMATRIX4",
173 "a_INSTANCEMATRIX5",
174 "a_INSTANCEMATRIX6",
175 "a_INSTANCEMATRIX7",
176 };
177
178 const char ** Semantics [] = {
179 PositionSemantics,
180 NormalSemantics,
181 ColorSemantics,
182 TexCoordSemantics,
183 TangentSemantics,
184 VectorSemantics,
185 MatrixSemantics
186 };
187
188 STATIC_ASSERT_MAPPING(Semantics, ElementSemantic::Semantic_Size);
189 }
190 }
191}
192
193void Cogs::AttributesGL20::initialize()
194{
195 GLint maxVertexAttribs;
196 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
197
198 for (size_t i = 0; i < MaxVertexAttributesGL20; ++i) {
199 const char * name = OpenGL20::GLSL::Semantics[i % NumAttributeSemanticsGL20][i / NumAttributeSemanticsGL20];
200
201 this->attributeIndexes[std::string(name)] = static_cast<GLint>(i);
202
203 name = OpenGL20::HLSL::Semantics[i % NumAttributeSemanticsGL20][i / NumAttributeSemanticsGL20];
204
205 this->attributeIndexesHLSL[std::string(name)] = static_cast<GLint>(i);
206 }
207}
208
209GLint Cogs::AttributesGL20::getAttributeIndex(const std::string & name, bool hlsl)
210{
211 auto & attributes = hlsl ? attributeIndexesHLSL : attributeIndexes;
212
213 auto it = attributes.find(name);
214
215 if (it == attributes.end()) {
216 return GL_INVALID_INDEX;
217 }
218
219 return it->second;
220}
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
@ OpenGL20
Graphics device using OpenGL, supporting at least OpenGL 2.0.