From 32e245f2b90ed4f286a44e4a10a6d22f165cf936 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 6 Dec 2018 20:52:03 +0100 Subject: [PATCH] - moved the software rendering specific parts of the sky setup to r_skyplane.cpp. --- src/polyrenderer/scene/poly_sky.cpp | 5 ++ src/r_sky.cpp | 67 ++----------------- src/r_sky.h | 4 -- src/r_utility.cpp | 2 + src/swrenderer/plane/r_skyplane.cpp | 57 ++++++++++++++++ src/swrenderer/r_swscene.cpp | 2 + wadsrc/static/zscript/statusbar/harm_sbar.txt | 8 +-- 7 files changed, 77 insertions(+), 68 deletions(-) diff --git a/src/polyrenderer/scene/poly_sky.cpp b/src/polyrenderer/scene/poly_sky.cpp index 1cca9dca4..cf5fc755d 100644 --- a/src/polyrenderer/scene/poly_sky.cpp +++ b/src/polyrenderer/scene/poly_sky.cpp @@ -32,6 +32,11 @@ EXTERN_CVAR(Float, skyoffset) +extern double skytexturemid; +extern float skyiscale; +extern double skyscale; +extern fixed_t sky1cyl, sky2cyl; + PolySkyDome::PolySkyDome() { diff --git a/src/r_sky.cpp b/src/r_sky.cpp index 6297a822d..5b161dde1 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -44,19 +44,9 @@ // FTextureID skyflatnum; FTextureID sky1texture, sky2texture; -double skytexturemid; -double skyscale; -float skyiscale; -bool skystretch; - -fixed_t sky1cyl, sky2cyl; double sky1pos, sky2pos; float hw_sky1pos, hw_sky2pos; - -CUSTOM_CVAR(Int, testskyoffset, 0, 0) -{ - R_InitSkyMap(); -} +bool skystretch; // [RH] Stretch sky texture if not taller than 128 pixels? // Also now controls capped skies. 0 = normal, 1 = stretched, 2 = capped @@ -67,10 +57,6 @@ CUSTOM_CVAR (Int, r_skymode, 2, CVAR_ARCHIVE) CVAR(Float, skyoffset, 0, 0) // for testing - - -int freelookviewheight; - //========================================================================== // // R_InitSkyMap @@ -79,7 +65,7 @@ int freelookviewheight; // //========================================================================== -void R_InitSkyMap () +void R_InitSkyMap() { int skyheight; FTexture *skytex1, *skytex2; @@ -102,7 +88,7 @@ void R_InitSkyMap () if ((level.flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight()) { - Printf (TEXTCOLOR_BOLD "Both sky textures must be the same height." TEXTCOLOR_NORMAL "\n"); + Printf(TEXTCOLOR_BOLD "Both sky textures must be the same height." TEXTCOLOR_NORMAL "\n"); sky2texture = sky1texture; } @@ -120,56 +106,17 @@ void R_InitSkyMap () // h > 200: Unstretched, but the baseline is shifted down so that the top // of the texture is at the top of the screen when looking fully up. skyheight = skytex1->GetDisplayHeight(); - + if (skyheight >= 128 && skyheight < 200) { skystretch = (r_skymode == 1 - && skyheight >= 128 - && level.IsFreelookAllowed() - && !(level.flags & LEVEL_FORCETILEDSKY)) ? 1 : 0; + && skyheight >= 128 + && level.IsFreelookAllowed() + && !(level.flags & LEVEL_FORCETILEDSKY)) ? 1 : 0; } else skystretch = false; - - // Anything below is only for the software renderer (todo - move it there!) - // Note: I don't think it is good that this stuff gets cached globally. - // For something that only needs to be once per frame it is rather pointless and makes it hard to swap out the underlying textures based on user settings. - FSoftwareTexture *sskytex1 = skytex1->GetSoftwareTexture(); - FSoftwareTexture *sskytex2 = skytex2->GetSoftwareTexture(); - skytexturemid = 0; - if (skyheight >= 128 && skyheight < 200) - { - skytexturemid = -28; - } - else if (skyheight > 200) - { - skytexturemid = (200 - skyheight) * sskytex1->GetScale().Y +((r_skymode == 2 && !(level.flags & LEVEL_FORCETILEDSKY)) ? skytex1->GetSkyOffset() + testskyoffset : 0); - } - - if (viewwidth != 0 && viewheight != 0) - { - skyiscale = float(r_Yaspect / freelookviewheight); - skyscale = freelookviewheight / r_Yaspect; - - skyiscale *= float(r_viewpoint.FieldOfView.Degrees / 90.); - skyscale *= float(90. / r_viewpoint.FieldOfView.Degrees); - } - - if (skystretch) - { - skyscale *= (double)SKYSTRETCH_HEIGHT / skyheight; - skyiscale *= skyheight / (float)SKYSTRETCH_HEIGHT; - skytexturemid *= skyheight / (double)SKYSTRETCH_HEIGHT; - } - - // The standard Doom sky texture is 256 pixels wide, repeated 4 times over 360 degrees, - // giving a total sky width of 1024 pixels. So if the sky texture is no wider than 1024, - // we map it to a cylinder with circumfrence 1024. For larger ones, we use the width of - // the texture as the cylinder's circumfrence. - sky1cyl = MAX(sskytex1->GetWidth(), fixed_t(sskytex1->GetScale().X * 1024)); - sky2cyl = MAX(sskytex2->GetWidth(), fixed_t(sskytex2->GetScale().Y * 1024)); } - //========================================================================== // // R_UpdateSky diff --git a/src/r_sky.h b/src/r_sky.h index d9963d96c..05154e2fd 100644 --- a/src/r_sky.h +++ b/src/r_sky.h @@ -31,13 +31,9 @@ #include "textures/textures.h" 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; extern bool skystretch; extern int freelookviewheight; diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 40b640e46..d12f3bf4d 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -144,6 +144,8 @@ bool setsizeneeded; unsigned int R_OldBlend = ~0; int validcount = 1; // increment every time a check is made int dl_validcount = 1; // increment every time a check is made +int freelookviewheight; + FCanvasTextureInfo *FCanvasTextureInfo::List; DVector3a view; diff --git a/src/swrenderer/plane/r_skyplane.cpp b/src/swrenderer/plane/r_skyplane.cpp index de30a0a89..feac5b5da 100644 --- a/src/swrenderer/plane/r_skyplane.cpp +++ b/src/swrenderer/plane/r_skyplane.cpp @@ -57,8 +57,65 @@ CVAR(Bool, r_linearsky, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); EXTERN_CVAR(Int, r_skymode) + +double skytexturemid; +double skyscale; +float skyiscale; +fixed_t sky1cyl, sky2cyl; + +void InitSoftwareSky() +{ + auto skytex1 = TexMan(sky1texture, true); + auto skytex2 = TexMan(sky2texture, true); + + if (skytex1 == nullptr) + return; + + // Note: I don't think it is good that this stuff gets cached globally. + // For something that only needs to be once per frame it is rather pointless and makes it hard to swap out the underlying textures based on user settings. + FSoftwareTexture *sskytex1 = skytex1->GetSoftwareTexture(); + FSoftwareTexture *sskytex2 = skytex2->GetSoftwareTexture(); + skytexturemid = 0; + int skyheight = skytex1->GetDisplayHeight(); + if (skyheight >= 128 && skyheight < 200) + { + skytexturemid = -28; + } + else if (skyheight > 200) + { + skytexturemid = (200 - skyheight) * sskytex1->GetScale().Y + ((r_skymode == 2 && !(level.flags & LEVEL_FORCETILEDSKY)) ? skytex1->GetSkyOffset() : 0); + } + + if (viewwidth != 0 && viewheight != 0) + { + skyiscale = float(r_Yaspect / freelookviewheight); + skyscale = freelookviewheight / r_Yaspect; + + skyiscale *= float(r_viewpoint.FieldOfView.Degrees / 90.); + skyscale *= float(90. / r_viewpoint.FieldOfView.Degrees); + } + + if (skystretch) + { + skyscale *= (double)SKYSTRETCH_HEIGHT / skyheight; + skyiscale *= skyheight / (float)SKYSTRETCH_HEIGHT; + skytexturemid *= skyheight / (double)SKYSTRETCH_HEIGHT; + } + + // The standard Doom sky texture is 256 pixels wide, repeated 4 times over 360 degrees, + // giving a total sky width of 1024 pixels. So if the sky texture is no wider than 1024, + // we map it to a cylinder with circumfrence 1024. For larger ones, we use the width of + // the texture as the cylinder's circumfrence. + sky1cyl = MAX(sskytex1->GetWidth(), fixed_t(sskytex1->GetScale().X * 1024)); + sky2cyl = MAX(sskytex2->GetWidth(), fixed_t(sskytex2->GetScale().Y * 1024)); +} + + + + namespace swrenderer { + static FSoftwareTexture *GetSWTex(FTextureID texid, bool allownull = true) { auto tex = TexMan(texid, true); diff --git a/src/swrenderer/r_swscene.cpp b/src/swrenderer/r_swscene.cpp index 7a3cfe2d7..c8b8da57c 100644 --- a/src/swrenderer/r_swscene.cpp +++ b/src/swrenderer/r_swscene.cpp @@ -37,6 +37,7 @@ // [RH] Base blending values (for e.g. underwater) int BaseBlendR, BaseBlendG, BaseBlendB; float BaseBlendA; +void InitSoftwareSky(); @@ -80,6 +81,7 @@ SWSceneDrawer::~SWSceneDrawer() sector_t *SWSceneDrawer::RenderView(player_t *player) { // Avoid using the pixel buffer from the last frame + InitSoftwareSky(); // do this here to avoid problems when texture modes are changed on the fly. FBTextureIndex = (FBTextureIndex + 1) % 2; auto &fbtex = FBTexture[FBTextureIndex]; diff --git a/wadsrc/static/zscript/statusbar/harm_sbar.txt b/wadsrc/static/zscript/statusbar/harm_sbar.txt index 729df7cda..ebed03f92 100644 --- a/wadsrc/static/zscript/statusbar/harm_sbar.txt +++ b/wadsrc/static/zscript/statusbar/harm_sbar.txt @@ -36,13 +36,13 @@ class HarmonyStatusBar : DoomStatusBar { Vector2 iconbox = (40, 20); // Draw health - DrawImage("MEDIA0", (20, -2), scale(scaleFactor, scaleFactor)); + DrawImage("MEDIA0", (20, -2), scale:(scaleFactor, scaleFactor)); DrawString(mHUDFont, FormatNumber(CPlayer.health, 3), (44, -20)); let armor = CPlayer.mo.FindInventory("BasicArmor"); if (armor != null && armor.Amount > 0) { - DrawInventoryIcon(armor, (20, -22), scale(scaleFactor, scaleFactor)); + DrawInventoryIcon(armor, (20, -22), scale:(scaleFactor, scaleFactor)); DrawString(mHUDFont, FormatNumber(armor.Amount, 3), (44, -40)); } Inventory ammotype1, ammotype2; @@ -50,13 +50,13 @@ class HarmonyStatusBar : DoomStatusBar int invY = -20; if (ammotype1 != null) { - DrawInventoryIcon(ammotype1, (-14, -4), scale(scaleFactor, scaleFactor)); + DrawInventoryIcon(ammotype1, (-14, -4), scale:(scaleFactor, scaleFactor)); DrawString(mHUDFont, FormatNumber(ammotype1.Amount, 3), (-30, -20), DI_TEXT_ALIGN_RIGHT); invY -= 20; } if (ammotype2 != null && ammotype2 != ammotype1) { - DrawInventoryIcon(ammotype2, (-14, invY + 17), scale(scaleFactor, scaleFactor)); + DrawInventoryIcon(ammotype2, (-14, invY + 17), scale:(scaleFactor, scaleFactor)); DrawString(mHUDFont, FormatNumber(ammotype2.Amount, 3), (-30, invY), DI_TEXT_ALIGN_RIGHT); invY -= 20; }