Skip to content

Commit ecaa1d3

Browse files
committed
REVIEWED: Attribute name and location, for consistency
1 parent ad82393 commit ecaa1d3

3 files changed

Lines changed: 34 additions & 38 deletions

File tree

src/rcore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
13051305
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
13061306
shader.locs[SHADER_LOC_VERTEX_BONEIDS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEINDICES);
13071307
shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS);
1308-
shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORMS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORMS);
1308+
shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORM] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORM);
13091309

13101310
// Get handles to GLSL uniform locations (vertex shader)
13111311
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);

src/rlgl.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,14 @@
345345
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES
346346
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES 6
347347
#endif
348-
#ifdef SUPPORT_GPU_SKINNING
349-
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEINDICES
350-
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEINDICES 7
351-
#endif
352-
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS
353-
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
354-
#endif
348+
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEINDICES
349+
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEINDICES 7
350+
#endif
351+
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS
352+
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
355353
#endif
356-
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORMS
357-
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORMS 9
354+
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORM
355+
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORM 9
358356
#endif
359357

360358
//----------------------------------------------------------------------------------
@@ -1018,8 +1016,8 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
10181016
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_BONEMATRICES
10191017
#define RL_DEFAULT_SHADER_UNIFORM_NAME_BONEMATRICES "boneMatrices" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEMATRICES
10201018
#endif
1021-
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORMS
1022-
#define RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORMS "instanceTransform" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORMS
1019+
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORM
1020+
#define RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORM "instanceTransform" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORM
10231021
#endif
10241022

10251023
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP
@@ -4335,20 +4333,18 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
43354333
glAttachShader(programId, vShaderId);
43364334
glAttachShader(programId, fShaderId);
43374335

4338-
// NOTE: Default attribute shader locations must be Bound before linking
4336+
// Default attribute shader locations must be bound before linking
4337+
// NOTE: There is no problem with binding a generic attribute index to an attribute variable name
4338+
// that is never used; if some attrib name is no found on the shader, it locations becomes -1
43394339
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
43404340
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
43414341
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
43424342
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
43434343
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
43444344
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
4345-
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORMS, RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORMS);
4346-
#ifdef SUPPORT_GPU_SKINNING
4345+
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCETRANSFORM, RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCETRANSFORM);
43474346
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEINDICES, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEINDICES);
43484347
glBindAttribLocation(programId, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS);
4349-
#endif
4350-
4351-
// NOTE: If some attrib name is no found on the shader, it locations becomes -1
43524348

43534349
glLinkProgram(programId);
43544350

src/rmodels.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
16881688
{
16891689
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
16901690
// Instancing required variables
1691-
float16 *instanceTransforms = NULL;
1691+
float16 *instanceTransform = NULL;
16921692
unsigned int instancesVboId = 0;
16931693

16941694
// Bind shader program
@@ -1737,10 +1737,10 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
17371737
if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], matProjection);
17381738

17391739
// Create instances buffer
1740-
instanceTransforms = (float16 *)RL_CALLOC(instances, sizeof(float16));
1740+
instanceTransform = (float16 *)RL_CALLOC(instances, sizeof(float16));
17411741

17421742
// Fill buffer with instances transformations as float16 arrays
1743-
for (int i = 0; i < instances; i++) instanceTransforms[i] = MatrixToFloatV(transforms[i]);
1743+
for (int i = 0; i < instances; i++) instanceTransform[i] = MatrixToFloatV(transforms[i]);
17441744

17451745
// Enable mesh VAO to attach new buffer
17461746
rlEnableVertexArray(mesh.vaoId);
@@ -1749,16 +1749,16 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
17491749
// It isn't clear which would be reliably faster in all cases and on all platforms,
17501750
// anecdotally glMapBuffer() seems very slow (syncs) while glBufferSubData() seems
17511751
// no faster, since all the transform matrices are transferred anyway
1752-
instancesVboId = rlLoadVertexBuffer(instanceTransforms, instances*sizeof(float16), false);
1752+
instancesVboId = rlLoadVertexBuffer(instanceTransform, instances*sizeof(float16), false);
17531753

1754-
// Instances transformation matrices are sent to shader attribute location: SHADER_LOC_VERTEX_INSTANCETRANSFORMS
1755-
if (material.shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORMS] != -1)
1754+
// Instances transformation matrices are sent to shader attribute location: SHADER_LOC_VERTEX_INSTANCETRANSFORM
1755+
if (material.shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORM] != -1)
17561756
{
17571757
for (unsigned int i = 0; i < 4; i++)
17581758
{
1759-
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORMS] + i);
1760-
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORMS] + i, 4, RL_FLOAT, 0, sizeof(Matrix), i*sizeof(Vector4));
1761-
rlSetVertexAttributeDivisor(material.shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORMS] + i, 1);
1759+
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORM] + i);
1760+
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORM] + i, 4, RL_FLOAT, 0, sizeof(Matrix), i*sizeof(Vector4));
1761+
rlSetVertexAttributeDivisor(material.shader.locs[SHADER_LOC_VERTEX_INSTANCETRANSFORM] + i, 1);
17621762
}
17631763
}
17641764

@@ -1918,7 +1918,7 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
19181918

19191919
// Remove instance transforms buffer
19201920
rlUnloadVertexBuffer(instancesVboId);
1921-
RL_FREE(instanceTransforms);
1921+
RL_FREE(instanceTransform);
19221922
#endif
19231923
}
19241924

@@ -4404,11 +4404,10 @@ static void BuildPoseFromParentJoints(BoneInfo *bones, int boneCount, Transform
44044404

44054405
#if defined(SUPPORT_FILEFORMAT_OBJ)
44064406
// Load OBJ mesh data
4407-
//
4408-
// Keep the following information in mind when reading this
4407+
// Notes to keep in mind:
44094408
// - A mesh is created for every material present in the obj file
4410-
// - the model.meshCount is therefore the materialCount returned from tinyobj
4411-
// - the mesh is automatically triangulated by tinyobj
4409+
// - The model.meshCount is therefore the materialCount returned from tinyobj
4410+
// - The mesh is automatically triangulated by tinyobj
44124411
static Model LoadOBJ(const char *fileName)
44134412
{
44144413
tinyobj_attrib_t objAttributes = { 0 };
@@ -4555,7 +4554,8 @@ static Model LoadOBJ(const char *fileName)
45554554
model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
45564555
model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4);
45574556
#else
4558-
if (objAttributes.texcoords != NULL && objAttributes.num_texcoords > 0) model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
4557+
if (objAttributes.texcoords != NULL && objAttributes.num_texcoords > 0)
4558+
model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
45594559
else model.meshes[i].texcoords = NULL;
45604560
model.meshes[i].colors = NULL;
45614561
#endif
@@ -4657,12 +4657,12 @@ static Model LoadOBJ(const char *fileName)
46574657
// Load IQM mesh data
46584658
static Model LoadIQM(const char *fileName)
46594659
{
4660-
#define IQM_MAGIC "INTERQUAKEMODEL" // IQM file magic number
4661-
#define IQM_VERSION 2 // only IQM version 2 supported
4660+
#define IQM_MAGIC "INTERQUAKEMODEL" // IQM file magic number
4661+
#define IQM_VERSION 2 // Only IQM version 2 supported
46624662

4663-
#define BONE_NAME_LENGTH 32 // BoneInfo name string length
4664-
#define MESH_NAME_LENGTH 32 // Mesh name string length
4665-
#define MATERIAL_NAME_LENGTH 32 // Material name string length
4663+
#define BONE_NAME_LENGTH 32 // BoneInfo name string length
4664+
#define MESH_NAME_LENGTH 32 // Mesh name string length
4665+
#define MATERIAL_NAME_LENGTH 32 // Material name string length
46664666

46674667
int dataSize = 0;
46684668
unsigned char *fileData = LoadFileData(fileName, &dataSize);

0 commit comments

Comments
 (0)