Skip to content

Commit 2554dcb

Browse files
fix rlSetTexture not overriding default mode (#5200)
1 parent 4f9b933 commit 2554dcb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/rlgl.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ typedef struct rlglData {
10671067
Matrix stack[RL_MAX_MATRIX_STACK_SIZE];// Matrix stack for push/pop
10681068
int stackCounter; // Matrix stack counter
10691069

1070+
unsigned int currentTextureId; // Current texture id to be used on glBegin
10701071
unsigned int defaultTextureId; // Default texture used on shapes/poly drawing (required by shader)
10711072
unsigned int activeTextureId[RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS]; // Active texture ids to be enabled on batch drawing (0 active by default)
10721073
unsigned int defaultVShaderId; // Default vertex shader id (used by default shader program)
@@ -1485,8 +1486,8 @@ void rlBegin(int mode)
14851486
if (RLGL.currentBatch->drawCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch);
14861487

14871488
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = mode;
1488-
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0;
1489-
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId;
1489+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.currentTextureId;
1490+
RLGL.State.currentTextureId = RLGL.State.defaultTextureId;
14901491
}
14911492
}
14921493

@@ -1651,13 +1652,15 @@ void rlSetTexture(unsigned int id)
16511652
{
16521653
rlDrawRenderBatch(RLGL.currentBatch);
16531654
}
1655+
RLGL.State.currentTextureId = RLGL.State.defaultTextureId;
16541656
#endif
16551657
}
16561658
else
16571659
{
16581660
#if defined(GRAPHICS_API_OPENGL_11)
16591661
rlEnableTexture(id);
16601662
#else
1663+
RLGL.State.currentTextureId = id;
16611664
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId != id)
16621665
{
16631666
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0)
@@ -1676,6 +1679,9 @@ void rlSetTexture(unsigned int id)
16761679
RLGL.State.vertexCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment;
16771680

16781681
RLGL.currentBatch->drawCounter++;
1682+
1683+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 2].mode;
1684+
16791685
}
16801686
}
16811687

@@ -2257,6 +2263,7 @@ void rlglInit(int width, int height)
22572263
// Init default white texture
22582264
unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
22592265
RLGL.State.defaultTextureId = rlLoadTexture(pixels, 1, 1, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
2266+
RLGL.State.currentTextureId = RLGL.State.defaultTextureId;
22602267

22612268
if (RLGL.State.defaultTextureId != 0) TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Default texture loaded successfully", RLGL.State.defaultTextureId);
22622269
else TRACELOG(RL_LOG_WARNING, "TEXTURE: Failed to load default texture");

0 commit comments

Comments
 (0)