diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 8ef5636aa..926f68fc6 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -68,6 +68,7 @@ ** */ + #include #include "../v_video.h" #include "hw_main.h" @@ -76,13 +77,7 @@ #include "../r_state.h" #include "../tables.h" #include "r_opengl/r_opengl.h" -#include "../r_main.h" // for cv_fov -#ifdef HAVE_SPHEREFRUSTRUM -static GLdouble viewMatrix[16]; -static GLdouble projMatrix[16]; -float frustum[6][4]; -#endif typedef struct clipnode_s { @@ -323,17 +318,12 @@ void gld_clipper_Clear(void) angle_t gld_FrustumAngle(angle_t tiltangle) { + double clipfov; double floatangle; angle_t a1; float tilt = (float)fabs(((double)(int)tiltangle) / ANG1); - // NEWCLIP TODO: SRB2CBTODO: make a global render_fov for this function - - float render_fov = FIXED_TO_FLOAT(cv_fov.value); - float render_fovratio = (float)BASEVIDWIDTH / (float)BASEVIDHEIGHT; // SRB2CBTODO: NEWCLIPTODO: Is this right? - float render_multiplier = 64.0f / render_fovratio / RMUL; - if (tilt > 90.0f) tilt = 90.0f; @@ -343,22 +333,28 @@ angle_t gld_FrustumAngle(angle_t tiltangle) // ok, this is a gross hack that barely works... // but at least it doesn't overestimate too much... - floatangle = 2.0f + (45.0f + (tilt / 1.9f)) * (float)render_fov * 48.0f / render_multiplier / 90.0f; - a1 = ANG1 * (int)floatangle; - if (a1 >= ANGLE_180) + clipfov = atan(1 / projMatrix[0]) * 360 / M_PIl; + floatangle = 2.0f + (45.0f + (tilt / 1.9f)) * clipfov / 90.0f; + if (floatangle >= 180.0) return 0xffffffff; + a1 = ANG1 * (int)floatangle; return a1; } + // 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)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 // -// gld_FrustrumSetup +// gld_FrustumSetup // +static GLdouble viewMatrix[16]; +static GLdouble projMatrix[16]; +float frustum[6][4]; + #define CALCMATRIX(a, b, c, d, e, f, g, h)\ (float)(viewMatrix[a] * projMatrix[b] + \ viewMatrix[c] * projMatrix[d] + \ @@ -375,7 +371,7 @@ frustum[i][1] /= t; \ frustum[i][2] /= t; \ frustum[i][3] /= t -void gld_FrustrumSetup(void) +void gld_FrustumSetup(void) { float t; float clip[16]; diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index 27a2ed1ef..dfaa87f81 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -19,6 +19,6 @@ void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); void gld_clipper_Clear(void); angle_t gld_FrustumAngle(angle_t tiltangle); #ifdef HAVE_SPHEREFRUSTRUM -void gld_FrustrumSetup(void); +void gld_FrustumSetup(void); boolean gld_SphereInFrustum(float x, float y, float z, float radius); #endif diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 66e520726..6b7d4f8c7 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -271,8 +271,6 @@ FTransform atransform; static float gr_viewx, gr_viewy, gr_viewz; float gr_viewsin, gr_viewcos; -static fixed_t dup_viewx, dup_viewy, dup_viewz; - static angle_t gr_aimingangle; static float gr_viewludsin, gr_viewludcos; @@ -854,7 +852,7 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc for (i = 0; i < subsector->numlines; i++, line++) { - if (line->linedef->special == HORIZONSPECIAL && R_PointOnSegSide(dup_viewx, dup_viewy, line) == 0) + if (line->linedef->special == HORIZONSPECIAL && R_PointOnSegSide(viewx, viewy, line) == 0) { P_ClosestPointOnLine(viewx, viewy, line->linedef, &v); dist = FIXED_TO_FLOAT(R_PointToDist(v.x, v.y)); @@ -5472,11 +5470,6 @@ void HWR_SetTransform(float fpov, player_t *player) postimg_t *postprocessor = &postimgtype[0]; INT32 i; - // copy view cam position for local use - dup_viewx = viewx; - dup_viewy = viewy; - dup_viewz = viewz; - gr_viewx = FIXED_TO_FLOAT(viewx); gr_viewy = FIXED_TO_FLOAT(viewy); gr_viewz = FIXED_TO_FLOAT(viewz); @@ -5545,7 +5538,7 @@ void HWR_ClearClipper(void) gld_clipper_Clear(); gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); #ifdef HAVE_SPHEREFRUSTRUM - gld_FrustrumSetup(); + gld_FrustumSetup(); #endif } @@ -5663,7 +5656,9 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe portalclipline = NULL; else HWR_PortalClipping(rootportal); + validcount++; + HWR_RenderBSPNode((INT32)numnodes-1);// no actual rendering happens // for each found portal: @@ -5681,11 +5676,12 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe // draw normal things in current frame in current incremented stencil buffer area HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); if (!cv_portalonly.value || rootportal) - { + { + HWR_SetTransform(fpov, player); + HWR_ClearClipper(); HWR_ClearSprites(); - // the frame should be correct, set by either the for loop or the above layer in recursion - HWR_SetTransform(fpov, player); + if (!rootportal) portalclipline = NULL; else @@ -5693,7 +5689,10 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search HWR_PortalClipping(rootportal); } - //drawcount = 0; + + // Set transform. + HWD.pfnSetTransform(&atransform); + validcount++; if (cv_grbatching.value) @@ -5769,8 +5768,6 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) { const float fpov = FIXED_TO_FLOAT(cv_fov.value+player->fovadd); - postimg_t *postprocessor = &postimgtype[0]; - INT32 i; // set window position gr_centerx = gr_basecenterx; @@ -5809,67 +5806,8 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) // check for new console commands. NetUpdate(); - gr_viewx = FIXED_TO_FLOAT(viewx); - gr_viewy = FIXED_TO_FLOAT(viewy); - gr_viewz = FIXED_TO_FLOAT(viewz); - gr_viewsin = FIXED_TO_FLOAT(viewsin); - gr_viewcos = FIXED_TO_FLOAT(viewcos); - - memset(&atransform, 0x00, sizeof(FTransform)); - - // Set T&L transform - atransform.x = gr_viewx; - atransform.y = gr_viewy; - atransform.z = gr_viewz; - - atransform.scalex = 1; - atransform.scaley = (float)vid.width/vid.height; - atransform.scalez = 1; - - // 14042019 - gr_aimingangle = aimingangle; - atransform.shearing = false; - atransform.viewaiming = aimingangle; - - if (cv_grshearing.value) - { - gr_aimingangle = 0; - atransform.shearing = true; - } - - gr_viewludsin = FIXED_TO_FLOAT(FINECOSINE(gr_aimingangle>>ANGLETOFINESHIFT)); - gr_viewludcos = FIXED_TO_FLOAT(-FINESINE(gr_aimingangle>>ANGLETOFINESHIFT)); - - atransform.anglex = (float)(gr_aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - - atransform.fovxangle = fpov; // Tails - atransform.fovyangle = fpov; // Tails - if (player->viewrollangle != 0) - { - fixed_t rol = AngleFixed(player->viewrollangle); - atransform.rollangle = FIXED_TO_FLOAT(rol); - atransform.roll = true; - } - atransform.splitscreen = splitscreen; - - for (i = 0; i <= splitscreen; i++) - { - if (player == &players[displayplayers[i]]) - postprocessor = &postimgtype[i]; - } - - atransform.flip = false; - if (*postprocessor == postimg_flip) - atransform.flip = true; - - atransform.mirror = false; - if (*postprocessor == postimg_mirror) - atransform.mirror = true; - // Clear view, set viewport (glViewport), set perspective... HWR_ClearView(); - HWR_ClearSprites(); ST_doPaletteStuff(); @@ -5890,16 +5828,8 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) current_bsp_culling_distance = bsp_culling_distances[cv_grrenderdistance.value - 1]; } - HWR_ClearClipper(); - - // Reset the shader state. - //HWR_SetShaderState(); - - validcount++; - portalclipline = NULL; HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); - HWR_SetTransform(fpov, player);// not sure if needed // Unset transform and shader HWD.pfnSetTransform(NULL); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index bb5c1fe3d..e287d681d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -28,6 +28,7 @@ #include "r_vbo.h" #include "../hw_shaders.h" #include "../hw_main.h" +#include "../hw_clip.h" // Eeeeh not sure is this right way, but it works < sry :c < sry again it had to go :c @@ -110,7 +111,7 @@ const GLubyte *gl_extensions = NULL; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) static GLfloat modelMatrix[16]; -static GLfloat projMatrix[16]; +GLfloat projMatrix[16]; static GLint viewport[4]; @@ -884,9 +885,11 @@ static void GLPerspective(GLfloat fovy, GLfloat aspect) m[1][1] = cotangent; m[2][2] = -(zFar + zNear) / deltaZ; m[3][2] = -2.0f * zNear * zFar / deltaZ; + pglMultMatrixf(&m[0][0]); } + // -----------------+ // SetModelView : // -----------------+ @@ -2725,7 +2728,9 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) static boolean special_splitscreen; GLdouble used_fov; boolean shearing = false; + pglLoadIdentity(); + if (stransform) { used_fov = stransform->fovxangle; @@ -2746,7 +2751,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) if (stransform->roll) pglRotatef(stransform->rollangle, 0.0f, 0.0f, 1.0f); - pglRotatef(stransform->anglex, 1.0f, 0.0f, 0.0f); + pglRotatef(stransform->anglex , 1.0f, 0.0f, 0.0f); pglRotatef(stransform->angley+270.0f, 0.0f, 1.0f, 0.0f); pglTranslatef(-stransform->x, -stransform->z, -stransform->y); @@ -2780,6 +2785,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) } else GLPerspective((GLfloat)used_fov, ASPECT_RATIO); + pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index ba3cccbce..34b2d3cf7 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -123,6 +123,8 @@ extern GLint maximumAnisotropy; extern INT32 oglflags; extern GLint textureformatGL; +extern GLfloat projMatrix[16]; + typedef enum { GLF_NOZBUFREAD = 0x01, diff --git a/src/m_menu.c b/src/m_menu.c index 5cf720be7..7fc8c98bf 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4338,7 +4338,8 @@ void M_Init(void) OP_ExpOptionsMenu[op_exp_fofcut].status = IT_DISABLED; } - if (rendermode == render_opengl){ + if (rendermode == render_opengl) + { OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_sprclip].status = IT_DISABLED; } diff --git a/src/r_main.c b/src/r_main.c index 8a975498d..a74be33d8 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -213,7 +213,7 @@ consvar_t cv_homremoval = {"homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL consvar_t cv_maxportals = {"maxportals", "2", CV_SAVE, maxportals_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t pointoangle_cons_t[] = {{0, "Ex"}, {1, "64"}, {0, NULL}}; -consvar_t cv_pointoangleexor64 = {"r_pointtoangle", "Ex", CV_SAVE, pointoangle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pointoangleexor64 = {"r_pointtoangle", "64", CV_SAVE, pointoangle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; void SplitScreen_OnChange(void) {