wavelength 1.0.0
Loading...
Searching...
No Matches
PsTex Class Reference

Texture, PlayStation 2. More...

#include <pstex.h>

Inheritance diagram for PsTex:
Collaboration diagram for PsTex:

Classes

struct  FreeRange
 A run of free GS blocks. More...
struct  UsedRange
 The GS blocks of the CLUT or of one mipmap. More...

Public Member Functions

 PsTex (const char *pszName)
 Construct a texture without GS blocks.
 ~PsTex () override
 Release the GS blocks and the movie packet.
void * operator new (size_t nSize)
 Allocate a texture from its pool.
void operator delete (void *pBlock)
 Return a texture to its pool.
RndBitmap * LockBitmap (int nFlags) override
 Give access to the bitmap, recording the access for UnlockBitmap().
void UnlockBitmap () override
 Mark the first range for upload, and the second as well when the palette changed.
void SyncBitmap () override
 Load the bitmap, then build the GS registers and the ranges for it.
void ResetBitmap () override
 Release the GS blocks, then the bitmap.
void Place ()
 Give each range without blocks its blocks and mark it for upload.
void BuildMoviePacket (bool bBuild)
 Release the movie packet, then build one for the current bitmap when requested.
void UploadMovie ()
 Copy the movie packet into the frame, flushing the frame whenever the packet fills it.
void UploadImage (int nDbp, int nPsm, int nBpp, int nWidth, int nHeight, const unsigned char *pPixels)
 Add an image transfer of pixels in main memory to the frame.
void Upload ()
 Place the ranges, upload those marked for upload, and flush the texture cache.
void BindAsRenderTarget ()
 Make the first mipmap the surface the GS draws into.
void SyncRegisters ()
 Build TEX0, TEX1, and the buffer widths of MIPTBP1 and MIPTBP2, and add a range for the CLUT and for each mipmap.
void ReleaseSurfaces ()
 Release the bitmap and the GS blocks, and empty the ranges.
void Select (int nTexFunction)
 Upload the texture when needed, then select it on the GS with a texture function.
Public Member Functions inherited from RndTex
 RndTex (const char *pszName)
 Construct an empty 32-bit texture without a file.
 ~RndTex () override
 Release the bitmap.
void * operator new (size_t nSize)
 Allocate a texture, billed to the class name.
void operator delete (void *pBlock)
 Release a texture.
void DumpText (PrnStream &stream) override
 Write a description of the texture, and of its bitmap at a dump level of 2 or more.
void Save (BinStream &stream) override
 Write the texture.
void Replace (RndObject *pFrom, RndObject *pTo) override
 Do nothing, for a texture refers to no object.
const char * ClassName () const override
 Report the class name.
void Copy (const RndObject *pSource, int nFlags) override
 Copy the size, the format, and the file of another texture, then load the bitmap again.
void Load (BinStream &stream) override
 Read what Save() wrote, or an earlier version of it, then load the bitmap.
void SetBitmap (int nWidth, int nHeight, int nBpp, const FilePath &file, int nMipMapK, int nRendered)
 Set the size, the format, and the file, then load the bitmap.
bool CheckSize ()
 Report whether the size and the format are valid, with a notice when they are not unless a dimension is 0.
const FilePath & GetFile () const
int GetHeight () const
int GetMipMapK () const
int GetWidth () const
Public Member Functions inherited from RndObject
 RndObject (const char *pszName)
 Construct an object and register it under a name.
virtual ~RndObject ()
 Notify every referrer, then erase the registration.
void SetName (const char *pszName)
 Register the object under a different name.
void AddRef (RndObject *pReferrer)
 Register an object as a store of a pointer to this one.
void RemoveRef (RndObject *pReferrer)
 Drop the first registration AddRef() made for a referrer.
const char * GetName () const
const std::list< RndObject * > & GetRefs () const
int GetInternal () const
void SetInternal (int nInternal)

Static Public Member Functions

static void BeginFrame ()
 Evict every range not selected since the last call, and record the stamp.
static int FreeBlockCount ()
 Count the free GS blocks.
static void ReserveDisplayMemory ()
 Free every block after the display and depth buffers, and evict every range.
static void FreeBlocks (int nStart, int nCount)
 Return a run of blocks to the free list, merging it with its neighbours.
static int NumBlocks (const RndBitmap &bitmap)
 Report the GS blocks a bitmap occupies, rounded up to the shapes the GS pages allow.
static void Init ()
 Install the texture factory for the class Tex of a .rnd file, and reset both stamps.
static RndObject * New (const char *pszName)
 Create a texture.
Static Public Member Functions inherited from RndTex
static const char * CheckDim (int nSize)
 Report what is wrong with a texture dimension.
static RndObject * New (const char *pszName)
 Create a texture.

Static Public Attributes

static std::list< FreeRange > sFreeRanges
 The free runs, in block order.
static std::list< UsedRange * > sUsedRanges
 The ranges with blocks, in the order they received them.
static int sStamp
 The count of selections, the stamp Select() records on each range.
static int sEvictStamp
 The value of sStamp at the last BeginFrame().
Static Public Attributes inherited from RndTex
static const char * sClassName
 The class name a .rnd file writes, Tex.
static int sRev
 The format version Save() writes and Load() accepts.
Static Public Attributes inherited from RndObject
static constexpr int kCopyChildLists = 0x200
 The bit of the Copy() flags that copies the child lists of the mix-ins.

Additional Inherited Members

Protected Attributes inherited from RndTex
RndBitmap mBitmap
int mMipMapK
int mRendered
int mWidth
int mHeight
int mBpp
FilePath mFile
Protected Attributes inherited from RndObject
std::list< RndObject * > mRefs
String mName

Detailed Description

Texture, PlayStation 2.

The RTTI includes the class name and records RndTex as the one base. GS memory is a cache of 16384 blocks of 256 bytes. Each texture has one UsedRange for its CLUT, when it has a palette, and one for each mipmap. A range receives blocks when the texture is next selected, from the free list or, failing that, from a range of another texture that was not selected since the last BeginFrame(). A texture also builds the TEX0, TEX1, MIPTBP1, and MIPTBP2 images it selects.

Constructor & Destructor Documentation

◆ PsTex()

PsTex::PsTex ( const char * pszName)
explicit

Construct a texture without GS blocks.

Parameters
pszNameThe registry key.
Ghidra address:
NTSC-U/C: 0x00218278
Ghidra address:
PAL: 0x00221090

◆ ~PsTex()

PsTex::~PsTex ( )
override

Release the GS blocks and the movie packet.

Ghidra address:
NTSC-U/C: 0x002182c8
Ghidra address:
PAL: 0x002210e0

Member Function Documentation

◆ operator new()

void * PsTex::operator new ( size_t nSize)
inline

Allocate a texture from its pool.

Parameters
nSizeThe object size the compiler supplies.
Returns
The block.

◆ operator delete()

void PsTex::operator delete ( void * pBlock)
inline

Return a texture to its pool.

Parameters
pBlockThe block.

◆ LockBitmap()

RndBitmap * PsTex::LockBitmap ( int nFlags)
overridevirtual

Give access to the bitmap, recording the access for UnlockBitmap().

Parameters
nFlagsThe access the caller needs. Bit 2 marks the palette as changed.
Returns
The bitmap.
Ghidra address:
NTSC-U/C: 0x00218fa8
Ghidra address:
PAL: 0x00221dc0

Reimplemented from RndTex.

◆ UnlockBitmap()

void PsTex::UnlockBitmap ( )
overridevirtual

Mark the first range for upload, and the second as well when the palette changed.

Ghidra address:
NTSC-U/C: 0x00218fb8
Ghidra address:
PAL: 0x00221dd0

Reimplemented from RndTex.

◆ SyncBitmap()

void PsTex::SyncBitmap ( )
inlineoverridevirtual

Load the bitmap, then build the GS registers and the ranges for it.

Ghidra address:
NTSC-U/C: 0x0037d0b0
Ghidra address:
PAL: 0x003eb7e0

Reimplemented from RndTex.

◆ ResetBitmap()

void PsTex::ResetBitmap ( )
inlineoverridevirtual

Release the GS blocks, then the bitmap.

Ghidra address:
NTSC-U/C: 0x0037d0e0
Ghidra address:
PAL: 0x003eb810

Reimplemented from RndTex.

◆ Place()

void PsTex::Place ( )

Give each range without blocks its blocks and mark it for upload.

When neither the free list nor another texture can supply a range, every texture is evicted and the free list starts again. The first range is the CLUT when the bitmap has a palette. The name is inferred.

Ghidra address:
NTSC-U/C: 0x00217380
Ghidra address:
PAL: 0x00220198

◆ BuildMoviePacket()

void PsTex::BuildMoviePacket ( bool bBuild)

Release the movie packet, then build one for the current bitmap when requested.

The packet uploads the bitmap in blocks of 16 by 16 pixels. UploadMovie() copies it into the frame. The name is inferred.

Parameters
bBuildWhether to build a packet.
Ghidra address:
NTSC-U/C: 0x00217628
Ghidra address:
PAL: 0x00220440

◆ UploadMovie()

void PsTex::UploadMovie ( )

Copy the movie packet into the frame, flushing the frame whenever the packet fills it.

The name is inferred.

Ghidra address:
NTSC-U/C: 0x00217830
Ghidra address:
PAL: 0x00220648

◆ UploadImage()

void PsTex::UploadImage ( int nDbp,
int nPsm,
int nBpp,
int nWidth,
int nHeight,
const unsigned char * pPixels )

Add an image transfer of pixels in main memory to the frame.

A null image adds nothing. The texture is not read. The name is inferred.

Parameters
nDbpThe destination base pointer in blocks.
nPsmThe GS pixel storage mode.
nBppThe bits per pixel.
nWidthThe width.
nHeightThe height.
pPixelsThe pixels, or null.
Ghidra address:
NTSC-U/C: 0x00217a18
Ghidra address:
PAL: 0x00220830

◆ Upload()

void PsTex::Upload ( )

Place the ranges, upload those marked for upload, and flush the texture cache.

The name is inferred.

Ghidra address:
NTSC-U/C: 0x00217be0
Ghidra address:
PAL: 0x002209f8

◆ BindAsRenderTarget()

void PsTex::BindAsRenderTarget ( )

Make the first mipmap the surface the GS draws into.

FRAME_1 addresses the mipmap, XYOFFSET_1 centres it, and a 16-bit texture is dithered.

Ghidra address:
NTSC-U/C: 0x00218028
Ghidra address:
PAL: 0x00220e40

◆ SyncRegisters()

void PsTex::SyncRegisters ( )

Build TEX0, TEX1, and the buffer widths of MIPTBP1 and MIPTBP2, and add a range for the CLUT and for each mipmap.

A rendered texture of fewer than 16 bits per pixel is first made 16 bits. The name is inferred.

Ghidra address:
NTSC-U/C: 0x002184f8
Ghidra address:
PAL: 0x00221310

◆ ReleaseSurfaces()

void PsTex::ReleaseSurfaces ( )

Release the bitmap and the GS blocks, and empty the ranges.

The name is inferred.

Ghidra address:
NTSC-U/C: 0x00218f00
Ghidra address:
PAL: 0x00221d18

◆ Select()

void PsTex::Select ( int nTexFunction)

Upload the texture when needed, then select it on the GS with a texture function.

Each range is stamped with sStamp, and sStamp then advances. A texture without a bitmap selects nothing.

Parameters
nTexFunctionThe TFX field of TEX0.
Ghidra address:
NTSC-U/C: 0x00218fe0
Ghidra address:
PAL: 0x00221df8

◆ BeginFrame()

void PsTex::BeginFrame ( )
static

Evict every range not selected since the last call, and record the stamp.

The name is inferred.

Ghidra address:
NTSC-U/C: 0x00216c98
Ghidra address:
PAL: 0x0021fab0

◆ FreeBlockCount()

int PsTex::FreeBlockCount ( )
static

Count the free GS blocks.

The name is inferred.

Returns
The count.
Ghidra address:
NTSC-U/C: 0x00216d38
Ghidra address:
PAL: 0x0021fb50

◆ ReserveDisplayMemory()

void PsTex::ReserveDisplayMemory ( )
static

Free every block after the display and depth buffers, and evict every range.

The name is inferred.

Ghidra address:
NTSC-U/C: 0x00216d88
Ghidra address:
PAL: 0x0021fba0

◆ FreeBlocks()

void PsTex::FreeBlocks ( int nStart,
int nCount )
static

Return a run of blocks to the free list, merging it with its neighbours.

The name is inferred.

Parameters
nStartThe first block.
nCountThe number of blocks, or 0 to change nothing.
Ghidra address:
NTSC-U/C: 0x00217d88
Ghidra address:
PAL: 0x00220ba0

◆ NumBlocks()

int PsTex::NumBlocks ( const RndBitmap & bitmap)
static

Report the GS blocks a bitmap occupies, rounded up to the shapes the GS pages allow.

The name is inferred.

Parameters
bitmapThe bitmap.
Returns
The block count.
Ghidra address:
NTSC-U/C: 0x002183d0
Ghidra address:
PAL: 0x002211e8

◆ Init()

void PsTex::Init ( )
static

Install the texture factory for the class Tex of a .rnd file, and reset both stamps.

The name is inferred.

Ghidra address:
NTSC-U/C: 0x00218168
Ghidra address:
PAL: 0x00220f80

◆ New()

RndObject * PsTex::New ( const char * pszName)
inlinestatic

Create a texture.

Parameters
pszNameThe registry key.
Returns
The texture.
Ghidra address:
NTSC-U/C: 0x0037d068
Ghidra address:
PAL: 0x003eb798

Member Data Documentation

◆ sFreeRanges

std::list<FreeRange> PsTex::sFreeRanges
static

The free runs, in block order.

Ghidra address:
NTSC-U/C: 0x0043c600

◆ sUsedRanges

std::list<UsedRange *> PsTex::sUsedRanges
static

The ranges with blocks, in the order they received them.

Ghidra address:
NTSC-U/C: 0x0043c608

◆ sStamp

int PsTex::sStamp
static

The count of selections, the stamp Select() records on each range.

Ghidra address:
NTSC-U/C: 0x003b07d8
Ghidra address:
PAL: 0x0042f670

◆ sEvictStamp

int PsTex::sEvictStamp
static

The value of sStamp at the last BeginFrame().

A range stamped before it is evicted.

Ghidra address:
NTSC-U/C: 0x003b07dc
Ghidra address:
PAL: 0x0042f674

The documentation for this class was generated from the following file: