PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
texture.h
1/* Copyright (C) 2000,2001,2002 Sony Computer Entertainment America
2
3 This file is subject to the terms and conditions of the GNU Lesser
4 General Public License Version 2.1. See the file "COPYING" in the
5 main directory of this archive for more details. */
6
7#ifndef ps2gl_texture_h
8#define ps2gl_texture_h
9
10#include "ps2s/gsmem.h"
11#include "ps2s/texture.h"
12
13#include "GL/gl.h"
14
15/********************************************
16 * CTexManager
17 */
18
19class CGLContext;
20class CMMTexture;
21class CMMClut;
22class CVifSCDmaPacket;
23
25 CGLContext& GLContext;
26
27 bool IsTexEnabled;
28 bool InsideDListDef;
29
30 static const int NumTexNames = 512; // :TODO: Make configurable
31 CMMTexture* TexNames[NumTexNames];
32 unsigned int Cursor;
33
34 CMMTexture *DefaultTex, *CurTexture, *LastTexSent;
35 CMMClut* CurClut;
36 GS::tTexMode TexMode;
37
38 void IncCursor() { Cursor = (Cursor + 1) & (NumTexNames - 1); }
39
40public:
41 CTexManager(CGLContext& context);
43
44 void SetTexEnabled(bool yesNo);
45 bool GetTexEnabled() const { return IsTexEnabled; }
46
47 void GenTextures(GLsizei numNewTexNames, GLuint* newTexNames);
48 void BindTexture(GLuint texNameToBind);
49 void DeleteTextures(GLsizei numToDelete, const GLuint* texNames);
50
51 CMMTexture& GetCurTexture() const { return *CurTexture; }
52
53 CMMTexture& GetNamedTexture(GLuint tex) const
54 {
55 mErrorIf(TexNames[tex] == NULL, "Trying to access a null texture");
56 return *TexNames[tex];
57 }
58
59 void UseCurTexture(CVifSCDmaPacket& renderPacket);
60
61 void SetTexMode(GS::tTexMode mode);
62
63 void SetCurTexParam(GLenum pname, GLint param);
64 void SetCurTexImage(tU128* imagePtr, tU32 w, tU32 h,
65 GS::tPSM psm);
66 void SetGsTexture(GS::CMemArea& area);
67 void SetCurClut(const void* clut, int numEntries);
68
69 void BeginDListDef() { InsideDListDef = true; }
70 void EndDListDef() { InsideDListDef = false; }
71};
72
73/********************************************
74 * CMMClut
75 */
76
80class CMMClut : public GS::CClut {
81 GS::CMemArea GsMem;
82
83public:
84 CMMClut(const void* table, int numEntries = 256)
85 : GS::CClut(table, numEntries)
86 , GsMem(16, 16, GS::kPsm32, GS::kAlignPage)
87 {
88 }
89
90 ~CMMClut() {}
91
92 void Load(CVifSCDmaPacket& packet);
93};
94
95/********************************************
96 * CMMTexture (Mem Managed Texture)
97 */
98
99namespace GS {
100class CMemArea;
101}
102
103class CMMTexture : public GS::CTexture {
104 GS::CMemArea* pImageMem;
105 bool XferImage;
106 bool IsResident;
107
108public:
109 CMMTexture(GS::tContext context);
110 ~CMMTexture();
111
112 void SetImage(const GS::CMemArea& area);
113 void SetImage(tU128* imagePtr, tU32 w, tU32 h, GS::tPSM psm);
114
115 void SetClut(const CMMClut& clut)
116 {
117 CTexEnv::SetClutGsAddr(clut.GetGsAddr());
118 }
119
120 void ChangePsm(GS::tPSM psm);
121
122 // the following Load methods will check to see if a texture is resident and
123 // transfer it if necessary. The Use methods invoke the corresponding Load but
124 // also transfer the gs register settings that belong to the texture
125
126 // warning! these two will flush the data cache!
127 void Load(bool waitForEnd = true);
128 void Use(bool waitForEnd = false);
129
130 void Load(CSCDmaPacket& packet);
131 void Load(CVifSCDmaPacket& packet);
132
133 void Use(CSCDmaPacket& packet);
134 void Use(CVifSCDmaPacket& packet);
135
136 void BindToSlot(GS::CMemSlot& slot);
137 void Free(void);
138};
139
140#endif // ps2gl_texture_h
void SetImage(const GS::CMemArea &area)
Definition texture.cpp:403