Skip to content

Commit

Permalink
- everything compiles again.
Browse files Browse the repository at this point in the history
As a bonus this already fixes several bugs caused by the botched texture scaling implementation the original texture manager came with.
System cursors are currently disabled because they rely on functionality that needs to be moved to different classes.
  • Loading branch information
coelckers committed Dec 6, 2018
1 parent 6eab4a8 commit a4d61e6
Show file tree
Hide file tree
Showing 41 changed files with 268 additions and 197 deletions.
4 changes: 1 addition & 3 deletions src/gl/renderer/gl_renderstate.cpp
Expand Up @@ -303,7 +303,6 @@ void FGLRenderState::Apply()

void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader)
{
#if 0
if (mat->tex->isHardwareCanvas())
{
mTempTM = TM_OPAQUE;
Expand All @@ -318,7 +317,7 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio

auto tex = mat->tex;
if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER;
if (tex->sHardwareCanvas()) clampmode = CLAMP_CAMTEX;
if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX;
else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;

// avoid rebinding the same texture multiple times.
Expand Down Expand Up @@ -351,7 +350,6 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio
FHardwareTexture::Unbind(i);
maxBoundMaterial = maxbound;
}
#endif
}

//==========================================================================
Expand Down
2 changes: 0 additions & 2 deletions src/gl/textures/gl_hwtexture.cpp
Expand Up @@ -422,7 +422,6 @@ void FHardwareTexture::BindToFrameBuffer(int width, int height)

bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags)
{
#if 0
int usebright = false;

if (translation <= 0)
Expand Down Expand Up @@ -465,7 +464,6 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i
}
if (tex->isHardwareCanvas()) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255);
#endif
return true;
}

Expand Down
73 changes: 39 additions & 34 deletions src/swrenderer/line/r_line.cpp
Expand Up @@ -425,7 +425,7 @@ namespace swrenderer
if (!onlyUpdatePlaneClip)
// allocate space for masked texture tables, if needed
// [RH] Don't just allocate the space; fill it in too.
if ((TexMan(sidedef->GetTexture(side_t::mid), true)->UseType != ETextureType::Null || draw_segment->Has3DFloorWalls() || IsFogBoundary(mFrontSector, mBackSector)) &&
if ((sidedef->GetTexture(side_t::mid).isValid() || draw_segment->Has3DFloorWalls() || IsFogBoundary(mFrontSector, mBackSector)) &&
(mCeilingClipped != ProjectedWallCull::OutsideBelow || !sidedef->GetTexture(side_t::top).isValid()) &&
(mFloorClipped != ProjectedWallCull::OutsideAbove || !sidedef->GetTexture(side_t::bottom).isValid()) &&
(WallC.sz1 >= TOO_CLOSE_Z && WallC.sz2 >= TOO_CLOSE_Z))
Expand All @@ -451,11 +451,12 @@ namespace swrenderer

lwal = draw_segment->maskedtexturecol;
swal = draw_segment->swall;
FTexture *pic = TexMan(sidedef->GetTexture(side_t::mid), true);
double yscale = pic->Scale.Y * sidedef->GetTextureYScale(side_t::mid);
FTexture *tex = TexMan(sidedef->GetTexture(side_t::mid), true);
FSoftwareTexture *pic = tex && tex->isValid()? tex->GetSoftwareTexture() : nullptr;
double yscale = pic->GetScale().Y * sidedef->GetTextureYScale(side_t::mid);
fixed_t xoffset = FLOAT2FIXED(sidedef->GetTextureXOffset(side_t::mid));

if (pic->bWorldPanning)
if (pic->useWorldPanning())
{
xoffset = xs_RoundToInt(xoffset * lwallscale);
}
Expand Down Expand Up @@ -769,17 +770,18 @@ namespace swrenderer
}
}

FTexture *midtex = TexMan(sidedef->GetTexture(side_t::mid), true);
FTexture *ftex = TexMan(sidedef->GetTexture(side_t::mid), true);
FSoftwareTexture *midtex = ftex && ftex->isValid() ? ftex->GetSoftwareTexture() : nullptr;

bool segtextured = midtex != NULL || mTopPart.Texture != NULL || mBottomPart.Texture != NULL;

// calculate light table
if (needlights && (segtextured || (mBackSector && IsFogBoundary(mFrontSector, mBackSector))))
{
lwallscale =
midtex ? (midtex->Scale.X * sidedef->GetTextureXScale(side_t::mid)) :
mTopPart.Texture ? (mTopPart.Texture->Scale.X * sidedef->GetTextureXScale(side_t::top)) :
mBottomPart.Texture ? (mBottomPart.Texture->Scale.X * sidedef->GetTextureXScale(side_t::bottom)) :
midtex ? (midtex->GetScale().X * sidedef->GetTextureXScale(side_t::mid)) :
mTopPart.Texture ? (mTopPart.Texture->GetScale().X * sidedef->GetTextureXScale(side_t::top)) :
mBottomPart.Texture ? (mBottomPart.Texture->GetScale().X * sidedef->GetTextureXScale(side_t::bottom)) :
1.;

walltexcoords.Project(Thread->Viewport.get(), sidedef->TexelLength * lwallscale, WallC.sx1, WallC.sx2, WallT);
Expand Down Expand Up @@ -814,13 +816,14 @@ namespace swrenderer
// No top texture for skyhack lines
if (mFrontSector->GetTexture(sector_t::ceiling) == skyflatnum && mBackSector->GetTexture(sector_t::ceiling) == skyflatnum) return;

mTopPart.Texture = TexMan(sidedef->GetTexture(side_t::top), true);
FTexture *tex = TexMan(sidedef->GetTexture(side_t::top), true);
mTopPart.Texture = tex && tex->isValid() ? tex->GetSoftwareTexture() : nullptr;

mTopPart.TextureOffsetU = FLOAT2FIXED(sidedef->GetTextureXOffset(side_t::top));
double rowoffset = sidedef->GetTextureYOffset(side_t::top);
mTopPart.TextureScaleU = sidedef->GetTextureXScale(side_t::top);
mTopPart.TextureScaleV = sidedef->GetTextureYScale(side_t::top);
double yrepeat = mTopPart.Texture->Scale.Y * mTopPart.TextureScaleV;
double yrepeat = mTopPart.Texture->GetScale().Y * mTopPart.TextureScaleV;
if (yrepeat >= 0)
{ // normal orientation
if (linedef->flags & ML_DONTPEGTOP)
Expand Down Expand Up @@ -848,7 +851,7 @@ namespace swrenderer
mTopPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::ceiling) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat;
}
}
if (mTopPart.Texture->bWorldPanning)
if (mTopPart.Texture->useWorldPanning())
{
mTopPart.TextureMid += rowoffset * yrepeat;
}
Expand All @@ -871,12 +874,13 @@ namespace swrenderer
if (linedef->isVisualPortal()) return;
if (linedef->special == Line_Horizon) return;

mMiddlePart.Texture = TexMan(sidedef->GetTexture(side_t::mid), true);
auto tex = TexMan(sidedef->GetTexture(side_t::mid), true);
mMiddlePart.Texture = tex && tex->isValid() ? tex->GetSoftwareTexture() : nullptr;
mMiddlePart.TextureOffsetU = FLOAT2FIXED(sidedef->GetTextureXOffset(side_t::mid));
double rowoffset = sidedef->GetTextureYOffset(side_t::mid);
mMiddlePart.TextureScaleU = sidedef->GetTextureXScale(side_t::mid);
mMiddlePart.TextureScaleV = sidedef->GetTextureYScale(side_t::mid);
double yrepeat = mMiddlePart.Texture->Scale.Y * mMiddlePart.TextureScaleV;
double yrepeat = mMiddlePart.Texture->GetScale().Y * mMiddlePart.TextureScaleV;
if (yrepeat >= 0)
{ // normal orientation
if (linedef->flags & ML_DONTPEGBOTTOM)
Expand Down Expand Up @@ -904,7 +908,7 @@ namespace swrenderer
mMiddlePart.TextureMid = (mFrontSector->GetPlaneTexZ(sector_t::ceiling) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + mMiddlePart.Texture->GetHeight();
}
}
if (mMiddlePart.Texture->bWorldPanning)
if (mMiddlePart.Texture->useWorldPanning())
{
mMiddlePart.TextureMid += rowoffset * yrepeat;
}
Expand Down Expand Up @@ -935,13 +939,14 @@ namespace swrenderer
frontlowertop = mBackSector->GetPlaneTexZ(sector_t::ceiling);
}

mBottomPart.Texture = TexMan(sidedef->GetTexture(side_t::bottom), true);
FTexture *tex = TexMan(sidedef->GetTexture(side_t::bottom), true);;
mBottomPart.Texture = tex && tex->isValid() ? tex->GetSoftwareTexture() : nullptr;

mBottomPart.TextureOffsetU = FLOAT2FIXED(sidedef->GetTextureXOffset(side_t::bottom));
double rowoffset = sidedef->GetTextureYOffset(side_t::bottom);
mBottomPart.TextureScaleU = sidedef->GetTextureXScale(side_t::bottom);
mBottomPart.TextureScaleV = sidedef->GetTextureYScale(side_t::bottom);
double yrepeat = mBottomPart.Texture->Scale.Y * mBottomPart.TextureScaleV;
double yrepeat = mBottomPart.Texture->GetScale().Y * mBottomPart.TextureScaleV;
if (yrepeat >= 0)
{ // normal orientation
if (linedef->flags & ML_DONTPEGBOTTOM)
Expand Down Expand Up @@ -969,7 +974,7 @@ namespace swrenderer
mBottomPart.TextureMid = (mBackSector->GetPlaneTexZ(sector_t::floor) - Thread->Viewport->viewpoint.Pos.Z) * yrepeat + mBottomPart.Texture->GetHeight();
}
}
if (mBottomPart.Texture->bWorldPanning)
if (mBottomPart.Texture->useWorldPanning())
{
mBottomPart.TextureMid += rowoffset * yrepeat;
}
Expand Down Expand Up @@ -1101,7 +1106,7 @@ namespace swrenderer
}
else
{ // two sided line
if (mTopPart.Texture != NULL && mTopPart.Texture->UseType != ETextureType::Null)
if (mTopPart.Texture != nullptr)
{ // top wall
for (int x = x1; x < x2; ++x)
{
Expand All @@ -1114,7 +1119,7 @@ namespace swrenderer
memcpy(ceilingclip + x1, walltop.ScreenY + x1, (x2 - x1) * sizeof(short));
}

if (mBottomPart.Texture != NULL && mBottomPart.Texture->UseType != ETextureType::Null)
if (mBottomPart.Texture != nullptr)
{ // bottom wall
for (int x = x1; x < x2; ++x)
{
Expand All @@ -1132,19 +1137,19 @@ namespace swrenderer
void SWRenderLine::RenderTopTexture(int x1, int x2)
{
if (mMiddlePart.Texture) return;
if (!mTopPart.Texture || mTopPart.Texture->UseType == ETextureType::Null) return;
if (!mTopPart.Texture) return;
if (!viewactive) return;

FTexture *rw_pic = mTopPart.Texture;
double xscale = rw_pic->Scale.X * mTopPart.TextureScaleU;
double yscale = rw_pic->Scale.Y * mTopPart.TextureScaleV;
auto rw_pic = mTopPart.Texture;
double xscale = rw_pic->GetScale().X * mTopPart.TextureScaleU;
double yscale = rw_pic->GetScale().Y * mTopPart.TextureScaleV;
if (xscale != lwallscale)
{
walltexcoords.ProjectPos(Thread->Viewport.get(), mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT);
lwallscale = xscale;
}
fixed_t offset;
if (mTopPart.Texture->bWorldPanning)
if (mTopPart.Texture->useWorldPanning())
{
offset = xs_RoundToInt(mTopPart.TextureOffsetU * xscale);
}
Expand Down Expand Up @@ -1179,19 +1184,19 @@ namespace swrenderer

void SWRenderLine::RenderMiddleTexture(int x1, int x2)
{
if (!mMiddlePart.Texture || mMiddlePart.Texture->UseType == ETextureType::Null) return;
if (!mMiddlePart.Texture) return;
if (!viewactive) return;

FTexture *rw_pic = mMiddlePart.Texture;
double xscale = rw_pic->Scale.X * mMiddlePart.TextureScaleU;
double yscale = rw_pic->Scale.Y * mMiddlePart.TextureScaleV;
auto rw_pic = mMiddlePart.Texture;
double xscale = rw_pic->GetScale().X * mMiddlePart.TextureScaleU;
double yscale = rw_pic->GetScale().Y * mMiddlePart.TextureScaleV;
if (xscale != lwallscale)
{
walltexcoords.ProjectPos(Thread->Viewport.get(), mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT);
lwallscale = xscale;
}
fixed_t offset;
if (mMiddlePart.Texture->bWorldPanning)
if (mMiddlePart.Texture->useWorldPanning())
{
offset = xs_RoundToInt(mMiddlePart.TextureOffsetU * xscale);
}
Expand Down Expand Up @@ -1227,19 +1232,19 @@ namespace swrenderer
void SWRenderLine::RenderBottomTexture(int x1, int x2)
{
if (mMiddlePart.Texture) return;
if (!mBottomPart.Texture || mBottomPart.Texture->UseType == ETextureType::Null) return;
if (!mBottomPart.Texture) return;
if (!viewactive) return;

FTexture *rw_pic = mBottomPart.Texture;
double xscale = rw_pic->Scale.X * mBottomPart.TextureScaleU;
double yscale = rw_pic->Scale.Y * mBottomPart.TextureScaleV;
auto rw_pic = mBottomPart.Texture;
double xscale = rw_pic->GetScale().X * mBottomPart.TextureScaleU;
double yscale = rw_pic->GetScale().Y * mBottomPart.TextureScaleV;
if (xscale != lwallscale)
{
walltexcoords.ProjectPos(Thread->Viewport.get(), mLineSegment->sidedef->TexelLength*xscale, WallC.sx1, WallC.sx2, WallT);
lwallscale = xscale;
}
fixed_t offset;
if (mBottomPart.Texture->bWorldPanning)
if (mBottomPart.Texture->useWorldPanning())
{
offset = xs_RoundToInt(mBottomPart.TextureOffsetU * xscale);
}
Expand Down
2 changes: 1 addition & 1 deletion src/swrenderer/line/r_line.h
Expand Up @@ -65,7 +65,7 @@ namespace swrenderer
double TextureMid;
double TextureScaleU;
double TextureScaleV;
FTexture *Texture;
FSoftwareTexture *Texture;
};

class SWRenderLine : VisibleSegmentRenderer
Expand Down

0 comments on commit a4d61e6

Please sign in to comment.