Browse Source

Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop

victorfisac 9 years ago
parent
commit
f874fdc1ad
6 changed files with 80 additions and 67 deletions
  1. 42 0
      src/core.c
  2. 9 0
      src/glad.c
  3. 9 0
      src/glad.h
  4. 1 2
      src/raymath.h
  5. 6 56
      src/rlgl.c
  6. 13 9
      src/rlgl.h

+ 42 - 0
src/core.c

@@ -54,8 +54,18 @@
 #include <errno.h>          // Macros for reporting and retrieving error conditions through error codes
 
 #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
+
+    #define GLAD_EXTENSIONS_LOADER
+    #if defined(GLEW_EXTENSIONS_LOADER)
+        #define GLEW_STATIC
+        #include <GL/glew.h>        // GLEW extensions loading lib
+    #elif defined(GLAD_EXTENSIONS_LOADER)
+        #include "glad.h"           // GLAD library: Manage OpenGL headers and extensions
+    #endif
+
     //#define GLFW_INCLUDE_NONE   // Disable the standard OpenGL header inclusion on GLFW3
     #include <GLFW/glfw3.h>     // GLFW3 library: Windows, OpenGL context and Input management
+
     #ifdef __linux
         #define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting
         #define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window
@@ -1378,6 +1388,38 @@ static void InitDisplay(int width, int height)
 
     glfwMakeContextCurrent(window);
 
+    // Extensions initialization for OpenGL 3.3
+    if (rlGetVersion() == OPENGL_33)
+    {
+        #if defined(GLEW_EXTENSIONS_LOADER)
+            // Initialize extensions using GLEW
+            glewExperimental = 1;       // Needed for core profile
+            GLenum error = glewInit();
+            
+            if (error != GLEW_OK) TraceLog(ERROR, "Failed to initialize GLEW - Error Code: %s\n", glewGetErrorString(error));
+            
+            if (glewIsSupported("GL_VERSION_3_3")) TraceLog(INFO, "OpenGL 3.3 Core profile supported");
+            else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported");
+
+            // With GLEW, we can check if an extension has been loaded in two ways:
+            //if (GLEW_ARB_vertex_array_object) { } 
+            //if (glewIsSupported("GL_ARB_vertex_array_object")) { }
+
+            // NOTE: GLEW is a big library that loads ALL extensions, we can use some alternative to load only required ones
+            // Alternatives: glLoadGen, glad, libepoxy
+        #elif defined(GLAD_EXTENSIONS_LOADER)
+            // NOTE: glad is generated and contains only required OpenGL version and Core extensions
+            //if (!gladLoadGL()) TraceLog(ERROR, "Failed to initialize glad\n");
+            if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) TraceLog(ERROR, "Failed to initialize glad\n"); // No GLFW3 in this module...
+
+            if (GLAD_GL_VERSION_3_3) TraceLog(INFO, "OpenGL 3.3 Core profile supported");
+            else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported");
+            
+            // With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
+            //if (GLAD_GL_ARB_vertex_array_object) // Use GL_ARB_vertex_array_object
+        #endif
+    }
+    
     // Enables GPU v-sync, so frames are not limited to screen refresh rate (60Hz -> 60 FPS)
     // If not set, swap interval uses GPU v-sync configuration
     // Framerate can be setup using SetTargetFPS()

File diff suppressed because it is too large
+ 9 - 0
src/glad.c


File diff suppressed because it is too large
+ 9 - 0
src/glad.h


+ 1 - 2
src/raymath.h

@@ -170,6 +170,7 @@ RMDEF void QuaternionTransform(Quaternion *q, Matrix mat);            // Transfo
 
 #endif  // notdef RAYMATH_EXTERN_INLINE
 
+#endif  // RAYMATH_H
 //////////////////////////////////////////////////////////////////// end of header file
 
 #if defined(RAYMATH_IMPLEMENTATION) || defined(RAYMATH_EXTERN_INLINE)
@@ -1096,5 +1097,3 @@ RMDEF void QuaternionTransform(Quaternion *q, Matrix mat)
 }
 
 #endif  // RAYMATH_IMPLEMENTATION
-
-#endif  // RAYMATH_H

+ 6 - 56
src/rlgl.c

@@ -43,13 +43,12 @@
 #endif
 
 #if defined(GRAPHICS_API_OPENGL_33)
-    #define GLEW_STATIC
     #ifdef __APPLE__                // OpenGL include for OSX
         #include <OpenGL/gl3.h>
     #else
-        #include <GL/glew.h>        // GLEW extensions loading lib
-        //#include "glad.h"         // glad extensions loading lib: ERRORS: windows.h
-        //#include "gl_core_3_3.h"  // glLoadGen extension loading lib: ERRORS: windows.h
+        //#define GLEW_STATIC
+        //#include <GL/glew.h>        // GLEW header, includes OpenGL headers
+        #include "glad.h"         // glad header, includes OpenGL headers
     #endif
 #endif
 
@@ -896,59 +895,10 @@ void rlglInit(void)
     
 #if defined(GRAPHICS_API_OPENGL_33)
 
-#define GLEW_EXTENSIONS_LOADER
-#if defined(GLEW_EXTENSIONS_LOADER)
-    // Initialize extensions using GLEW
-    glewExperimental = 1;       // Needed for core profile
-    GLenum error = glewInit();
-    
-    if (error != GLEW_OK) TraceLog(ERROR, "Failed to initialize GLEW - Error Code: %s\n", glewGetErrorString(error));
-    
-    if (glewIsSupported("GL_VERSION_3_3"))
-    {
-        TraceLog(INFO, "OpenGL 3.3 Core profile supported");
-        
-        vaoSupported = true;
-        npotSupported = true;
-    }
-    else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported");
-
-    // With GLEW, we can check if an extension has been loaded in two ways:
-    //if (GLEW_ARB_vertex_array_object) { } 
-    //if (glewIsSupported("GL_ARB_vertex_array_object")) { }
-
-    // NOTE: GLEW is a big library that loads ALL extensions, we can use some alternative to load only required ones
-    // Alternatives: glLoadGen, glad, libepoxy
-    
-#elif defined(GLAD_EXTENSIONS_LOADER)
-    // NOTE: glad is generated and contains only required OpenGL version and core extensions
-    //if (!gladLoadGL()) TraceLog(ERROR, "Failed to initialize glad\n");
-    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) TraceLog(ERROR, "Failed to initialize glad\n"); // No GLFW3 in this module...
-
-    if (GLAD_GL_VERSION_3_3)
-    {
-        TraceLog(INFO, "OpenGL 3.3 Core profile supported");
-        
-        vaoSupported = true;
-        npotSupported = true;
-    }
-    else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported");
-    
-    // With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
-    //if (GLAD_GL_ARB_vertex_array_object) // Use GL_ARB_vertex_array_object
+    // NOTE: On OpenGL 3.3 VAO and NPOT are supported by default
+    vaoSupported = true;
+    npotSupported = true;
 
-#elif defined(GLLOADGEN_EXTENSIONS_LOADER)
-    // NOTE: glLoadGen already generates a header with required OpenGL version and core extensions
-    if (ogl_LoadFunctions() != ogl_LOAD_FAILED)
-    {
-        TraceLog(INFO, "OpenGL 3.3 Core profile supported");
-        
-        vaoSupported = true;
-        npotSupported = true;
-    }
-    else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported");
-#endif
-    
     // NOTE: We don't need to check again supported extensions but we do (in case GLEW is replaced sometime)
     // We get a list of available extensions and we check for some of them (compressed textures)
     glGetIntegerv(GL_NUM_EXTENSIONS, &numExt);

+ 13 - 9
src/rlgl.h

@@ -36,12 +36,7 @@
     #include "utils.h"          // Required for function TraceLog()
 #endif
 
-#if defined(RLGL_STANDALONE)
-    #define RAYMATH_IMPLEMENTATION  // Use raymath as a header-only library (includes implementation)
-    #define RAYMATH_EXTERN_INLINE   // Compile raymath functions as static inline (remember, it's a compiler hint)
-    #define RAYMATH_STANDALONE      // Not dependent on raylib.h structs: Vector3, Matrix
-    #include "raymath.h"            // Required for Vector3 and Matrix functions
-#endif
+#include "raymath.h"
 
 // Select desired OpenGL version
 // NOTE: Those preprocessor defines are only used on rlgl module,
@@ -131,6 +126,12 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
         COMPRESSED_ASTC_4x4_RGBA,       // 8 bpp
         COMPRESSED_ASTC_8x8_RGBA        // 2 bpp
     } TextureFormat;
+    
+    // Bounding box type
+    typedef struct BoundingBox {
+        Vector3 min;
+        Vector3 max;
+    } BoundingBox;
 
     // Mesh with vertex data type
     // NOTE: If using OpenGL 1.1, data loaded in CPU; if OpenGL 3.3+ data loaded in GPU (vaoId)
@@ -177,10 +178,13 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
     } Shader;
 
     // Texture2D type
+    // NOTE: Data stored in GPU memory
     typedef struct Texture2D {
-        unsigned int id;            // Texture id
-        int width;
-        int height;
+        unsigned int id;        // OpenGL texture id
+        int width;              // Texture base width
+        int height;             // Texture base height
+        int mipmaps;            // Mipmap levels, 1 by default
+        int format;             // Data format (TextureFormat)
     } Texture2D;
     
     // 3d Model type

Some files were not shown because too many files changed in this diff