- moved the software rendering specific parts of the sky setup to r_skyplane.cpp.

This commit is contained in:
Christoph Oelckers 2018-12-06 20:52:03 +01:00
parent d500dc99ea
commit 32e245f2b9
7 changed files with 77 additions and 68 deletions

View File

@ -32,6 +32,11 @@
EXTERN_CVAR(Float, skyoffset)
extern double skytexturemid;
extern float skyiscale;
extern double skyscale;
extern fixed_t sky1cyl, sky2cyl;
PolySkyDome::PolySkyDome()
{

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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];

View File

@ -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;
}