Skip to content

Fix GLES byte readback from HDR framebuffers - #3043

Open
8Keep wants to merge 3 commits into
jMonkeyEngine:masterfrom
8Keep:fix/gles-hdr-framebuffer-readback
Open

8Keep wants to merge 3 commits into
jMonkeyEngine:masterfrom
8Keep:fix/gles-hdr-framebuffer-readback

Conversation

@8Keep

@8Keep 8Keep commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

On ANGLE/GLES, renderer.readFrameBuffer(hdrFramebuffer, buffer) can fail when the color attachment is RGBA16F or RGBA32F. The current code requests RGBA/UNSIGNED_BYTE; GLES rejects that read from a floating-point surface with GL_INVALID_OPERATION, leaving the caller without the image. I reproduced this on native ANGLE: an RGBA8 control succeeds, then reading the RGBA16F target reports GL error 0x502.

For RGBA8/BGRA8 byte output from floating-point GLES attachments, read RGBA/FLOAT and convert the pixels on the CPU. This is a supported read format in EXT_color_buffer_float. Components are clamped to [0, 1] and rounded to bytes: (0.25, 0.5, 0.75, 1) becomes (64, 128, 191, 255). BGRA output swaps red and blue. There is no exposure or gamma adjustment.

The conversion uses the actual read attachment, including mixed render targets and the main framebuffer override. Texture attachments use their current image format after image replacement; renderbuffers use their stored format. It preserves the caller's buffer position/limit. It uses a temporary RGBA float buffer, released after conversion. The format check is explicit so other requested channel layouts cannot silently receive RGBA bytes.

Validation: seven regression cases fail on the original implementation; all twelve pass with the fix. Native GLES and desktop GL each pass 30,776 checks, including both texture-format replacement directions, covering 16F/32F targets, RGBA/BGRA output, buffer sentinels, explicit float output, the main override and mixed read attachments. On the original implementation the native GLES HDR read fails while the desktop control passes.

Full core suite: 1,183 passed, one skipped, zero failures. Core Checkstyle tasks and LWJGL3 compilation pass; existing style warnings remain. Native validation is from this Linux/NVIDIA machine.

Reading an RGBA16F or RGBA32F attachment through readFrameBuffer requests
RGBA/UNSIGNED_BYTE, which GLES rejects with GL_INVALID_OPERATION. Native
ANGLE reproduces error 0x502 while the normalized RGBA8 control succeeds.

Read floating-point GLES attachments with RGBA/FLOAT, then clamp and round
into the requested RGBA8/BGRA8 byte layout. Use the selected read attachment
for mixed render targets and honor the main framebuffer override. Preserve
the caller's buffer range and release temporary float storage in finally.
Restrict conversion to the explicit supported byte layouts.

Seven regression cases fail before the fix; all ten pass afterward. Native
GLES and desktop GL each pass 22,570 checks for float targets, channel order,
buffer guards, explicit float output, main overrides and MRT selection.
The original GLES implementation fails the HDR read while desktop GL passes.

Full core suite passes 1,181 tests with one skipped and no failures.
Both core Checkstyle tasks and LWJGL3 compilation pass. Native validation
is from Linux/NVIDIA; other platforms remain for CI.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T16:20:21.850066Z 642b0c0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jaime-jmebot jaime-jmebot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, thanks for putting together a focused fix and a thorough regression suite for GLES HDR readback. I reviewed the renderer changes and the new tests. The implementation identifies the effective read attachment before deciding whether the GLES float-read conversion applies, which is important for both MRT read-buffer selection and the main framebuffer path. Restricting the conversion to RGBA8/BGRA8 requests also avoids silently changing the semantics of other output formats.

The conversion itself keeps the caller’s buffer range intact, clamps and rounds normalized values as described, handles BGRA channel order, and releases its temporary buffer in a finally block. The tests exercise those details along with floating-point versus byte reads and attachment selection, providing good coverage for the edge cases this change introduces.

I don’t see any blocking issues. The reported native GLES and desktop validation, together with the core suite and compile/style checks, are reassuring. Looks good to me—thanks for tackling this.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 642b0c07c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

8Keep and others added 2 commits November 5, 2026 11:39
A texture target retains its original RenderBuffer format after Texture.setImage replaces the image. Choose the readback type from the current image so normalized-to-float and float-to-normalized replacements use legal GLES reads. Renderbuffer targets continue using their stored format. Both new regressions fail before the fix and pass afterward; native GLES reproduces error 0x502 before the fix and passes both replacement directions afterward. The full core suite and style checks pass.
@riccardobl

Copy link
Copy Markdown
Member

I'm not fully convinced by the approach of allocating a temporary buffer on every read.

Could we reuse a scratch buffer instead, growing it in chunks as needed to accommodate the largest read and retaining that capacity for subsequent reads?

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.

3 participants