3dphotoshoot
view src/gfxstate.cc @ 10:c71c477521ca
converting to GLES2 and C++
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 31 May 2015 00:40:26 +0300 |
parents | |
children |
line source
1 #include <stack>
2 #include "vmath/vmath.h"
3 #include "gfxstate.h"
5 static std::stack<Matrix4x4> mstack[NUM_MATRICES];
7 static bool init_stack(int midx)
8 {
9 if(mstack[midx].empty()) {
10 mstack[midx].push(Matrix4x4::identity);
11 return true;
12 }
13 return false;
14 }
16 void push_matrix(int midx)
17 {
18 init_stack(midx);
19 mstack[midx].push(mstack[midx].top());
20 }
22 void pop_matrix(int midx)
23 {
24 if(!mstack[midx].empty()) {
25 mstack[midx].pop();
26 }
27 }
29 void set_identity_matrix(int midx)
30 {
31 set_matrix4x4(midx, Matrix4x4::identity);
32 }
34 void set_matrix(int midx, const float *m)
35 {
36 Matrix4x4 tmp;
37 memcpy(tmp[0], m, 16 * sizeof *m);
38 set_matrix4x4(midx, tmp.transposed());
39 }
41 void mult_matrix(int midx, const float *m)
42 {
43 Matrix4x4 tmp;
44 memcpy(tmp[0], m, 16 * sizeof *m);
45 mult_matrix4x4(midx, tmp.transposed());
46 }
48 void get_matrix(int midx, float *m)
49 {
50 Matrix4x4 tmp = get_matrix4x4(midx);
51 tmp.transpose();
52 memcpy(m, tmp[0], 16 * sizeof *m);
53 }
55 void set_matrix4x4(int midx, const Matrix4x4 &m)
56 {
57 mstack[midx].top() = m;
58 }
60 void mult_matrix4x4(int midx, const Matrix4x4 &m)
61 {
62 mstack[midx].top() *= m;
63 }
65 Matrix4x4 &get_matrix4x4(int midx)
66 {
67 return mstack[midx].top();
68 }