resonance 1.0.1
Loading...
Searching...
No Matches
gfxdevice.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "math/color.h"
6
8
10constexpr int kGifBufferQuadwords = 0x1e0;
11
13constexpr int kGsRegisterCount = 128;
14
22 unsigned long long mLo;
23 unsigned long long mHi;
24};
25
38class GfxDevice {
39public:
50 struct Rect {
51 float x;
52 float y;
53 float w;
54 float h;
55 };
56
68
76 Terminate();
77 }
78
90 void Terminate();
91
102
112
122
141 void Init(int nWidth, int nHeight, int nBitDepth);
142
155
166 void PresentFrame(int nSwapBuffers);
167
183
196
216 void SetGsReg(int nReg, unsigned long long qwValue, unsigned long long qwMask);
217
234 void ReserveGifSpace(int nQuadwords);
235
246
257
272 void CloseGifTag(int bEndOfPacket);
273
284 void WriteGifTag(const GifQuadword *pTag);
285
302 int FlushGifPacket(int bRetainOpenTag, int bOnlyWhenFull);
303
315
326
338
350 void SetClearColor(const Color &color);
351
362
370 void DrawSubsystemTimingGraph(int nFullScaleMs);
371
385
386 // The layout is recovered only where the packet routines read it. A reserved run records a span
387 // that has not been recovered and is not a field.
388
398 std::vector<GifQuadword> mSavedPacket;
401#ifdef VIDEO_STANDARD_PAL
407 int mnNtscOutput;
408#endif
424 unsigned long long mGsRegs[kGsRegisterCount];
449
459
460private:
469 void SendPacket();
470
480 void SwapBuffers();
481
495 static void DrawDebugText(const char *pszText, const Rect &rect, const Color &color);
496
506 static void DrawTimingBar(const Rect &rect, const Color &color);
507
517 void DrawFpsReadout();
518
519 // Frame-rate sampling for DrawFpsReadout().
520 int mnFpsCountdown; // +0x454
521 float mflFrameMsSum; // +0x458
522 int mnFps; // +0x45c
523 float mflSyncMsSum; // +0x460
524 int mnSyncMsAverage; // +0x464
525
526public:
553
554private:
555 unsigned char mReserved484[0x0c]; // +0x484
556 // Colour SetClearColor() last recorded.
557 Color mClearColor; // +0x490
558};
559
560namespace Rnd {
561
568extern GfxDevice ThePs;
569
570} // namespace Rnd
571
580extern volatile int gVCount;
581
594int DrawVSyncCB(int nCause);
595
596extern "C" {
597
610
621}
Owner of the display, the GIF packet buffer, and the frame timing counters.
Definition gfxdevice.h:38
int mnUseVu1
Non-zero while geometry is submitted through VU1 rather than the software path.
Definition gfxdevice.h:440
void SavePacket()
Wait for the GIF and VIF1 channels to stop, then copy the packet into mSavedPacket.
int mnSwapVblank
Vertical blank count before which SwapBuffers() does not show the next frame.
Definition gfxdevice.h:429
int mnDisplayHeight
Display height in pixels.
Definition gfxdevice.h:412
int mnDisplayWidth
Display width in pixels, as Init() recorded it.
Definition gfxdevice.h:410
void SetGsReg(int nReg, unsigned long long qwValue, unsigned long long qwMask)
Set the masked part of one GS register, unless it already agrees.
GifQuadword * mpReservedRegion
Start of the reserved region, or null when none is open.
Definition gfxdevice.h:396
int mFeedbackInset
Inset of the texture window at both corners, in sixteenths of a texel.
Definition gfxdevice.h:552
int GetReservedVramWords() const
Words of video memory the display and depth buffers occupy.
GifQuadword * mpOpenVifDirect
First quadword after the VIF DIRECT code that WriteGifTag() opened, or null.
Definition gfxdevice.h:448
int mnDrawBuffer
Half of the double buffer being drawn, which RestoreFrameBufferTarget() selects by.
Definition gfxdevice.h:432
void EnterVu1Path()
Route later packets through VIF1 and VU1 rather than straight to the GIF.
void DrawRenderStatsOverlay()
Draw the render statistics as debug text.
void SwapGifWrite()
Exchange the write pointer with the one the reservation preserved.
void Terminate()
Restore the base render class factories that Init() replaced.
unsigned long long mGsRegs[kGsRegisterCount]
Last value written to each GS register, indexed by register number.
Definition gfxdevice.h:424
GifQuadword * mpSavedWrite
Write pointer preserved across a reservation.
Definition gfxdevice.h:394
Rect mFeedbackRect
Rectangle SetupGsDrawContext() draws and samples, in fractions of the display.
Definition gfxdevice.h:540
void WriteGifTag(const GifQuadword *pTag)
Start a GIFtag at the write pointer.
void FlipFrameBuffer()
Put the draw environment of the current half, then run SwapBuffers().
void PresentFrame(int nSwapBuffers)
Finish a frame and show it.
void RestoreFrameBufferTarget()
Point FRAME_1 and XYOFFSET_1 back at the display buffer being drawn.
void Init(int nWidth, int nHeight, int nBitDepth)
Bring up the display and the drawing subsystems.
void InitDisplayMode()
Program the GS display registers for the recorded geometry.
std::vector< GifQuadword > mSavedPacket
Copy of the packet under construction, filled by SavePacket().
Definition gfxdevice.h:398
float mFeedbackAlpha
Blend factor SetupGsDrawContext() writes into ALPHA_1 FIX after scaling it by 128.
Definition gfxdevice.h:546
void SetupGsDrawContext()
Blend the displayed frame back over the frame being drawn.
~GfxDevice()
Undo what Init() installs.
Definition gfxdevice.h:75
void RestorePacket()
Copy mSavedPacket back over the packet buffer, for the length SavePacket() used.
void DrawSubsystemTimingGraph(int nFullScaleMs)
Draw one bar per profiler timer, scaled against a full-scale time.
int FlushGifPacket(int bRetainOpenTag, int bOnlyWhenFull)
Send the assembled packet and move to the other scratchpad half.
GifQuadword * mpWrite
Where the next quadword is written.
Definition gfxdevice.h:390
GsDoubleBuffer * mpDisplayBuffers
Double buffer InitDisplayMode() builds at 0x006f36c0, addressed through its uncached alias.
Definition gfxdevice.h:438
GfxDevice()
Construct the device with an empty packet and the default feedback and clear settings.
void ReserveGifSpace(int nQuadwords)
Divert writes into a region carved off the end of the packet buffer.
int mFeedbackEnabled
Non-zero while the feedback effect is enabled, stored as a whole word.
Definition gfxdevice.h:534
int mnDepthBytes
Depth buffer bytes per sample, which InitDisplayMode() derives from mnPixelBytes.
Definition gfxdevice.h:420
int mnPixelBytes
Framebuffer bytes per pixel, the Init() bit depth divided by 8.
Definition gfxdevice.h:414
void FlushReservedGif()
Copy the reserved region into the main stream and close the reservation.
void BeginFrame()
Start a frame.
void SetClearColor(const Color &color)
Record the colour both halves of the double buffer clear to.
void ResetVramAndSavePacket()
Release every video memory record and save the packet under construction.
void LeaveVu1Path()
Return to sending packets straight to the GIF.
GifQuadword mAdTag
A+D GIFtag SetGsReg() opens when the open tag is not already an A+D tag.
Definition gfxdevice.h:422
void CloseGifTag(int bEndOfPacket)
Fill in the loop count of the open GIFtag, and optionally end the packet.
GifQuadword * mpOpenTag
GIFtag whose loop count is still to be filled in, or null when none is open.
Definition gfxdevice.h:400
GifQuadword * mpBuffer
Scratchpad half currently being filled.
Definition gfxdevice.h:392
The display and draw environments of a double-buffered framebuffer.
Definition gsdoublebuffer.h:23
GifQuadword g_vu1MicrocodeChain[]
DMA chain that uploads the VU1 microcode, the start of the .vutext section.
int DrawVSyncCB(int nCause)
Count one vertical blank in gVCount.
volatile int gVCount
Vertical blanks counted since start-up.
GifQuadword g_vu0MicrocodeChain[]
DMA chain at the end of .vutext that uploads the VU0 microcode.
constexpr int kGsRegisterCount
GS registers the device shadows, the whole register address space.
Definition gfxdevice.h:13
constexpr int kGifBufferQuadwords
Quadwords of the packet buffer a caller may fill before it has to be submitted.
Definition gfxdevice.h:10
The rendering engine.
Definition animhelper.h:3
GfxDevice ThePs
The display device.
Linear colour with four float components.
Definition color.h:10
Rectangle of four floats.
Definition gfxdevice.h:50
float y
Definition gfxdevice.h:52
float x
Definition gfxdevice.h:51
float w
Definition gfxdevice.h:53
float h
Definition gfxdevice.h:54
One quadword of a packet stream.
Definition gfxdevice.h:21
unsigned long long mHi
Definition gfxdevice.h:23
unsigned long long mLo
Definition gfxdevice.h:22