Bladeren bron

REVIEWED: rlLoadShaderDefault()

Operate over global variable
pull/1707/head
raysan5 3 jaren geleden
bovenliggende
commit
5fd441969d
1 gewijzigde bestanden met toevoegingen van 19 en 20 verwijderingen
  1. +19
    -20
      src/rlgl.h

+ 19
- 20
src/rlgl.h Bestand weergeven

@ -1,6 +1,6 @@
/**********************************************************************************************
*
* rlgl v3.5 - raylib OpenGL abstraction layer
* rlgl v3.7 - raylib OpenGL abstraction layer
*
* rlgl is a wrapper for multiple OpenGL versions (1.1, 2.1, 3.3 Core, ES 2.0) to
* pseudo-OpenGL 1.1 style functions (rlVertex, rlTranslate, rlRotate...).
@ -901,8 +901,8 @@ static PFNGLVERTEXATTRIBDIVISOREXTPROC glVertexAttribDivisor = NULL;
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
static n">Shader rlLoadShaderDefault(void); // Load default shader (just vertex positioning and texture coloring)
static void rlUnloadShaderDefault(void); // Unload default shader
static kt">void rlLoadShaderDefault(void); // Load default shader (RLGL.State.defaultShader)
static void rlUnloadShaderDefault(void); // Unload default shader (RLGL.State.defaultShader)
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
#if defined(GRAPHICS_API_OPENGL_11)
static int rlGenerateMipmapsData(unsigned char *data, int baseWidth, int baseHeight); // Generate mipmaps data on CPU side
@ -1816,7 +1816,7 @@ void rlglInit(int width, int height)
else TRACELOG(LOG_WARNING, "TEXTURE: Failed to load default texture");
// Init default Shader (customized for GL 3.3 and ES2)
RLGL.State.defaultShader = rlLoadShaderDefault();
rlLoadShaderDefault(); // RLGL.State.defaultShader
RLGL.State.currentShader = RLGL.State.defaultShader;
// Init default vertex arrays buffers
@ -3700,13 +3700,13 @@ void rlLoadDrawCube(void)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Load default shader (just vertex positioning and texture coloring)
// NOTE: This shader program is used for internal buffers
static Shader rlLoadShaderDefault(void)
// NOTE: It uses global variable: RLGL.State.defaultShader
static void rlLoadShaderDefault(void)
{
Shader shader = { 0 };
shader.locs = (int *)RL_CALLOC(MAX_SHADER_LOCATIONS, sizeof(int));
RLGL.State.defaultShader.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;
for (int i = 0; i < MAX_SHADER_LOCATIONS; i++) RLGLspan>.State.defaultShader.locs[i] = -1;
// Vertex shader directly defined, no external file required
const char *defaultVShaderStr =
@ -3776,28 +3776,27 @@ static Shader rlLoadShaderDefault(void)
RLGL.State.defaultVShaderId = rlCompileShader(defaultVShaderStr, GL_VERTEX_SHADER); // Compile default vertex shader
RLGL.State.defaultFShaderId = rlCompileShader(defaultFShaderStr, GL_FRAGMENT_SHADER); // Compile default fragment shader
shader.id = rlLoadShaderProgram(RLGL.State.defaultVShaderId, RLGL.State.defaultFShaderId);
RLGLspan>.State.defaultShader.id = rlLoadShaderProgram(RLGL.State.defaultVShaderId, RLGL.State.defaultFShaderId);
if (shader.id > 0)
if (RLGLspan>.State.defaultShader.id > 0)
{
TRACELOG(LOG_INFO, "SHADER: [ID %i] Default shader loaded successfully", shader.id);
TRACELOG(LOG_INFO, "SHADER: [ID %i] Default shader loaded successfully", RLGLspan>.State.defaultShader.id);
// Set default shader locations: attributes locations
shader.locs[SHADER_LOC_VERTEX_POSITION] = glGetAttribLocation(shader.id, "vertexPosition");
shader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(shader.id, "vertexTexCoord");
shader.locs[SHADER_LOC_VERTEX_COLOR] = glGetAttribLocation(shader.id, "vertexColor");
RLGLspan>.State.defaultShader.locs[SHADER_LOC_VERTEX_POSITION] = glGetAttribLocation(RLGLspan>.State.defaultShader.id, "vertexPosition");
RLGLspan>.State.defaultShader.locs[SHADER_LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(RLGLspan>.State.defaultShader.id, "vertexTexCoord");
RLGLspan>.State.defaultShader.locs[SHADER_LOC_VERTEX_COLOR] = glGetAttribLocation(RLGLspan>.State.defaultShader.id, "vertexColor");
// Set default shader locations: uniform locations
shader.locs[SHADER_LOC_MATRIX_MVP] = glGetUniformLocation(shader.id, "mvp");
shader.locs[SHADER_LOC_COLOR_DIFFUSE] = glGetUniformLocation(shader.id, "colDiffuse");
shader.locs[SHADER_LOC_MAP_DIFFUSE] = glGetUniformLocation(shader.id, "texture0");
RLGLspan>.State.defaultShader.locs[SHADER_LOC_MATRIX_MVP] = glGetUniformLocation(RLGLspan>.State.defaultShader.id, "mvp");
RLGLspan>.State.defaultShader.locs[SHADER_LOC_COLOR_DIFFUSE] = glGetUniformLocation(RLGLspan>.State.defaultShader.id, "colDiffuse");
RLGLspan>.State.defaultShader.locs[SHADER_LOC_MAP_DIFFUSE] = glGetUniformLocation(RLGLspan>.State.defaultShader.id, "texture0");
}
else TRACELOG(LOG_WARNING, "SHADER: [ID %i] Failed to load default shader", shader.id);
return shader;
else TRACELOG(LOG_WARNING, "SHADER: [ID %i] Failed to load default shader", RLGL.State.defaultShader.id);
}
// Unload default shader
// NOTE: It uses global variable: RLGL.State.defaultShader
static void rlUnloadShaderDefault(void)
{
glUseProgram(0);

Laden…
Annuleren
Opslaan