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

clear.cpp

Go to the documentation of this file.
00001 /*           Copyright (C) 2001 Sony Computer Entertainment America
00002                               All Rights Reserved
00003                                SCEA Confidential                                */
00004 
00005 #include "ps2s/math.h"
00006 #include "ps2s/packet.h"
00007 
00008 #include "ps2gl/clear.h"
00009 #include "ps2gl/glcontext.h"
00010 #include "ps2gl/immgmanager.h"
00011 #include "ps2gl/drawcontext.h"
00012 
00013 CClearEnv::CClearEnv()
00014 {
00015    pDrawEnv = new GS::CDrawEnv( GS::kContext2 );
00016    pDrawEnv->SetDepthTestPassMode( GS::ZTest::kAlways );
00017 
00018    pSprite = new CSprite( GS::kContext2, 0, 0, 0, 0 );
00019    pSprite->SetUseTexture( false );
00020    unsigned int clearColor[4] = { 0, 0, 0, 0 };
00021    pSprite->SetColor( clearColor[0], clearColor[1], clearColor[2], clearColor[3] );
00022    pSprite->SetDepth( 0 );
00023 }
00024 
00025 CClearEnv::~CClearEnv()
00026 {
00027    delete pDrawEnv;
00028    delete pSprite;
00029 }
00030 
00031 void
00032 CClearEnv::SetDimensions( int width, int height )
00033 {
00034    pDrawEnv->SetFrameBufferDim( width, height );
00035    pSprite->SetVertices( 0, 0, width, height );
00036 }
00037 
00038 void
00039 CClearEnv::SetFrameBufPsm( GS::tPSM psm )
00040 {
00041    pDrawEnv->SetFrameBufferPSM( psm );
00042 }
00043 
00044 void
00045 CClearEnv::SetDepthBufPsm( GS::tPSM psm )
00046 {
00047    pDrawEnv->SetDepthBufferPSM( psm );
00048 }
00049 
00050 void
00051 CClearEnv::ClearBuffers( unsigned int bitMask )
00052 {
00053   if ( bitMask & GL_DEPTH_BUFFER_BIT )
00054     pDrawEnv->EnableDepthTest();
00055   else
00056     pDrawEnv->DisableDepthTest();
00057 
00058   if ( bitMask & GL_COLOR_BUFFER_BIT )
00059     pDrawEnv->SetFrameBufferDrawMask( 0 );
00060   else
00061     pDrawEnv->SetFrameBufferDrawMask( 0xffffffff );
00062 
00063   CVifSCDmaPacket &packet = pGLContext->GetVif1Packet();
00064   pDrawEnv->SendSettings( packet );
00065   pSprite->Draw( packet );
00066 }
00067 
00068 /********************************************
00069  * C gl api
00070  */
00071 
00072 void glClearColor( GLclampf red,
00073                    GLclampf green,
00074                    GLclampf blue,
00075                    GLclampf alpha )
00076 {
00077    CClearEnv& clearEnv = pGLContext->GetImmDrawContext().GetClearEnv();
00078 
00079    using namespace Math;
00080    clearEnv.SetClearColor( Clamp(red, 0.0f, 1.0f),
00081                            Clamp(green, 0.0f, 1.0f),
00082                            Clamp(blue, 0.0f, 1.0f),
00083                            Clamp(alpha, 0.0f, 1.0f) );
00084 }
00085 
00086 void glClearDepth( GLclampd depth )
00087 {
00088    CClearEnv& clearEnv = pGLContext->GetImmDrawContext().GetClearEnv();
00089 
00090    clearEnv.SetClearDepth( (float)depth );
00091 }
00092 
00093 void glClear( GLbitfield mask )
00094 {
00095   pGLContext->GetImmDrawContext().GetClearEnv().ClearBuffers( mask );
00096 }
00097 

ps2gl version 0.2