Browse Source

OpenGLES 2.0 support on PLATFORM_DESKTOP (#2840)

* OpenGLES 2.0 support on PLATFORM_DESKTOP

* exmples raylib_opengl_interop desktop GLES2 support

* rename gles2.h -> glad_gles2.h
Go Watanabe 2 years ago
parent
commit
f549f67be9

+ 1 - 1
cmake/LibraryConfigurations.cmake

@@ -93,7 +93,7 @@ elseif ("${PLATFORM}" MATCHES "DRM")
 
 
 endif ()
 endif ()
 
 
-if (${OPENGL_VERSION})
+if (NOT ${OPENGL_VERSION})
     set(${SUGGESTED_GRAPHICS} "${GRAPHICS}")
     set(${SUGGESTED_GRAPHICS} "${GRAPHICS}")
     if (${OPENGL_VERSION} MATCHES "4.3")
     if (${OPENGL_VERSION} MATCHES "4.3")
 		set(GRAPHICS "GRAPHICS_API_OPENGL_43")
 		set(GRAPHICS "GRAPHICS_API_OPENGL_43")

File diff suppressed because it is too large
+ 21 - 0
examples/others/external/include/glad_gles2.h


+ 20 - 10
examples/others/raylib_opengl_interop.c

@@ -26,21 +26,29 @@
 
 
 #include "raylib.h"
 #include "raylib.h"
 
 
-#include "rlgl.h"           // Required for: rlDrawRenderBatchActive(), rlGetMatrixModelview(), rlGetMatrixProjection()
-#if defined(__APPLE__)
-    #include <OpenGL/gl3.h>     // OpenGL 3 library for OSX
-    #include <OpenGL/gl3ext.h>  // OpenGL 3 extensions library for OSX
-#else
-    #include "glad.h"       // Required for: OpenGL functionality 
-#endif
-#include "raymath.h"        // Required for: MatrixMultiply(), MatrixToFloat()
-
 #if defined(PLATFORM_DESKTOP)
 #if defined(PLATFORM_DESKTOP)
-    #define GLSL_VERSION            330
+    #if defined(GRAPHICS_API_OPENGL_ES2)
+        #include "glad_gles2.h"       // Required for: OpenGL functionality 
+        #define glGenVertexArrays glGenVertexArraysOES
+        #define glBindVertexArray glBindVertexArrayOES
+        #define glDeleteVertexArrays glDeleteVertexArraysOES
+        #define GLSL_VERSION            100
+    #else
+        #if defined(__APPLE__)
+            #include <OpenGL/gl3.h>     // OpenGL 3 library for OSX
+            #include <OpenGL/gl3ext.h>  // OpenGL 3 extensions library for OSX
+        #else
+            #include "glad.h"       // Required for: OpenGL functionality 
+        #endif
+        #define GLSL_VERSION            330
+    #endif
 #else   // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
 #else   // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
     #define GLSL_VERSION            100
     #define GLSL_VERSION            100
 #endif
 #endif
 
 
+#include "rlgl.h"           // Required for: rlDrawRenderBatchActive(), rlGetMatrixModelview(), rlGetMatrixProjection()
+#include "raymath.h"        // Required for: MatrixMultiply(), MatrixToFloat()
+
 #define MAX_PARTICLES       1000
 #define MAX_PARTICLES       1000
 
 
 // Particle type
 // Particle type
@@ -97,7 +105,9 @@ int main(void)
     glBindVertexArray(0);
     glBindVertexArray(0);
 
 
     // Allows the vertex shader to set the point size of each particle individually
     // Allows the vertex shader to set the point size of each particle individually
+    #ifndef GRAPHICS_API_OPENGL_ES2
     glEnable(GL_PROGRAM_POINT_SIZE);
     glEnable(GL_PROGRAM_POINT_SIZE);
+    #endif
 
 
     SetTargetFPS(60);
     SetTargetFPS(60);
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------

File diff suppressed because it is too large
+ 21 - 0
src/external/glad_gles2.h


+ 12 - 0
src/rlgl.h

@@ -789,10 +789,16 @@ RLAPI void rlLoadDrawQuad(void);     // Load and draw a quad
 #endif
 #endif
 
 
 #if defined(GRAPHICS_API_OPENGL_ES2)
 #if defined(GRAPHICS_API_OPENGL_ES2)
+
+    #if defined(PLATFORM_DESKTOP)
+    #define GLAD_GLES2_IMPLEMENTATION
+    #include "external/glad_gles2.h"
+    #else
     #define GL_GLEXT_PROTOTYPES
     #define GL_GLEXT_PROTOTYPES
     //#include <EGL/egl.h>              // EGL library -> not required, platform layer
     //#include <EGL/egl.h>              // EGL library -> not required, platform layer
     #include <GLES2/gl2.h>              // OpenGL ES 2.0 library
     #include <GLES2/gl2.h>              // OpenGL ES 2.0 library
     #include <GLES2/gl2ext.h>           // OpenGL ES 2.0 extensions library
     #include <GLES2/gl2ext.h>           // OpenGL ES 2.0 extensions library
+    #endif
 
 
     // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
     // It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
     // provided headers (despite being defined in official Khronos GLES2 headers)
     // provided headers (despite being defined in official Khronos GLES2 headers)
@@ -2144,6 +2150,12 @@ void rlLoadExtensions(void *loader)
 #endif  // GRAPHICS_API_OPENGL_33
 #endif  // GRAPHICS_API_OPENGL_33
 
 
 #if defined(GRAPHICS_API_OPENGL_ES2)
 #if defined(GRAPHICS_API_OPENGL_ES2)
+
+    #if defined(PLATFORM_DESKTOP)
+    if (gladLoadGLES2((GLADloadfunc)loader) == 0) TRACELOG(RL_LOG_WARNING, "GLAD: Cannot load OpenGL ES2.0 functions");
+    else TRACELOG(RL_LOG_INFO, "GLAD: OpenGL ES2.0 loaded successfully");
+    #endif
+
     // Get supported extensions list
     // Get supported extensions list
     GLint numExt = 0;
     GLint numExt = 0;
     const char **extList = RL_MALLOC(512*sizeof(const char *)); // Allocate 512 strings pointers (2 KB)
     const char **extList = RL_MALLOC(512*sizeof(const char *)); // Allocate 512 strings pointers (2 KB)

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