Skip to content

removed sdfRenderOp, reduces object creation#790

Open
jfboeve wants to merge 15 commits into
mainfrom
feat/removed-sdfrenderop
Open

removed sdfRenderOp, reduces object creation#790
jfboeve wants to merge 15 commits into
mainfrom
feat/removed-sdfrenderop

Conversation

@jfboeve
Copy link
Copy Markdown
Collaborator

@jfboeve jfboeve commented May 11, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors SDF text rendering to remove the dedicated SdfRenderOp render-op object and instead render SDF text by submitting CoreTextNode instances directly to the WebGL render op list, aiming to reduce per-frame object creation/GC.

Changes:

  • Replaced TextRenderInfo with a discriminated union (SdfRenderInfo / CanvasRenderInfo) and adjusted renderer interfaces accordingly.
  • Removed SdfRenderOp and moved SDF buffer/shader-prop setup into CoreTextNode + special-case binding in WebGlShaderProgram.
  • Updated WebGlRenderer render-op typing and related glue code to accept SDF text nodes as render ops.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/core/text-rendering/TextRenderer.ts Introduces new discriminated TextRenderInfo model and updates TextRenderer interface.
src/core/text-rendering/SdfTextRenderer.ts Stops building SdfRenderOp; caches SDF render info and submits CoreTextNode as a render op.
src/core/text-rendering/CanvasTextRenderer.ts Updates cache typing and returns CanvasRenderInfo with type: 'canvas'.
src/core/renderers/webgl/WebGlShaderProgram.ts Adds SDF-specific uniform binding branch keyed off render-op type/flags.
src/core/renderers/webgl/WebGlRenderer.ts Updates WebGlRenderOp type to include text nodes as render ops.
src/core/renderers/webgl/SdfRenderOp.ts Deleted (render-op replaced by node-driven approach).
src/core/CoreTextNode.ts Implements SDF render-op behavior directly: buffer upload/caching, shader props, and custom draw for SDF text.
src/core/CoreNode.ts Adjusts isCoreNode type annotation.
Comments suppressed due to low confidence (1)

src/core/CoreTextNode.ts:289

  • This check only guards against imageData === undefined, but CanvasTextRenderer can currently produce imageData === null (when canvas dims are 0). That means null can flow into the createTexture({ src: ... }) call below and crash. Update the check (or the renderer types/behavior) to handle null explicitly.
    if (textRendererType === 'canvas') {
      if (result.imageData === undefined) {
        this.emit('failed', {
          type: 'text',

Comment thread src/core/CoreTextNode.ts Outdated
Comment thread src/core/CoreTextNode.ts
Comment on lines +453 to +455
override get quadBufferCollection(): BufferCollection {
return this._sdfQuadCollection || super.quadBufferCollection;
}
Comment thread src/core/text-rendering/SdfTextRenderer.ts
Comment on lines +252 to +256
if (
isCoreNode === false &&
(renderOp as CoreTextNode).sdfShaderProps !== null
) {
const opShader = renderOp.shader!; // SdfRenderOp has .shader
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback in seperate PR

Comment thread src/core/CoreTextNode.ts
Comment thread src/core/text-rendering/SdfTextRenderer.ts Outdated
Comment thread src/core/text-rendering/CanvasTextRenderer.ts
jfboeve and others added 2 commits May 11, 2026 14:18
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

@jfboeve I've opened a new pull request, #791, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

@jfboeve I've opened a new pull request, #792, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

@jfboeve I've opened a new pull request, #793, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 5 commits May 11, 2026 12:22
#791)

`CoreTextNode` was taking the SDF-specific branch by overriding
`isCoreNode`, which also changed earlier RTT framebuffer selection in
`bindRenderOp`. That coupling could produce incorrect `u_resolution` /
`u_pixelRatio` for SDF text rendered under an RTT parent.

- **What changed**
  - Added a dedicated `isSdfRenderOp` signal on render ops.
- Switched SDF-specific bind logic in `WebGlShaderProgram` to use
`isSdfRenderOp` instead of `isCoreNode`.
- Restored `CoreTextNode` to the normal core-node framebuffer path so
RTT parent dimensions continue to be used for resolution selection.

- **Behavioral impact**
  - SDF text keeps its custom shader binding path.
- RTT resolution/pixel ratio selection continues to follow core-node
semantics for text nodes.
  - Render-op reuse remains stable for SDF text under RTT parents.

- **Regression coverage**
  - Added focused WebGL tests for:
- SDF text using parent RTT framebuffer dimensions during uniform
binding
    - SDF render-op reuse when parent RTT dimensions match

- **Illustrative change**
  ```ts
  // before
if (isCoreNode === false && (renderOp as CoreTextNode).sdfShaderProps
!== null) {
    // SDF bind
  }

  // after
  if (renderOp.isSdfRenderOp === true) {
    // SDF bind
  }
  ```
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ jfboeve
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

jfboeve and others added 5 commits May 11, 2026 14:40
…ontract (#793)

`SdfTextRenderer.renderText` declared `TextRenderInfo | null` as its
return type, violating the `TextRenderer` interface which requires
`TextRenderInfo`. A `null` return reaching
`CoreTextNode.handleRenderResult` would throw on `result.type` access.

## Changes

- **Return type corrected** — `renderText` now returns `TextRenderInfo`,
matching the interface
- **Redundant null guards removed:**
- `props.text.length === 0` early-return dropped — `CoreTextNode` blocks
`renderText` calls when text is empty
- `fontData === undefined` null-return dropped — `CoreTextNode` verifies
`isFontLoaded` before invoking `renderText`; font lookup inlined with
`!` per zero-safety-checks policy

```ts
// Before
const renderText = (props: CoreTextNodeProps): TextRenderInfo | null => {
  if (props.text.length === 0) return null;
  // ...
  const fontData = SdfFontHandler.getFontData(props.fontFamily);
  if (fontData === undefined) return null;
  // ...
};

// After
const renderText = (props: CoreTextNodeProps): TextRenderInfo => {
  // ...
  const layout = generateTextLayout(props, SdfFontHandler.getFontData(props.fontFamily)!);
  // ...
};
```
…opilot/sub-pr-790-again

# Conflicts:
#	src/core/CoreTextNode.test.ts
#	src/core/renderers/webgl/WebGlShaderProgram.test.ts
…#792)

- [x] Inspect current branch state, recent commits, and whether merge
conflicts exist locally
- [x] Check recent GitHub Actions runs for `feat/removed-sdfrenderop`
and this branch if needed
- [x] Fetch the stacked base branch and compare it against the current
branch
- [x] Resolve any new conflicts if present and run targeted validation
- [x] Run final validation and reply on the review thread
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants