3dphotoshoot

annotate 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
rev   line source
nuclear@10 1 #include <stack>
nuclear@10 2 #include "vmath/vmath.h"
nuclear@10 3 #include "gfxstate.h"
nuclear@10 4
nuclear@10 5 static std::stack<Matrix4x4> mstack[NUM_MATRICES];
nuclear@10 6
nuclear@10 7 static bool init_stack(int midx)
nuclear@10 8 {
nuclear@10 9 if(mstack[midx].empty()) {
nuclear@10 10 mstack[midx].push(Matrix4x4::identity);
nuclear@10 11 return true;
nuclear@10 12 }
nuclear@10 13 return false;
nuclear@10 14 }
nuclear@10 15
nuclear@10 16 void push_matrix(int midx)
nuclear@10 17 {
nuclear@10 18 init_stack(midx);
nuclear@10 19 mstack[midx].push(mstack[midx].top());
nuclear@10 20 }
nuclear@10 21
nuclear@10 22 void pop_matrix(int midx)
nuclear@10 23 {
nuclear@10 24 if(!mstack[midx].empty()) {
nuclear@10 25 mstack[midx].pop();
nuclear@10 26 }
nuclear@10 27 }
nuclear@10 28
nuclear@10 29 void set_identity_matrix(int midx)
nuclear@10 30 {
nuclear@10 31 set_matrix4x4(midx, Matrix4x4::identity);
nuclear@10 32 }
nuclear@10 33
nuclear@10 34 void set_matrix(int midx, const float *m)
nuclear@10 35 {
nuclear@10 36 Matrix4x4 tmp;
nuclear@10 37 memcpy(tmp[0], m, 16 * sizeof *m);
nuclear@10 38 set_matrix4x4(midx, tmp.transposed());
nuclear@10 39 }
nuclear@10 40
nuclear@10 41 void mult_matrix(int midx, const float *m)
nuclear@10 42 {
nuclear@10 43 Matrix4x4 tmp;
nuclear@10 44 memcpy(tmp[0], m, 16 * sizeof *m);
nuclear@10 45 mult_matrix4x4(midx, tmp.transposed());
nuclear@10 46 }
nuclear@10 47
nuclear@10 48 void get_matrix(int midx, float *m)
nuclear@10 49 {
nuclear@10 50 Matrix4x4 tmp = get_matrix4x4(midx);
nuclear@10 51 tmp.transpose();
nuclear@10 52 memcpy(m, tmp[0], 16 * sizeof *m);
nuclear@10 53 }
nuclear@10 54
nuclear@10 55 void set_matrix4x4(int midx, const Matrix4x4 &m)
nuclear@10 56 {
nuclear@10 57 mstack[midx].top() = m;
nuclear@10 58 }
nuclear@10 59
nuclear@10 60 void mult_matrix4x4(int midx, const Matrix4x4 &m)
nuclear@10 61 {
nuclear@10 62 mstack[midx].top() *= m;
nuclear@10 63 }
nuclear@10 64
nuclear@10 65 Matrix4x4 &get_matrix4x4(int midx)
nuclear@10 66 {
nuclear@10 67 return mstack[midx].top();
nuclear@10 68 }