Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rtexture] Cubemap mipmap loading improvements #4721

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

Not-Nik
Copy link
Contributor

@Not-Nik Not-Nik commented Jan 23, 2025

Another two patches for loading cubemaps with mipmaps. Hopefully the last ones 😅

Two fixes in one PR for loading cubemaps with mipmaps:

  1. Previously we were always generating mipmaps if we could. This makes sense for cubemaps with some mipmaps, but not all possible. If we didn't do it there, that cubemap would be incomplete when filtering with GL_LINEAR_MIPMAP_LINEAR/RL_TEXTURE_FILTER_MIP_LINEAR or GL_NEAREST_MIPMAP_LINEAR/RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR, because those require all possible mipmaps to be available1. For cubemaps with no mipmaps (just the base mipmap level), there is no need to generate any mipmaps (or use VRAM to store them), because the user wouldn't expect there to be any mipmaps in the first place. Thus, only build cubemap mipmaps when necessary.
  2. Previously, a cubemaps mipmap count would always be set to 1 (on the CPU), regardless of the actual number of mipmaps present on the GPU. This change neatly ties in with the first patch, because we can just use the number of mipmaps the image has, were we may or may not have generated them.

I tested that the model_skybox example still works, and obviously I tested it with my own IBL setup, where everything also works.

As last time, I structured the PR to be able to just be rebased onto master if you want all the different changes to reflect in the tree.

Footnotes

  1. This is not entirely true for "normal" OpenGL, but since there is no way to set GL_TEXTURE_MAX_LEVEL in plain raylib, I'd say it applies for us. See "The base and max levels must only specify mipmap levels that have been allocated [...]" here

@raysan5 raysan5 merged commit 49d37b0 into raysan5:master Jan 24, 2025
14 checks passed
@raysan5
Copy link
Owner

raysan5 commented Jan 24, 2025

@Not-Nik Nice improvement! Thanks!

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.

2 participants