3dphotoshoot

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/gfxstate.cc	Sun May 31 00:40:26 2015 +0300
     1.3 @@ -0,0 +1,68 @@
     1.4 +#include <stack>
     1.5 +#include "vmath/vmath.h"
     1.6 +#include "gfxstate.h"
     1.7 +
     1.8 +static std::stack<Matrix4x4> mstack[NUM_MATRICES];
     1.9 +
    1.10 +static bool init_stack(int midx)
    1.11 +{
    1.12 +	if(mstack[midx].empty()) {
    1.13 +		mstack[midx].push(Matrix4x4::identity);
    1.14 +		return true;
    1.15 +	}
    1.16 +	return false;
    1.17 +}
    1.18 +
    1.19 +void push_matrix(int midx)
    1.20 +{
    1.21 +	init_stack(midx);
    1.22 +	mstack[midx].push(mstack[midx].top());
    1.23 +}
    1.24 +
    1.25 +void pop_matrix(int midx)
    1.26 +{
    1.27 +	if(!mstack[midx].empty()) {
    1.28 +		mstack[midx].pop();
    1.29 +	}
    1.30 +}
    1.31 +
    1.32 +void set_identity_matrix(int midx)
    1.33 +{
    1.34 +	set_matrix4x4(midx, Matrix4x4::identity);
    1.35 +}
    1.36 +
    1.37 +void set_matrix(int midx, const float *m)
    1.38 +{
    1.39 +	Matrix4x4 tmp;
    1.40 +	memcpy(tmp[0], m, 16 * sizeof *m);
    1.41 +	set_matrix4x4(midx, tmp.transposed());
    1.42 +}
    1.43 +
    1.44 +void mult_matrix(int midx, const float *m)
    1.45 +{
    1.46 +	Matrix4x4 tmp;
    1.47 +	memcpy(tmp[0], m, 16 * sizeof *m);
    1.48 +	mult_matrix4x4(midx, tmp.transposed());
    1.49 +}
    1.50 +
    1.51 +void get_matrix(int midx, float *m)
    1.52 +{
    1.53 +	Matrix4x4 tmp = get_matrix4x4(midx);
    1.54 +	tmp.transpose();
    1.55 +	memcpy(m, tmp[0], 16 * sizeof *m);
    1.56 +}
    1.57 +
    1.58 +void set_matrix4x4(int midx, const Matrix4x4 &m)
    1.59 +{
    1.60 +	mstack[midx].top() = m;
    1.61 +}
    1.62 +
    1.63 +void mult_matrix4x4(int midx, const Matrix4x4 &m)
    1.64 +{
    1.65 +	mstack[midx].top() *= m;
    1.66 +}
    1.67 +
    1.68 +Matrix4x4 &get_matrix4x4(int midx)
    1.69 +{
    1.70 +	return mstack[midx].top();
    1.71 +}