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

PlayStation 2 material, which drives the GS register state. More...

#include <psmat.h>

Inheritance diagram for Rnd::PsMat:
Collaboration diagram for Rnd::PsMat:

Public Member Functions

 PsMat (const HxStr &name)
 Construct a material with the default surface.
virtual ~PsMat ()
virtual void SetAmbient (const Color &color)
virtual void SetDiffuse (const Color &color)
virtual void SetEmissive (const Color &color)
virtual void SetAlpha (float flAlpha)
virtual void SetSpecular (const Color &color, float flAlpha)
int Select ()
 Apply the next pass of this material to the GS.
void SelectAlphaBlend ()
 Force ALPHA_1 to the standard source-alpha equation whatever the material blend is.
Public Member Functions inherited from Rnd::Mat
 Mat (const HxStr &name)
 Construct a material with the default surface.
virtual ~Mat ()
void AddStage ()
 Append one stage with the default surface, owned by this material.
void RemoveStage (int nIndex)
 Remove one stage, dropping this material's reference on its texture.
void GetMeshReferrers (std::vector< Mesh * > &meshes)
 Append every referrer of this material whose class is "Mesh" to meshes.
virtual void DumpText (Dbg &sink)
 Write the material to the engine text sink.
virtual void Save (Stream &stream)
 Serialise the material.
virtual void Replace (Object *pFrom, Object *pTo)
 Replace one object reference with another.
virtual const HxStr & ClassName () const
 Return the registered class name, "Mat".
virtual void Copy (const Object *pSource, unsigned nFlags)
 Copy another material over this one.
virtual void Load (Stream &stream)
 Load the material.
virtual void SyncMat (int nStage)
 Virtual with an empty body in Rnd::Mat.
virtual void SetLighting (int nEnable, int nVertAmbient, int nVertDiffuse, int nVertSpecular, int nVertEmissive, int nVertAlpha, int nNormalize)
 Set the lighting enable flag, the five per-vertex source flags, and the normalise flag.
virtual void Refresh ()
 Resynchronise the material after its state or its stage vector has changed.
void SetMultiPass (int nMultiPass)
 Set the multi-pass count.
void SetFlat (int nFlat)
 Set whether the surface shades flat.
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 InstallCreator ()
 Install the PlayStation 2 material creator and build the fixed sphere-map UV transform.
static void SelectDefault ()
 Drop the cached material state and program the GS for the default opaque surface.
Static Public Member Functions inherited from Rnd::Mat
static void * operator new (size_t nSize)
 Allocate a material block under the tag "Rnd::Mat".
static void operator delete (void *pBlock)
 Release a material block under the same tag.

Static Public Attributes

static Mat * sCurrent
 Material that Rnd::Mat::SelectMaterial() last applied, or null when the applied state is stale.
Static Public Attributes inherited from Rnd::Mat
static HxStr sClassName
 Registered class name of Rnd::Mat, the string "Mat".

Additional Inherited Members

Public Types inherited from Rnd::Mat
enum  BlendMode {
  kBlendModeDest = 0 , kBlendModeSrc = 1 , kBlendModeAdd = 2 , kBlendModeMultiply = 3 ,
  kBlendModeMultiply2 = 4 , kBlendModeSrcAlpha = 5 , kBlendModeSrcAlphaAdd = 6 , kBlendModeSrcAdd = 7 ,
  kBlendModeInvSrcAlpha = 8 , kBlendModeDestAlpha = 9 , kBlendModeInvDestAlpha = 10 , kBlendModeSrcAlphaOpaque = 11 ,
  kBlendModeSrcAlphaCutout = 12
}
 Frame buffer blend, as the text dump labels the values. More...
enum  Cull { kCullModeCw = 0 , kCullModeCcw = 1 , kCullModeNone = 2 }
 Face winding the rasteriser discards, as the text dump labels the values. More...
enum  TexGen {
  kGenModeFixed = 0 , kGenModeSphere = 1 , kGenModePlanar = 2 , kGenModeOrthoCube = 3 ,
  kGenModeLocalCube = 4
}
 How a texture stage produces its texture coordinates. More...
enum  TexWrap { kWrapModeClamp = 0 , kWrapModeRepeat = 1 , kWrapModeMirror = 2 }
 How a texture coordinate outside the unit square resolves. More...
enum  { kSerialVersion = 7 }
 Serial version this build writes, and the highest version it loads. More...
Public Attributes inherited from Rnd::Mat
std::vector< Stage > mStages
Color mEmissive
 Colour the surface emits.
Color mAmbient
 Ambient colour.
Color mDiffuse
 Diffuse colour.
Color mSpecular
int mVertAmbient
 Non-zero when the vertex colour supplies the ambient term in place of mAmbient.
int mVertDiffuse
 Non-zero when the vertex colour supplies the diffuse term in place of mDiffuse.
int mVertEmissive
 Vertex emissive flag.
int mVertAlpha
 Vertex alpha flag.
Cull mCull
int mFlat
Public Attributes inherited from Rnd::Object
HxStr mName
int mInternal
Protected Member Functions inherited from Rnd::Mat
void RemoveStageTexRefs ()
 Drop this material's reference on every stage texture.
Protected Member Functions inherited from Rnd::Object
void ReleaseAllRefs ()
 Tell every referrer to drop its pointer to this object.
Protected Attributes inherited from Rnd::Mat
BlendMode mBlend
int mEnable
int mVertSpecular
int mNormalize
int mMultiPass
Protected Attributes inherited from Rnd::Object
std::list< Object * > mRefs

Detailed Description

PlayStation 2 material, which drives the GS register state.

Its RTTI descriptor is at 0x008efe50. It has Rnd::Mat as its one public base at offset 0 and no member. The sixteen-entry vtable at 0x00830f98 differs from the Rnd::Mat table at 0x00822dd8 in six slots, the destructor at slot 1 and the five colour setters at slots 9 through 13.

Every override below performs the base assignment and then clears sCurrent, which forces the next draw to re-emit the material registers.

The constructor body is empty and the destructor body is one statement. The factory at 0x005914b8 inlines the constructor, and the destructor at 0x00591590 inlines the whole Rnd::Mat destructor after its one statement.

The hardware binding path is the rest of the file, and every title in it is inferred from the register writes and from the cache global each routine maintains.

Which class declares that path is ambiguous. Every call site passes a plain Rnd::Mat *, Rnd::Mesh::DrawInstanced at 0x005b2f84, Rnd::PsParticleSys::Draw at 0x005fcbcc and 0x005fcc20, and Rnd::PsMesh::DrawShowing at 0x0060239c and 0x00602518, and an upcast to a base at offset 0 emits no instruction, so the image cannot separate a platform-implemented Rnd::Mat member from a Rnd::PsMat member the caller narrowed to. The declarations are here because the rest of this tree places a platform surface on the Ps subclass, as Rnd::PsTex does with its GS binding. Moving them to mat.h unchanged is the alternative reading.

Constructor & Destructor Documentation

◆ PsMat()

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

Construct a material with the default surface.

The body is empty. Rnd::NewPsMat() is the only construction site.

Parameters
nameThe object name, passed to the Rnd::Object constructor.

◆ ~PsMat()

virtual Rnd::PsMat::~PsMat ( )
virtual
Ghidra address:
NTSC-U/C: 0x00591590
Ghidra address:
PAL: 0x005d4928

Member Function Documentation

◆ InstallCreator()

void Rnd::PsMat::InstallCreator ( )
static

Install the PlayStation 2 material creator and build the fixed sphere-map UV transform.

GfxDevice::Init() invokes this at 0x0049af48. The title is inferred from the creator hook the routine overwrites.

Ghidra address:
NTSC-U/C: 0x00591240
Ghidra address:
PAL: 0x005d45c0

◆ SetAmbient()

virtual void Rnd::PsMat::SetAmbient ( const Color & color)
virtual
Ghidra address:
NTSC-U/C: 0x005916b0
Ghidra address:
PAL: 0x005d4a48

Reimplemented from Rnd::Mat.

◆ SetDiffuse()

virtual void Rnd::PsMat::SetDiffuse ( const Color & color)
virtual
Ghidra address:
NTSC-U/C: 0x005916c8
Ghidra address:
PAL: 0x005d4a60

Reimplemented from Rnd::Mat.

◆ SetEmissive()

virtual void Rnd::PsMat::SetEmissive ( const Color & color)
virtual
Ghidra address:
NTSC-U/C: 0x005916f0
Ghidra address:
PAL: 0x005d4a88

Reimplemented from Rnd::Mat.

◆ SetAlpha()

virtual void Rnd::PsMat::SetAlpha ( float flAlpha)
virtual
Ghidra address:
NTSC-U/C: 0x00591730
Ghidra address:
PAL: 0x005d4ac8

Reimplemented from Rnd::Mat.

◆ SetSpecular()

virtual void Rnd::PsMat::SetSpecular ( const Color & color,
float flAlpha )
virtual
Ghidra address:
NTSC-U/C: 0x00591708
Ghidra address:
PAL: 0x005d4aa0

Reimplemented from Rnd::Mat.

◆ Select()

int Rnd::PsMat::Select ( )

Apply the next pass of this material to the GS.

A material that is already selected and has at most one stage re-emits ALPHA_1 alone, and only when SelectAlphaBlend() overrode it. Otherwise the stage index resets or advances, and the blend mode, the stage texture, and the UV transform are all reselected.

Returns
Non-zero while further stages remain, which asks the caller to draw again.
Ghidra address:
NTSC-U/C: 0x0058eb40
Ghidra address:
PAL: 0x005d1e98

◆ SelectDefault()

void Rnd::PsMat::SelectDefault ( )
static

Drop the cached material state and program the GS for the default opaque surface.

GfxDevice::BeginFrame() invokes this once per frame, and a draw of a mesh with no material invokes it in place of Select().

Ghidra address:
NTSC-U/C: 0x005910b0
Ghidra address:
PAL: 0x005d4430

◆ SelectAlphaBlend()

void Rnd::PsMat::SelectAlphaBlend ( )

Force ALPHA_1 to the standard source-alpha equation whatever the material blend is.

The override is recorded, so the next Select() on the same material restores the material blend. The edge pass of Rnd::PsMesh::DrawShowing() is the only call site.

Ghidra address:
NTSC-U/C: 0x00591170
Ghidra address:
PAL: 0x005d44f0

Member Data Documentation

◆ sCurrent

Mat* Rnd::PsMat::sCurrent
static

Material that Rnd::Mat::SelectMaterial() last applied, or null when the applied state is stale.

Selecting a material stores it here, and the PlayStation 2 entry point compares against it to skip work that is already done. Every property setter writes null to make the next selection apply the change, and Rnd::PsMat's destructor clears it when the material being destroyed is the selected one.

Ghidra address:
NTSC-U/C: 0x0076d658
Ghidra address:
PAL: 0x007b13b0

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