Skip to content
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
2 changes: 2 additions & 0 deletions src/rlgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,8 @@ void rlSetTexture(unsigned int id)
RLGL.State.vertexCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment;

RLGL.currentBatch->drawCounter++;

RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 2].mode;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/rmodels.c
Original file line number Diff line number Diff line change
Expand Up @@ -3939,8 +3939,13 @@ void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector
texcoords[2] = (Vector2){ (float)(source.x + source.width)/texture.width, (float)source.y/texture.height };
texcoords[3] = (Vector2){ (float)source.x/texture.width, (float)source.y/texture.height };

#if defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(texture.id);
rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(texture.id);
#endif

rlColor4ub(tint.r, tint.g, tint.b, tint.a);
for (int i = 0; i < 4; i++)
Expand Down
89 changes: 83 additions & 6 deletions src/rshapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,16 @@ void DrawPixel(int posX, int posY, Color color)
void DrawPixelV(Vector2 position, Color color)
{
#if defined(SUPPORT_QUADS_DRAW_MODE)
#if defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

rlNormal3f(0.0f, 0.0f, 1.0f);
rlColor4ub(color.r, color.g, color.b, color.a);
Expand Down Expand Up @@ -311,10 +317,16 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA
float angle = startAngle;

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

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

// NOTE: Every QUAD actually represents two segments
for (int i = 0; i < segments/2; i++)
Expand Down Expand Up @@ -552,10 +564,17 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startA
float angle = startAngle;

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

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

for (int i = 0; i < segments; i++)
{
rlColor4ub(color.r, color.g, color.b, color.a);
Expand Down Expand Up @@ -732,10 +751,17 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color
}

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

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif


rlNormal3f(0.0f, 0.0f, 1.0f);
rlColor4ub(color.r, color.g, color.b, color.a);
Expand Down Expand Up @@ -787,10 +813,18 @@ void DrawRectangleGradientH(int posX, int posY, int width, int height, Color lef
// Draw a gradient-filled rectangle
void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Color bottomRight, Color topRight)
{

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

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

rlNormal3f(0.0f, 0.0f, 1.0f);

// NOTE: Default raylib font character 95 is a white square
Expand Down Expand Up @@ -952,10 +986,17 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co
const float angles[4] = { 180.0f, 270.0f, 0.0f, 90.0f };

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

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

// Draw all the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner
for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop
{
Expand Down Expand Up @@ -1206,10 +1247,17 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f
if (lineThick > 1)
{
#if defined(SUPPORT_QUADS_DRAW_MODE)
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#if defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

rlBegin(RL_QUADS);

// Draw all the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner
for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop
Expand Down Expand Up @@ -1382,10 +1430,17 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f
void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
{
#if defined(SUPPORT_QUADS_DRAW_MODE)
#if defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

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

rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height);
Expand Down Expand Up @@ -1436,10 +1491,18 @@ void DrawTriangleFan(const Vector2 *points, int pointCount, Color color)
{
if (pointCount >= 3)
{
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();

rlBegin(RL_QUADS);
#if defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

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

for (int i = 1; i < pointCount - 1; i++)
Expand Down Expand Up @@ -1497,10 +1560,17 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col
float angleStep = 360.0f/(float)sides*DEG2RAD;

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

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

for (int i = 0; i < sides; i++)
{
rlColor4ub(color.r, color.g, color.b, color.a);
Expand Down Expand Up @@ -1566,10 +1636,17 @@ void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, fl
float innerRadius = radius - (lineThick*cosf(DEG2RAD*exteriorAngle/2.0f));

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

rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(GetShapesTexture().id);
Rectangle shapeRect = GetShapesTextureRectangle();
#endif

for (int i = 0; i < sides; i++)
{
rlColor4ub(color.r, color.g, color.b, color.a);
Expand Down
19 changes: 17 additions & 2 deletions src/rtextures.c
Original file line number Diff line number Diff line change
Expand Up @@ -4568,8 +4568,13 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2
bottomRight.y = y + (dx + dest.width)*sinRotation + (dy + dest.height)*cosRotation;
}

#if defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(texture.id);
rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(texture.id);
#endif

rlColor4ub(tint.r, tint.g, tint.b, tint.a);
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
Expand Down Expand Up @@ -4603,13 +4608,18 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2
// 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);
rlTranslatef(-origin.x, -origin.y, 0.0f);

#if defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(texture.id);
rlBegin(RL_QUADS);
#else
rlBegin(RL_QUADS);
rlSetTexture(texture.id);
#endif
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer

Expand Down Expand Up @@ -4698,14 +4708,19 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest,
coordD.x = (nPatchInfo.source.x + nPatchInfo.source.width)/width;
coordD.y = (nPatchInfo.source.y + nPatchInfo.source.height)/height;

rlSetTexture(texture.id);
#if defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(texture.id);
#endif

rlPushMatrix();
rlTranslatef(dest.x, dest.y, 0.0f);
rlRotatef(rotation, 0.0f, 0.0f, 1.0f);
rlTranslatef(-origin.x, -origin.y, 0.0f);

rlBegin(RL_QUADS);
#if !defined(GRAPHICS_API_OPENGL_11)
rlSetTexture(texture.id);
#endif
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer

Expand Down
Loading