|
|
@ -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 = NULL; |
|
|
|
char *fShaderStr = NULL; |
|
|
|
|
|
|
|
">if (vsFileName != NULL) vShaderStr = LoadFileText(vsFileName); |
|
|
|
">if (fsFileName != NULL) fShaderStr = LoadFileText(fsFileName); |
|
|
|
char *vShaderStr = LoadFileText(vsFileName); |
|
|
|
char *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 |
|
|
|
shader = LoadShaderFromMemory(vShaderStr, fShaderStr); |
|
|
|
|
|
|
|
// 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; |
|
|
|
} |
|
|
@ -2388,13 +2347,16 @@ 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"); |
|
|
|
} |
|
|
|
|
|
|
|