The player should be able to toggle shaders

This commit is contained in:
Jaime Passos 2019-04-07 00:09:53 -03:00
parent fa7f627c88
commit 4ea1dd3525
11 changed files with 61 additions and 101 deletions

View file

@ -140,7 +140,7 @@ enum EPolyFlags
PF_Modulated = 0x00001000, // Modulation (multiply output with constant ARGB)
// When set, pass the color constant into the FSurfaceInfo -> FlatColor
PF_NoTexture = 0x00002000, // Use the small white texture
PF_Ripple = 0x00004000, // jimita: water shader effect
PF_Ripple = 0x00004000, // Water shader effect
// 0x00008000
PF_RemoveYWrap = 0x00010000, // Force clamp texture on Y
PF_ForceWrapX = 0x00020000, // Force repeat texture on X
@ -181,6 +181,8 @@ typedef struct FSurfaceInfo FSurfaceInfo;
enum hwdsetspecialstate
{
HWD_SET_SHADERS,
HWD_SET_FOG_MODE,
HWD_SET_FOG_DENSITY,

View file

@ -188,6 +188,11 @@ void HWR_NoColormapLighting(FSurfaceInfo *Surface, INT32 light_level, UINT32 mix
// You see the problem is that darker light isn't actually as dark as it SHOULD be.
lightmix = 255 - ((255 - light_level)*100/96);
// fml
if (lightmix < 0)
lightmix = 0;
if (lightmix > 255)
lightmix = 255;
mix_color.rgba = mixcolor;
fog_color.rgba = fadecolor;
@ -465,9 +470,11 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is
else
PolyFlags |= PF_Masked|PF_Modulated;
HWD.pfnSetShader(1); // jimita: floor shader
if (PolyFlags & PF_Ripple)
HWD.pfnSetShader(5); // jimita: water shader
HWD.pfnSetShader(5); // water shader
else
HWD.pfnSetShader(1); // floor shader
HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags);
}
@ -538,7 +545,7 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf)
break;
}
HWD.pfnSetShader(2); // jimita: wall shader
HWD.pfnSetShader(2); // wall shader
HWD.pfnDrawPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal);
}
}
@ -591,7 +598,7 @@ static void HWR_ProjectWall(FOutVector * wallVerts,
else
HWR_NoColormapLighting(pSurf, lightlevel, GL_NORMALFOG, GL_FADEFOG);
HWD.pfnSetShader(2); // jimita: wall shader
HWD.pfnSetShader(2); // wall shader
HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude);
#ifdef WALLSPLATS
@ -2283,7 +2290,7 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling,
else
blendmode |= PF_Masked|PF_Modulated;
HWD.pfnSetShader(1); // jimita: floor shader
HWD.pfnSetShader(1); // floor shader
HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode);
}
@ -2980,7 +2987,7 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t
if (sSurf.PolyColor.s.alpha > floorheight/4)
{
sSurf.PolyColor.s.alpha = (UINT8)(sSurf.PolyColor.s.alpha - floorheight/4);
HWD.pfnSetShader(1); // jimita: floor shader
HWD.pfnSetShader(1); // floor shader
HWD.pfnDrawPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated);
}
}
@ -3235,7 +3242,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
Surf.PolyColor.s.alpha = alpha;
HWD.pfnSetShader(3); // jimita: sprite shader
HWD.pfnSetShader(3); // sprite shader
HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated);
top = bot;
@ -3278,7 +3285,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
Surf.PolyColor.s.alpha = alpha;
HWD.pfnSetShader(3); // jimita: sprite shader
HWD.pfnSetShader(3); // sprite shader
HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated);
}
@ -3429,7 +3436,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr)
blend = PF_Translucent|PF_Occlude;
}
HWD.pfnSetShader(3); // jimita: sprite shader
HWD.pfnSetShader(3); // sprite shader
HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated);
}
}
@ -3528,7 +3535,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr)
blend = PF_Translucent|PF_Occlude;
}
HWD.pfnSetShader(3); // jimita: sprite shader
HWD.pfnSetShader(3); // sprite shader
HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated);
}
@ -3900,7 +3907,7 @@ static void HWR_RenderDrawNodes(void)
} // loop++
HWD.pfnSetTransform(&atransform);
HWD.pfnSetShader(0); // jimita
HWD.pfnSetShader(0);
// Okay! Let's draw it all! Woo!
for (i = 0; i < p; i++)
{
@ -4435,9 +4442,9 @@ static void HWR_DrawSkyBackground(void)
v[0].t = v[1].t -= ((float) angle / angleturn);
}
HWD.pfnSetShader(6); // jimita: sky shader
HWD.pfnSetShader(6); // sky shader
HWD.pfnDrawPolygon(NULL, v, 4, 0);
HWD.pfnSetShader(0); // jimita
HWD.pfnSetShader(0);
}
@ -4566,6 +4573,9 @@ static void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox)
HWD.pfnSetTransform(&atransform);
HWD.pfnSetShader(0);
// Check for shaders
HWD.pfnSetSpecialState(HWD_SET_SHADERS, cv_grshaders.value);
// Check for fog (shader)
if (cv_grfog.value)
HWR_FoggingOn(); // First of all, turn it on, set the default user settings too
@ -4754,7 +4764,7 @@ static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIE
pSurf->PolyColor.s.alpha = alpha; // put the alpha back after lighting
HWD.pfnSetShader(2); // jimita: wall shader
HWD.pfnSetShader(2); // wall shader
if (blend & PF_Environment)
HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blend|PF_Modulated|PF_Occlude); // PF_Occlude must be used for solid objects
else

View file

@ -67,6 +67,7 @@ void HWR_NoColormapLighting(FSurfaceInfo *Surface, INT32 light_level, UINT32 mix
extern CV_PossibleValue_t granisotropicmode_cons_t[];
extern consvar_t cv_grshaders;
extern consvar_t cv_grfov;
extern consvar_t cv_grmd2;
extern consvar_t cv_grfog;

View file

@ -1092,7 +1092,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr)
p.mirror = atransform.mirror; // from Kart
#endif
HWD.pfnSetShader(4); // jimita: model shader
HWD.pfnSetShader(4); // model shader
HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, finalscale, flip, &Surf);
}
}

View file

@ -492,10 +492,6 @@ boolean SetupGLfunc(void)
static INT32 glstate_fog_mode = 0;
static float glstate_fog_density = 0;
// glEXT
boolean GLEXT_legacy = false;
boolean GLEXT_shaders = false;
// hw_glob.h
INT32 gl_leveltime = 0;
@ -510,6 +506,7 @@ INT32 gl_leveltime = 0;
static GLuint gl_shaders[MAXSHADERS];
static GLint gl_totalshaders = 0;
static boolean gl_allowshaders = false;
static boolean gl_shadersenabled = false;
static GLuint gl_currentshaderprogram = 0;
static GLuint gl_shaderprograms[MAXSHADERPROGRAMS];
@ -837,12 +834,14 @@ EXPORT void HWRAPI(InitCustomShaders) (void)
EXPORT void HWRAPI(SetShader) (int shader)
{
#ifdef USE_SHADERS
if (GLEXT_shaders)
if (gl_allowshaders)
{
gl_shadersenabled = true;
gl_currentshaderprogram = shader;
}
else
#endif
gl_shadersenabled = false;
}
EXPORT void HWRAPI(UnSetShader) (void)
@ -945,16 +944,11 @@ void SetModelView(GLint w, GLint h)
pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix);
}
// -----------------+
// SetStates : Set permanent states
// -----------------+
void SetStates(void)
{
#ifdef GL_LIGHT_MODEL_AMBIENT
GLfloat LightDiffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
#endif
pglShadeModel(GL_SMOOTH); // iterate vertice colors
pglEnable(GL_TEXTURE_2D); // two-dimensional texturing
@ -980,12 +974,6 @@ void SetStates(void)
pglPolygonOffset(-1.0f, -1.0f);
// Lighting for models
#ifdef GL_LIGHT_MODEL_AMBIENT
pglLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightDiffuse);
pglEnable(GL_LIGHT0);
#endif
// bp : when no t&l :)
pglLoadIdentity();
pglScalef(1.0f, 1.0f, -1.0f);
@ -1594,7 +1582,6 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
}
// jimita
static void load_shaders(FSurfaceInfo *Surface, GLRGBAFloat *mix, GLRGBAFloat *fade)
{
#ifdef USE_SHADERS
@ -1653,7 +1640,9 @@ static void load_shaders(FSurfaceInfo *Surface, GLRGBAFloat *mix, GLRGBAFloat *f
else
pglUseProgram(0);
}
else
#endif
pglUseProgram(0);
}
// -----------------+
@ -1716,6 +1705,18 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value)
{
switch (IdState)
{
case HWD_SET_SHADERS:
switch (Value)
{
case 1:
gl_allowshaders = true;
break;
default:
gl_allowshaders = false;
break;
}
break;
case HWD_SET_FOG_MODE:
glstate_fog_mode = Value;
break;
@ -1975,11 +1976,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
static GLRGBAFloat mix = {0,0,0,0};
static GLRGBAFloat fade = {0,0,0,0};
#ifdef GL_LIGHT_MODEL_AMBIENT
GLfloat ambient[4];
GLfloat diffuse[4];
#endif
float pol = 0.0f;
float scalex, scaley, scalez;
@ -1987,9 +1983,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
int i;
// Because Otherwise, scaling the screen negatively vertically breaks the lighting
GLfloat LightPos[] = {0.0f, 1.0f, 0.0f, 0.0f};
// Affect input model scaling
scale *= 0.5f;
scalex = scale;
@ -2014,30 +2007,13 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
mix.blue = byte2float[Surface->PolyColor.s.blue];
mix.alpha = byte2float[Surface->PolyColor.s.alpha];
#ifdef GL_LIGHT_MODEL_AMBIENT
ambient[0] = (mix.red/255.0f);
ambient[1] = (mix.green/255.0f);
ambient[2] = (mix.blue/255.0f);
ambient[3] = (mix.alpha/255.0f);
diffuse[0] = (mix.red/255.0f);
diffuse[1] = (mix.green/255.0f);
diffuse[2] = (mix.blue/255.0f);
diffuse[3] = (mix.alpha/255.0f);
if (ambient[0] > 0.75f)
ambient[0] = 0.75f;
if (ambient[1] > 0.75f)
ambient[1] = 0.75f;
if (ambient[2] > 0.75f)
ambient[2] = 0.75f;
#endif
if (mix.alpha < 1)
SetBlend(PF_Translucent|PF_Modulated);
else
SetBlend(PF_Masked|PF_Modulated|PF_Occlude);
pglColor4ubv((GLubyte*)&Surface->PolyColor.s);
fade.red = byte2float[Surface->FadeColor.s.red];
fade.green = byte2float[Surface->FadeColor.s.green];
fade.blue = byte2float[Surface->FadeColor.s.blue];
@ -2069,14 +2045,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
pglCullFace(GL_BACK);
#endif
pglLightfv(GL_LIGHT0, GL_POSITION, LightPos);
pglShadeModel(GL_SMOOTH);
#ifdef GL_LIGHT_MODEL_AMBIENT
pglEnable(GL_LIGHTING);
pglMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
pglMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
#endif
pglPushMatrix(); // should be the same as glLoadIdentity
pglTranslatef(pos->x, pos->z, pos->y);
if (flipped)
@ -2189,10 +2157,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32
pglDisableClientState(GL_NORMAL_ARRAY);
pglPopMatrix(); // should be the same as glLoadIdentity
#ifdef GL_LIGHT_MODEL_AMBIENT
pglDisable(GL_LIGHTING);
#endif
pglShadeModel(GL_FLAT);
pglDisable(GL_CULL_FACE);
pglDisable(GL_NORMALIZE);

View file

@ -119,10 +119,6 @@ extern GLint screen_height;
extern GLbyte screen_depth;
extern GLint maximumAnisotropy;
// jimita
extern boolean GLEXT_legacy;
extern boolean GLEXT_shaders;
/** \brief OpenGL flags for video driver
*/
extern INT32 oglflags;

View file

@ -1206,15 +1206,16 @@ static menuitem_t OP_VideoModeMenu[] =
#ifdef HWRENDER
static menuitem_t OP_OpenGLOptionsMenu[] =
{
{IT_STRING|IT_CVAR, NULL, "Field of view", &cv_grfov, 10},
{IT_STRING|IT_CVAR, NULL, "Quality", &cv_scr_depth, 20},
{IT_STRING|IT_CVAR, NULL, "Texture Filter", &cv_grfiltermode, 30},
{IT_STRING|IT_CVAR, NULL, "Anisotropic", &cv_granisotropicmode,40},
{IT_STRING|IT_CVAR, NULL, "Shaders", &cv_grshaders, 10},
{IT_STRING|IT_CVAR, NULL, "Field of view", &cv_grfov, 20},
{IT_STRING|IT_CVAR, NULL, "Quality", &cv_scr_depth, 30},
{IT_STRING|IT_CVAR, NULL, "Texture Filter", &cv_grfiltermode, 40},
{IT_STRING|IT_CVAR, NULL, "Anisotropic", &cv_granisotropicmode,50},
#ifdef _WINDOWS
{IT_STRING|IT_CVAR, NULL, "Fullscreen", &cv_fullscreen, 50},
{IT_STRING|IT_CVAR, NULL, "Fullscreen", &cv_fullscreen, 60},
#endif
{IT_SUBMENU|IT_STRING, NULL, "Fog...", &OP_OpenGLFogDef, 80},
{IT_SUBMENU|IT_STRING, NULL, "Gamma...", &OP_OpenGLColorDef, 90},
{IT_SUBMENU|IT_STRING, NULL, "Fog...", &OP_OpenGLFogDef, 90},
{IT_SUBMENU|IT_STRING, NULL, "Gamma...", &OP_OpenGLColorDef, 100},
};
static menuitem_t OP_OpenGLFogMenu[] =

View file

@ -1395,6 +1395,7 @@ void R_RegisterEngineStuff(void)
CV_RegisterVar(&cv_grsoftwarefog);
CV_RegisterVar(&cv_grfogdensity);
CV_RegisterVar(&cv_grmd2);
CV_RegisterVar(&cv_grshaders);
#endif
#ifdef HWRENDER

View file

@ -175,14 +175,6 @@ boolean OglSdlSurface(INT32 w, INT32 h)
SetupGLFunc4();
// jimita
if (isExtAvailable("GL_ARB_compatibility", gl_extensions))
GLEXT_legacy = true;
if (isExtAvailable("GL_ARB_fragment_shader", gl_extensions)
&& isExtAvailable("GL_ARB_vertex_shader", gl_extensions))
GLEXT_shaders = true;
granisotropicmode_cons_t[1].value = maximumAnisotropy;
SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0);

View file

@ -605,15 +605,6 @@ static void ST_drawDebugInfo(void)
if (cv_debug & DBG_MEMORY)
V_DrawRightAlignedString(320, height, V_MONOSPACE, va("Heap used: %7sKB", sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)));
// jimita
if (cv_debug & DBG_RENDER)
{
height = 0;
#ifdef HWRENDER
V_DrawString(0, height, V_MONOSPACE|V_ALLOWLOWERCASE|V_NOSCALESTART, va("glstate_fog: %d", cv_grfog.value ? (cv_grsoftwarefog.value ? 2 : 1) : 0));
#endif // HWRENDER
}
}
static void ST_drawScore(void)

View file

@ -60,10 +60,11 @@ static void CV_Gammaxxx_ONChange(void);
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}};
consvar_t cv_grfovchange = {"gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 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_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};
consvar_t cv_grgammagreen = {"gr_gammagreen", "127", CV_SAVE|CV_CALL, grgamma_cons_t,
@ -71,6 +72,7 @@ consvar_t cv_grgammagreen = {"gr_gammagreen", "127", CV_SAVE|CV_CALL, grgamma_co
consvar_t cv_grgammablue = {"gr_gammablue", "127", CV_SAVE|CV_CALL, grgamma_cons_t,
CV_Gammaxxx_ONChange, 0, NULL, NULL, 0, 0, NULL};
static CV_PossibleValue_t CV_MD2[] = {{0, "Off"}, {1, "On"}, {2, "Old"}, {0, NULL}};
// console variables in development
consvar_t cv_grmd2 = {"gr_md2", "Off", CV_SAVE, CV_MD2, NULL, 0, NULL, NULL, 0, 0, NULL};