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

ps2gl version cvs