From dbbaadf2045deb412b167bc2a0e6dea02bc34c62 Mon Sep 17 00:00:00 2001 From: uis Date: Thu, 18 Jan 2024 02:33:59 +0300 Subject: [PATCH] Fix GLES2 --- gl_rmain.c | 21 +++++++++++++++++++++ gl_textures.c | 4 ++-- makefile | 5 +++++ makefile.inc | 4 ++-- shader_glsl.h | 4 ++-- vid_sdl.c | 22 +++++++++++++++++----- 6 files changed, 49 insertions(+), 11 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index 681e1326..6816a108 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -1105,6 +1105,7 @@ static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode strlcat(permutationname, modeinfo->filename, sizeof(permutationname)); + #ifndef USE_GLES2 // we need 140 for r_glsl_skeletal (GL_ARB_uniform_buffer_object) if(vid.support.glshaderversion >= 140) { @@ -1135,6 +1136,26 @@ static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode geomstrings_list[geomstrings_count++] = "#define GLSL120\n"; fragstrings_list[fragstrings_count++] = "#define GLSL120\n"; } + #else + if(vid.support.glshaderversion >= 300) + { + vertstrings_list[vertstrings_count++] = "#version 300 es\n"; + geomstrings_list[geomstrings_count++] = "#version 300 es\n"; + fragstrings_list[fragstrings_count++] = "#version 300 es\n"; + vertstrings_list[vertstrings_count++] = "#define GLSL140\n"; + geomstrings_list[geomstrings_count++] = "#define GLSL140\n"; + fragstrings_list[fragstrings_count++] = "#define GLSL140\n"; + } + else + { + vertstrings_list[vertstrings_count++] = "#version 100 es\n"; + geomstrings_list[geomstrings_count++] = "#version 100 es\n"; + fragstrings_list[fragstrings_count++] = "#version 100 es\n"; + vertstrings_list[vertstrings_count++] = "#define GLSL120\n"; + geomstrings_list[geomstrings_count++] = "#define GLSL120\n"; + fragstrings_list[fragstrings_count++] = "#define GLSL120\n"; + } + #endif // GLES also adds several things from GLSL120 switch(vid.renderpath) { diff --git a/gl_textures.c b/gl_textures.c index 29d325ed..3955a804 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -96,8 +96,8 @@ static textypeinfo_t textype_depth16 = {"depth16", static textypeinfo_t textype_depth24 = {"depth24", TEXTYPE_DEPTHBUFFER24 , 2, 2, 2.0f, GL_DEPTH_COMPONENT16 , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; static textypeinfo_t textype_depth24stencil8 = {"depth24stencil8", TEXTYPE_DEPTHBUFFER24STENCIL8, 2, 2, 2.0f, GL_DEPTH_COMPONENT16 , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; static textypeinfo_t textype_colorbuffer = {"colorbuffer", TEXTYPE_COLORBUFFER , 2, 2, 2.0f, GL_RGB565 , GL_RGBA , GL_UNSIGNED_SHORT_5_6_5}; -static textypeinfo_t textype_colorbuffer16f = {"colorbuffer16f", TEXTYPE_COLORBUFFER16F , 2, 2, 2.0f, GL_RGBA16F , GL_RGBA , GL_HALF_FLOAT_ARB}; -static textypeinfo_t textype_colorbuffer32f = {"colorbuffer32f", TEXTYPE_COLORBUFFER32F , 2, 2, 2.0f, GL_RGBA32F , GL_RGBA , GL_FLOAT}; +static textypeinfo_t textype_colorbuffer16f = {"colorbuffer16f", TEXTYPE_COLORBUFFER16F , 2, 2, 2.0f, GL_RGBA16F_EXT , GL_RGBA , GL_HALF_FLOAT_OES}; +static textypeinfo_t textype_colorbuffer32f = {"colorbuffer32f", TEXTYPE_COLORBUFFER32F , 2, 2, 2.0f, GL_RGBA32F_EXT , GL_RGBA , GL_FLOAT}; // image formats: static textypeinfo_t textype_alpha = {"alpha", TEXTYPE_ALPHA , 1, 4, 4.0f, GL_ALPHA , GL_ALPHA , GL_UNSIGNED_BYTE }; diff --git a/makefile b/makefile index 0f9d8e70..8ba5105f 100644 --- a/makefile +++ b/makefile @@ -401,6 +401,11 @@ ifeq ($(DP_SOUND_API),3DRAS) LIB_SOUND=$(LIB_SND_3DRAS) endif +ifeq ($(DP_GLES),2) + LIB_GLES=-lGLESv2 + CFLAGS_GLES=-DUSE_GLES2 +endif + ##### Extra CFLAGS ##### CFLAGS_MAKEDEP?=-MMD diff --git a/makefile.inc b/makefile.inc index a2e814b5..dcfe670e 100644 --- a/makefile.inc +++ b/makefile.inc @@ -174,7 +174,7 @@ OBJ_SDL= builddate.c sys_sdl.o vid_sdl.o thread_sdl.o $(OBJ_MENU) $(OBJ_SND_COMM # Compilation -CFLAGS_COMMON=$(CFLAGS_MAKEDEP) $(CFLAGS_PRELOAD) $(CFLAGS_FS) $(CFLAGS_WARNINGS) $(CFLAGS_LIBZ) $(CFLAGS_LIBJPEG) $(CFLAGS_D3D) $(CFLAGS_NET) $(CFLAGS_SDL) -D_FILE_OFFSET_BITS=64 -D__KERNEL_STRICT_NAMES -I../../../ +CFLAGS_COMMON=$(CFLAGS_MAKEDEP) $(CFLAGS_PRELOAD) $(CFLAGS_FS) $(CFLAGS_WARNINGS) $(CFLAGS_LIBZ) $(CFLAGS_LIBJPEG) $(CFLAGS_D3D) $(CFLAGS_NET) $(CFLAGS_SDL) -D_FILE_OFFSET_BITS=64 -D__KERNEL_STRICT_NAMES -I../../../ $(CFLAGS_GLES) CFLAGS_CLIENT=-DCONFIG_MENU -DCONFIG_CD $(CFLAGS_VIDEO_CAPTURE) CFLAGS_SERVER= CFLAGS_DEBUG=-ggdb @@ -214,7 +214,7 @@ LDFLAGS_RELEASE=$(OPTIM_RELEASE) -DSVNREVISION=`{ test -d .svn && svnversion; } OBJ_GLX= builddate.c sys_linux.o vid_glx.o thread_pthread.o keysym2ucs.o $(OBJ_MENU) $(OBJ_SOUND) $(OBJ_CD) $(OBJ_VIDEO_CAPTURE) $(OBJ_COMMON) -LDFLAGS_UNIXCOMMON=-lm $(LIB_ODE) $(LIB_Z) $(LIB_JPEG) $(LIB_CRYPTO) $(LIB_CRYPTO_RIJNDAEL) +LDFLAGS_UNIXCOMMON=-lm $(LIB_ODE) $(LIB_Z) $(LIB_JPEG) $(LIB_CRYPTO) $(LIB_CRYPTO_RIJNDAEL) $(LIB_GLES) LDFLAGS_UNIXCL=-L$(UNIX_X11LIBPATH) -lX11 -lXpm -lXext -lXxf86vm -pthread $(LIB_SOUND) LDFLAGS_UNIXCL_PRELOAD=-lz -ljpeg -lpng -logg -ltheora -lvorbis -lvorbisenc -lvorbisfile -lcurl LDFLAGS_UNIXSV_PRELOAD=-lz -ljpeg -lpng -lcurl diff --git a/shader_glsl.h b/shader_glsl.h index 954fda21..112a91cd 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -21,7 +21,7 @@ "# endif\n", "#endif\n", "\n", -"#define sat(x) clamp(x, 0, 1)\n", +"#define sat(x) clamp(x, 0.0, 1.0)\n", "#define possat(x) sat(x)\n",//As replacement of max(x, 0) when x<=1, better for gpus that can't do 0-cycle max(x, 0) "#define minonesat(x) sat(x)\n",//As replacement of min(x, 1) when x>=0, better for gpus that can't do 0-cycle min(x, 1) "#define possatdot(x, y) possat(dot(x, y))\n", @@ -1543,7 +1543,7 @@ " #ifdef USEDIFFUSE\n", " myhalf3 lightnormal = cast_myhalf3(normalize(LightVector));\n", " #endif\n", -" #define lightcolor 1\n", +" #define lightcolor 1.0\n", "#endif // MODE_LIGHTDIRECTION\n", "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n", " #define SHADING\n", diff --git a/vid_sdl.c b/vid_sdl.c index 27f4ce5f..151a73c5 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -1940,10 +1940,10 @@ void GLES_Init(void) if (!gl_platformextensions) gl_platformextensions = ""; - Con_Printf("GL_VENDOR: %s\n", gl_vendor); - Con_Printf("GL_RENDERER: %s\n", gl_renderer); - Con_Printf("GL_VERSION: %s\n", gl_version); - Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions); + Con_Printf("GLES_VENDOR: %s\n", gl_vendor); + Con_Printf("GLES_RENDERER: %s\n", gl_renderer); + Con_Printf("GLES_VERSION: %s\n", gl_version); + Con_DPrintf("GLES_EXTENSIONS: %s\n", gl_extensions); Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions); // LordHavoc: report supported extensions @@ -1961,7 +1961,7 @@ void GLES_Init(void) vid.support.arb_query_buffer_object = false; vid.support.arb_shadow = false; vid.support.arb_texture_compression = false; // different (vendor-specific) formats than on desktop OpenGL... - vid.support.arb_texture_cube_map = SDL_GL_ExtensionSupported("GL_OES_texture_cube_map") != 0; + vid.support.arb_texture_cube_map = true; vid.support.arb_texture_env_combine = false; vid.support.arb_texture_gather = false; vid.support.arb_texture_non_power_of_two = strstr(gl_extensions, "GL_OES_texture_npot") != NULL; @@ -1990,6 +1990,17 @@ void GLES_Init(void) vid.support.arb_texture_float = SDL_GL_ExtensionSupported("GL_OES_texture_float") != 0; vid.support.arb_half_float_pixel = SDL_GL_ExtensionSupported("GL_OES_texture_half_float") != 0; vid.support.arb_half_float_vertex = SDL_GL_ExtensionSupported("GL_OES_vertex_half_float") != 0; + { + char *s; + // detect what GLSL version is available, to enable features like r_glsl_skeletal and higher quality reliefmapping + vid.support.glshaderversion = 100; + s = (char *) qglGetString(GL_SHADING_LANGUAGE_VERSION); + if (s) + vid.support.glshaderversion = (int)(atof(strrchr(s, ' ') + 1) * 100.0f + 0.5f); + if (vid.support.glshaderversion < 100) + vid.support.glshaderversion = 100; + Con_DPrintf("Detected GLSL #version %i\n", vid.support.glshaderversion); + } // NOTE: On some devices, a value of 512 gives better FPS than the maximum. qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d); @@ -2634,6 +2645,7 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute (SDL_GL_RETAINED_BACKING, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); #endif #endif -- 2.39.2