Browse Source

Redesign to use Material type -IN PROGRESS-

Requires Shader access functions review
raysan5 9 năm trước cách đây
mục cha
commit
c9d22c7a14
4 tập tin đã thay đổi với 89 bổ sung233 xóa
  1. 3 15
      src/models.c
  2. 16 24
      src/raylib.h
  3. 53 187
      src/rlgl.c
  4. 17 7
      src/rlgl.h

+ 3 - 15
src/models.c

@@ -551,10 +551,7 @@ Model LoadModel(const char *fileName)
 
     // NOTE: At this point we have all vertex, texcoord, normal data for the model in mesh struct
     
-    if (mesh.vertexCount == 0)
-    {
-        TraceLog(WARNING, "Model could not be loaded");
-    }
+    if (mesh.vertexCount == 0) TraceLog(WARNING, "Model could not be loaded");
     else
     {
         // NOTE: model properties (transform, texture, shader) are initialized inside rlglLoadModel()
@@ -627,17 +624,8 @@ void UnloadModel(Model model)
 // Link a texture to a model
 void SetModelTexture(Model *model, Texture2D texture)
 {
-    if (texture.id <= 0)
-    {
-        // Use default white texture (use mesh color)
-        model->texture.id = whiteTexture;               // OpenGL 1.1
-        model->shader.texDiffuseId = whiteTexture;      // OpenGL 3.3 / ES 2.0
-    }
-    else
-    {
-        model->texture = texture;
-        model->shader.texDiffuseId = texture.id;
-    }
+    if (texture.id <= 0) model->material.texDiffuse.id = whiteTexture;  // Use default white texture
+    else model->material.texDiffuse = texture;
 }
 
 static Mesh GenMeshHeightmap(Image heightmap, Vector3 size)

+ 16 - 24
src/raylib.h

@@ -347,12 +347,7 @@ typedef struct Mesh {
 
 // Shader type (generic shader)
 typedef struct Shader {
-    unsigned int id;                // Shader program id
-
-    // TODO: This should be Texture2D objects
-    unsigned int texDiffuseId;      // Diffuse texture id
-    unsigned int texNormalId;       // Normal texture id
-    unsigned int texSpecularId;     // Specular texture id
+    unsigned int id;            // Shader program id
     
     // Variable attributes
     int vertexLoc;        // Vertex attribute location point (vertex shader)
@@ -370,20 +365,19 @@ typedef struct Shader {
 } Shader;
 
 // Material type
-// TODO: Redesign material-shaders-textures system
 typedef struct Material {
-    //Shader shader;
+    Shader shader;              // Standard shader (supports 3 map types: diffuse, normal, specular)
 
-    //Texture2D texDiffuse;      // Diffuse texture
-    //Texture2D texNormal;       // Normal texture
-    //Texture2D texSpecular;     // Specular texture
+    Texture2D texDiffuse;       // Diffuse texture
+    Texture2D texNormal;        // Normal texture
+    Texture2D texSpecular;      // Specular texture
     
-    Color colDiffuse;
-    Color colAmbient;
-    Color colSpecular;
+    Color colDiffuse;           // Diffuse color
+    Color colAmbient;           // Ambient color
+    Color colSpecular;          // Specular color
     
-    float glossiness;
-    float normalDepth;
+    float glossiness;           // Glossiness level
+    float normalDepth;          // Normal map depth
 } Material;
 
 // 3d Model type
@@ -391,9 +385,7 @@ typedef struct Material {
 typedef struct Model {
     Mesh mesh;
     Matrix transform;
-    Texture2D texture;    // Only for OpenGL 1.1, on newer versions this should be in the shader
-    Shader shader;
-    //Material material;
+    Material material;
 } Model;
 
 // Ray type (useful for raycast)
@@ -774,7 +766,7 @@ void SetModelTexture(Model *model, Texture2D texture);
 void DrawModel(Model model, Vector3 position, float scale, Color tint);                            // Draw a model (with texture if set)
 void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint);      // Draw a model with extended parameters
 void DrawModelWires(Model model, Vector3 position, float scale, Color color);                      // Draw a model wires (with texture if set)
-void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint);      // Draw a model wires (with texture if set) with extended parameters
+void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
 void DrawBoundingBox(BoundingBox box, Color color);                                                // Draw bounding box (wires)
 
 void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint);                         // Draw a billboard texture
@@ -806,10 +798,10 @@ int GetShaderLocation(Shader shader, const char *uniformName);
 void SetShaderValue(Shader shader, int uniformLoc, float *value, int size);             // Set shader uniform value (float)
 void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size);              // Set shader uniform value (int)
 void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat);                   // Set shader uniform value (matrix 4x4)
-void SetShaderMapDiffuse(Shader *shader, Texture2D texture);                            // Default diffuse shader map texture assignment
-void SetShaderMapNormal(Shader *shader, const char *uniformName, Texture2D texture);    // Normal map texture shader assignment
-void SetShaderMapSpecular(Shader *shader, const char *uniformName, Texture2D texture);  // Specular map texture shader assignment
-void SetShaderMap(Shader *shader, int mapLocation, Texture2D texture, int textureUnit); // TODO: Generic shader map assignment
+//void SetShaderMapDiffuse(Shader *shader, Texture2D texture);                            // Default diffuse shader map texture assignment
+//void SetShaderMapNormal(Shader *shader, const char *uniformName, Texture2D texture);    // Normal map texture shader assignment
+//void SetShaderMapSpecular(Shader *shader, const char *uniformName, Texture2D texture);  // Specular map texture shader assignment
+//void SetShaderMap(Shader *shader, int mapLocation, Texture2D texture, int textureUnit); // TODO: Generic shader map assignment
 
 void SetBlendMode(int mode);                                        // Set blending mode (alpha, additive, multiplied)
 

+ 53 - 187
src/rlgl.c

@@ -1421,7 +1421,7 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float ro
 
 #if defined(GRAPHICS_API_OPENGL_11)
     glEnable(GL_TEXTURE_2D);
-    glBindTexture(GL_TEXTURE_2D, model.texture.id);
+    glBindTexture(GL_TEXTURE_2D, model.material.texDiffuse.id);
 
     // NOTE: On OpenGL 1.1 we use Vertex Arrays to draw model
     glEnableClientState(GL_VERTEX_ARRAY);                     // Enable vertex array
@@ -1452,7 +1452,7 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float ro
 #endif
 
 #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
-    glUseProgram(model.shader.id);
+    glUseProgram(model.material.shader.id);
     
     // At this point the modelview matrix just contains the view matrix (camera)
     // That's because Begin3dMode() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix()
@@ -1476,28 +1476,30 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float ro
     Matrix matMVP = MatrixMultiply(matModelView, matProjection);        // Transform to screen-space coordinates
 
     // Send combined model-view-projection matrix to shader
-    glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP));
+    glUniformMatrix4fv(model.material.shader.mvpLoc, 1, false, MatrixToFloat(matMVP));
 
     // Apply color tinting to model
     // NOTE: Just update one uniform on fragment shader
     float vColor[4] = { (float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255 };
-    glUniform4fv(model.shader.tintColorLoc, 1, vColor);
+    glUniform4fv(model.material.shader.tintColorLoc, 1, vColor);
 
     // Set shader textures (diffuse, normal, specular)
     glActiveTexture(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, model.shader.texDiffuseId);
-    glUniform1i(model.shader.mapDiffuseLoc, 0);
-
-    if (model.shader.texNormalId != 0)
+    glBindTexture(GL_TEXTURE_2D, model.material.texDiffuse.id);
+    glUniform1i(model.material.shader.mapDiffuseLoc, 0);        // Texture fits in active texture unit 0
+    
+    if (model.material.texNormal.id != 0)
     {
         glActiveTexture(GL_TEXTURE1);
-        glBindTexture(GL_TEXTURE_2D, model.shader.texNormalId);
+        glBindTexture(GL_TEXTURE_2D, model.material.texNormal.id);
+        glUniform1i(model.material.shader.mapNormalLoc, 1);     // Texture fits in active texture unit 1
     }
     
-    if (model.shader.texSpecularId != 0)
+    if (model.material.texSpecular.id != 0)
     {
         glActiveTexture(GL_TEXTURE2);
-        glBindTexture(GL_TEXTURE_2D, model.shader.texSpecularId);
+        glBindTexture(GL_TEXTURE_2D, model.material.texSpecular.id);
+        glUniform1i(model.material.shader.mapSpecularLoc, 2);   // Texture fits in active texture unit 2
     }
 
     if (vaoSupported)
@@ -1508,19 +1510,19 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float ro
     {
         // Bind model VBOs data
         glBindBuffer(GL_ARRAY_BUFFER, model.mesh.vboId[0]);
-        glVertexAttribPointer(model.shader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
-        glEnableVertexAttribArray(model.shader.vertexLoc);
+        glVertexAttribPointer(model.material.shader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
+        glEnableVertexAttribArray(model.material.shader.vertexLoc);
 
         glBindBuffer(GL_ARRAY_BUFFER, model.mesh.vboId[1]);
-        glVertexAttribPointer(model.shader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
-        glEnableVertexAttribArray(model.shader.texcoordLoc);
+        glVertexAttribPointer(model.material.shader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
+        glEnableVertexAttribArray(model.material.shader.texcoordLoc);
 
         // Add normals support
-        if (model.shader.normalLoc != -1)
+        if (model.material.shader.normalLoc != -1)
         {
             glBindBuffer(GL_ARRAY_BUFFER, model.mesh.vboId[2]);
-            glVertexAttribPointer(model.shader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
-            glEnableVertexAttribArray(model.shader.normalLoc);
+            glVertexAttribPointer(model.material.shader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
+            glEnableVertexAttribArray(model.material.shader.normalLoc);
         }
     }
 
@@ -1531,13 +1533,13 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float ro
     //glDisableVertexAttribArray(model.shader.texcoordLoc);
     //if (model.shader.normalLoc != -1) glDisableVertexAttribArray(model.shader.normalLoc);
     
-    if (model.shader.texNormalId != 0)
+    if (model.material.texNormal.id != 0)
     {
         glActiveTexture(GL_TEXTURE1);
         glBindTexture(GL_TEXTURE_2D, 0);
     }
     
-    if (model.shader.texSpecularId != 0)
+    if (model.material.texSpecular.id != 0)
     {
         glActiveTexture(GL_TEXTURE2);
         glBindTexture(GL_TEXTURE_2D, 0);
@@ -1907,22 +1909,29 @@ Model rlglLoadModel(Mesh mesh)
     Model model;
 
     model.mesh = mesh;
-    model.transform = MatrixIdentity();
     model.mesh.vaoId = 0;       // Vertex Array Object
-    model.mesh.vboId[0] = 0;    // Vertex position VBO
-    model.mesh.vboId[1] = 0;    // Texcoords VBO
-    model.mesh.vboId[2] = 0;    // Normals VBO
+    model.mesh.vboId[0] = 0;    // Vertex positions VBO
+    model.mesh.vboId[1] = 0;    // Vertex texcoords VBO
+    model.mesh.vboId[2] = 0;    // Vertex normals VBO
+    
+    model.transform = MatrixIdentity();
 
 #if defined(GRAPHICS_API_OPENGL_11)
-    model.texture.id = 0;       // No texture required
-    model.shader.id = 0;        // No shader used
+    model.material.texDiffuse.id = 0;    // No texture required
+    model.material.shader.id = 0;        // No shader used
 
 #elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
-    model.texture.id = whiteTexture;    // Default whiteTexture
-    model.texture.width = 1;            // Default whiteTexture width
-    model.texture.height = 1;           // Default whiteTexture height
-    model.texture.format = UNCOMPRESSED_R8G8B8A8; // Default whiteTexture format
-    model.shader = simpleShader;        // Default model shader
+    model.material.shader = simpleShader;           // Default model shader
+    
+    model.material.texDiffuse.id = whiteTexture;    // Default whiteTexture
+    model.material.texDiffuse.width = 1;            // Default whiteTexture width
+    model.material.texDiffuse.height = 1;           // Default whiteTexture height
+    model.material.texDiffuse.format = UNCOMPRESSED_R8G8B8A8; // Default whiteTexture format
+    
+    model.material.texNormal.id = 0;        // By default, no normal texture
+    model.material.texSpecular.id = 0;      // By default, no specular texture
+    
+    // TODO: Fill default material properties (color, glossiness...)
     
     GLuint vaoModel = 0;         // Vertex Array Objects (VAO)
     GLuint vertexBuffer[3];      // Vertex Buffer Objects (VBO)
@@ -1940,20 +1949,20 @@ Model rlglLoadModel(Mesh mesh)
     // Enable vertex attributes: position
     glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[0]);
     glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.vertices, GL_STATIC_DRAW);
-    glVertexAttribPointer(model.shader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
-    glEnableVertexAttribArray(model.shader.vertexLoc);
+    glVertexAttribPointer(model.material.shader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
+    glEnableVertexAttribArray(model.material.shader.vertexLoc);
 
     // Enable vertex attributes: texcoords
     glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[1]);
     glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*mesh.vertexCount, mesh.texcoords, GL_STATIC_DRAW);
-    glVertexAttribPointer(model.shader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
-    glEnableVertexAttribArray(model.shader.texcoordLoc);
+    glVertexAttribPointer(model.material.shader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
+    glEnableVertexAttribArray(model.material.shader.texcoordLoc);
 
     // Enable vertex attributes: normals
     glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[2]);
     glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.normals, GL_STATIC_DRAW);
-    glVertexAttribPointer(model.shader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
-    glEnableVertexAttribArray(model.shader.normalLoc);
+    glVertexAttribPointer(model.material.shader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
+    glEnableVertexAttribArray(model.material.shader.normalLoc);
 
     model.mesh.vboId[0] = vertexBuffer[0];     // Vertex position VBO
     model.mesh.vboId[1] = vertexBuffer[1];     // Texcoords VBO
@@ -2153,11 +2162,6 @@ Shader LoadShader(char *vsFileName, char *fsFileName)
         if (shader.id != 0)
         {
             TraceLog(INFO, "[SHDR ID %i] Custom shader loaded successfully", shader.id);
-        
-            // Set shader textures ids (all 0 by default)
-            shader.texDiffuseId = 0;
-            shader.texNormalId = 0;
-            shader.texSpecularId = 0;
 
             // Get handles to GLSL input attibute locations
             //-------------------------------------------------------------------
@@ -2314,28 +2318,7 @@ void SetCustomShader(Shader shader)
     if (currentShader.id != shader.id)
     {
         rlglDraw();
-
         currentShader = shader;
-/*
-        if (vaoSupported) glBindVertexArray(vaoQuads);
-        
-        // Enable vertex attributes: position
-        glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[0]);
-        glEnableVertexAttribArray(currentShader.vertexLoc);
-        glVertexAttribPointer(currentShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
-
-        // Enable vertex attributes: texcoords
-        glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[1]);
-        glEnableVertexAttribArray(currentShader.texcoordLoc);
-        glVertexAttribPointer(currentShader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
-
-        // Enable vertex attributes: colors
-        glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[2]);
-        glEnableVertexAttribArray(currentShader.colorLoc);
-        glVertexAttribPointer(currentShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
-
-        if (vaoSupported) glBindVertexArray(0);     // Unbind VAO
-*/
     }
 #endif
 }
@@ -2358,7 +2341,7 @@ void SetPostproShader(Shader shader)
     texture.width = screenWidth;
     texture.height = screenHeight;
 
-    SetShaderMapDiffuse(&postproQuad.shader, texture);
+    postproQuad.material.texDiffuse = texture;
     
     //TraceLog(DEBUG, "Postproquad texture id: %i", postproQuad.texture.id);
     //TraceLog(DEBUG, "Postproquad shader diffuse map id: %i", postproQuad.shader.texDiffuseId);
@@ -2386,7 +2369,7 @@ void SetDefaultShader(void)
 void SetModelShader(Model *model, Shader shader)
 {
 #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
-    model->shader = shader;
+    model->material.shader = shader;
 
     if (vaoSupported) glBindVertexArray(model->mesh.vaoId);
 
@@ -2406,9 +2389,7 @@ void SetModelShader(Model *model, Shader shader)
     glVertexAttribPointer(shader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
 
     if (vaoSupported) glBindVertexArray(0);     // Unbind VAO
-    
-    // NOTE: If SetModelTexture() is called previously, texture is not assigned to new shader
-    if (model->texture.id > 0) model->shader.texDiffuseId = model->texture.id;
+
 #elif (GRAPHICS_API_OPENGL_11)
     TraceLog(WARNING, "Shaders not supported on OpenGL 1.1");
 #endif
@@ -2480,104 +2461,6 @@ void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat)
 #endif
 }
 
-// Default diffuse shader map texture assignment
-void SetShaderMapDiffuse(Shader *shader, Texture2D texture)
-{
-#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
-    shader->texDiffuseId = texture.id;
-    
-    glUseProgram(shader->id);
-    
-    glActiveTexture(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, shader->texDiffuseId);
-    
-    glUniform1i(shader->mapDiffuseLoc, 0);    // Texture fits in active texture unit 0
-    
-    glBindTexture(GL_TEXTURE_2D, 0);
-    glActiveTexture(GL_TEXTURE0);
-    glUseProgram(0);
-#endif
-}
-
-// Normal map texture shader assignment
-void SetShaderMapNormal(Shader *shader, const char *uniformName, Texture2D texture)
-{
-#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
-    shader->mapNormalLoc = glGetUniformLocation(shader->id, uniformName);
-
-    if (shader->mapNormalLoc == -1) TraceLog(WARNING, "[SHDR ID %i] Shader location for %s could not be found", shader->id, uniformName);
-    else
-    {
-        shader->texNormalId = texture.id;
-        
-        glUseProgram(shader->id);
-        
-        glActiveTexture(GL_TEXTURE1);
-        glBindTexture(GL_TEXTURE_2D, shader->texNormalId);
-        
-        glUniform1i(shader->mapNormalLoc, 1);    // Texture fits in active texture unit 1
-        
-        glBindTexture(GL_TEXTURE_2D, 0);
-        glActiveTexture(GL_TEXTURE0);
-        glUseProgram(0);
-    }
-#endif
-}
-
-// Specular map texture shader assignment
-void SetShaderMapSpecular(Shader *shader, const char *uniformName, Texture2D texture)
-{
-#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
-    shader->mapSpecularLoc = glGetUniformLocation(shader->id, uniformName);
-
-    if (shader->mapSpecularLoc == -1) TraceLog(WARNING, "[SHDR ID %i] Shader location for %s could not be found", shader->id, uniformName);
-    else
-    {
-        shader->texSpecularId = texture.id;
-        
-        glUseProgram(shader->id);
-        
-        glActiveTexture(GL_TEXTURE2);
-        glBindTexture(GL_TEXTURE_2D, shader->texSpecularId);
-        
-        glUniform1i(shader->mapSpecularLoc, 2);    // Texture fits in active texture unit 2
-        
-        glBindTexture(GL_TEXTURE_2D, 0);
-        glActiveTexture(GL_TEXTURE0);
-        glUseProgram(0);
-    }
-#endif
-}
-
-// Generic shader maps assignment
-// TODO: Trying to find a generic shader to allow any kind of map
-// NOTE: mapLocation should be retrieved by user with GetShaderLocation()
-// ISSUE: mapTextureId: Shader should contain a reference to map texture and corresponding textureUnit,
-//        so it can be automatically checked and used in rlglDrawModel()
-void SetShaderMap(Shader *shader, int mapLocation, Texture2D texture, int textureUnit)
-{
-/*
-#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
-    if (mapLocation == -1) TraceLog(WARNING, "[SHDR ID %i] Map location could not be found", shader->id);
-    else
-    {
-        shader->mapTextureId = texture.id;
-        
-        glUseProgram(shader->id);
-        
-        glActiveTexture(GL_TEXTURE0 + textureUnit);
-        glBindTexture(GL_TEXTURE_2D, shader->mapTextureId);
-        
-        glUniform1i(mapLocation, textureUnit);    // Texture fits in active textureUnit
-        
-        glBindTexture(GL_TEXTURE_2D, 0);
-        glActiveTexture(GL_TEXTURE0);
-        glUseProgram(0);
-    }
-#endif
-*/
-}
-
 // Set blending mode (alpha, additive, multiplied)
 // NOTE: Only 3 blending modes predefined
 void SetBlendMode(int mode)
@@ -2652,15 +2535,11 @@ static void LoadCompressedTexture(unsigned char *data, int width, int height, in
 }
 
 // Load Shader (Vertex and Fragment)
-// NOTE: This shader program is used only for batch buffers (lines, triangles, quads)
+// NOTE: This shader program is used for batch buffers (lines, triangles, quads)
 static Shader LoadDefaultShader(void)
 {
     Shader shader;
 
-    // NOTE: Shaders are written using GLSL 110 (desktop), that is equivalent to GLSL 100 on ES2
-    // NOTE: Detected an error on ATI cards if defined #version 110 while OpenGL 3.3+
-    // Just defined #version 330 despite shader is #version 110
-
     // Vertex shader directly defined, no external file required
 #if defined(GRAPHICS_API_OPENGL_33)
     char vShaderStr[] = "#version 330       \n"
@@ -2668,7 +2547,7 @@ static Shader LoadDefaultShader(void)
         "in vec2 vertexTexCoord;            \n"
         "in vec4 vertexColor;               \n"
         "out vec2 fragTexCoord;             \n"
-        "out vec4 fragTintColor;                \n"
+        "out vec4 fragTintColor;            \n"
 #elif defined(GRAPHICS_API_OPENGL_ES2)
     char vShaderStr[] = "#version 100       \n"
         "attribute vec3 vertexPosition;     \n"
@@ -2677,7 +2556,7 @@ static Shader LoadDefaultShader(void)
         "varying vec2 fragTexCoord;         \n"
         "varying vec4 fragTintColor;        \n"
 #endif
-        "uniform mat4 mvpMatrix;     \n"
+        "uniform mat4 mvpMatrix;            \n"
         "void main()                        \n"
         "{                                  \n"
         "    fragTexCoord = vertexTexCoord; \n"
@@ -2689,7 +2568,7 @@ static Shader LoadDefaultShader(void)
 #if defined(GRAPHICS_API_OPENGL_33)
     char fShaderStr[] = "#version 330       \n"
         "in vec2 fragTexCoord;              \n"
-        "in vec4 fragTintColor;                 \n"
+        "in vec4 fragTintColor;             \n"
 #elif defined(GRAPHICS_API_OPENGL_ES2)
     char fShaderStr[] = "#version 100       \n"
         "precision mediump float;           \n"     // precision required for OpenGL ES2 (WebGL)
@@ -2724,10 +2603,6 @@ static Shader LoadDefaultShader(void)
     shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
     shader.mapNormalLoc = -1;       // It can be set later
     shader.mapSpecularLoc = -1;     // It can be set later
-    
-    shader.texDiffuseId = whiteTexture; // Default white texture
-    shader.texNormalId = 0;
-    shader.texSpecularId = 0;
     //--------------------------------------------------------------------
 
     return shader;
@@ -2739,10 +2614,6 @@ static Shader LoadSimpleShader(void)
 {
     Shader shader;
 
-    // NOTE: Shaders are written using GLSL 110 (desktop), that is equivalent to GLSL 100 on ES2
-    // NOTE: Detected an error on ATI cards if defined #version 110 while OpenGL 3.3+
-    // Just defined #version 330 despite shader is #version 110
-
     // Vertex shader directly defined, no external file required
 #if defined(GRAPHICS_API_OPENGL_33)
     char vShaderStr[] = "#version 330       \n"
@@ -2802,10 +2673,6 @@ static Shader LoadSimpleShader(void)
     shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
     shader.mapNormalLoc = -1;       // It can be set later
     shader.mapSpecularLoc = -1;     // It can be set later
-    
-    shader.texDiffuseId = whiteTexture; // Default white texture
-    shader.texNormalId = 0;
-    shader.texSpecularId = 0;
     //--------------------------------------------------------------------
 
     return shader;
@@ -2878,7 +2745,6 @@ static void InitializeBuffers(void)
     quads.indices = (unsigned short *)malloc(sizeof(short)*6*MAX_QUADS_BATCH);  // 6 int by quad (indices)
 #endif
 
-
     for (int i = 0; i < (3*4*MAX_QUADS_BATCH); i++) quads.vertices[i] = 0.0f;
     for (int i = 0; i < (2*4*MAX_QUADS_BATCH); i++) quads.texcoords[i] = 0.0f;
     for (int i = 0; i < (4*4*MAX_QUADS_BATCH); i++) quads.colors[i] = 0;

+ 17 - 7
src/rlgl.h

@@ -154,11 +154,6 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
     typedef struct Shader {
         unsigned int id;                // Shader program id
 
-        // TODO: This should be Texture2D objects
-        unsigned int texDiffuseId;      // Diffuse texture id
-        unsigned int texNormalId;       // Normal texture id
-        unsigned int texSpecularId;     // Specular texture id
-        
         // Variable attributes
         int vertexLoc;        // Vertex attribute location point (vertex shader)
         int texcoordLoc;      // Texcoord attribute location point (vertex shader)
@@ -184,12 +179,27 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
         int format;             // Data format (TextureFormat)
     } Texture2D;
     
+    // Material type
+    typedef struct Material {
+        Shader shader;
+
+        Texture2D texDiffuse;      // Diffuse texture
+        Texture2D texNormal;       // Normal texture
+        Texture2D texSpecular;     // Specular texture
+        
+        Color colDiffuse;
+        Color colAmbient;
+        Color colSpecular;
+        
+        float glossiness;
+        float normalDepth;
+    } Material;
+
     // 3d Model type
     typedef struct Model {
         Mesh mesh;
         Matrix transform;
-        Texture2D texture;
-        Shader shader;
+        Material material;
     } Model;
 	
     // Color blending modes (pre-defined)