PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
gmanager.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_gmanager_h
8#define ps2gl_gmanager_h
9
10#include "GL/gl.h"
11#include "ps2s/cpu_matrix.h"
12#include "ps2s/cpu_vector.h"
13#include "ps2s/gs.h"
14#include "ps2s/packet.h"
15
16#include "ps2gl/gblock.h"
17#include "ps2gl/renderermanager.h"
18
19/********************************************
20 * constants
21 */
22
23/********************************************
24 * CVertArray
25 */
26
28 void *Vertices, *Normals, *TexCoords, *Colors;
29 bool VerticesAreValid, NormalsAreValid, TexCoordsAreValid, ColorsAreValid;
30 char WordsPerVertex, WordsPerNormal, WordsPerTexCoord, WordsPerColor;
31
32public:
33 CVertArray();
34
35 inline bool GetVerticesAreValid() const { return VerticesAreValid; }
36 inline bool GetNormalsAreValid() const { return NormalsAreValid; }
37 inline bool GetTexCoordsAreValid() const { return TexCoordsAreValid; }
38 inline bool GetColorsAreValid() const { return ColorsAreValid; }
39
40 inline void SetVerticesValid(bool valid) { VerticesAreValid = valid; }
41 inline void SetNormalsValid(bool valid) { NormalsAreValid = valid; }
42 inline void SetTexCoordsValid(bool valid) { TexCoordsAreValid = valid; }
43 inline void SetColorsValid(bool valid) { ColorsAreValid = valid; }
44
45 inline void* GetVertices() const { return Vertices; }
46 inline void* GetNormals() const { return Normals; }
47 inline void* GetTexCoords() const { return TexCoords; }
48 inline void* GetColors() const { return Colors; }
49
50 inline void SetVertices(void* newPtr) { Vertices = newPtr; }
51 inline void SetNormals(void* newPtr) { Normals = newPtr; }
52 inline void SetTexCoords(void* newPtr) { TexCoords = newPtr; }
53 inline void SetColors(void* newPtr) { Colors = newPtr; }
54
55 inline int GetWordsPerVertex() const { return WordsPerVertex; }
56 inline int GetWordsPerNormal() const { return WordsPerNormal; }
57 inline int GetWordsPerTexCoord() const { return WordsPerTexCoord; }
58 inline int GetWordsPerColor() const { return WordsPerColor; }
59
60 inline void SetWordsPerVertex(int numWords) { WordsPerVertex = numWords; }
61 inline void SetWordsPerNormal(int numWords) { WordsPerNormal = numWords; }
62 inline void SetWordsPerTexCoord(int numWords) { WordsPerTexCoord = numWords; }
63 inline void SetWordsPerColor(int numWords) { WordsPerColor = numWords; }
64
65 // // for indexed arrays only
66
67 // inline void SetIndices( void *newPtr ) { Indices = newPtr; }
68 // inline void SetStripLengths( void *newPtr ) { StripLengths = newPtr; }
69 // inline void SetNumIndices( int num ) { NumIndices = num; }
70 // inline void SetNumStrips( int num ) { NumStrips = num; }
71
72 // inline void* GetIndices() { return Indices; }
73 // inline void* GetStripLengths() { return StripLengths; }
74 // inline int GetNumIndices() { return NumIndices; }
75 // inline int GetNumStrips() { return NumStrips; }
76};
77
78/********************************************
79 * types
80 */
81
82typedef struct {
83 tU64 requirements;
84 tU64 rendererReqMask;
85 bool mergeContiguous;
87
88/********************************************
89 * CGeomManager - contains code common to the display list and immediate renderers
90 */
91
92class CVifSCDmaPacket;
93class CGLContext;
94class CDList;
95
97protected:
98 CGLContext& GLContext;
99
100 // vertex array geometry
101 static CVertArray* VertArray;
102
103 static const unsigned int kMaxUserPrimTypes = PGL_MAX_CUSTOM_PRIM_TYPES;
104 static tUserPrimEntry UserPrimTypes[kMaxUserPrimTypes];
105
106 // GL state
107 cpu_vec_xyz CurNormal;
108 float CurTexCoord[2];
109 static bool DoNormalize;
110
111 GLenum Prim;
112
113 bool InsideBeginEnd;
114
115 bool LastArrayAccessWasIndexed, LastArrayAccessIsValid;
116
117 bool UserRenderContextChanged;
118
119 static inline void CheckPrimAccess(GLenum prim)
120 {
121 prim &= 0x7fffffff;
122 mErrorIf(prim >= kMaxUserPrimTypes,
123 "trying to access prim %d; max number of custom prim types is %d\n",
124 prim, kMaxUserPrimTypes);
125 }
126
127public:
128 CGeomManager(CGLContext& context);
129
130 // user prim types
131
132 static inline bool IsUserPrimType(unsigned int prim) { return (prim & 0x80000000); }
133
134 static inline void RegisterUserPrimType(GLenum prim,
135 tU64 requirements,
136 tU64 rendererReqMask,
137 bool mergeContiguous)
138 {
139 CheckPrimAccess(prim);
140 prim &= 0x7fffffff;
141 UserPrimTypes[prim].requirements = requirements;
142 UserPrimTypes[prim].rendererReqMask = rendererReqMask;
143 UserPrimTypes[prim].mergeContiguous = mergeContiguous;
144 }
145
146 static inline tU64 GetUserPrimRequirements(GLenum prim)
147 {
148 CheckPrimAccess(prim);
149 prim &= 0x7fffffff;
150 return UserPrimTypes[prim].requirements;
151 }
152
153 static inline bool GetUserPrimMerge(GLenum prim)
154 {
155 CheckPrimAccess(prim);
156 prim &= 0x7fffffff;
157 return UserPrimTypes[prim].mergeContiguous;
158 }
159
160 static inline tU64 GetUserPrimReqMask(GLenum prim)
161 {
162 CheckPrimAccess(prim);
163 prim &= 0x7fffffff;
164 return UserPrimTypes[prim].rendererReqMask;
165 }
166
167 void SetUserRenderContextChanged() { UserRenderContextChanged = true; }
168
169 // GL state
170
171 inline cpu_vec_xyz GetCurNormal() const { return CurNormal; }
172 inline void SetCurNormal(cpu_vec_xyz normal) { CurNormal = normal; }
173
174 inline const float* GetCurTexCoord() const { return CurTexCoord; }
175 inline void SetCurTexCoord(float u, float v)
176 {
177 CurTexCoord[0] = u;
178 CurTexCoord[1] = v;
179 }
180
181 // we're not really supporting this
182 void SetDoNormalize(bool normalize) { DoNormalize = normalize; }
183
184 inline CVertArray& GetVertArray() { return *VertArray; }
185
186 // user state
187
188 virtual void EnableCustom(tU64 flag) = 0;
189 virtual void DisableCustom(tU64 flag) = 0;
190
191 // rendering interface
192
193 virtual void BeginGeom(GLenum mode) = 0;
194 virtual void Vertex(cpu_vec_xyzw newVert) = 0;
195 virtual void Normal(cpu_vec_xyz normal) = 0;
196 virtual void TexCoord(float u, float v) = 0;
197 virtual void Color(cpu_vec_xyzw color) = 0;
198 virtual void EndGeom() = 0;
199 virtual void DrawArrays(GLenum mode, int first, int count) = 0;
200 virtual void DrawIndexedArrays(GLenum primType,
201 int numIndices, const unsigned char* indices,
202 int numVertices)
203 = 0;
204 virtual void Flush() = 0;
205};
206
207#endif // ps2gl_gmanager_h
Definition gmanager.h:82