From 66aef3c7546d71cc28ec0aaac2e434363fbaf709 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 11 Jun 2023 14:59:51 +0200 Subject: [PATCH 1/3] Continuation of support for ES3/WebGL2 --- src/Makefile | 3 ++- src/rlgl.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index c6cd30e812aa..808ca8b7bf4b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -245,7 +245,8 @@ ifeq ($(PLATFORM),PLATFORM_DRM) endif ifeq ($(PLATFORM),PLATFORM_WEB) # On HTML5 OpenGL ES 2.0 is used, emscripten translates it to WebGL 1.0 - GRAPHICS = GRAPHICS_API_OPENGL_ES2 + #GRAPHICS = GRAPHICS_API_OPENGL_ES2 + GRAPHICS = GRAPHICS_API_OPENGL_ES3 # Uncomment to use ES3/WebGL2 (preliminary support). endif ifeq ($(PLATFORM),PLATFORM_ANDROID) # By default use OpenGL ES 2.0 on Android diff --git a/src/rlgl.h b/src/rlgl.h index 5ba2593f256c..8c101a79cea2 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -148,7 +148,8 @@ !defined(GRAPHICS_API_OPENGL_21) && \ !defined(GRAPHICS_API_OPENGL_33) && \ !defined(GRAPHICS_API_OPENGL_43) && \ - !defined(GRAPHICS_API_OPENGL_ES2) + !defined(GRAPHICS_API_OPENGL_ES2) && \ + !defined(GRAPHICS_API_OPENGL_ES3) #define GRAPHICS_API_OPENGL_33 #endif @@ -1711,7 +1712,7 @@ void rlDisableFramebuffer(void) // NOTE: One color buffer is always active by default void rlActiveDrawBuffers(int count) { -#if (defined(GRAPHICS_API_OPENGL_33) && defined(RLGL_RENDER_TEXTURES_HINT)) +#if ((defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES3)) && defined(RLGL_RENDER_TEXTURES_HINT)) // NOTE: Maximum number of draw buffers supported is implementation dependant, // it can be queried with glGet*() but it must be at least 8 //GLint maxDrawBuffers = 0; @@ -1723,6 +1724,16 @@ void rlActiveDrawBuffers(int count) else { unsigned int buffers[8] = { +#if defined(GRAPHICS_API_OPENGL_ES3) + GL_COLOR_ATTACHMENT0_EXT, + GL_COLOR_ATTACHMENT1_EXT, + GL_COLOR_ATTACHMENT2_EXT, + GL_COLOR_ATTACHMENT3_EXT, + GL_COLOR_ATTACHMENT4_EXT, + GL_COLOR_ATTACHMENT5_EXT, + GL_COLOR_ATTACHMENT6_EXT, + GL_COLOR_ATTACHMENT7_EXT, +#else GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, @@ -1731,9 +1742,14 @@ void rlActiveDrawBuffers(int count) GL_COLOR_ATTACHMENT5, GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7, +#endif }; +#if defined(GRAPHICS_API_OPENGL_ES3) + glDrawBuffersEXT(count, buffers); +#else glDrawBuffers(count, buffers); +#endif } } else TRACELOG(LOG_WARNING, "GL: One color buffer active by default"); @@ -2201,7 +2217,29 @@ void rlLoadExtensions(void *loader) #endif // GRAPHICS_API_OPENGL_33 -#if defined(GRAPHICS_API_OPENGL_ES2) +#if defined(GRAPHICS_API_OPENGL_ES3) + // Register supported extensions flags + // OpenGL ES 3.0 extensions supported by default + RLGL.ExtSupported.vao = true; + RLGL.ExtSupported.instancing = true; + RLGL.ExtSupported.texNPOT = true; + RLGL.ExtSupported.texFloat32 = true; + RLGL.ExtSupported.texDepth = true; + RLGL.ExtSupported.texDepthWebGL = true; + RLGL.ExtSupported.maxDepthBits = 24; + RLGL.ExtSupported.texAnisoFilter = true; + RLGL.ExtSupported.texMirrorClamp = true; + // TODO: Make sure that the ones above are actually present by default + // TODO: Check for these... + // RLGL.ExtSupported.texCompDXT + // RLGL.ExtSupported.texCompETC1 + // RLGL.ExtSupported.texCompETC2 + // RLGL.ExtSupported.texCompPVRT + // RLGL.ExtSupported.texCompASTC + // RLGL.ExtSupported.computeShader + // RLGL.ExtSupported.ssbo + // RLGL.ExtSupported.maxAnisotropyLevel +#elif defined(GRAPHICS_API_OPENGL_ES2) #if defined(PLATFORM_DESKTOP) // TODO: Support OpenGL ES 3.0 @@ -3057,7 +3095,7 @@ unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer) // Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F unsigned int glInternalFormat = GL_DEPTH_COMPONENT; -#if defined(GRAPHICS_API_OPENGL_ES2) +#if (defined(GRAPHICS_API_OPENGL_ES2) || defined(GRAPHICS_API_OPENGL_ES3)) // WARNING: WebGL platform requires unsized internal format definition (GL_DEPTH_COMPONENT) // while other platforms using OpenGL ES 2.0 require/support sized internal formats depending on the GPU capabilities if (!RLGL.ExtSupported.texDepthWebGL || useRenderBuffer) @@ -3214,10 +3252,16 @@ void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned case RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: *glInternalFormat = GL_RGBA; *glFormat = GL_RGBA; *glType = GL_UNSIGNED_SHORT_4_4_4_4; break; case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: *glInternalFormat = GL_RGBA; *glFormat = GL_RGBA; *glType = GL_UNSIGNED_BYTE; break; #if !defined(GRAPHICS_API_OPENGL_11) + #if defined(GRAPHICS_API_OPENGL_ES3) + case RL_PIXELFORMAT_UNCOMPRESSED_R32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_R32F_EXT; *glFormat = GL_RED_EXT; *glType = GL_FLOAT; break; + case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGB32F_EXT; *glFormat = GL_RGB; *glType = GL_FLOAT; break; + case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGBA32F_EXT; *glFormat = GL_RGBA; *glType = GL_FLOAT; break; + #else case RL_PIXELFORMAT_UNCOMPRESSED_R32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_LUMINANCE; *glFormat = GL_LUMINANCE; *glType = GL_FLOAT; break; // NOTE: Requires extension OES_texture_float case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGB; *glFormat = GL_RGB; *glType = GL_FLOAT; break; // NOTE: Requires extension OES_texture_float case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGBA; *glFormat = GL_RGBA; *glType = GL_FLOAT; break; // NOTE: Requires extension OES_texture_float #endif + #endif #elif defined(GRAPHICS_API_OPENGL_33) case RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: *glInternalFormat = GL_R8; *glFormat = GL_RED; *glType = GL_UNSIGNED_BYTE; break; case RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: *glInternalFormat = GL_RG8; *glFormat = GL_RG; *glType = GL_UNSIGNED_BYTE; break; From f45e0cf5a804c57ff2396987fd1df85ac631e962 Mon Sep 17 00:00:00 2001 From: chemguerra Date: Sun, 11 Jun 2023 15:51:00 +0200 Subject: [PATCH 2/3] GetTouchPointState() --- src/Makefile | 3 ++- src/raylib.h | 1 + src/rcore.c | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 808ca8b7bf4b..21b343d15427 100644 --- a/src/Makefile +++ b/src/Makefile @@ -345,7 +345,8 @@ endif ifeq ($(RAYLIB_BUILD_MODE),RELEASE) ifeq ($(PLATFORM),PLATFORM_WEB) - CFLAGS += -Os + #CFLAGS += -Os + CFLAGS += -O3 endif ifeq ($(PLATFORM),PLATFORM_DESKTOP) CFLAGS += -O1 diff --git a/src/raylib.h b/src/raylib.h index f6a48bc736d7..ad920ed48398 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1149,6 +1149,7 @@ RLAPI int GetTouchX(void); // Get touch posit RLAPI int GetTouchY(void); // Get touch position Y for touch point 0 (relative to screen size) RLAPI Vector2 GetTouchPosition(int index); // Get touch position XY for a touch point index (relative to screen size) RLAPI int GetTouchPointId(int index); // Get touch point identifier for given index +RLAPI bool GetTouchPointState(int index); // Patch for touch events in web browsers RLAPI int GetTouchPointCount(void); // Get number of touch points //------------------------------------------------------------------------------------ diff --git a/src/rcore.c b/src/rcore.c index ee682e8b09b4..5cbdade449ae 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -4022,6 +4022,11 @@ int GetTouchPointId(int index) return id; } +bool GetTouchPointState(int index) +{ + return ( (index < MAX_TOUCH_POINTS) && (CORE.Input.Touch.currentTouchState[index] != 0) ); +} + // Get number of touch points int GetTouchPointCount(void) { From c0bcf2d671edf84008f3a99c557809b6a4ab5c33 Mon Sep 17 00:00:00 2001 From: chemguerra Date: Mon, 12 Jun 2023 06:57:55 +0200 Subject: [PATCH 3/3] Amends to the WebGL2 PR --- src/Makefile | 7 +++---- src/raylib.h | 1 - src/rcore.c | 5 ----- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Makefile b/src/Makefile index 21b343d15427..fc4c5b0c721c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -245,8 +245,8 @@ ifeq ($(PLATFORM),PLATFORM_DRM) endif ifeq ($(PLATFORM),PLATFORM_WEB) # On HTML5 OpenGL ES 2.0 is used, emscripten translates it to WebGL 1.0 - #GRAPHICS = GRAPHICS_API_OPENGL_ES2 - GRAPHICS = GRAPHICS_API_OPENGL_ES3 # Uncomment to use ES3/WebGL2 (preliminary support). + GRAPHICS = GRAPHICS_API_OPENGL_ES2 + #GRAPHICS = GRAPHICS_API_OPENGL_ES3 # Uncomment to use ES3/WebGL2 (preliminary support). endif ifeq ($(PLATFORM),PLATFORM_ANDROID) # By default use OpenGL ES 2.0 on Android @@ -345,8 +345,7 @@ endif ifeq ($(RAYLIB_BUILD_MODE),RELEASE) ifeq ($(PLATFORM),PLATFORM_WEB) - #CFLAGS += -Os - CFLAGS += -O3 + CFLAGS += -Os endif ifeq ($(PLATFORM),PLATFORM_DESKTOP) CFLAGS += -O1 diff --git a/src/raylib.h b/src/raylib.h index ad920ed48398..f6a48bc736d7 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1149,7 +1149,6 @@ RLAPI int GetTouchX(void); // Get touch posit RLAPI int GetTouchY(void); // Get touch position Y for touch point 0 (relative to screen size) RLAPI Vector2 GetTouchPosition(int index); // Get touch position XY for a touch point index (relative to screen size) RLAPI int GetTouchPointId(int index); // Get touch point identifier for given index -RLAPI bool GetTouchPointState(int index); // Patch for touch events in web browsers RLAPI int GetTouchPointCount(void); // Get number of touch points //------------------------------------------------------------------------------------ diff --git a/src/rcore.c b/src/rcore.c index 5cbdade449ae..ee682e8b09b4 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -4022,11 +4022,6 @@ int GetTouchPointId(int index) return id; } -bool GetTouchPointState(int index) -{ - return ( (index < MAX_TOUCH_POINTS) && (CORE.Input.Touch.currentTouchState[index] != 0) ); -} - // Get number of touch points int GetTouchPointCount(void) {