resonance 1.0.1
Loading...
Searching...
No Matches
Rnd::Tex Class Reference

Texture, as a bitmap path plus the load state of its mip levels. More...

#include <tex.h>

Inheritance diagram for Rnd::Tex:
Collaboration diagram for Rnd::Tex:

Public Types

enum  TexFunc { kTexFuncModulate = 0 , kTexFuncDecal = 1 , kTexFuncHighlight = 2 , kTexFuncHighlight2 = 3 }
 Texture function, the GS TEX0.TFX field, which decides how a texel meets the vertex. More...

Public Member Functions

 Tex (const HxStr &name)
 Construct a texture with no bitmap.
virtual ~Tex ()
 Free the loaded bitmaps and drop every reference to this texture.
int GetBitmapInfo (int &nWidth, int &nHeight, int &nBitsPerPixel, int &nBytes)
 Report the size of mip level 0 and the bytes every loaded level occupies.
const HxStr & GetRelativeBitmapPath () const
 Report mBitmapPath relative to FilePath::sRoot.
virtual void DumpText (Dbg &sink)
 Write the dimensions, the mip selector, the path, and the flag names to sink.
virtual void Save (Stream &stream)
 Write revision 4, the three dimensions, the path, mFlags, and mMipSelect.
virtual void Replace (Object *pFrom, Object *pTo)
 Do nothing.
virtual const HxStr & ClassName () const
 Report the registered class name, "Tex".
virtual void Copy (const Object *pSource, unsigned nFlags)
 Take the dimensions, path, mip selector, and flags of another texture and reload.
virtual void Load (Stream &stream)
 Replace this texture's configuration from stream and reload.
bool IsLoadComplete ()
 Report whether every requested mip level has finished loading.
void SetBitmapConfig (int nWidth, int nHeight, int nBitsPerPixel, const HxStr &path, int nMipSelect, int nFlags)
 Point the texture at a bitmap and restart its load.
bool PollAsyncMips ()
 Advance the asynchronous mip loads and report whether any level is still outstanding.
void AllocateBitmapFromStream ()
 Start loading the configured bitmap, or build a blank one when no path is set.
void CancelPendingMips ()
 Cancel whatever mip reads are still outstanding and drop every mip handle.
virtual void ReloadBitmaps ()
 Release the loaded bitmaps and start loading from the configured path again.
virtual ACanvas * LockMipBitmap (int nMip, int nReserved, int nFlags)
 Lock the bitmap of one mip level for direct access.
virtual void UnlockMipBitmap ()
 Release the mip level that LockMipBitmap() locked.
virtual void SetPalette (APalette *pPalette, int nReserved)
 Replace the palette every mip level shares.
virtual void SetGsPageInUse (bool bInUse)
 Mark the texture's GS page as in use or free.
virtual void FreeLoadedBitmaps ()
 Release every loaded bitmap and cancel the outstanding reads.
Public Member Functions inherited from Rnd::Object
 Object ()
 Construct an unnamed object.
 Object (const HxStr &name)
 Construct an object and register it under name.
virtual ~Object ()
 Erase the registry entry and release the name buffer.
void SetName (const HxStr &name)
 Re-register this object under a different name.
void AddRef (Object *pReferrer)
 Register pReferrer as a store of a pointer to this object.
void RemoveRef (Object *pReferrer)
 Drop one registration made by AddRef().

Static Public Member Functions

static void * operator new (size_t nSize)
 Allocate a texture block under the tag "Rnd::Tex".
static void operator delete (void *pBlock)
 Release a texture block under the same tag.

Public Attributes

int mWidth
int mHeight
int mBitsPerPixel
int mFlags
 Flag word SetBitmapConfig() records and DumpText() labels " flags:".
int mMipSelect
 Mip selector SetBitmapConfig() records, starting at -0x80.
Public Attributes inherited from Rnd::Object
HxStr mName
int mInternal

Static Public Attributes

static Tex *(* sNew )(const HxStr &name)
 Creator the registered "Tex" class builds through.
static HxStr sClassName
 Registered class name of Rnd::Tex, the string "Tex".

Protected Member Functions

void WaitForMipsLoaded ()
 Block until every requested mip level has arrived, pumping the asynchronous reads meanwhile.
virtual void RestoreSurfaces ()
 Rebuild whatever the texture keeps in GS memory.
virtual void OnMipLoaded (int nMip)
 Take delivery of one mip level whose read has just finished.
Protected Member Functions inherited from Rnd::Object
void ReleaseAllRefs ()
 Tell every referrer to drop its pointer to this object.

Protected Attributes

std::vector< int > mMipHandles
unsigned char mPendingMipMask
FilePath mBitmapPath
int mZone
std::vector< ABitmap * > mLoadedBitmaps
Protected Attributes inherited from Rnd::Object
std::list< Object * > mRefs

Detailed Description

Texture, as a bitmap path plus the load state of its mip levels.

Its RTTI descriptor is at 0x008ef140. It has Rnd::Object as its one public non-virtual base at offset 0. The class factory allocates 0x58 bytes. The texture's members therefore occupy +0x1c through +0x57. The implementation file is rndtex.cpp, attested by its assert strings, and the bitmap header it includes is C:/FREQ/src/rndartt/abitmap.h.

A texture owns no pixels. The mip levels load asynchronously into the handle vector, and the hardware residency belongs to the PlayStation 2 subclass Rnd::PsTex, whose GS slot state extends the object past +0x4a8.

The vtable has sixteen entries, so the class declares eight virtuals of its own beyond the six of Rnd::Object. Slots 8 through 15 are ReloadBitmaps(), LockMipBitmap(), UnlockMipBitmap(), SetPalette(), SetGsPageInUse(), FreeLoadedBitmaps(), RestoreSurfaces(), and OnMipLoaded().

mFlags is the flag word DumpText() labels " flags:", and DumpText() lists its bits by name.

mBitmapPath is a Rnd::FilePath, whose routines sit in this unit and take the path's address rather than the texture's. SetBitmapConfig() installs the path through FilePath::Set() for a verbatim path and through FilePath::SetFromRoot() to prefix FilePath::sRoot.

Member Enumeration Documentation

◆ TexFunc

Texture function, the GS TEX0.TFX field, which decides how a texel meets the vertex.

Enumerator
kTexFuncModulate 

Texel times vertex colour.

kTexFuncDecal 

Texel alone.

kTexFuncHighlight 

Texel plus vertex colour.

kTexFuncHighlight2 

Texel plus vertex colour, alpha from the texel.

Constructor & Destructor Documentation

◆ Tex()

Rnd::Tex::Tex ( const HxStr & name)

Construct a texture with no bitmap.

The mip selector starts at -0x80 and mZone at -1, which selects the tagged heap.

Parameters
nameThe object name, passed to the Rnd::Object constructor.
Ghidra address:
NTSC-U/C: 0x004e3dc8
Ghidra address:
PAL: 0x00522698

◆ ~Tex()

virtual Rnd::Tex::~Tex ( )
virtual

Free the loaded bitmaps and drop every reference to this texture.

Ghidra address:
NTSC-U/C: 0x004e7628
Ghidra address:
PAL: 0x005260c8

Member Function Documentation

◆ operator new()

void * Rnd::Tex::operator new ( size_t nSize)
static

Allocate a texture block under the tag "Rnd::Tex".

Parameters
nSizeThe object size the compiler supplies.
Returns
The block.
Ghidra address:
NTSC-U/C: 0x004e7388
Ghidra address:
PAL: 0x00525e28

◆ operator delete()

void Rnd::Tex::operator delete ( void * pBlock)
static

Release a texture block under the same tag.

Parameters
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x004e73a8
Ghidra address:
PAL: 0x00525e48

◆ GetBitmapInfo()

int Rnd::Tex::GetBitmapInfo ( int & nWidth,
int & nHeight,
int & nBitsPerPixel,
int & nBytes )

Report the size of mip level 0 and the bytes every loaded level occupies.

Level 0 is locked through LockMipBitmap() for its width, height, and depth. Every level is then locked with read-back requested, and each contributes its pixel bytes and four bytes per palette entry. A texture with no level 0 bitmap reports failure without unlocking it. The name is inferred.

Parameters
nWidthReceives the width of level 0.
nHeightReceives the height of level 0.
nBitsPerPixelReceives the depth of level 0.
nBytesReceives the bytes of every level.
Returns
Non-zero on success.
Ghidra address:
NTSC-U/C: 0x004e3e48
Ghidra address:
PAL: 0x00522720

◆ GetRelativeBitmapPath()

const HxStr & Rnd::Tex::GetRelativeBitmapPath ( ) const

Report mBitmapPath relative to FilePath::sRoot.

The result lives in the function-local static FilePath::RelativeToRoot() returns. The routine has no caller in the shipped build. The name is inferred.

Returns
The relative path.
Ghidra address:
NTSC-U/C: 0x004e7568
Ghidra address:
PAL: 0x00526008

◆ DumpText()

virtual void Rnd::Tex::DumpText ( Dbg & sink)
virtual

Write the dimensions, the mip selector, the path, and the flag names to sink.

The flag word is dumped under " flags:" by name, or as "None" when it is zero. Bit kABitmapColorKeyBlack prints "TransparentWhite, " as bit kABitmapColorKeyWhite does, because the image reuses the one string for both.

Parameters
sinkThe text sink.
Ghidra address:
NTSC-U/C: 0x004e4738
Ghidra address:
PAL: 0x00523010

Reimplemented from Rnd::Object.

◆ Save()

virtual void Rnd::Tex::Save ( Stream & stream)
virtual

Write revision 4, the three dimensions, the path, mFlags, and mMipSelect.

Rnd::Object::Save() is not called.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x004e4910
Ghidra address:
PAL: 0x005231e8

Implements Rnd::Object.

◆ Replace()

virtual void Rnd::Tex::Replace ( Object * pFrom,
Object * pTo )
virtual

Do nothing.

A texture has no object references to retarget.

Parameters
pFromUnused.
pToUnused.
Ghidra address:
NTSC-U/C: 0x004e7610
Ghidra address:
PAL: 0x005260b0

Implements Rnd::Object.

◆ ClassName()

virtual const HxStr & Rnd::Tex::ClassName ( ) const
virtual

Report the registered class name, "Tex".

Returns
Tex::sClassName.
Ghidra address:
NTSC-U/C: 0x004e7618
Ghidra address:
PAL: 0x005260b8

Implements Rnd::Object.

◆ Copy()

virtual void Rnd::Tex::Copy ( const Object * pSource,
unsigned nFlags )
virtual

Take the dimensions, path, mip selector, and flags of another texture and reload.

The loaded bitmaps are freed first and AllocateBitmapFromStream() runs last. Rnd::Object::Copy() is not called, and nFlags is ignored.

Parameters
pSourceThe texture to copy, which has to be a Rnd::Tex.
nFlagsUnused.
Ghidra address:
NTSC-U/C: 0x004e79f0
Ghidra address:
PAL: 0x005264a0

Implements Rnd::Object.

◆ Load()

virtual void Rnd::Tex::Load ( Stream & stream)
virtual

Replace this texture's configuration from stream and reload.

A revision above 4 is reported as "Can't load new Tex" and nothing else is read. Revision 1 stores the width and the height as 16-bit values. Revisions 1 and 2 store one byte after the flags that is read and discarded, and mMipSelect is stored from revision 4. The loaded bitmaps are freed before the read and AllocateBitmapFromStream() runs after it. Rnd::Object::Load() is not called.

Parameters
streamThe stream to read from.
Ghidra address:
NTSC-U/C: 0x004e4a20
Ghidra address:
PAL: 0x005232f8

Implements Rnd::Object.

◆ IsLoadComplete()

bool Rnd::Tex::IsLoadComplete ( )

Report whether every requested mip level has finished loading.

Returns
True when no level is outstanding.
Ghidra address:
NTSC-U/C: 0x004e7878
Ghidra address:
PAL: 0x00526328

◆ SetBitmapConfig()

void Rnd::Tex::SetBitmapConfig ( int nWidth,
int nHeight,
int nBitsPerPixel,
const HxStr & path,
int nMipSelect,
int nFlags )

Point the texture at a bitmap and restart its load.

Records the bitmap dimensions, the mip selector, and the flags. An absolute path is stored through FilePath::Set() and any other through FilePath::SetFromRoot(). The pending mip reads are then cancelled and the mip handle vector is emptied. No load starts here.

Parameters
nWidthThe bitmap width.
nHeightThe bitmap height.
nBitsPerPixelThe bitmap depth.
pathThe bitmap path.
nMipSelectThe mip selector, which starts at -0x80.
nFlagsThe flag word, recorded in mFlags.
Ghidra address:
NTSC-U/C: 0x004e7908
Ghidra address:
PAL: 0x005263b8

◆ PollAsyncMips()

bool Rnd::Tex::PollAsyncMips ( )

Advance the asynchronous mip loads and report whether any level is still outstanding.

Each pending level is polled once. A level that has arrived is stored, reported through OnMipLoaded(), and cleared from the pending mask. A level that failed is reported through the failure sink and also cleared, which stops a caller spinning on a read that will never finish. RestoreSurfaces() runs once the mask empties.

Returns
True once no level is outstanding, including after a failure.
Ghidra address:
NTSC-U/C: 0x004e4410
Ghidra address:
PAL: 0x00522ce8

◆ AllocateBitmapFromStream()

void Rnd::Tex::AllocateBitmapFromStream ( )

Start loading the configured bitmap, or build a blank one when no path is set.

The mip handles are dropped and the current zone becomes mZone. With a bitmap path the cached copies of the base level and its mip levels are queued for reading, and a failure zeroes the dimensions and the depth before RestoreSurfaces() runs. Without a path one blank level is allocated in a single block, from the tagged heap when mZone is -1 and from the zone otherwise. The block holds the bitmap header, then a palette for a depth of 8 bits or fewer, then the pixels on a 16-byte boundary. Flag 0x40 of mFlags triples the width and doubles the height of that level. The level is recorded as loaded and RestoreSurfaces() runs.

Ghidra address:
NTSC-U/C: 0x004e3fe8
Ghidra address:
PAL: 0x005228c0

◆ CancelPendingMips()

void Rnd::Tex::CancelPendingMips ( )

Cancel whatever mip reads are still outstanding and drop every mip handle.

The pending mask is left as it was, so a later poll still waits on the cancelled levels.

Ghidra address:
NTSC-U/C: 0x004e4648
Ghidra address:
PAL: 0x00522f20

◆ ReloadBitmaps()

virtual void Rnd::Tex::ReloadBitmaps ( )
virtual

Release the loaded bitmaps and start loading from the configured path again.

Vtable slot 8. The body is FreeLoadedBitmaps() followed by AllocateBitmapFromStream(). Rnd::PsTex's table addresses a byte-identical per-unit copy at 0x0059a8c8. Rnd::Movie's SetFrameSelf() calls it after SetBitmapConfig(). The name is inferred.

Ghidra address:
NTSC-U/C: 0x004e73c8
Ghidra address:
PAL: 0x00525e68

◆ LockMipBitmap()

virtual ACanvas * Rnd::Tex::LockMipBitmap ( int nMip,
int nReserved,
int nFlags )
virtual

Lock the bitmap of one mip level for direct access.

Vtable slot 9. Rnd::Tex returns null without doing anything. Rnd::PsTex records the level so that UnlockMipBitmap() can mark it dirty. The second parameter is read by neither implementation, so its purpose is unrecovered. The name is inferred from the pairing with slot 10 rather than from any string in the image.

Parameters
nMipThe mip level.
nReservedThe second parameter. No recovered implementation reads it. Every recovered caller passes 0.
nFlagsBit 1 requests a read-back from GS memory.
Returns
The canvas over the level, or null when the class has none.
Ghidra address:
NTSC-U/C: 0x004e75a0
Ghidra address:
PAL: 0x00526040

Reimplemented in Rnd::PsTex.

◆ UnlockMipBitmap()

virtual void Rnd::Tex::UnlockMipBitmap ( )
virtual

Release the mip level that LockMipBitmap() locked.

Vtable slot 10. Empty in Rnd::Tex. The name is inferred as above.

Ghidra address:
NTSC-U/C: 0x004e75f8
Ghidra address:
PAL: 0x00526098

Reimplemented in Rnd::PsTex.

◆ SetPalette()

virtual void Rnd::Tex::SetPalette ( APalette * pPalette,
int nReserved )
virtual

Replace the palette every mip level shares.

Vtable slot 11. Empty in Rnd::Tex. The name is inferred as above.

Parameters
pPaletteThe replacement palette.
nReservedA second word, unread by every recovered implementation. Rnd::Movie's palette chunk handler passes -1 explicitly at 0x005cf55c.
Ghidra address:
NTSC-U/C: 0x004e7600
Ghidra address:
PAL: 0x005260a0

Reimplemented in Rnd::PsTex.

◆ SetGsPageInUse()

virtual void Rnd::Tex::SetGsPageInUse ( bool bInUse)
virtual

Mark the texture's GS page as in use or free.

Vtable slot 12. Empty in Rnd::Tex. The PlayStation 2 override pins the video memory block of mip 0 against eviction, or releases the pin. The name is inferred.

Parameters
bInUseWhether the page is in use.
Ghidra address:
NTSC-U/C: 0x004e7608
Ghidra address:
PAL: 0x005260a8

Reimplemented in Rnd::PsTex.

◆ FreeLoadedBitmaps()

virtual void Rnd::Tex::FreeLoadedBitmaps ( )
virtual

Release every loaded bitmap and cancel the outstanding reads.

Vtable slot 13. A bitmap allocated from a zone goes with its zone. Only a bitmap from the tagged heap, while mZone is -1, is released, and the release is billed to rndtex.cpp line 610.

Ghidra address:
NTSC-U/C: 0x004e7aa8
Ghidra address:
PAL: 0x00526558

Reimplemented in Rnd::PsTex.

◆ WaitForMipsLoaded()

void Rnd::Tex::WaitForMipsLoaded ( )
inlineprotected

Block until every requested mip level has arrived, pumping the asynchronous reads meanwhile.

Rnd::PsTex open-codes the body in BindToGsSlot(), LockMipBitmap(), SetGsPageInUse(), and the routine at 0x00596d68. The out-of-line copy has no caller.

Ghidra address:
NTSC-U/C: 0x004e75a8
Ghidra address:
PAL: 0x00526048

◆ RestoreSurfaces()

virtual void Rnd::Tex::RestoreSurfaces ( )
protectedvirtual

Rebuild whatever the texture keeps in GS memory.

Vtable slot 14. The base body refreshes mWidth, mHeight, and mBitsPerPixel from the first loaded bitmap when there is one, and then empties the mip handle vector. The name is the routine's own. The PlayStation 2 override reports "ERROR - RestoreSurfaces(s), mipmap d has no bm!", and the helper it calls reports "Got NULL Palette in RestoreSurfaces".

Ghidra address:
NTSC-U/C: 0x004e4598
Ghidra address:
PAL: 0x00522e70

Reimplemented in Rnd::PsTex.

◆ OnMipLoaded()

virtual void Rnd::Tex::OnMipLoaded ( int nMip)
protectedvirtual

Take delivery of one mip level whose read has just finished.

Vtable slot 15. The level's block is a bitmap header followed by a palette and the pixels. An indexed format (4 bit, 8 bit, or run length 8 bit) points the bitmap at both. A direct colour format has no palette, and its pixels start where the palette would. Red and blue are then swapped unless g_nSkipColorSwap is set. Flag 0x10 of mFlags runs ABitmap::SetPaletteAlphaFromLowByte(0), or else flag 0x20 runs it with 1, and ABitmap::ApplyColorKey() receives mFlags whole. A level whose width or height is not a power of two is reported to Rnd::TheDbg. A level above zero whose size is not mWidth and mHeight shifted right by nMip is reported as well. Neither report stops the load. Rnd::PsTex runs this body first and then uploads the level to GS memory. The name is inferred from the position of the call inside PollAsyncMips().

Parameters
nMipThe level that arrived, which both implementations use to index the loaded bitmaps.
Ghidra address:
NTSC-U/C: 0x004e5928
Ghidra address:
PAL: 0x00524378

Reimplemented in Rnd::PsTex.

Member Data Documentation

◆ sNew

Tex *(* Rnd::Tex::sNew) (const HxStr &name)
static

Creator the registered "Tex" class builds through.

The default creator allocates 0x58 bytes and constructs a Rnd::Tex. GfxDevice::Init() and the PlayStation 2 texture layer both overwrite the hook with the Rnd::PsTex creator.

Ghidra address:
NTSC-U/C: 0x007033a8
Ghidra address:
PAL: 0x00746e58

◆ sClassName

HxStr Rnd::Tex::sClassName
static

Registered class name of Rnd::Tex, the string "Tex".

Ghidra address:
NTSC-U/C: 0x007033b0
Ghidra address:
PAL: 0x00746e60

◆ mWidth

int Rnd::Tex::mWidth

◆ mHeight

int Rnd::Tex::mHeight

◆ mBitsPerPixel

int Rnd::Tex::mBitsPerPixel

◆ mFlags

int Rnd::Tex::mFlags

Flag word SetBitmapConfig() records and DumpText() labels " flags:".

Public because Rnd::Movie's SetFrameSelf() reads it to pass it back unchanged. +0x28

◆ mMipHandles

std::vector<int> Rnd::Tex::mMipHandles
protected

◆ mPendingMipMask

unsigned char Rnd::Tex::mPendingMipMask
protected

◆ mMipSelect

int Rnd::Tex::mMipSelect

Mip selector SetBitmapConfig() records, starting at -0x80.

Public because Rnd::Movie's SetFrameSelf() reads it to pass it back unchanged. +0x3c

◆ mBitmapPath

FilePath Rnd::Tex::mBitmapPath
protected

◆ mZone

int Rnd::Tex::mZone
protected

◆ mLoadedBitmaps

std::vector<ABitmap *> Rnd::Tex::mLoadedBitmaps
protected

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