wavelength 1.0.0
Loading...
Searching...
No Matches
pstex.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <list>
5#include <vector>
6
7#include "os/mem.h"
8#include "rnd/dmapacket.h"
9#include "rnd/rndbitmap.h"
10#include "rnd/rndtex.h"
11
21class PsTex : public RndTex {
22public:
24 struct FreeRange {
25 unsigned short mStart;
26 unsigned short mCount;
27 };
28
30 struct UsedRange {
40 int AlignShift() const;
41
52 bool AllocFree();
53
66 bool AllocUsed();
67
76 void Release();
77
78 unsigned short mStart : 15;
79 unsigned short mPinned
80 : 1;
81
83 unsigned short GetCount() const {
84 return mCount;
85 }
86
88 void SetCount(unsigned short nCount) {
89 mCount = nCount;
90 }
91
93 int GetFrame() const {
94 return mFrame;
95 }
96
98 void SetFrame(int nFrame) {
99 mFrame = nFrame;
100 }
101
102 private:
103 unsigned short mCount;
104 int mFrame;
105 };
106
114 explicit PsTex(const char *pszName);
115
122 ~PsTex() override;
123
130 void *operator new(size_t nSize) {
131 return PoolAlloc(static_cast<int>(nSize), sizeof(PsTex), "PsTex", 0);
132 }
133
139 void operator delete(void *pBlock) {
140 PoolFree(sizeof(PsTex), pBlock);
141 }
142
151 RndBitmap *LockBitmap(int nFlags) override;
152
159 void UnlockBitmap() override;
160
167 void SyncBitmap() override {
170 }
171
178 void ResetBitmap() override {
181 }
182
193 void Place();
194
205 void BuildMoviePacket(bool bBuild);
206
216
232 int nDbp, int nPsm, int nBpp, int nWidth, int nHeight, const unsigned char *pPixels);
233
242 void Upload();
243
253
265
275
286 void Select(int nTexFunction);
287
296 static void BeginFrame();
297
307 static int FreeBlockCount();
308
317 static void ReserveDisplayMemory();
318
329 static void FreeBlocks(int nStart, int nCount);
330
341 static int NumBlocks(const RndBitmap &bitmap);
342
351 static void Init();
352
361 static RndObject *New(const char *pszName) {
362 return new PsTex(pszName);
363 }
364
370 static std::list<FreeRange> sFreeRanges;
371
377 static std::list<UsedRange *> sUsedRanges;
378
385 static int sStamp;
386
393 static int sEvictStamp;
394
395private:
396 unsigned long long mTex0;
397 unsigned long long mTex1;
398 unsigned long long mMipTbp1;
399 unsigned long long mMipTbp2;
400 std::vector<UsedRange> mRanges;
401 int mLockFlags;
402 unsigned int mDirty;
403 DmaQuadword *mMoviePacket;
404};
static void Init()
Install the texture factory for the class Tex of a .rnd file, and reset both stamps.
~PsTex() override
Release the GS blocks and the movie packet.
void BindAsRenderTarget()
Make the first mipmap the surface the GS draws into.
static int FreeBlockCount()
Count the free GS blocks.
RndBitmap * LockBitmap(int nFlags) override
Give access to the bitmap, recording the access for UnlockBitmap().
static int sEvictStamp
The value of sStamp at the last BeginFrame().
Definition pstex.h:393
PsTex(const char *pszName)
Construct a texture without GS blocks.
static void ReserveDisplayMemory()
Free every block after the display and depth buffers, and evict every range.
void Upload()
Place the ranges, upload those marked for upload, and flush the texture cache.
static int sStamp
The count of selections, the stamp Select() records on each range.
Definition pstex.h:385
void BuildMoviePacket(bool bBuild)
Release the movie packet, then build one for the current bitmap when requested.
void Place()
Give each range without blocks its blocks and mark it for upload.
void ResetBitmap() override
Release the GS blocks, then the bitmap.
Definition pstex.h:178
void SyncBitmap() override
Load the bitmap, then build the GS registers and the ranges for it.
Definition pstex.h:167
void UploadImage(int nDbp, int nPsm, int nBpp, int nWidth, int nHeight, const unsigned char *pPixels)
Add an image transfer of pixels in main memory to the frame.
void UnlockBitmap() override
Mark the first range for upload, and the second as well when the palette changed.
void Select(int nTexFunction)
Upload the texture when needed, then select it on the GS with a texture function.
void SyncRegisters()
Build TEX0, TEX1, and the buffer widths of MIPTBP1 and MIPTBP2, and add a range for the CLUT and for ...
void ReleaseSurfaces()
Release the bitmap and the GS blocks, and empty the ranges.
static std::list< UsedRange * > sUsedRanges
The ranges with blocks, in the order they received them.
Definition pstex.h:377
static void BeginFrame()
Evict every range not selected since the last call, and record the stamp.
static void FreeBlocks(int nStart, int nCount)
Return a run of blocks to the free list, merging it with its neighbours.
static int NumBlocks(const RndBitmap &bitmap)
Report the GS blocks a bitmap occupies, rounded up to the shapes the GS pages allow.
static std::list< FreeRange > sFreeRanges
The free runs, in block order.
Definition pstex.h:370
static RndObject * New(const char *pszName)
Create a texture.
Definition pstex.h:361
void UploadMovie()
Copy the movie packet into the frame, flushing the frame whenever the packet fills it.
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.
virtual void ResetBitmap()
Release the bitmap.
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.
void * PoolAlloc(int nSize, int nBlockSize, const char *pszTag, int nUnused)
Allocate a block from the small-block pool and bill it to a tag.
void PoolFree(int nSize, void *pBlock)
Return a block to the small-block pool.
One quadword of a DMA packet, viewed as doublewords, words, or halfwords.
Definition dmapacket.h:4
A run of free GS blocks.
Definition pstex.h:24
unsigned short mCount
Definition pstex.h:26
unsigned short mStart
Definition pstex.h:25
The GS blocks of the CLUT or of one mipmap.
Definition pstex.h:30
unsigned short mStart
Definition pstex.h:78
int AlignShift() const
Report the alignment the range requires, as a power of two of blocks.
unsigned short GetCount() const
Definition pstex.h:83
bool AllocFree()
Take the free run that wastes the fewest blocks once aligned.
void Release()
Free the blocks and remove the range from sUsedRanges.
unsigned short mPinned
Definition pstex.h:80
int GetFrame() const
Definition pstex.h:93
void SetFrame(int nFrame)
Definition pstex.h:98
void SetCount(unsigned short nCount)
Definition pstex.h:88
bool AllocUsed()
Take the blocks of the range of another texture that wastes the fewest of them.