Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

drawcontext.cpp

Go to the documentation of this file.
00001 /*        Copyright (C) 2000,2001,2002  Sony Computer Entertainment America
00002           
00003           This file is subject to the terms and conditions of the GNU Lesser
00004           General Public License Version 2.1. See the file "COPYING" in the
00005           main directory of this archive for more details.                             */
00006 
00007 #include "ps2s/drawenv.h"
00008 
00009 #include "GL/ps2gl.h"
00010 
00011 #include "ps2gl/debug.h"
00012 #include "ps2gl/dlist.h"
00013 #include "ps2gl/immgmanager.h"
00014 #include "ps2gl/dlgmanager.h"
00015 #include "ps2gl/drawcontext.h"
00016 #include "ps2gl/clear.h"
00017 #include "ps2gl/matrix.h"
00018 
00019 /********************************************
00020  * CImmDrawContext methods
00021  */
00022 
00023 CImmDrawContext::CImmDrawContext( CGLContext &context )
00024    : CDrawContext(context),
00025      DrawEnv(NULL),
00026      ClearEnv(NULL),
00027      FrameIsDblBuffered(false),
00028      DoSmoothShading(true),
00029      DoClipping(true),
00030      DoCullFace(false),
00031      CullFaceDir(1),
00032      RescaleNormals(false),
00033      BlendIsEnabled(false),
00034      AlphaTestIsEnabled(false),
00035      DrawInterlaced(true),
00036      PolyMode(GL_FILL),
00037      IsVertexXformValid(false),
00038      Width(0), Height(0)
00039 {
00040    GSScale.set_identity();
00041 
00042    ClearEnv = new CClearEnv;
00043 
00044    DrawEnv = new GS::CDrawEnv( GS::kContext1 );
00045    DrawEnv->SetDepthTestPassMode( GS::ZTest::kGEqual );
00046    using namespace GS::ABlend;
00047    DrawEnv->SetAlphaBlendFunc( kSourceRGB, kDestRGB, kSourceAlpha, kDestRGB, 0x80 );
00048    DrawEnv->SetFogColor( 255, 255, 255 );
00049 
00050    // alpha test
00051    DrawEnv->DisableAlphaTest();
00052    DrawEnv->SetAlphaRefVal( 0 );
00053    DrawEnv->SetAlphaTestPassMode( GS::ATest::kAlways );
00054 }
00055 
00056 CImmDrawContext::~CImmDrawContext()
00057 {
00058    // don't delete the frame mem areas -- they are created/destroyed by
00059    // the app
00060 
00061    delete ClearEnv;
00062    delete DrawEnv;
00063 }
00064 
00065 void
00066 CImmDrawContext::SetDrawBuffers( bool interlaced,
00067                                  GS::CMemArea *frame0Mem, GS::CMemArea *frame1Mem,
00068                                  GS::CMemArea *depthMem )
00069 {
00070    Frame0Mem = frame0Mem;
00071    Frame1Mem = frame1Mem;
00072    ZBufMem = depthMem;
00073 
00074    DrawInterlaced = interlaced;
00075    FrameIsDblBuffered = ( frame0Mem && frame1Mem );
00076 
00077    // see displaycontext for a comment on this..
00078    CurFrameMem = Frame0Mem;
00079    LastFrameMem = Frame1Mem;
00080 
00081    int width = frame0Mem->GetWidth(), height = frame0Mem->GetHeight();
00082    Width = width;
00083    Height = height;
00084 
00085    // get max depth buffer value
00086 
00087    int depthPsm = GS::kPsmz24;
00088    if ( depthMem ) depthPsm = depthMem->GetPixFormat();
00089    DepthBits = 0;
00090    if ( depthPsm == GS::kPsmz24 ) DepthBits = 24;
00091    else if ( depthPsm == GS::kPsmz32 ) DepthBits = 28; // for fog
00092    else if ( depthPsm == GS::kPsmz16 ) DepthBits = 16;
00093    else { mError( "Unknown depth buffer format" ); }
00094    int maxDepthValue = (1 << DepthBits) - 1;
00095 
00096    // projection xform
00097 
00098    // -1 here flips mapping to: far_clip -> -1, near_clip -> 1
00099    GSScale.set_scale( cpu_vec_xyz(width/2.0f, -1 * height/2.0f, -1 * (float)maxDepthValue/2.0f) );
00100    SetVertexXformValid(false);
00101 
00102    // clear environment
00103 
00104    ClearEnv->SetDimensions( width, height );
00105    ClearEnv->SetFrameBufAddr( frame0Mem->GetWordAddr() );
00106    ClearEnv->SetFrameBufPsm( frame0Mem->GetPixFormat() );
00107    if ( ZBufMem ) {
00108       ClearEnv->SetDepthBufAddr( ZBufMem->GetWordAddr() );
00109       ClearEnv->SetDepthBufPsm( ZBufMem->GetPixFormat() );
00110    }
00111 
00112    // draw environment
00113 
00114    DrawEnv->SetFrameBufferAddr( CurFrameMem->GetWordAddr() );
00115    DrawEnv->SetFrameBufferDim( width, height );
00116    DrawEnv->CalculateClippedFBXYOffsets( GS::kDontAddHalfPixel );
00117    DrawEnv->SetFrameBufferPSM( frame0Mem->GetPixFormat() );
00118 
00119    // DrawEnv->SetScissorArea( 0, height * 0.25f, width, height * 0.25f );
00120 
00121    if ( ZBufMem ) {
00122       DrawEnv->EnableDepthTest();
00123       DrawEnv->SetDepthBufferAddr( ZBufMem->GetWordAddr() );
00124       DrawEnv->SetDepthBufferPSM( ZBufMem->GetPixFormat() );
00125    }
00126    else
00127       DrawEnv->DisableDepthTest();
00128 
00129    GLContext.DrawBufferChanged();
00130 }
00131 
00132 void
00133 CImmDrawContext::SwapBuffers( bool fieldIsEven )
00134 {
00135    // flip frame buffer ptrs
00136    if ( FrameIsDblBuffered ) {
00137       GS::CMemArea* temp = CurFrameMem;
00138       CurFrameMem = LastFrameMem;
00139       LastFrameMem = temp;
00140 
00141       // clear the new frame
00142       ClearEnv->SetFrameBufAddr( CurFrameMem->GetWordAddr() );
00143 
00144       // draw to the new frame
00145       DrawEnv->SetFrameBufferAddr( CurFrameMem->GetWordAddr() );
00146 
00147       GLContext.DrawEnvChanged();
00148    }
00149 
00150    if ( DrawInterlaced ) {
00151       // add a half-pixel offset if the frame we're going to build on the core will
00152       // be displayed in an odd field
00153       DrawEnv->CalculateClippedFBXYOffsets( ! fieldIsEven );
00154 
00155       GLContext.DrawEnvChanged();
00156    }
00157 }
00158 
00159 const cpu_mat_44&
00160 CImmDrawContext::GetVertexXform()
00161 {
00162    if ( ! IsVertexXformValid ) {
00163       IsVertexXformValid = true;
00164       VertexXform = (GLContext.GetProjectionStack().GetTop()
00165                      * GLContext.GetModelViewStack().GetTop());
00166       VertexXform = GSScale * VertexXform;
00167    }
00168 
00169    return VertexXform;
00170 }
00171 
00172 void
00173 CImmDrawContext::SetDoSmoothShading( bool yesNo )
00174 {
00175    if ( DoSmoothShading != yesNo ) {
00176       DoSmoothShading = yesNo;
00177       GLContext.ShadingChanged();
00178    }
00179 }
00180 
00181 void
00182 CImmDrawContext::SetDoClipping( bool clip )
00183 {
00184    if ( DoClipping != clip ) {
00185       DoClipping = clip;
00186       GLContext.ClippingEnabledChanged();
00187       GLContext.GetImmGeomManager().GetRendererManager().ClippingEnabledChanged(clip);
00188    }
00189 }
00190          
00191 void
00192 CImmDrawContext::SetDoCullFace( bool cull )
00193 {
00194    if ( DoCullFace != cull ) {
00195       DoCullFace = cull;
00196       GLContext.CullFaceEnabledChanged();
00197       GLContext.GetImmGeomManager().GetRendererManager().CullFaceEnabledChanged(cull);
00198    }
00199 }
00200          
00201 void
00202 CImmDrawContext::SetCullFaceDir( int direction )
00203 {
00204    if ( CullFaceDir != direction ) {
00205       CullFaceDir = direction;
00206       GLContext.CullFaceDirChanged();
00207    }
00208 }
00209 
00210 void
00211 CImmDrawContext::SetBlendEnabled( bool enabled )
00212 {
00213    if ( BlendIsEnabled != enabled ) {
00214       BlendIsEnabled = enabled;
00215       GLContext.BlendEnabledChanged();
00216    }
00217 }
00218       
00219 void
00220 CImmDrawContext::SetRescaleNormals( bool rescale )
00221 {
00222    if ( RescaleNormals != rescale ) {
00223       RescaleNormals = rescale;
00224       GLContext.LightPropChanged();
00225    }
00226 }
00227 
00228 void
00229 CImmDrawContext::SetDepthWriteEnabled( bool enabled )
00230 {
00231    DrawEnv->SetDepthWriteEnabled(enabled);
00232    GLContext.DepthWriteEnabledChanged();
00233 }
00234 
00235 void
00236 CImmDrawContext::SetFrameBufferDrawMask(unsigned int mask)
00237 {
00238    DrawEnv->SetFrameBufferDrawMask(mask);
00239    GLContext.FrameBufferDrawMaskChanged(); 
00240 }
00241 
00242 void
00243 CImmDrawContext::SetPolygonMode( GLenum mode )
00244 {
00245    if ( PolyMode != mode ) {
00246       PolyMode = mode;
00247       GLContext.PolyModeChanged();
00248    }
00249 }
00250 
00251 void 
00252 CImmDrawContext::SetAlphaTestEnabled( bool enabled ) 
00253 {
00254    if ( AlphaTestIsEnabled != enabled ) {
00255       AlphaTestIsEnabled = enabled;
00256 
00257       if (enabled) {
00258           DrawEnv->EnableAlphaTest();
00259       } else {
00260           DrawEnv->DisableAlphaTest();
00261       }
00262 
00263       GLContext.AlphaTestEnabledChanged();
00264    }
00265 }
00266 
00267 void
00268 CImmDrawContext::SetInterlacingOffset( float yPixels )
00269 {
00270    if ( DrawEnv->GetInterlacedPixelOffset() != yPixels ) {
00271       DrawEnv->SetInterlacedPixelOffset( yPixels );
00272       bool offset = (DrawInterlaced && GLContext.GetCurrentFieldIsEven());
00273       DrawEnv->CalculateClippedFBXYOffsets( offset );
00274 
00275       GLContext.DrawEnvChanged();
00276    }
00277 }
00278 
00279 // I hate to do it, but...
00280 #define mCombineBlendFactors( _src, _dest )             \
00281    ((unsigned int)(_src) << 16) | (unsigned int)(_dest)
00282 
00283 void
00284 CImmDrawContext::SetBlendMode( GLenum source, GLenum dest )
00285 {
00286    unsigned int blendFactor = mCombineBlendFactors(source, dest);
00287 
00288    switch (blendFactor) {
00289       case mCombineBlendFactors( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ):
00290          using namespace GS::ABlend;
00291          DrawEnv->SetAlphaBlendFunc( kSourceRGB, kDestRGB, kSourceAlpha, kDestRGB, 0x80 );
00292          GLContext.BlendModeChanged();
00293          break;
00294       case mCombineBlendFactors( GL_SRC_ALPHA, GL_ONE ):
00295          DrawEnv->SetAlphaBlendFunc( kSourceRGB, kZero, kSourceAlpha, kDestRGB, 0x80 );
00296          GLContext.BlendModeChanged();
00297          break;
00298          // the following is actually subtractive blending, which
00299          // should be GL_MINUS_ALPHA, GL_ONE but there is no minus alpha in GL
00300      case mCombineBlendFactors( GL_ONE_MINUS_SRC_ALPHA, GL_ONE ):
00301          DrawEnv->SetAlphaBlendFunc( kZero, kSourceRGB, kSourceAlpha, kDestRGB, 0x80 );
00302          GLContext.BlendModeChanged();
00303          break;
00304       default:
00305          mNotImplemented( "alpha blending mode: source = %d, dest = %d", source, dest );
00306    }
00307 }
00308 
00309 #undef mCombineBlendFactors
00310 
00311 void 
00312 CImmDrawContext::SetAlphaFunc( GLenum func, GLclampf ref )
00313 {
00314    GS::tAlphaTestPassMode ePassMode;
00315        
00316    switch(func) {
00317       case GL_NEVER:
00318          ePassMode = GS::ATest::kNever;
00319          break;
00320 
00321       case GL_LESS:
00322          ePassMode = GS::ATest::kLess;
00323          break;
00324 
00325       case GL_EQUAL:
00326          ePassMode = GS::ATest::kEqual;
00327          break;
00328 
00329       case GL_LEQUAL:
00330          ePassMode = GS::ATest::kLEqual;
00331          break;
00332 
00333       case GL_GREATER:
00334          ePassMode = GS::ATest::kGreater;
00335          break;
00336 
00337       case GL_NOTEQUAL:
00338          ePassMode = GS::ATest::kNotEqual;
00339          break;
00340 
00341       case GL_GEQUAL:
00342          ePassMode = GS::ATest::kGEqual;
00343          break;
00344 
00345       case GL_ALWAYS:
00346          ePassMode = GS::ATest::kAlways;
00347          break;
00348 
00349       default:
00350          mError("Unknown alpha test function");
00351          return;
00352    }
00353 
00354    DrawEnv->SetAlphaRefVal((unsigned int)(ref * 0xff));
00355    DrawEnv->SetAlphaTestPassMode(ePassMode);
00356    DrawEnv->SetAlphaTestFailAction(GS::ATest::kKeep);
00357 
00358    GLContext.AlphaTestFuncChanged();
00359 }
00360 
00361 /********************************************
00362  * CDListDrawContext methods
00363  */
00364 
00365 class CSetDrawBuffers : public CDListCmd {
00366       GS::CMemArea      *Frame0, *Frame1, *Depth;
00367       bool              Interlaced;
00368    public:
00369       CSetDrawBuffers( bool inter, GS::CMemArea *frame0, GS::CMemArea *frame1, GS::CMemArea *depth )
00370          : Frame0(frame0), Frame1(frame1), Depth(depth), Interlaced(inter) {}
00371       CDListCmd* Play() {
00372          pGLContext->GetImmDrawContext().SetDrawBuffers( Interlaced, Frame0, Frame1, Depth );
00373          return CDListCmd::GetNextCmd(this);
00374       }
00375 };
00376 
00377 void
00378 CDListDrawContext::SetDrawBuffers( bool interlaced,
00379                                    GS::CMemArea *frame0Mem, GS::CMemArea *frame1Mem,
00380                                    GS::CMemArea *depthMem )
00381 {
00382    GLContext.GetDListGeomManager().Flush();
00383 
00384    GLContext.GetDListManager().GetOpenDList() += CSetDrawBuffers(interlaced,
00385                                                                  frame0Mem, frame1Mem,
00386                                                                  depthMem);
00387    GLContext.DrawBufferChanged();
00388 }
00389 
00390 class CSetDoSmoothShadingCmd : public CDListCmd {
00391       bool      DoSS;
00392    public:
00393       CSetDoSmoothShadingCmd( bool yesNo ) : DoSS(yesNo) {}
00394       CDListCmd* Play() {
00395          pGLContext->GetImmDrawContext().SetDoSmoothShading( DoSS );
00396          return CDListCmd::GetNextCmd( this );
00397       }
00398 };
00399 
00400 void
00401 CDListDrawContext::SetDoSmoothShading( bool yesNo )
00402 {
00403    GLContext.GetDListGeomManager().Flush();
00404 
00405    GLContext.GetDListManager().GetOpenDList() += CSetDoSmoothShadingCmd( yesNo );
00406    GLContext.ShadingChanged();
00407 }
00408 
00409 class CSetDoClippingCmd : public CDListCmd {
00410       bool      DoClip;
00411    public:
00412       CSetDoClippingCmd(bool clip) : DoClip(clip) {}
00413       CDListCmd* Play() {
00414          pGLContext->GetImmDrawContext().SetDoClipping(DoClip);
00415          return CDListCmd::GetNextCmd(this);
00416       }
00417 };
00418 
00419 void
00420 CDListDrawContext::SetDoClipping( bool clip )
00421 {
00422    GLContext.GetDListGeomManager().Flush();
00423 
00424    GLContext.GetDListManager().GetOpenDList() += CSetDoClippingCmd(clip);
00425    GLContext.ClippingEnabledChanged();
00426 }
00427 
00428 class CSetDoCullFaceCmd : public CDListCmd {
00429       bool      DoCull;
00430    public:
00431       CSetDoCullFaceCmd(bool cull) : DoCull(cull) {}
00432       CDListCmd* Play() {
00433          pGLContext->GetImmDrawContext().SetDoCullFace(DoCull);
00434          return CDListCmd::GetNextCmd(this);
00435       }
00436 };
00437 
00438 void
00439 CDListDrawContext::SetDoCullFace( bool cull )
00440 {
00441    GLContext.GetDListGeomManager().Flush();
00442 
00443    GLContext.GetDListManager().GetOpenDList() += CSetDoCullFaceCmd(cull);
00444    GLContext.CullFaceEnabledChanged();
00445 }
00446 
00447 class CSetCullFaceDir : public CDListCmd {
00448       int       CullDir;
00449    public:
00450       CSetCullFaceDir(int dir) : CullDir(dir) {}
00451       CDListCmd* Play() {
00452          pGLContext->GetImmDrawContext().SetCullFaceDir(CullDir);
00453          return CDListCmd::GetNextCmd(this);
00454       }
00455 };
00456 
00457 void
00458 CDListDrawContext::SetCullFaceDir( int direction )
00459 {
00460    GLContext.GetDListGeomManager().Flush();
00461 
00462    GLContext.GetDListManager().GetOpenDList() += CSetCullFaceDir(direction);
00463    GLContext.CullFaceDirChanged();
00464 }
00465 
00466 class CSetBlendEnabledCmd : public CDListCmd {
00467       bool      Enabled;
00468    public:
00469       CSetBlendEnabledCmd( bool enabled ) : Enabled(enabled) {}
00470       CDListCmd* Play() {
00471          pGLContext->GetImmDrawContext().SetBlendEnabled(Enabled);
00472          return CDListCmd::GetNextCmd(this);
00473       }
00474 };
00475 
00476 void
00477 CDListDrawContext::SetBlendEnabled( bool enabled )
00478 {
00479    GLContext.GetDListGeomManager().Flush();
00480 
00481    GLContext.GetDListManager().GetOpenDList() += CSetBlendEnabledCmd(enabled);
00482    GLContext.BlendEnabledChanged();
00483 }
00484 
00485 class CSetAlphaTestEnabledCmd : public CDListCmd {
00486       bool      Enabled;
00487    public:
00488       CSetAlphaTestEnabledCmd( bool enabled ) : Enabled(enabled) {}
00489       CDListCmd* Play() {
00490          pGLContext->GetImmDrawContext().SetAlphaTestEnabled(Enabled);
00491          return CDListCmd::GetNextCmd(this);
00492       }
00493 };
00494 
00495 void
00496 CDListDrawContext::SetAlphaTestEnabled( bool enabled )
00497 {
00498    GLContext.GetDListGeomManager().Flush();
00499 
00500    GLContext.GetDListManager().GetOpenDList() += CSetAlphaTestEnabledCmd(enabled);
00501    GLContext.AlphaTestEnabledChanged();
00502 }
00503 
00504 class CSetInterlacingOffsetCmd : public CDListCmd {
00505       float     Offset;
00506    public:
00507       CSetInterlacingOffsetCmd( float offset ) : Offset(offset) {}
00508       CDListCmd* Play() {
00509          pGLContext->GetImmDrawContext().SetInterlacingOffset(Offset);
00510          return CDListCmd::GetNextCmd(this);
00511       }
00512 };
00513 
00514 void
00515 CDListDrawContext::SetInterlacingOffset( float yPixels )
00516 {
00517    GLContext.GetDListGeomManager().Flush();
00518 
00519    GLContext.GetDListManager().GetOpenDList() += CSetInterlacingOffsetCmd(yPixels);
00520    GLContext.DrawEnvChanged();
00521 }
00522 
00523 class CSetAlphaFuncCmd : public CDListCmd {
00524     GLenum   Func;
00525     GLclampf Ref;
00526 public:
00527     CSetAlphaFuncCmd( GLenum func, GLclampf ref ) : Func(func), Ref(ref) {}
00528     CDListCmd* Play() {
00529         pGLContext->GetImmDrawContext().SetAlphaFunc(Func, Ref);
00530         return CDListCmd::GetNextCmd(this);
00531     }
00532 };
00533 
00534 void 
00535 CDListDrawContext::SetAlphaFunc( GLenum func, GLclampf ref )
00536 {
00537     GLContext.GetDListGeomManager().Flush();
00538     
00539     GLContext.GetDListManager().GetOpenDList() += CSetAlphaFuncCmd(func, ref);
00540     GLContext.AlphaTestFuncChanged();
00541 }
00542 
00543 class CSetRescaleNormalsCmd : public CDListCmd {
00544       bool      Rescale;
00545    public:
00546       CSetRescaleNormalsCmd( bool rescale ) : Rescale(rescale) {}
00547       CDListCmd* Play() {
00548          pGLContext->GetDrawContext().SetRescaleNormals(Rescale);
00549          return CDListCmd::GetNextCmd(this);
00550       }
00551 };
00552 
00553 void
00554 CDListDrawContext::SetRescaleNormals( bool rescale )
00555 {
00556    GLContext.GetDListGeomManager().Flush();
00557 
00558    GLContext.GetDListManager().GetOpenDList() += CSetRescaleNormalsCmd(rescale);
00559    GLContext.LightPropChanged();
00560 }
00561 
00562 class CSetBlendMode : public CDListCmd {
00563       GLenum    Source, Dest;
00564    public:
00565       CSetBlendMode( GLenum s, GLenum d ) : Source(s), Dest(d) {}
00566       CDListCmd* Play() {
00567          pGLContext->GetImmDrawContext().SetBlendMode( Source, Dest );
00568          return CDListCmd::GetNextCmd(this);
00569       }
00570 };
00571 
00572 void
00573 CDListDrawContext::SetBlendMode( GLenum source, GLenum dest )
00574 {
00575    GLContext.GetDListGeomManager().Flush();
00576 
00577    GLContext.GetDListManager().GetOpenDList() += CSetBlendMode(source, dest);
00578    GLContext.BlendModeChanged();
00579 }
00580 
00581 class CSetDepthWriteEnabledCmd : public CDListCmd {
00582       bool      Enabled;
00583    public:
00584       CSetDepthWriteEnabledCmd( bool enabled ) : Enabled(enabled) {}
00585       CDListCmd* Play() {
00586          pGLContext->GetImmDrawContext().SetDepthWriteEnabled(Enabled);
00587          return CDListCmd::GetNextCmd(this);
00588       }
00589 };
00590 
00591 void
00592 CDListDrawContext::SetDepthWriteEnabled( bool enabled )
00593 {
00594    GLContext.GetDListGeomManager().Flush();
00595 
00596    GLContext.GetDListManager().GetOpenDList() += CSetDepthWriteEnabledCmd(enabled);
00597    GLContext.DepthWriteEnabledChanged();
00598 }
00599 
00600 class CSetFrameBufferDrawMaskCmd : public CDListCmd {
00601       unsigned int      Mask;
00602    public:
00603       CSetFrameBufferDrawMaskCmd( unsigned int mask ) : Mask(mask) {}
00604       CDListCmd* Play() {
00605          pGLContext->GetImmDrawContext().SetFrameBufferDrawMask(Mask);
00606          return CDListCmd::GetNextCmd(this);
00607       }
00608 };
00609 
00610 void
00611 CDListDrawContext::SetFrameBufferDrawMask( unsigned int mask )
00612 {
00613    GLContext.GetDListGeomManager().Flush();
00614 
00615    GLContext.GetDListManager().GetOpenDList() += CSetFrameBufferDrawMaskCmd(mask);
00616    GLContext.FrameBufferDrawMaskChanged();  
00617 }
00618 
00619 /********************************************
00620  * gl api
00621  */
00622 
00623 void glDepthFunc( GLenum func )
00624 {
00625    mNotImplemented( );
00626 }
00627 
00628 void glDrawBuffer( GLenum mode )
00629 {
00630    mNotImplemented( );
00631 }
00632 
00633 void glClipPlane( GLenum plane, const GLdouble *equation )
00634 {
00635    mNotImplemented( );
00636 }
00637 
00638 // alpha blending
00639 
00640 void glBlendFunc( GLenum sfactor, GLenum dfactor )
00641 {
00642    pGLContext->GetDrawContext().SetBlendMode( sfactor, dfactor );
00643 }
00644 
00645 // alpha test
00646 
00647 void glAlphaFunc( GLenum func, GLclampf ref )
00648 {
00649    pGLContext->GetDrawContext().SetAlphaFunc( func, ref );
00650 }
00651 
00652 // depth test
00653 
00654 void glDepthMask( GLboolean enabled )
00655 {
00656    CImmDrawContext &drawContext = pGLContext->GetImmDrawContext();
00657    drawContext.SetDepthWriteEnabled(enabled);
00658 }
00659 
00660 void glShadeModel( GLenum mode )
00661 {
00662    CImmDrawContext &drawContext = pGLContext->GetImmDrawContext();
00663    drawContext.SetDoSmoothShading( (mode == GL_FLAT) ? false : true );
00664 }
00665 
00666 void glCullFace( GLenum mode )
00667 {
00668    mWarnIf( mode == GL_FRONT_AND_BACK, "GL_FRONT_AND_BACK culling is not supported" );
00669    CImmDrawContext &drawContext = pGLContext->GetImmDrawContext();
00670    drawContext.SetCullFaceDir( (mode == GL_FRONT) ? 1 : -1 );
00671 }
00672 
00673 void glColorMask( GLboolean r_enabled, GLboolean g_enabled, 
00674                   GLboolean b_enabled, GLboolean a_enabled)
00675 {
00676    CImmDrawContext &drawContext = pGLContext->GetImmDrawContext();
00677    unsigned int mask=0;
00678    if (r_enabled==GL_FALSE) mask|=0xff;
00679    if (g_enabled==GL_FALSE) mask|=0xff00;
00680    if (b_enabled==GL_FALSE) mask|=0xff0000;
00681    if (a_enabled==GL_FALSE) mask|=0xff000000;
00682    drawContext.SetFrameBufferDrawMask(mask);
00683 }
00684 
00685 void glPolygonMode( GLenum /*face*/, GLenum mode )
00686 {
00687    CImmDrawContext &drawContext = pGLContext->GetImmDrawContext();
00688    drawContext.SetPolygonMode(mode);
00689 }
00690 
00691 /********************************************
00692  * ps2gl api
00693  */
00694 
00708 void
00709 pglSetDrawBuffers( int interlaced,
00710                    pgl_area_handle_t frame0_mem, pgl_area_handle_t frame1_mem,
00711                    pgl_area_handle_t depth_mem )
00712 {
00713    pGLContext->GetDrawContext().SetDrawBuffers( interlaced,
00714                                                 reinterpret_cast<GS::CMemArea*>(frame0_mem),
00715                                                 reinterpret_cast<GS::CMemArea*>(frame1_mem),
00716                                                 reinterpret_cast<GS::CMemArea*>(depth_mem) );
00717 }
00718 
00719 void
00720 pglSetInterlacingOffset( float yPixels )
00721 {
00722    pGLContext->GetDrawContext().SetInterlacingOffset(yPixels);
00723 }
00724  // pgl_api

ps2gl version cvs