]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix GLES2
authoruis <uis9936@gmail.com>
Wed, 17 Jan 2024 23:33:59 +0000 (02:33 +0300)
committeruis <uis9936@gmail.com>
Wed, 17 Jan 2024 23:34:55 +0000 (02:34 +0300)
gl_rmain.c
gl_textures.c
makefile
makefile.inc
shader_glsl.h
vid_sdl.c

index 681e1326b44b999d81ea199b52735a72591f5efb..6816a1082f75c3105ad30916f5f9e656a4855ec8 100644 (file)
@@ -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)
        {
index 29d325ed68763bc7c0792b3e32fc80b443caab2c..3955a8040effd4da7435e3f85862984f165c9b4c 100644 (file)
@@ -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 };
index 0f9d8e7020c83c823de0da2c056c328e049fa8fd..8ba5105fa60eb197bc45578d4e86f68b1bb77e75 100644 (file)
--- 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
index a2e814b55e17320120f7b2038a5953bca4297fa2..dcfe670e5f8a4b53a3d0825a0a98f17dd314cd02 100644 (file)
@@ -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
index 954fda21cdf6ae6bffca1f4a3209fabb77cd6437..112a91cd5226b8a4158c5f040b18904af9100c98 100644 (file)
@@ -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",
 "      #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",
index 27f4ce5f23a706c767d951f996682a8bf2959e34..151a73c5920bd8a66756dc7d8cfbafe82f89075d 100644 (file)
--- 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