resonance 1.0.1
Loading...
Searching...
No Matches
tex.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4#include <vector>
5
6#include "os/async.h"
7#include "os/hxstr.h"
8#include "rnd/filepath.h"
9#include "rnd/manager.h"
10#include "rnd/object.h"
11
12class ACanvas;
13class APalette;
14namespace Rnd {
15class Stream;
16}
17class ABitmap;
18
19namespace Rnd {
20
43class Tex : public Object {
44public:
54 static Tex *(*sNew)(const HxStr &name);
55
63
73 Tex(const HxStr &name);
74
81 virtual ~Tex();
82
91 static void *operator new(size_t nSize);
92
100 static void operator delete(void *pBlock);
101
118 int GetBitmapInfo(int &nWidth, int &nHeight, int &nBitsPerPixel, int &nBytes);
119
131
132 // Rnd::Object leaves slots 3 through 7 pointing at the shared pure-virtual handler at
133 // `0x005381a8` and gives slot 2 a body of its own at `0x0053e5a8`. Every one of the six below
134 // is a distinct `rndtex.cpp` body in the Rnd::Tex table, so the class declares all six and is
135 // not abstract. Rnd::PsTex repeats them byte-identically, which is to say it inherits them.
136
148 virtual void DumpText(Dbg &sink);
149
159 virtual void Save(Stream &stream);
160
169 virtual void Replace(Object *pFrom, Object *pTo);
170
178 virtual const HxStr &ClassName() const;
179
191 virtual void Copy(const Object *pSource, unsigned nFlags);
192
206 virtual void Load(Stream &stream);
207
216
234 int nWidth, int nHeight, int nBitsPerPixel, const HxStr &path, int nMipSelect, int nFlags);
235
249
266
276
287 virtual void ReloadBitmaps();
288
296
313 virtual ACanvas *LockMipBitmap(int nMip, int nReserved, int nFlags);
314
323 virtual void UnlockMipBitmap();
324
336 virtual void SetPalette(APalette *pPalette, int nReserved);
337
348 virtual void SetGsPageInUse(bool bInUse);
349
360 virtual void FreeLoadedBitmaps();
361
362protected:
373 if (!IsLoadComplete()) {
374 while (!PollAsyncMips()) {
376 }
377 }
378 }
379
392 virtual void RestoreSurfaces();
393
413 virtual void OnMipLoaded(int nMip);
414
415protected:
416public:
417 // RestoreSurfaces() writes these three from the bitmap it is restoring. They are public rather
418 // than protected because Rnd::Cam reads the first two from outside the hierarchy, through a
419 // Rnd::Tex pointer, in both UpdateTargetAspect() and SetTargetTex(), and Rnd::PsCam does the
420 // same in ScreenToPixels(). The image supplies no accessor for either.
424
425protected:
426 // Every member below is protected rather than private, because Rnd::PsTex reads the mip
427 // handles, the pending mask, and the bitmap path while it uploads to GS memory. No access from
428 // outside the hierarchy is recovered for any of them. The order is the recovered offset order.
429public:
435
436private:
446 bool LoadMipFiles();
447
457 int QueueMipRead(const char *pszPath);
458
459protected:
460 std::vector<int> mMipHandles; // +0x2c
461 unsigned char mPendingMipMask; // +0x38 One bit per mip level still loading.
462
463public:
469
470protected:
472 // Zone the loaded bitmaps are allocated from, or -1 for the tagged heap. Starts at -1, and
473 // AllocateBitmapFromStream() records the current zone. FreeLoadedBitmaps() releases a bitmap
474 // only while this is -1, because zone memory goes with its zone. +0x48
475 int mZone;
476 std::vector<ABitmap *> mLoadedBitmaps;
477};
478
487Tex *NewTex(const HxStr &name);
488
501
511
523inline void RegisterTexClass() {
526}
527
528} // namespace Rnd
void AsyncPumpCompletedRequests()
Service the queue once.
Description of a pixel rectangle, its layout, and its palette.
Definition abitmap.h:95
Drawing surface over an ABitmap, with a clip rectangle.
Definition acanvas.h:74
A 256 entry colour table an ABitmap points at.
Definition apalette.h:31
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
File name that the renderer resolves against a shared root directory.
Definition filepath.h:24
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
static HxStr sClassName
Registered class name of Rnd::Tex, the string "Tex".
Definition tex.h:62
int mHeight
Definition tex.h:422
virtual void Copy(const Object *pSource, unsigned nFlags)
Take the dimensions, path, mip selector, and flags of another texture and reload.
void AllocateBitmapFromStream()
Start loading the configured bitmap, or build a blank one when no path is set.
unsigned char mPendingMipMask
Definition tex.h:461
virtual void ReloadBitmaps()
Release the loaded bitmaps and start loading from the configured path again.
bool PollAsyncMips()
Advance the asynchronous mip loads and report whether any level is still outstanding.
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 UnlockMipBitmap()
Release the mip level that LockMipBitmap() locked.
bool IsLoadComplete()
Report whether every requested mip level has finished loading.
int mMipSelect
Mip selector SetBitmapConfig() records, starting at -0x80.
Definition tex.h:468
virtual void Save(Stream &stream)
Write revision 4, the three dimensions, the path, mFlags, and mMipSelect.
TexFunc
Texture function, the GS TEX0.TFX field, which decides how a texel meets the vertex.
Definition tex.h:290
@ kTexFuncHighlight
Definition tex.h:293
@ kTexFuncHighlight2
Definition tex.h:294
@ kTexFuncModulate
Definition tex.h:291
@ kTexFuncDecal
Definition tex.h:292
void WaitForMipsLoaded()
Block until every requested mip level has arrived, pumping the asynchronous reads meanwhile.
Definition tex.h:372
std::vector< int > mMipHandles
Definition tex.h:460
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.
FilePath mBitmapPath
Definition tex.h:471
const HxStr & GetRelativeBitmapPath() const
Report mBitmapPath relative to FilePath::sRoot.
virtual const HxStr & ClassName() const
Report the registered class name, "Tex".
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.
static Tex *(* sNew)(const HxStr &name)
Creator the registered "Tex" class builds through.
Definition tex.h:54
virtual void DumpText(Dbg &sink)
Write the dimensions, the mip selector, the path, and the flag names to sink.
virtual void Load(Stream &stream)
Replace this texture's configuration from stream and reload.
int mZone
Definition tex.h:475
int GetBitmapInfo(int &nWidth, int &nHeight, int &nBitsPerPixel, int &nBytes)
Report the size of mip level 0 and the bytes every loaded level occupies.
virtual void FreeLoadedBitmaps()
Release every loaded bitmap and cancel the outstanding reads.
Tex(const HxStr &name)
Construct a texture with no bitmap.
virtual ~Tex()
Free the loaded bitmaps and drop every reference to this texture.
int mBitsPerPixel
Definition tex.h:423
std::vector< ABitmap * > mLoadedBitmaps
Definition tex.h:476
int mFlags
Flag word SetBitmapConfig() records and DumpText() labels " flags:".
Definition tex.h:434
int mWidth
Definition tex.h:421
virtual ACanvas * LockMipBitmap(int nMip, int nReserved, int nFlags)
Lock the bitmap of one mip level for direct access.
void CancelPendingMips()
Cancel whatever mip reads are still outstanding and drop every mip handle.
virtual void Replace(Object *pFrom, Object *pTo)
Do nothing.
The rendering engine.
Definition animhelper.h:3
Tex * NewTex(const HxStr &name)
Allocate and construct a texture, the base creator of the "Tex" class.
Object * CreateRegisteredTex(const HxStr &name)
Build a texture for the registered "Tex" class by calling through Tex::sNew.
void RegisterTexClass()
Point Tex::sNew at NewTex() and register the "Tex" class with Rnd::Manager.
Definition tex.h:523
Manager TheManager
The renderer's object registry.
Tex * NewTexThroughHook(const HxStr &name)
Build a texture through the creator hook.