Skip to content

docs: document 2D coordinate spaces#9847

Open
poweifeng wants to merge 1 commit intomainfrom
docs-update-readpixels
Open

docs: document 2D coordinate spaces#9847
poweifeng wants to merge 1 commit intomainfrom
docs-update-readpixels

Conversation

@poweifeng
Copy link
Copy Markdown
Contributor

No description provided.

@poweifeng poweifeng added the internal Issue/PR does not affect clients label Mar 27, 2026
@poweifeng poweifeng force-pushed the docs-update-readpixels branch from 0985c4c to bb73db2 Compare April 9, 2026 19:27
@poweifeng poweifeng changed the title docs: upload and read pixels vs. backend docs: document 2D coordinate spaces Apr 13, 2026
@poweifeng poweifeng requested a review from pixelflinger April 13, 2026 18:34
And remove the pngs that documented the same thing.
@poweifeng poweifeng force-pushed the docs-update-readpixels branch from bb73db2 to f0a3b10 Compare April 13, 2026 18:35
Comment on lines +29 to +30
- Filament defines its coordinate system using the *top-left* of the image as \\((0, 0)\\) and
the *bottom-right* is \\((1, 1)\\).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is that true though? (like it's not true for textures). Maybe give an example of a filament public API that uses that convention?

Copy link
Copy Markdown
Collaborator

@pixelflinger pixelflinger left a comment

Choose a reason for hiding this comment

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

I think i would structure things differently.

The first paragraph is good. I would then describe what each backend does:

GL:

  • uploads: low-address is bottom
  • readbacks: bottom is low address
  • rendering: origin is bottom-left
  • sampling: origin is bottom-left

Others:

  • uploads: low-address is top
  • readbacks: top is low address
  • rendering: origin is top-left
  • sampling: origin is top-left

Then I would explain that this means that:

  • upload + read: works in all backend
  • but: render + read: produces different results

Then I would say that filament addresses this by:

  • inverting reads when reading
  • this fixes the render + read path
  • this sacrifices the upload + read path
    • this is an unsolved problem in filament, only case where backends behave differently

coordinate system.

The GL function for uploading texture is `glTexImage2D`. Even though GL interprets \\((0, 0)\\) as
the bottom-left of a 2D image, `glTexImage2D` uploads the lower-bits as the *bottom* of the image
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would say "lower-address bytes/data/pixels".


| |
|---|
| *Filament's internal texture coordinate space defines the **top-left** corner of the image as the origin.* |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see what you mean, but strangely I think of it the other way around.

origin. Hence, the first row of the image in CPU memory is the bottom-most row of the image (when
displayed).

This creates two related inconsistencies:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This bothers me to say this because GL is actually very consistant (it's in fact the most consistant of the APIs, imho).

displayed).

This creates two related inconsistencies:
- First, (not a real use case), if one were to upload a texture, attach it as an attachment, and
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

True, but since glTexImage2D also did that, this all works out perfectly. The image wouldn't be "upside down". You'd get exactly the same bytes that you used for glTexImage2D.

Comment on lines +69 to +70
- Second, the other backends consider the top-left corner as the origin, which means their
readbacks would place the top of the image as the first row of the image in CPU memory.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This also works out because their upload is consistant.

Comment on lines +72 to +73
To account for these inconsistencies, *the GL backend vertically flips the rows of the readback
image*.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's actually not correct. The GL backend inverts read pixel for a different reason!

It's for the case where you RENDER into an attachment. We want to get the same data back on all backends when using readPixels.

Copy link
Copy Markdown
Member

@bejado bejado left a comment

Choose a reason for hiding this comment

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

Are the diagrams inside art/diagrams no longer accurate? If so, maybe we could update them instead of getting rid of them entirely.

@poweifeng
Copy link
Copy Markdown
Contributor Author

Are the diagrams inside art/diagrams no longer accurate? If so, maybe we could update them instead of getting rid of them entirely.

Yes initially I just wanted to add text to the pictures because I found the pictures themselves a little confusing. But as I started writing, I thought words enough would be sufficient. But we could do something in the middle where the pictures are included in this doc as embedded illustrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Issue/PR does not affect clients

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants