Switch from GLEW to GLAD

This commit is contained in:
ROllerozxa 2025-12-04 19:08:32 +01:00
commit 2034ca87e6
33 changed files with 28865 additions and 235 deletions

View file

@ -30,7 +30,7 @@ jobs:
- name: Install deps
run: |
apt-get update
apt-get install -y clang-16 libgtk-3-dev libgl-dev libglew-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libfreetype6-dev cmake ninja-build desktop-file-utils ca-certificates wget file --no-install-recommends
apt-get install -y clang-16 libgtk-3-dev libgl-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libfreetype6-dev cmake ninja-build desktop-file-utils ca-certificates wget file --no-install-recommends
wget https://github.com/principia-game/linux-deps/releases/download/latest/deps.tar.gz -O linux-deps.tar.gz
tar -xaf linux-deps.tar.gz -C /

View file

@ -29,9 +29,7 @@ jobs:
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
brew update --auto-update
brew install cmake ninja glew libpng libjpeg-turbo freetype sdl2 gtk+3
patch /opt/homebrew/include/GL/glew.h < packaging/glew_macos_fix.patch
brew install cmake ninja libpng libjpeg-turbo freetype sdl2 gtk+3
- name: Compile
run: |
@ -40,8 +38,7 @@ jobs:
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 \
-DCMAKE_FIND_FRAMEWORK=LAST \
-DCMAKE_INSTALL_PREFIX=../build/macos/ \
-DCMAKE_EXE_LINKER_FLAGS="-L/opt/homebrew/lib/" \
-DGLEW_LIBRARY_RELEASE=/opt/homebrew/lib/libGLEW.dylib
-DCMAKE_EXE_LINKER_FLAGS="-L/opt/homebrew/lib/"
ninja
- name: Package

View file

@ -37,7 +37,6 @@ jobs:
gcc:p
cmake:p
ninja:p
glew:p
zlib:p
gtk3:p
libpng:p

View file

@ -90,6 +90,7 @@ endif()
include_directories(
lib/
lib/GLAD/include/
lib/imgui/
lib/lua/
lib/SDL_image/
@ -107,6 +108,7 @@ file(GLOB SRCS
src/*.cc
src/*.c
lib/GLAD/src/gl.c
lib/lua/*.c
lib/SDL_image/*.c
@ -133,8 +135,6 @@ if(NOT SCREENSHOT_BUILD)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
endif()
find_package(GLEW REQUIRED)
if(NOT BACKEND_IMGUI)
include_directories(${GTK3_INCLUDE_DIRS})
endif()
@ -215,10 +215,6 @@ if(NOT EMSCRIPTEN)
if(NOT ANDROID)
list(APPEND LIBS ${GTK3_LIBRARIES})
endif()
if(NOT SHOULD_USE_GLES)
list(APPEND LIBS GLEW::GLEW)
endif()
endif()
endif()
@ -243,8 +239,6 @@ add_dependencies(${PROJECT_NAME} GenerateGitVersion)
if(SHOULD_USE_GLES)
add_definitions(-DTMS_USE_GLES)
elseif(NOT SCREENSHOT_BUILD)
add_definitions(-DTMS_USE_GLEW)
endif()
if(WIN32)

View file

@ -0,0 +1,311 @@
#ifndef __khrplatform_h_
#define __khrplatform_h_
/*
** Copyright (c) 2008-2018 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/* Khronos platform-specific types and definitions.
*
* The master copy of khrplatform.h is maintained in the Khronos EGL
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
* The last semantic modification to khrplatform.h was at commit ID:
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
*
* Adopters may modify this file to suit their platform. Adopters are
* encouraged to submit platform specific modifications to the Khronos
* group so that they can be included in future versions of this file.
* Please submit changes by filing pull requests or issues on
* the EGL Registry repository linked above.
*
*
* See the Implementer's Guidelines for information about where this file
* should be located on your system and for more details of its use:
* http://www.khronos.org/registry/implementers_guide.pdf
*
* This file should be included as
* #include <KHR/khrplatform.h>
* by Khronos client API header files that use its types and defines.
*
* The types in khrplatform.h should only be used to define API-specific types.
*
* Types defined in khrplatform.h:
* khronos_int8_t signed 8 bit
* khronos_uint8_t unsigned 8 bit
* khronos_int16_t signed 16 bit
* khronos_uint16_t unsigned 16 bit
* khronos_int32_t signed 32 bit
* khronos_uint32_t unsigned 32 bit
* khronos_int64_t signed 64 bit
* khronos_uint64_t unsigned 64 bit
* khronos_intptr_t signed same number of bits as a pointer
* khronos_uintptr_t unsigned same number of bits as a pointer
* khronos_ssize_t signed size
* khronos_usize_t unsigned size
* khronos_float_t signed 32 bit floating point
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* nanoseconds
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
* khronos_boolean_enum_t enumerated boolean type. This should
* only be used as a base type when a client API's boolean type is
* an enum. Client APIs which use an integer or other type for
* booleans cannot use this as the base type for their boolean.
*
* Tokens defined in khrplatform.h:
*
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
*
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
*
* Calling convention macros defined in this file:
* KHRONOS_APICALL
* KHRONOS_APIENTRY
* KHRONOS_APIATTRIBUTES
*
* These may be used in function prototypes as:
*
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
* int arg1,
* 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(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
#elif defined(__ANDROID__)
# define KHRONOS_APICALL __attribute__((visibility("default")))
#else
# define KHRONOS_APICALL
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIENTRY
*-------------------------------------------------------------------------
* This follows the return type of the function and precedes the function
* name in the function prototype.
*/
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
/* Win32 but not WinCE */
# define KHRONOS_APIENTRY __stdcall
#else
# define KHRONOS_APIENTRY
#endif
/*-------------------------------------------------------------------------
* Definition of KHRONOS_APIATTRIBUTES
*-------------------------------------------------------------------------
* This follows the closing parenthesis of the function prototype arguments.
*/
#if defined (__ARMCC_2__)
#define KHRONOS_APIATTRIBUTES __softfp
#else
#define KHRONOS_APIATTRIBUTES
#endif
/*-------------------------------------------------------------------------
* basic type definitions
*-----------------------------------------------------------------------*/
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
/*
* Using <stdint.h>
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
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)
/*
* Using <inttypes.h>
*/
#include <inttypes.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
/*
* Win32
*/
typedef __int32 khronos_int32_t;
typedef unsigned __int32 khronos_uint32_t;
typedef __int64 khronos_int64_t;
typedef unsigned __int64 khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif defined(__sun__) || defined(__digital__)
/*
* Sun or Digital
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#if defined(__arch64__) || defined(_LP64)
typedef long int khronos_int64_t;
typedef unsigned long int khronos_uint64_t;
#else
typedef long long int khronos_int64_t;
typedef unsigned long long int khronos_uint64_t;
#endif /* __arch64__ */
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#elif 0
/*
* Hypothetical platform with no float or int64 support
*/
typedef int khronos_int32_t;
typedef unsigned int khronos_uint32_t;
#define KHRONOS_SUPPORT_INT64 0
#define KHRONOS_SUPPORT_FLOAT 0
#else
/*
* Generic fallback
*/
#include <stdint.h>
typedef int32_t khronos_int32_t;
typedef uint32_t khronos_uint32_t;
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#define KHRONOS_SUPPORT_INT64 1
#define KHRONOS_SUPPORT_FLOAT 1
#endif
/*
* Types that are (so far) the same on all platforms
*/
typedef signed char khronos_int8_t;
typedef unsigned char khronos_uint8_t;
typedef signed short int khronos_int16_t;
typedef unsigned short int khronos_uint16_t;
/*
* Types that differ between LLP64 and LP64 architectures - in LLP64,
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
* to be the only LLP64 architecture in current use.
*/
#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;
#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
#if KHRONOS_SUPPORT_FLOAT
/*
* Float type
*/
typedef float khronos_float_t;
#endif
#if KHRONOS_SUPPORT_INT64
/* Time types
*
* These types can be used to represent a time interval in nanoseconds or
* an absolute Unadjusted System Time. Unadjusted System Time is the number
* of nanoseconds since some arbitrary system event (e.g. since the last
* time the system booted). The Unadjusted System Time is an unsigned
* 64 bit value that wraps back to 0 every 584 years. Time intervals
* may be either signed or unsigned.
*/
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
typedef khronos_int64_t khronos_stime_nanoseconds_t;
#endif
/*
* Dummy value used to pad enum types to 32 bits.
*/
#ifndef KHRONOS_MAX_ENUM
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
#endif
/*
* Enumerated boolean type
*
* Values other than zero should be considered to be true. Therefore
* comparisons should not be made against KHRONOS_TRUE.
*/
typedef enum {
KHRONOS_FALSE = 0,
KHRONOS_TRUE = 1,
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
} khronos_boolean_enum_t;
#endif /* __khrplatform_h_ */

17460
lib/GLAD/include/glad/gl.h Normal file

File diff suppressed because one or more lines are too long

10975
lib/GLAD/src/gl.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -69,7 +69,6 @@ chmod +x AppRun
# installed by the user and other libraries like libcurl and libfreetype are
# expected to already exist on the system.
INCLUDE_LIBS=(
libGLEW.so.2.1
libjpeg.so.62
libpng16.so.16
)

View file

@ -1,21 +0,0 @@
--- glew.h 2022-11-15 14:16:27.000000000 +0100
+++ glew_mod.h 2024-05-11 17:12:43.597037795 +0200
@@ -220,13 +220,13 @@
*/
#if defined(__APPLE__) || defined(__linux__)
-# if defined(__cplusplus)
-# include <cstddef>
-# include <cstdint>
-# else
+//# if defined(__cplusplus)
+//# include <cstddef>
+//# include <cstdint>
+//# else
# include <stddef.h>
# include <stdint.h>
-# endif
+//# endif
#else
# include <stddef.h>

View file

@ -72,7 +72,7 @@
#include "terrain.hh"
#endif
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#include <unistd.h>
#include <iterator>
@ -3082,12 +3082,11 @@ game::render()
glBindTexture(GL_TEXTURE_2D, this->main_fb->fb_texture[0][0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#ifdef TMS_USE_GLEW
if (GLEW_VERSION_3_0) { /* XXX */
#ifndef TMS_USE_GLES
if (glad_glGenerateMipmap)
glGenerateMipmap(GL_TEXTURE_2D);
} else {
else
glGenerateMipmapEXT(GL_TEXTURE_2D);
}
#else
glGenerateMipmap(GL_TEXTURE_2D);
#endif
@ -3101,12 +3100,11 @@ game::render()
glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, this->bloom_fb->fb_texture[this->bloom_fb->toggle][0]);
#ifdef TMS_USE_GLEW
if (GLEW_VERSION_3_0) { /* XXX */
#ifndef TMS_USE_GLES
if (glad_glGenerateMipmap)
glGenerateMipmap(GL_TEXTURE_2D);
} else {
else
glGenerateMipmapEXT(GL_TEXTURE_2D);
}
#else
glGenerateMipmap(GL_TEXTURE_2D);
#endif

View file

@ -6,6 +6,10 @@
#include "zlib.h"
#include "misc.hh"
#ifdef TMS_BACKEND_WINDOWS
#include <windows.h>
#endif
/* for lvledit command line tool */
#ifdef _NO_TMS
#include <stdlib.h>

View file

@ -12,7 +12,7 @@
#include <tms/core/event.h>
#include <tms/core/tms.h>
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#include "settings.hh"
#include "main.hh"
@ -340,58 +340,34 @@ tbackend_init_surface()
#endif
#ifdef TMS_USE_GLES
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_CreateContext(_window);
#else
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
#endif
SDL_GLContext gl_context = SDL_GL_CreateContext(_window);
if (gl_context == NULL)
tms_fatalf("Error creating GL Context: %s", SDL_GetError());
tms_infof("Initializing GLEW...");
GLenum err = glewInit();
if (err != GLEW_OK && err != GLEW_ERROR_NO_GLX_DISPLAY) {
tms_infof("ERROR: %s", glewGetErrorString(err));
exit(1);
}
tms_infof("GLEW init OK (v%s)", glewGetString(GLEW_VERSION));
#ifdef TMS_USE_GLES
int version = gladLoadGLES2((GLADloadfunc)SDL_GL_GetProcAddress);
#else
int version = gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
#endif
tms_infof("Loaded GL version %d.%d", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
tms_infof("GL Info: %s/%s/%s", glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_VERSION));
tms_infof("GLSL Version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
tms_printf("GL versions supported: ");
if (GLEW_VERSION_4_6) tms_printf("4.6,");
if (GLEW_VERSION_4_5) tms_printf("4.5,");
if (GLEW_VERSION_4_4) tms_printf("4.4,");
if (GLEW_VERSION_4_3) tms_printf("4.3,");
if (GLEW_VERSION_4_2) tms_printf("4.2,");
if (GLEW_VERSION_4_1) tms_printf("4.1,");
if (GLEW_VERSION_3_3) tms_printf("3.3,");
if (GLEW_VERSION_3_1) tms_printf("3.1,");
if (GLEW_VERSION_3_0) tms_printf("3.0,");
if (GLEW_VERSION_2_1) tms_printf("2.1,");
if (GLEW_VERSION_2_0) tms_printf("2.0,");
if (GLEW_VERSION_1_5) tms_printf("1.5,");
if (GLEW_VERSION_1_4) tms_printf("1.4,");
if (GLEW_VERSION_1_3) tms_printf("1.3,");
if (GLEW_VERSION_1_2) tms_printf("1.2,");
if (GLEW_VERSION_1_1) tms_printf("1.1");
tms_printf("\n");
#ifdef TMS_BACKEND_WINDOWS
if (!GLEW_VERSION_1_2) {
if (!GLAD_GL_VERSION_1_2) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Principia",
R"(Your graphics driver does not support OpenGL >1.1 and as such Principia will not start.
Most likely this is because you do not have any graphics drivers installed and are using
@ -403,8 +379,6 @@ get Principia running. (place the Mesa opengl32.dll library next to principia.ex
exit(1);
}
#endif
#endif
return T_OK;

View file

@ -14,7 +14,7 @@
#include <tms/core/event.h>
#include <tms/core/tms.h>
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#include "settings.hh"
#include "game.hh"
@ -378,10 +378,11 @@ tbackend_init_surface()
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_CreateContext(_window);
int version = gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
tms_infof("Loaded GL version %d.%d", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
return T_OK;
}

View file

@ -1,31 +0,0 @@
#ifndef _TMS_BACKEND_OPENGL__H_
#define _TMS_BACKEND_OPENGL__H_
#ifdef TMS_BACKEND_WINDOWS
#include <windows.h>
#endif
#ifdef TMS_USE_GLES
#define GL_GLEXT_PROTOTYPES 1
#include <GLES2/gl2.h>
#else
#ifdef TMS_USE_GLEW
#include <GL/glew.h>
#else
// e.g. screenshotter doesn't use GLEW
#define GL_GLEXT_PROTOTYPES 1
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glx.h>
#endif
#endif
#ifdef TMS_BACKEND_WINDOWS
#include <GL/wglew.h>
#endif
#include <SDL.h>
#endif

View file

@ -13,7 +13,7 @@
#include <tms/core/event.h>
#include <tms/core/tms.h>
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#ifdef TMS_BACKEND_WINDOWS

View file

@ -544,12 +544,11 @@ tms_fb_init(struct tms_fb* fb)
int ierr;
fb->toggle = 0;
tms_assertf((ierr = glGetError()) == 0, "gl error %d before tms_fb_init", ierr);
#ifdef TMS_USE_GLEW
if (__glewGenFramebuffers) {
__glewGenFramebuffers(fb->double_buffering ? 2 : 1, fb->fb_o);
} else {
__glewGenFramebuffersEXT(fb->double_buffering ? 2 : 1, fb->fb_o);
}
#ifndef TMS_USE_GLES
if (glad_glGenFramebuffers)
glGenFramebuffers(fb->double_buffering ? 2 : 1, fb->fb_o);
else
glGenFramebuffersEXT(fb->double_buffering ? 2 : 1, fb->fb_o);
#else
glGenFramebuffers(fb->double_buffering ? 2 : 1, fb->fb_o);
#endif
@ -624,13 +623,11 @@ tms_fb_enable_depth(struct tms_fb *fb, int format)
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth (begin)", ierr);
for (int x=0; x<(fb->double_buffering ? 2 : 1); x++) {
#ifdef TMS_USE_GLEW
//if (GLEW_VERSION_1_5) {
if (__glewBindFramebuffer) {
__glewBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
} else {
__glewBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
}
#ifndef TMS_USE_GLES
if (glad_glBindFramebuffer)
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
else
glBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
#else
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
#endif
@ -639,13 +636,13 @@ tms_fb_enable_depth(struct tms_fb *fb, int format)
//tms_infof("enable depth after bind %d", glGetError());
#ifdef TMS_USE_GLEW
if (__glewGenRenderbuffers) {
__glewGenRenderbuffers(1, &fb->fb_depth[x]);
__glewBindRenderbuffer(GL_RENDERBUFFER, fb->fb_depth[x]);
#ifndef TMS_USE_GLES
if (glad_glGenRenderbuffers) {
glGenRenderbuffers(1, &fb->fb_depth[x]);
glBindRenderbuffer(GL_RENDERBUFFER, fb->fb_depth[x]);
} else {
__glewGenRenderbuffersEXT(1, &fb->fb_depth[x]);
__glewBindRenderbufferEXT(GL_RENDERBUFFER, fb->fb_depth[x]);
glGenRenderbuffersEXT(1, &fb->fb_depth[x]);
glBindRenderbufferEXT(GL_RENDERBUFFER, fb->fb_depth[x]);
}
#else
glGenRenderbuffers(1, &fb->fb_depth[x]);
@ -659,23 +656,19 @@ tms_fb_enable_depth(struct tms_fb *fb, int format)
#ifdef TMS_USE_GLES
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, fb->width, fb->height);
#elif defined TMS_USE_GLEW
if (__glewRenderbufferStorage) {
__glewRenderbufferStorage(GL_RENDERBUFFER, format, fb->width, fb->height);
} else {
__glewRenderbufferStorageEXT(GL_RENDERBUFFER, format, fb->width, fb->height);
}
#else
glRenderbufferStorage(GL_RENDERBUFFER, format, fb->width, fb->height);
if (glad_glRenderbufferStorage)
glRenderbufferStorage(GL_RENDERBUFFER, format, fb->width, fb->height);
else
glRenderbufferStorageEXT(GL_RENDERBUFFER, format, fb->width, fb->height);
#endif
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth %d 4", ierr, x);
#ifdef TMS_USE_GLEW
if (__glewFramebufferRenderbuffer) {
__glewFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
} else {
__glewFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
}
#ifndef TMS_USE_GLES
if (glad_glFramebufferRenderbuffer)
glad_glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
else
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
#else
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fb->fb_depth[x]);
#endif
@ -683,11 +676,11 @@ tms_fb_enable_depth(struct tms_fb *fb, int format)
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth %d 5", ierr, x);
//tms_infof("enable depth after hello %d", glGetError());
#ifdef TMS_USE_GLEW
if (__glewBindRenderbuffer) {
__glewBindRenderbuffer(GL_RENDERBUFFER, 0);
#ifndef TMS_USE_GLES
if (glad_glBindRenderbuffer) {
glBindRenderbuffer(GL_RENDERBUFFER, 0);
} else {
__glewBindRenderbufferEXT(GL_RENDERBUFFER, 0);
glBindRenderbufferEXT(GL_RENDERBUFFER, 0);
}
#else
glBindRenderbuffer(GL_RENDERBUFFER, 0);
@ -695,12 +688,11 @@ tms_fb_enable_depth(struct tms_fb *fb, int format)
tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_enable_depth %d 6", ierr, x);
}
#ifdef TMS_USE_GLEW
if (__glewBindFramebuffer) {
__glewBindFramebuffer(GL_FRAMEBUFFER, 0);
} else {
__glewBindFramebufferEXT(GL_FRAMEBUFFER, 0);
}
#ifndef TMS_USE_GLES
if (glad_glBindFramebuffer)
glBindFramebuffer(GL_FRAMEBUFFER, 0);
else
glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
@ -711,12 +703,11 @@ void
tms_fb_enable_depth_texture(struct tms_fb *fb, int format)
{
for (int x=0; x<(fb->double_buffering ? 2 : 1); x++) {
#ifdef TMS_USE_GLEW
if (__glewBindFramebuffer) {
__glewBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
} else {
__glewBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
}
#ifndef TMS_USE_GLES
if (glad_glBindFramebuffer)
glad_glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
else
glad_glBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
#else
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
#endif
@ -743,12 +734,11 @@ tms_fb_enable_depth_texture(struct tms_fb *fb, int format)
glBindTexture(GL_TEXTURE_2D, 0);
}
#ifdef TMS_USE_GLEW
if (__glewBindFramebuffer) {
__glewBindFramebuffer(GL_FRAMEBUFFER, 0);
} else {
__glewBindFramebufferEXT(GL_FRAMEBUFFER, 0);
}
#ifndef TMS_USE_GLES
if (glad_glBindFramebuffer)
glad_glBindFramebuffer(GL_FRAMEBUFFER, 0);
else
glad_glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
@ -767,12 +757,11 @@ tms_fb_add_texture(struct tms_fb *fb, int format,
for (int x=0; x<(fb->double_buffering ? 2 : 1); x++) {
//tms_infof("add texture before bind %d", glGetError());
#ifdef TMS_USE_GLEW
if (__glewBindFramebuffer) {
__glewBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
} else {
__glewBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
}
#ifndef TMS_USE_GLES
if (glad_glBindFramebuffer)
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
else
glBindFramebufferEXT(GL_FRAMEBUFFER, fb->fb_o[x]);
#else
glBindFramebuffer(GL_FRAMEBUFFER, fb->fb_o[x]);
#endif
@ -829,12 +818,11 @@ tms_fb_add_texture(struct tms_fb *fb, int format,
//tms_infof("add texture after parameters %d", glGetError());
#ifdef TMS_USE_GLEW
if (__glewFramebufferTexture2D) {
__glewFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+fb->num_textures, GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures], 0);
} else {
__glewFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+fb->num_textures, GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures], 0);
}
#ifndef TMS_USE_GLES
if (glad_glFramebufferTexture2D)
glad_glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+fb->num_textures, GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures], 0);
else
glad_glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+fb->num_textures, GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures], 0);
#else
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+fb->num_textures,
GL_TEXTURE_2D, fb->fb_texture[x][fb->num_textures], 0);
@ -861,12 +849,11 @@ tms_fb_add_texture(struct tms_fb *fb, int format,
fb->num_textures ++;
#ifdef TMS_USE_GLEW
if (__glewBindFramebuffer) {
__glewBindFramebuffer(GL_FRAMEBUFFER, 0);
} else {
__glewBindFramebufferEXT(GL_FRAMEBUFFER, 0);
}
#ifndef TMS_USE_GLES
if (glad_glBindFramebuffer)
glBindFramebuffer(GL_FRAMEBUFFER, 0);
else
glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
@ -979,25 +966,21 @@ tms_fb_bind_last_textures(struct tms_fb *fb, int first_unit)
static int _bind(struct tms_fb *f)
{
if (f != 0) {
#ifdef TMS_USE_GLEW
if (__glewBindFramebuffer) {
__glewBindFramebuffer(GL_FRAMEBUFFER, f->fb_o[f->toggle]);
} else {
__glewBindFramebufferEXT(GL_FRAMEBUFFER, f->fb_o[f->toggle]);
}
#ifndef TMS_USE_GLES
if (glad_glBindFramebuffer)
glBindFramebuffer(GL_FRAMEBUFFER, f->fb_o[f->toggle]);
else
glBindFramebufferEXT(GL_FRAMEBUFFER, f->fb_o[f->toggle]);
#else
glBindFramebuffer(GL_FRAMEBUFFER, f->fb_o[f->toggle]);
#endif
glViewport(0, 0, f->width, f->height);
} else {
#ifdef TMS_USE_GLEW
if (__glewBindFramebuffer) {
__glewBindFramebuffer(GL_FRAMEBUFFER, 0);
} else {
__glewBindFramebufferEXT(GL_FRAMEBUFFER, 0);
}
#elif defined (TMS_BACKEND_IOS)
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
#ifndef TMS_USE_GLES
if (glad_glBindFramebuffer)
glBindFramebuffer(GL_FRAMEBUFFER, 0);
else
glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif

View file

@ -3,7 +3,7 @@
/** @relates tms_fb @{ */
#include <tms/backend/opengl.h>
#include <glad/gl.h>
struct tms_program;

View file

@ -1,4 +1,5 @@
#include "gbuffer.h"
#include <string.h>
#include <tms/core/err.h>
#include <tms/backend/print.h>

View file

@ -2,7 +2,7 @@
#define _TMS_GBUFFER__H_
#include <stdlib.h>
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#define TMS_GBUFFER_STATIC_DRAW GL_STATIC_DRAW
#define TMS_GBUFFER_STATIC_COPY GL_STATIC_COPY

View file

@ -2,7 +2,7 @@
#include <tms/math/glob.h>
#include "util.h"
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#pragma GCC push_options
#pragma GCC optimize ("O0")

View file

@ -4,7 +4,7 @@
/** @relates tms_mesh @{ */
#include <tms/core/settings.h>
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#define TMS_TRIANGLE_FAN GL_TRIANGLE_FAN
#define TMS_TRIANGLES GL_TRIANGLES

View file

@ -4,7 +4,7 @@
#include "varray.h"
#include <tms/math/vector.h>
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#define SPHERE_QUALITY 40

View file

@ -1,6 +1,6 @@
#include "pipeline.h"
#include "framebuffer.h"
#include <tms/backend/opengl.h>
#include <glad/gl.h>
static struct tms_pipeline pipelines[TMS_NUM_PIPELINES] = {0};
static int n_local_uniforms = 0;

View file

@ -204,15 +204,8 @@ tms_program_get_locations(struct tms_program *s, struct tms_varray *va)
if (last != m->gbuf) {
//tms_gbuffer_bind(va->mappings[x].gbuf, GL_ARRAY_BUFFER);
#ifdef TMS_USE_GLEW
if (GLEW_VERSION_1_5) {
glBindBuffer(GL_ARRAY_BUFFER, bufdata->gbuf->vbo);
} else {
glBindBufferARB(GL_ARRAY_BUFFER, bufdata->gbuf->vbo);
}
#else
glBindBuffer(GL_ARRAY_BUFFER, bufdata->gbuf->vbo);
#endif
last = m->gbuf;
}

View file

@ -1,7 +1,7 @@
#ifndef _TMS_PROGRAM__H_
#define _TMS_PROGRAM__H_
#include <tms/backend/opengl.h>
#include <glad/gl.h>
struct tms_entity;

View file

@ -1,7 +1,7 @@
#include <stdlib.h>
#include <tms/math/intersect.h>
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#include "tms.h"
#include "screen.h"

View file

@ -9,7 +9,7 @@
#include <tms/core/program.h>
#include <tms/core/pipeline.h>
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#define INFOLOG_SIZE 2048

View file

@ -3,7 +3,7 @@
/** @relates tms_shader @{ */
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#include <tms/math/vector.h>
#include <tms/core/tms.h>

View file

@ -10,7 +10,7 @@
#include "../math/glob.h"
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#include "ddraw.h"

View file

@ -481,12 +481,11 @@ tms_texture_set_filtering(struct tms_texture *tex, int filter)
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
#ifdef TMS_USE_GLEW
if (GLEW_VERSION_3_0) { /* XXX */
#ifndef TMS_USE_GLES
if (glad_glGenerateMipmap)
glGenerateMipmap(GL_TEXTURE_2D);
} else {
else
glGenerateMipmapEXT(GL_TEXTURE_2D);
}
#else
glGenerateMipmap(GL_TEXTURE_2D);
#endif

View file

@ -3,7 +3,8 @@
/** @relates tms_texture @{ */
#include <tms/backend/opengl.h>
#include <stddef.h>
#include <glad/gl.h>
#define TMS_MIPMAP -1

View file

@ -1,5 +1,6 @@
#include "varray.h"
#include "gbuffer.h"
#include <string.h>
#include <tms/core/err.h>
static int last_amax = 0;
@ -108,15 +109,7 @@ tms_varray_bind_attributes(struct tms_varray *va,
if (last != m->gbuf) {
//tms_gbuffer_bind(va->mappings[x].gbuf, GL_ARRAY_BUFFER);
#ifdef TMS_USE_GLEW
if (GLEW_VERSION_1_5) {
glBindBuffer(GL_ARRAY_BUFFER, bufdata->gbuf->vbo);
} else {
glBindBufferARB(GL_ARRAY_BUFFER, bufdata->gbuf->vbo);
}
#else
glBindBuffer(GL_ARRAY_BUFFER, bufdata->gbuf->vbo);
#endif
last = m->gbuf;
}

View file

@ -1,7 +1,7 @@
#ifndef _TMS_VARRAY__H_
#define _TMS_VARRAY__H_
#include <tms/backend/opengl.h>
#include <glad/gl.h>
#include <stdint.h>
#include <stdlib.h>