Browse Source

Reorganized a couple of functions

raysan5 8 years ago
parent
commit
0dabb2708b
2 changed files with 54 additions and 55 deletions
  1. 41 42
      src/rlgl.c
  2. 13 13
      src/rlgl.h

+ 41 - 42
src/rlgl.c

@@ -992,43 +992,6 @@ void rlClearScreenBuffers(void)
     //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);     // Stencil buffer not used...
 }
 
-// Returns current OpenGL version
-int rlGetVersion(void)
-{
-#if defined(GRAPHICS_API_OPENGL_11)
-    return OPENGL_11;
-#elif defined(GRAPHICS_API_OPENGL_21)
-    return OPENGL_21;
-#elif defined(GRAPHICS_API_OPENGL_33)
-    return OPENGL_33;
-#elif defined(GRAPHICS_API_OPENGL_ES2)
-    return OPENGL_ES_20;
-#endif
-}
-
-// Get world coordinates from screen coordinates
-Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view)
-{
-    Vector3 result = { 0.0f, 0.0f, 0.0f };
-
-    // Calculate unproject matrix (multiply projection matrix and view matrix) and invert it
-    Matrix matProjView = MatrixMultiply(proj, view);
-    MatrixInvert(&matProjView);
-
-    // Create quaternion from source point
-    Quaternion quat = { source.x, source.y, source.z, 1.0f };
-
-    // Multiply quat point by unproject matrix
-    QuaternionTransform(&quat, matProjView);
-
-    // Normalized world points in vectors
-    result.x = quat.x/quat.w;
-    result.y = quat.y/quat.w;
-    result.z = quat.z/quat.w;
-
-    return result;
-}
-
 //----------------------------------------------------------------------------------
 // Module Functions Definition - rlgl Functions
 //----------------------------------------------------------------------------------
@@ -1287,11 +1250,10 @@ void rlglInit(int width, int height)
 void rlglClose(void)
 {
 #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
-    UnloadShaderDefault();
-    UnloadBuffersDefault();
-
-    // Delete default white texture
-    glDeleteTextures(1, &whiteTexture);
+    UnloadShaderDefault();              // Unload default shader
+    UnloadBuffersDefault();             // Unload default buffers (lines, triangles, quads)  
+    glDeleteTextures(1, &whiteTexture); // Unload default texture
+    
     TraceLog(LOG_INFO, "[TEX ID %i] Unloaded texture data (base white texture) from VRAM", whiteTexture);
 
     free(draws);
@@ -1311,6 +1273,20 @@ void rlglDraw(void)
 #endif
 }
 
+// Returns current OpenGL version
+int rlGetVersion(void)
+{
+#if defined(GRAPHICS_API_OPENGL_11)
+    return OPENGL_11;
+#elif defined(GRAPHICS_API_OPENGL_21)
+    return OPENGL_21;
+#elif defined(GRAPHICS_API_OPENGL_33)
+    return OPENGL_33;
+#elif defined(GRAPHICS_API_OPENGL_ES2)
+    return OPENGL_ES_20;
+#endif
+}
+
 // Load OpenGL extensions
 // NOTE: External loader function could be passed as a pointer
 void rlLoadExtensions(void *loader)
@@ -1334,6 +1310,29 @@ void rlLoadExtensions(void *loader)
 #endif
 }
 
+// Get world coordinates from screen coordinates
+Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view)
+{
+    Vector3 result = { 0.0f, 0.0f, 0.0f };
+
+    // Calculate unproject matrix (multiply projection matrix and view matrix) and invert it
+    Matrix matProjView = MatrixMultiply(proj, view);
+    MatrixInvert(&matProjView);
+
+    // Create quaternion from source point
+    Quaternion quat = { source.x, source.y, source.z, 1.0f };
+
+    // Multiply quat point by unproject matrix
+    QuaternionTransform(&quat, matProjView);
+
+    // Normalized world points in vectors
+    result.x = quat.x/quat.w;
+    result.y = quat.y/quat.w;
+    result.z = quat.z/quat.w;
+
+    return result;
+}
+
 // Convert image data to OpenGL texture (returns OpenGL valid Id)
 unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount)
 {

+ 13 - 13
src/rlgl.h

@@ -238,27 +238,27 @@ typedef unsigned char byte;
     } Mesh;
     
     // Shader and material limits
-    #define MAX_SHADER_LOCATIONS        32
-    #define MAX_MATERIAL_MAPS   12
+    #define MAX_SHADER_LOCATIONS    32
+    #define MAX_MATERIAL_MAPS       12
     
     // Shader type (generic)
     typedef struct Shader {
-        unsigned int id;        // Shader program id
-        int locs[MAX_SHADER_LOCATIONS];     // Initialized on LoadShader(), set to MAX_SHADER_LOCATIONS
+        unsigned int id;                // Shader program id
+        int locs[MAX_SHADER_LOCATIONS]; // Shader locations array
     } Shader;
 
     // Material texture map
     typedef struct MaterialMap {
-        Texture2D tex;
-        Color color;
-        float value;
+        Texture2D texture;      // Material map texture
+        Color color;            // Material map color
+        float value;            // Material map value
     } MaterialMap;
 
     // Material type (generic)
     typedef struct Material {
-        Shader shader;
-        MaterialMap maps[MAX_TEXTURE_MAPS];  // Initialized on LoadMaterial*(), set to MAX_TEXTURE_MAPS
-        float *params;          // Initialized on LoadMaterial*(), set to MAX_MATERIAL_PARAMS
+        Shader shader;          // Material shader
+        MaterialMap maps[MAX_MATERIAL_MAPS]; // Material maps
+        float *params;          // Material generic parameters (if required)
     } Material;
 
     // Camera type, defines a camera position/orientation in 3d space
@@ -394,17 +394,17 @@ void rlDeleteVertexArrays(unsigned int id);             // Unload vertex data (V
 void rlDeleteBuffers(unsigned int id);                  // Unload vertex data (VBO) from GPU memory
 void rlClearColor(byte r, byte g, byte b, byte a);      // Clear color buffer with color
 void rlClearScreenBuffers(void);                        // Clear used screen buffers (color and depth)
-int rlGetVersion(void);                                 // Returns current OpenGL version
-Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view);  // Get world coordinates from screen coordinates
 
 //------------------------------------------------------------------------------------
 // Functions Declaration - rlgl functionality
 //------------------------------------------------------------------------------------
 void rlglInit(int width, int height);           // Initialize rlgl (buffers, shaders, textures, states)
 void rlglClose(void);                           // De-inititialize rlgl (buffers, shaders, textures)
-void rlglDraw(void);                // Update and Draw default buffers (lines, triangles, quads)
+void rlglDraw(void);                            // Update and Draw default buffers (lines, triangles, quads)
 
+int rlGetVersion(void);                         // Returns current OpenGL version
 void rlLoadExtensions(void *loader);            // Load OpenGL extensions
+Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view);  // Get world coordinates from screen coordinates
 
 // Textures data management
 unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount);    // Load texture in GPU