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

A few little fix ups #81

Merged
merged 19 commits into from
Nov 16, 2024
Merged

A few little fix ups #81

merged 19 commits into from
Nov 16, 2024

Conversation

mardy
Copy link
Collaborator

@mardy mardy commented Nov 8, 2024

Please review commit by commit, as the fixes are unrelated to each other.

mardy added 7 commits November 8, 2024 22:18
The DirectVboReader class has its own setup_draw() method, and it should
replicate the logic to enable texture arrays sequentially.
We forgot to update the glEnableClientState() and glDisableClientState()
functions to operate on the active texture unit.
We previously added GL_MAX_TEXTURE_IMAGE_UNITS, which has about the same
meaning, but it's for meaningful for fragment shaders only: programs
using OpenGL in immediate mode use GL_MAX_TEXTURE_UNITS.
Extension names need to be separated by a space.
We could indeed add this library to our pkg-config file, but we don't
use any other of its functions, and using malloc() and free() is more
efficient anyway.
Small refactoring of the CoordVertexReader class to support vertex
elements consisting of a single float coordinate (that's the case
normally handled by GX_TexCoord1f32()).
For some reason, Neverball passes the same array where vertex position
coordinates are stored as texture coordinates, but GX does not support
more than 2 texture coordinates per elements.

It may be that we can do something smarter here (detect that the vertex
data pointer is the same as the vertex coordinates, and don't pass it
twice to GX, instead setup a texgen matrix to process it), but for the
time being just limit the number of components in order not to send
wrong data into the FIFO.
mardy added 7 commits November 9, 2024 10:50
Ths OpenGL spec says that the texture index 0 must be silently ignored
by glDeleteTextures(). Failure to ignore this value was causing weird
artifacts with text labels in Neverball.

We also invert the logic of the "if" condition, to make it easier to
read.
How this did not break all other applications is a mystery.
Avoid performing a matrix multiplication if the angle is zero, but also
if the rotation axis is null: in that case, the rotation matrix would
get filled with some NaN values, therefore corrupting the resulting
matrix.
There are subtle differences between these, but for the time being just
map them to GX_CLAMP, which the most appropriate match.
We should check all the four TEV inputs for the "one" constant, and we
need a way to tell it apart from GX_CA_KONST (which could be used when
an arbitrary constant value is desired).
The alpha should not get summed, but multiplied.
We should not hardcode the input to be GX_CC_CPREV or GX_CA_APREV,
because this would not work for the first stage. Instead, check if we
are computing inputs for the first stage, and in that case use the
raster color.
@mardy mardy marked this pull request as draft November 11, 2024 20:03
@mardy mardy marked this pull request as ready for review November 11, 2024 20:32
In the second color channel, the alpha component of the diffuse material
should not be added, but multiplied with the input from the previous
stage, because the OpenGL spec says that the value of alpha should be
taken from the alpha component of the color material's diffuse value.

This fixes the rendering of glass parts in Neverball.
The client code might have called glTexParameteri() and set a specific
wrapping mode before loading the texture data, and we should preserve
it.

This effectively reverts 2853d62, but
now the GX_REVERT wrapping mode is set automatically in glGenTextures
and glBindTexture if the texture was previously unused.
It turns out that while this works on Dolphin, the GX_TEVPREV register
cannot be written to, on a real Wii. Therefore, write on a GX_TEVREGx
register, and allocate them dynamically.
The GX_CC_RASC and GX_CA_RASA constants do not refer to the untextured
vertex color, but only to the color being generated by the color channel
associated with the current stage: while in some situation these two
entities coincide, in the case of a lit object we do have two active
color channels, and these constants can only be used to refer to one of
them at a time. Furthermore, when we enter the texturing stage on a lit
geometry, we pass GX_COLORNULL, meaning that no rasterizer color channel
is associated, and here GX_CC_RASC and GX_CA_RASA only render black.

Yet, the texture environment operations in OpenGL sometimes need to
operate on the color emitted on the vertex by the rasterizer.

The solution is to emit the result of the lighting operations not on
GX_TEVPREV (which gets changed at each stage), but on a well-named
register (one of GX_TEVREG0 - GX_TEVREG2), which later stages can
then refer to.
@WinterMute WinterMute merged commit d89ccf9 into devkitPro:master Nov 16, 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