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] Preserve texture on mode switching #4364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 1 addition & 5 deletions examples/textures/textures_polygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2
{
rlSetTexture(texture.id);

// Texturing is only supported on RL_QUADS
rlBegin(RL_QUADS);
rlBegin(RL_TRIANGLES);

rlColor4ub(tint.r, tint.g, tint.b, tint.a);

Expand All @@ -130,9 +129,6 @@ void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2

rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y);
rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y);

rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y);
rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y);
}
rlEnd();

Expand Down
4 changes: 3 additions & 1 deletion src/rlgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,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 @@ -1472,13 +1473,14 @@ 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;
}
}

// Finish vertex providing
void rlEnd(void)
{
rlSetTexture(RLGL.State.defaultTextureId);
// NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
// as well as depth buffer bit-depth (16bit or 24bit or 32bit)
// Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
Expand Down