Skip to content

Commit a76f747

Browse files
meisei4psxdev
authored andcommitted
[rlgl] Allow tint colors in GL_LINE (wires) and GL_POINT (points) draw modes on OpenGL 1.1 clean (raysan5#5207)
* gate with OPENGL_11 prototype and definition for rlSetPointSize and rlGetPointSize * gate with OPENGL_11 prototype and definition for rlSetPointSize and rlGetPointSize * more coverage for fixing expected texcoords, normals, and colors * fix guard styling * fix guard issue, and remove fallback unneccessary else clause (default shader ill work) * opengl3.3 and es2 need the color array allocated in order to allow for updates later (unlike opengl11)
1 parent 2f14b1d commit a76f747

2 files changed

Lines changed: 59 additions & 15 deletions

File tree

src/rlgl.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,8 @@ RLAPI void rlEnableVertexBufferElement(unsigned int id); // Enable vertex buffer
652652
RLAPI void rlDisableVertexBufferElement(void); // Disable vertex buffer element (VBO element)
653653
RLAPI void rlEnableVertexAttribute(unsigned int index); // Enable vertex attribute index
654654
RLAPI void rlDisableVertexAttribute(unsigned int index); // Disable vertex attribute index
655-
#if defined(GRAPHICS_API_OPENGL_11)
656655
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
657656
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
658-
#endif
659657

660658
// Textures state
661659
RLAPI void rlActiveTextureSlot(int slot); // Select and active a texture slot
@@ -694,6 +692,8 @@ RLAPI void rlDisableScissorTest(void); // Disable scissor test
694692
RLAPI void rlScissor(int x, int y, int width, int height); // Scissor test
695693
RLAPI void rlEnablePointMode(void); // Enable point mode
696694
RLAPI void rlDisablePointMode(void); // Disable point mode
695+
RLAPI void rlSetPointSize(float size); // Set the point drawing size
696+
RLAPI float rlGetPointSize(void); // Get the point drawing size
697697
RLAPI void rlEnableWireMode(void); // Enable wire mode
698698
RLAPI void rlDisableWireMode(void); // Disable wire mode
699699
RLAPI void rlSetLineWidth(float width); // Set the line drawing width
@@ -2038,6 +2038,25 @@ float rlGetLineWidth(void)
20382038
return width;
20392039
}
20402040

2041+
// Set the point drawing size
2042+
void rlSetPointSize(float size)
2043+
{
2044+
#if defined(GRAPHICS_API_OPENGL_11)
2045+
glPointSize(size);
2046+
#endif
2047+
}
2048+
2049+
// Get the point drawing size
2050+
float rlGetPointSize(void)
2051+
{
2052+
float size = 1;
2053+
#if defined(GRAPHICS_API_OPENGL_11)
2054+
glGetFloatv(GL_POINT_SIZE, &size);
2055+
#endif
2056+
return size;
2057+
2058+
}
2059+
20412060
// Enable line aliasing
20422061
void rlEnableSmoothLines(void)
20432062
{
@@ -4090,10 +4109,10 @@ void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffe
40904109
#endif
40914110
}
40924111

4093-
#if defined(GRAPHICS_API_OPENGL_11)
40944112
// Enable vertex state pointer
40954113
void rlEnableStatePointer(int vertexAttribType, void *buffer)
40964114
{
4115+
#if defined(GRAPHICS_API_OPENGL_11)
40974116
if (buffer != NULL) glEnableClientState(vertexAttribType);
40984117
switch (vertexAttribType)
40994118
{
@@ -4104,14 +4123,16 @@ void rlEnableStatePointer(int vertexAttribType, void *buffer)
41044123
//case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
41054124
default: break;
41064125
}
4126+
#endif
41074127
}
41084128

41094129
// Disable vertex state pointer
41104130
void rlDisableStatePointer(int vertexAttribType)
41114131
{
4132+
#if defined(GRAPHICS_API_OPENGL_11)
41124133
glDisableClientState(vertexAttribType);
4113-
}
41144134
#endif
4135+
}
41154136

41164137
// Load vertex array object (VAO)
41174138
unsigned int rlLoadVertexArray(void)

src/rmodels.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,10 +1337,19 @@ void UploadMesh(Mesh *mesh, bool dynamic)
13371337
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
13381338

13391339
// Enable vertex attributes: texcoords (shader-location = 1)
1340-
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD] = rlLoadVertexBuffer(mesh->texcoords, mesh->vertexCount*2*sizeof(float), dynamic);
1341-
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, RL_FLOAT, 0, 0, 0);
1342-
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
13431340

1341+
if (mesh->texcoords != NULL)
1342+
{
1343+
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD] = rlLoadVertexBuffer(mesh->texcoords, mesh->vertexCount*2*sizeof(float), dynamic);
1344+
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, RL_FLOAT, 0, 0, 0);
1345+
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
1346+
}
1347+
else
1348+
{
1349+
float value[2] = { 0.0f, 0.0f };
1350+
rlSetVertexAttributeDefault(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, value, SHADER_ATTRIB_VEC2, 2);
1351+
rlDisableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
1352+
}
13441353
// WARNING: When setting default vertex attribute values, the values for each generic vertex attribute
13451354
// is part of current state, and it is maintained even if a different program object is used
13461355
#if !defined(PLATFORM_VITA)
@@ -1474,11 +1483,12 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
14741483
if (mesh.animVertices) rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.animVertices);
14751484
else rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.vertices);
14761485

1477-
rlEnableStatePointer(GL_TEXTURE_COORD_ARRAY, mesh.texcoords);
1486+
if (mesh.texcoords) rlEnableStatePointer(GL_TEXTURE_COORD_ARRAY, mesh.texcoords);
14781487

14791488
if (mesh.animNormals) rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.animNormals);
1480-
else rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.normals);
1481-
rlEnableStatePointer(GL_COLOR_ARRAY, mesh.colors);
1489+
else if (mesh.normals) rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.normals);
1490+
1491+
if (mesh.colors) rlEnableStatePointer(GL_COLOR_ARRAY, mesh.colors);
14821492

14831493
rlPushMatrix();
14841494
rlMultMatrixf(MatrixToFloat(transform));
@@ -3887,6 +3897,7 @@ void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float
38873897

38883898
// Draw a model points
38893899
// WARNING: OpenGL ES 2.0 does not support point mode drawing
3900+
// TODO: gate these properly for non es 2.0 versions only
38903901
void DrawModelPoints(Model model, Vector3 position, float scale, Color tint)
38913902
{
38923903
rlEnablePointMode();
@@ -4475,7 +4486,11 @@ static Model LoadOBJ(const char *fileName)
44754486
model.meshes[i].vertices = (float *)MemAlloc(sizeof(float)*vertexCount*3);
44764487
model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3);
44774488
model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
4489+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
44784490
model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4);
4491+
#else
4492+
model.meshes[i].colors = NULL;
4493+
#endif
44794494
}
44804495

44814496
MemFree(localMeshVertexCounts);
@@ -4529,7 +4544,17 @@ static Model LoadOBJ(const char *fileName)
45294544

45304545
for (int i = 0; i < 3; i++) model.meshes[meshIndex].vertices[localMeshVertexCount*3 + i] = objAttributes.vertices[vertIndex*3 + i];
45314546

4532-
for (int i = 0; i < 2; i++) model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + i] = objAttributes.texcoords[texcordIndex*2 + i];
4547+
if (objAttributes.texcoords != NULL && texcordIndex != TINYOBJ_INVALID_INDEX && texcordIndex >= 0)
4548+
{
4549+
for (int i = 0; i < 2; i++) model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + i] = objAttributes.texcoords[texcordIndex*2 + i];
4550+
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1];
4551+
}
4552+
else
4553+
{
4554+
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 0] = 0.0f;
4555+
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 0.0f;
4556+
}
4557+
45334558
if (objAttributes.normals != NULL && normalIndex != TINYOBJ_INVALID_INDEX && normalIndex >= 0)
45344559
{
45354560
for (int i = 0; i < 3; i++) model.meshes[meshIndex].normals[localMeshVertexCount*3 + i] = objAttributes.normals[normalIndex*3 + i];
@@ -4540,11 +4565,9 @@ static Model LoadOBJ(const char *fileName)
45404565
model.meshes[meshIndex].normals[localMeshVertexCount*3 + 1] = 1.0f;
45414566
model.meshes[meshIndex].normals[localMeshVertexCount*3 + 2] = 0.0f;
45424567
}
4543-
4544-
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1];
4545-
4568+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
45464569
for (int i = 0; i < 4; i++) model.meshes[meshIndex].colors[localMeshVertexCount*4 + i] = 255;
4547-
4570+
#endif
45484571
faceVertIndex++;
45494572
localMeshVertexCount++;
45504573
}

0 commit comments

Comments
 (0)