diff --git a/src/doomdef.h b/src/doomdef.h index 7358da51..6289217b 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -529,6 +529,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// on the bright side it fixes some weird issues with translucent walls /// \note SRB2CB port. /// SRB2CB itself ported this from PrBoom+ -#define NEWCLIP +//#define NEWCLIP #endif // __DOOMDEF__ diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index e5057334..e4996fd6 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -351,7 +351,7 @@ angle_t gld_FrustumAngle(void) } // SRB2CB I don't think used any of this stuff, let's disable for now since SRB2 probably doesn't want it either -// compiler complains about (p)glGetDoublev anyway, in case anyone wants this +// compiler complains about (p)glGetFloatv anyway, in case anyone wants this // only r_opengl.c can use the base gl funcs as it turns out, that's a problem for whoever wants sphere frustum checks // btw to renable define HAVE_SPHEREFRUSTRUM in hw_clip.h #ifdef HAVE_SPHEREFRUSTRUM diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 4fd2fd18..03fe0d76 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -74,21 +74,11 @@ typedef struct FLOAT x,y; } F2DCoord, v2d_t; -// Simple 3D vector -typedef struct FVector -{ - FLOAT x,y,z; -} FVector; - -// 3D model vector (coords + texture coords) -typedef struct -{ - FLOAT x,y,z; - FLOAT s,t,w; // texture coordinates -} wallVert3D; - -//Hurdler: Transform (coords + angles) -//BP: transform order : scale(rotation_x(rotation_y(translation(v)))) +// ====================== +// wallVert3D +// ---------------------- +// :crab: IS GONE! :crab: +// ====================== // Kart features //#define USE_FTRANSFORM_ANGLEZ @@ -118,9 +108,7 @@ typedef struct typedef struct { FLOAT x,y,z; - FLOAT sow; // s texture ordinate (s over w) - FLOAT tow; // t texture ordinate (t over w) - FUINT argb; // flat-shaded color + FLOAT s,t; } FOutVector; // ========================================================================== @@ -203,6 +191,9 @@ enum hwdsetspecialstate }; typedef enum hwdsetspecialstate hwdspecialstate_t; +#define GL_NORMALFOG 0x00000000 +#define GL_FADEFOG 0x19000000 + enum hwdfiltermode { HWD_SET_TEXTUREFILTER_POINTSAMPLED, diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 08bb182e..24f04494 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -108,10 +108,10 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].sow = v[3].sow = 0.0f; - v[2].sow = v[1].sow = gpatch->max_s; - v[0].tow = v[1].tow = 0.0f; - v[2].tow = v[3].tow = gpatch->max_t; + v[0].s = v[3].s = 0.0f; + v[2].s = v[1].s = gpatch->max_s; + v[0].t = v[1].t = 0.0f; + v[2].t = v[3].t = gpatch->max_t; flags = PF_Translucent|PF_NoDepthTest; @@ -265,17 +265,17 @@ void HWR_DrawFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, if (option & V_FLIP) { - v[0].sow = v[3].sow = gpatch->max_s; - v[2].sow = v[1].sow = 0.0f; + v[0].s = v[3].s = gpatch->max_s; + v[2].s = v[1].s = 0.0f; } else { - v[0].sow = v[3].sow = 0.0f; - v[2].sow = v[1].sow = gpatch->max_s; + v[0].s = v[3].s = 0.0f; + v[2].s = v[1].s = gpatch->max_s; } - v[0].tow = v[1].tow = 0.0f; - v[2].tow = v[3].tow = gpatch->max_t; + v[0].t = v[1].t = 0.0f; + v[2].t = v[3].t = gpatch->max_t; flags = PF_Translucent|PF_NoDepthTest; @@ -426,10 +426,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].sow = v[3].sow = ((sx)/(float)SHORT(gpatch->width) )*gpatch->max_s; - v[2].sow = v[1].sow = ((w )/(float)SHORT(gpatch->width) )*gpatch->max_s; - v[0].tow = v[1].tow = ((sy)/(float)SHORT(gpatch->height))*gpatch->max_t; - v[2].tow = v[3].tow = ((h )/(float)SHORT(gpatch->height))*gpatch->max_t; + v[0].s = v[3].s = ((sx)/(float)SHORT(gpatch->width) )*gpatch->max_s; + v[2].s = v[1].s = ((w )/(float)SHORT(gpatch->width) )*gpatch->max_s; + v[0].t = v[1].t = ((sy)/(float)SHORT(gpatch->height))*gpatch->max_t; + v[2].t = v[3].t = ((h )/(float)SHORT(gpatch->height))*gpatch->max_t; flags = PF_Translucent|PF_NoDepthTest; @@ -514,10 +514,10 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; // flat is 64x64 lod and texture offsets are [0.0, 1.0] - v[0].sow = v[3].sow = (float)((x & flatflag)/dflatsize); - v[2].sow = v[1].sow = (float)(v[0].sow + w/dflatsize); - v[0].tow = v[1].tow = (float)((y & flatflag)/dflatsize); - v[2].tow = v[3].tow = (float)(v[0].tow + h/dflatsize); + v[0].s = v[3].s = (float)((x & flatflag)/dflatsize); + v[2].s = v[1].s = (float)(v[0].s + w/dflatsize); + v[0].t = v[1].t = (float)((y & flatflag)/dflatsize); + v[2].t = v[3].t = (float)(v[0].t + h/dflatsize); HWR_GetFlat(flatlumpnum); @@ -553,10 +553,10 @@ void HWR_FadeScreenMenuBack(UINT32 color, INT32 height) v[2].y = v[3].y = 1.0f; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].sow = v[3].sow = 0.0f; - v[2].sow = v[1].sow = 1.0f; - v[0].tow = v[1].tow = 1.0f; - v[2].tow = v[3].tow = 0.0f; + v[0].s = v[3].s = 0.0f; + v[2].s = v[1].s = 1.0f; + v[0].t = v[1].t = 1.0f; + v[2].t = v[3].t = 0.0f; Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = (UINT8)((0xff/2) * ((float)height / vid.height)); //calum: varies console alpha @@ -579,10 +579,10 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height) v[2].y = v[3].y = 1.0f; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].sow = v[3].sow = 0.0f; - v[2].sow = v[1].sow = 1.0f; - v[0].tow = v[1].tow = 1.0f; - v[2].tow = v[3].tow = 0.0f; + v[0].s = v[3].s = 0.0f; + v[2].s = v[1].s = 1.0f; + v[0].t = v[1].t = 1.0f; + v[2].t = v[3].t = 0.0f; Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = 0x80; @@ -834,14 +834,12 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 v[0].y = v[1].y = fy; v[2].y = v[3].y = fy - fh; - //Hurdler: do we still use this argb color? if not, we should remove it - v[0].argb = v[1].argb = v[2].argb = v[3].argb = 0xff00ff00; //; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].sow = v[3].sow = 0.0f; - v[2].sow = v[1].sow = 1.0f; - v[0].tow = v[1].tow = 0.0f; - v[2].tow = v[3].tow = 1.0f; + v[0].s = v[3].s = 0.0f; + v[2].s = v[1].s = 1.0f; + v[0].t = v[1].t = 0.0f; + v[2].t = v[3].t = 1.0f; Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = 0x80; @@ -939,14 +937,12 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) v[0].y = v[1].y = fy; v[2].y = v[3].y = fy - fh; - //Hurdler: do we still use this argb color? if not, we should remove it - v[0].argb = v[1].argb = v[2].argb = v[3].argb = 0xff00ff00; //; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].sow = v[3].sow = 0.0f; - v[2].sow = v[1].sow = 1.0f; - v[0].tow = v[1].tow = 0.0f; - v[2].tow = v[3].tow = 1.0f; + v[0].s = v[3].s = 0.0f; + v[2].s = v[1].s = 1.0f; + v[0].t = v[1].t = 0.0f; + v[2].t = v[3].t = 1.0f; Surf.PolyColor = V_GetColor(color); diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 0b927bd0..b7f4b4b0 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -27,12 +27,6 @@ // ========================================================================== EXPORT boolean HWRAPI(Init) (void); -#ifndef HAVE_SDL -EXPORT void HWRAPI(Shutdown) (void); -#endif -#ifdef _WINDOWS -EXPORT void HWRAPI(GetModeList) (vmode_t **pvidmodes, INT32 *numvidmodes); -#endif #if defined (PURESDL) || defined (macintosh) EXPORT void HWRAPI(SetPalette) (INT32 *, RGBA_t *gamma); #else @@ -56,7 +50,6 @@ EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, INT32 duration, EXPORT void HWRAPI(CreateModelVBOs) (model_t *model); EXPORT void HWRAPI(SetTransform) (FTransform *ptransform); EXPORT INT32 HWRAPI(GetTextureUsed) (void); -EXPORT INT32 HWRAPI(GetRenderVersion) (void); EXPORT void HWRAPI(FlushScreenTextures) (void); EXPORT void HWRAPI(StartScreenWipe) (void); @@ -103,13 +96,6 @@ struct hwdriver_s CreateModelVBOs pfnCreateModelVBOs; SetTransform pfnSetTransform; GetTextureUsed pfnGetTextureUsed; - GetRenderVersion pfnGetRenderVersion; -#ifdef _WINDOWS - GetModeList pfnGetModeList; -#endif -#ifndef HAVE_SDL - Shutdown pfnShutdown; -#endif PostImgRedraw pfnPostImgRedraw; FlushScreenTextures pfnFlushScreenTextures; StartScreenWipe pfnStartScreenWipe; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 07b77a47..9a51fa9e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -17,8 +17,10 @@ #ifdef HWRENDER #include "hw_glob.h" -#include "hw_light.h" #include "hw_drv.h" +#include "hw_md2.h" +#include "hw_clip.h" +#include "hw_light.h" #include "../i_video.h" // for rendermode == render_glide #include "../v_video.h" @@ -34,14 +36,12 @@ #include "../st_stuff.h" #include "../i_system.h" #include "../m_cheat.h" + #ifdef ESLOPE #include "../p_slopes.h" #endif -#include "hw_md2.h" -#ifdef NEWCLIP -#include "hw_clip.h" -#endif +#define ABS(x) ((x) < 0 ? -(x) : (x)) // ========================================================================== // the hardware driver object @@ -52,7 +52,6 @@ struct hwdriver_s hwdriver; // PROTOS // ========================================================================== - static void HWR_AddSprites(sector_t *sec); static void HWR_ProjectSprite(mobj_t *thing); static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing); @@ -80,16 +79,6 @@ static CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSA {0, NULL}}; CV_PossibleValue_t granisotropicmode_cons_t[] = {{1, "MIN"}, {16, "MAX"}, {0, NULL}}; -boolean drawsky = true; - -// needs fix: walls are incorrectly clipped one column less -#ifndef NEWCLIP -static consvar_t cv_grclipwalls = {"gr_clipwalls", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -#endif -//development variables for diverse uses -static consvar_t cv_gralpha = {"gr_alpha", "160", 0, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; -static consvar_t cv_grbeta = {"gr_beta", "0", 0, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; - consvar_t cv_grrounddown = {"gr_rounddown", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfov = {"gr_fov", "90", CV_FLOAT|CV_CALL, grfov_cons_t, CV_grFov_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -111,26 +100,6 @@ static void CV_anisotropic_ONChange(void) HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_granisotropicmode.value); } -// ========================================================================== -// VIEW GLOBALS -// ========================================================================== -// Fineangles in the SCREENWIDTH wide window. -#define FIELDOFVIEW ANGLE_90 -#define ABS(x) ((x) < 0 ? -(x) : (x)) - -static angle_t gr_clipangle; - -// The viewangletox[viewangle + FINEANGLES/4] lookup -// maps the visible view angles to screen X coordinates, -// flattening the arc to a flat projection plane. -// There will be many angles mapped to the same X. -static INT32 gr_viewangletox[FINEANGLES/2]; - -// The xtoviewangleangle[] table maps a screen pixel -// to the lowest viewangle that maps back to x ranges -// from clipangle to -clipangle. -static angle_t gr_xtoviewangle[MAXVIDWIDTH+1]; - // ========================================================================== // GLOBALS // ========================================================================== @@ -160,6 +129,7 @@ static sector_t *gr_backsector; FTransform atransform; // duplicates of the main code, set after R_SetupFrame() passed them into sharedstruct, // copied here for local use +// (why?) static fixed_t dup_viewx, dup_viewy, dup_viewz; static angle_t dup_viewangle; @@ -171,8 +141,6 @@ static float gr_viewsin, gr_viewcos; // ========================================================================== #define CALCLIGHT(x,y) ((float)(x)*((y)/255.0f)) -#define NORMALFOG 0x00000000 -#define FADEFOG 0x19000000 void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, UINT32 mixcolor, UINT32 fadecolor) { @@ -453,23 +421,23 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is for (i = 0; i < nrPlaneVerts; i++,v3d++,pv++) { // Hurdler: add scrolling texture on floor/ceiling - v3d->sow = (float)((pv->x / fflatsize) - flatxref + scrollx); - v3d->tow = (float)(flatyref - (pv->y / fflatsize) + scrolly); + v3d->s = (float)((pv->x / fflatsize) - flatxref + scrollx); + v3d->t = (float)(flatyref - (pv->y / fflatsize) + scrolly); - //v3d->sow = (float)(pv->x / fflatsize); - //v3d->tow = (float)(pv->y / fflatsize); + //v3d->s = (float)(pv->x / fflatsize); + //v3d->t = (float)(pv->y / fflatsize); // Need to rotate before translate if (angle) // Only needs to be done if there's an altered angle { - tempxsow = FLOAT_TO_FIXED(v3d->sow); - tempytow = FLOAT_TO_FIXED(v3d->tow); - v3d->sow = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - v3d->tow = (FIXED_TO_FLOAT(-FixedMul(tempxsow, FINESINE(angle)) - FixedMul(tempytow, FINECOSINE(angle)))); + tempxsow = FLOAT_TO_FIXED(v3d->s); + tempytow = FLOAT_TO_FIXED(v3d->t); + v3d->s = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); + v3d->t = (FIXED_TO_FLOAT(-FixedMul(tempxsow, FINESINE(angle)) - FixedMul(tempytow, FINECOSINE(angle)))); } - //v3d->sow = (float)(v3d->sow - flatxref + scrollx); - //v3d->tow = (float)(flatyref - v3d->tow + scrolly); + //v3d->s = (float)(v3d->s - flatxref + scrollx); + //v3d->t = (float)(flatyref - v3d->t + scrolly); v3d->x = pv->x; v3d->y = height; @@ -487,7 +455,7 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is if (planecolormap) HWR_Lighting(&Surf, lightlevel, planecolormap->rgba, planecolormap->fadergba); else - HWR_NoColormapLighting(&Surf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(&Surf, lightlevel, GL_NORMALFOG, GL_FADEFOG); if (PolyFlags & (PF_Translucent|PF_Fog)) { @@ -513,13 +481,10 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is #ifdef WALLSPLATS static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) { - FOutVector trVerts[4], *wv; - wallVert3D wallVerts[4]; - wallVert3D *pwallVerts; + FOutVector wallVerts[4]; wallsplat_t *splat; GLPatch_t *gpatch; fixed_t i; - FSurfaceInfo pSurf2; // seg bbox fixed_t segbbox[4]; @@ -557,38 +522,24 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) wallVerts[3].s = wallVerts[3].t = wallVerts[2].s = wallVerts[0].t = 0.0f; wallVerts[1].s = wallVerts[1].t = wallVerts[2].t = wallVerts[0].s = 1.0f; - // transform - wv = trVerts; - pwallVerts = wallVerts; - for (i = 0; i < 4; i++,wv++,pwallVerts++) - { - wv->x = pwallVerts->x; - wv->z = pwallVerts->z; - wv->y = pwallVerts->y; - - // Kalaron: TOW and SOW needed to be switched - wv->sow = pwallVerts->t; - wv->tow = pwallVerts->s; - } - M_Memcpy(&pSurf2,pSurf,sizeof (FSurfaceInfo)); switch (splat->flags & SPLATDRAWMODE_MASK) { case SPLATDRAWMODE_OPAQUE : - pSurf2.PolyColor.s.alpha = 0xff; + pSurf.PolyColor.s.alpha = 0xff; i = PF_Translucent; break; case SPLATDRAWMODE_TRANS : - pSurf2.PolyColor.s.alpha = 128; + pSurf.PolyColor.s.alpha = 128; i = PF_Translucent; break; case SPLATDRAWMODE_SHADE : - pSurf2.PolyColor.s.alpha = 0xff; + pSurf.PolyColor.s.alpha = 0xff; i = PF_Substractive; break; } HWD.pfnSetShader(2); // jimita: wall shader - HWD.pfnDrawPolygon(&pSurf2, trVerts, 4, i|PF_Modulated|PF_Decal); + HWD.pfnDrawPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal); } } #endif @@ -619,7 +570,7 @@ FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf) // clipped so that only a visible portion of the wall seg is drawn. // floorheight, ceilingheight : depend on wall upper/lower/middle, comes from the sectors. -static void HWR_AddTransparentWall(wallVert3D *wallVerts, FSurfaceInfo * pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); +static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo * pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); // -----------------+ // HWR_ProjectWall : @@ -631,52 +582,17 @@ static void HWR_AddTransparentWall(wallVert3D *wallVerts, FSurfaceInfo * pSurf, |/ | 0--1 */ -static void HWR_ProjectWall(wallVert3D * wallVerts, +static void HWR_ProjectWall(FOutVector * wallVerts, FSurfaceInfo * pSurf, FBITFIELD blendmode, INT32 lightlevel, extracolormap_t *wallcolormap) { - FOutVector trVerts[4]; - FOutVector *wv; - - // transform - wv = trVerts; - // it sounds really stupid to do this conversion with the new T&L code - // we should directly put the right information in the right structure - // wallVerts3D seems ok, doesn't need FOutVector - // also remove the light copy - - // More messy to unwrap, but it's also quicker, uses less memory. - wv->sow = wallVerts->s; - wv->tow = wallVerts->t; - wv->x = wallVerts->x; - wv->y = wallVerts->y; - wv->z = wallVerts->z; - wv++; wallVerts++; - wv->sow = wallVerts->s; - wv->tow = wallVerts->t; - wv->x = wallVerts->x; - wv->y = wallVerts->y; - wv->z = wallVerts->z; - wv++; wallVerts++; - wv->sow = wallVerts->s; - wv->tow = wallVerts->t; - wv->x = wallVerts->x; - wv->y = wallVerts->y; - wv->z = wallVerts->z; - wv++; wallVerts++; - wv->sow = wallVerts->s; - wv->tow = wallVerts->t; - wv->x = wallVerts->x; - wv->y = wallVerts->y; - wv->z = wallVerts->z; - if (wallcolormap) HWR_Lighting(pSurf, lightlevel, wallcolormap->rgba, wallcolormap->fadergba); else - HWR_NoColormapLighting(pSurf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(pSurf, lightlevel, GL_NORMALFOG, GL_FADEFOG); HWD.pfnSetShader(2); // jimita: wall shader - HWD.pfnDrawPolygon(pSurf, trVerts, 4, blendmode|PF_Modulated|PF_Occlude); + HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude); #ifdef WALLSPLATS if (gr_curline->linedef->splats && cv_splats.value) @@ -688,45 +604,10 @@ static void HWR_ProjectWall(wallVert3D * wallVerts, // BSP, CULL, ETC.. // ========================================================================== -// return the frac from the interception of the clipping line -// (in fact a clipping plane that has a constant, so can clip with simple 2d) -// with the wall segment -// -#ifndef NEWCLIP -static float HWR_ClipViewSegment(INT32 x, polyvertex_t *v1, polyvertex_t *v2) -{ - float num, den; - float v1x, v1y, v1dx, v1dy, v2dx, v2dy; - angle_t pclipangle = gr_xtoviewangle[x]; - - // a segment of a polygon - v1x = v1->x; - v1y = v1->y; - v1dx = (v2->x - v1->x); - v1dy = (v2->y - v1->y); - - // the clipping line - pclipangle = pclipangle + dup_viewangle; //back to normal angle (non-relative) - v2dx = FIXED_TO_FLOAT(FINECOSINE(pclipangle>>ANGLETOFINESHIFT)); - v2dy = FIXED_TO_FLOAT(FINESINE(pclipangle>>ANGLETOFINESHIFT)); - - den = v2dy*v1dx - v2dx*v1dy; - if (den == 0) - return -1; // parallel - - // calc the frac along the polygon segment, - //num = (v2x - v1x)*v2dy + (v1y - v2y)*v2dx; - //num = -v1x * v2dy + v1y * v2dx; - num = (gr_viewx - v1x)*v2dy + (v1y - gr_viewy)*v2dx; - - return num / den; -} -#endif - // // HWR_SplitWall // -static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor) +static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor) { /* SoM: split up and light walls according to the lightlist. This may also include leaving out parts @@ -973,7 +854,7 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, // HWR_DrawSkyWalls // Draw walls into the depth buffer so that anything behind is culled properly -static void HWR_DrawSkyWall(wallVert3D *wallVerts, FSurfaceInfo *Surf, fixed_t bottom, fixed_t top) +static void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf, fixed_t bottom, fixed_t top) { HWD.pfnSetTexture(NULL); // no texture @@ -991,19 +872,15 @@ static void HWR_DrawSkyWall(wallVert3D *wallVerts, FSurfaceInfo *Surf, fixed_t b } // -// HWR_StoreWallRange +// HWR_ProcessSeg // A portion or all of a wall segment will be drawn, from startfrac to endfrac, // where 0 is the start of the segment, 1 the end of the segment // Anything between means the wall segment has been clipped with solidsegs, // reducing wall overdraw to a minimum // -#ifdef NEWCLIP static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom -#else -static void HWR_StoreWallRange(double startfrac, double endfrac) -#endif { - wallVert3D wallVerts[4]; + FOutVector wallVerts[4]; v2d_t vs, ve; // start, end vertices of 2d line (view from above) fixed_t worldtop, worldbottom; @@ -1026,11 +903,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) extracolormap_t *colormap; FSurfaceInfo Surf; -#ifndef NEWCLIP - if (startfrac > endfrac) - return; -#endif - gr_sidedef = gr_curline->sidedef; gr_linedef = gr_curline->linedef; @@ -1072,35 +944,19 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[0].z = wallVerts[3].z = vs.y; wallVerts[2].x = wallVerts[1].x = ve.x; wallVerts[2].z = wallVerts[1].z = ve.y; - wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f; + // x offset the texture { - // x offset the texture fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset; - -#ifndef NEWCLIP - // clip texture s start/end coords with solidsegs - if (startfrac > 0.0f && startfrac < 1.0f) - cliplow = (float)(texturehpeg + (gr_curline->flength*FRACUNIT) * startfrac); - else -#endif - cliplow = (float)texturehpeg; - -#ifndef NEWCLIP - if (endfrac > 0.0f && endfrac < 1.0f) - cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT) * endfrac); - else -#endif - cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT)); + cliplow = (float)texturehpeg; + cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT)); } lightnum = gr_frontsector->lightlevel; colormap = gr_frontsector->extra_colormap; if (gr_frontsector) - { Surf.PolyColor.s.alpha = 255; - } if (gr_backsector) { @@ -1861,14 +1717,9 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) colormap = rover->master->frontsector->extra_colormap; if (rover->master->frontsector->extra_colormap) - { - Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,rover->master->frontsector->extra_colormap->rgba); - } else - { - Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,NORMALFOG); - } + Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,GL_NORMALFOG); if (gr_frontsector->numlights) HWR_SplitWall(gr_frontsector, wallVerts, 0, &Surf, rover->flags, rover); @@ -1981,13 +1832,9 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) colormap = rover->master->frontsector->extra_colormap; if (rover->master->frontsector->extra_colormap) - { Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,rover->master->frontsector->extra_colormap->rgba); - } else - { - Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,NORMALFOG); - } + Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel,GL_NORMALFOG); if (gr_backsector->numlights) HWR_SplitWall(gr_backsector, wallVerts, 0, &Surf, rover->flags, rover); @@ -2024,7 +1871,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // // e6y: Check whether the player can look beyond this line // -#ifdef NEWCLIP + boolean checkforemptylines = true; // Don't modify anything here, just check // Kalaron: Modified for sloped linedefs @@ -2123,293 +1970,6 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks return false; } -#else -//Hurdler: just like in r_bsp.c -#if 1 -#define MAXSEGS MAXVIDWIDTH/2+1 -#else -//Alam_GBC: Or not (may cause overflow) -#define MAXSEGS 128 -#endif - -// hw_newend is one past the last valid seg -static cliprange_t * hw_newend; -static cliprange_t gr_solidsegs[MAXSEGS]; - - -static void printsolidsegs(void) -{ - cliprange_t * start; - if (!hw_newend || cv_grbeta.value != 2) - return; - for (start = gr_solidsegs;start != hw_newend;start++) - { - CONS_Debug(DBG_RENDER, "%d-%d|",start->first,start->last); - } - CONS_Debug(DBG_RENDER, "\n\n"); -} - -// -// -// -static void HWR_ClipSolidWallSegment(INT32 first, INT32 last) -{ - cliprange_t *next, *start; - float lowfrac, highfrac; - boolean poorhack = false; - - // Find the first range that touches the range - // (adjacent pixels are touching). - start = gr_solidsegs; - while (start->last < first-1) - start++; - - if (first < start->first) - { - if (last < start->first-1) - { - // Post is entirely visible (above start), - // so insert a new clippost. - HWR_StoreWallRange(first, last); - - next = hw_newend; - hw_newend++; - - while (next != start) - { - *next = *(next-1); - next--; - } - - next->first = first; - next->last = last; - printsolidsegs(); - return; - } - - // There is a fragment above *start. - if (!cv_grclipwalls.value) - { - if (!poorhack) HWR_StoreWallRange(first, last); - poorhack = true; - } - else - { - highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); - HWR_StoreWallRange(0, highfrac); - } - // Now adjust the clip size. - start->first = first; - } - - // Bottom contained in start? - if (last <= start->last) - { - printsolidsegs(); - return; - } - next = start; - while (last >= (next+1)->first-1) - { - // There is a fragment between two posts. - if (!cv_grclipwalls.value) - { - if (!poorhack) HWR_StoreWallRange(first,last); - poorhack = true; - } - else - { - lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); - highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); - HWR_StoreWallRange(lowfrac, highfrac); - } - next++; - - if (last <= next->last) - { - // Bottom is contained in next. - // Adjust the clip size. - start->last = next->last; - goto crunch; - } - } - - if (first == next->first+1) // 1 line texture - { - if (!cv_grclipwalls.value) - { - if (!poorhack) HWR_StoreWallRange(first,last); - poorhack = true; - } - else - HWR_StoreWallRange(0, 1); - } - else - { - // There is a fragment after *next. - if (!cv_grclipwalls.value) - { - if (!poorhack) HWR_StoreWallRange(first,last); - poorhack = true; - } - else - { - lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); - HWR_StoreWallRange(lowfrac, 1); - } - } - - // Adjust the clip size. - start->last = last; - - // Remove start+1 to next from the clip list, - // because start now covers their area. -crunch: - if (next == start) - { - printsolidsegs(); - // Post just extended past the bottom of one post. - return; - } - - - while (next++ != hw_newend) - { - // Remove a post. - *++start = *next; - } - - hw_newend = start; - printsolidsegs(); -} - -// -// handle LineDefs with upper and lower texture (windows) -// -static void HWR_ClipPassWallSegment(INT32 first, INT32 last) -{ - cliprange_t *start; - float lowfrac, highfrac; - //to allow noclipwalls but still solidseg reject of non-visible walls - boolean poorhack = false; - - // Find the first range that touches the range - // (adjacent pixels are touching). - start = gr_solidsegs; - while (start->last < first - 1) - start++; - - if (first < start->first) - { - if (last < start->first-1) - { - // Post is entirely visible (above start). - HWR_StoreWallRange(0, 1); - return; - } - - // There is a fragment above *start. - if (!cv_grclipwalls.value) - { //20/08/99: Changed by Hurdler (taken from faB's code) - if (!poorhack) HWR_StoreWallRange(0, 1); - poorhack = true; - } - else - { - highfrac = HWR_ClipViewSegment(min(start->first + 1, - start->last), (polyvertex_t *)gr_curline->pv1, - (polyvertex_t *)gr_curline->pv2); - HWR_StoreWallRange(0, highfrac); - } - } - - // Bottom contained in start? - if (last <= start->last) - return; - - while (last >= (start+1)->first-1) - { - // There is a fragment between two posts. - if (!cv_grclipwalls.value) - { - if (!poorhack) HWR_StoreWallRange(0, 1); - poorhack = true; - } - else - { - lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); - highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); - HWR_StoreWallRange(lowfrac, highfrac); - } - start++; - - if (last <= start->last) - return; - } - - if (first == start->first+1) // 1 line texture - { - if (!cv_grclipwalls.value) - { - if (!poorhack) HWR_StoreWallRange(0, 1); - poorhack = true; - } - else - HWR_StoreWallRange(0, 1); - } - else - { - // There is a fragment after *next. - if (!cv_grclipwalls.value) - { - if (!poorhack) HWR_StoreWallRange(0,1); - poorhack = true; - } - else - { - lowfrac = HWR_ClipViewSegment(max(start->last - 1, - start->first), (polyvertex_t *)gr_curline->pv1, - (polyvertex_t *)gr_curline->pv2); - HWR_StoreWallRange(lowfrac, 1); - } - } -} - -// -------------------------------------------------------------------------- -// HWR_ClipToSolidSegs check if it is hide by wall (solidsegs) -// -------------------------------------------------------------------------- -static boolean HWR_ClipToSolidSegs(INT32 first, INT32 last) -{ - cliprange_t * start; - - // Find the first range that touches the range - // (adjacent pixels are touching). - start = gr_solidsegs; - while (start->last < first-1) - start++; - - if (first < start->first) - return true; - - // Bottom contained in start? - if (last <= start->last) - return false; - - return true; -} - -// -// HWR_ClearClipSegs -// -static void HWR_ClearClipSegs(void) -{ - gr_solidsegs[0].first = -0x7fffffff; - gr_solidsegs[0].last = -1; - gr_solidsegs[1].first = vid.width; //viewwidth; - gr_solidsegs[1].last = 0x7fffffff; - hw_newend = gr_solidsegs+2; -} -#endif // NEWCLIP // -----------------+ // HWR_AddLine : Clips the given segment and adds any visible pieces to the line list. @@ -2419,10 +1979,6 @@ static void HWR_ClearClipSegs(void) static void HWR_AddLine(seg_t * line) { angle_t angle1, angle2; -#ifndef NEWCLIP - INT32 x1, x2; - angle_t span, tspan; -#endif // SoM: Backsector needs to be run through R_FakeFlat static sector_t tempsec; @@ -2441,112 +1997,25 @@ static void HWR_AddLine(seg_t * line) v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle(v1x, v1y); - angle2 = R_PointToAngle(v2x, v2y); + angle1 = R_PointToAngleEx(viewx, viewy, v1x, v1y); + angle2 = R_PointToAngleEx(viewx, viewy, v2x, v2y); -#ifdef NEWCLIP // PrBoom: Back side, i.e. backface culling - read: endAngle >= startAngle! if (angle2 - angle1 < ANGLE_180) return; // PrBoom: use REAL clipping math YAYYYYYYY!!! - if (!gld_clipper_SafeCheckRange(angle2, angle1)) - { return; - } checkforemptylines = true; -#else - // Clip to view edges. - span = angle1 - angle2; - - // backface culling : span is < ANGLE_180 if ang1 > ang2 : the seg is facing - if (span >= ANGLE_180) - return; - - // Global angle needed by segcalc. - //rw_angle1 = angle1; - angle1 -= dup_viewangle; - angle2 -= dup_viewangle; - - tspan = angle1 + gr_clipangle; - if (tspan > 2*gr_clipangle) - { - tspan -= 2*gr_clipangle; - - // Totally off the left edge? - if (tspan >= span) - return; - - angle1 = gr_clipangle; - } - tspan = gr_clipangle - angle2; - if (tspan > 2*gr_clipangle) - { - tspan -= 2*gr_clipangle; - - // Totally off the left edge? - if (tspan >= span) - return; - - angle2 = (angle_t)-(signed)gr_clipangle; - } - -#if 0 - { - float fx1,fx2,fy1,fy2; - //BP: test with a better projection than viewangletox[R_PointToAngle(angle)] - // do not enable this at release 4 mul and 2 div - fx1 = ((polyvertex_t *)(line->pv1))->x-gr_viewx; - fy1 = ((polyvertex_t *)(line->pv1))->y-gr_viewy; - fy2 = (fx1 * gr_viewcos + fy1 * gr_viewsin); - if (fy2 < 0) - // the point is back - fx1 = 0; - else - fx1 = gr_windowcenterx + (fx1 * gr_viewsin - fy1 * gr_viewcos) * gr_centerx / fy2; - - fx2 = ((polyvertex_t *)(line->pv2))->x-gr_viewx; - fy2 = ((polyvertex_t *)(line->pv2))->y-gr_viewy; - fy1 = (fx2 * gr_viewcos + fy2 * gr_viewsin); - if (fy1 < 0) - // the point is back - fx2 = vid.width; - else - fx2 = gr_windowcenterx + (fx2 * gr_viewsin - fy2 * gr_viewcos) * gr_centerx / fy1; - - x1 = fx1+0.5f; - x2 = fx2+0.5f; - } -#else - // The seg is in the view range, - // but not necessarily visible. - angle1 = (angle1+ANGLE_90)>>ANGLETOFINESHIFT; - angle2 = (angle2+ANGLE_90)>>ANGLETOFINESHIFT; - - x1 = gr_viewangletox[angle1]; - x2 = gr_viewangletox[angle2]; -#endif - // Does not cross a pixel? -// if (x1 == x2) -/* { - // BP: HERE IS THE MAIN PROBLEM ! - //CONS_Debug(DBG_RENDER, "tineline\n"); - return; - } -*/ -#endif gr_backsector = line->backsector; -#ifdef NEWCLIP if (!line->backsector) - { gld_clipper_SafeAddClipRange(angle2, angle1); - } - else - { + else + { gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); if (CheckClip(line, gr_frontsector, gr_backsector)) { @@ -2563,92 +2032,6 @@ static void HWR_AddLine(seg_t * line) HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D return; -#else - // Single sided line? - if (!gr_backsector) - goto clipsolid; - - gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); - -#ifdef ESLOPE - if (gr_frontsector->f_slope || gr_frontsector->c_slope || gr_backsector->f_slope || gr_backsector->c_slope) - { - fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends - fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends - -#define SLOPEPARAMS(slope, end1, end2, normalheight) \ - if (slope) { \ - end1 = P_GetZAt(slope, v1x, v1y); \ - end2 = P_GetZAt(slope, v2x, v2y); \ - } else \ - end1 = end2 = normalheight; - - SLOPEPARAMS(gr_frontsector->f_slope, frontf1, frontf2, gr_frontsector->floorheight) - SLOPEPARAMS(gr_frontsector->c_slope, frontc1, frontc2, gr_frontsector->ceilingheight) - SLOPEPARAMS( gr_backsector->f_slope, backf1, backf2, gr_backsector->floorheight) - SLOPEPARAMS( gr_backsector->c_slope, backc1, backc2, gr_backsector->ceilingheight) -#undef SLOPEPARAMS - - // Closed door. - if ((backc1 <= frontf1 && backc2 <= frontf2) - || (backf1 >= frontc1 && backf2 >= frontc2)) - { - goto clipsolid; - } - - // Check for automap fix. - if (backc1 <= backf1 && backc2 <= backf2 - && ((backc1 >= frontc1 && backc2 >= frontc2) || gr_curline->sidedef->toptexture) - && ((backf1 <= frontf1 && backf2 >= frontf2) || gr_curline->sidedef->bottomtexture) - && (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum)) - goto clipsolid; - - // Window. - if (backc1 != frontc1 || backc2 != frontc2 - || backf1 != frontf1 || backf2 != frontf2) - { - goto clippass; - } - } - else -#endif - { - // Closed door. - if (gr_backsector->ceilingheight <= gr_frontsector->floorheight || - gr_backsector->floorheight >= gr_frontsector->ceilingheight) - goto clipsolid; - - // Check for automap fix. - if (gr_backsector->ceilingheight <= gr_backsector->floorheight - && ((gr_backsector->ceilingheight >= gr_frontsector->ceilingheight) || gr_curline->sidedef->toptexture) - && ((gr_backsector->floorheight <= gr_backsector->floorheight) || gr_curline->sidedef->bottomtexture) - && (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum)) - goto clipsolid; - - // Window. - if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || - gr_backsector->floorheight != gr_frontsector->floorheight) - goto clippass; - } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if (R_IsEmptyLine(gr_curline, gr_frontsector, gr_backsector)) - return; - -clippass: - if (x1 == x2) - { x2++;x1 -= 2; } - HWR_ClipPassWallSegment(x1, x2-1); - return; - -clipsolid: - if (x1 == x2) - goto clippass; - HWR_ClipSolidWallSegment(x1, x2-1); -#endif } // HWR_CheckBBox @@ -2663,10 +2046,6 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) INT32 boxpos; fixed_t px1, py1, px2, py2; angle_t angle1, angle2; -#ifndef NEWCLIP - INT32 sx1, sx2; - angle_t span, tspan; -#endif // Find the corners of the box // that define the edges from current viewpoint. @@ -2692,59 +2071,9 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) px2 = bspcoord[checkcoord[boxpos][2]]; py2 = bspcoord[checkcoord[boxpos][3]]; -#ifdef NEWCLIP angle1 = R_PointToAngle(px1, py1); angle2 = R_PointToAngle(px2, py2); return gld_clipper_SafeCheckRange(angle2, angle1); -#else - // check clip list for an open space - angle1 = R_PointToAngle2(dup_viewx>>1, dup_viewy>>1, px1>>1, py1>>1) - dup_viewangle; - angle2 = R_PointToAngle2(dup_viewx>>1, dup_viewy>>1, px2>>1, py2>>1) - dup_viewangle; - - span = angle1 - angle2; - - // Sitting on a line? - if (span >= ANGLE_180) - return true; - - tspan = angle1 + gr_clipangle; - - if (tspan > 2*gr_clipangle) - { - tspan -= 2*gr_clipangle; - - // Totally off the left edge? - if (tspan >= span) - return false; - - angle1 = gr_clipangle; - } - tspan = gr_clipangle - angle2; - if (tspan > 2*gr_clipangle) - { - tspan -= 2*gr_clipangle; - - // Totally off the left edge? - if (tspan >= span) - return false; - - angle2 = (angle_t)-(signed)gr_clipangle; - } - - // Find the first clippost - // that touches the source post - // (adjacent pixels are touching). - angle1 = (angle1+ANGLE_90)>>ANGLETOFINESHIFT; - angle2 = (angle2+ANGLE_90)>>ANGLETOFINESHIFT; - sx1 = gr_viewangletox[angle1]; - sx2 = gr_viewangletox[angle2]; - - // Does not cross a pixel. - if (sx1 == sx2) - return false; - - return HWR_ClipToSolidSegs(sx1, sx2 - 1); -#endif } #ifdef POLYOBJECTS @@ -2924,16 +2253,16 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, for (i = 0; i < (INT32)nrPlaneVerts; i++,v3d++) { // Hurdler: add scrolling texture on floor/ceiling - v3d->sow = (float)((FIXED_TO_FLOAT(polysector->origVerts[i].x) / fflatsize) - flatxref + scrollx); // Go from the polysector's original vertex locations - v3d->tow = (float)(flatyref - (FIXED_TO_FLOAT(polysector->origVerts[i].y) / fflatsize) + scrolly); // Means the flat is offset based on the original vertex locations + v3d->s = (float)((FIXED_TO_FLOAT(polysector->origVerts[i].x) / fflatsize) - flatxref + scrollx); // Go from the polysector's original vertex locations + v3d->t = (float)(flatyref - (FIXED_TO_FLOAT(polysector->origVerts[i].y) / fflatsize) + scrolly); // Means the flat is offset based on the original vertex locations // Need to rotate before translate if (angle) // Only needs to be done if there's an altered angle { - tempxsow = FLOAT_TO_FIXED(v3d->sow); - tempytow = FLOAT_TO_FIXED(v3d->tow); - v3d->sow = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - v3d->tow = (FIXED_TO_FLOAT(-FixedMul(tempxsow, FINESINE(angle)) - FixedMul(tempytow, FINECOSINE(angle)))); + tempxsow = FLOAT_TO_FIXED(v3d->s); + tempytow = FLOAT_TO_FIXED(v3d->t); + v3d->s = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); + v3d->t = (FIXED_TO_FLOAT(-FixedMul(tempxsow, FINESINE(angle)) - FixedMul(tempytow, FINECOSINE(angle)))); } v3d->x = FIXED_TO_FLOAT(polysector->vertices[i]->x); @@ -2944,7 +2273,7 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, if (planecolormap) HWR_Lighting(&Surf, lightlevel, planecolormap->rgba, planecolormap->fadergba); else - HWR_NoColormapLighting(&Surf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(&Surf, lightlevel, GL_NORMALFOG, GL_FADEFOG); if (blendmode & PF_Translucent) { @@ -3179,10 +2508,6 @@ static void HWR_Subsector(size_t num) } } - // Moved here because before, when above the ceiling and the floor does not have the sky flat, it doesn't draw the sky - if (gr_frontsector->ceilingpic == skyflatnum || gr_frontsector->floorpic == skyflatnum) - drawsky = true; - if (gr_frontsector->ffloors) { /// \todo fix light, xoffs, yoffs, extracolormap ? @@ -3222,7 +2547,7 @@ static void HWR_Subsector(size_t num) if (rover->master->frontsector->extra_colormap) alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap->rgba); else - alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, NORMALFOG); + alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, GL_NORMALFOG); HWR_AddTransparentFloor(0, &extrasubsectors[num], @@ -3277,7 +2602,7 @@ static void HWR_Subsector(size_t num) if (rover->master->frontsector->extra_colormap) alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap->rgba); else - alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, NORMALFOG); + alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, GL_NORMALFOG); HWR_AddTransparentFloor(0, &extrasubsectors[num], @@ -3402,100 +2727,6 @@ static void HWR_RenderBSPNode(INT32 bspnum) HWR_RenderBSPNode(bsp->children[side^1]); } -/* -// -// Clear 'stack' of subsectors to draw -// -static void HWR_ClearDrawSubsectors(void) -{ - gr_drawsubsector_p = gr_drawsubsectors; -} - -// -// Draw subsectors pushed on the drawsubsectors 'stack', back to front -// -static void HWR_RenderSubsectors(void) -{ - while (gr_drawsubsector_p > gr_drawsubsectors) - { - HWR_RenderBSPNode( - lastsubsec->nextsubsec = bspnum & (~NF_SUBSECTOR); - } -} -*/ - -// ========================================================================== -// FROM R_MAIN.C -// ========================================================================== - -//BP : exactely the same as R_InitTextureMapping -void HWR_InitTextureMapping(void) -{ - angle_t i; - INT32 x; - INT32 t; - fixed_t focallength; - fixed_t grcenterx; - fixed_t grcenterxfrac; - INT32 grviewwidth; - -#define clipanglefov (FIELDOFVIEW>>ANGLETOFINESHIFT) - - grviewwidth = vid.width; - grcenterx = grviewwidth/2; - grcenterxfrac = grcenterx< FRACUNIT*2) - t = -1; - else if (FINETANGENT(i) < -FRACUNIT*2) - t = grviewwidth+1; - else - { - t = FixedMul(FINETANGENT(i), focallength); - t = (grcenterxfrac - t+FRACUNIT-1)>>FRACBITS; - - if (t < -1) - t = -1; - else if (t > grviewwidth+1) - t = grviewwidth+1; - } - gr_viewangletox[i] = t; - } - - // Scan viewangletox[] to generate xtoviewangle[]: - // xtoviewangle will give the smallest view angle - // that maps to x. - for (x = 0; x <= grviewwidth; x++) - { - i = 0; - while (gr_viewangletox[i]>x) - i++; - gr_xtoviewangle[x] = (i<flip) { - swallVerts[0].sow = swallVerts[3].sow = gpatch->max_s; - swallVerts[2].sow = swallVerts[1].sow = 0; + swallVerts[0].s = swallVerts[3].s = gpatch->max_s; + swallVerts[2].s = swallVerts[1].s = 0; } else { - swallVerts[0].sow = swallVerts[3].sow = 0; - swallVerts[2].sow = swallVerts[1].sow = gpatch->max_s; + swallVerts[0].s = swallVerts[3].s = 0; + swallVerts[2].s = swallVerts[1].s = gpatch->max_s; } // flip the texture coords (look familiar?) if (spr->vflip) { - swallVerts[3].tow = swallVerts[2].tow = gpatch->max_t; - swallVerts[0].tow = swallVerts[1].tow = 0; + swallVerts[3].t = swallVerts[2].t = gpatch->max_t; + swallVerts[0].t = swallVerts[1].t = 0; } else { - swallVerts[3].tow = swallVerts[2].tow = 0; - swallVerts[0].tow = swallVerts[1].tow = gpatch->max_t; + swallVerts[3].t = swallVerts[2].t = 0; + swallVerts[0].t = swallVerts[1].t = gpatch->max_t; } sSurf.PolyColor.s.red = 0x00; @@ -3821,24 +3052,28 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (spr->flip) { - wallVerts[0].sow = wallVerts[3].sow = gpatch->max_s; - wallVerts[2].sow = wallVerts[1].sow = 0; - }else{ - wallVerts[0].sow = wallVerts[3].sow = 0; - wallVerts[2].sow = wallVerts[1].sow = gpatch->max_s; + wallVerts[0].s = wallVerts[3].s = gpatch->max_s; + wallVerts[2].s = wallVerts[1].s = 0; + } + else + { + wallVerts[0].s = wallVerts[3].s = 0; + wallVerts[2].s = wallVerts[1].s = gpatch->max_s; } // flip the texture coords (look familiar?) if (spr->vflip) { - wallVerts[3].tow = wallVerts[2].tow = gpatch->max_t; - wallVerts[0].tow = wallVerts[1].tow = 0; - }else{ - wallVerts[3].tow = wallVerts[2].tow = 0; - wallVerts[0].tow = wallVerts[1].tow = gpatch->max_t; + wallVerts[3].t = wallVerts[2].t = gpatch->max_t; + wallVerts[0].t = wallVerts[1].t = 0; + } + else + { + wallVerts[3].t = wallVerts[2].t = 0; + wallVerts[0].t = wallVerts[1].t = gpatch->max_t; } - // if it has a dispoffset, push it a little towards the camera + // if it has a dispoffset, push it a little tards the camera if (spr->dispoffset) { float co = -gr_viewcos*(0.05f*spr->dispoffset); float si = -gr_viewsin*(0.05f*spr->dispoffset); @@ -3850,8 +3085,8 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) realtop = top = wallVerts[3].y; realbot = bot = wallVerts[0].y; - towtop = wallVerts[3].tow; - towbot = wallVerts[0].tow; + towtop = wallVerts[3].t; + towbot = wallVerts[0].t; towmult = (towbot - towtop) / (top - bot); #ifdef ESLOPE @@ -3976,18 +3211,18 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) #endif #ifdef ESLOPE - wallVerts[3].tow = towtop + ((realtop - top) * towmult); - wallVerts[2].tow = towtop + ((endrealtop - endtop) * towmult); - wallVerts[0].tow = towtop + ((realtop - bot) * towmult); - wallVerts[1].tow = towtop + ((endrealtop - endbot) * towmult); + wallVerts[3].t = towtop + ((realtop - top) * towmult); + wallVerts[2].t = towtop + ((endrealtop - endtop) * towmult); + wallVerts[0].t = towtop + ((realtop - bot) * towmult); + wallVerts[1].t = towtop + ((endrealtop - endbot) * towmult); wallVerts[3].y = top; wallVerts[2].y = endtop; wallVerts[0].y = bot; wallVerts[1].y = endbot; #else - wallVerts[3].tow = wallVerts[2].tow = towtop + ((realtop - top) * towmult); - wallVerts[0].tow = wallVerts[1].tow = towtop + ((realtop - bot) * towmult); + wallVerts[3].t = wallVerts[2].t = towtop + ((realtop - top) * towmult); + wallVerts[0].t = wallVerts[1].t = towtop + ((realtop - bot) * towmult); wallVerts[2].y = wallVerts[3].y = top; wallVerts[0].y = wallVerts[1].y = bot; @@ -3996,7 +3231,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (colormap) HWR_Lighting(&Surf, lightlevel, colormap->rgba, colormap->fadergba); else - HWR_NoColormapLighting(&Surf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(&Surf, lightlevel, GL_NORMALFOG, GL_FADEFOG); Surf.PolyColor.s.alpha = alpha; @@ -4019,18 +3254,18 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // If we're ever down here, somehow the above loop hasn't draw all the light levels of sprite #ifdef ESLOPE - wallVerts[3].tow = towtop + ((realtop - top) * towmult); - wallVerts[2].tow = towtop + ((endrealtop - endtop) * towmult); - wallVerts[0].tow = towtop + ((realtop - bot) * towmult); - wallVerts[1].tow = towtop + ((endrealtop - endbot) * towmult); + wallVerts[3].t = towtop + ((realtop - top) * towmult); + wallVerts[2].t = towtop + ((endrealtop - endtop) * towmult); + wallVerts[0].t = towtop + ((realtop - bot) * towmult); + wallVerts[1].t = towtop + ((endrealtop - endbot) * towmult); wallVerts[3].y = top; wallVerts[2].y = endtop; wallVerts[0].y = bot; wallVerts[1].y = endbot; #else - wallVerts[3].tow = wallVerts[2].tow = towtop + ((realtop - top) * towmult); - wallVerts[0].tow = wallVerts[1].tow = towtop + ((realtop - bot) * towmult); + wallVerts[3].t = wallVerts[2].t = towtop + ((realtop - top) * towmult); + wallVerts[0].t = wallVerts[1].t = towtop + ((realtop - bot) * towmult); wallVerts[2].y = wallVerts[3].y = top; wallVerts[0].y = wallVerts[1].y = bot; @@ -4039,7 +3274,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (colormap) HWR_Lighting(&Surf, lightlevel, colormap->rgba, colormap->fadergba); else - HWR_NoColormapLighting(&Surf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(&Surf, lightlevel, GL_NORMALFOG, GL_FADEFOG); Surf.PolyColor.s.alpha = alpha; @@ -4107,21 +3342,21 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) if (spr->flip) { - wallVerts[0].sow = wallVerts[3].sow = gpatch->max_s; - wallVerts[2].sow = wallVerts[1].sow = 0; + wallVerts[0].s = wallVerts[3].s = gpatch->max_s; + wallVerts[2].s = wallVerts[1].s = 0; }else{ - wallVerts[0].sow = wallVerts[3].sow = 0; - wallVerts[2].sow = wallVerts[1].sow = gpatch->max_s; + wallVerts[0].s = wallVerts[3].s = 0; + wallVerts[2].s = wallVerts[1].s = gpatch->max_s; } // flip the texture coords (look familiar?) if (spr->vflip) { - wallVerts[3].tow = wallVerts[2].tow = gpatch->max_t; - wallVerts[0].tow = wallVerts[1].tow = 0; + wallVerts[3].t = wallVerts[2].t = gpatch->max_t; + wallVerts[0].t = wallVerts[1].t = 0; }else{ - wallVerts[3].tow = wallVerts[2].tow = 0; - wallVerts[0].tow = wallVerts[1].tow = gpatch->max_t; + wallVerts[3].t = wallVerts[2].t = 0; + wallVerts[0].t = wallVerts[1].t = gpatch->max_t; } // cache the patch in the graphics card memory @@ -4141,7 +3376,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) HWR_DrawSpriteShadow(spr, gpatch, this_scale); } - // if it has a dispoffset, push it a little towards the camera + // if it has a dispoffset, push it a little tards the camera if (spr->dispoffset) { float co = -gr_viewcos*(0.05f*spr->dispoffset); float si = -gr_viewsin*(0.05f*spr->dispoffset); @@ -4167,7 +3402,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) if (colormap) HWR_Lighting(&Surf, lightlevel, colormap->rgba, colormap->fadergba); else - HWR_NoColormapLighting(&Surf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(&Surf, lightlevel, GL_NORMALFOG, GL_FADEFOG); } { @@ -4232,11 +3467,11 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) wallVerts[0].z = wallVerts[3].z = spr->z1; wallVerts[1].z = wallVerts[2].z = spr->z2; - wallVerts[0].sow = wallVerts[3].sow = 0; - wallVerts[2].sow = wallVerts[1].sow = gpatch->max_s; + wallVerts[0].s = wallVerts[3].s = 0; + wallVerts[2].s = wallVerts[1].s = gpatch->max_s; - wallVerts[3].tow = wallVerts[2].tow = 0; - wallVerts[0].tow = wallVerts[1].tow = gpatch->max_t; + wallVerts[3].t = wallVerts[2].t = 0; + wallVerts[0].t = wallVerts[1].t = gpatch->max_t; // cache the patch in the graphics card memory //12/12/99: Hurdler: same comment as above (for md2) @@ -4273,7 +3508,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) if (colormap) HWR_Lighting(&Surf, lightlevel, colormap->rgba, colormap->fadergba); else - HWR_NoColormapLighting(&Surf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(&Surf, lightlevel, GL_NORMALFOG, GL_FADEFOG); } if (spr->mobj->flags2 & MF2_SHADOW) @@ -4396,7 +3631,7 @@ static void HWR_SortVisSprites(void) // middle texture. This is used for sorting with sprites. typedef struct { - wallVert3D wallVerts[4]; + FOutVector wallVerts[4]; FSurfaceInfo Surf; INT32 texnum; FBITFIELD blend; @@ -4409,7 +3644,7 @@ typedef struct static wallinfo_t *wallinfo = NULL; static size_t numwalls = 0; // a list of transparent walls to be drawn -static void HWR_RenderWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); +static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, INT32 lightlevel, extracolormap_t *wallcolormap); #define MAX_TRANSPARENTWALL 256 @@ -4523,9 +3758,9 @@ void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *polysector, } // -// HWR_CreateDrawNodes -// Creates and sorts a list of drawnodes for the scene being rendered. -static void HWR_CreateDrawNodes(void) +// HWR_RenderDrawNodes +// Creates, sorts and renders a list of drawnodes for the current frame. +static void HWR_RenderDrawNodes(void) { UINT32 i = 0, p = 0, prev = 0, loop; const fixed_t pviewz = dup_viewz; @@ -4693,7 +3928,7 @@ static void HWR_CreateDrawNodes(void) { if (!(sortnode[sortindex[i]].wall->blend & PF_NoTexture)) HWR_GetTexture(sortnode[sortindex[i]].wall->texnum); - HWR_RenderWall(sortnode[sortindex[i]].wall->wallVerts, &sortnode[sortindex[i]].wall->Surf, sortnode[sortindex[i]].wall->blend, sortnode[sortindex[i]].wall->fogwall, + HWR_RenderWall(sortnode[sortindex[i]].wall->wallVerts, &sortnode[sortindex[i]].wall->Surf, sortnode[sortindex[i]].wall->blend, sortnode[sortindex[i]].wall->lightlevel, sortnode[sortindex[i]].wall->wallcolormap); } } @@ -5156,11 +4391,11 @@ static void HWR_DrawSkyBackground(void) // software doesn't draw any further than 1024 for skies anyway, but this doesn't overlap properly // The only time this will probably be an issue is when a sky wider than 1024 is used as a sky AND a regular wall texture - angle = (dup_viewangle + gr_xtoviewangle[0]); + angle = (dup_viewangle + xtoviewangle[0]); dimensionmultiply = ((float)textures[skytexture]->width/256.0f); - v[0].sow = v[3].sow = ((float) angle / ((ANGLE_90-1)*dimensionmultiply)); - v[2].sow = v[1].sow = (-1.0f/dimensionmultiply)+((float) angle / ((ANGLE_90-1)*dimensionmultiply)); + 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)); // Y angle = aimingangle; @@ -5177,13 +4412,13 @@ static void HWR_DrawSkyBackground(void) if (atransform.flip) { // During vertical flip the sky should be flipped and it's y movement should also be flipped obviously - v[3].tow = v[2].tow = -(0.5f-(0.5f/dimensionmultiply)); - v[0].tow = v[1].tow = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); + v[3].t = v[2].t = -(0.5f-(0.5f/dimensionmultiply)); + v[0].t = v[1].t = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); } else { - v[3].tow = v[2].tow = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); - v[0].tow = v[1].tow = -(0.5f-(0.5f/dimensionmultiply)); + v[3].t = v[2].t = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); + v[0].t = v[1].t = -(0.5f-(0.5f/dimensionmultiply)); } angleturn = (((float)ANGLE_45-1.0f)*aspectratio)*dimensionmultiply; @@ -5191,13 +4426,13 @@ static void HWR_DrawSkyBackground(void) if (angle > ANGLE_180) // Do this because we don't want the sky to suddenly teleport when crossing over 0 to 360 and vice versa { angle = InvAngle(angle); - v[3].tow = v[2].tow += ((float) angle / angleturn); - v[0].tow = v[1].tow += ((float) angle / angleturn); + v[3].t = v[2].t += ((float) angle / angleturn); + v[0].t = v[1].t += ((float) angle / angleturn); } else { - v[3].tow = v[2].tow -= ((float) angle / angleturn); - v[0].tow = v[1].tow -= ((float) angle / angleturn); + v[3].t = v[2].t -= ((float) angle / angleturn); + v[0].t = v[1].t -= ((float) angle / angleturn); } HWD.pfnSetShader(6); // jimita: sky shader @@ -5211,23 +4446,12 @@ static void HWR_DrawSkyBackground(void) // -----------------+ static inline void HWR_ClearView(void) { - // 3--2 - // | /| - // |/ | - // 0--1 - - /// \bug faB - enable depth mask, disable color mask - HWD.pfnGClipRect((INT32)gr_viewwindowx, (INT32)gr_viewwindowy, (INT32)(gr_viewwindowx + gr_viewwidth), (INT32)(gr_viewwindowy + gr_viewheight), ZCLIP_PLANE); HWD.pfnClearBuffer(false, true, 0); - - //disable clip window - set to full size - // rem by Hurdler - // HWD.pfnGClipRect(0, 0, vid.width, vid.height); } @@ -5263,28 +4487,13 @@ void HWR_SetViewSize(void) } // ========================================================================== -// Same as rendering the player view, but from the skybox object +// Render the current frame. // ========================================================================== -void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) +static void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) { + angle_t a1; const float fpov = FIXED_TO_FLOAT(cv_grfov.value+player->fovadd); - postimg_t *type; - - if (splitscreen && player == &players[secondarydisplayplayer]) - type = &postimgtype2; - else - type = &postimgtype; - - { - // do we really need to save player (is it not the same)? - player_t *saved_player = stplyr; - stplyr = player; - ST_doPaletteStuff(); - stplyr = saved_player; - } - - // note: sets viewangle, viewx, viewy, viewz - R_SkyboxFrame(player); + postimg_t *postprocessor; // copy view cam position for local use dup_viewx = viewx; @@ -5311,95 +4520,64 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) gr_viewsin = FIXED_TO_FLOAT(viewsin); gr_viewcos = FIXED_TO_FLOAT(viewcos); - //04/01/2000: Hurdler: added for T&L - // It should replace all other gr_viewxxx when finished - atransform.anglex = (float)(aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + // Set T&L transform + atransform.x = gr_viewx; + atransform.y = gr_viewy; + atransform.z = gr_viewz; - if (*type == postimg_flip) - atransform.flip = true; - else - atransform.flip = false; - - atransform.x = gr_viewx; // FIXED_TO_FLOAT(viewx) - atransform.y = gr_viewy; // FIXED_TO_FLOAT(viewy) - atransform.z = gr_viewz; // FIXED_TO_FLOAT(viewz) atransform.scalex = 1; atransform.scaley = (float)vid.width/vid.height; atransform.scalez = 1; + + atransform.anglex = (float)(aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + atransform.fovxangle = fpov; // Tails atransform.fovyangle = fpov; // Tails atransform.splitscreen = splitscreen; - //------------------------------------------------------------------------ + // Check for postprocessors + if (splitscreen && player == &players[secondarydisplayplayer]) + postprocessor = &postimgtype2; + else + postprocessor = &postimgtype; + + atransform.flip = false; + if (*postprocessor == postimg_flip) + atransform.flip = true; + + // Clear view, set viewport (glViewport), set perspective... HWR_ClearView(); - - if (drawsky) - HWR_DrawSkyBackground(); - - //Hurdler: it doesn't work in splitscreen mode - drawsky = splitscreen; - HWR_ClearSprites(); - drawcount = 0; -#ifdef NEWCLIP - if (rendermode == render_opengl) - { - angle_t a1 = gld_FrustumAngle(); - gld_clipper_Clear(); - gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); + ST_doPaletteStuff(); + + // Draw the sky background. + HWR_DrawSkyBackground(); + + a1 = gld_FrustumAngle(); + gld_clipper_Clear(); + gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); #ifdef HAVE_SPHEREFRUSTRUM - gld_FrustrumSetup(); -#endif - } -#else - HWR_ClearClipSegs(); + gld_FrustrumSetup(); #endif - //04/01/2000: Hurdler: added for T&L - // Actually it only works on Walls and Planes + // Set transform and shader HWD.pfnSetTransform(&atransform); - HWD.pfnSetShader(0); // jimita + HWD.pfnSetShader(0); + // Check for fog (shader) if (cv_grfog.value) HWR_FoggingOn(); // First of all, turn it on, set the default user settings too else HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, 0); // Turn it off + drawcount = 0; validcount++; + // Recursively "render" the BSP tree. HWR_RenderBSPNode((INT32)numnodes-1); -#ifndef NEWCLIP - // Make a viewangle int so we can render things based on mouselook - if (player == &players[consoleplayer]) - viewangle = localaiming; - else if (splitscreen && player == &players[secondarydisplayplayer]) - viewangle = localaiming2; - - // Handle stuff when you are looking farther up or down. - if ((aimingangle || cv_grfov.value+player->fovadd > 90*FRACUNIT)) - { - dup_viewangle += ANGLE_90; - HWR_ClearClipSegs(); - HWR_RenderBSPNode((INT32)numnodes-1); //left - - dup_viewangle += ANGLE_90; - if (((INT32)aimingangle > ANGLE_45 || (INT32)aimingangle<-ANGLE_45)) - { - HWR_ClearClipSegs(); - HWR_RenderBSPNode((INT32)numnodes-1); //back - } - - dup_viewangle += ANGLE_90; - HWR_ClearClipSegs(); - HWR_RenderBSPNode((INT32)numnodes-1); //right - - dup_viewangle += ANGLE_90; - } -#endif - // Check for new console commands. NetUpdate(); @@ -5407,16 +4585,21 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) HWR_SortVisSprites(); HWR_DrawSprites(); - if (numplanes || numpolyplanes || numwalls) //Hurdler: render 3D water and transparent walls after everything - HWR_CreateDrawNodes(); + if (numplanes || numpolyplanes || numwalls) // Render FOFs and translucent walls after everything + HWR_RenderDrawNodes(); + // Unset transform and shader HWD.pfnSetTransform(NULL); - HWD.pfnUnSetShader(); // jimita + HWD.pfnUnSetShader(); - // put it off for menus etc + // Disable fog if (cv_grfog.value) HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, 0); + // Run post processor effects + if (!skybox) + HWR_DoPostProcessor(player); + // Check for new console commands. NetUpdate(); @@ -5426,20 +4609,13 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) } // ========================================================================== -// +// Render the player view. // ========================================================================== void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) { - const float fpov = FIXED_TO_FLOAT(cv_grfov.value+player->fovadd); - postimg_t *type; - const boolean skybox = (skyboxmo[0] && cv_skybox.value); // True if there's a skybox object and skyboxes are on - if (splitscreen && player == &players[secondarydisplayplayer]) - type = &postimgtype2; - else - type = &postimgtype; - + // Clear the color buffer, stops HOMs. Also seems to fix the skybox issue on Intel GPUs. if (viewnumber == 0) // Only do it if it's the first screen being rendered { FRGBAFloat ClearColor; @@ -5447,167 +4623,18 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ClearColor.green = 0.0f; ClearColor.blue = 0.0f; ClearColor.alpha = 1.0f; - // Clear the Color Buffer, stops HOMs. Also seems to fix the skybox issue on Intel GPUs. HWD.pfnClearBuffer(true, false, &ClearColor); } - if (skybox && drawsky) // If there's a skybox and we should be drawing the sky, draw the skybox - HWR_RenderSkyboxView(viewnumber, player); // This is drawn before everything else so it is placed behind - + // Render the skybox if there is one. + if (skybox) { - // do we really need to save player (is it not the same)? - player_t *saved_player = stplyr; - stplyr = player; - ST_doPaletteStuff(); - stplyr = saved_player; + R_SkyboxFrame(player); + HWR_RenderFrame(viewnumber, player, true); } - // note: sets viewangle, viewx, viewy, viewz R_SetupFrame(player, false); // This can stay false because it is only used to set viewsky in r_main.c, which isn't used here - - // copy view cam position for local use - dup_viewx = viewx; - dup_viewy = viewy; - dup_viewz = viewz; - dup_viewangle = viewangle; - - // set window position - gr_centery = gr_basecentery; - gr_viewwindowy = gr_baseviewwindowy; - gr_windowcentery = gr_basewindowcentery; - if (splitscreen && viewnumber == 1) - { - gr_viewwindowy += (vid.height/2); - gr_windowcentery += (vid.height/2); - } - - // check for new console commands. - NetUpdate(); - - gr_viewx = FIXED_TO_FLOAT(dup_viewx); - gr_viewy = FIXED_TO_FLOAT(dup_viewy); - gr_viewz = FIXED_TO_FLOAT(dup_viewz); - gr_viewsin = FIXED_TO_FLOAT(viewsin); - gr_viewcos = FIXED_TO_FLOAT(viewcos); - - //04/01/2000: Hurdler: added for T&L - // It should replace all other gr_viewxxx when finished - atransform.anglex = (float)(aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - - if (*type == postimg_flip) - atransform.flip = true; - else - atransform.flip = false; - - atransform.x = gr_viewx; // FIXED_TO_FLOAT(viewx) - atransform.y = gr_viewy; // FIXED_TO_FLOAT(viewy) - atransform.z = gr_viewz; // FIXED_TO_FLOAT(viewz) - atransform.scalex = 1; - atransform.scaley = (float)vid.width/vid.height; - atransform.scalez = 1; - atransform.fovxangle = fpov; // Tails - atransform.fovyangle = fpov; // Tails - atransform.splitscreen = splitscreen; - - //------------------------------------------------------------------------ - HWR_ClearView(); // Clears the depth buffer and resets the view I believe - - if (!skybox && drawsky) // Don't draw the regular sky if there's a skybox - HWR_DrawSkyBackground(); - - //Hurdler: it doesn't work in splitscreen mode - drawsky = splitscreen; - - HWR_ClearSprites(); - - drawcount = 0; -#ifdef NEWCLIP - if (rendermode == render_opengl) - { - angle_t a1 = gld_FrustumAngle(); - gld_clipper_Clear(); - gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); -#ifdef HAVE_SPHEREFRUSTRUM - gld_FrustrumSetup(); -#endif - } -#else - HWR_ClearClipSegs(); -#endif - - //04/01/2000: Hurdler: added for T&L - // Actually it only works on Walls and Planes - HWD.pfnSetTransform(&atransform); - - // jimita - HWD.pfnSetShader(0); - - gl_leveltime = leveltime; - - if (cv_grfog.value) - HWR_FoggingOn(); // First of all, turn it on, set the default user settings too - else - HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, 0); // Turn it off - - validcount++; - - HWR_RenderBSPNode((INT32)numnodes-1); - -#ifndef NEWCLIP - // Make a viewangle int so we can render things based on mouselook - if (player == &players[consoleplayer]) - viewangle = localaiming; - else if (splitscreen && player == &players[secondarydisplayplayer]) - viewangle = localaiming2; - - // Handle stuff when you are looking farther up or down. - if ((aimingangle || cv_grfov.value+player->fovadd > 90*FRACUNIT)) - { - dup_viewangle += ANGLE_90; - HWR_ClearClipSegs(); - HWR_RenderBSPNode((INT32)numnodes-1); //left - - dup_viewangle += ANGLE_90; - if (((INT32)aimingangle > ANGLE_45 || (INT32)aimingangle<-ANGLE_45)) - { - HWR_ClearClipSegs(); - HWR_RenderBSPNode((INT32)numnodes-1); //back - } - - dup_viewangle += ANGLE_90; - HWR_ClearClipSegs(); - HWR_RenderBSPNode((INT32)numnodes-1); //right - - dup_viewangle += ANGLE_90; - } -#endif - - // Check for new console commands. - NetUpdate(); - - // Draw MD2 and sprites - HWR_SortVisSprites(); - HWR_DrawSprites(); - - if (numplanes || numpolyplanes || numwalls) //Hurdler: render 3D water and transparent walls after everything - HWR_CreateDrawNodes(); - - HWD.pfnSetTransform(NULL); - HWD.pfnUnSetShader(); // jimita - - // put it off for menus etc - if (cv_grfog.value) - HWD.pfnSetSpecialState(HWD_SET_FOG_MODE, 0); - - HWR_DoPostProcessor(player); - - // Check for new console commands. - NetUpdate(); - - // added by Hurdler for correct splitscreen - // moved here by hurdler so it works with the new near clipping plane - HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE); + HWR_RenderFrame(viewnumber, player, skybox); } // ========================================================================== @@ -5624,23 +4651,12 @@ static void HWR_FoggingOn(void) // 3D ENGINE COMMANDS // ========================================================================== - static void CV_grFov_OnChange(void) { if ((netgame || multiplayer) && !cv_debug && cv_grfov.value != 90*FRACUNIT) CV_Set(&cv_grfov, cv_grfov.defaultvalue); } -static void Command_GrStats_f(void) -{ - Z_CheckHeap(9875); // debug - - CONS_Printf(M_GetText("Patch info headers: %7s kb\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); - CONS_Printf(M_GetText("3D Texture cache : %7s kb\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); - CONS_Printf(M_GetText("Plane polygon : %7s kb\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); -} - - // ************************************************************************** // 3D ENGINE SETUP // ************************************************************************** @@ -5659,24 +4675,6 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grsolvetjoin); } -static inline void HWR_AddEngineCommands(void) -{ - // engine state variables - //CV_RegisterVar(&cv_grzbuffer); -#ifndef NEWCLIP - CV_RegisterVar(&cv_grclipwalls); -#endif - - // engine development mode variables - // - usage may vary from version to version.. - CV_RegisterVar(&cv_gralpha); - CV_RegisterVar(&cv_grbeta); - - // engine commands - COM_AddCommand("gr_stats", Command_GrStats_f); -} - - // -------------------------------------------------------------------------- // Setup the hardware renderer // -------------------------------------------------------------------------- @@ -5687,11 +4685,8 @@ void HWR_Startup(void) // do this once if (!startupdone) { - CONS_Printf("HWR_Startup()\n"); - // add console cmds & vars - HWR_AddEngineCommands(); + CONS_Printf("HWR_Startup()...\n"); HWR_InitTextureCache(); - HWR_InitMD2(); } @@ -5722,7 +4717,7 @@ void HWR_Shutdown(void) HWD.pfnFlushScreenTextures(); } -static void HWR_AddTransparentWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) +static void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) { static size_t allocedwalls = 0; @@ -5747,45 +4742,23 @@ static void HWR_AddTransparentWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, I numwalls++; } -static void HWR_RenderWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) +static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, INT32 lightlevel, extracolormap_t *wallcolormap) { - FOutVector trVerts[4]; - UINT8 i; - FOutVector *wv; - UINT8 alpha; - - (void)fogwall; ///@TODO remove shitty unused variable - - // transform - wv = trVerts; - // it sounds really stupid to do this conversion with the new T&L code - // we should directly put the right information in the right structure - // wallVerts3D seems ok, doesn't need FOutVector - // also remove the light copy - for (i = 0; i < 4; i++, wv++, wallVerts++) - { - wv->x = wallVerts->x; - wv->y = wallVerts->y; - wv->z = wallVerts->z; - wv->sow = wallVerts->s; - wv->tow = wallVerts->t; - } - - alpha = pSurf->PolyColor.s.alpha; // retain the alpha + UINT8 alpha = pSurf->PolyColor.s.alpha; // retain the alpha // Lighting is done here instead so that fog isn't drawn incorrectly on transparent walls after sorting if (wallcolormap) HWR_Lighting(pSurf, lightlevel, wallcolormap->rgba, wallcolormap->fadergba); else - HWR_NoColormapLighting(pSurf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(pSurf, lightlevel, GL_NORMALFOG, GL_FADEFOG); pSurf->PolyColor.s.alpha = alpha; // put the alpha back after lighting HWD.pfnSetShader(2); // jimita: wall shader if (blend & PF_Environment) - HWD.pfnDrawPolygon(pSurf, trVerts, 4, blend|PF_Modulated|PF_Occlude); // PF_Occlude must be used for solid objects + HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blend|PF_Modulated|PF_Occlude); // PF_Occlude must be used for solid objects else - HWD.pfnDrawPolygon(pSurf, trVerts, 4, blend|PF_Modulated); // No PF_Occlude means overlapping (incorrect) transparency + HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blend|PF_Modulated); // No PF_Occlude means overlapping (incorrect) transparency #ifdef WALLSPLATS if (gr_curline->linedef->splats && cv_splats.value) @@ -5793,11 +4766,6 @@ static void HWR_RenderWall(wallVert3D *wallVerts, FSurfaceInfo *pSurf, FBITFIE #endif } -INT32 HWR_GetTextureUsed(void) -{ - return HWD.pfnGetTextureUsed(); -} - void HWR_DoPostProcessor(player_t *player) { postimg_t *type; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index cb37f3cf..efa04825 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -34,13 +34,11 @@ void HWR_Shutdown(void); void HWR_drawAMline(const fline_t *fl, INT32 color); void HWR_FadeScreenMenuBack(UINT32 color, INT32 height); void HWR_DrawConsoleBack(UINT32 color, INT32 height); -void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player); void HWR_RenderPlayerView(INT32 viewnumber, player_t *player); void HWR_DrawViewBorder(INT32 clearlines); void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum); UINT8 *HWR_GetScreenshot(void); boolean HWR_Screenshot(const char *lbmname); -void HWR_InitTextureMapping(void); void HWR_SetViewSize(void); void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option); void HWR_DrawFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t scale, INT32 option, const UINT8 *colormap); @@ -53,9 +51,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 void HWR_AddCommands(void); void HWR_CorrectSWTricks(void); -void transform(float *cx, float *cy, float *cz); FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf); -INT32 HWR_GetTextureUsed(void); void HWR_DoPostProcessor(player_t *player); void HWR_StartScreenWipe(void); void HWR_EndScreenWipe(void); diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 965d6e9d..79612fad 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -520,7 +520,7 @@ void HWR_InitMD2(void) } } // no sprite/player skin name found?!? - CONS_Printf("Unknown sprite/player skin %s detected in md2.dat\n", name); + //CONS_Printf("Unknown sprite/player skin %s detected in md2.dat\n", name); md2found: // move on to next line... continue; @@ -864,10 +864,6 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, con // Returns : // -----------------+ -// hw_main.c -#define NORMALFOG 0x00000000 -#define FADEFOG 0x19000000 - void HWR_DrawMD2(gr_vissprite_t *spr) { md2_t *md2; @@ -916,7 +912,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) if (colormap) HWR_Lighting(&Surf, lightlevel, colormap->rgba, colormap->fadergba); else - HWR_NoColormapLighting(&Surf, lightlevel, NORMALFOG, FADEFOG); + HWR_NoColormapLighting(&Surf, lightlevel, GL_NORMALFOG, GL_FADEFOG); } // Look at HWR_ProjectSprite for more diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index d094ba7c..2a2e2cc9 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1179,7 +1179,7 @@ EXPORT void HWRAPI(Draw2DLine) (F2DCoord * v1, F2DCoord * v2, RGBA_t Color) { - //GL_DBG_Printf("DrawLine() (%f %f %f) %d\n", v1->x, -v1->y, -v1->z, v1->argb); + //GL_DBG_Printf("DrawLine(): %f %f, %f %f\n", v1->x, v1->y, v2->x, v2->y); GLfloat p[12]; GLfloat dx, dy; GLfloat angle; @@ -1692,7 +1692,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI load_shaders(pSurf, &mix, &fade); pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x); - pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].sow); + pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s); pglDrawArrays(GL_TRIANGLE_FAN, 0, iNumPts); if (PolyFlags & PF_RemoveYWrap) @@ -2279,11 +2279,6 @@ EXPORT INT32 HWRAPI(GetTextureUsed) (void) return res; } -EXPORT INT32 HWRAPI(GetRenderVersion) (void) -{ - return VERSION; -} - EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]) { INT32 x, y; diff --git a/src/nds/r_nds3d.c b/src/nds/r_nds3d.c index dbdcec15..6734e8c1 100644 --- a/src/nds/r_nds3d.c +++ b/src/nds/r_nds3d.c @@ -160,7 +160,7 @@ void NDS3D_DrawPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts z = pOutVerts[index].z; } - glTexCoord2f(pOutVerts[index].sow, pOutVerts[index].tow); + glTexCoord2f(pOutVerts[index].s, pOutVerts[index].tow); glVertex3f(x,y,z); } glEnd(); diff --git a/src/r_main.c b/src/r_main.c index 10a1216e..f12ab30d 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -609,11 +609,6 @@ void R_ExecuteSetViewSize(void) R_InitTextureMapping(); -#ifdef HWRENDER - if (rendermode != render_soft) - HWR_InitTextureMapping(); -#endif - // thing clipping for (i = 0; i < viewwidth; i++) screenheightarray[i] = (INT16)viewheight; diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 0774bc73..bd2b5ab7 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -91,7 +91,6 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(DrawModel); GETFUNC(CreateModelVBOs); GETFUNC(SetTransform); - GETFUNC(GetRenderVersion); GETFUNC(PostImgRedraw); GETFUNC(FlushScreenTextures); GETFUNC(StartScreenWipe); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b967e7a6..21a04682 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1459,9 +1459,11 @@ void I_StartupGraphics(void) framebuffer = SDL_TRUE; } if (M_CheckParm("-software")) - { rendermode = render_soft; - } +#ifdef HWRENDER + else if (M_CheckParm("-opengl")) + rendermode = render_opengl; +#endif usesdl2soft = M_CheckParm("-softblit"); borderlesswindow = M_CheckParm("-borderless"); @@ -1469,9 +1471,8 @@ void I_StartupGraphics(void) //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY>>1,SDL_DEFAULT_REPEAT_INTERVAL<<2); VID_Command_ModeList_f(); #ifdef HWRENDER - if (M_CheckParm("-opengl") || rendermode == render_opengl) + if (rendermode == render_opengl) { - rendermode = render_opengl; HWD.pfnInit = hwSym("Init",NULL); HWD.pfnFinishUpdate = NULL; HWD.pfnDraw2DLine = hwSym("Draw2DLine",NULL); @@ -1488,7 +1489,6 @@ void I_StartupGraphics(void) HWD.pfnDrawModel = hwSym("DrawModel",NULL); HWD.pfnCreateModelVBOs = hwSym("CreateModelVBOs",NULL); HWD.pfnSetTransform = hwSym("SetTransform",NULL); - HWD.pfnGetRenderVersion = hwSym("GetRenderVersion",NULL); HWD.pfnPostImgRedraw = hwSym("PostImgRedraw",NULL); HWD.pfnFlushScreenTextures=hwSym("FlushScreenTextures",NULL); HWD.pfnStartScreenWipe = hwSym("StartScreenWipe",NULL); @@ -1508,9 +1508,6 @@ void I_StartupGraphics(void) HWD.pfnLoadCustomShader = hwSym("LoadCustomShader",NULL); HWD.pfnInitCustomShaders = hwSym("InitCustomShaders",NULL); - // check gl renderer lib - if (HWD.pfnGetRenderVersion() != VERSION) - I_Error("%s", M_GetText("The version of the renderer doesn't match the version of the executable\nBe sure you have installed SRB2 properly.\n")); if (!HWD.pfnInit()) // load the OpenGL library rendermode = render_soft; } diff --git a/src/z_zone.c b/src/z_zone.c index a3e13422..dae7dff0 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -637,7 +637,6 @@ void Command_Memfree_f(void) CONS_Printf(M_GetText("Mipmap patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); CONS_Printf(M_GetText("HW Texture cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); - CONS_Printf(M_GetText("HW Texture used : %7d KB\n"), HWR_GetTextureUsed()>>10); } #endif