Skip to content

Commit 735ba4e

Browse files
Add support for GL_POINTS
1 parent 1e74aba commit 735ba4e

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/rlgl.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
#define RL_TEXTURE 0x1702 // GL_TEXTURE
265265

266266
// Primitive assembly draw modes
267+
#define RL_POINTS 0x0000 // GL_POINTS
267268
#define RL_LINES 0x0001 // GL_LINES
268269
#define RL_TRIANGLES 0x0004 // GL_TRIANGLES
269270
#define RL_QUADS 0x0007 // GL_QUADS
@@ -1455,6 +1456,7 @@ void rlBegin(int mode)
14551456
{
14561457
switch (mode)
14571458
{
1459+
case RL_POINTS: glBegin(GL_POINTS); break;
14581460
case RL_LINES: glBegin(GL_LINES); break;
14591461
case RL_TRIANGLES: glBegin(GL_TRIANGLES); break;
14601462
case RL_QUADS: glBegin(GL_QUADS); break;
@@ -1487,7 +1489,8 @@ void rlBegin(int mode)
14871489
// It implies adding some extra alignment vertex at the end of the draw,
14881490
// those vertex are not processed but they are considered as an additional offset
14891491
// for the next set of vertex to be drawn
1490-
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4);
1492+
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_POINTS) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount & 3)) & 3;
1493+
else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4);
14911494
else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4)));
14921495
else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = 0;
14931496

@@ -1536,7 +1539,15 @@ void rlVertex3f(float x, float y, float z)
15361539
// Checking current draw.mode when a new vertex is required and finish the batch only if the draw.mode draw.vertexCount is %2, %3 or %4
15371540
if (RLGL.State.vertexCounter > (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4 - 4))
15381541
{
1539-
if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) &&
1542+
if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_POINTS) &&
1543+
(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount != 0))
1544+
{
1545+
// Reached the maximum number of vertices for RL_POINTS drawing
1546+
// Launch a draw call but keep current state for next vertices comming
1547+
// NOTE: Adding +1 vertex to the check for some safety
1548+
rlCheckRenderBatchLimit(1 + 1);
1549+
}
1550+
else if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) &&
15401551
(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%2 == 0))
15411552
{
15421553
// Reached the maximum number of vertices for RL_LINES drawing
@@ -1685,7 +1696,8 @@ void rlSetTexture(unsigned int id)
16851696
// It implies adding some extra alignment vertex at the end of the draw,
16861697
// those vertex are not processed but they are considered as an additional offset
16871698
// for the next set of vertex to be drawn
1688-
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4);
1699+
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_POINTS) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount & 3)) & 3;
1700+
else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4);
16891701
else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4)));
16901702
else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = 0;
16911703

@@ -3131,7 +3143,7 @@ void rlDrawRenderBatch(rlRenderBatch *batch)
31313143
// Bind current draw call texture, activated as GL_TEXTURE0 and bound to sampler2D texture0 by default
31323144
glBindTexture(GL_TEXTURE_2D, batch->draws[i].textureId);
31333145

3134-
if ((batch->draws[i].mode == RL_LINES) || (batch->draws[i].mode == RL_TRIANGLES)) glDrawArrays(batch->draws[i].mode, vertexOffset, batch->draws[i].vertexCount);
3146+
if ((batch->draws[i].mode == RL_POINTS) || (batch->draws[i].mode == RL_LINES) || (batch->draws[i].mode == RL_TRIANGLES)) glDrawArrays(batch->draws[i].mode, vertexOffset, batch->draws[i].vertexCount);
31353147
else
31363148
{
31373149
#if defined(GRAPHICS_API_OPENGL_33)

src/rmodels.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,13 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color)
189189
rlEnd();
190190
}
191191

192-
// Draw a point in 3D space, actually a small line
193-
// WARNING: OpenGL ES 2.0 does not support point mode drawing
192+
// Draw a point in 3D space
194193
void DrawPoint3D(Vector3 position, Color color)
195194
{
196-
rlPushMatrix();
197-
rlTranslatef(position.x, position.y, position.z);
198-
rlBegin(RL_LINES);
199-
rlColor4ub(color.r, color.g, color.b, color.a);
200-
rlVertex3f(0.0f, 0.0f, 0.0f);
201-
rlVertex3f(0.0f, 0.0f, 0.1f);
202-
rlEnd();
203-
rlPopMatrix();
195+
rlBegin(RL_POINTS);
196+
rlColor4ub(color.r, color.g, color.b, color.a);
197+
rlVertex3f(position.x, position.y, position.z);
198+
rlEnd();
204199
}
205200

206201
// Draw a circle in 3D world space

0 commit comments

Comments
 (0)