mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-06 09:56:28 +00:00
[rlgl] Allow tint colors in GL_LINE (wires) and GL_POINT (points) draw modes on OpenGL 1.1 clean (#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)
This commit is contained in:
29
src/rlgl.h
29
src/rlgl.h
@@ -644,10 +644,8 @@ RLAPI void rlEnableVertexBufferElement(unsigned int id); // Enable vertex buffer
|
|||||||
RLAPI void rlDisableVertexBufferElement(void); // Disable vertex buffer element (VBO element)
|
RLAPI void rlDisableVertexBufferElement(void); // Disable vertex buffer element (VBO element)
|
||||||
RLAPI void rlEnableVertexAttribute(unsigned int index); // Enable vertex attribute index
|
RLAPI void rlEnableVertexAttribute(unsigned int index); // Enable vertex attribute index
|
||||||
RLAPI void rlDisableVertexAttribute(unsigned int index); // Disable vertex attribute index
|
RLAPI void rlDisableVertexAttribute(unsigned int index); // Disable vertex attribute index
|
||||||
#if defined(GRAPHICS_API_OPENGL_11)
|
|
||||||
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
||||||
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
||||||
#endif
|
|
||||||
|
|
||||||
// Textures state
|
// Textures state
|
||||||
RLAPI void rlActiveTextureSlot(int slot); // Select and active a texture slot
|
RLAPI void rlActiveTextureSlot(int slot); // Select and active a texture slot
|
||||||
@@ -686,6 +684,8 @@ RLAPI void rlDisableScissorTest(void); // Disable scissor test
|
|||||||
RLAPI void rlScissor(int x, int y, int width, int height); // Scissor test
|
RLAPI void rlScissor(int x, int y, int width, int height); // Scissor test
|
||||||
RLAPI void rlEnablePointMode(void); // Enable point mode
|
RLAPI void rlEnablePointMode(void); // Enable point mode
|
||||||
RLAPI void rlDisablePointMode(void); // Disable point mode
|
RLAPI void rlDisablePointMode(void); // Disable point mode
|
||||||
|
RLAPI void rlSetPointSize(float size); // Set the point drawing size
|
||||||
|
RLAPI float rlGetPointSize(void); // Get the point drawing size
|
||||||
RLAPI void rlEnableWireMode(void); // Enable wire mode
|
RLAPI void rlEnableWireMode(void); // Enable wire mode
|
||||||
RLAPI void rlDisableWireMode(void); // Disable wire mode
|
RLAPI void rlDisableWireMode(void); // Disable wire mode
|
||||||
RLAPI void rlSetLineWidth(float width); // Set the line drawing width
|
RLAPI void rlSetLineWidth(float width); // Set the line drawing width
|
||||||
@@ -2016,6 +2016,25 @@ float rlGetLineWidth(void)
|
|||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the point drawing size
|
||||||
|
void rlSetPointSize(float size)
|
||||||
|
{
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_11)
|
||||||
|
glPointSize(size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the point drawing size
|
||||||
|
float rlGetPointSize(void)
|
||||||
|
{
|
||||||
|
float size = 1;
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_11)
|
||||||
|
glGetFloatv(GL_POINT_SIZE, &size);
|
||||||
|
#endif
|
||||||
|
return size;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Enable line aliasing
|
// Enable line aliasing
|
||||||
void rlEnableSmoothLines(void)
|
void rlEnableSmoothLines(void)
|
||||||
{
|
{
|
||||||
@@ -4003,10 +4022,10 @@ void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffe
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11)
|
|
||||||
// Enable vertex state pointer
|
// Enable vertex state pointer
|
||||||
void rlEnableStatePointer(int vertexAttribType, void *buffer)
|
void rlEnableStatePointer(int vertexAttribType, void *buffer)
|
||||||
{
|
{
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_11)
|
||||||
if (buffer != NULL) glEnableClientState(vertexAttribType);
|
if (buffer != NULL) glEnableClientState(vertexAttribType);
|
||||||
switch (vertexAttribType)
|
switch (vertexAttribType)
|
||||||
{
|
{
|
||||||
@@ -4017,14 +4036,16 @@ void rlEnableStatePointer(int vertexAttribType, void *buffer)
|
|||||||
//case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
|
//case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable vertex state pointer
|
// Disable vertex state pointer
|
||||||
void rlDisableStatePointer(int vertexAttribType)
|
void rlDisableStatePointer(int vertexAttribType)
|
||||||
{
|
{
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_11)
|
||||||
glDisableClientState(vertexAttribType);
|
glDisableClientState(vertexAttribType);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Load vertex array object (VAO)
|
// Load vertex array object (VAO)
|
||||||
unsigned int rlLoadVertexArray(void)
|
unsigned int rlLoadVertexArray(void)
|
||||||
|
@@ -1293,10 +1293,19 @@ void UploadMesh(Mesh *mesh, bool dynamic)
|
|||||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
||||||
|
|
||||||
// Enable vertex attributes: texcoords (shader-location = 1)
|
// Enable vertex attributes: texcoords (shader-location = 1)
|
||||||
|
|
||||||
|
if (mesh->texcoords != NULL)
|
||||||
|
{
|
||||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD] = rlLoadVertexBuffer(mesh->texcoords, mesh->vertexCount*2*sizeof(float), dynamic);
|
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD] = rlLoadVertexBuffer(mesh->texcoords, mesh->vertexCount*2*sizeof(float), dynamic);
|
||||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, RL_FLOAT, 0, 0, 0);
|
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, RL_FLOAT, 0, 0, 0);
|
||||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float value[2] = { 0.0f, 0.0f };
|
||||||
|
rlSetVertexAttributeDefault(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, value, SHADER_ATTRIB_VEC2, 2);
|
||||||
|
rlDisableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||||
|
}
|
||||||
// WARNING: When setting default vertex attribute values, the values for each generic vertex attribute
|
// WARNING: When setting default vertex attribute values, the values for each generic vertex attribute
|
||||||
// is part of current state, and it is maintained even if a different program object is used
|
// is part of current state, and it is maintained even if a different program object is used
|
||||||
|
|
||||||
@@ -1431,12 +1440,12 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||||||
if (mesh.animVertices) rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.animVertices);
|
if (mesh.animVertices) rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.animVertices);
|
||||||
else rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.vertices);
|
else rlEnableStatePointer(GL_VERTEX_ARRAY, mesh.vertices);
|
||||||
|
|
||||||
rlEnableStatePointer(GL_TEXTURE_COORD_ARRAY, mesh.texcoords);
|
if (mesh.texcoords) rlEnableStatePointer(GL_TEXTURE_COORD_ARRAY, mesh.texcoords);
|
||||||
|
|
||||||
if (mesh.animNormals) rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.animNormals);
|
if (mesh.animNormals) rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.animNormals);
|
||||||
else rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.normals);
|
else if (mesh.normals) rlEnableStatePointer(GL_NORMAL_ARRAY, mesh.normals);
|
||||||
|
|
||||||
rlEnableStatePointer(GL_COLOR_ARRAY, mesh.colors);
|
if (mesh.colors) rlEnableStatePointer(GL_COLOR_ARRAY, mesh.colors);
|
||||||
|
|
||||||
rlPushMatrix();
|
rlPushMatrix();
|
||||||
rlMultMatrixf(MatrixToFloat(transform));
|
rlMultMatrixf(MatrixToFloat(transform));
|
||||||
@@ -3836,6 +3845,7 @@ void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float
|
|||||||
|
|
||||||
// Draw a model points
|
// Draw a model points
|
||||||
// WARNING: OpenGL ES 2.0 does not support point mode drawing
|
// WARNING: OpenGL ES 2.0 does not support point mode drawing
|
||||||
|
// TODO: gate these properly for non es 2.0 versions only
|
||||||
void DrawModelPoints(Model model, Vector3 position, float scale, Color tint)
|
void DrawModelPoints(Model model, Vector3 position, float scale, Color tint)
|
||||||
{
|
{
|
||||||
rlEnablePointMode();
|
rlEnablePointMode();
|
||||||
@@ -4420,7 +4430,11 @@ static Model LoadOBJ(const char *fileName)
|
|||||||
model.meshes[i].vertices = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
model.meshes[i].vertices = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
||||||
model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
||||||
model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
|
model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4);
|
model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4);
|
||||||
|
#else
|
||||||
|
model.meshes[i].colors = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MemFree(localMeshVertexCounts);
|
MemFree(localMeshVertexCounts);
|
||||||
@@ -4474,7 +4488,17 @@ static Model LoadOBJ(const char *fileName)
|
|||||||
|
|
||||||
for (int i = 0; i < 3; i++) model.meshes[meshIndex].vertices[localMeshVertexCount*3 + i] = objAttributes.vertices[vertIndex*3 + i];
|
for (int i = 0; i < 3; i++) model.meshes[meshIndex].vertices[localMeshVertexCount*3 + i] = objAttributes.vertices[vertIndex*3 + i];
|
||||||
|
|
||||||
|
if (objAttributes.texcoords != NULL && texcordIndex != TINYOBJ_INVALID_INDEX && texcordIndex >= 0)
|
||||||
|
{
|
||||||
for (int i = 0; i < 2; i++) model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + i] = objAttributes.texcoords[texcordIndex*2 + i];
|
for (int i = 0; i < 2; i++) model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + i] = objAttributes.texcoords[texcordIndex*2 + i];
|
||||||
|
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 0] = 0.0f;
|
||||||
|
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
if (objAttributes.normals != NULL && normalIndex != TINYOBJ_INVALID_INDEX && normalIndex >= 0)
|
if (objAttributes.normals != NULL && normalIndex != TINYOBJ_INVALID_INDEX && normalIndex >= 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 3; i++) model.meshes[meshIndex].normals[localMeshVertexCount*3 + i] = objAttributes.normals[normalIndex*3 + i];
|
for (int i = 0; i < 3; i++) model.meshes[meshIndex].normals[localMeshVertexCount*3 + i] = objAttributes.normals[normalIndex*3 + i];
|
||||||
@@ -4485,11 +4509,9 @@ static Model LoadOBJ(const char *fileName)
|
|||||||
model.meshes[meshIndex].normals[localMeshVertexCount*3 + 1] = 1.0f;
|
model.meshes[meshIndex].normals[localMeshVertexCount*3 + 1] = 1.0f;
|
||||||
model.meshes[meshIndex].normals[localMeshVertexCount*3 + 2] = 0.0f;
|
model.meshes[meshIndex].normals[localMeshVertexCount*3 + 2] = 0.0f;
|
||||||
}
|
}
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1];
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) model.meshes[meshIndex].colors[localMeshVertexCount*4 + i] = 255;
|
for (int i = 0; i < 4; i++) model.meshes[meshIndex].colors[localMeshVertexCount*4 + i] = 255;
|
||||||
|
#endif
|
||||||
faceVertIndex++;
|
faceVertIndex++;
|
||||||
localMeshVertexCount++;
|
localMeshVertexCount++;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user