Skip to content

Commit

Permalink
[GLES] Added GLES 3.1/3.2 extensions and fixed initialization of EGL …
Browse files Browse the repository at this point in the history
…context.

- Created shared EGL surface since Android apps only have a single window and we need a valid surface before making the EGL context current.
- Added majority of GLES 3.1 and 3.2 extensions.
- Added "LLGL_GL_ENABLE_OPENGLES" CMake property to select GLES versions 3.0, 3.1, 3.2.
- Added '--gles=VER' argument to BuildAndroid.sh script to select GLES version.
- Deprecated struct RendererConfigurationOpenGLES3 and redirected to RendererConfigurationOpenGL.
- Used more '#if' preprocessor conditions than '#ifdef'/'#if defined' since most GL version constants are defined with value 1.
  • Loading branch information
LukasBanana committed Aug 3, 2024
1 parent 861116e commit d1e3dec
Show file tree
Hide file tree
Showing 25 changed files with 568 additions and 166 deletions.
27 changes: 23 additions & 4 deletions BuildAndroid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GENERATOR="CodeBlocks - Unix Makefiles"
ANDROID_ABI=x86_64
ANDROID_API_LEVEL=21
SUPPORTED_ANDROID_ABIS=("arm64-v8a" "armeabi-v7a" "x86" "x86_64")
GLES_VER="OpenGLES 3.0"
BUILD_APPS=0

print_help()
Expand All @@ -32,6 +33,7 @@ print_help()
echo " --abi=ABI ................. Set Android ABI (default is x86_64; accepts 'all')"
echo " --api-level=VERSION ....... Set Android API level (default is 21)"
echo " --apps .................... Generate Android Studio projects to build example apps (implies '--abi=all -s')"
echo " --gles=VER ................ Enables the maximum OpenGLES version: 300 (default), 310, or 320"
echo " --vulkan .................. Include Vulkan renderer"
echo " --no-examples ............. Exclude example projects"
echo "NOTES:"
Expand Down Expand Up @@ -64,6 +66,14 @@ for ARG in "$@"; do
ANDROID_ABI="${ARG:6}"
elif [[ "$ARG" == --api-level=* ]]; then
ANDROID_API_LEVEL=${ARG:12}
elif [[ "$ARG" == --gles=* ]]; then
GLES_VER_NO=${ARG:7}
case $GLES_VER_NO in
320) GLES_VER="OpenGLES 3.2" ;;
310) GLES_VER="OpenGLES 3.1" ;;
300) GLES_VER="OpenGLES 3.0" ;;
*) echo "Unknown GLES version: $GLES_VER_NO; Must be 320, 310, or 300"; exit 1 ;;
esac
elif [ "$ARG" = "--vulkan" ]; then
ENABLE_VULKAN="ON"
elif [ "$ARG" = "--no-examples" ]; then
Expand Down Expand Up @@ -154,6 +164,7 @@ BASE_OPTIONS=(
-DANDROID_STL=$ANDROID_CXX_LIB
-DANDROID_CPP_FEATURES="rtti exceptions"
-DLLGL_BUILD_RENDERER_OPENGLES3=ON
-DLLGL_GL_ENABLE_OPENGLES=$GLES_VER
-DLLGL_BUILD_RENDERER_NULL=$ENABLE_NULL
-DLLGL_BUILD_RENDERER_VULKAN=$ENABLE_VULKAN
-DLLGL_BUILD_EXAMPLES=$ENABLE_EXAMPLES
Expand Down Expand Up @@ -272,11 +283,19 @@ generate_app_project()
fi

# Find all shaders and copy them into app folder
for FILE in $PROJECT_SOURCE_DIR/*.vert $PROJECT_SOURCE_DIR/*.frag $PROJECT_SOURCE_DIR/*.spv; do
if [ $VERBOSE -eq 1 ]; then
echo "Copy shader: $(basename $FILE)"
for FILE in $PROJECT_SOURCE_DIR/*.vert \
$PROJECT_SOURCE_DIR/*.geom \
$PROJECT_SOURCE_DIR/*.tesc \
$PROJECT_SOURCE_DIR/*.tese \
$PROJECT_SOURCE_DIR/*.frag \
$PROJECT_SOURCE_DIR/*.comp \
$PROJECT_SOURCE_DIR/*.spv; do
if [ -f "$FILE" ]; then
if [ $VERBOSE -eq 1 ]; then
echo "Copy shader: $(basename $FILE)"
fi
cp "$FILE" "$ASSET_DIR/$(basename $FILE)"
fi
cp "$FILE" "$ASSET_DIR/$(basename $FILE)"
done
}

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ if(LLGL_BUILD_RENDERER_OPENGL)
endif()

if(LLGL_BUILD_RENDERER_OPENGLES3)
message(STATUS "Build Renderer: OpenGLES 3")
message(STATUS "Build Renderer: ${LLGL_GL_ENABLE_OPENGLES}")
endif()

if(LLGL_BUILD_RENDERER_VULKAN)
Expand Down
3 changes: 1 addition & 2 deletions include/LLGL/RenderSystemFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ struct RenderSystemDescriptor
\see rendererConfigSize
\see RendererConfigurationVulkan
\see RendererConfigurationOpenGL
\see RendererConfigurationOpenGLES3
*/
const void* rendererConfig = nullptr;

Expand Down Expand Up @@ -851,7 +850,7 @@ struct RenderingCapabilities
/**
\brief Screen coordinate system origin.
\remarks This determines the native coordinate space of viewports, scissors, and framebuffers.
If the native screen origin is lower-left, LLGL emulates it to always maintain the upper-left as the screen origin.
If the native screen origin is in the bottom-left corner, LLGL emulates it to always maintain the upper-left corner as its screen origin.
*/
ScreenOrigin screenOrigin = ScreenOrigin::UpperLeft;

Expand Down
36 changes: 21 additions & 15 deletions include/LLGL/RendererConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


#include <LLGL/Container/ArrayView.h>
#include <LLGL/Deprecated.h>
#include <LLGL/Platform/Platform.h>
#include <cstdint>


Expand All @@ -36,6 +38,16 @@ enum class OpenGLContextProfile
\note Only supported on: Android and iOS.
*/
ESProfile,

/**
\brief Default GL profile.
\remarks This is equivalent to CoreProfile for OpenGL and ESProfile for OpenGLES.
*/
#if defined(LLGL_OS_ANDROID) || defined(LLGL_OS_IOS)
DefaultProfile = ESProfile,
#else
DefaultProfile = CoreProfile,
#endif
};


Expand Down Expand Up @@ -100,13 +112,16 @@ struct RendererConfigurationVulkan
};

/**
\brief OpenGL profile descriptor structure.
\brief OpenGL/OpenGLES profile descriptor structure.
\note On MacOS the only supported OpenGL profiles are compatibility profile (for lagecy OpenGL before 3.0), 3.2 core profile, or 4.1 core profile.
*/
struct RendererConfigurationOpenGL
{
//! Specifies the requested OpenGL context profile. By default OpenGLContextProfile::CoreProfile.
OpenGLContextProfile contextProfile = OpenGLContextProfile::CoreProfile;
/**
\brief Specifies the requested OpenGL context profile. By default OpenGLContextProfile::DefaultProfile.
\remarks The default value is either equivalent to OpenGLContextProfile::CoreProfile for OpenGL or OpenGLContextProfile::ESProfile for OpenGLES.
*/
OpenGLContextProfile contextProfile = OpenGLContextProfile::DefaultProfile;

/**
\brief Specifies the requested OpenGL context major version. By default 0.
Expand All @@ -130,18 +145,9 @@ struct RendererConfigurationOpenGL
bool suppressFailedExtensions = false;
};

/**
\brief OpenGL ES 3 profile descriptor structure.
\todo Replace with RendererConfigurationOpenGL and make use of OpenGLContextProfile::ESProfile.
*/
struct RendererConfigurationOpenGLES3
{
//! Specifies the requested OpenGL ES context major version. Must be 3. By default 3.
int majorVersion = 3;

//! Specifies the requested OpenGL ES context minor version. Must be 0, 1, or 2. By default 0.
int minorVersion = 0;
};
//! \deprecated Since 0.04b; Use RendererConfigurationOpenGL instead!
LLGL_DEPRECATED("LLGL::RendererConfigurationOpenGLES3 is deprecated since 0.04b; Use LLGL::RendererConfigurationOpenGL instead!", "RendererConfigurationOpenGL")
typedef RendererConfigurationOpenGL RendererConfigurationOpenGLES3;


} // /namespace LLGL
Expand Down
18 changes: 18 additions & 0 deletions sources/Renderer/OpenGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ project(LLGL_OpenGL)

# === Options ===

if(LLGL_BUILD_RENDERER_OPENGLES3)
set(LLGL_GL_ENABLE_OPENGLES "OpenGLES 3.0" CACHE STRING "Enable maximum OpenGLES version to include (requires <GLES3/gl3.h>, <GLES3/gl31.h>, or <GLES3/gl32.h> header files")
set_property(CACHE LLGL_GL_ENABLE_OPENGLES PROPERTY STRINGS "OpenGLES 3.0" "OpenGLES 3.1" "OpenGLES 3.2")
endif()

option(LLGL_GL_ENABLE_VENDOR_EXT "Enable vendor specific OpenGL extensions (e.g. GL_NV_..., GL_AMD_... etc.)" ON)
option(LLGL_GL_ENABLE_DSA_EXT "Enable OpenGL direct state access (DSA) extension if available" ON)
option(LLGL_GL_ENABLE_OPENGL2X "Enable support for OpenGL 2.x compatibility profile" OFF)
Expand All @@ -29,6 +34,19 @@ if(LLGL_GL_ENABLE_OPENGL2X)
ADD_DEFINE(LLGL_GL_ENABLE_OPENGL2X)
endif()

if(LLGL_BUILD_RENDERER_OPENGLES3)
if(${LLGL_GL_ENABLE_OPENGLES} STREQUAL "OpenGLES 3.2")
ADD_DEFINE(LLGL_GL_ENABLE_OPENGLES=320)
elseif(${LLGL_GL_ENABLE_OPENGLES} STREQUAL "OpenGLES 3.1")
ADD_DEFINE(LLGL_GL_ENABLE_OPENGLES=310)
elseif(${LLGL_GL_ENABLE_OPENGLES} STREQUAL "OpenGLES 3.0")
ADD_DEFINE(LLGL_GL_ENABLE_OPENGLES=300)
else()
message(SEND_ERROR "Unknown OpenGLES version: ${LLGL_GL_ENABLE_OPENGLES}")
message("Accepted values for LLGL_GL_ENABLE_OPENGLES are: 'OpenGLES 3.0', 'OpenGLES 3.1', or 'OpenGLES 3.2'")
endif()
endif()


# === Source files ===

Expand Down
10 changes: 5 additions & 5 deletions sources/Renderer/OpenGL/GLCoreProfile/GLCoreExtensionLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ static GLExtensionMap QuerySupportedOpenGLExtensions(bool isCoreProfile)
/* Filter standard GL extensions */
if (isCoreProfile)
{
#if defined(GL_VERSION_3_0) && !defined(GL_GLEXT_PROTOTYPES)
#if GL_VERSION_3_0 && !GL_GLEXT_PROTOTYPES

#ifndef __APPLE__
if (glGetStringi || LoadGLProc(glGetStringi, "glGetStringi"))
Expand All @@ -905,7 +905,7 @@ static GLExtensionMap QuerySupportedOpenGLExtensions(bool isCoreProfile)
for_range(i, numExtensions)
{
/* Get current extension string */
if (auto extString = reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i)))
if (const char* extString = reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i)))
extensions[extString] = false;
}
}
Expand All @@ -915,16 +915,16 @@ static GLExtensionMap QuerySupportedOpenGLExtensions(bool isCoreProfile)
else
{
/* Get complete extension string */
if (auto extString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)))
if (const char* extString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)))
ExtractExtensionsFromString(extensions, extString);
}

#if defined(_WIN32) && defined(WGL_ARB_extensions_string)
#if defined(_WIN32) && WGL_ARB_extensions_string

/* Filter Win32 related extensions */
if (wglGetExtensionsStringARB != nullptr || LoadGLProc(wglGetExtensionsStringARB, "wglGetExtensionsStringARB"))
{
if (auto extString = wglGetExtensionsStringARB(::wglGetCurrentDC()))
if (const char* extString = wglGetExtensionsStringARB(::wglGetCurrentDC()))
ExtractExtensionsFromString(extensions, extString);
}

Expand Down
1 change: 0 additions & 1 deletion sources/Renderer/OpenGL/GLCoreProfile/GLCoreExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace LLGL
{



#define DECL_GLPROC(PFNTYPE, NAME, RTYPE, ARGS) \
extern PFNTYPE NAME

Expand Down
7 changes: 7 additions & 0 deletions sources/Renderer/OpenGL/GLCoreProfile/GLCoreExtensionsProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_GL_EXTENSIONS_PROXY_H
#define LLGL_GL_EXTENSIONS_PROXY_H


#include "../OpenGL.h"


Expand All @@ -24,5 +28,8 @@ namespace LLGL
} // /namespace LLGL


#endif



// ================================================================================
Loading

0 comments on commit d1e3dec

Please sign in to comment.