Skip to content

Commit

Permalink
deps: replace glew with glad
Browse files Browse the repository at this point in the history
  • Loading branch information
scribam committed Nov 10, 2023
1 parent 9268773 commit 989e81d
Show file tree
Hide file tree
Showing 46 changed files with 31,114 additions and 42,919 deletions.
61 changes: 26 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ if(NINTENDO_SWITCH)
set(CMAKE_STATIC_LIBRARY_PREFIX "")
else()
add_executable(${PROJECT_NAME} core/emulator.cpp)
target_compile_definitions(${PROJECT_NAME} PRIVATE EGL_NO_PLATFORM_SPECIFIC_TYPES)
endif()
if(USE_GLES)
target_compile_definitions(${PROJECT_NAME} PRIVATE GLES)
Expand Down Expand Up @@ -239,7 +238,7 @@ if(NOT "${SENTRY_UPLOAD_URL}" STREQUAL "")
target_compile_definitions(${PROJECT_NAME} PRIVATE SENTRY_UPLOAD="${SENTRY_UPLOAD_URL}")
endif()

target_include_directories(${PROJECT_NAME} PRIVATE core core/deps core/deps/stb core/deps/khronos core/deps/json)
target_include_directories(${PROJECT_NAME} PRIVATE core core/deps core/deps/stb core/deps/json)
if(LIBRETRO)
target_include_directories(${PROJECT_NAME} PRIVATE shell/libretro)
endif()
Expand Down Expand Up @@ -505,11 +504,6 @@ if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND NOT LIBRETRO)
endif()
endif()

if(NINTENDO_SWITCH AND USE_GLES)
pkg_check_modules(GLESV2 IMPORTED_TARGET glesv2)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::GLESV2)
endif()

if(UNIX AND NOT APPLE AND NOT ANDROID)
add_definitions(
-DFLYCAST_DATADIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/"
Expand All @@ -521,20 +515,9 @@ if(UNIX AND NOT APPLE AND NOT ANDROID)
if(USE_VIDEOCORE)
target_link_libraries(${PROJECT_NAME} PRIVATE "-lbrcmGLESv2")
target_link_directories(${PROJECT_NAME} PRIVATE "/opt/vc/lib")
else()
target_link_libraries(${PROJECT_NAME} PRIVATE GLESv2)
endif()
elseif(USE_GLES)
target_compile_definitions(${PROJECT_NAME} PRIVATE GLES GLES3)
if(NOT SDL2_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE EGL)
endif()
find_library(GLES3_LIBRARIES NAMES GLESv3 GLESv2 NO_CACHE REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${GLES3_LIBRARIES})
elseif(USE_OPENGL)
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)
endif()

find_package(Threads REQUIRED)
Expand All @@ -553,8 +536,6 @@ if(UNIX AND NOT APPLE AND NOT ANDROID)
target_include_directories(${PROJECT_NAME} PRIVATE ${X11_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${X11_LIBRARIES})
endif()
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE EGL_NO_X11)
endif()

find_library(LIBRT rt)
Expand Down Expand Up @@ -739,6 +720,11 @@ if(LIBRETRO)
core/deps/libretro-common/file/retro_dirent.c
core/deps/libretro-common/string/stdstring.c)
if(USE_OPENGL)
if(UNIX AND NOT APPLE AND NOT ANDROID)
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)
endif()

target_sources(${PROJECT_NAME} PRIVATE
core/deps/libretro-common/glsm/glsm.c
core/deps/libretro-common/glsym/rglgen.c)
Expand Down Expand Up @@ -1163,15 +1149,6 @@ if(USE_OPENGL)
core/wsi/xgl.cpp
core/wsi/xgl.h)

if(NOT APPLE AND NOT LIBRETRO)
target_sources(${PROJECT_NAME} PRIVATE
core/wsi/gl32funcs.c
core/wsi/gl32funcs.h)
endif()
if(NOT (NINTENDO_SWITCH AND LIBRETRO))
target_sources(${PROJECT_NAME} PRIVATE core/wsi/gl4funcs.cpp)
endif()

target_sources(${PROJECT_NAME} PRIVATE
core/rend/gles/glcache.h
core/rend/gles/gldraw.cpp
Expand Down Expand Up @@ -1491,6 +1468,24 @@ if("x86" IN_LIST ARCHITECTURE OR "x86_64" IN_LIST ARCHITECTURE)
endif()
endif()

if((USE_OPENGL OR USE_GLES2 OR USE_GLES) AND NOT LIBRETRO)
add_library(glad STATIC core/deps/glad/src/gl.c)
if(X11_FOUND)
target_sources(glad PRIVATE core/deps/glad/src/glx.c)
endif()
if(ANDROID OR USE_GLES2 OR USE_GLES)
target_sources(glad PRIVATE core/deps/glad/src/egl.c)
endif()
if(WIN32)
target_sources(glad PRIVATE core/deps/glad/src/wgl.c)
endif()
if(NINTENDO_SWITCH)
target_compile_definitions(glad PRIVATE EGL_NO_PLATFORM_SPECIFIC_TYPES)
endif()
target_include_directories(glad PUBLIC core/deps/glad/include)
target_link_libraries(${PROJECT_NAME} PRIVATE glad)
endif()

if(NOT LIBRETRO)
target_include_directories(${PROJECT_NAME} PRIVATE core/deps/ggpo/include core/deps/ggpo/lib/ggpo)
target_sources(${PROJECT_NAME} PRIVATE
Expand Down Expand Up @@ -1537,7 +1532,7 @@ if(NOT LIBRETRO)
shell/android-studio/flycast/src/main/jni/src/android_gamepad.h
shell/android-studio/flycast/src/main/jni/src/android_keyboard.h)

target_link_libraries(${PROJECT_NAME} PRIVATE android EGL GLESv2 log)
target_link_libraries(${PROJECT_NAME} PRIVATE android log)
elseif(APPLE)
string(TIMESTAMP YEAR "%Y")
string(REGEX MATCH "^[^-]+" TAG_VERSION ${GIT_VERSION})
Expand Down Expand Up @@ -1603,15 +1598,13 @@ if(NOT LIBRETRO)

find_library(UIKIT UIKit)
find_library(FOUNDATION Foundation)
find_library(OPENGLES OpenGLES)
find_library(GLKIT GLKit)
find_library(GAMECONTROLLER GameController)
find_library(AUDIOTOOLBOX AudioToolbox)
find_library(AVFOUNDATION AVFoundation)
target_link_libraries(${PROJECT_NAME} PRIVATE
${UIKIT}
${FOUNDATION}
${OPENGLES}
${GLKIT}
${GAMECONTROLLER}
${AUDIOTOOLBOX}
Expand Down Expand Up @@ -1678,7 +1671,6 @@ if(NOT LIBRETRO)
find_library(AUDIO_UNIT_LIBRARY AudioUnit)
find_library(FOUNDATION_LIBRARY Foundation)
find_library(AUDIO_TOOLBOX_LIBRARY AudioToolbox)
find_library(OPENGL_LIBRARY OpenGL)
find_library(METAL_LIBRARY Metal)
find_library(IOSURFACE_LIBRARY IOSurface)
find_library(MULTITOUCH_SUPPORT_LIBRARY MultitouchSupport /System/Library/PrivateFrameworks)
Expand All @@ -1687,7 +1679,6 @@ if(NOT LIBRETRO)
${AUDIO_UNIT_LIBRARY}
${FOUNDATION_LIBRARY}
${AUDIO_TOOLBOX_LIBRARY}
${OPENGL_LIBRARY}
${METAL_LIBRARY}
${IOSURFACE_LIBRARY}
${MULTITOUCH_SUPPORT_LIBRARY})
Expand Down Expand Up @@ -1748,7 +1739,7 @@ if(NOT LIBRETRO)
endif()

target_sources(${PROJECT_NAME} PRIVATE shell/windows/flycast.rc)
target_link_libraries(${PROJECT_NAME} PRIVATE dsound opengl32 winmm ws2_32 wsock32 xinput9_1_0 cfgmgr32 wininet)
target_link_libraries(${PROJECT_NAME} PRIVATE dsound winmm ws2_32 wsock32 xinput9_1_0 cfgmgr32 wininet)
endif()
endif()
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,7 @@ typedef intptr_t EGLNativeDisplayType;
typedef intptr_t EGLNativePixmapType;
typedef intptr_t EGLNativeWindowType;

#elif defined(__unix__) && defined(EGL_NO_X11)

typedef void *EGLNativeDisplayType;
typedef khronos_uintptr_t EGLNativePixmapType;
typedef khronos_uintptr_t EGLNativeWindowType;

#elif defined(__unix__) || defined(USE_X11)
#elif defined(USE_X11)

/* X11 (tentative) */
#include <X11/Xlib.h>
Expand All @@ -119,6 +113,12 @@ typedef Display *EGLNativeDisplayType;
typedef Pixmap EGLNativePixmapType;
typedef Window EGLNativeWindowType;

#elif defined(__unix__)

typedef void *EGLNativeDisplayType;
typedef khronos_uintptr_t EGLNativePixmapType;
typedef khronos_uintptr_t EGLNativeWindowType;

#elif defined(__APPLE__)

typedef int EGLNativeDisplayType;
Expand All @@ -139,6 +139,12 @@ typedef void *EGLNativeDisplayType;
typedef khronos_uintptr_t EGLNativePixmapType;
typedef khronos_uintptr_t EGLNativeWindowType;

#elif defined(__QNX__)

typedef khronos_uintptr_t EGLNativeDisplayType;
typedef struct _screen_pixmap* EGLNativePixmapType; /* screen_pixmap_t */
typedef struct _screen_window* EGLNativeWindowType; /* screen_window_t */

#else
#error "Platform not recognized"
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@
* int arg2) KHRONOS_APIATTRIBUTES;
*/

#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
# define KHRONOS_STATIC 1
#endif

/*-------------------------------------------------------------------------
* Definition of KHRONOS_APICALL
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
#if defined(KHRONOS_STATIC)
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
* header compatible with static linking. */
# define KHRONOS_APICALL
#elif defined(_WIN32)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C
Expand Down Expand Up @@ -145,6 +153,20 @@ typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
/*
* To support platform where unsigned long cannot be used interchangeably with
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
* unsigned long long or similar (this results in different C++ name mangling).
* To avoid changes for existing platforms, we restrict usage of intptr_t to
* platforms where the size of a pointer is larger than the size of long.
*/
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
#define KHRONOS_USE_INTPTR_T
#endif
#endif

#elif defined(__VMS ) || defined(__sgi)

Expand Down Expand Up @@ -227,14 +249,21 @@ typedef unsigned short int khronos_uint16_t;
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
* to be the only LLP64 architecture in current use.
*/
#ifdef _WIN64
#ifdef KHRONOS_USE_INTPTR_T
typedef intptr_t khronos_intptr_t;
typedef uintptr_t khronos_uintptr_t;
#elif defined(_WIN64)
typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t;
typedef signed long long int khronos_ssize_t;
typedef unsigned long long int khronos_usize_t;
#else
typedef signed long int khronos_intptr_t;
typedef unsigned long int khronos_uintptr_t;
#endif

#if defined(_WIN64)
typedef signed long long int khronos_ssize_t;
typedef unsigned long long int khronos_usize_t;
#else
typedef signed long int khronos_ssize_t;
typedef unsigned long int khronos_usize_t;
#endif
Expand Down
Loading

0 comments on commit 989e81d

Please sign in to comment.