From 84640200538e68b80867161ba453a912c5523909 Mon Sep 17 00:00:00 2001 From: TimeServ Date: Mon, 30 May 2011 21:48:32 +0000 Subject: [PATCH] remove gl_lightmap_shift, fix shader to match gl_overbright, es2/egl fixes git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3804 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/r_surf.c | 4 +- engine/client/renderer.c | 5 --- engine/client/sys_linux.c | 28 ++++++++---- engine/client/sys_morphos.c | 28 ++++++++---- engine/client/sys_sdl.c | 27 ++++++++---- engine/gl/gl_shader.c | 85 ++++++++++++++++++------------------- engine/gl/gl_videgl.c | 59 ++++++++----------------- engine/server/sv_sys_unix.c | 28 +++++++----- engine/server/sv_sys_win.c | 21 +++++---- 9 files changed, 147 insertions(+), 138 deletions(-) diff --git a/engine/client/r_surf.c b/engine/client/r_surf.c index ed7cc05d1..cfa681973 100644 --- a/engine/client/r_surf.c +++ b/engine/client/r_surf.c @@ -58,10 +58,10 @@ extern cvar_t r_stainfadeammount; static int lightmap_shift; int Surf_LightmapShift (model_t *model) { - extern cvar_t gl_overbright_all, gl_overbright, gl_lightmap_shift; + extern cvar_t gl_overbright_all, gl_overbright; if (gl_overbright_all.ival || (model->engineflags & MDLF_NEEDOVERBRIGHT)) - lightmap_shift = bound(0, gl_lightmap_shift.ival + gl_overbright.ival, 2); + lightmap_shift = bound(0, gl_overbright.ival, 2); else lightmap_shift = 0; return lightmap_shift; diff --git a/engine/client/renderer.c b/engine/client/renderer.c index f1c1c9d24..d8f9671b4 100644 --- a/engine/client/renderer.c +++ b/engine/client/renderer.c @@ -236,9 +236,6 @@ cvar_t gl_font = CVARF ("gl_font", "", CVAR_RENDERERCALLBACK); cvar_t gl_lateswap = CVAR ("gl_lateswap", "0"); cvar_t gl_lerpimages = CVAR ("gl_lerpimages", "1"); -cvar_t gl_lightmap_shift = CVARFC ("gl_lightmap_shift", "1", - CVAR_ARCHIVE, - Surf_RebuildLightmap_Callback); //cvar_t gl_lightmapmode = SCVARF("gl_lightmapmode", "", // CVAR_ARCHIVE); cvar_t gl_load24bit = SCVARF ("gl_load24bit", "1", @@ -433,8 +430,6 @@ void GLRenderer_Init(void) Cvar_Register (&gl_blendsprites, GLRENDEREROPTIONS); - Cvar_Register (&gl_lightmap_shift, GLRENDEREROPTIONS); - Cvar_Register (&gl_menutint_shader, GLRENDEREROPTIONS); R_BloomRegister(); diff --git a/engine/client/sys_linux.c b/engine/client/sys_linux.c index e684dfb74..dc8d6b683 100644 --- a/engine/client/sys_linux.c +++ b/engine/client/sys_linux.c @@ -533,21 +533,31 @@ dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs) if (!lib) return NULL; - for (i = 0; funcs[i].name; i++) + if (funcs) { - *funcs[i].funcptr = dlsym(lib, funcs[i].name); - if (!*funcs[i].funcptr) - break; - } - if (funcs[i].name) - { - Sys_CloseLibrary((dllhandle_t*)lib); - lib = NULL; + for (i = 0; funcs[i].name; i++) + { + *funcs[i].funcptr = dlsym(lib, funcs[i].name); + if (!*funcs[i].funcptr) + break; + } + if (funcs[i].name) + { + Sys_CloseLibrary((dllhandle_t*)lib); + lib = NULL; + } } return (dllhandle_t*)lib; } +void *Sys_GetAddressForName(dllhandle_t *module, const char *exportname) +{ + if (!module) + return NULL; + return dlsym(module, exportname); +} + // ======================================================================= // Sleeps for microseconds // ======================================================================= diff --git a/engine/client/sys_morphos.c b/engine/client/sys_morphos.c index dccbf9dad..876a1cd63 100755 --- a/engine/client/sys_morphos.c +++ b/engine/client/sys_morphos.c @@ -366,21 +366,31 @@ dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs) if (!lib) return NULL; - for (i = 0; funcs[i].name; i++) + if (funcs) { - *funcs[i].funcptr = dlsym(lib, funcs[i].name); - if (!*funcs[i].funcptr) - break; - } - if (funcs[i].name) - { - Sys_CloseLibrary((dllhandle_t*)lib); - lib = NULL; + for (i = 0; funcs[i].name; i++) + { + *funcs[i].funcptr = dlsym(lib, funcs[i].name); + if (!*funcs[i].funcptr) + break; + } + if (funcs[i].name) + { + Sys_CloseLibrary((dllhandle_t*)lib); + lib = NULL; + } } return (dllhandle_t*)lib; } +void *Sys_GetAddressForName(dllhandle_t *module, const char *exportname) +{ + if (!module) + return NULL; + return dlsym(module, exportname); +} + int main(int argc, char **argv) { double oldtime, newtime; diff --git a/engine/client/sys_sdl.c b/engine/client/sys_sdl.c index 319dfab30..0a6c0905b 100644 --- a/engine/client/sys_sdl.c +++ b/engine/client/sys_sdl.c @@ -299,20 +299,29 @@ dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs) if (!lib) return NULL; - for (i = 0; funcs[i].name; i++) + if (funcs) { - *funcs[i].funcptr = SDL_LoadFunction(lib, funcs[i].name); - if (!*funcs[i].funcptr) - break; - } - if (funcs[i].name) - { - Sys_CloseLibrary((dllhandle_t*)lib); - lib = NULL; + for (i = 0; funcs[i].name; i++) + { + *funcs[i].funcptr = SDL_LoadFunction(lib, funcs[i].name); + if (!*funcs[i].funcptr) + break; + } + if (funcs[i].name) + { + Sys_CloseLibrary((dllhandle_t*)lib); + lib = NULL; + } } return (dllhandle_t*)lib; } +void *Sys_GetAddressForName(dllhandle_t *module, const char *exportname) +{ + if (!module) + return NULL; + return SDL_LoadFunction((void *)module, exportname); +} //Without these two we cannot run Q2 gamecode. dllhandle_t *q2gamedll; diff --git a/engine/gl/gl_shader.c b/engine/gl/gl_shader.c index 2508437f3..9dabc4d0f 100644 --- a/engine/gl/gl_shader.c +++ b/engine/gl/gl_shader.c @@ -944,6 +944,40 @@ struct sbuiltin_s "}\n" "#endif\n" }, + {QR_OPENGL/*ES*/, 100, "defaultwall", + "!!cvarf gl_overbright\n" + "#ifdef VERTEX_SHADER\n" + "uniform mat4 m_modelview;\n" + "uniform mat4 m_projection;\n" + "attribute vec3 v_position;\n" + "attribute vec2 v_texcoord;\n" + "attribute vec2 v_lmcoord;\n" + "varying vec2 tc, lm;\n" + + "void main (void)\n" + "{\n" + " tc = v_texcoord;\n" + " lm = v_lmcoord;\n" + " gl_Position = m_projection * m_modelview * vec4(v_position, 1.0);\n" + "}\n" + "#endif\n" + + "#ifdef FRAGMENT_SHADER\n" + "uniform sampler2D s_t0;\n" /*tex_diffuse*/ + "uniform sampler2D s_t1;\n" /*tex_lightmap*/ + //"uniform sampler2D s_t2;\n" /*tex_normalmap*/ + //"uniform sampler2D s_t3;\n" /*tex_deluxmap*/ + //"uniform sampler2D s_t4;\n" /*tex_fullbright*/ + "varying mediump vec2 tc, lm;\n" + "uniform mediump float cvar_gl_overbright;\n" + + "void main (void)\n" + "{\n" + " mediump float scale = exp2(floor(clamp(cvar_gl_overbright, 0.0, 2.0)));\n" + " gl_FragColor = texture2D(s_t0, tc) * texture2D(s_t1, lm) * vec4(scale, scale, scale, 1);\n" + "}\n" + "#endif\n" + }, {QR_OPENGL, 110, "defaultwall", "!!cvarf gl_overbright\n" "#ifdef VERTEX_SHADER\n" @@ -972,45 +1006,8 @@ struct sbuiltin_s "void main (void)\n" "{\n" - " gl_FragColor = texture2D(s_t0, tc) * texture2D(s_t1, lm) * vec4(cvar_gl_overbright, cvar_gl_overbright, cvar_gl_overbright, 1);\n" - "}\n" - "#endif\n" - }, - /*FIXME: this doesn't match the gl3 version*/ - {QR_OPENGL/*ES*/, 100, "defaultwall", - "!!permu FULLBRIGHT\n" - "#ifdef VERTEX_SHADER\n" - "uniform mat4 m_modelview;\n" - "uniform mat4 m_projection;\n" - "attribute vec3 v_position;\n" - "attribute vec2 v_texcoord;\n" - "attribute vec2 v_lmcoord;\n" - "varying vec2 tc, lm;\n" - - "void main (void)\n" - "{\n" - " tc = v_texcoord;\n" - " lm = v_lmcoord;\n" - " gl_Position = m_projection * m_modelview * vec4(v_position, 1.0);\n" - "}\n" - "#endif\n" - - "#ifdef FRAGMENT_SHADER\n" - "uniform sampler2D s_t0;\n" /*tex_diffuse*/ - "uniform sampler2D s_t1;\n" /*tex_lightmap*/ - //"uniform sampler2D s_t2;\n" /*tex_normalmap*/ - //"uniform sampler2D s_t3;\n" /*tex_deluxmap*/ - "#ifdef FULLBRIGHT\n" - "uniform sampler2D s_t4;\n" /*tex_fullbright*/ - "#endif\n" - "varying mediump vec2 tc, lm;\n" - - "void main (void)\n" - "{\n" - " gl_FragColor = texture2D(s_t0, tc) * texture2D(s_t1, lm);\n" - "#ifdef FULLBRIGHT\n" - " gl_FragColor += texture2D(s_t4, tc);\n" - "#endif\n" + " float scale = exp2(floor(clamp(cvar_gl_overbright, 0.0, 2.0)));\n" + " gl_FragColor = texture2D(s_t0, tc) * texture2D(s_t1, lm) * vec4(scale, scale, scale, 1);\n" "}\n" "#endif\n" }, @@ -1199,23 +1196,23 @@ struct sbuiltin_s "#endif\n" "varying mediump vec2 tc;\n" "varying lowp vec3 light;\n" - "uniform vec4 e_colourident;\n" + "uniform lowp vec4 e_colourident;\n" "void main (void)\n" "{\n" - " vec4 col, sp;\n" + " lowp vec4 col;\n" " col = texture2D(s_t0, tc);\n" "#ifdef UPPER\n" - " vec4 uc = texture2D(s_t2, tc);\n" + " lowp vec4 uc = texture2D(s_t2, tc);\n" " col.rgb = mix(col.rgb, uc.rgb*e_uppercolour, uc.a);\n" "#endif\n" "#ifdef LOWER\n" - " vec4 lc = texture2D(s_t1, tc);\n" + " lowp vec4 lc = texture2D(s_t1, tc);\n" " col.rgb = mix(col.rgb, lc.rgb*e_lowercolour, lc.a);\n" "#endif\n" " col.rgb *= light;\n" "#ifdef FULLBRIGHT\n" - " vec4 fb = texture2D(s_t3, tc);\n" + " lowp vec4 fb = texture2D(s_t3, tc);\n" " col.rgb = mix(col.rgb, fb.rgb, fb.a);\n" "#endif\n" " gl_FragColor = col * e_colourident;\n" diff --git a/engine/gl/gl_videgl.c b/engine/gl/gl_videgl.c index 2bbe2eb12..35174571b 100644 --- a/engine/gl/gl_videgl.c +++ b/engine/gl/gl_videgl.c @@ -4,8 +4,8 @@ EGLContext eglctx = EGL_NO_CONTEXT; EGLDisplay egldpy = EGL_NO_DISPLAY; EGLSurface eglsurf = EGL_NO_SURFACE; -static void *egllibrary; -static void *eslibrary; +static dllhandle_t egllibrary; +static dllhandle_t eslibrary; static EGLint (*qeglGetError)(void); @@ -26,10 +26,11 @@ static EGLContext (*qeglCreateContext)(EGLDisplay dpy, EGLConfig config, EGLCont static EGLBoolean (*qeglDestroyContext)(EGLDisplay dpy, EGLContext ctx); static void *(*qeglGetProcAddress) (char *name); -/* static dllfunction_t qeglfuncs[] = { {(void*)&qeglGetError, "eglGetError"}, + + {(void*)&qeglGetDisplay, "eglGetDisplay"}, {(void*)&qeglInitialize, "eglInitialize"}, {(void*)&qeglTerminate, "eglTerminate"}, @@ -49,7 +50,7 @@ static dllfunction_t qeglfuncs[] = {NULL} }; -*/ + void *EGL_Proc(char *f) { @@ -66,9 +67,9 @@ void *EGL_Proc(char *f) if (qeglGetProcAddress) proc = qeglGetProcAddress(f); if (!proc) - proc = dlsym(eslibrary, f); + proc = Sys_GetAddressForName(eslibrary, f); if (!proc) - proc = dlsym(egllibrary, f); + proc = Sys_GetAddressForName(egllibrary, f); return proc; } @@ -76,52 +77,28 @@ void *EGL_Proc(char *f) void EGL_UnloadLibrary(void) { if (egllibrary) - dlclose(egllibrary); + Sys_CloseLibrary(egllibrary); if (egllibrary == eslibrary) eslibrary = NULL; if (eslibrary) - dlclose(eslibrary); + Sys_CloseLibrary(eslibrary); eslibrary = egllibrary = NULL; } qboolean EGL_LoadLibrary(char *driver) { - /* ignore driver for now */ - egllibrary = dlopen("libEGL.so", RTLD_LAZY); - if (!egllibrary) - return false; - - /*eslibrary = dlopen("GLESwrap.so", RTLD_LAZY);*/ - eslibrary = dlopen("libGLESv2.so", RTLD_LAZY); + /* apps seem to load glesv2 first for dependency issues */ + eslibrary = Sys_LoadLibrary("libGLESv2", NULL); if (!eslibrary) return false; - - qeglGetError = dlsym(egllibrary, "eglGetError"); - - qeglGetDisplay = dlsym(egllibrary, "eglGetDisplay"); - qeglInitialize = dlsym(egllibrary, "eglInitialize"); - qeglTerminate = dlsym(egllibrary, "eglTerminate"); - - qeglGetConfigs = dlsym(egllibrary, "eglGetConfigs"); - qeglChooseConfig = dlsym(egllibrary, "eglChooseConfig"); - - qeglCreateWindowSurface = dlsym(egllibrary, "eglCreateWindowSurface"); - qeglDestroySurface = dlsym(egllibrary, "eglDestroySurface"); - qeglQuerySurface = dlsym(egllibrary, "eglQuerySurface"); - - qeglSwapBuffers = dlsym(egllibrary, "eglSwapBuffers"); - qeglMakeCurrent = dlsym(egllibrary, "eglMakeCurrent"); - qeglCreateContext = dlsym(egllibrary, "eglCreateContext"); - qeglDestroyContext = dlsym(egllibrary, "eglDestroyContext"); - - qeglGetProcAddress = dlsym(egllibrary, "eglGetProcAddress"); - - // TODO: properly unload on error - if (!qeglGetError || !qeglGetDisplay || !qeglInitialize || !qeglTerminate || !qeglCreateWindowSurface || - !qeglDestroySurface || !qeglGetConfigs || !qeglChooseConfig || !qeglQuerySurface || - !qeglSwapBuffers || !qeglMakeCurrent || !qeglCreateContext || !qeglDestroyContext || - !qeglGetProcAddress) + + egllibrary = Sys_LoadLibrary("libEGL", qeglfuncs); + if (!egllibrary) + { + /* TODO: some implementations combine EGL/GLESv2 into single library... */ + Sys_CloseLibrary(eslibrary); return false; + } return true; } diff --git a/engine/server/sv_sys_unix.c b/engine/server/sv_sys_unix.c index 7d59d66e8..5762dabe5 100644 --- a/engine/server/sv_sys_unix.c +++ b/engine/server/sv_sys_unix.c @@ -794,21 +794,29 @@ dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs) if (!lib) return NULL; - for (i = 0; funcs[i].name; i++) + if (funcs) { - *funcs[i].funcptr = dlsym(lib, funcs[i].name); - if (!*funcs[i].funcptr) - break; - } - if (funcs[i].name) - { - Sys_CloseLibrary((dllhandle_t*)lib); - lib = NULL; + for (i = 0; funcs[i].name; i++) + { + *funcs[i].funcptr = dlsym(lib, funcs[i].name); + if (!*funcs[i].funcptr) + break; + } + if (funcs[i].name) + { + Sys_CloseLibrary((dllhandle_t*)lib); + lib = NULL; + } } return (dllhandle_t*)lib; } - +void *Sys_GetAddressForName(dllhandle_t *module, const char *exportname) +{ + if (!module) + return NULL; + return dlsym(module, exportname); +} static void *game_library; diff --git a/engine/server/sv_sys_win.c b/engine/server/sv_sys_win.c index 96f666764..1ccbab18e 100644 --- a/engine/server/sv_sys_win.c +++ b/engine/server/sv_sys_win.c @@ -141,16 +141,19 @@ dllhandle_t *Sys_LoadLibrary(const char *name, dllfunction_t *funcs) if (!lib) return NULL; - for (i = 0; funcs[i].name; i++) + if (funcs) { - *funcs[i].funcptr = GetProcAddress(lib, funcs[i].name); - if (!*funcs[i].funcptr) - break; - } - if (funcs[i].name) - { - Sys_CloseLibrary((dllhandle_t*)lib); - lib = NULL; + for (i = 0; funcs[i].name; i++) + { + *funcs[i].funcptr = GetProcAddress(lib, funcs[i].name); + if (!*funcs[i].funcptr) + break; + } + if (funcs[i].name) + { + Sys_CloseLibrary((dllhandle_t*)lib); + lib = NULL; + } } return (dllhandle_t*)lib;