PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
matrix.h
1/* Copyright (C) 2000,2001,2002 Sony Computer Entertainment America
2
3 This file is subject to the terms and conditions of the GNU Lesser
4 General Public License Version 2.1. See the file "COPYING" in the
5 main directory of this archive for more details. */
6
7#ifndef ps2gl_matrix_h
8#define ps2gl_matrix_h
9
10#include "ps2gl/debug.h"
11#include "ps2s/cpu_matrix.h"
12
13#include "ps2gl/drawcontext.h"
14#include "ps2gl/glcontext.h"
15
16/********************************************
17 * CMatrixStack
18 */
19
20class CGLContext;
21
23protected:
24 CGLContext& GLContext;
25 static const int MaxStackDepth = 16;
26 cpu_mat_44 Matrices[MaxStackDepth], InverseMatrices[MaxStackDepth];
27 int CurStackDepth;
28
29public:
30 CMatrixStack(CGLContext& context)
31 : GLContext(context)
32 , CurStackDepth(0)
33 {
34 Matrices[0].set_identity();
35 InverseMatrices[0].set_identity();
36 }
37 virtual ~CMatrixStack()
38 {
39 }
40
41 virtual void Pop() = 0;
42 virtual void Push() = 0;
43 virtual void Concat(const cpu_mat_44& xform, const cpu_mat_44& inverse) = 0;
44 virtual void SetTop(const cpu_mat_44& newMat, const cpu_mat_44& newInv) = 0;
45};
46
47/********************************************
48 * CImmMatrixStack
49 */
50
52public:
54 : CMatrixStack(context)
55 {
56 }
57
58 void Pop()
59 {
60 mErrorIf(CurStackDepth == 0, "No matrices to pop!");
61 --CurStackDepth;
62 GLContext.GetImmDrawContext().SetVertexXformValid(false);
63 }
64
65 void Push()
66 {
67 mErrorIf(CurStackDepth == MaxStackDepth - 1,
68 "No room on stack!");
69 Matrices[CurStackDepth + 1] = Matrices[CurStackDepth];
70 InverseMatrices[CurStackDepth + 1] = InverseMatrices[CurStackDepth];
71 ++CurStackDepth;
72 }
73
74 void Concat(const cpu_mat_44& xform, const cpu_mat_44& inverse)
75 {
76 cpu_mat_44& curMat = Matrices[CurStackDepth];
77 cpu_mat_44& curInv = InverseMatrices[CurStackDepth];
78 curMat = curMat * xform;
79 curInv = inverse * curInv;
80 GLContext.GetImmDrawContext().SetVertexXformValid(false);
81 }
82
83 void SetTop(const cpu_mat_44& newMat, const cpu_mat_44& newInv)
84 {
85 Matrices[CurStackDepth] = newMat;
86 InverseMatrices[CurStackDepth] = newInv;
87 GLContext.GetImmDrawContext().SetVertexXformValid(false);
88 }
89
90 const cpu_mat_44& GetTop() const { return Matrices[CurStackDepth]; }
91 const cpu_mat_44& GetInvTop() const { return InverseMatrices[CurStackDepth]; }
92};
93
94/********************************************
95 * CDListMatrixStack
96 */
97
99public:
101 : CMatrixStack(context)
102 {
103 }
104
105 void Pop();
106 void Push();
107 void Concat(const cpu_mat_44& xform, const cpu_mat_44& inverse);
108 void SetTop(const cpu_mat_44& newMat, const cpu_mat_44& newInv);
109};
110
111#endif // ps2gl_matrix_h