wavelength 1.0.0
Loading...
Searching...
No Matches
rndmat.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <vector>
5
6#include "math/color.h"
7#include "math/transform.h"
8#include "math/triangle.h"
9#include "os/binstream.h"
10#include "os/mem.h"
11#include "os/prnstream.h"
12#include "rnd/rndobject.h"
13#include "rnd/rndtex.h"
14
20class RndMat : public RndObject {
21public:
39
48
55
61 class Stage {
62 public:
70
78 void SetTex(RndTex *pTex);
79
87 void Print(PrnStream &stream) const;
88
96 void Save(BinStream &stream) const;
97
107 void Load(BinStream &stream);
108
110 int GetBlend() const {
111 return mBlend;
112 }
113
115 void SetBlend(int nBlend) {
116 mBlend = nBlend;
117 }
118
120 int GetGenMode() const {
121 return mGenMode;
122 }
123
125 RndMat *GetMat() const {
126 return mMat;
127 }
128
130 void SetMat(RndMat *pMat) {
131 mMat = pMat;
132 }
133
135 RndTex *GetTex() const {
136 return mTex;
137 }
138
140 int GetUseXfm() const {
141 return mUseXfm;
142 }
143
145 void SetUseXfm(int nUseXfm) {
146 mUseXfm = nUseXfm;
147 }
148
150 int GetWrap() const {
151 return mWrap;
152 }
153
155 void SetWrap(int nWrap) {
156 mWrap = nWrap;
157 }
158
160 const Transform &GetXfm() const {
161 return mXfm;
162 }
163
166 return mXfm;
167 }
168
170 void SetXfm(const Transform &xfm) {
171 mXfm = xfm;
172 }
173
174 private:
175 int mBlend;
176 int mCoordIndex;
177 int mGenMode;
178 Transform mXfm;
179 int mUseXfm;
180 int mWrap;
181 RndTex *mTex;
182 RndMat *mMat;
183 };
184
193 explicit RndMat(const char *pszName);
194
201 ~RndMat() override;
202
209 void *operator new(size_t nSize) {
210 return PoolMemAlloc(static_cast<int>(nSize), "Mat", 0);
211 }
212
218 void operator delete(void *pBlock) {
219 PoolMemFree(pBlock);
220 }
221
229 void DumpText(PrnStream &stream) override;
230
238 void Save(BinStream &stream) override;
239
250 void Replace(RndObject *pFrom, RndObject *pTo) override;
251
259 const char *ClassName() const override {
260 return sClassName;
261 }
262
273 void Copy(const RndObject *pSource, int nFlags) override;
274
282 void Load(BinStream &stream) override;
283
293 virtual void SyncStage([[maybe_unused]] int nStage) {
294 }
295
303 virtual void SetBaseColor(const Color &color) {
304 mBaseColor.r = color.r;
305 mBaseColor.b = color.b;
306 mBaseColor.g = color.g;
307 }
308
316 virtual void SetLightColor(const Color &color) {
317 mLightColor = color;
318 }
319
327 virtual void SetEdgeColor(const Color &color) {
328 mEdgeColor = color;
329 }
330
338 virtual void SetAlpha(float fAlpha) {
339 mBaseColor.a = fAlpha;
340 }
341
354 virtual void SetLighting(int bEnable,
355 int bVertBase,
356 int bVertLight,
357 int bVertEdge,
358 int bNormalize,
359 int bBaseAmbient);
360
369 virtual void Refresh();
370
379 void AddStage();
380
389 static RndObject *New(const char *pszName) {
390 return new RndMat(pszName);
391 }
392
399 static const char *sClassName;
400
406 static int sRev;
407
413 static int sLoadRev;
414
416 int GetBaseAmbient() const {
417 return mBaseAmbient;
418 }
419
421 const Color &GetBaseColor() const {
422 return mBaseColor;
423 }
424
426 int GetBlend() const {
427 return mBlend;
428 }
429
431 void SetBlend(int nBlend) {
432 mBlend = nBlend;
433 }
434
436 int GetCull() const {
437 return mCull;
438 }
439
441 void SetCull(int nCull) {
442 mCull = nCull;
443 }
444
446 const Color &GetEdgeColor() const {
447 return mEdgeColor;
448 }
449
451 const Color &GetLightColor() const {
452 return mLightColor;
453 }
454
456 const std::vector<Stage> &GetStages() const {
457 return mStages;
458 }
459
461 std::vector<Stage> &GetStages() {
462 return mStages;
463 }
464
466 int GetVertBase() const {
467 return mVertBase;
468 }
469
471 int GetVertLight() const {
472 return mVertLight;
473 }
474
475protected:
485
486 std::vector<Stage> mStages;
487
488 int mBlend;
489
491
493
495
497
499
501
503
505
507
508 int mCull;
509
510 int mFlat;
511
513};
514
525
536
547
557PrnStream &operator<<(PrnStream &stream, const std::vector<RndMat::Stage> &stages);
558
568BinStream &operator<<(BinStream &stream, const std::vector<RndMat::Stage> &stages);
569
579BinStream &operator>>(BinStream &stream, std::vector<RndMat::Stage> &stages);
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Text output stream.
Definition prnstream.h:16
void Save(BinStream &stream) const
Write the stage.
Transform & GetXfm()
Definition rndmat.h:165
RndTex * GetTex() const
Definition rndmat.h:135
void SetBlend(int nBlend)
Definition rndmat.h:115
RndMat * GetMat() const
Definition rndmat.h:125
void SetWrap(int nWrap)
Definition rndmat.h:155
void SetXfm(const Transform &xfm)
Definition rndmat.h:170
void SetMat(RndMat *pMat)
Definition rndmat.h:130
void SetUseXfm(int nUseXfm)
Definition rndmat.h:145
const Transform & GetXfm() const
Definition rndmat.h:160
void SetTex(RndTex *pTex)
Set the texture, moving the material's reference to it.
int GetGenMode() const
Definition rndmat.h:120
Stage()
Construct a multiplying stage with an identity transform and no texture.
int GetWrap() const
Definition rndmat.h:150
int GetBlend() const
Definition rndmat.h:110
void Load(BinStream &stream)
Read what Save() wrote, or an earlier version of it.
int GetUseXfm() const
Definition rndmat.h:140
void Print(PrnStream &stream) const
Write a description of the stage.
Color mLightColor
Definition rndmat.h:492
std::vector< Stage > & GetStages()
Definition rndmat.h:461
int mVertEdge
Definition rndmat.h:502
void Save(BinStream &stream) override
Write the material.
int mBlend
Definition rndmat.h:488
int mVertBase
Definition rndmat.h:498
int GetBlend() const
Definition rndmat.h:426
const Color & GetLightColor() const
Definition rndmat.h:451
int GetCull() const
Definition rndmat.h:436
virtual void SyncStage(int nStage)
Bring the platform state of one stage up to date.
Definition rndmat.h:293
int mMultiPass
Definition rndmat.h:512
int mEnable
Definition rndmat.h:496
RndMat(const char *pszName)
Construct an enabled material that blends by source alpha, with a black base colour,...
int mBaseAmbient
Definition rndmat.h:506
Color mBaseColor
Definition rndmat.h:490
virtual void SetLightColor(const Color &color)
Set the light colour.
Definition rndmat.h:316
static const char * sClassName
The class name a .rnd file writes, Mat.
Definition rndmat.h:399
const std::vector< Stage > & GetStages() const
Definition rndmat.h:456
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace a stage texture with another object.
int GetBaseAmbient() const
Definition rndmat.h:416
int mVertLight
Definition rndmat.h:500
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it.
void ReleaseStageTex()
Drop the reference on every stage texture.
const char * ClassName() const override
Report the class name.
Definition rndmat.h:259
int GetVertBase() const
Definition rndmat.h:466
TexWrap
How texture coordinates outside the unit range wrap.
Definition rndmat.h:50
@ kTexWrapRepeat
Definition rndmat.h:52
@ kTexWrapMirror
Definition rndmat.h:53
@ kTexWrapClamp
Definition rndmat.h:51
virtual void Refresh()
Take a reference on every stage texture and bring every stage up to date.
static int sLoadRev
The version Load() read last, which Stage::Load() consults.
Definition rndmat.h:413
int mCull
Definition rndmat.h:508
virtual void SetEdgeColor(const Color &color)
Set the edge colour.
Definition rndmat.h:327
Blend
How a surface or a texture stage combines with what is beneath it.
Definition rndmat.h:23
@ kBlendMultiply2
Definition rndmat.h:28
@ kBlendDestAlpha
Definition rndmat.h:33
@ kBlendInvSrcAlpha
Definition rndmat.h:32
@ kBlendSrcAlpha
Definition rndmat.h:29
@ kBlendSrcAlphaAdd
Definition rndmat.h:30
@ kBlendDest
Definition rndmat.h:24
@ kBlendSrc
Definition rndmat.h:25
@ kBlendSrcAlphaCutout
Definition rndmat.h:36
@ kBlendSubtract
Definition rndmat.h:37
@ kBlendSrcAdd
Definition rndmat.h:31
@ kBlendAdd
Definition rndmat.h:26
@ kBlendSrcAlphaOpaque
Definition rndmat.h:35
@ kBlendInvDestAlpha
Definition rndmat.h:34
@ kBlendMultiply
Definition rndmat.h:27
std::vector< Stage > mStages
Definition rndmat.h:486
void SetBlend(int nBlend)
Definition rndmat.h:431
void AddStage()
Append a default stage.
void SetCull(int nCull)
Definition rndmat.h:441
static int sRev
The format version Save() writes and Load() accepts.
Definition rndmat.h:406
const Color & GetBaseColor() const
Definition rndmat.h:421
~RndMat() override
Drop the references on the stage textures.
int mNormalize
Definition rndmat.h:504
virtual void SetAlpha(float fAlpha)
Set the alpha of the base colour.
Definition rndmat.h:338
static RndObject * New(const char *pszName)
Create a material.
Definition rndmat.h:389
TexGen
How a texture stage produces its texture coordinates.
Definition rndmat.h:41
@ kTexGenPlanar
Definition rndmat.h:44
@ kTexGenOrthoCube
Definition rndmat.h:45
@ kTexGenLocalCube
Definition rndmat.h:46
@ kTexGenFixed
Definition rndmat.h:42
@ kTexGenSphere
Definition rndmat.h:43
virtual void SetLighting(int bEnable, int bVertBase, int bVertLight, int bVertEdge, int bNormalize, int bBaseAmbient)
Set the lighting switches.
void DumpText(PrnStream &stream) override
Write a description of the material.
int mFlat
Definition rndmat.h:510
Color mEdgeColor
Definition rndmat.h:494
const Color & GetEdgeColor() const
Definition rndmat.h:446
virtual void SetBaseColor(const Color &color)
Set the red, green, and blue of the base colour.
Definition rndmat.h:303
void Copy(const RndObject *pSource, int nFlags) override
Copy another material.
int GetVertLight() const
Definition rndmat.h:471
RndObject(const char *pszName)
Construct an object and register it under a name.
Texture, a bitmap loaded from a file or rendered to.
Definition rndtex.h:17
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.
BinStream & operator>>(BinStream &stream, std::vector< RndMat::Stage > &stages)
Read the stages of a material the stage writer wrote.
PrnStream & operator<<(PrnStream &stream, RndMat::Blend eBlend)
Write the name of a blend mode.
Linear colour with four float components.
Definition color.h:12
float b
Definition color.h:15
float r
Definition color.h:13
float g
Definition color.h:14
Affine transform stored as three basis rows and a translation row.
Definition transform.h:18