resonance 1.0.1
Loading...
Searching...
No Matches
pstex.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "gfx/vram.h"
6#include "rnd/tex.h"
7#include "rndartt/apalette.h"
8
9class ACanvas;
10class HxStr;
11class VramPalEntry;
12
13namespace Rnd {
14
55class PsTex : public Tex {
56public:
68 PsTex(const HxStr &name);
69
78 virtual ~PsTex();
79
94 virtual ACanvas *LockMipBitmap(int nMip, int nReserved, int nFlags);
95
105 virtual void UnlockMipBitmap();
106
119 virtual void SetPalette(APalette *pPalette, int nReserved);
120
131 virtual void SetGsPageInUse(bool bInUse);
132
141 virtual void FreeLoadedBitmaps();
142
158 virtual void RestoreSurfaces();
159
177 bool BindToGsSlot(unsigned nTexFunc);
178
195
208 int UploadBitmapMipToGs(int nMip);
209
225 int UploadMipAndBuildMipTbp(int nMip, bool bSkipIfResident);
226
239
249 static void Init();
250
251protected:
263 virtual void OnMipLoaded(int nMip);
264
265private:
266 // One mip level's residency, its video memory block and the canvas LockMipBitmap() hands out.
267 // FreeGsSurfaces() deletes the canvas through its virtual destructor.
268 struct GsMip {
269 VRAM::Entry *mPage;
270 ACanvas *mVramBitmap;
271 };
272
282 void FreeGsSurfaces();
283
294 void RebuildClut();
295
305 void AllocPaletteVram();
306
318 int UploadPaletteClut();
319
332 void UploadBitmapMipToSubImage(VRAM::Entry *pPage, int nMip, int nBlockOffset);
333
334 // Declared in recovered offset order. Every member is private, because no access from outside
335 // this class is recovered.
336
337 std::vector<GsMip> mGsMips; // One entry per loaded mip level.
338 unsigned long long mTex0; // GS TEX0_1 image.
339 unsigned long long mTex1; // GS TEX1_1 image.
340 unsigned long long mMipTbp1; // GS MIPTBP1_1 image, levels 1 through 3.
341 unsigned long long mMipTbp2; // GS MIPTBP2_1 image, levels 4 through 6.
342 int mGsPsm; // From g_anGsPixelStorageModes.
343 int mBitsPerPixel; // From g_anBitsPerPixelTable.
344 // First level that shares the page of the level before it, or 9999 while none does.
345 int mFirstPackedMip;
346 // One bit per level awaiting upload, with the sign bit standing for a dirty CLUT.
347 unsigned mDirtyMips;
348 unsigned long long mReserved98; // +0x98 Inferred from the alignment of mClut.
349 // CLUT staging palette, in the GS CSM1 order. The upload sends it by DMA in whole
350 // quadwords. The entries must therefore start on a quadword boundary.
351 alignas(16) APalette mClut;
352 VramPalEntry *mPaletteVram; // The manager's CLUT slot, or null.
353 int mLockedMip; // Level recorded by LockMipBitmap().
354};
355
369Tex *NewPsTex(const HxStr &name);
370
377extern const unsigned int g_dwDefaultClutEntry;
378
387extern const int g_anClutSwizzleBlocks[4];
388
399extern const int g_anPackedMipPageOffsets[6];
400
401} // namespace Rnd
Drawing surface over an ABitmap, with a clip rectangle.
Definition acanvas.h:74
A 256 entry colour table an ABitmap points at.
Definition apalette.h:31
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
void UploadPendingMips()
Upload every level whose dirty bit is set, then clear the mask.
virtual ACanvas * LockMipBitmap(int nMip, int nReserved, int nFlags)
Give the caller the canvas over a mip level to draw into.
int UploadMipAndBuildMipTbp(int nMip, bool bSkipIfResident)
Resolve one mip level's GS block address, uploading the level when needed.
virtual void FreeLoadedBitmaps()
Release every loaded bitmap and every GS surface.
virtual void SetPalette(APalette *pPalette, int nReserved)
Replace the palette of the texture.
static void Init()
Install this class as the texture the renderer builds and program the default filtering.
virtual void OnMipLoaded(int nMip)
Take delivery of one mip level whose read has just finished.
PsTex(const HxStr &name)
Construct a texture with no GS residency.
int UploadBitmapMipToGs(int nMip)
Upload one mip level into the video memory block of its level.
virtual void SetGsPageInUse(bool bInUse)
Pin the video memory block of mip 0 against eviction, or release the pin.
void BindAsRenderTarget()
Make mip 0 the surface the GS draws into.
virtual void UnlockMipBitmap()
Take back the canvas LockMipBitmap() handed out.
virtual void RestoreSurfaces()
Rebuild the GS state of the whole texture from the loaded bitmaps.
virtual ~PsTex()
Release the GS residency and the texture.
bool BindToGsSlot(unsigned nTexFunc)
Make the texture current on the GS, with the given texture function.
Texture, as a bitmap path plus the load state of its mip levels.
Definition tex.h:43
Tex(const HxStr &name)
Construct a texture with no bitmap.
int mBitsPerPixel
Definition tex.h:423
One entry of the GS video memory block table.
Definition vram.h:537
One entry of the GS video memory palette table.
Definition vram.h:139
The rendering engine.
Definition animhelper.h:3
const int g_anPackedMipPageOffsets[6]
Block offset of each packed mip level inside the page of the level before mFirstPackedMip.
const int g_anClutSwizzleBlocks[4]
Block groups of a 256-entry CLUT in the order the CSM1 layout stores them, {0, 2, 1,...
const unsigned int g_dwDefaultClutEntry
The palette entry a level that fails validation is left with, an opaque 8888 colour.
Tex * NewPsTex(const HxStr &name)
Allocate and construct a PlayStation 2 texture.