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

[rlgl] [rshapes] [rtextures] Fixes for disabled SUPPORT_QUADS_DRAW_MODE #4296

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/rlgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ void rlBegin(int mode)
// NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode != mode)
{
int currentTexture = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId;
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0)
{
// Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
Expand All @@ -1450,7 +1451,7 @@ void rlBegin(int mode)

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

Expand Down
17 changes: 14 additions & 3 deletions src/rshapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,10 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color
bottomRight.y = y + (dx + rec.width)*sinRotation + (dy + rec.height)*cosRotation;
}

#if defined(SUPPORT_QUADS_DRAW_MODE)
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();

#if defined(SUPPORT_QUADS_DRAW_MODE)
rlBegin(RL_QUADS);

rlNormal3f(0.0f, 0.0f, 1.0f);
Expand All @@ -740,23 +740,34 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color
rlVertex2f(topRight.x, topRight.y);

rlEnd();

rlSetTexture(0);
#else
rlBegin(RL_TRIANGLES);

rlNormal3f(0.0f, 0.0f, 1.0f);
rlColor4ub(color.r, color.g, color.b, color.a);

rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height);
rlVertex2f(topLeft.x, topLeft.y);

rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height);
rlVertex2f(bottomLeft.x, bottomLeft.y);

rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height);
rlVertex2f(topRight.x, topRight.y);

rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height);
rlVertex2f(topRight.x, topRight.y);

rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height);
rlVertex2f(bottomLeft.x, bottomLeft.y);

rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height);
rlVertex2f(bottomRight.x, bottomRight.y);

rlEnd();
#endif

rlSetTexture(0);
}

// Draw a vertical-gradient-filled rectangle
Expand Down
44 changes: 41 additions & 3 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -4604,6 +4604,7 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2
}

rlSetTexture(texture.id);
#if defined(SUPPORT_QUADS_DRAW_MODE)
rlBegin(RL_QUADS);

rlColor4ub(tint.r, tint.g, tint.b, tint.a);
Expand All @@ -4630,15 +4631,13 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2
rlVertex2f(topRight.x, topRight.y);

rlEnd();
rlSetTexture(0);

// NOTE: Vertex position can be transformed using matrices
// but the process is way more costly than just calculating
// the vertex positions manually, like done above
// I leave here the old implementation for educational purposes,
// just in case someone wants to do some performance test
/*
rlSetTexture(texture.id);
rlPushMatrix();
rlTranslatef(dest.x, dest.y, 0.0f);
if (rotation != 0.0f) rlRotatef(rotation, 0.0f, 0.0f, 1.0f);
Expand Down Expand Up @@ -4669,8 +4668,47 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2
rlVertex2f(dest.width, 0.0f);
rlEnd();
rlPopMatrix();
rlSetTexture(0);
*/

#else
rlBegin(RL_TRIANGLES);

rlColor4ub(tint.r, tint.g, tint.b, tint.a);
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer

// Top-left corner for texture
if (flipX) rlTexCoord2f((source.x + source.width)/width, source.y/height);
else rlTexCoord2f(source.x/width, source.y/height);
rlVertex2f(topLeft.x, topLeft.y);

// Bottom-left corner for texture
if (flipX) rlTexCoord2f((source.x + source.width)/width, (source.y + source.height)/height);
else rlTexCoord2f(source.x/width, (source.y + source.height)/height);
rlVertex2f(bottomLeft.x, bottomLeft.y);

// Bottom-right corner for texture
if (flipX) rlTexCoord2f(source.x/width, (source.y + source.height)/height);
else rlTexCoord2f((source.x + source.width)/width, (source.y + source.height)/height);
rlVertex2f(bottomRight.x, bottomRight.y);

// Top-left corner for texture
if (flipX) rlTexCoord2f((source.x + source.width)/width, source.y/height);
else rlTexCoord2f(source.x/width, source.y/height);
rlVertex2f(topLeft.x, topLeft.y);

// Bottom-right corner for texture
if (flipX) rlTexCoord2f(source.x/width, (source.y + source.height)/height);
else rlTexCoord2f((source.x + source.width)/width, (source.y + source.height)/height);
rlVertex2f(bottomRight.x, bottomRight.y);

// Top-right corner for texture
if (flipX) rlTexCoord2f(source.x/width, source.y/height);
else rlTexCoord2f((source.x + source.width)/width, source.y/height);
rlVertex2f(topRight.x, topRight.y);

rlEnd();
#endif
rlSetTexture(0);
}
}

Expand Down