]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/reflect.cpp
Even more validation for uniform mismatches
[libs/gl.git] / source / glsl / reflect.cpp
1 #include "reflect.h"
2
3 namespace Msp {
4 namespace GL {
5 namespace SL {
6
7 LocationCounter::LocationCounter():
8         r_count(0)
9 { }
10
11 void LocationCounter::visit(BasicTypeDeclaration &basic)
12 {
13         r_count = basic.kind==BasicTypeDeclaration::MATRIX ? basic.size>>16 : 1;
14 }
15
16 void LocationCounter::visit(ImageTypeDeclaration &)
17 {
18         r_count = 1;
19 }
20
21 void LocationCounter::visit(StructDeclaration &strct)
22 {
23         unsigned total = 0;
24         for(NodeList<Statement>::const_iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i)
25         {
26                 r_count = 1;
27                 (*i)->visit(*this);
28                 total += r_count;
29         }
30         r_count = total;
31 }
32
33 void LocationCounter::visit(VariableDeclaration &var)
34 {
35         r_count = 1;
36         if(var.type_declaration)
37                 var.type_declaration->visit(*this);
38         if(var.array)
39                 if(const Literal *literal = dynamic_cast<const Literal *>(var.array_size.get()))
40                         if(literal->value.check_type<int>())
41                                 r_count *= literal->value.value<int>();
42 }
43
44 } // namespace SL
45 } // namespace GL
46 } // namespace Msp