Skip to content

switch from GL_TRIANGLE_FAN to GL_TRIANGLE_STRIP#538

Merged
nschimme merged 1 commit into
MUME:masterfrom
nschimme:fix-ccw
Jun 5, 2026
Merged

switch from GL_TRIANGLE_FAN to GL_TRIANGLE_STRIP#538
nschimme merged 1 commit into
MUME:masterfrom
nschimme:fix-ccw

Conversation

@nschimme

@nschimme nschimme commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This is a work-around for a bug in VmWare SVGA3D,
which renders GL_TRIANGLE_FAN incorrectly.

Triangle strips are used more often than triangle fans, so bugs with triangle fans are less likely to be tested and reported to driver vendors.

Summary by Sourcery

Switch room quad rendering from GL_TRIANGLE_FAN to GL_TRIANGLE_STRIP to work around a VMware SVGA3D bug and adjust the vertex shader accordingly.

Enhancements:

  • Update the legacy room textured vertex shader to generate vertices suitable for GL_TRIANGLE_STRIP instead of GL_TRIANGLE_FAN, with improved documentation comments.
  • Change Legacy::drawRoomQuad to render quads using GL_TRIANGLE_STRIP to avoid driver issues with triangle fans.

This is a work-around for a bug in VmWare SVGA3D,
which renders GL_TRIANGLE_FAN incorrectly.

Triangle strips are used more often than triangle fans,
so bugs with triangle fans are less likely to be tested
and reported to driver vendors.
@sourcery-ai

sourcery-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Switches room quad rendering from GL_TRIANGLE_FAN to GL_TRIANGLE_STRIP and updates the legacy room tex/acolor vertex shader to generate vertices with the correct ordering and improved documentation/comments about triangle strip vs fan winding.

Sequence diagram for room quad rendering with GL_TRIANGLE_STRIP

sequenceDiagram
    participant App as App
    participant LegacySimpleMesh as LegacySimpleMesh
    participant Functions as Functions_gl
    participant VertexShader as VertexShader_main

    App->>LegacySimpleMesh: drawRoomQuad(gl, numInstances)
    LegacySimpleMesh->>Functions: glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, numInstances)
    loop for each instance
        Functions->>VertexShader: main(gl_VertexID)
        VertexShader->>VertexShader: ioffset = ioffsets[gl_VertexID]
        VertexShader-->>Functions: position, texCoord
    end
Loading

File-Level Changes

Change Details Files
Update vertex shader to support GL_TRIANGLE_STRIP instead of GL_TRIANGLE_FAN for quad generation based on gl_VertexID.
  • Replaced previous CCW triangle-fan-based ioffsets array with a new ioffsets layout suitable for GL_TRIANGLE_STRIP, adjusting the order of the third and fourth vertices.
  • Wrapped the old GL_TRIANGLE_FAN offsets in an #if 0 block and expanded comments explaining the geometry and winding differences between fans and strips, including notes about alternating winding and effects on gl_FrontFacing.
  • Updated the shader to index the new ioffsets array directly via gl_VertexID.
src/resources/shaders/legacy/room/tex/acolor/vert.glsl
Change draw call primitive type from GL_TRIANGLE_FAN to GL_TRIANGLE_STRIP for room quad rendering.
  • Updated Legacy::drawRoomQuad to call glDrawArraysInstanced with GL_TRIANGLE_STRIP instead of GL_TRIANGLE_FAN while still emitting four vertices per instance.
src/opengl/legacy/SimpleMesh.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider removing the #if 0 block and the unused GL_TRIANGLE_FAN code from the shader to avoid carrying dead code and reduce maintenance overhead; a brief comment on why strips are used should be sufficient.
  • Since the triangle strip winding alternates, it may be helpful to explicitly note in a short comment whether any downstream logic assumes consistent front-face orientation, so future changes don’t accidentally rely on the old fan behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider removing the `#if 0` block and the unused GL_TRIANGLE_FAN code from the shader to avoid carrying dead code and reduce maintenance overhead; a brief comment on why strips are used should be sufficient.
- Since the triangle strip winding alternates, it may be helpful to explicitly note in a short comment whether any downstream logic assumes consistent front-face orientation, so future changes don’t accidentally rely on the old fan behavior.

## Individual Comments

### Comment 1
<location path="src/resources/shaders/legacy/room/tex/acolor/vert.glsl" line_range="28-29" />
<code_context>
+    // GL_TRIANGLE_STRIP
+    //  2--3  Note: Triangle strips alternate CCW/CW winding on every other triangle. This means...
+    //  |\ |    triangle 012 is CCW order, but triangle 123 is CW order (backwards).
+    //  | \|  Keep in mind that OpenGL does not actually draw the triangle backwards,
+    //  0--1    so it does not affect glFrontFace() or the gl_FrontFacing variable.
+    const ivec3[4] ioffsets = ivec3[4](ivec3(0, 0, 0), ivec3(1, 0, 0), ivec3(0, 1, 0), ivec3(1, 1, 0)); // strip
+#endif
</code_context>
<issue_to_address>
**issue:** Clarify the impact of alternating winding on glFrontFace/gl_FrontFacing.

The note about triangle strips not affecting `glFrontFace()` / `gl_FrontFacing` is inaccurate. Alternating winding in strips *does* change which triangles are classified as front-facing/back-facing under the current `glFrontFace` setting, which in turn impacts `gl_FrontFacing` and face culling. Please reword this to avoid misleading anyone relying on those behaviors.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +28 to +29
// | \| Keep in mind that OpenGL does not actually draw the triangle backwards,
// 0--1 so it does not affect glFrontFace() or the gl_FrontFacing variable.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue: Clarify the impact of alternating winding on glFrontFace/gl_FrontFacing.

The note about triangle strips not affecting glFrontFace() / gl_FrontFacing is inaccurate. Alternating winding in strips does change which triangles are classified as front-facing/back-facing under the current glFrontFace setting, which in turn impacts gl_FrontFacing and face culling. Please reword this to avoid misleading anyone relying on those behaviors.

@nschimme nschimme merged commit 2649fae into MUME:master Jun 5, 2026
19 checks passed
@nschimme nschimme deleted the fix-ccw branch June 5, 2026 17:13
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 25.69%. Comparing base (e912fbf) to head (a6d1ec6).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/opengl/legacy/SimpleMesh.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #538   +/-   ##
=======================================
  Coverage   25.69%   25.69%           
=======================================
  Files         521      521           
  Lines       43187    43187           
  Branches     4708     4708           
=======================================
  Hits        11099    11099           
  Misses      32088    32088           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant