Skip to content

Conversation

maiconpintoabreu
Copy link
Contributor

@maiconpintoabreu maiconpintoabreu commented Sep 21, 2025

This PR is to fix the rlSetTexture as when you have different textures it will not override the mode that is default to GL_QUAD.
The fix is to check if the drawCounter has more then 1 and copy the previous mode to the new Draw.
No Need to change the order of rlSetTexture and rlBegin for it to work.

Removed vertexCount and textureId set from rlBegin as it is already set for every draw.

        RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0;
        RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId;

Initializer: https://github.com/maiconpintoabreu/raylib/blob/8d1add31d92da6f8704426f5bcb6c307e4e9cd85/src/rlgl.h#L2848
https://github.com/maiconpintoabreu/raylib/blob/8d1add31d92da6f8704426f5bcb6c307e4e9cd85/src/rlgl.h#L3124

Fix for the issue: #5142

RenderDoc Test:

BunnyMark:

image

Test Case

image image

            DrawText("textured polygon", 20, 20, 20, DARKGRAY);

            DrawCircleV(ballPosition, (float)ballRadius, MAROON);
            
            for (int i = 0; i < 4100; i++) {
                DrawTexture(textureLogo, screenWidth/2 - texture.width/4, screenHeight/3 - texture.height/2, WHITE);
                
            }
            DrawTexture(textureLogo, screenWidth/2 - texture.width, screenHeight/3 - texture.height/2, WHITE);

            for (int i = 0; i < 800; i++) {
                DrawTexturePoly(texture, (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f },
                                positions, texcoords, MAX_POINTS, WHITE);

                DrawTexturePoly(texture, (Vector2){ GetScreenWidth()/1.5f, GetScreenHeight()/2.0f },
                                positions, texcoords, MAX_POINTS, WHITE);
            }
            for (int i = 0; i < 5000; i++) {
                DrawTexture(textureLogo, screenWidth/2 - texture.width/4, screenHeight/2, WHITE);
            }

            for (int i = 0; i < bunniesCount; i++)
            {
                // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
                // a draw call is launched and buffer starts being filled again;
                // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
                // Process of sending data is costly and it could happen that GPU data has not been completely
                // processed for drawing while new data is tried to be sent (updating current in-use buffers)
                // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies
                DrawTexture(texBunny, (int)bunnies[i].position.x, (int)bunnies[i].position.y, bunnies[i].color);
            }

            DrawLine(0,screenHeight/2,screenWidth,screenHeight/2, BLACK);
            
            DrawTexture(textureLogo, screenWidth/2 - texture.width, screenHeight/2, WHITE);

            DrawRectangle(0, 0, screenWidth, 40, BLACK);
            DrawText(TextFormat("bunnies: %i", bunniesCount), 120, 10, 20, GREEN);
            DrawText(TextFormat("batched draw calls: %i", 1 + bunniesCount/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON);

OpenGL Versions Test:
GRAPHICS_API_OPENGL_33 = Working
GRAPHICS_API_OPENGL_11 = Working
GRAPHICS_API_OPENGL_21 = Working
GRAPHICS_API_OPENGL_43 = Working
GRAPHICS_API_OPENGL_ES2 = Working

@maiconpintoabreu maiconpintoabreu force-pushed the second-try-fix-multimode branch 3 times, most recently from 0e618cb to 3b57089 Compare September 22, 2025 09:42
@maiconpintoabreu maiconpintoabreu marked this pull request as ready for review September 22, 2025 09:43
@maiconpintoabreu
Copy link
Contributor Author

maiconpintoabreu commented Sep 22, 2025

Shapes Colors Palette

image

Shapes Ring Drawing:

image

Shapes Lines Bezier:

image

Core 3d camera split

image

#5142 Code Sample

image

Jeff's Sample (2 squares and 2 triangles)

image

@maiconpintoabreu
Copy link
Contributor Author

Did some cleaning on the commits and the extra draw was a commit pollution.

@raysan5
Copy link
Owner

raysan5 commented Sep 23, 2025

@maiconpintoabreu Thank you very much again for reviewing this issue and all the time put into, also the wide testing for multiple examples and configurations.

Checking the code, it looks good to me and really elegant solution. Let me know if there is some more testing left before merging.

@maiconpintoabreu
Copy link
Contributor Author

Thanks @raysan5, I am happy to help remove this limitation, about the tests, I think I did all the cases that I thought of.

@raysan5 raysan5 merged commit 2554dcb into raysan5:master Sep 24, 2025
16 checks passed
@raysan5
Copy link
Owner

raysan5 commented Sep 24, 2025

@maiconpintoabreu thanks for the improvement!

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