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

texture.h

Go to the documentation of this file.
00001 /*           Copyright (C) 2001 Sony Computer Entertainment America
00002                               All Rights Reserved
00003                                SCEA Confidential                                */
00004 
00005 #ifndef ps2gl_texture_h
00006 #define ps2gl_texture_h
00007 
00008 #include "ps2s/texture.h"
00009 
00010 #include "GL/gl.h"
00011 
00012 /********************************************
00013  * CTexManager
00014  */
00015 
00016 class CGLContext;
00017 class CMMTexture;
00018 class CMMClut;
00019 class CVifSCDmaPacket;
00020 
00021 class CTexManager {
00022       CGLContext        &GLContext;
00023 
00024       bool              IsTexEnabled;
00025       bool              InsideDListDef;
00026 
00027       static const int  NumTexNames = 512;      // :TODO: Make configurable
00028       CMMTexture        *TexNames[NumTexNames];
00029       unsigned int      Cursor;
00030 
00031       CMMTexture        *DefaultTex, *CurTexture, *LastTexSent;
00032       CMMClut           *CurClut;
00033       GS::tTexMode      TexMode;
00034 
00035       void IncCursor() { Cursor = (Cursor + 1) & (NumTexNames - 1); }
00036    public:
00037       CTexManager( CGLContext &context );
00038       ~CTexManager();
00039 
00040       void SetTexEnabled( bool yesNo );
00041       bool GetTexEnabled() const { return IsTexEnabled; }
00042 
00043       void GenTextures( GLsizei numNewTexNames, GLuint *newTexNames );
00044       void BindTexture( GLuint texNameToBind );
00045       void DeleteTextures( GLsizei numToDelete, const GLuint *texNames );
00046 
00047       CMMTexture& GetCurTexture() const { return *CurTexture; }
00048 
00049       void UseCurTexture( CVifSCDmaPacket &renderPacket );
00050 
00051       void SetTexMode( GS::tTexMode mode );
00052 
00053       void SetCurTexParam( GLenum pname, GLint param );
00054       void SetCurTexImage( tU128* imagePtr, tU32 w, tU32 h,
00055                            GS::tPSM psm );
00056       void SetGsTexture( GS::CMemArea &area );
00057       void SetCurClut( const void *clut, int numEntries );
00058 
00059       void BeginDListDef() { InsideDListDef = true; }
00060       void EndDListDef() { InsideDListDef = false; }
00061 };
00062 
00063 /********************************************
00064  * CMMClut
00065  */
00066 
00070 class CMMClut : public GS::CClut {
00071       GS::CMemArea      GsMem;
00072    public:
00073       CMMClut( const void *table, int numEntries = 256 )
00074          : GS::CClut(table, numEntries),
00075            GsMem(16, 16, GS::kPsm32, GS::kAlignPage)
00076       { }
00077 
00078       ~CMMClut() { }
00079 
00080       void Load( CVifSCDmaPacket &packet );
00081 };
00082 
00083 /********************************************
00084  * CMMTexture (Mem Managed Texture)
00085  */
00086 
00087 namespace GS {
00088    class CMemArea;
00089 }
00090 
00091 class CMMTexture : public GS::CTexture
00092 {
00093       GS::CMemArea      *pImageMem;
00094       bool              XferImage;
00095 
00096    public:
00097       CMMTexture( GS::tContext context );
00098       ~CMMTexture();
00099 
00100       void SetImage( const GS::CMemArea &area );
00101       void SetImage( tU128* imagePtr, tU32 w, tU32 h, GS::tPSM psm );
00102 
00103       void SetClut( const CMMClut &clut ) {
00104          CTexEnv::SetClutGsAddr( clut.GetGsAddr() );
00105       }
00106 
00107       // the following Load methods will check to see if a texture is resident and
00108       // transfer it if necessary.  The Use methods invoke the corresponding Load but
00109       // also transfer the gs register settings that belong to the texture
00110 
00111       // warning! these two will flush the data cache!
00112       void Load( bool waitForEnd = true );
00113       void Use( bool waitForEnd = false );
00114 
00115       void Load( CSCDmaPacket& packet );
00116       void Load( CVifSCDmaPacket& packet );
00117 
00118       void Use( CSCDmaPacket& packet );
00119       void Use( CVifSCDmaPacket& packet );
00120 
00121       void Free( void );
00122 };
00123 
00124 #endif // ps2gl_texture_h

ps2gl version 0.2