2016-09-14 18:01:13 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright(C) 2006-2016 Christoph Oelckers
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
2018-04-26 05:07:46 +00:00
|
|
|
#include "r_defs.h"
|
|
|
|
#include "hwrenderer/data/flatvertices.h"
|
2018-04-26 18:07:56 +00:00
|
|
|
#include "hwrenderer/scene/hw_drawinfo.h"
|
2018-04-26 22:22:00 +00:00
|
|
|
#include "hwrenderer/scene/hw_drawstructs.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
EXTERN_CVAR(Bool, gl_seamless)
|
2014-05-31 07:32:17 +00:00
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Split upper edge of wall
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-05-05 09:48:39 +00:00
|
|
|
void GLWall::SplitUpperEdge(FFlatVertex *&ptr)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
side_t *sidedef = seg->sidedef;
|
|
|
|
float polyw = glseg.fracright - glseg.fracleft;
|
2016-05-05 09:48:39 +00:00
|
|
|
float facu = (tcs[UPRGT].u - tcs[UPLFT].u) / polyw;
|
|
|
|
float facv = (tcs[UPRGT].v - tcs[UPLFT].v) / polyw;
|
2014-05-31 07:32:17 +00:00
|
|
|
float fact = (ztop[1] - ztop[0]) / polyw;
|
2013-06-23 07:49:34 +00:00
|
|
|
float facc = (zceil[1] - zceil[0]) / polyw;
|
|
|
|
float facf = (zfloor[1] - zfloor[0]) / polyw;
|
|
|
|
|
2014-05-31 07:32:17 +00:00
|
|
|
for (int i = 0; i < sidedef->numsegs - 1; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t *cseg = sidedef->segs[i];
|
|
|
|
float sidefrac = cseg->sidefrac;
|
2014-05-31 07:32:17 +00:00
|
|
|
if (sidefrac <= glseg.fracleft) continue;
|
|
|
|
if (sidefrac >= glseg.fracright) return;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
float fracfac = sidefrac - glseg.fracleft;
|
|
|
|
|
2016-04-03 09:40:14 +00:00
|
|
|
ptr->x = cseg->v2->fX();
|
|
|
|
ptr->y = cseg->v2->fY();
|
2014-05-31 07:32:17 +00:00
|
|
|
ptr->z = ztop[0] + fact * fracfac;
|
2016-05-05 09:48:39 +00:00
|
|
|
ptr->u = tcs[UPLFT].u + facu * fracfac;
|
|
|
|
ptr->v = tcs[UPLFT].v + facv * fracfac;
|
2014-05-31 07:32:17 +00:00
|
|
|
ptr++;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:32:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Split upper edge of wall
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-05-05 09:48:39 +00:00
|
|
|
void GLWall::SplitLowerEdge(FFlatVertex *&ptr)
|
2014-05-10 23:23:27 +00:00
|
|
|
{
|
|
|
|
side_t *sidedef = seg->sidedef;
|
|
|
|
float polyw = glseg.fracright - glseg.fracleft;
|
2016-05-05 09:48:39 +00:00
|
|
|
float facu = (tcs[LORGT].u - tcs[LOLFT].u) / polyw;
|
|
|
|
float facv = (tcs[LORGT].v - tcs[LOLFT].v) / polyw;
|
2014-05-10 23:23:27 +00:00
|
|
|
float facb = (zbottom[1] - zbottom[0]) / polyw;
|
|
|
|
float facc = (zceil[1] - zceil[0]) / polyw;
|
|
|
|
float facf = (zfloor[1] - zfloor[0]) / polyw;
|
|
|
|
|
|
|
|
for (int i = sidedef->numsegs - 2; i >= 0; i--)
|
|
|
|
{
|
|
|
|
seg_t *cseg = sidedef->segs[i];
|
|
|
|
float sidefrac = cseg->sidefrac;
|
|
|
|
if (sidefrac >= glseg.fracright) continue;
|
|
|
|
if (sidefrac <= glseg.fracleft) return;
|
|
|
|
|
|
|
|
float fracfac = sidefrac - glseg.fracleft;
|
|
|
|
|
2016-04-03 09:40:14 +00:00
|
|
|
ptr->x = cseg->v2->fX();
|
|
|
|
ptr->y = cseg->v2->fY();
|
2014-05-10 23:23:27 +00:00
|
|
|
ptr->z = zbottom[0] + facb * fracfac;
|
2016-05-05 09:48:39 +00:00
|
|
|
ptr->u = tcs[LOLFT].u + facu * fracfac;
|
|
|
|
ptr->v = tcs[LOLFT].v + facv * fracfac;
|
2014-05-10 23:23:27 +00:00
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Split left edge of wall
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-05-05 09:48:39 +00:00
|
|
|
void GLWall::SplitLeftEdge(FFlatVertex *&ptr)
|
2014-05-10 23:23:27 +00:00
|
|
|
{
|
|
|
|
if (vertexes[0] == NULL) return;
|
|
|
|
|
|
|
|
vertex_t * vi = vertexes[0];
|
|
|
|
|
|
|
|
if (vi->numheights)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
float polyh1 = ztop[0] - zbottom[0];
|
2016-05-05 09:48:39 +00:00
|
|
|
float factv1 = polyh1 ? (tcs[UPLFT].v - tcs[LOLFT].v) / polyh1 : 0;
|
|
|
|
float factu1 = polyh1 ? (tcs[UPLFT].u - tcs[LOLFT].u) / polyh1 : 0;
|
2014-05-10 23:23:27 +00:00
|
|
|
|
|
|
|
while (i<vi->numheights && vi->heightlist[i] <= zbottom[0]) i++;
|
|
|
|
while (i<vi->numheights && vi->heightlist[i] < ztop[0])
|
|
|
|
{
|
|
|
|
ptr->x = glseg.x1;
|
|
|
|
ptr->y = glseg.y1;
|
|
|
|
ptr->z = vi->heightlist[i];
|
2016-05-05 09:48:39 +00:00
|
|
|
ptr->u = factu1*(vi->heightlist[i] - ztop[0]) + tcs[UPLFT].u;
|
|
|
|
ptr->v = factv1*(vi->heightlist[i] - ztop[0]) + tcs[UPLFT].v;
|
2014-05-10 23:23:27 +00:00
|
|
|
ptr++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Split right edge of wall
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-05-05 09:48:39 +00:00
|
|
|
void GLWall::SplitRightEdge(FFlatVertex *&ptr)
|
2014-05-10 23:23:27 +00:00
|
|
|
{
|
|
|
|
if (vertexes[1] == NULL) return;
|
|
|
|
|
|
|
|
vertex_t * vi = vertexes[1];
|
|
|
|
|
|
|
|
if (vi->numheights)
|
|
|
|
{
|
|
|
|
int i = vi->numheights - 1;
|
|
|
|
|
|
|
|
float polyh2 = ztop[1] - zbottom[1];
|
2016-05-05 09:48:39 +00:00
|
|
|
float factv2 = polyh2 ? (tcs[UPRGT].v - tcs[LORGT].v) / polyh2 : 0;
|
|
|
|
float factu2 = polyh2 ? (tcs[UPRGT].u - tcs[LORGT].u) / polyh2 : 0;
|
2014-05-10 23:23:27 +00:00
|
|
|
|
|
|
|
while (i>0 && vi->heightlist[i] >= ztop[1]) i--;
|
|
|
|
while (i>0 && vi->heightlist[i] > zbottom[1])
|
|
|
|
{
|
|
|
|
ptr->x = glseg.x2;
|
|
|
|
ptr->y = glseg.y2;
|
|
|
|
ptr->z = vi->heightlist[i];
|
2016-05-05 09:48:39 +00:00
|
|
|
ptr->u = factu2*(vi->heightlist[i] - ztop[1]) + tcs[UPRGT].u;
|
|
|
|
ptr->v = factv2*(vi->heightlist[i] - ztop[1]) + tcs[UPRGT].v;
|
2014-05-10 23:23:27 +00:00
|
|
|
ptr++;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-26 05:07:46 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Create vertices for one wall
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-04-26 17:25:11 +00:00
|
|
|
void GLWall::CreateVertices(FFlatVertex *&ptr, bool split)
|
2018-04-26 05:07:46 +00:00
|
|
|
{
|
|
|
|
ptr->Set(glseg.x1, zbottom[0], glseg.y1, tcs[LOLFT].u, tcs[LOLFT].v);
|
|
|
|
ptr++;
|
|
|
|
if (split && glseg.fracleft == 0) SplitLeftEdge(ptr);
|
|
|
|
ptr->Set(glseg.x1, ztop[0], glseg.y1, tcs[UPLFT].u, tcs[UPLFT].v);
|
|
|
|
ptr++;
|
2018-04-26 17:25:11 +00:00
|
|
|
if (split && !(flags & GLWF_NOSPLITUPPER && seg->sidedef->numsegs > 1)) SplitUpperEdge(ptr);
|
2018-04-26 05:07:46 +00:00
|
|
|
ptr->Set(glseg.x2, ztop[1], glseg.y2, tcs[UPRGT].u, tcs[UPRGT].v);
|
|
|
|
ptr++;
|
|
|
|
if (split && glseg.fracright == 1) SplitRightEdge(ptr);
|
|
|
|
ptr->Set(glseg.x2, zbottom[1], glseg.y2, tcs[LORGT].u, tcs[LORGT].v);
|
|
|
|
ptr++;
|
2018-04-26 17:25:11 +00:00
|
|
|
if (split && !(flags & GLWF_NOSPLITLOWER) && seg->sidedef->numsegs > 1) SplitLowerEdge(ptr);
|
2018-04-26 05:07:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-26 17:25:11 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
int GLWall::CountVertices()
|
|
|
|
{
|
|
|
|
int cnt = 4;
|
|
|
|
vertex_t * vi = vertexes[0];
|
|
|
|
if (glseg.fracleft == 0 && vi != nullptr && vi->numheights)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (i<vi->numheights && vi->heightlist[i] <= zbottom[0]) i++;
|
|
|
|
while (i<vi->numheights && vi->heightlist[i] < ztop[0])
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto sidedef = seg->sidedef;
|
2018-05-02 10:14:04 +00:00
|
|
|
constexpr auto NOSPLIT_LOWER_UPPER = GLWF_NOSPLITLOWER | GLWF_NOSPLITUPPER;
|
|
|
|
const bool canSplit = (flags & NOSPLIT_LOWER_UPPER) != NOSPLIT_LOWER_UPPER;
|
|
|
|
if (canSplit && sidedef->numsegs > 1)
|
2018-04-26 17:25:11 +00:00
|
|
|
{
|
|
|
|
int cnt2 = 0;
|
|
|
|
for (int i = sidedef->numsegs - 2; i >= 0; i--)
|
|
|
|
{
|
|
|
|
float sidefrac = sidedef->segs[i]->sidefrac;
|
|
|
|
if (sidefrac >= glseg.fracright) continue;
|
|
|
|
if (sidefrac <= glseg.fracleft) break;
|
|
|
|
cnt2++;
|
|
|
|
}
|
2018-05-02 10:14:04 +00:00
|
|
|
const bool splitBoth = !(flags & NOSPLIT_LOWER_UPPER);
|
|
|
|
if (splitBoth) cnt2 <<= 1;
|
2018-04-26 17:25:11 +00:00
|
|
|
cnt += cnt2;
|
|
|
|
}
|
|
|
|
vi = vertexes[1];
|
|
|
|
if (glseg.fracright == 1 && vi != nullptr && vi->numheights)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (i<vi->numheights && vi->heightlist[i] <= zbottom[1]) i++;
|
|
|
|
while (i<vi->numheights && vi->heightlist[i] < ztop[1])
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cnt;
|
2018-04-26 18:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// build the vertices for this wall
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void GLWall::MakeVertices(HWDrawInfo *di, bool nosplit)
|
|
|
|
{
|
|
|
|
if (vertcount == 0)
|
|
|
|
{
|
|
|
|
bool split = (gl_seamless && !nosplit && seg->sidedef != nullptr && !(seg->sidedef->Flags & WALLF_POLYOBJ) && !(flags & GLWF_NOSPLIT));
|
|
|
|
vertcount = split ? CountVertices() : 4;
|
|
|
|
|
|
|
|
auto ret = di->AllocVertices(vertcount);
|
|
|
|
vertindex = ret.second;
|
|
|
|
CreateVertices(ret.first, split);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|