GuDevice class
#include <nCine/Graphics/RHI/GU/GuDevice.h>
Pipeline-state and draw-call facade of the GU backend (aliased as RHI::Device).
The PlayStation Portable twin of the GX and PVR devices: each draw decodes the bound program's instance block(s) exactly like SwDevice::Dispatch, CPU-transforms the four sprite corners to screen pixels and submits them to the Allegrex GE as GU_TRANSFORM_2D primitives - the GE's "through" mode, which skips transform and lighting and takes screen coordinates and texel-space texture coordinates directly. Axis-aligned quads (nearly everything: UI, tiles, unrotated sprites) go out as GU_SPRITES, two vertices per quad; rotated ones as triangle pairs.
Everything the frame draws is written into one display list the GE consumes while it is being filled, and vertices come out of a per-frame arena that is written back from the data cache before each draw call - the GE reads main memory without seeing the CPU's cache, which is the classic source of "nothing renders" on this hardware. Consecutive primitives that share their whole GE state are accumulated into a single sceGuDrawArray, so a tile layer or a text run costs one draw call.
Unlike the PowerVR, the GE has a real raster scissor (sceGuScissor), so scissored draws are not clipped geometrically - the rect is programmed and the hardware cuts the primitives. Indexed textures are resolved by the hardware CLUT (GU_PSM_T8), loaded per draw from whatever palette texture the material bound, which is the direct analogue of the PVR's palette banks and the GX's TLUTs; RG8 index+alpha content has no paletted form and takes the same per-palette-row CPU bake the other consoles use.
Because the GE has no programmable shaders, the game runs the direct tier (see RhiFwd.h): the scene is rendered straight to the display at the logical resolution and the CPU lightmap is handed to the device through SetPendingSoftwareLighting() instead of a compositing shader pass.
Public types
- struct ScissorState
- struct BlendingState
- struct DepthTestState
- struct CullFaceState
Public static variables
-
static std::
int32_t HardwareTextureDimension constexpr - The dimension a single GE texture cannot exceed (9-bit u/v addressing - a hardware limit).
Public static functions
-
static auto GetSceneCounter() -> std::
uint32_t - Monotonic count of finished frames, used to detect "still referenced by the current frame" resources.
- static auto FindGeneratedEffect(const char* program, const char* variant) -> const FixedFunctionGeneratedEffect*
- Returns the generated fixed-function effect of a (program, variant) key, or
nullptr. - static void SetBlendingEnabled(bool enabled)
-
static void SetBlendingFactors(nCine::
BlendingFactor srcRgb, nCine:: BlendingFactor dstRgb, nCine:: BlendingFactor srcAlpha, nCine:: BlendingFactor dstAlpha) - static auto GetBlendingState() -> BlendingState
- static void SetBlendingState(const BlendingState& state)
- static void SetDepthTestEnabled(bool enabled)
- static void SetDepthMaskEnabled(bool enabled)
- static auto GetDepthTestState() -> DepthTestState
- static void SetDepthTestState(const DepthTestState& state)
- static void SetCullFaceEnabled(bool enabled)
- static auto GetCullFaceState() -> CullFaceState
- static void SetCullFaceState(const CullFaceState& state)
- static auto GetScissorState() -> ScissorState
- static void SetScissorState(const ScissorState& state)
- static void SetScissor(const Recti& rect)
- static void SetScissorTestEnabled(bool enabled)
- static auto GetViewport() -> Recti
- static void SetViewport(const Recti& rect)
-
static void InitViewport(std::
int32_t x, std:: int32_t y, std:: int32_t width, std:: int32_t height) - static auto GetClearColor() -> Colorf
- static void SetClearColor(const Colorf& color)
- static void Clear(ClearFlags flags)
-
static void DrawArrays(PrimitiveType primitive,
std::
int32_t firstVertex, std:: int32_t numVertices) -
static void DrawArraysInstanced(PrimitiveType primitive,
std::
int32_t firstVertex, std:: int32_t numVertices, std:: int32_t numInstances) -
static void DrawElements(PrimitiveType primitive,
std::
uint32_t numIndices, IndexFormat indexFormat, std:: uintptr_t indexOffset, std:: int32_t baseVertex) -
static void DrawElements(PrimitiveType primitive,
std::
uint32_t numIndices, std:: uintptr_t indexOffset, std:: int32_t baseVertex) -
static void DrawElementsInstanced(PrimitiveType primitive,
std::
uint32_t numIndices, IndexFormat indexFormat, std:: uintptr_t indexOffset, std:: int32_t numInstances, std:: int32_t baseVertex) -
static void DrawElementsInstanced(PrimitiveType primitive,
std::
uint32_t numIndices, std:: uintptr_t indexOffset, std:: int32_t numInstances, std:: int32_t baseVertex) - static auto InsertFence() -> FenceHandle
- static void DeleteFence(FenceHandle& fence)
-
static auto ClientWaitFence(FenceHandle fence,
std::
uint64_t timeoutNs) -> bool - static void SetupInitialState()
-
static auto CreateSwapchain(void* windowHandle,
std::
int32_t width, std:: int32_t height, bool vsync) -> bool - No-op (the window backend owns the presentation path).
- static void DestroySwapchain()
- No-op.
-
static void ResizeSwapchain(std::
int32_t width, std:: int32_t height) - No-op (the logical resolution is driven by ResizeScreenFramebuffer() from the render pipeline).
- static void PresentFrame()
- Closes the frame's display list and flips the display buffers (called by the Psp window backend once per frame).
-
static auto GetMaxTextureDimension() -> std::
int32_t - Returns the maximum supported texture dimension (drives the tileset chunking).
-
static void ResizeScreenFramebuffer(std::
int32_t width, std:: int32_t height) - Sets the logical resolution the scene is rendered at (scaled to 480x272 at submit).
- static void InitializeGu()
- Brings up the GE (sceGuInit, the double-buffered 480x272 display, the initial pipeline state).
- static void ShutdownGu()
- Tears the GE session down again (sceGuTerm), so the exit path leaves the hardware idle.
- static void BindProgram(GuShaderProgram* program)
- Records the currently bound shader program.
- static auto CurrentProgram() -> GuShaderProgram*
- Returns the currently bound shader program.
-
static void BindTexture(std::
uint32_t unit, const GuTexture* texture) - Records the texture bound to a texture unit.
- static void UnbindTexture(const GuTexture* texture)
- Clears a texture from every unit it is bound to (called from ~GuTexture).
-
static auto GetBoundTexture(std::
uint32_t unit) -> const GuTexture* - Returns the texture bound to a texture unit.
-
static void BindUniformRange(std::
uint32_t index, const std:: uint8_t* data, std:: uint32_t size) - Records the host data range bound to a uniform binding point.
- static void SetRenderTarget(GuRenderTarget* renderTarget)
- Records the current draw render target (draws redirect the GE's draw buffer to it).
- static void UnbindRenderTarget(const GuRenderTarget* renderTarget)
- Clears a render target from the device if it is the current one (called from ~GuRenderTarget).
- static void RegisterPaletteTexture(GuTexture* texture)
- Registers the intercepted shared palette texture (rows become hardware CLUTs).
-
static void NotifyPaletteTextureChanged(GuTexture* texture,
std::
int32_t firstRow, std:: int32_t rowCount) - Invalidates the CLUT copies (and RG8 bakes) built from the given palette rows after an upload.
-
static auto AllocateVram(std::
size_t size) -> void* - Allocates a block of video memory, or
nullptrwhen none is left. - static void FreeVram(void* ptr)
- Returns a block obtained from AllocateVram().
-
static void SetPendingSoftwareLighting(const float* lightmap,
std::
int32_t lmW, std:: int32_t lmH, std:: int32_t scale, std:: int32_t vpX, std:: int32_t vpY, std:: int32_t vpW, std:: int32_t vpH, float ambR, float ambG, float ambB, bool waterActive = false, float waterLevelPx = 0.0f, float waterTime = 0.0f, float waterCamY = 0.0f) - Queues the CPU lightmap/water combine for the next
Combinedraw (the direct-tier lighting contract). - static void EndFrame()
- Drops any lighting entries not consumed this frame (called by the window backend at present).
Constructors, destructors, conversion operators
Function documentation
static const FixedFunctionGeneratedEffect* nCine:: RHI:: GU:: GuDevice:: FindGeneratedEffect(const char* program,
const char* variant)
Returns the generated fixed-function effect of a (program, variant) key, or nullptr.
Called once per program load from GuShaderProgram::fixed_function block in its .shader file (Lighting, Blur, the Resize* family, ...) and its draws are skipped with a one-time warning, exactly as on the other fixed-function backends.
static std:: int32_t nCine:: RHI:: GU:: GuDevice:: GetMaxTextureDimension()
Returns the maximum supported texture dimension (drives the tileset chunking).
The GE's true limit, reported honestly: it makes ContentResolver cut tileset atlases into chunks that each fit one GE texture, which is what the number is for. Prebaked content that is larger anyway (the small font atlas is 128x529) is NOT rejected - GuTexture splits such an image into 512x512 pages internally and the draw path picks the page a primitive samples - so Texture::Initialize() only warns about it on this backend instead of asserting.
static void* nCine:: RHI:: GU:: GuDevice:: AllocateVram(std:: size_t size)
Allocates a block of video memory, or nullptr when none is left.
The 2 MB of embedded video memory is laid out by hand (there is no allocator behind sceGeEdramGetAddr()): the display buffers and the depth buffer sit at the front, and whatever follows them is handed out through this first-fit allocator to the surfaces that are worth keeping there - render targets. Sprite atlases deliberately stay in main memory, which the GE samples too.