From 2f64ee4d21bc6b5fd8427c61e466b43e8ff63016 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Tue, 21 Dec 2021 13:11:34 +0900 Subject: [PATCH 1/2] Do not use GLEW if USE_GLES is defined GLEW does not support OpenGL ES so it shouldn't be used when targetting OpenGL ES. --- include/dungeon/dungeon.h | 2 +- include/dungeon/renderer.h | 2 +- include/gfx/gfx.h | 2 +- include/gfx/gl.h | 31 +++++++++++++++++++++++++++++++ include/gfx/private.h | 2 +- src/draw.c | 2 +- src/dungeon/dungeon.c | 2 +- src/dungeon/renderer.c | 2 +- src/dungeon/skybox.c | 2 +- src/video.c | 9 +++------ 10 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 include/gfx/gl.h diff --git a/include/dungeon/dungeon.h b/include/dungeon/dungeon.h index f63d491..affde29 100644 --- a/include/dungeon/dungeon.h +++ b/include/dungeon/dungeon.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include "gfx/gl.h" struct page; struct dgn; diff --git a/include/dungeon/renderer.h b/include/dungeon/renderer.h index d7b6ca9..8970020 100644 --- a/include/dungeon/renderer.h +++ b/include/dungeon/renderer.h @@ -18,7 +18,7 @@ #define SYSTEM4_DUNGEON_RENDERER_H #include -#include +#include "gfx/gl.h" struct dgn_cell; struct dtx; diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index e6feb85..88b848e 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include "gfx/gl.h" #include "gfx/types.h" struct cg; diff --git a/include/gfx/gl.h b/include/gfx/gl.h new file mode 100644 index 0000000..22279b1 --- /dev/null +++ b/include/gfx/gl.h @@ -0,0 +1,31 @@ +/* Copyright (C) 2021 kichikuou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef SYSTEM4_GFX_GL_H +#define SYSTEM4_GFX_GL_H + +/* + * Define this to target OpenGL ES 3.0. + */ +//#define USE_GLES + +#ifdef USE_GLES +#include +#else +#include +#endif + +#endif /* SYSTEM4_GFX_GL_H */ diff --git a/include/gfx/private.h b/include/gfx/private.h index 2123ba8..1c34f58 100644 --- a/include/gfx/private.h +++ b/include/gfx/private.h @@ -22,7 +22,7 @@ #include #include -#include +#include "gfx/gl.h" struct sdl_private { SDL_Window *window; diff --git a/src/draw.c b/src/draw.c index 3485cdb..e44edd6 100644 --- a/src/draw.c +++ b/src/draw.c @@ -16,7 +16,7 @@ #include #include -#include +#include "gfx/gl.h" #include #include "gfx/gfx.h" diff --git a/src/dungeon/dungeon.c b/src/dungeon/dungeon.c index 2a3892f..b939e93 100644 --- a/src/dungeon/dungeon.c +++ b/src/dungeon/dungeon.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include "gfx/gl.h" #include "system4.h" #include "system4/alk.h" #include "system4/archive.h" diff --git a/src/dungeon/renderer.c b/src/dungeon/renderer.c index 83cc31b..5a33b3a 100644 --- a/src/dungeon/renderer.c +++ b/src/dungeon/renderer.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include "gfx/gl.h" #include "system4.h" #include "system4/buffer.h" #include "system4/cg.h" diff --git a/src/dungeon/skybox.c b/src/dungeon/skybox.c index e99a49b..2a68bab 100644 --- a/src/dungeon/skybox.c +++ b/src/dungeon/skybox.c @@ -15,7 +15,7 @@ */ #include -#include +#include "gfx/gl.h" #include "system4.h" #include "system4/cg.h" diff --git a/src/video.c b/src/video.c index 82a6311..7ec9f9a 100644 --- a/src/video.c +++ b/src/video.c @@ -16,7 +16,7 @@ */ #include -#include +#include "gfx/gl.h" #include #include #include @@ -33,11 +33,6 @@ struct sdl_private sdl; -/* - * Define this to target OpenGL ES 3.0. - */ -//#define USE_GLES - static const GLchar glsl_preamble[] = #ifdef USE_GLES "#version 300 es\n" @@ -218,10 +213,12 @@ int gfx_init(void) if (!sdl.gl.context) ERROR("SDL_GL_CreateContext failed: %s", SDL_GetError()); +#ifndef USE_GLES glewExperimental = GL_TRUE; GLenum err = glewInit(); if (err != GLEW_OK && err != GLEW_ERROR_NO_GLX_DISPLAY) ERROR("glewInit failed"); +#endif SDL_GL_SetSwapInterval(0); gl_initialize(); From 7caf0092096fda319ad75dfc669e94ba7e870707 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Tue, 21 Dec 2021 13:36:26 +0900 Subject: [PATCH 2/2] Add `use_gles` meson build option --- include/gfx/gl.h | 5 ----- meson.build | 12 ++++++++++-- meson_options.txt | 1 + src/meson.build | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/gfx/gl.h b/include/gfx/gl.h index 22279b1..c436c74 100644 --- a/include/gfx/gl.h +++ b/include/gfx/gl.h @@ -17,11 +17,6 @@ #ifndef SYSTEM4_GFX_GL_H #define SYSTEM4_GFX_GL_H -/* - * Define this to target OpenGL ES 3.0. - */ -//#define USE_GLES - #ifdef USE_GLES #include #else diff --git a/meson.build b/meson.build index 1c38fa0..56fc094 100644 --- a/meson.build +++ b/meson.build @@ -8,14 +8,22 @@ libm = meson.get_compiler('c').find_library('m', required: false) sdl2 = dependency('sdl2') sdl2ttf = dependency('SDL2_ttf') ffi = dependency('libffi') -gl = dependency('GL') -glew = dependency('glew') tj = dependency('libturbojpeg') webp = dependency('libwebp') png = dependency('libpng') cglm = dependency('cglm', fallback : ['cglm', 'cglm_dep']) sndfile = dependency('sndfile') +if get_option('use_gles') + gles = dependency('glesv2') + gl_deps = [gles] + add_project_arguments('-DUSE_GLES', language : 'c') +else + gl = dependency('GL') + glew = dependency('glew') + gl_deps = [gl, glew] +endif + chibi = dependency('chibi-scheme', required : get_option('debugger')) flex = find_program('flex') diff --git a/meson_options.txt b/meson_options.txt index 488e03c..ee54de0 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ option('debugger', type : 'feature', value : 'auto') +option('use_gles', type : 'boolean', value : false, description : 'Target OpenGL ES 3.0') diff --git a/src/meson.build b/src/meson.build index 939ca55..8e4a2c2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -81,7 +81,7 @@ xsystem4 = ['audio.c', 'hll/VSFile.c', ] -xsystem4_deps = [libm, zlib, sdl2, sdl2ttf, ffi, gl, glew, cglm, sndfile, libsys4_dep] +xsystem4_deps = [libm, zlib, sdl2, sdl2ttf, ffi, cglm, sndfile, libsys4_dep] + gl_deps if chibi.found() xsystem4_deps += chibi