PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
gmanager.cpp
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#include <stdio.h>
8
9#include "GL/ps2gl.h"
10
11#include "ps2s/cpu_matrix.h"
12#include "ps2s/displayenv.h"
13#include "ps2s/math.h"
14#include "ps2s/packet.h"
15
16#include "ps2gl/clear.h"
17#include "ps2gl/debug.h"
18#include "ps2gl/dlist.h"
19#include "ps2gl/glcontext.h"
20#include "ps2gl/gmanager.h"
21#include "ps2gl/matrix.h"
22
23/********************************************
24 * class CVertArray
25 */
26
27CVertArray::CVertArray()
28{
29 Vertices = Normals = TexCoords = Colors = NULL;
30 VerticesAreValid = NormalsAreValid = TexCoordsAreValid = ColorsAreValid = false;
31 WordsPerVertex = WordsPerTexCoord = WordsPerColor = 0;
32 WordsPerNormal = 3; // not set by NormalPointer
33}
34
35/********************************************
36 * class CGeomManager
37 */
38
39// static members
40
41CVertArray* CGeomManager::VertArray;
42
43tUserPrimEntry CGeomManager::UserPrimTypes[kMaxUserPrimTypes];
44
45bool CGeomManager::DoNormalize = false;
46
47CGeomManager::CGeomManager(CGLContext& context)
48 : GLContext(context)
49 , CurNormal(0.0f, 0.0f, 1.0f)
50 , Prim(GL_INVALID_VALUE)
51 , InsideBeginEnd(false)
52 , LastArrayAccessWasIndexed(false)
53 , LastArrayAccessIsValid(false)
54 , UserRenderContextChanged(false)
55{
56 for (unsigned int i = 0; i < kMaxUserPrimTypes; i++)
57 UserPrimTypes[i].requirements = 0xffffffff;
58}
59
60/********************************************
61 * gl api
62 */
63
80void glVertexPointer(GLint size, GLenum type,
81 GLsizei stride, const GLvoid* ptr)
82{
83 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
84
85 if (stride != 0) {
86 mNotImplemented("stride must be 0");
87 return;
88 }
89 if (type != GL_FLOAT) {
90 mNotImplemented("type must be float");
91 return;
92 }
93
94 CVertArray& vertArray = pGLContext->GetGeomManager().GetVertArray();
95 vertArray.SetVertices((void*)ptr);
96 vertArray.SetWordsPerVertex(size);
97}
98
104void glNormalPointer(GLenum type, GLsizei stride,
105 const GLvoid* ptr)
106{
107 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
108
109 pglNormalPointer(3, type, stride, ptr);
110}
111
118void glTexCoordPointer(GLint size, GLenum type,
119 GLsizei stride, const GLvoid* ptr)
120{
121 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
122
123 if (stride != 0) {
124 mNotImplemented("stride must be 0");
125 return;
126 }
127 if (type != GL_FLOAT) {
128 mNotImplemented("type must be float");
129 return;
130 }
131
132 CVertArray& vertArray = pGLContext->GetGeomManager().GetVertArray();
133 vertArray.SetTexCoords((void*)ptr);
134 vertArray.SetWordsPerTexCoord(size);
135}
136
143void glColorPointer(GLint size, GLenum type,
144 GLsizei stride, const GLvoid* ptr)
145{
146 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
147
148 if (stride != 0) {
149 mNotImplemented("stride must be 0");
150 return;
151 }
152 if (type != GL_FLOAT) {
153 mNotImplemented("type must be float");
154 return;
155 }
156
157 CVertArray& vertArray = pGLContext->GetGeomManager().GetVertArray();
158 vertArray.SetColors((void*)ptr);
159 vertArray.SetWordsPerColor(size);
160}
161
173void glDrawArrays(GLenum mode, GLint first, GLsizei count)
174{
175 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
176
177 CGeomManager& gmanager = pGLContext->GetGeomManager();
178 gmanager.DrawArrays(mode, first, count);
179}
180
184void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
185{
186 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
187
188 mError("glDrawElements is a placeholder ATM and should not be called");
189}
190
194void glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid* pointer)
195{
196 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
197
198 mError("glInterleavedArrays is a placeholder ATM and should not be called");
199}
200
204void glArrayElement(GLint i)
205{
206 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
207
208 mError("glArrayElement is a placeholder ATM and should not be called");
209}
210
214void glFlush(void)
215{
216 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
217
218 CGeomManager& gmanager = pGLContext->GetGeomManager();
219 gmanager.Flush();
220}
221
// gl_api
223
224void glEnableClientState(GLenum cap)
225{
226 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
227
228 CGeomManager& gmanager = pGLContext->GetGeomManager();
229 CVertArray& vertArray = gmanager.GetVertArray();
230
231 switch (cap) {
232 case GL_NORMAL_ARRAY:
233 vertArray.SetNormalsValid(true);
234 break;
235 case GL_VERTEX_ARRAY:
236 vertArray.SetVerticesValid(true);
237 break;
238 case GL_COLOR_ARRAY:
239 vertArray.SetColorsValid(true);
240 break;
241 case GL_TEXTURE_COORD_ARRAY:
242 vertArray.SetTexCoordsValid(true);
243 break;
244
245 case GL_INDEX_ARRAY:
246 case GL_EDGE_FLAG_ARRAY:
247 mNotImplemented("capability = %d", cap);
248 break;
249 }
250}
251
252void glDisableClientState(GLenum cap)
253{
254 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
255
256 CGeomManager& gmanager = pGLContext->GetGeomManager();
257 CVertArray& vertArray = gmanager.GetVertArray();
258
259 switch (cap) {
260 case GL_NORMAL_ARRAY:
261 vertArray.SetNormalsValid(false);
262 break;
263 case GL_VERTEX_ARRAY:
264 vertArray.SetVerticesValid(false);
265 break;
266 case GL_COLOR_ARRAY:
267 vertArray.SetColorsValid(false);
268 break;
269 case GL_TEXTURE_COORD_ARRAY:
270 vertArray.SetTexCoordsValid(false);
271 break;
272
273 case GL_INDEX_ARRAY:
274 case GL_EDGE_FLAG_ARRAY:
275 mNotImplemented("capability = %d", cap);
276 break;
277 }
278}
279
280void glBegin(GLenum mode)
281{
282 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
283
284 CGeomManager& gmanager = pGLContext->GetGeomManager();
285 gmanager.BeginGeom(mode);
286}
287
288void glNormal3f(GLfloat x, GLfloat y, GLfloat z)
289{
290 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
291
292 CGeomManager& gmanager = pGLContext->GetGeomManager();
293 gmanager.Normal(cpu_vec_xyz(x, y, z));
294}
295
296void glNormal3fv(const GLfloat* v)
297{
298 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
299
300 glNormal3f(v[0], v[1], v[2]);
301}
302
303void glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
304{
305 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
306
307 CGeomManager& gmanager = pGLContext->GetGeomManager();
308 gmanager.Vertex(cpu_vec_xyzw(x, y, z, w));
309}
310
311void glVertex4fv(const GLfloat* vertex)
312{
313 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
314
315 glVertex4f(vertex[0], vertex[1], vertex[2], vertex[3]);
316}
317
318void glVertex3f(GLfloat x, GLfloat y, GLfloat z)
319{
320 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
321
322 glVertex4f(x, y, z, 1.0f);
323}
324
325void glVertex3fv(const GLfloat* vertex)
326{
327 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
328
329 glVertex4f(vertex[0], vertex[1], vertex[2], 1.0f);
330}
331
332void glVertex2f(GLfloat x, GLfloat y)
333{
334 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
335
336 glVertex4f(x, y, 0.0f, 1.0f);
337}
338
339void glVertex2i(GLint x, GLint y)
340{
341 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
342
343 glVertex4f((GLfloat)x, (GLfloat)y, 0.0f, 1.0f);
344}
345
346void glVertex2fv(const GLfloat* vertex)
347{
348 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
349
350 glVertex4f(vertex[0], vertex[1], 0.0f, 1.0f);
351}
352
353void glTexCoord2f(GLfloat u, GLfloat v)
354{
355 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
356
357 CGeomManager& gmanager = pGLContext->GetGeomManager();
358 gmanager.TexCoord(u, v);
359}
360
361void glTexCoord2fv(const GLfloat* texCoord)
362{
363 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
364
365 glTexCoord2f(texCoord[0], texCoord[1]);
366}
367
368void glColor3f(GLfloat red, GLfloat green, GLfloat blue)
369{
370 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
371
372 CGeomManager& gmanager = pGLContext->GetGeomManager();
373 gmanager.Color(cpu_vec_xyzw(red, green, blue, 1.0f));
374}
375
376void glColor3fv(const GLfloat* color)
377{
378 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
379
380 glColor3f(color[0], color[1], color[2]);
381}
382
383void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
384{
385 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
386
387 CGeomManager& gmanager = pGLContext->GetGeomManager();
388 gmanager.Color(cpu_vec_xyzw(red, green, blue, alpha));
389}
390
391void glColor4fv(const GLfloat* color)
392{
393 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
394
395 glColor4f(color[0], color[1], color[2], color[3]);
396}
397
398void glEnd(void)
399{
400 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
401
402 CGeomManager& gmanager = pGLContext->GetGeomManager();
403 gmanager.EndGeom();
404}
405
406/********************************************
407 * pgl api
408 */
409
420void pglNormalPointer(GLint size, GLenum type,
421 GLsizei stride, const GLvoid* ptr)
422{
423 if (stride != 0) {
424 mNotImplemented("stride must be 0");
425 return;
426 }
427 if (type != GL_FLOAT) {
428 mNotImplemented("type must be float");
429 return;
430 }
431
432 CVertArray& vertArray = pGLContext->GetGeomManager().GetVertArray();
433 vertArray.SetNormals((void*)ptr);
434 vertArray.SetWordsPerNormal(size);
435}
436
437void pglDrawIndexedArrays(GLenum primType,
438 int numIndices, const unsigned char* indices,
439 int numVertices)
440{
441 pGLContext->GetGeomManager().DrawIndexedArrays(primType, numIndices, indices, numVertices);
442}
443
477void pglRegisterCustomPrimType(GLenum primType,
478 pglU64_t requirements, pglU64_t rendererReqMask, int mergeContiguous)
479{
480 mErrorIf(!CGeomManager::IsUserPrimType(primType), "custom prim types must have bit 31 set");
481 CGeomManager::RegisterUserPrimType(primType, requirements, rendererReqMask, mergeContiguous);
482}
483
490void pglEnableCustom(pglU64_t flag)
491{
492 flag &= ~(tU64)0xffffffff;
493 pGLContext->GetGeomManager().EnableCustom(flag);
494}
495
502void pglDisableCustom(pglU64_t flag)
503{
504 flag &= ~(tU64)0xffffffff;
505 pGLContext->GetGeomManager().DisableCustom(flag);
506}
507
508void pglUserRenderContextChanged()
509{
510 pGLContext->GetGeomManager().SetUserRenderContextChanged();
511}
512
void pglDisableCustom(pglU64_t flag)
Definition gmanager.cpp:502
void pglRegisterCustomPrimType(GLenum primType, pglU64_t requirements, pglU64_t rendererReqMask, int mergeContiguous)
Definition gmanager.cpp:477
void pglEnableCustom(pglU64_t flag)
Definition gmanager.cpp:490
void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
Definition gmanager.cpp:118
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
Definition gmanager.cpp:80
void glArrayElement(GLint i)
Definition gmanager.cpp:204
void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
Definition gmanager.cpp:104
void glFlush(void)
Definition gmanager.cpp:214
void glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
Definition gmanager.cpp:194
void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
Definition gmanager.cpp:184
void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
Definition gmanager.cpp:143
void glDrawArrays(GLenum mode, GLint first, GLsizei count)
Definition gmanager.cpp:173
void pglNormalPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
Definition gmanager.cpp:420
Definition gmanager.h:82