REVIEWED: LoadShader() and default locations
Reviewed locations descriptions
This commit is contained in:
parent
a226e11aac
commit
d4c03b47ec
3 changed files with 64 additions and 101 deletions
61
src/core.c
61
src/core.c
|
@ -2330,55 +2330,14 @@ void UnloadVrStereoConfig(VrStereoConfig config)
|
|||
Shader LoadShader(const char *vsFileName, const char *fsFileName)
|
||||
{
|
||||
Shader shader = { 0 };
|
||||
shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS, sizeof(int));
|
||||
|
||||
// NOTE: All locations must be reseted to -1 (no location)
|
||||
for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1;
|
||||
char *vShaderStr = LoadFileText(vsFileName);
|
||||
char *fShaderStr = LoadFileText(fsFileName);
|
||||
|
||||
char *vShaderStr = NULL;
|
||||
char *fShaderStr = NULL;
|
||||
shader = LoadShaderFromMemory(vShaderStr, fShaderStr);
|
||||
|
||||
if (vsFileName != NULL) vShaderStr = LoadFileText(vsFileName);
|
||||
if (fsFileName != NULL) fShaderStr = LoadFileText(fsFileName);
|
||||
|
||||
shader.id = rlLoadShaderCode(vShaderStr, fShaderStr);
|
||||
|
||||
if (vShaderStr != NULL) UnloadFileText(vShaderStr);
|
||||
if (fShaderStr != NULL) UnloadFileText(fShaderStr);
|
||||
|
||||
// After shader loading, we TRY to set default location names
|
||||
if (shader.id > 0)
|
||||
{
|
||||
// Default shader attrib locations have been fixed before linking:
|
||||
// vertex position location = 0
|
||||
// vertex texcoord location = 1
|
||||
// vertex normal location = 2
|
||||
// vertex color location = 3
|
||||
// vertex tangent location = 4
|
||||
// vertex texcoord2 location = 5
|
||||
|
||||
// NOTE: If any location is not found, loc point becomes -1
|
||||
|
||||
// Get handles to GLSL input attibute locations
|
||||
shader.locs[SHADER_LOC_VERTEX_POSITION] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
||||
shader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
||||
shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
shader.locs[SHADER_LOC_VERTEX_NORMAL] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
shader.locs[SHADER_LOC_VERTEX_TANGENT] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
|
||||
// Get handles to GLSL uniform locations (vertex shader)
|
||||
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, "mvp");
|
||||
shader.locs[SHADER_LOC_MATRIX_VIEW] = rlGetLocationUniform(shader.id, "view");
|
||||
shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, "projection");
|
||||
shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, "matNormal");
|
||||
|
||||
// Get handles to GLSL uniform locations (fragment shader)
|
||||
shader.locs[SHADER_LOC_COLOR_DIFFUSE] = rlGetLocationUniform(shader.id, "colDiffuse");
|
||||
shader.locs[SHADER_LOC_MAP_DIFFUSE] = rlGetLocationUniform(shader.id, "texture0");
|
||||
shader.locs[SHADER_LOC_MAP_SPECULAR] = rlGetLocationUniform(shader.id, "texture1");
|
||||
shader.locs[SHADER_LOC_MAP_NORMAL] = rlGetLocationUniform(shader.id, "texture2");
|
||||
}
|
||||
UnloadFileText(vShaderStr);
|
||||
UnloadFileText(fShaderStr);
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
@ -2389,12 +2348,15 @@ RLAPI Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
|
|||
Shader shader = { 0 };
|
||||
shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS, sizeof(int));
|
||||
|
||||
// NOTE: All locations must be reseted to -1 (no location)
|
||||
for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1;
|
||||
|
||||
shader.id = rlLoadShaderCode(vsCode, fsCode);
|
||||
|
||||
// After shader loading, we TRY to set default location names
|
||||
if (shader.id > 0)
|
||||
{
|
||||
// Default shader attrib locations have been fixed before linking:
|
||||
// Default shader attribute locations have been binded before linking:
|
||||
// vertex position location = 0
|
||||
// vertex texcoord location = 1
|
||||
// vertex normal location = 2
|
||||
|
@ -2416,12 +2378,13 @@ RLAPI Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
|
|||
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, "mvp");
|
||||
shader.locs[SHADER_LOC_MATRIX_VIEW] = rlGetLocationUniform(shader.id, "view");
|
||||
shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, "projection");
|
||||
//shader.locs[SHADER_LOC_MATRIX_MODEL] = rlGetLocationUniform(shader.id, "matModel");
|
||||
shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, "matNormal");
|
||||
|
||||
// Get handles to GLSL uniform locations (fragment shader)
|
||||
shader.locs[SHADER_LOC_COLOR_DIFFUSE] = rlGetLocationUniform(shader.id, "colDiffuse");
|
||||
shader.locs[SHADER_LOC_MAP_DIFFUSE] = rlGetLocationUniform(shader.id, "texture0");
|
||||
shader.locs[SHADER_LOC_MAP_SPECULAR] = rlGetLocationUniform(shader.id, "texture1");
|
||||
shader.locs[SHADER_LOC_MAP_DIFFUSE] = rlGetLocationUniform(shader.id, "texture0"); // SHADER_LOC_MAP_ALBEDO
|
||||
shader.locs[SHADER_LOC_MAP_SPECULAR] = rlGetLocationUniform(shader.id, "texture1"); // SHADER_LOC_MAP_METALNESS
|
||||
shader.locs[SHADER_LOC_MAP_NORMAL] = rlGetLocationUniform(shader.id, "texture2");
|
||||
}
|
||||
|
||||
|
|
52
src/raylib.h
52
src/raylib.h
|
@ -734,32 +734,32 @@ typedef enum {
|
|||
|
||||
// Shader location index
|
||||
typedef enum {
|
||||
SHADER_LOC_VERTEX_POSITION = 0, // Shader location point: position
|
||||
SHADER_LOC_VERTEX_TEXCOORD01, // Shader location point: texcoord01
|
||||
SHADER_LOC_VERTEX_TEXCOORD02, // Shader location point: texcoord02
|
||||
SHADER_LOC_VERTEX_NORMAL, // Shader location point: normal
|
||||
SHADER_LOC_VERTEX_TANGENT, // Shader location point: tangent
|
||||
SHADER_LOC_VERTEX_COLOR, // Shader location point: color
|
||||
SHADER_LOC_MATRIX_MVP, // Shader location point: model-view-projection matrix
|
||||
SHADER_LOC_MATRIX_VIEW, // Shader location point: view matrix
|
||||
SHADER_LOC_MATRIX_PROJECTION, // Shader location point: projection matrix
|
||||
SHADER_LOC_MATRIX_MODEL, // Shader location point: model matrix
|
||||
SHADER_LOC_MATRIX_NORMAL, // Shader location point: normal matrix
|
||||
SHADER_LOC_VECTOR_VIEW, // Shader location point: view vector
|
||||
SHADER_LOC_COLOR_DIFFUSE, // Shader location point: diffuse color
|
||||
SHADER_LOC_COLOR_SPECULAR, // Shader location point: specular color
|
||||
SHADER_LOC_COLOR_AMBIENT, // Shader location point: ambient color
|
||||
SHADER_LOC_MAP_ALBEDO, // Shader location point: albedo texture (same as: SHADER_LOC_MAP_DIFFUSE)
|
||||
SHADER_LOC_MAP_METALNESS, // Shader location point: metalness texture (same as: SHADER_LOC_MAP_SPECULAR)
|
||||
SHADER_LOC_MAP_NORMAL, // Shader location point: normal texture
|
||||
SHADER_LOC_MAP_ROUGHNESS, // Shader location point: roughness texture
|
||||
SHADER_LOC_MAP_OCCLUSION, // Shader location point: occlusion texture
|
||||
SHADER_LOC_MAP_EMISSION, // Shader location point: emission texture
|
||||
SHADER_LOC_MAP_HEIGHT, // Shader location point: height texture
|
||||
SHADER_LOC_MAP_CUBEMAP, // Shader location point: cubemap texture_cube_map
|
||||
SHADER_LOC_MAP_IRRADIANCE, // Shader location point: irradiance texture_cube_map
|
||||
SHADER_LOC_MAP_PREFILTER, // Shader location point: prefilter texture_cube_map
|
||||
SHADER_LOC_MAP_BRDF // Shader location point: brdf texture
|
||||
SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
|
||||
SHADER_LOC_VERTEX_TEXCOORD01, // Shader location: vertex attribute: texcoord01
|
||||
SHADER_LOC_VERTEX_TEXCOORD02, // Shader location: vertex attribute: texcoord02
|
||||
SHADER_LOC_VERTEX_NORMAL, // Shader location: vertex attribute: normal
|
||||
SHADER_LOC_VERTEX_TANGENT, // Shader location: vertex attribute: tangent
|
||||
SHADER_LOC_VERTEX_COLOR, // Shader location: vertex attribute: color
|
||||
SHADER_LOC_MATRIX_MVP, // Shader location: matrix uniform: model-view-projection
|
||||
SHADER_LOC_MATRIX_VIEW, // Shader location: matrix uniform: view (camera transform)
|
||||
SHADER_LOC_MATRIX_PROJECTION, // Shader location: matrix uniform: projection
|
||||
SHADER_LOC_MATRIX_MODEL, // Shader location: matrix uniform: model (transform)
|
||||
SHADER_LOC_MATRIX_NORMAL, // Shader location: matrix uniform: normal
|
||||
SHADER_LOC_VECTOR_VIEW, // Shader location: vector uniform: view
|
||||
SHADER_LOC_COLOR_DIFFUSE, // Shader location: vector uniform: diffuse color
|
||||
SHADER_LOC_COLOR_SPECULAR, // Shader location: vector uniform: specular color
|
||||
SHADER_LOC_COLOR_AMBIENT, // Shader location: vector uniform: ambient color
|
||||
SHADER_LOC_MAP_ALBEDO, // Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE)
|
||||
SHADER_LOC_MAP_METALNESS, // Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR)
|
||||
SHADER_LOC_MAP_NORMAL, // Shader location: sampler2d texture: normal
|
||||
SHADER_LOC_MAP_ROUGHNESS, // Shader location: sampler2d texture: roughness
|
||||
SHADER_LOC_MAP_OCCLUSION, // Shader location: sampler2d texture: occlusion
|
||||
SHADER_LOC_MAP_EMISSION, // Shader location: sampler2d texture: emission
|
||||
SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: height
|
||||
SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap
|
||||
SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance
|
||||
SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter
|
||||
SHADER_LOC_MAP_BRDF // Shader location: sampler2d texture: brdf
|
||||
} ShaderLocationIndex;
|
||||
|
||||
#define SHADER_LOC_MAP_DIFFUSE SHADER_LOC_MAP_ALBEDO
|
||||
|
|
52
src/rlgl.h
52
src/rlgl.h
|
@ -383,32 +383,32 @@ typedef struct RenderBatch {
|
|||
|
||||
// Shader location point type
|
||||
typedef enum {
|
||||
SHADER_LOC_VERTEX_POSITION = 0, // Shader location point: position
|
||||
SHADER_LOC_VERTEX_TEXCOORD01, // Shader location point: texcoord01
|
||||
SHADER_LOC_VERTEX_TEXCOORD02, // Shader location point: texcoord02
|
||||
SHADER_LOC_VERTEX_NORMAL, // Shader location point: normal
|
||||
SHADER_LOC_VERTEX_TANGENT, // Shader location point: tangent
|
||||
SHADER_LOC_VERTEX_COLOR, // Shader location point: color
|
||||
SHADER_LOC_MATRIX_MVP, // Shader location point: model-view-projection matrix
|
||||
SHADER_LOC_MATRIX_VIEW, // Shader location point: view matrix
|
||||
SHADER_LOC_MATRIX_PROJECTION, // Shader location point: projection matrix
|
||||
SHADER_LOC_MATRIX_MODEL, // Shader location point: model matrix
|
||||
SHADER_LOC_MATRIX_NORMAL, // Shader location point: normal matrix
|
||||
SHADER_LOC_VECTOR_VIEW, // Shader location point: view vector
|
||||
SHADER_LOC_COLOR_DIFFUSE, // Shader location point: diffuse color
|
||||
SHADER_LOC_COLOR_SPECULAR, // Shader location point: specular color
|
||||
SHADER_LOC_COLOR_AMBIENT, // Shader location point: ambient color
|
||||
SHADER_LOC_MAP_ALBEDO, // Shader location point: albedo texture (same as: SHADER_LOC_MAP_DIFFUSE)
|
||||
SHADER_LOC_MAP_METALNESS, // Shader location point: metalness texture (same as: SHADER_LOC_MAP_SPECULAR)
|
||||
SHADER_LOC_MAP_NORMAL, // Shader location point: normal texture
|
||||
SHADER_LOC_MAP_ROUGHNESS, // Shader location point: roughness texture
|
||||
SHADER_LOC_MAP_OCCLUSION, // Shader location point: occlusion texture
|
||||
SHADER_LOC_MAP_EMISSION, // Shader location point: emission texture
|
||||
SHADER_LOC_MAP_HEIGHT, // Shader location point: height texture
|
||||
SHADER_LOC_MAP_CUBEMAP, // Shader location point: cubemap texture_cube_map
|
||||
SHADER_LOC_MAP_IRRADIANCE, // Shader location point: irradiance texture_cube_map
|
||||
SHADER_LOC_MAP_PREFILTER, // Shader location point: prefilter texture_cube_map
|
||||
SHADER_LOC_MAP_BRDF // Shader location point: brdf texture
|
||||
SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
|
||||
SHADER_LOC_VERTEX_TEXCOORD01, // Shader location: vertex attribute: texcoord01
|
||||
SHADER_LOC_VERTEX_TEXCOORD02, // Shader location: vertex attribute: texcoord02
|
||||
SHADER_LOC_VERTEX_NORMAL, // Shader location: vertex attribute: normal
|
||||
SHADER_LOC_VERTEX_TANGENT, // Shader location: vertex attribute: tangent
|
||||
SHADER_LOC_VERTEX_COLOR, // Shader location: vertex attribute: color
|
||||
SHADER_LOC_MATRIX_MVP, // Shader location: matrix uniform: model-view-projection
|
||||
SHADER_LOC_MATRIX_VIEW, // Shader location: matrix uniform: view (camera transform)
|
||||
SHADER_LOC_MATRIX_PROJECTION, // Shader location: matrix uniform: projection
|
||||
SHADER_LOC_MATRIX_MODEL, // Shader location: matrix uniform: model (transform)
|
||||
SHADER_LOC_MATRIX_NORMAL, // Shader location: matrix uniform: normal
|
||||
SHADER_LOC_VECTOR_VIEW, // Shader location: vector uniform: view
|
||||
SHADER_LOC_COLOR_DIFFUSE, // Shader location: vector uniform: diffuse color
|
||||
SHADER_LOC_COLOR_SPECULAR, // Shader location: vector uniform: specular color
|
||||
SHADER_LOC_COLOR_AMBIENT, // Shader location: vector uniform: ambient color
|
||||
SHADER_LOC_MAP_ALBEDO, // Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE)
|
||||
SHADER_LOC_MAP_METALNESS, // Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR)
|
||||
SHADER_LOC_MAP_NORMAL, // Shader location: sampler2d texture: normal
|
||||
SHADER_LOC_MAP_ROUGHNESS, // Shader location: sampler2d texture: roughness
|
||||
SHADER_LOC_MAP_OCCLUSION, // Shader location: sampler2d texture: occlusion
|
||||
SHADER_LOC_MAP_EMISSION, // Shader location: sampler2d texture: emission
|
||||
SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: height
|
||||
SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap
|
||||
SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance
|
||||
SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter
|
||||
SHADER_LOC_MAP_BRDF // Shader location: sampler2d texture: brdf
|
||||
} ShaderLocationIndex;
|
||||
|
||||
#define SHADER_LOC_MAP_DIFFUSE SHADER_LOC_MAP_ALBEDO
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue