diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 53c39f605d..b661b62662 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -155,8 +155,6 @@ public: FTextureID glPart; FTextureID mirrorTexture; - float mSky1Pos, mSky2Pos; - FRotator mAngles; FVector2 mViewVector; diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 47a619b77f..1ddb6523c7 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -70,7 +70,6 @@ int GLPortal::renderdepth; int GLPortal::PlaneMirrorMode; GLuint GLPortal::QueryObject; -int GLPortal::instack[2]; bool GLPortal::inskybox; UniqueList UniqueSkies; @@ -442,7 +441,7 @@ void GLPortal::StartFrame() if (renderdepth==0) { inskybox=false; - instack[sector_t::floor]=instack[sector_t::ceiling]=0; + screen->instack[sector_t::floor] = screen->instack[sector_t::ceiling] = 0; } renderdepth++; } @@ -743,7 +742,7 @@ void GLSectorStackPortal::DrawContents() GLRenderer->mViewActor = NULL; // avoid recursions! - if (origin->plane != -1) instack[origin->plane]++; + if (origin->plane != -1) screen->instack[origin->plane]++; drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); SaveMapSection(); @@ -762,7 +761,7 @@ void GLSectorStackPortal::DrawContents() drawer->DrawScene(DM_PORTAL); RestoreMapSection(); - if (origin->plane != -1) instack[origin->plane]--; + if (origin->plane != -1) screen->instack[origin->plane]--; } //----------------------------------------------------------------------------- @@ -789,7 +788,7 @@ void GLPlaneMirrorPortal::DrawContents() return; } // A plane mirror needs to flip the portal exclusion logic because inside the mirror, up is down and down is up. - std::swap(instack[sector_t::floor], instack[sector_t::ceiling]); + std::swap(screen->instack[sector_t::floor], screen->instack[sector_t::ceiling]); int old_pm = PlaneMirrorMode; @@ -810,7 +809,7 @@ void GLPlaneMirrorPortal::DrawContents() gl_RenderState.SetClipHeight(0.f, 0.f); PlaneMirrorFlag--; PlaneMirrorMode = old_pm; - std::swap(instack[sector_t::floor], instack[sector_t::ceiling]); + std::swap(screen->instack[sector_t::floor], screen->instack[sector_t::ceiling]); } void GLPlaneMirrorPortal::PushState() diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index 7401316ad5..fbb817a20d 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -64,7 +64,6 @@ public: static GLSceneDrawer *drawer; static int PlaneMirrorMode; static int inupperstack; - static int instack[2]; static bool inskybox; private: diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 11d53cd5dc..8df73e032d 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -672,12 +672,6 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, f GLRenderer->mAngles.Pitch = (float)RAD2DEG(asin(angy / alen)); GLRenderer->mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees; - // Scroll the sky - GLRenderer->mSky1Pos = (double)fmod((double)screen->FrameTime * (double)level.skyspeed1, 1024.f) * 90./256.; - GLRenderer->mSky2Pos = (double)fmod((double)screen->FrameTime * (double)level.skyspeed2, 1024.f) * 90./256.; - - - if (camera->player && camera->player-players==consoleplayer && ((camera->player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)) && camera==camera->player->mo) { diff --git a/src/gl/scene/gl_sky.cpp b/src/gl/scene/gl_sky.cpp index be9e5a13d4..24bd48e936 100644 --- a/src/gl/scene/gl_sky.cpp +++ b/src/gl/scene/gl_sky.cpp @@ -33,9 +33,6 @@ #include "hwrenderer/utility/hw_lighting.h" #include "hwrenderer/textures/hw_material.h" -#include "gl/renderer/gl_renderer.h" -#include "gl/scene/gl_portal.h" - CVAR(Bool,gl_noskyboxes, false, 0) //========================================================================== @@ -76,7 +73,7 @@ void GLSkyInfo::init(int sky1, PalEntry FadeColor) if (level.flags&LEVEL_DOUBLESKY) { texture[1] = FMaterial::ValidateTexture(sky1texture, false, true); - x_offset[1] = GLRenderer->mSky1Pos; + x_offset[1] = hw_sky1pos; doublesky = true; } @@ -86,13 +83,13 @@ void GLSkyInfo::init(int sky1, PalEntry FadeColor) texture[0] = FMaterial::ValidateTexture(sky2texture, false, true); skytexno1 = sky2texture; sky2 = true; - x_offset[0] = GLRenderer->mSky2Pos; + x_offset[0] = hw_sky2pos; } else if (!doublesky) { texture[0] = FMaterial::ValidateTexture(sky1texture, false, true); skytexno1 = sky1texture; - x_offset[0] = GLRenderer->mSky1Pos; + x_offset[0] = hw_sky1pos; } } if (level.skyfog > 0) @@ -124,7 +121,8 @@ void GLWall::SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowref GLSkyInfo skyinfo; skyinfo.init(sector->sky, Colormap.FadeColor); ptype = PORTALTYPE_SKY; - sky = UniqueSkies.Get(&skyinfo); + sky = &skyinfo; + PutPortal(di, ptype); } else if (sportal != nullptr) { @@ -139,7 +137,7 @@ void GLWall::SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowref { if (sector->PortalBlocksView(plane)) return; - if (GLPortal::instack[1 - plane]) return; + if (screen->instack[1 - plane]) return; ptype = PORTALTYPE_SECTORSTACK; portal = glport; } @@ -192,7 +190,7 @@ void GLWall::SkyLine(HWDrawInfo *di, sector_t *fs, line_t *line) { skyinfo.init(fs->sky, Colormap.FadeColor); ptype = PORTALTYPE_SKY; - sky = UniqueSkies.Get(&skyinfo); + sky = &skyinfo; } ztop[0] = zceil[0]; ztop[1] = zceil[1]; diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 93cf8ceef4..3d1b0dc958 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -463,6 +463,7 @@ void FDrawInfo::AddPortal(GLWall *wall, int ptype) break; case PORTALTYPE_SKY: + wall->sky = UniqueSkies.Get(wall->sky); portal = GLPortal::FindPortal(wall->sky); if (!portal) portal = new GLSkyPortal(wall->sky); portal->AddLine(wall); diff --git a/src/r_sky.cpp b/src/r_sky.cpp index 31a9ec491d..9bc3d0fc1d 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -51,6 +51,7 @@ bool skystretch; fixed_t sky1cyl, sky2cyl; double sky1pos, sky2pos; +float hw_sky1pos, hw_sky2pos; CUSTOM_CVAR(Int, testskyoffset, 0, 0) { @@ -170,5 +171,10 @@ void R_UpdateSky (uint64_t mstime) double ms = (double)mstime * FRACUNIT; sky1pos = ms * level.skyspeed1; sky2pos = ms * level.skyspeed2; + + // The hardware renderer uses a different value range and clamps it to a single rotation + hw_sky1pos = (float)(fmod((double(mstime) * level.skyspeed1), 1024.) * (90. / 256.)); + hw_sky2pos = (float)(fmod((double(mstime) * level.skyspeed2), 1024.) * (90. / 256.)); + } diff --git a/src/r_sky.h b/src/r_sky.h index e186ad3ae5..a6e4cae9f4 100644 --- a/src/r_sky.h +++ b/src/r_sky.h @@ -34,6 +34,7 @@ extern FTextureID skyflatnum; extern fixed_t sky1cyl, sky2cyl; extern FTextureID sky1texture, sky2texture; extern double sky1pos, sky2pos; +extern float hw_sky1pos, hw_sky2pos; extern double skytexturemid; extern float skyiscale; extern double skyscale; diff --git a/src/v_video.h b/src/v_video.h index b976e54157..92f1dc37d7 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -327,6 +327,7 @@ protected: public: int hwcaps = 0; + int instack[2] = { 0,0 }; // this is globally maintained state for portal recursion avoidance. public: DFrameBuffer (int width, int height, bool bgra);