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

graphics: Fix backwards compatibility with integer attributes #463

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

not-fl3
Copy link
Owner

@not-fl3 not-fl3 commented Jun 25, 2024

Follow up on #461

I can't really think of any better solution, just added a doc comment over gl_pass_as_float.

cc @eloraiby @birhburh

@@ -1332,7 +1334,9 @@ impl RenderingBackend for GlContext {
unsafe {
match attribute.type_ {
GL_INT | GL_UNSIGNED_INT | GL_SHORT | GL_UNSIGNED_SHORT
| GL_UNSIGNED_BYTE | GL_BYTE => {
| GL_UNSIGNED_BYTE | GL_BYTE
if !attribute.gl_pass_as_float =>
Copy link
Contributor

Choose a reason for hiding this comment

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

QQ: why not something like:

                        match attribute.type_ {
                            GL_INT | GL_UNSIGNED_INT | GL_SHORT | GL_UNSIGNED_SHORT
                            | GL_UNSIGNED_BYTE | GL_BYTE
                                if self.has_integer_attributes() =>
                            {
                                glVertexAttribIPointer(
                                    attr_index as GLuint,
                                    attribute.size,
                                    attribute.type_,
                                    attribute.stride,
                                    attribute.offset as *mut _,
                                )
                            }
                            _ => glVertexAttribPointer(
                                attr_index as GLuint,
                                attribute.size,
                                attribute.type_,
                                GL_FALSE as u8,
                                attribute.stride,
                                attribute.offset as *mut _,
                            ),
                        }

Copy link
Owner Author

Choose a reason for hiding this comment

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

thx, I agree, a lot better!

Copy link
Owner Author

Choose a reason for hiding this comment

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

oh, wait, I misread it.

has_integer_attributes doesn't neccessarily mean we want uvec4 in the shader.

has_integer_attributes means the backend support glVertexAttribIPointer, gl_pass_as_float means that the user wants glVertexAttribIPointer to be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you d need gl_pass_as_float, because the moment it supports integer and the user is passing a byte, it'll convert it. glsl 150 requires opengl 3.2 and above, so that shouldn't affect it. But better test this one.

Copy link
Owner Author

Choose a reason for hiding this comment

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

It does not, thats how that whole thing started :)
glsl100 shaders do not receive glVertexAttribIPointer Byte4 as vec4, even on OpenGL4+

@not-fl3 not-fl3 force-pushed the integer_attributes_fix branch 3 times, most recently from 929e542 to e1f2750 Compare June 25, 2024 03:40
Since a359a34, glVertexAttribIPointer was used for VertexAttribute:Byte*/Short*/etc. While it is a correct behavior, it broke backwards compatibility with glsl100 shaders receiving Byte4 vectors as vec4. This commit makes this feature opt-in: it is possible to pass Byte4 as uvec4, but only if its explicitly required.
@not-fl3
Copy link
Owner Author

not-fl3 commented Jun 25, 2024

triangle_color4b example works, macroquad works, all old miniquad using code should not be affected, so lets merge it and will see how it goes!

Feel free to send follow up PRs if it was not, in fact, a good idea :)

@not-fl3 not-fl3 merged commit 0cd517c into master Jun 25, 2024
20 checks passed
@not-fl3 not-fl3 deleted the integer_attributes_fix branch June 25, 2024 15:23
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