00001
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 #ifndef ps2gl_texture_h
00008 #define ps2gl_texture_h
00009
00010 #include "ps2s/texture.h"
00011 #include "ps2s/gsmem.h"
00012
00013 #include "GL/gl.h"
00014
00015
00016 * CTexManager
00017 */
00018
00019 class CGLContext;
00020 class CMMTexture;
00021 class CMMClut;
00022 class CVifSCDmaPacket;
00023
00024 class CTexManager {
00025 CGLContext &GLContext;
00026
00027 bool IsTexEnabled;
00028 bool InsideDListDef;
00029
00030 static const int NumTexNames = 512;
00031 CMMTexture *TexNames[NumTexNames];
00032 unsigned int Cursor;
00033
00034 CMMTexture *DefaultTex, *CurTexture, *LastTexSent;
00035 CMMClut *CurClut;
00036 GS::tTexMode TexMode;
00037
00038 void IncCursor() { Cursor = (Cursor + 1) & (NumTexNames - 1); }
00039 public:
00040 CTexManager( CGLContext &context );
00041 ~CTexManager();
00042
00043 void SetTexEnabled( bool yesNo );
00044 bool GetTexEnabled() const { return IsTexEnabled; }
00045
00046 void GenTextures( GLsizei numNewTexNames, GLuint *newTexNames );
00047 void BindTexture( GLuint texNameToBind );
00048 void DeleteTextures( GLsizei numToDelete, const GLuint *texNames );
00049
00050 CMMTexture& GetCurTexture() const { return *CurTexture; }
00051
00052 CMMTexture& GetNamedTexture( GLuint tex ) const {
00053 mErrorIf( TexNames[tex] == NULL, "Trying to access a null texture" );
00054 return *TexNames[tex];
00055 }
00056
00057 void UseCurTexture( CVifSCDmaPacket &renderPacket );
00058
00059 void SetTexMode( GS::tTexMode mode );
00060
00061 void SetCurTexParam( GLenum pname, GLint param );
00062 void SetCurTexImage( tU128* imagePtr, tU32 w, tU32 h,
00063 GS::tPSM psm );
00064 void SetGsTexture( GS::CMemArea &area );
00065 void SetCurClut( const void *clut, int numEntries );
00066
00067 void BeginDListDef() { InsideDListDef = true; }
00068 void EndDListDef() { InsideDListDef = false; }
00069 };
00070
00071
00072 * CMMClut
00073 */
00074
00078 class CMMClut : public GS::CClut {
00079 GS::CMemArea GsMem;
00080 public:
00081 CMMClut( const void *table, int numEntries = 256 )
00082 : GS::CClut(table, numEntries),
00083 GsMem(16, 16, GS::kPsm32, GS::kAlignPage)
00084 { }
00085
00086 ~CMMClut() { }
00087
00088 void Load( CVifSCDmaPacket &packet );
00089 };
00090
00091
00092 * CMMTexture (Mem Managed Texture)
00093 */
00094
00095 namespace GS {
00096 class CMemArea;
00097 }
00098
00099 class CMMTexture : public GS::CTexture
00100 {
00101 GS::CMemArea *pImageMem;
00102 bool XferImage;
00103 bool IsResident;
00104
00105 public:
00106 CMMTexture( GS::tContext context );
00107 ~CMMTexture();
00108
00109 void SetImage( const GS::CMemArea &area );
00110 void SetImage( tU128* imagePtr, tU32 w, tU32 h, GS::tPSM psm );
00111
00112 void SetClut( const CMMClut &clut ) {
00113 CTexEnv::SetClutGsAddr( clut.GetGsAddr() );
00114 }
00115
00116 void ChangePsm( GS::tPSM psm );
00117
00118
00119
00120
00121
00122
00123 void Load( bool waitForEnd = true );
00124 void Use( bool waitForEnd = false );
00125
00126 void Load( CSCDmaPacket& packet );
00127 void Load( CVifSCDmaPacket& packet );
00128
00129 void Use( CSCDmaPacket& packet );
00130 void Use( CVifSCDmaPacket& packet );
00131
00132 void BindToSlot( GS::CMemSlot &slot );
00133 void Free( void );
00134 };
00135
00136 #endif // ps2gl_texture_h