Completed
Push — master ( ab9984...af827b )
by Matthew
01:19
created

ed2d.View   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %
Metric Value
dl 0
loc 61
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 11 1
A if_projection() 0 2 1
A new_projection() 0 6 1
A set_projection() 0 11 2
A create_uniforms() 0 12 2
A register_shader() 0 11 1
1
from ed2d import idgen
2
3
class View(object):
4
5
    def __init__(self):
6
7
        self.sids = idgen.IdGenerator()
8
        self.programs = []
9
        self.uniforms = []
10
        self.uniformIds = []
11
12
        self.pids = idgen.IdGenerator()
13
        self.projections = []
14
        self.projNames = []
15
        self.progPerProj = []
16
    
17
    def if_projection(self, name):
18
        return name in self.projNames
19
    
20
    def new_projection(self, name, projection):
21
        pid = self.pids.gen_id()
22
23
        idgen.set_uid_list(self.projNames, pid, name)
24
        idgen.set_uid_list(self.projections, pid, projection)
25
        idgen.set_uid_list(self.progPerProj, pid, [])
26
27
    def set_projection(self, name, projection):
28
        pid = self.projNames.index(name)
29
        sids = self.progPerProj[pid]
30
31
        self.projections[pid] = projection
32
33
        for i in sids:
34
            program = self.programs[i-1]
35
            program.use()
36
            uniformId = self.uniformIds[i-1]
37
            program.set_uniform_matrix(uniformId, projection)
38
39
    def create_uniforms(self, name):
40
        pid = self.projNames.index(name)
41
        sids = self.progPerProj[pid]
42
        projection = self.projections[pid]
43
44
        for i in sids:
45
            program = self.programs[i-1]
46
            program.use()
47
48
            uniformId = program.new_uniform(name.encode('utf-8'))
49
            program.set_uniform_matrix(uniformId, projection)
50
            self.uniformIds[i-1] = uniformId
51
52
53
    def register_shader(self, projName, program):
54
        pid = self.projNames.index(projName)
55
        sid = self.sids.gen_id()
56
        print (sid)
57
58
        self.progPerProj[pid].append(sid)
59
60
        idgen.set_uid_list(self.programs, sid, program)
61
        idgen.set_uid_list(self.uniformIds, sid, [])
62
63
        self.create_uniforms(projName)
64