Reusable helpers for uploading pixel data to a GPU texture and drawing it as a textured quad through GeodeImagePipeline. More...
#include "donner/svg/renderer/geode/GeodeTextureEncoder.h"
Classes | |
| struct | UniformAllocation |
| Borrowed uniform-buffer range for one blit uniform upload. The buffer field is a raw non-owning handle: the provider keeps it alive (see UniformScratch's contract below); holders must not retain the allocation beyond the current frame. More... | |
| class | UniformScratch |
| Interface for callers that pool blit uniform uploads into a per-frame scratch arena instead of creating one uniform buffer per blit. More... | |
| struct | QuadParams |
| Parameters for a single textured-quad draw call. More... | |
| class | RetainedQuadBinding |
| Uniform buffer and bind group that one textured quad keeps across frames, so drawing it again with unchanged inputs writes no buffer and creates no bind group. More... | |
Public Types | |
| enum class | Filter : uint8_t { Linear , Nearest , Pixelated , Cubic , Anchored } |
| Filtering mode for drawTexturedQuad. More... | |
Static Public Member Functions | |
| static gpu::Texture | uploadRgba8Texture (const GeodeGpuContext &context, const uint8_t *rgbaPixels, uint32_t width, uint32_t height) |
| Upload a tightly packed RGBA8 pixel buffer to a freshly created sampled texture. | |
| static void | BuildClipFromLocal (const Transform2d &targetFromLocal, uint32_t targetWidth, uint32_t targetHeight, float out16[16]) |
Build the column-major clip-from-local matrix for a quad drawn through targetFromLocal into a targetWidth x targetHeight target (y down in target pixels, up in clip space). | |
| static void | drawTexturedQuad (const GeodeGpuContext &context, const GeodeImagePipeline &pipeline, gpu::RenderPassEncoder &pass, const gpu::Texture &texture, const float mvp[16], uint32_t targetWidth, uint32_t targetHeight, const QuadParams ¶ms, GeodeTransientResources &resourceArena, UniformScratch *scratch=nullptr) |
| Record a textured-quad draw call into an already-open render pass. | |
| static bool | drawRetainedQuad (const GeodeGpuContext &context, const GeodeImagePipeline &pipeline, gpu::RenderPassEncoder &pass, const gpu::Texture &texture, const float mvp[16], uint32_t targetWidth, uint32_t targetHeight, const QuadParams ¶ms, RetainedQuadBinding &binding) |
Record a textured-quad draw through binding, reusing its uniform buffer and bind group when they still match this draw (see RetainedQuadBinding). | |
Static Public Attributes | |
| static constexpr uint64_t | kUniformOffsetAlignment = geode::kUniformOffsetAlignment |
| Uniform-buffer binding offset alignment shared by the blit path and any UniformScratch implementation. Names donner::geode::kUniformOffsetAlignment, which is the one definition; this member is the spelling the blit path and its tests already use. | |
Reusable helpers for uploading pixel data to a GPU texture and drawing it as a textured quad through GeodeImagePipeline.
This is the piece drawImage and pattern tile rendering share. Both paths need:
Pattern rendering calls uploadRgba8Texture to move a rendered pattern tile into a sampled texture and then drawTexturedQuad to stamp that tile across the target region (with srcRect chosen to implement the patternContentUnits / patternUnits mapping).
The class is pure helpers - no mutable state. It's a class rather than free functions only to keep namespacing sensible.
| struct donner::geode::GeodeTextureEncoder::UniformAllocation |
Borrowed uniform-buffer range for one blit uniform upload. The buffer field is a raw non-owning handle: the provider keeps it alive (see UniformScratch's contract below); holders must not retain the allocation beyond the current frame.
| Class Members | ||
|---|---|---|
| BufferRef | buffer | |
| uint64_t | offset = 0 | |
| uint64_t | size = 0 | |
| struct donner::geode::GeodeTextureEncoder::QuadParams |
Parameters for a single textured-quad draw call.
destRect is in target-pixel space; the caller must bake the current model-view transform into targetFromLocal if the rect is authored in a different coordinate system. This keeps drawTexturedQuad agnostic about where the MVP lives in the larger renderer's state stack.
| Class Members | ||
|---|---|---|
| Vector2i | anchor = Vector2i::Zero() | Target pixel that the content stays aligned to for Filter::Anchored: two draws whose source and target differ by whole pixels, with the anchor at the same target pixel, sample corresponding pixels with the same bilinear weights. |
| bool | applyMaskBounds = false | When true, output pixels outside maskBounds are discarded. Used to honour the <mask> element's x/y/width/height. |
| uint32_t | blendMode = 0 | SVG mix-blend-mode selector. 0 = plain source-over; 1..=16 map to the enumeration in donner::svg::MixBlendMode (Normal..Luminosity). When non-zero, dstSnapshotTexture must hold the parent render target's frozen content for the fragment shader to read as the backdrop. |
| const TextureView * | clipMaskView = nullptr | Path-clip mask view. When set, the image shader samples it in target-pixel space and gates the source content before any blend/mask compositing. Borrowed. |
| Box2d | destRect | Destination rectangle (in target-pixel space after applying targetFromLocal). |
| const Texture * | dstSnapshotTexture = nullptr | Frozen snapshot of the parent render target - see RendererGeode::popIsolatedLayer which copies the prior parent content into a separate texture before opening the blend blit pass. Ignored unless blendMode != 0. Borrowed. |
| Filter | filter = Filter::Linear | Sampling filter mode. |
| Box2d | maskBounds | Mask bounds in target-pixel space. Ignored unless applyMaskBounds is true. |
| uint32_t | maskMode = 0 | Mask coverage selector: 0 disables masks, 1 uses sRGB luminance, 2 alpha, 3 linear luminance. |
| const Texture * | maskTexture = nullptr | <mask> compositing input. Ignored unless maskMode is nonzero. Borrowed. |
| double | opacity = 1.0 | Overall opacity multiplier in [0, 1]. Combined with the sampled alpha inside the fragment shader. |
| double | pixelatedScaleX = 1.0 | Device-pixel scale per source texel for CSS pixelated sampling. |
| double | pixelatedScaleY = 1.0 |
|
| bool | sourceIsPremultiplied = false | Set when the source texture already stores premultiplied-alpha pixels. drawImage premultiplies ImageResource pixels before upload, and offscreen render targets blitted during popIsolatedLayer / pattern compositing are already premultiplied. Both paths set this flag to avoid a second premultiplication that darkens the RGB channel. Straight-alpha callers leave the default false so the shader premultiplies on output. |
| Box2d | srcRect = Box2d({0.0, 0.0}, {1.0, 1.0}) | Source UV rectangle in [0,1] × [0,1]. Default = entire texture. |
| Transform2d | targetFromLocal | Maps destRect's space to target pixels; the MVP must apply the same mapping. Nearest sampling inverts it to find the source texel under each pixel center. |
|
strong |
Filtering mode for drawTexturedQuad.
| Enumerator | |
|---|---|
| Linear | Bilinear filtering, for image-rendering: smooth and layer or pattern composites. |
| Nearest | The texel containing each sample, for crisp-edges, translation-only image draws and explicit pattern sampling. |
| Pixelated | Integer nearest-neighbor scaling followed by smooth scaling. |
| Cubic | Mitchell-Netravali cubic (B = C = 1/3) over premultiplied texels, for <image> quality rendering. Uses the linear sampler only for mask and backdrop reads. |
| Anchored | Bilinear filtering through a texel mapping split at QuadParams::anchor, for resamples that must not change when the target and the content move together by whole pixels. |
|
static |
Build the column-major clip-from-local matrix for a quad drawn through targetFromLocal into a targetWidth x targetHeight target (y down in target pixels, up in clip space).
| targetFromLocal | Transform from the quad's local space to target pixels. |
| targetWidth | Render-target width in pixels. |
| targetHeight | Render-target height in pixels. |
| out16 | Receives the 16 matrix entries. |
|
static |
Record a textured-quad draw through binding, reusing its uniform buffer and bind group when they still match this draw (see RetainedQuadBinding).
Takes the same draw inputs as drawTexturedQuad. Returns false without recording anything when the binding cannot serve the draw (a buffer, view or bind group the device refused); the caller then draws through drawTexturedQuad.
| context | GPU context used to allocate draw resources. |
| pipeline | Image pipeline compatible with the active target. |
| pass | Open render pass receiving the draw. |
| texture | Source texture sampled by the quad. |
| mvp | Column-major 4x4 transform from quad coordinates to clip space. |
| targetWidth | Render-target width in physical pixels. |
| targetHeight | Render-target height in physical pixels. |
| params | Quad placement, sampling, clipping, and compositing settings. |
| binding | Binding this quad keeps across frames. |
|
static |
Record a textured-quad draw call into an already-open render pass.
The caller must:
Allocates a bind group per call (retained in resourceArena until the caller finishes the enclosing command encoder). The uniform upload either goes into scratch when provided (one buffer create on arena growth instead of one per blit) or into a fresh per-blit buffer on the legacy path.
| resourceArena | Scoped owner for GPU handles created by the draw. |
| scratch | Optional pooled uniform scratch (see UniformScratch). |
| context | GPU context used to allocate draw resources. |
| pipeline | Image pipeline compatible with the active target. |
| pass | Open render pass receiving the draw. |
| texture | Source texture sampled by the quad. |
| mvp | Column-major 4x4 transform from quad coordinates to clip space. |
| targetWidth | Render-target width in physical pixels. |
| targetHeight | Render-target height in physical pixels. |
| params | Quad placement, sampling, clipping, and compositing settings. |
|
static |
Upload a tightly packed RGBA8 pixel buffer to a freshly created sampled texture.
Alpha interpretation is carried by the draw parameters.
Texture writes carry a 256-byte row pitch. This function handles the case where the source buffer's row stride (width * 4) is not 256-aligned by copying rows into a padded staging buffer before the upload.
Returns an empty texture if width, height, or rgbaPixels are invalid.
| context | The recording context providing the GPU runtime device. |
| rgbaPixels | RGBA8 pixels in row-major order. Must contain at least width * height * 4 bytes. |
| width | Image width in pixels. Must be > 0. |
| height | Image height in pixels. Must be > 0. |