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

glTexSubImage2D(), support more texture formats, fast conversions #30

Merged
merged 12 commits into from
May 30, 2024

Conversation

mardy
Copy link
Collaborator

@mardy mardy commented May 25, 2024

This branch contains many loosely-related changes about texture handling:

  • Support for nearly all OpenGL 1.1 texture formats
  • Move glTex*() functions to a separate texture.c file
  • glTexSubImage2D()
  • Use C++ templates to create specialized texture converters
  • Let the client specify which fast texture converters needs to be built in

As usual, reviewing commit-by-commit is strongly recommented.

mardy added 12 commits May 25, 2024 17:13
This was used by one of our glu functions.
Use templates to unify the implementation as much as possible.

Note that with this commit we temporarily lose support form GL_BGR and
GL_BGRA formats, which are part of OpenGL 1.2, but we will bring them
back later.
Add a Texel base class for the Texel writer classes, so that they can be
used in non-template code. Add a method to set the pixel color from a
GXColor.

Add a DataReaderBase class defining an interface for pixel readers
(using GXColor as the result), and a couple of generic subclasses (one
of which needs to be a template, in order to read pixel components as
bytes, words, longs and floats without excessive pain) to read texture
input data pixel by pixel.

Finally, we combine these two sides inside a generic texture conversion
function, which reads the client pixel data and stores it into a GX
texture.

This is a minimal implementation: we will need to support specifying the
pitch and the pixel alignment. We also do not support loading textures
whose components are encoded with one of the signed types GL_BYTE,
GL_SHORT and GL_INTEGER; these are easy to add, but since they would be
used in the templated reader, and given that they are fairly uncommon,
we leave them out until someone requests them, in order to save on code
size.
The bytesperpixelsrc is now just unused, and the infomation in
bytesperpixelinternal can be obtained by gx_format.
This is going to grow once we add support for more glTex* functions.
This function will be used by glTexSubImage2D as well.
The width and height parameters are now indicating the size of the
source image only; for the destination it's enough to know the row
pitch.
This also is going to be used by glTexSubImage2D. We also refactor the
way that the texture format GX_TF_A8 is propagated, by keeping a flag in
the userdata field, which tells us if the GX_TF_I8 format is in reality
a GX_TF_A8.
This is almost trivial, by using the update_texture method. Tested on
crack-attack, which uses this feature extensively to write text.
This is a compromise to allow keeping the binary size small while still
activating all the faster textures conversions needed: we instantiate all
the texture conversion templates, but we don't directly use them, so
that the linker will not bring them into the compiled object. Instead,
we expose their symbols and a public function to let the client register
the conversions it needs.

The conversion functions are exposed as intptr_t in order to hide the
full signature, since we might need to change it later.

If the client doesn't do this, opengx will pick the slower conversion
(which can be up to 10x slower), but the program will not break in any
case.
@WinterMute WinterMute merged commit 38d07cc into devkitPro:master May 30, 2024
2 checks passed
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