Move extensions loading to core module
This commit is contained in:
parent
882e2abee1
commit
23d66e9b6f
2 changed files with 44 additions and 56 deletions
39
src/core.c
39
src/core.c
|
@ -54,8 +54,13 @@
|
||||||
#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
|
#define GLEW_STATIC
|
||||||
|
#include <GL/glew.h> // GLEW extensions loading lib
|
||||||
|
//#include "glad.h" // GLAD library: Manage OpenGL headers and extensions
|
||||||
|
|
||||||
//#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
|
//#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
|
||||||
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
#define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting
|
#define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting
|
||||||
#define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window
|
#define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window
|
||||||
|
@ -1378,6 +1383,40 @@ static void InitDisplay(int width, int height)
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
// Extensions initialization for OpenGL 3.3
|
||||||
|
if (rlGetVersion() == 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");
|
||||||
|
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)
|
// 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
|
// If not set, swap interval uses GPU v-sync configuration
|
||||||
// Framerate can be setup using SetTargetFPS()
|
// Framerate can be setup using SetTargetFPS()
|
||||||
|
|
61
src/rlgl.c
61
src/rlgl.c
|
@ -43,13 +43,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_33)
|
#if defined(GRAPHICS_API_OPENGL_33)
|
||||||
#define GLEW_STATIC
|
|
||||||
#ifdef __APPLE__ // OpenGL include for OSX
|
#ifdef __APPLE__ // OpenGL include for OSX
|
||||||
#include <OpenGL/gl3.h>
|
#include <OpenGL/gl3.h>
|
||||||
#else
|
#else
|
||||||
#include <GL/glew.h> // GLEW extensions loading lib
|
#include <GL/glew.h> // GLEW header, includes OpenGL headers
|
||||||
//#include "glad.h" // glad extensions loading lib: ERRORS: windows.h
|
//#include "glad.h" // glad header, includes OpenGL headers
|
||||||
//#include "gl_core_3_3.h" // glLoadGen extension loading lib: ERRORS: windows.h
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -896,58 +894,9 @@ void rlglInit(void)
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_33)
|
#if defined(GRAPHICS_API_OPENGL_33)
|
||||||
|
|
||||||
#define GLEW_EXTENSIONS_LOADER
|
// NOTE: On OpenGL 3.3 VAO and NPOT are supported by default
|
||||||
#if defined(GLEW_EXTENSIONS_LOADER)
|
vaoSupported = true;
|
||||||
// Initialize extensions using GLEW
|
npotSupported = true;
|
||||||
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
|
|
||||||
|
|
||||||
#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)
|
// 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)
|
// We get a list of available extensions and we check for some of them (compressed textures)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue