wavelength 1.0.0
Loading...
Searching...
No Matches
rndtex.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5#include "os/binstream.h"
6#include "os/filepath.h"
7#include "os/mem.h"
8#include "os/prnstream.h"
9#include "rnd/rndbitmap.h"
10#include "rnd/rndobject.h"
11
17class RndTex : public RndObject {
18public:
26 explicit RndTex(const char *pszName);
27
34 ~RndTex() override;
35
42 void *operator new(size_t nSize) {
43 return PoolMemAlloc(static_cast<int>(nSize), "Tex", 0);
44 }
45
51 void operator delete(void *pBlock) {
52 PoolMemFree(pBlock);
53 }
54
62 void DumpText(PrnStream &stream) override;
63
71 void Save(BinStream &stream) override;
72
81 void Replace([[maybe_unused]] RndObject *pFrom, [[maybe_unused]] RndObject *pTo) override {
82 }
83
91 const char *ClassName() const override {
92 return sClassName;
93 }
94
103 void Copy(const RndObject *pSource, int nFlags) override;
104
114 void Load(BinStream &stream) override;
115
126 virtual RndBitmap *LockBitmap([[maybe_unused]] int nFlags) {
127 return &mBitmap;
128 }
129
138 virtual void UnlockBitmap() {
139 }
140
150 virtual void SyncBitmap();
151
160 virtual void ResetBitmap();
161
174 void
175 SetBitmap(int nWidth, int nHeight, int nBpp, const FilePath &file, int nMipMapK, int nRendered);
176
185 static const char *CheckDim(int nSize);
186
195 bool CheckSize();
196
205 static RndObject *New(const char *pszName) {
206 return new RndTex(pszName);
207 }
208
215 static const char *sClassName;
216
222 static int sRev;
223
225 const FilePath &GetFile() const {
226 return mFile;
227 }
228
230 int GetHeight() const {
231 return mHeight;
232 }
233
235 int GetMipMapK() const {
236 return mMipMapK;
237 }
238
240 int GetWidth() const {
241 return mWidth;
242 }
243
244protected:
246
248
250
251 int mWidth;
252
254
255 int mBpp;
256
258};
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Path of a file, kept relative to a shared root directory.
Definition filepath.h:14
Text output stream.
Definition prnstream.h:16
Pixel rectangle with an optional palette and a chain of smaller mipmaps.
Definition rndbitmap.h:16
RndObject(const char *pszName)
Construct an object and register it under a name.
int mWidth
Definition rndtex.h:251
virtual void UnlockBitmap()
End an access LockBitmap() gave.
Definition rndtex.h:138
void Save(BinStream &stream) override
Write the texture.
virtual void ResetBitmap()
Release the bitmap.
void SetBitmap(int nWidth, int nHeight, int nBpp, const FilePath &file, int nMipMapK, int nRendered)
Set the size, the format, and the file, then load the bitmap.
int GetWidth() const
Definition rndtex.h:240
~RndTex() override
Release the bitmap.
void Replace(RndObject *pFrom, RndObject *pTo) override
Do nothing, for a texture refers to no object.
Definition rndtex.h:81
const char * ClassName() const override
Report the class name.
Definition rndtex.h:91
int mHeight
Definition rndtex.h:253
bool CheckSize()
Report whether the size and the format are valid, with a notice when they are not unless a dimension ...
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it, then load the bitmap.
const FilePath & GetFile() const
Definition rndtex.h:225
static int sRev
The format version Save() writes and Load() accepts.
Definition rndtex.h:222
void DumpText(PrnStream &stream) override
Write a description of the texture, and of its bitmap at a dump level of 2 or more.
RndBitmap mBitmap
Definition rndtex.h:245
static const char * CheckDim(int nSize)
Report what is wrong with a texture dimension.
static const char * sClassName
The class name a .rnd file writes, Tex.
Definition rndtex.h:215
void Copy(const RndObject *pSource, int nFlags) override
Copy the size, the format, and the file of another texture, then load the bitmap again.
int GetMipMapK() const
Definition rndtex.h:235
int mMipMapK
Definition rndtex.h:247
FilePath mFile
Definition rndtex.h:257
static RndObject * New(const char *pszName)
Create a texture.
Definition rndtex.h:205
virtual RndBitmap * LockBitmap(int nFlags)
Give access to the bitmap.
Definition rndtex.h:126
int GetHeight() const
Definition rndtex.h:230
int mBpp
Definition rndtex.h:255
virtual void SyncBitmap()
Load the bitmap from the file, or allocate a blank one of the size and the format when there is no fi...
RndTex(const char *pszName)
Construct an empty 32-bit texture without a file.
int mRendered
Definition rndtex.h:249
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.