From df789e1d67ee6ab2da0b30988a6a803a51649154 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Wed, 12 Jun 2019 23:01:18 -0300 Subject: [PATCH] Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering. --- src/hardware/hw_cache.c | 13 ++++++++++++- src/hardware/hw_defs.h | 3 ++- src/hardware/hw_main.c | 23 +++++++++++++---------- src/hardware/hw_main.h | 3 ++- src/hardware/r_opengl/r_opengl.c | 19 ++++++++++++++++--- src/m_menu.c | 1 + src/r_main.c | 2 +- src/v_video.c | 8 +++++--- 8 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index c41812c1..32f9c285 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -573,6 +573,10 @@ GLTexture_t *HWR_GetTexture(INT32 tex) static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) { +#ifdef GLENCORE + UINT8 *flat; + INT32 steppy; +#endif size_t size, pflatsize; // setup the texture info @@ -614,6 +618,13 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) // the flat raw data needn't be converted with palettized textures W_ReadLump(flatlumpnum, Z_Malloc(W_LumpLength(flatlumpnum), PU_HWRCACHE, &grMipmap->grInfo.data)); + +#ifdef GLENCORE + flat = grMipmap->grInfo.data; + for (steppy = 0; steppy < size; steppy++) + if (flat[steppy] != HWR_PATCHES_CHROMAKEY_COLORINDEX) + flat[steppy] = grMipmap->colormap[flat[steppy]]; +#endif } @@ -859,4 +870,4 @@ void HWR_GetFadeMask(lumpnum_t fademasklumpnum) Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED); } -#endif //HWRENDER \ No newline at end of file +#endif //HWRENDER diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 32cb8a25..aba91675 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -241,6 +241,7 @@ enum hwdsetspecialstate HWD_SET_SHADERS, HWD_SET_FOG_MODE, + HWD_SET_FOG_FUNCTION, HWD_SET_FOG_DENSITY, HWD_SET_TEXTUREFILTERMODE, @@ -263,4 +264,4 @@ enum hwdfiltermode HWD_SET_TEXTUREFILTER_MIXED3, }; -#endif //_HWR_DEFS_ \ No newline at end of file +#endif //_HWR_DEFS_ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 91208e69..d19cb4ae 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -161,15 +161,16 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, UINT32 mixcolor, UIN fog_color.s.green = (UINT8)(((float)fog_color.s.green) * fog_alpha); fog_color.s.blue = (UINT8)(((float)fog_color.s.blue) * fog_alpha); + if (cv_grfog.value) { // be careful, this may get negative for high lightlevel values. float fog = (fog_alpha - (light_level/255.0f))*3/2; if (fog < 0) fog = 0; - float red = (fog_color.s.red/255.0f) * fog / 1.0f + (final_color.s.red/255.0f) * (1.0f - fog) / 1.0f; - float green = (fog_color.s.green/255.0f) * fog / 1.0f + (final_color.s.green/255.0f) * (1.0f - fog) / 1.0f; - float blue = (fog_color.s.blue/255.0f) * fog / 1.0f + (final_color.s.blue/255.0f) * (1.0f - fog) / 1.0f; + float red = ((fog_color.s.red/255.0f) * fog) + ((final_color.s.red/255.0f) * (1.0f - fog)); + float green = ((fog_color.s.green/255.0f) * fog) + ((final_color.s.green/255.0f) * (1.0f - fog)); + float blue = ((fog_color.s.blue/255.0f) * fog) + ((final_color.s.blue/255.0f) * (1.0f - fog)); final_color.s.red = (UINT8)(red*255.0f); final_color.s.green = (UINT8)(green*255.0f); final_color.s.blue = (UINT8)(blue*255.0f); @@ -4540,6 +4541,12 @@ void HWR_DrawSkyBackground(void) angle = (viewangle + xtoviewangle[0]); dimensionmultiply = ((float)textures[skytexture]->width/256.0f)*2; + if (atransform.mirror) + { + angle = InvAngle(angle); + dimensionmultiply *= -1; + } + v[0].s = v[3].s = ((float) angle / ((ANGLE_90-1)*dimensionmultiply)); v[2].s = v[1].s = (-1.0f/dimensionmultiply)+((float) angle / ((ANGLE_90-1)*dimensionmultiply)); @@ -4547,12 +4554,6 @@ void HWR_DrawSkyBackground(void) angle = aimingangle; dimensionmultiply = ((float)textures[skytexture]->height/(128.0f*aspectratio)); - if (atransform.mirror) - { - angle = InvAngle(angle); - dimensionmultiply *= -1; - } - if (splitscreen == 1) { dimensionmultiply *= 2; @@ -4726,6 +4727,7 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) if (*postprocessor == postimg_flip) atransform.flip = true; + atransform.mirror = false; if (*postprocessor == postimg_mirror) atransform.mirror = true; @@ -4832,6 +4834,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) void HWR_FoggingOn(void) { HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, cv_grsoftwarefog.value ? 2 : 1); + HWD.pfnSetSpecialState(HWD_SET_FOG_FUNCTION, cv_grfogfunction.value); HWD.pfnSetSpecialState(HWD_SET_FOG_DENSITY, cv_grfogdensity.value); } @@ -5258,4 +5261,4 @@ skip_field: return; } -#endif // HWRENDER \ No newline at end of file +#endif // HWRENDER diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index b4073b86..ad771824 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -137,6 +137,7 @@ extern consvar_t cv_grmdls; extern consvar_t cv_grfog; extern consvar_t cv_grfogdensity; extern consvar_t cv_grsoftwarefog; +extern consvar_t cv_grfogfunction; extern consvar_t cv_grgammared; extern consvar_t cv_grgammagreen; extern consvar_t cv_grgammablue; @@ -150,4 +151,4 @@ extern consvar_t cv_grfallbackplayermodel; extern CV_PossibleValue_t granisotropicmode_cons_t[]; -#endif \ No newline at end of file +#endif diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 51f348b7..59ae9e61 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -490,6 +490,7 @@ boolean SetupGLfunc(void) } static INT32 glstate_fog_mode = 0; +static INT32 glstate_fog_function = 0; static float glstate_fog_density = 0; INT32 gl_leveltime = 0; @@ -572,12 +573,17 @@ static PFNglGetUniformLocation pglGetUniformLocation; #define GLSL_SHARED_FOG_MIX \ "float fog_distance = gl_FragCoord.z / gl_FragCoord.w;\n" \ - "float fog_attenuation = fog(fog_distance, 0.0001 * ((256-lighting)/24), fog_density);\n" \ + "float fog_attenuation = 0.0001 * ((256-lighting)/24);\n" \ + "if (fog_function == 2)\n" \ + "fog_attenuation = fog2(fog_distance, fog_attenuation, fog_density);\n" \ + "else\n" \ + "fog_attenuation = fog(fog_distance, fog_attenuation, fog_density);\n" \ "if (fog_mode == 2)\n" \ "fog_attenuation = floor(fog_attenuation*10)/10;\n" \ "vec4 fog_color = vec4(fade_color[0], fade_color[1], fade_color[2], 1.0);\n" \ "vec4 mixed_color = texel * mix_color;\n" \ - "vec4 final_color = mix(mixed_color, fog_color, fog_attenuation);\n" \ + "vec4 fog_mix = mix(mixed_color, fog_color, fog_attenuation);\n" \ + "vec4 final_color = mix(fog_mix, fog_color, ((256-lighting)/256));\n" \ "final_color[3] = mixed_color[3];\n" #define GLSL_FRAGMENT_SHADER_HEADER \ @@ -586,6 +592,7 @@ static PFNglGetUniformLocation pglGetUniformLocation; "uniform vec4 fade_color;\n" \ "uniform float lighting;\n" \ "uniform int fog_mode;\n" \ + "uniform int fog_function;\n" \ "uniform float fog_density;\n" \ #define SHARED_FRAGMENT_SHADER \ @@ -1596,6 +1603,7 @@ static void load_shaders(FSurfaceInfo *Surface, GLRGBAFloat *mix, GLRGBAFloat *f { #define GETUNI(uniform) pglGetUniformLocation(gl_shaderprograms[gl_currentshaderprogram], uniform); GLint UNIFORM_fog_mode = GETUNI("fog_mode"); + GLint UNIFORM_fog_function = GETUNI("fog_function"); GLint UNIFORM_fog_density = GETUNI("fog_density"); GLint UNIFORM_mix_color = GETUNI("mix_color"); @@ -1624,6 +1632,7 @@ static void load_shaders(FSurfaceInfo *Surface, GLRGBAFloat *mix, GLRGBAFloat *f // glstate UNIFORM_1(UNIFORM_fog_mode, glstate_fog_mode, pglUniform1i); + UNIFORM_1(UNIFORM_fog_function, glstate_fog_function, pglUniform1i); UNIFORM_1(UNIFORM_fog_density, glstate_fog_density, pglUniform1f); // polygon @@ -1724,6 +1733,10 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) glstate_fog_mode = Value; break; + case HWD_SET_FOG_FUNCTION: + glstate_fog_function = Value; + break; + case HWD_SET_FOG_DENSITY: glstate_fog_density = FIXED_TO_FLOAT(Value); break; @@ -2686,4 +2699,4 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; } -#endif //HWRENDER \ No newline at end of file +#endif //HWRENDER diff --git a/src/m_menu.c b/src/m_menu.c index 826fa806..7c40eb2c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1300,6 +1300,7 @@ static menuitem_t OP_OpenGLFogMenu[] = {IT_STRING|IT_CVAR, NULL, "Fog", &cv_grfog, 10}, {IT_STRING|IT_CVAR, NULL, "Fog density", &cv_grfogdensity, 20}, {IT_STRING|IT_CVAR, NULL, "Software fog",&cv_grsoftwarefog,30}, + {IT_STRING|IT_CVAR, NULL, "Fog algorithm",&cv_grfogfunction,40}, }; static menuitem_t OP_OpenGLColorMenu[] = diff --git a/src/r_main.c b/src/r_main.c index 65e2fb19..f156c286 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1552,7 +1552,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_grfovchange); CV_RegisterVar(&cv_grfog); //CV_RegisterVar(&cv_grfogcolor); - CV_RegisterVar(&cv_grsoftwarefog); + CV_RegisterVar(&cv_grfogfunction); #ifdef ALAM_LIGHTING CV_RegisterVar(&cv_grstaticlighting); CV_RegisterVar(&cv_grdynamiclighting); diff --git a/src/v_video.c b/src/v_video.c index 5ec92eb5..90fb322b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -59,11 +59,13 @@ static void CV_Gammaxxx_ONChange(void); // but they won't do anything. static CV_PossibleValue_t grgamma_cons_t[] = {{1, "MIN"}, {255, "MAX"}, {0, NULL}}; static CV_PossibleValue_t grfogdensity_cons_t[] = {{FRACUNIT/2, "MIN"}, {FRACUNIT*2, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t grfogfunction_cons_t[] = {{1, "exp"}, {2, "exp2"}, {0, NULL}}; consvar_t cv_grshaders = {"gr_shaders", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfog = {"gr_fog", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grsoftwarefog = {"gr_softwarefog", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grfogdensity = {"gr_fogdensity", "1", CV_SAVE|CV_FLOAT, grfogdensity_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grfogfunction = {"gr_fogfunction", "exp2", CV_SAVE, grfogfunction_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grfogdensity = {"gr_fogdensity", "1.0", CV_SAVE|CV_FLOAT, grfogdensity_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfovchange = {"gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grgammared = {"gr_gammared", "127", CV_SAVE|CV_CALL, grgamma_cons_t, CV_Gammaxxx_ONChange, 0, NULL, NULL, 0, 0, NULL}; @@ -77,8 +79,8 @@ consvar_t cv_grgammablue = {"gr_gammablue", "127", CV_SAVE|CV_CALL, grgamma_cons consvar_t cv_grmdls = {"gr_mdls", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfallbackplayermodel = {"gr_fallbackplayermodel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grshearing = {"gr_shearing", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grspritebillboarding = {"gr_spritebillboarding", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grshearing = {"gr_shearing", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grspritebillboarding = {"gr_spritebillboarding", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif const UINT8 gammatable[5][256] =