resonance 1.0.1
Loading...
Searching...
No Matches
mat.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4#include <vector>
5
6#include "math/color.h"
7#include "math/transform.h"
8#include "math/vector3.h"
9#include "os/hxstr.h"
10#include "rnd/manager.h"
11#include "rnd/object.h"
12
13namespace Rnd {
14class Dbg;
15class Mesh;
16class Stream;
17class Tex;
18} // namespace Rnd
19
20namespace Rnd {
21
36class Mat : public Object {
37public:
45
66
73
82
85
94 class Stage {
95 public:
96 BlendMode mBlend; // +0x00 Defaults to kBlendModeMultiply.
97 int mCoordIndex; // +0x04 Which of the two vertex texture coordinate sets to read.
98 TexGen mGenMode; // +0x08
99 Transform mXfm; // +0x10 Identity until a file or an animation writes it.
100 int mUseXfm; // +0x50
101 TexWrap mWrap; // +0x54 Defaults to kWrapModeRepeat.
102 Tex *mTex; // +0x58
103 Mat *mMat; // +0x5c
104
115 void SetTex(Tex *pTex);
116
127
135 void Dump(Dbg &sink) const;
136
148 void Save(Stream &stream) const;
149
164 void Load(Stream &stream);
165 };
166
168 enum { kSerialVersion = 7 };
169
180 Mat(const HxStr &name);
181
186 virtual ~Mat();
187
196 static void *operator new(size_t nSize);
197
205 static void operator delete(void *pBlock);
206
215 void AddStage();
216
227 void RemoveStage(int nIndex);
228
240 void GetMeshReferrers(std::vector<Mesh *> &meshes);
241
242protected:
255
256public:
264 virtual void DumpText(Dbg &sink);
265
273 virtual void Save(Stream &stream);
274
286 virtual void Replace(Object *pFrom, Object *pTo);
287
298 virtual const HxStr &ClassName() const;
299
309 virtual void Copy(const Object *pSource, unsigned nFlags);
310
322 virtual void Load(Stream &stream);
323
335 virtual void SyncMat(int nStage);
336
346 virtual void SetAmbient(const Color &color);
347
362 virtual void SetDiffuse(const Color &color);
363
371 virtual void SetEmissive(const Color &color);
372
380 virtual void SetAlpha(float flAlpha);
381
395 virtual void SetSpecular(const Color &color, float flAlpha);
396
410 virtual void SetLighting(int nEnable,
411 int nVertAmbient,
412 int nVertDiffuse,
413 int nVertSpecular,
414 int nVertEmissive,
415 int nVertAlpha,
416 int nNormalize);
417
427 virtual void Refresh();
428
436 void SetMultiPass(int nMultiPass);
437
445 void SetFlat(int nFlat);
446
447 // Rnd::Font::CharInfo::CharInfo at 0x004ca050 reads the vector's bounds through a Rnd::Mat
448 // pointer from outside the hierarchy, divides the span by 96 to size it, and then reads the
449 // first stage's texture. The image supplies no accessor. The same evidence makes mSpecular
450 // public. The assignment operator Copy() uses is instantiated out of line
451 // at 0x004d77d8, which is library code and has no body in this tree.
452 std::vector<Stage> mStages; // +0x1c
453
454protected:
455 // Every member below is protected rather than private. Rnd::PsMat writes four of the colours in
456 // its setter overrides, and the material selection path in the same file reads the whole
457 // surface to build the GS register writes. The order below is the recovered offset order.
458 BlendMode mBlend; // +0x28 Defaults to kBlendModeSrcAlpha.
459
460public:
468
482
483 // Both edge draw paths read this through a Rnd::Mat pointer from outside the hierarchy, and the
484 // image supplies no accessor for it. That is the same evidence that makes mCull public.
485 Color mSpecular; // +0x60 Defaults to black with full alpha.
486
487protected:
488 int mEnable; // +0x70 Defaults to 1. Serialised as one byte.
489
490public:
506
507protected:
508 int mVertSpecular; // +0x7c Serialised as one byte.
509
510public:
523
524protected:
525 int mNormalize; // +0x88 Serialised as one byte.
526
527public:
532
533protected:
534 int mMultiPass; // +0x90
535
536public:
541 int mFlat;
542};
543
554extern int g_nRndMatLoadVersion;
555
565extern Mat *(*g_pfnNewMat)(const HxStr &name);
566
575Mat *NewMat(const HxStr &name);
576
589
599
611inline void RegisterMatClass() {
614}
615
626extern int g_nStageTextureBound;
627
628} // namespace Rnd
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
void Dump(Dbg &sink) const
Write the stage to the engine text sink.
Stage()
Construct a stage with the default surface.
void SetTex(Tex *pTex)
Replace the stage's texture.
TexGen mGenMode
Definition mat.h:98
Transform mXfm
Definition mat.h:99
void Load(Stream &stream)
Load the stage.
Tex * mTex
Definition mat.h:102
BlendMode mBlend
Definition mat.h:96
int mCoordIndex
Definition mat.h:97
Mat * mMat
Definition mat.h:103
int mUseXfm
Definition mat.h:100
void Save(Stream &stream) const
Serialise the stage.
TexWrap mWrap
Definition mat.h:101
Surface description a Rnd::Mesh draws with.
Definition mat.h:36
virtual void Refresh()
Resynchronise the material after its state or its stage vector has changed.
virtual void SetAlpha(float flAlpha)
Set the diffuse alpha.
void SetMultiPass(int nMultiPass)
Set the multi-pass count.
TexWrap
How a texture coordinate outside the unit square resolves.
Definition mat.h:84
@ kWrapModeMirror
Definition mat.h:84
@ kWrapModeClamp
Definition mat.h:84
@ kWrapModeRepeat
Definition mat.h:84
Color mSpecular
Definition mat.h:485
void GetMeshReferrers(std::vector< Mesh * > &meshes)
Append every referrer of this material whose class is "Mesh" to meshes.
int mVertDiffuse
Non-zero when the vertex colour supplies the diffuse term in place of mDiffuse.
Definition mat.h:505
void RemoveStageTexRefs()
Drop this material's reference on every stage texture.
int mVertEmissive
Vertex emissive flag.
Definition mat.h:516
static HxStr sClassName
Registered class name of Rnd::Mat, the string "Mat".
Definition mat.h:44
Color mEmissive
Colour the surface emits.
Definition mat.h:467
void SetFlat(int nFlat)
Set whether the surface shades flat.
int mMultiPass
Definition mat.h:534
virtual void SetEmissive(const Color &color)
Set the emissive colour.
int mVertAmbient
Non-zero when the vertex colour supplies the ambient term in place of mAmbient.
Definition mat.h:498
BlendMode
Frame buffer blend, as the text dump labels the values.
Definition mat.h:51
@ kBlendModeInvDestAlpha
Definition mat.h:62
@ kBlendModeMultiply
Definition mat.h:55
@ kBlendModeAdd
Definition mat.h:54
@ kBlendModeInvSrcAlpha
Definition mat.h:60
@ kBlendModeSrcAlpha
Definition mat.h:57
@ kBlendModeSrcAlphaOpaque
Definition mat.h:63
@ kBlendModeSrcAdd
Definition mat.h:59
@ kBlendModeSrc
Definition mat.h:53
@ kBlendModeDestAlpha
Definition mat.h:61
@ kBlendModeMultiply2
Definition mat.h:56
@ kBlendModeDest
Definition mat.h:52
@ kBlendModeSrcAlphaAdd
Definition mat.h:58
@ kBlendModeSrcAlphaCutout
Definition mat.h:64
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.
int mVertSpecular
Definition mat.h:508
int mVertAlpha
Vertex alpha flag.
Definition mat.h:522
TexGen
How a texture stage produces its texture coordinates.
Definition mat.h:75
@ kGenModeSphere
Definition mat.h:77
@ kGenModeLocalCube
Definition mat.h:80
@ kGenModeOrthoCube
Definition mat.h:79
@ kGenModeFixed
Definition mat.h:76
@ kGenModePlanar
Definition mat.h:78
Cull mCull
Definition mat.h:531
Color mAmbient
Ambient colour.
Definition mat.h:475
int mNormalize
Definition mat.h:525
virtual ~Mat()
Mat(const HxStr &name)
Construct a material with the default surface.
Color mDiffuse
Diffuse colour.
Definition mat.h:481
virtual void Save(Stream &stream)
Serialise the material.
virtual void Replace(Object *pFrom, Object *pTo)
Replace one object reference with another.
virtual void SetDiffuse(const Color &color)
Set the diffuse colour, retaining the current alpha.
virtual void Load(Stream &stream)
Load the material.
virtual void SetAmbient(const Color &color)
Set the ambient colour.
virtual void Copy(const Object *pSource, unsigned nFlags)
Copy another material over this one.
int mFlat
Definition mat.h:541
virtual void DumpText(Dbg &sink)
Write the material to the engine text sink.
int mEnable
Definition mat.h:488
@ kSerialVersion
Definition mat.h:168
std::vector< Stage > mStages
Definition mat.h:452
virtual const HxStr & ClassName() const
Return the registered class name, "Mat".
Cull
Face winding the rasteriser discards, as the text dump labels the values.
Definition mat.h:68
@ kCullModeNone
Definition mat.h:71
@ kCullModeCw
Definition mat.h:69
@ kCullModeCcw
Definition mat.h:70
BlendMode mBlend
Definition mat.h:458
virtual void SyncMat(int nStage)
Virtual with an empty body in Rnd::Mat.
virtual void SetSpecular(const Color &color, float flAlpha)
Set the specular colour and its alpha.
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.
Indexed triangle mesh with one material.
Definition mesh.h:46
Base of every object the renderer can load, resolve by name, and serialise.
Definition object.h:43
Object()
Construct an unnamed object.
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
Texture, as a bitmap path plus the load state of its mip levels.
Definition tex.h:43
The rendering engine.
Definition animhelper.h:3
Object * CreateRegisteredMat(const HxStr &name)
Build a material for the registered "Mat" class by calling through g_pfnNewMat.
Mat * NewMat(const HxStr &name)
Allocate and construct a material, the base creator of the "Mat" class.
Mat * NewMatThroughHook(const HxStr &name)
Build a material through the creator hook.
int g_nRndMatLoadVersion
Serial version of the material record currently being read.
int g_nStageTextureBound
Non-zero while the material stage being applied has a texture bound.
Manager TheManager
The renderer's object registry.
Mat *(* g_pfnNewMat)(const HxStr &name)
Creator the registered "Mat" class builds through.
void RegisterMatClass()
Point g_pfnNewMat at NewMat() and register the "Mat" class with Rnd::Manager.
Definition mat.h:611
Linear colour with four float components.
Definition color.h:10
Affine transform stored as three basis rows and a translation row.
Definition transform.h:14