PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
drawcontext.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 "ps2s/drawenv.h"
8
9#include "GL/ps2gl.h"
10
11#include "ps2gl/clear.h"
12#include "ps2gl/debug.h"
13#include "ps2gl/dlgmanager.h"
14#include "ps2gl/dlist.h"
15#include "ps2gl/drawcontext.h"
16#include "ps2gl/immgmanager.h"
17#include "ps2gl/matrix.h"
18
19/********************************************
20 * CImmDrawContext methods
21 */
22
23CImmDrawContext::CImmDrawContext(CGLContext& context)
24 : CDrawContext(context)
25 , DrawEnv(NULL)
26 , ClearEnv(NULL)
27 , FrameIsDblBuffered(false)
28 , DoSmoothShading(true)
29 , DoClipping(true)
30 , DoCullFace(false)
31 , CullFaceDir(1)
32 , RescaleNormals(false)
33 , BlendIsEnabled(false)
34 , AlphaTestIsEnabled(false)
35 , DepthTestIsEnabled(false)
36 , DrawInterlaced(true)
37 , PolyMode(GL_FILL)
38 , IsVertexXformValid(false)
39 , Width(0)
40 , Height(0)
41{
42 GSScale.set_identity();
43
44 ClearEnv = new CClearEnv;
45
46 DrawEnv = new GS::CDrawEnv(GS::kContext1);
47 DrawEnv->SetDepthTestPassMode(GS::ZTest::kGEqual);
48 using namespace GS::ABlend;
49 DrawEnv->SetAlphaBlendFunc(kSourceRGB, kDestRGB, kSourceAlpha, kDestRGB, 0x80);
50 DrawEnv->SetFogColor(255, 255, 255);
51
52 // alpha test
53 DrawEnv->DisableAlphaTest();
54 DrawEnv->SetAlphaRefVal(0);
55 DrawEnv->SetAlphaTestPassMode(GS::ATest::kAlways);
56}
57
58CImmDrawContext::~CImmDrawContext()
59{
60 // don't delete the frame mem areas -- they are created/destroyed by
61 // the app
62
63 delete ClearEnv;
64 delete DrawEnv;
65}
66
67void CImmDrawContext::SetDrawBuffers(bool interlaced,
68 GS::CMemArea* frame0Mem, GS::CMemArea* frame1Mem,
69 GS::CMemArea* depthMem)
70{
71 Frame0Mem = frame0Mem;
72 Frame1Mem = frame1Mem;
73 ZBufMem = depthMem;
74
75 DrawInterlaced = interlaced;
76 FrameIsDblBuffered = (frame0Mem && frame1Mem);
77
78 // see displaycontext for a comment on this..
79 CurFrameMem = Frame0Mem;
80 LastFrameMem = Frame1Mem;
81
82 int width = frame0Mem->GetWidth(), height = frame0Mem->GetHeight();
83 Width = width;
84 Height = height;
85
86 // get max depth buffer value
87
88 int depthPsm = GS::kPsmz24;
89 if (depthMem)
90 depthPsm = depthMem->GetPixFormat();
91 DepthBits = 0;
92 if (depthPsm == GS::kPsmz24)
93 DepthBits = 24;
94 else if (depthPsm == GS::kPsmz32)
95 DepthBits = 28; // for fog
96 else if (depthPsm == GS::kPsmz16)
97 DepthBits = 16;
98 else {
99 mError("Unknown depth buffer format");
100 }
101 int maxDepthValue = (1 << DepthBits) - 1;
102
103 // projection xform
104
105 // -1 here flips mapping to: far_clip -> -1, near_clip -> 1
106 GSScale.set_scale(cpu_vec_xyz(width / 2.0f, -1 * height / 2.0f, -1 * (float)maxDepthValue / 2.0f));
107 SetVertexXformValid(false);
108
109 // clear environment
110
111 ClearEnv->SetDimensions(width, height);
112 ClearEnv->SetFrameBufAddr(frame0Mem->GetWordAddr());
113 ClearEnv->SetFrameBufPsm(frame0Mem->GetPixFormat());
114 if (ZBufMem) {
115 ClearEnv->SetDepthBufAddr(ZBufMem->GetWordAddr());
116 ClearEnv->SetDepthBufPsm(ZBufMem->GetPixFormat());
117 }
118
119 // draw environment
120
121 DrawEnv->SetFrameBufferAddr(CurFrameMem->GetWordAddr());
122 DrawEnv->SetFrameBufferDim(width, height);
123 DrawEnv->CalculateClippedFBXYOffsets(GS::kDontAddHalfPixel);
124 DrawEnv->SetFrameBufferPSM(frame0Mem->GetPixFormat());
125
126 // DrawEnv->SetScissorArea( 0, height * 0.25f, width, height * 0.25f );
127
128 if (ZBufMem) {
129 DrawEnv->EnableDepthTest();
130 DrawEnv->SetDepthBufferAddr(ZBufMem->GetWordAddr());
131 DrawEnv->SetDepthBufferPSM(ZBufMem->GetPixFormat());
132 } else
133 DrawEnv->DisableDepthTest();
134
135 GLContext.DrawBufferChanged();
136}
137
138void CImmDrawContext::SwapBuffers(bool fieldIsEven)
139{
140 // flip frame buffer ptrs
141 if (FrameIsDblBuffered) {
142 GS::CMemArea* temp = CurFrameMem;
143 CurFrameMem = LastFrameMem;
144 LastFrameMem = temp;
145
146 // clear the new frame
147 ClearEnv->SetFrameBufAddr(CurFrameMem->GetWordAddr());
148
149 // draw to the new frame
150 DrawEnv->SetFrameBufferAddr(CurFrameMem->GetWordAddr());
151
152 GLContext.DrawEnvChanged();
153 }
154
155 if (DrawInterlaced) {
156 // add a half-pixel offset if the frame we're going to build on the core will
157 // be displayed in an odd field
158 DrawEnv->CalculateClippedFBXYOffsets(!fieldIsEven);
159
160 GLContext.DrawEnvChanged();
161 }
162}
163
164const cpu_mat_44&
165CImmDrawContext::GetVertexXform()
166{
167 if (!IsVertexXformValid) {
168 IsVertexXformValid = true;
169 VertexXform = (GLContext.GetProjectionStack().GetTop()
170 * GLContext.GetModelViewStack().GetTop());
171 VertexXform = GSScale * VertexXform;
172 }
173
174 return VertexXform;
175}
176
177void CImmDrawContext::SetDoSmoothShading(bool yesNo)
178{
179 if (DoSmoothShading != yesNo) {
180 DoSmoothShading = yesNo;
181 GLContext.ShadingChanged();
182 }
183}
184
185void CImmDrawContext::SetDoClipping(bool clip)
186{
187 if (DoClipping != clip) {
188 DoClipping = clip;
189 GLContext.ClippingEnabledChanged();
190 GLContext.GetImmGeomManager().GetRendererManager().ClippingEnabledChanged(clip);
191 }
192}
193
194void CImmDrawContext::SetDoCullFace(bool cull)
195{
196 if (DoCullFace != cull) {
197 DoCullFace = cull;
198 GLContext.CullFaceEnabledChanged();
199 GLContext.GetImmGeomManager().GetRendererManager().CullFaceEnabledChanged(cull);
200 }
201}
202
203void CImmDrawContext::SetCullFaceDir(int direction)
204{
205 if (CullFaceDir != direction) {
206 CullFaceDir = direction;
207 GLContext.CullFaceDirChanged();
208 }
209}
210
211void CImmDrawContext::SetBlendEnabled(bool enabled)
212{
213 if (BlendIsEnabled != enabled) {
214 BlendIsEnabled = enabled;
215 GLContext.BlendEnabledChanged();
216 }
217}
218
219void CImmDrawContext::SetRescaleNormals(bool rescale)
220{
221 if (RescaleNormals != rescale) {
222 RescaleNormals = rescale;
223 GLContext.LightPropChanged();
224 }
225}
226
227void CImmDrawContext::SetDepthWriteEnabled(bool enabled)
228{
229 DrawEnv->SetDepthWriteEnabled(enabled);
230 GLContext.DepthWriteEnabledChanged();
231}
232
233void CImmDrawContext::SetFrameBufferDrawMask(unsigned int mask)
234{
235 DrawEnv->SetFrameBufferDrawMask(mask);
236 GLContext.FrameBufferDrawMaskChanged();
237}
238
239void CImmDrawContext::SetPolygonMode(GLenum mode)
240{
241 if (PolyMode != mode) {
242 PolyMode = mode;
243 GLContext.PolyModeChanged();
244 }
245}
246
247void CImmDrawContext::SetAlphaTestEnabled(bool enabled)
248{
249 if (AlphaTestIsEnabled != enabled) {
250 AlphaTestIsEnabled = enabled;
251
252 if (enabled) {
253 DrawEnv->EnableAlphaTest();
254 } else {
255 DrawEnv->DisableAlphaTest();
256 }
257
258 GLContext.AlphaTestEnabledChanged();
259 }
260}
261
262void CImmDrawContext::SetDepthTestEnabled(bool enabled)
263{
264 if (DepthTestIsEnabled != enabled) {
265 DepthTestIsEnabled = enabled;
266
267 if (enabled) {
268 DrawEnv->EnableDepthTest();
269 } else {
270 DrawEnv->DisableDepthTest();
271 }
272
273 GLContext.DepthTestEnabledChanged();
274 }
275}
276
277void CImmDrawContext::SetInterlacingOffset(float yPixels)
278{
279 if (DrawEnv->GetInterlacedPixelOffset() != yPixels) {
280 DrawEnv->SetInterlacedPixelOffset(yPixels);
281 bool offset = (DrawInterlaced && GLContext.GetCurrentFieldIsEven());
282 DrawEnv->CalculateClippedFBXYOffsets(offset);
283
284 GLContext.DrawEnvChanged();
285 }
286}
287
288// I hate to do it, but...
289#define mCombineBlendFactors(_src, _dest) \
290 ((unsigned int)(_src) << 16) | (unsigned int)(_dest)
291
292void CImmDrawContext::SetBlendMode(GLenum source, GLenum dest)
293{
294 unsigned int blendFactor = mCombineBlendFactors(source, dest);
295
296 switch (blendFactor) {
297 case mCombineBlendFactors(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA):
298 using namespace GS::ABlend;
299 DrawEnv->SetAlphaBlendFunc(kSourceRGB, kDestRGB, kSourceAlpha, kDestRGB, 0x80);
300 GLContext.BlendModeChanged();
301 break;
302 case mCombineBlendFactors(GL_SRC_ALPHA, GL_ONE):
303 DrawEnv->SetAlphaBlendFunc(kSourceRGB, kZero, kSourceAlpha, kDestRGB, 0x80);
304 GLContext.BlendModeChanged();
305 break;
306 // the following is actually subtractive blending, which
307 // should be GL_MINUS_ALPHA, GL_ONE but there is no minus alpha in GL
308 case mCombineBlendFactors(GL_ONE_MINUS_SRC_ALPHA, GL_ONE):
309 DrawEnv->SetAlphaBlendFunc(kZero, kSourceRGB, kSourceAlpha, kDestRGB, 0x80);
310 GLContext.BlendModeChanged();
311 break;
312 default:
313 mNotImplemented("alpha blending mode: source = %d, dest = %d", source, dest);
314 }
315}
316
317#undef mCombineBlendFactors
318
319void CImmDrawContext::SetAlphaFunc(GLenum func, GLclampf ref)
320{
321 GS::tAlphaTestPassMode ePassMode;
322
323 switch (func) {
324 case GL_NEVER:
325 ePassMode = GS::ATest::kNever;
326 break;
327
328 case GL_LESS:
329 ePassMode = GS::ATest::kLess;
330 break;
331
332 case GL_EQUAL:
333 ePassMode = GS::ATest::kEqual;
334 break;
335
336 case GL_LEQUAL:
337 ePassMode = GS::ATest::kLEqual;
338 break;
339
340 case GL_GREATER:
341 ePassMode = GS::ATest::kGreater;
342 break;
343
344 case GL_NOTEQUAL:
345 ePassMode = GS::ATest::kNotEqual;
346 break;
347
348 case GL_GEQUAL:
349 ePassMode = GS::ATest::kGEqual;
350 break;
351
352 case GL_ALWAYS:
353 ePassMode = GS::ATest::kAlways;
354 break;
355
356 default:
357 mError("Unknown alpha test function");
358 return;
359 }
360
361 DrawEnv->SetAlphaRefVal((unsigned int)(ref * 0xff));
362 DrawEnv->SetAlphaTestPassMode(ePassMode);
363 DrawEnv->SetAlphaTestFailAction(GS::ATest::kKeep);
364
365 GLContext.AlphaTestFuncChanged();
366}
367
368void CImmDrawContext::SetDepthFunc(GLenum func)
369{
370 /*
371 * NOTE:
372 * The PS2 does not support GL_LESS/GL_LEQUAL
373 * but this is what 99% of OpenGL programs use.
374 *
375 * As a result depth is inverted.
376 * See glDepthFunc/glFrustum/glOrtho
377 */
378 GS::tZTestPassMode ePassMode;
379
380 switch (func) {
381 case GL_NEVER:
382 ePassMode = GS::ZTest::kNever;
383 break;
384
385 case GL_LESS:
386 ePassMode = GS::ZTest::kGreater;
387 break;
388
389 case GL_LEQUAL:
390 ePassMode = GS::ZTest::kGEqual;
391 break;
392
393 case GL_ALWAYS:
394 ePassMode = GS::ZTest::kAlways;
395 break;
396
397 case GL_EQUAL:
398 case GL_GREATER:
399 case GL_NOTEQUAL:
400 case GL_GEQUAL:
401 default:
402 mError("Unknown/unsupported depth test function");
403 return;
404 }
405
406 DrawEnv->SetDepthTestPassMode(ePassMode);
407
408 GLContext.DepthTestFuncChanged();
409}
410
411/********************************************
412 * CDListDrawContext methods
413 */
414
416 GS::CMemArea *Frame0, *Frame1, *Depth;
417 bool Interlaced;
418
419public:
420 CSetDrawBuffers(bool inter, GS::CMemArea* frame0, GS::CMemArea* frame1, GS::CMemArea* depth)
421 : Frame0(frame0)
422 , Frame1(frame1)
423 , Depth(depth)
424 , Interlaced(inter)
425 {
426 }
427 CDListCmd* Play()
428 {
429 pGLContext->GetImmDrawContext().SetDrawBuffers(Interlaced, Frame0, Frame1, Depth);
430 return CDListCmd::GetNextCmd(this);
431 }
432};
433
434void CDListDrawContext::SetDrawBuffers(bool interlaced,
435 GS::CMemArea* frame0Mem, GS::CMemArea* frame1Mem,
436 GS::CMemArea* depthMem)
437{
438 GLContext.GetDListGeomManager().Flush();
439
440 GLContext.GetDListManager().GetOpenDList() += CSetDrawBuffers(interlaced,
441 frame0Mem, frame1Mem,
442 depthMem);
443 GLContext.DrawBufferChanged();
444}
445
447 bool DoSS;
448
449public:
450 CSetDoSmoothShadingCmd(bool yesNo)
451 : DoSS(yesNo)
452 {
453 }
454 CDListCmd* Play()
455 {
456 pGLContext->GetImmDrawContext().SetDoSmoothShading(DoSS);
457 return CDListCmd::GetNextCmd(this);
458 }
459};
460
461void CDListDrawContext::SetDoSmoothShading(bool yesNo)
462{
463 GLContext.GetDListGeomManager().Flush();
464
465 GLContext.GetDListManager().GetOpenDList() += CSetDoSmoothShadingCmd(yesNo);
466 GLContext.ShadingChanged();
467}
468
470 bool DoClip;
471
472public:
473 CSetDoClippingCmd(bool clip)
474 : DoClip(clip)
475 {
476 }
477 CDListCmd* Play()
478 {
479 pGLContext->GetImmDrawContext().SetDoClipping(DoClip);
480 return CDListCmd::GetNextCmd(this);
481 }
482};
483
484void CDListDrawContext::SetDoClipping(bool clip)
485{
486 GLContext.GetDListGeomManager().Flush();
487
488 GLContext.GetDListManager().GetOpenDList() += CSetDoClippingCmd(clip);
489 GLContext.ClippingEnabledChanged();
490}
491
493 bool DoCull;
494
495public:
496 CSetDoCullFaceCmd(bool cull)
497 : DoCull(cull)
498 {
499 }
500 CDListCmd* Play()
501 {
502 pGLContext->GetImmDrawContext().SetDoCullFace(DoCull);
503 return CDListCmd::GetNextCmd(this);
504 }
505};
506
507void CDListDrawContext::SetDoCullFace(bool cull)
508{
509 GLContext.GetDListGeomManager().Flush();
510
511 GLContext.GetDListManager().GetOpenDList() += CSetDoCullFaceCmd(cull);
512 GLContext.CullFaceEnabledChanged();
513}
514
516 int CullDir;
517
518public:
519 CSetCullFaceDir(int dir)
520 : CullDir(dir)
521 {
522 }
523 CDListCmd* Play()
524 {
525 pGLContext->GetImmDrawContext().SetCullFaceDir(CullDir);
526 return CDListCmd::GetNextCmd(this);
527 }
528};
529
530void CDListDrawContext::SetCullFaceDir(int direction)
531{
532 GLContext.GetDListGeomManager().Flush();
533
534 GLContext.GetDListManager().GetOpenDList() += CSetCullFaceDir(direction);
535 GLContext.CullFaceDirChanged();
536}
537
539 bool Enabled;
540
541public:
542 CSetBlendEnabledCmd(bool enabled)
543 : Enabled(enabled)
544 {
545 }
546 CDListCmd* Play()
547 {
548 pGLContext->GetImmDrawContext().SetBlendEnabled(Enabled);
549 return CDListCmd::GetNextCmd(this);
550 }
551};
552
553void CDListDrawContext::SetBlendEnabled(bool enabled)
554{
555 GLContext.GetDListGeomManager().Flush();
556
557 GLContext.GetDListManager().GetOpenDList() += CSetBlendEnabledCmd(enabled);
558 GLContext.BlendEnabledChanged();
559}
560
562 bool Enabled;
563
564public:
565 CSetAlphaTestEnabledCmd(bool enabled)
566 : Enabled(enabled)
567 {
568 }
569 CDListCmd* Play()
570 {
571 pGLContext->GetImmDrawContext().SetAlphaTestEnabled(Enabled);
572 return CDListCmd::GetNextCmd(this);
573 }
574};
575
576void CDListDrawContext::SetAlphaTestEnabled(bool enabled)
577{
578 GLContext.GetDListGeomManager().Flush();
579
580 GLContext.GetDListManager().GetOpenDList() += CSetAlphaTestEnabledCmd(enabled);
581 GLContext.AlphaTestEnabledChanged();
582}
583
585 bool Enabled;
586
587public:
588 CSetDepthTestEnabledCmd(bool enabled)
589 : Enabled(enabled)
590 {
591 }
592 CDListCmd* Play()
593 {
594 pGLContext->GetImmDrawContext().SetDepthTestEnabled(Enabled);
595 return CDListCmd::GetNextCmd(this);
596 }
597};
598
599void CDListDrawContext::SetDepthTestEnabled(bool enabled)
600{
601 GLContext.GetDListGeomManager().Flush();
602
603 GLContext.GetDListManager().GetOpenDList() += CSetDepthTestEnabledCmd(enabled);
604 GLContext.DepthTestEnabledChanged();
605}
606
608 float Offset;
609
610public:
611 CSetInterlacingOffsetCmd(float offset)
612 : Offset(offset)
613 {
614 }
615 CDListCmd* Play()
616 {
617 pGLContext->GetImmDrawContext().SetInterlacingOffset(Offset);
618 return CDListCmd::GetNextCmd(this);
619 }
620};
621
622void CDListDrawContext::SetInterlacingOffset(float yPixels)
623{
624 GLContext.GetDListGeomManager().Flush();
625
626 GLContext.GetDListManager().GetOpenDList() += CSetInterlacingOffsetCmd(yPixels);
627 GLContext.DrawEnvChanged();
628}
629
631 GLenum Func;
632 GLclampf Ref;
633
634public:
635 CSetAlphaFuncCmd(GLenum func, GLclampf ref)
636 : Func(func)
637 , Ref(ref)
638 {
639 }
640 CDListCmd* Play()
641 {
642 pGLContext->GetImmDrawContext().SetAlphaFunc(Func, Ref);
643 return CDListCmd::GetNextCmd(this);
644 }
645};
646
647void CDListDrawContext::SetAlphaFunc(GLenum func, GLclampf ref)
648{
649 GLContext.GetDListGeomManager().Flush();
650
651 GLContext.GetDListManager().GetOpenDList() += CSetAlphaFuncCmd(func, ref);
652 GLContext.AlphaTestFuncChanged();
653}
654
656 GLenum Func;
657
658public:
659 CSetDepthFuncCmd(GLenum func)
660 : Func(func)
661 {
662 }
663 CDListCmd* Play()
664 {
665 pGLContext->GetImmDrawContext().SetDepthFunc(Func);
666 return CDListCmd::GetNextCmd(this);
667 }
668};
669
670void CDListDrawContext::SetDepthFunc(GLenum func)
671{
672 GLContext.GetDListGeomManager().Flush();
673
674 GLContext.GetDListManager().GetOpenDList() += CSetDepthFuncCmd(func);
675 GLContext.DepthTestFuncChanged();
676}
677
679 bool Rescale;
680
681public:
682 CSetRescaleNormalsCmd(bool rescale)
683 : Rescale(rescale)
684 {
685 }
686 CDListCmd* Play()
687 {
688 pGLContext->GetDrawContext().SetRescaleNormals(Rescale);
689 return CDListCmd::GetNextCmd(this);
690 }
691};
692
693void CDListDrawContext::SetRescaleNormals(bool rescale)
694{
695 GLContext.GetDListGeomManager().Flush();
696
697 GLContext.GetDListManager().GetOpenDList() += CSetRescaleNormalsCmd(rescale);
698 GLContext.LightPropChanged();
699}
700
701class CSetBlendMode : public CDListCmd {
702 GLenum Source, Dest;
703
704public:
705 CSetBlendMode(GLenum s, GLenum d)
706 : Source(s)
707 , Dest(d)
708 {
709 }
710 CDListCmd* Play()
711 {
712 pGLContext->GetImmDrawContext().SetBlendMode(Source, Dest);
713 return CDListCmd::GetNextCmd(this);
714 }
715};
716
717void CDListDrawContext::SetBlendMode(GLenum source, GLenum dest)
718{
719 GLContext.GetDListGeomManager().Flush();
720
721 GLContext.GetDListManager().GetOpenDList() += CSetBlendMode(source, dest);
722 GLContext.BlendModeChanged();
723}
724
726 bool Enabled;
727
728public:
729 CSetDepthWriteEnabledCmd(bool enabled)
730 : Enabled(enabled)
731 {
732 }
733 CDListCmd* Play()
734 {
735 pGLContext->GetImmDrawContext().SetDepthWriteEnabled(Enabled);
736 return CDListCmd::GetNextCmd(this);
737 }
738};
739
740void CDListDrawContext::SetDepthWriteEnabled(bool enabled)
741{
742 GLContext.GetDListGeomManager().Flush();
743
744 GLContext.GetDListManager().GetOpenDList() += CSetDepthWriteEnabledCmd(enabled);
745 GLContext.DepthWriteEnabledChanged();
746}
747
749 unsigned int Mask;
750
751public:
752 CSetFrameBufferDrawMaskCmd(unsigned int mask)
753 : Mask(mask)
754 {
755 }
756 CDListCmd* Play()
757 {
758 pGLContext->GetImmDrawContext().SetFrameBufferDrawMask(Mask);
759 return CDListCmd::GetNextCmd(this);
760 }
761};
762
763void CDListDrawContext::SetFrameBufferDrawMask(unsigned int mask)
764{
765 GLContext.GetDListGeomManager().Flush();
766
767 GLContext.GetDListManager().GetOpenDList() += CSetFrameBufferDrawMaskCmd(mask);
768 GLContext.FrameBufferDrawMaskChanged();
769}
770
771/********************************************
772 * gl api
773 */
774
775void glDepthFunc(GLenum func)
776{
777 GL_FUNC_DEBUG("%s(0x%x)\n", __FUNCTION__, func);
778
779 pGLContext->GetDrawContext().SetDepthFunc(func);
780}
781
782void glDrawBuffer(GLenum mode)
783{
784 GL_FUNC_DEBUG("%s(0x%x)\n", __FUNCTION__, mode);
785
786 mNotImplemented();
787}
788
789void glReadBuffer(GLenum mode)
790{
791 GL_FUNC_DEBUG("%s(0x%x)\n", __FUNCTION__, mode);
792
793 mNotImplemented();
794}
795
796void glClipPlane(GLenum plane, const GLdouble* equation)
797{
798 GL_FUNC_DEBUG("%s(0x%x,%f)\n", __FUNCTION__, plane, equation);
799
800 mNotImplemented();
801}
802
803// alpha blending
804
805void glBlendFunc(GLenum sfactor, GLenum dfactor)
806{
807 GL_FUNC_DEBUG("%s(0x%x,0x%x)\n", __FUNCTION__, sfactor, dfactor);
808
809 pGLContext->GetDrawContext().SetBlendMode(sfactor, dfactor);
810}
811
812// alpha test
813
814void glAlphaFunc(GLenum func, GLclampf ref)
815{
816 GL_FUNC_DEBUG("%s(0x%x,%f)\n", __FUNCTION__, func, ref);
817
818 pGLContext->GetDrawContext().SetAlphaFunc(func, ref);
819}
820
821// depth test
822
823void glDepthMask(GLboolean enabled)
824{
825 GL_FUNC_DEBUG("%s(%d)\n", __FUNCTION__, enabled);
826
827 CImmDrawContext& drawContext = pGLContext->GetImmDrawContext();
828 drawContext.SetDepthWriteEnabled(enabled);
829}
830
831void glShadeModel(GLenum mode)
832{
833 GL_FUNC_DEBUG("%s(0x%x)\n", __FUNCTION__, mode);
834
835 CImmDrawContext& drawContext = pGLContext->GetImmDrawContext();
836 drawContext.SetDoSmoothShading((mode == GL_FLAT) ? false : true);
837}
838
839void glCullFace(GLenum mode)
840{
841 GL_FUNC_DEBUG("%s(0x%x)\n", __FUNCTION__, mode);
842
843 mWarnIf(mode == GL_FRONT_AND_BACK, "GL_FRONT_AND_BACK culling is not supported");
844 CImmDrawContext& drawContext = pGLContext->GetImmDrawContext();
845 drawContext.SetCullFaceDir((mode == GL_FRONT) ? 1 : -1);
846}
847
848void glColorMask(GLboolean r_enabled, GLboolean g_enabled,
849 GLboolean b_enabled, GLboolean a_enabled)
850{
851 GL_FUNC_DEBUG("%s(%d,%d,%d,%d)\n", __FUNCTION__, r_enabled, g_enabled, b_enabled, a_enabled);
852
853 CImmDrawContext& drawContext = pGLContext->GetImmDrawContext();
854 unsigned int mask = 0;
855 if (r_enabled == GL_FALSE)
856 mask |= 0xff;
857 if (g_enabled == GL_FALSE)
858 mask |= 0xff00;
859 if (b_enabled == GL_FALSE)
860 mask |= 0xff0000;
861 if (a_enabled == GL_FALSE)
862 mask |= 0xff000000;
863 drawContext.SetFrameBufferDrawMask(mask);
864}
865
866void glScissor(int x, int y, int width, int height)
867{
868 GL_FUNC_DEBUG("%s(%d,%d,%d,%d)\n", __FUNCTION__, x, y, width, height);
869
870 mNotImplemented();
871}
872
873void glClearAccum(float red, float green, float blue, float alpha)
874{
875 GL_FUNC_DEBUG("%s(%f,%f,%f,%f)\n", __FUNCTION__, red, green, blue, alpha);
876
877 mNotImplemented();
878}
879
880void glClearStencil(int s)
881{
882 GL_FUNC_DEBUG("%s(%d)\n", __FUNCTION__, s);
883
884 mNotImplemented();
885}
886
887void glPolygonMode(GLenum face, GLenum mode)
888{
889 GL_FUNC_DEBUG("%s(0x%x,0x%x)\n", __FUNCTION__, face, mode);
890
891 CImmDrawContext& drawContext = pGLContext->GetImmDrawContext();
892 drawContext.SetPolygonMode(mode);
893}
894
895void glPolygonOffset(GLfloat factor, GLfloat units)
896{
897 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
898
899 mNotImplemented();
900}
901
902void glGetPolygonStipple(GLubyte* mask)
903{
904 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
905
906 mNotImplemented();
907}
908
909/********************************************
910 * ps2gl api
911 */
912
926void pglSetDrawBuffers(int interlaced,
927 pgl_area_handle_t frame0_mem, pgl_area_handle_t frame1_mem,
928 pgl_area_handle_t depth_mem)
929{
930 pGLContext->GetDrawContext().SetDrawBuffers(interlaced,
931 reinterpret_cast<GS::CMemArea*>(frame0_mem),
932 reinterpret_cast<GS::CMemArea*>(frame1_mem),
933 reinterpret_cast<GS::CMemArea*>(depth_mem));
934}
935
936void pglSetInterlacingOffset(float yPixels)
937{
938 pGLContext->GetDrawContext().SetInterlacingOffset(yPixels);
939}
940
// pgl_api
void pglSetDrawBuffers(int interlaced, pgl_area_handle_t frame0_mem, pgl_area_handle_t frame1_mem, pgl_area_handle_t depth_mem)