mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 15:21:51 +00:00
- moved hardware independent part of flat vertex data out of GL folder.
This commit is contained in:
parent
ba4cc1a6ca
commit
0affc119fd
7 changed files with 398 additions and 271 deletions
|
@ -1082,6 +1082,7 @@ set (PCH_SOURCES
|
|||
gl/textures/gl_texture.cpp
|
||||
gl/textures/gl_material.cpp
|
||||
gl/textures/gl_samplers.cpp
|
||||
hwrenderer/data/flatvertices.cpp
|
||||
hwrenderer/dynlights/hw_aabbtree.cpp
|
||||
|
||||
menu/joystickmenu.cpp
|
||||
|
|
|
@ -126,7 +126,7 @@ void FSimpleVertexBuffer::set(FSimpleVertex *verts, int count)
|
|||
//==========================================================================
|
||||
|
||||
FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
|
||||
: FVertexBuffer(!gl.legacyMode)
|
||||
: FVertexBuffer(!gl.legacyMode), FFlatVertexGenerator(width, height)
|
||||
{
|
||||
switch (gl.buffermethod)
|
||||
{
|
||||
|
@ -159,36 +159,6 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
|
|||
}
|
||||
mIndex = mCurIndex = 0;
|
||||
mNumReserved = NUM_RESERVED;
|
||||
vbo_shadowdata.Resize(mNumReserved);
|
||||
|
||||
// the first quad is reserved for handling coordinates through uniforms.
|
||||
vbo_shadowdata[0].Set(0, 0, 0, 0, 0);
|
||||
vbo_shadowdata[1].Set(1, 0, 0, 0, 0);
|
||||
vbo_shadowdata[2].Set(2, 0, 0, 0, 0);
|
||||
vbo_shadowdata[3].Set(3, 0, 0, 0, 0);
|
||||
|
||||
// and the second one for the fullscreen quad used for blend overlays.
|
||||
vbo_shadowdata[4].Set(0, 0, 0, 0, 0);
|
||||
vbo_shadowdata[5].Set(0, (float)height, 0, 0, 1);
|
||||
vbo_shadowdata[6].Set((float)width, 0, 0, 1, 0);
|
||||
vbo_shadowdata[7].Set((float)width, (float)height, 0, 1, 1);
|
||||
|
||||
// and this is for the postprocessing copy operation
|
||||
vbo_shadowdata[8].Set(-1.0f, -1.0f, 0, 0.0f, 0.0f);
|
||||
vbo_shadowdata[9].Set(-1.0f, 1.0f, 0, 0.0f, 1.f);
|
||||
vbo_shadowdata[10].Set(1.0f, -1.0f, 0, 1.f, 0.0f);
|
||||
vbo_shadowdata[11].Set(1.0f, 1.0f, 0, 1.f, 1.f);
|
||||
|
||||
// The next two are the stencil caps.
|
||||
vbo_shadowdata[12].Set(-32767.0f, 32767.0f, -32767.0f, 0, 0);
|
||||
vbo_shadowdata[13].Set(-32767.0f, 32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[14].Set(32767.0f, 32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[15].Set(32767.0f, 32767.0f, -32767.0f, 0, 0);
|
||||
|
||||
vbo_shadowdata[16].Set(-32767.0f, -32767.0f, -32767.0f, 0, 0);
|
||||
vbo_shadowdata[17].Set(-32767.0f, -32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[18].Set(32767.0f, -32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[19].Set(32767.0f, -32767.0f, -32767.0f, 0, 0);
|
||||
|
||||
if (gl.buffermethod == BM_DEFERRED)
|
||||
{
|
||||
|
@ -216,11 +186,7 @@ FFlatVertexBuffer::~FFlatVertexBuffer()
|
|||
|
||||
void FFlatVertexBuffer::OutputResized(int width, int height)
|
||||
{
|
||||
vbo_shadowdata[4].Set(0, 0, 0, 0, 0);
|
||||
vbo_shadowdata[5].Set(0, (float)height, 0, 0, 1);
|
||||
vbo_shadowdata[6].Set((float)width, 0, 0, 1, 0);
|
||||
vbo_shadowdata[7].Set((float)width, (float)height, 0, 1, 1);
|
||||
|
||||
FFlatVertexGenerator::OutputResized(width, height);
|
||||
Map();
|
||||
memcpy(&map[4], &vbo_shadowdata[4], 4 * sizeof(FFlatVertex));
|
||||
Unmap();
|
||||
|
@ -272,173 +238,6 @@ void FFlatVertexBuffer::Unmap()
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Initialize a single vertex
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertex::SetFlatVertex(vertex_t *vt, const secplane_t & plane)
|
||||
{
|
||||
x = vt->fX();
|
||||
y = vt->fY();
|
||||
z = plane.ZatPoint(vt);
|
||||
u = vt->fX()/64.f;
|
||||
v = -vt->fY()/64.f;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Find a 3D floor
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static F3DFloor *Find3DFloor(sector_t *target, sector_t *model)
|
||||
{
|
||||
for(unsigned i=0; i<target->e->XFloor.ffloors.Size(); i++)
|
||||
{
|
||||
F3DFloor *ffloor = target->e->XFloor.ffloors[i];
|
||||
if (ffloor->model == model && !(ffloor->flags & FF_THISINSIDE)) return ffloor;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Creates the vertices for one plane in one subsector
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFlatVertexBuffer::CreateSubsectorVertices(subsector_t *sub, const secplane_t &plane, int floor)
|
||||
{
|
||||
int idx = vbo_shadowdata.Reserve(sub->numlines);
|
||||
for(unsigned int k=0; k<sub->numlines; k++, idx++)
|
||||
{
|
||||
vbo_shadowdata[idx].SetFlatVertex(sub->firstline[k].v1, plane);
|
||||
if (sub->sector->transdoor && floor) vbo_shadowdata[idx].z -= 1.f;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Creates the vertices for one plane in one subsector
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFlatVertexBuffer::CreateSectorVertices(sector_t *sec, const secplane_t &plane, int floor)
|
||||
{
|
||||
int rt = vbo_shadowdata.Size();
|
||||
// First calculate the vertices for the sector itself
|
||||
for(int j=0; j<sec->subsectorcount; j++)
|
||||
{
|
||||
subsector_t *sub = sec->subsectors[j];
|
||||
CreateSubsectorVertices(sub, plane, floor);
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFlatVertexBuffer::CreateVertices(int h, sector_t *sec, const secplane_t &plane, int floor)
|
||||
{
|
||||
// First calculate the vertices for the sector itself
|
||||
sec->vboheight[h] = sec->GetPlaneTexZ(h);
|
||||
sec->vboindex[h] = CreateSectorVertices(sec, plane, floor);
|
||||
|
||||
// Next are all sectors using this one as heightsec
|
||||
TArray<sector_t *> &fakes = sec->e->FakeFloor.Sectors;
|
||||
for (unsigned g=0; g<fakes.Size(); g++)
|
||||
{
|
||||
sector_t *fsec = fakes[g];
|
||||
fsec->vboindex[2+h] = CreateSectorVertices(fsec, plane, false);
|
||||
}
|
||||
|
||||
// and finally all attached 3D floors
|
||||
TArray<sector_t *> &xf = sec->e->XFloor.attached;
|
||||
for (unsigned g=0; g<xf.Size(); g++)
|
||||
{
|
||||
sector_t *fsec = xf[g];
|
||||
F3DFloor *ffloor = Find3DFloor(fsec, sec);
|
||||
|
||||
if (ffloor != NULL && ffloor->flags & FF_RENDERPLANES)
|
||||
{
|
||||
bool dotop = (ffloor->top.model == sec) && (ffloor->top.isceiling == h);
|
||||
bool dobottom = (ffloor->bottom.model == sec) && (ffloor->bottom.isceiling == h);
|
||||
|
||||
if (dotop || dobottom)
|
||||
{
|
||||
if (dotop) ffloor->top.vindex = vbo_shadowdata.Size();
|
||||
if (dobottom) ffloor->bottom.vindex = vbo_shadowdata.Size();
|
||||
|
||||
CreateSectorVertices(fsec, plane, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
sec->vbocount[h] = vbo_shadowdata.Size() - sec->vboindex[h];
|
||||
return sec->vboindex[h];
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexBuffer::CreateFlatVBO()
|
||||
{
|
||||
for (int h = sector_t::floor; h <= sector_t::ceiling; h++)
|
||||
{
|
||||
for(auto &sec : level.sectors)
|
||||
{
|
||||
CreateVertices(h, &sec, sec.GetSecPlane(h), h == sector_t::floor);
|
||||
}
|
||||
}
|
||||
|
||||
// We need to do a final check for Vavoom water and FF_FIX sectors.
|
||||
// No new vertices are needed here. The planes come from the actual sector
|
||||
for (auto &sec : level.sectors)
|
||||
{
|
||||
for(auto ff : sec.e->XFloor.ffloors)
|
||||
{
|
||||
if (ff->top.model == &sec)
|
||||
{
|
||||
ff->top.vindex = sec.vboindex[ff->top.isceiling];
|
||||
}
|
||||
if (ff->bottom.model == &sec)
|
||||
{
|
||||
ff->bottom.vindex = sec.vboindex[ff->top.isceiling];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane)
|
||||
{
|
||||
int startvt = sec->vboindex[plane];
|
||||
int countvt = sec->vbocount[plane];
|
||||
secplane_t &splane = sec->GetSecPlane(plane);
|
||||
FFlatVertex *vt = &vbo_shadowdata[startvt];
|
||||
FFlatVertex *mapvt = &map[startvt];
|
||||
for(int i=0; i<countvt; i++, vt++, mapvt++)
|
||||
{
|
||||
vt->z = splane.ZatPoint(vt->x, vt->y);
|
||||
if (plane == sector_t::floor && sec->transdoor) vt->z -= 1;
|
||||
mapvt->z = vt->z;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
|
@ -448,45 +247,9 @@ void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane)
|
|||
void FFlatVertexBuffer::CreateVBO()
|
||||
{
|
||||
vbo_shadowdata.Resize(mNumReserved);
|
||||
CreateFlatVBO();
|
||||
FFlatVertexGenerator::CreateVertices();
|
||||
mCurIndex = mIndex = vbo_shadowdata.Size();
|
||||
Map();
|
||||
memcpy(map, &vbo_shadowdata[0], vbo_shadowdata.Size() * sizeof(FFlatVertex));
|
||||
Unmap();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexBuffer::CheckPlanes(sector_t *sector)
|
||||
{
|
||||
if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling])
|
||||
{
|
||||
UpdatePlaneVertices(sector, sector_t::ceiling);
|
||||
sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling);
|
||||
}
|
||||
if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor])
|
||||
{
|
||||
UpdatePlaneVertices(sector, sector_t::floor);
|
||||
sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor);
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// checks the validity of all planes attached to this sector
|
||||
// and updates them if possible.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexBuffer::CheckUpdate(sector_t *sector)
|
||||
{
|
||||
CheckPlanes(sector);
|
||||
sector_t *hs = sector->GetHeightSec();
|
||||
if (hs != NULL) CheckPlanes(hs);
|
||||
for (unsigned i = 0; i < sector->e->XFloor.ffloors.Size(); i++)
|
||||
CheckPlanes(sector->e->XFloor.ffloors[i]->model);
|
||||
}
|
|
@ -27,6 +27,7 @@
|
|||
#include "gl/utility/gl_clock.h"
|
||||
#include "gl/system/gl_interface.h"
|
||||
#include "r_data/models/models.h"
|
||||
#include "hwrenderer/data/flatvertices.h"
|
||||
|
||||
struct vertex_t;
|
||||
struct secplane_t;
|
||||
|
@ -56,22 +57,6 @@ public:
|
|||
void EnableBufferArrays(int enable, int disable);
|
||||
};
|
||||
|
||||
struct FFlatVertex
|
||||
{
|
||||
float x,z,y; // world position
|
||||
float u,v; // texture coordinates
|
||||
|
||||
void SetFlatVertex(vertex_t *vt, const secplane_t &plane);
|
||||
void Set(float xx, float zz, float yy, float uu, float vv)
|
||||
{
|
||||
x = xx;
|
||||
z = zz;
|
||||
y = yy;
|
||||
u = uu;
|
||||
v = vv;
|
||||
}
|
||||
};
|
||||
|
||||
struct FSimpleVertex
|
||||
{
|
||||
float x, z, y; // world position
|
||||
|
@ -104,14 +89,13 @@ public:
|
|||
void EnableColorArray(bool on);
|
||||
};
|
||||
|
||||
class FFlatVertexBuffer : public FVertexBuffer
|
||||
class FFlatVertexBuffer : public FVertexBuffer, public FFlatVertexGenerator
|
||||
{
|
||||
FFlatVertex *map;
|
||||
unsigned int mIndex;
|
||||
unsigned int mCurIndex;
|
||||
unsigned int mNumReserved;
|
||||
|
||||
void CheckPlanes(sector_t *sector);
|
||||
|
||||
static const unsigned int BUFFER_SIZE = 2000000;
|
||||
static const unsigned int BUFFER_SIZE_TO_USE = 1999500;
|
||||
|
@ -128,8 +112,6 @@ public:
|
|||
NUM_RESERVED = 20
|
||||
};
|
||||
|
||||
TArray<FFlatVertex> vbo_shadowdata; // this is kept around for updating the actual (non-readable) buffer and as stand-in for pre GL 4.x
|
||||
|
||||
FFlatVertexBuffer(int width, int height);
|
||||
~FFlatVertexBuffer();
|
||||
|
||||
|
@ -138,7 +120,6 @@ public:
|
|||
void BindVBO();
|
||||
|
||||
void CreateVBO();
|
||||
void CheckUpdate(sector_t *sector);
|
||||
|
||||
FFlatVertex *GetBuffer()
|
||||
{
|
||||
|
@ -180,6 +161,17 @@ public:
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
void CheckPlanes(sector_t *sector)
|
||||
{
|
||||
FFlatVertexGenerator::CheckPlanes(sector, map);
|
||||
}
|
||||
|
||||
void CheckUpdate(sector_t *sector)
|
||||
{
|
||||
FFlatVertexGenerator::CheckUpdate(sector, map);
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
mCurIndex = mIndex;
|
||||
|
@ -187,14 +179,6 @@ public:
|
|||
|
||||
void Map();
|
||||
void Unmap();
|
||||
|
||||
private:
|
||||
int CreateSubsectorVertices(subsector_t *sub, const secplane_t &plane, int floor);
|
||||
int CreateSectorVertices(sector_t *sec, const secplane_t &plane, int floor);
|
||||
int CreateVertices(int h, sector_t *sec, const secplane_t &plane, int floor);
|
||||
void CreateFlatVBO();
|
||||
void UpdatePlaneVertices(sector_t *sec, int plane);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -623,7 +623,7 @@ SortNode * GLDrawList::SortSpriteList(SortNode * head)
|
|||
|
||||
sortspritelist.Clear();
|
||||
for(count=0,n=head;n;n=n->next) sortspritelist.Push(n);
|
||||
std::sort(sortspritelist.begin(), sortspritelist.end(), [=](SortNode *a, SortNode *b)
|
||||
std::stable_sort(sortspritelist.begin(), sortspritelist.end(), [=](SortNode *a, SortNode *b)
|
||||
{
|
||||
return CompareSprites(a, b) < 0;
|
||||
});
|
||||
|
|
298
src/hwrenderer/data/flatvertices.cpp
Normal file
298
src/hwrenderer/data/flatvertices.cpp
Normal file
|
@ -0,0 +1,298 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2005-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/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
/*
|
||||
** hw_flatvertices.cpp
|
||||
** Creates flat vertex data for hardware rendering.
|
||||
**
|
||||
**/
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "p_local.h"
|
||||
#include "r_state.h"
|
||||
#include "m_argv.h"
|
||||
#include "c_cvars.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "flatvertices.h"
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FFlatVertexGenerator::FFlatVertexGenerator(int width, int height)
|
||||
{
|
||||
vbo_shadowdata.Resize(NUM_RESERVED);
|
||||
|
||||
// the first quad is reserved for handling coordinates through uniforms.
|
||||
vbo_shadowdata[0].Set(0, 0, 0, 0, 0);
|
||||
vbo_shadowdata[1].Set(1, 0, 0, 0, 0);
|
||||
vbo_shadowdata[2].Set(2, 0, 0, 0, 0);
|
||||
vbo_shadowdata[3].Set(3, 0, 0, 0, 0);
|
||||
|
||||
// and the second one for the fullscreen quad used for blend overlays.
|
||||
vbo_shadowdata[4].Set(0, 0, 0, 0, 0);
|
||||
vbo_shadowdata[5].Set(0, (float)height, 0, 0, 1);
|
||||
vbo_shadowdata[6].Set((float)width, 0, 0, 1, 0);
|
||||
vbo_shadowdata[7].Set((float)width, (float)height, 0, 1, 1);
|
||||
|
||||
// and this is for the postprocessing copy operation
|
||||
vbo_shadowdata[8].Set(-1.0f, -1.0f, 0, 0.0f, 0.0f);
|
||||
vbo_shadowdata[9].Set(-1.0f, 1.0f, 0, 0.0f, 1.f);
|
||||
vbo_shadowdata[10].Set(1.0f, -1.0f, 0, 1.f, 0.0f);
|
||||
vbo_shadowdata[11].Set(1.0f, 1.0f, 0, 1.f, 1.f);
|
||||
|
||||
// The next two are the stencil caps.
|
||||
vbo_shadowdata[12].Set(-32767.0f, 32767.0f, -32767.0f, 0, 0);
|
||||
vbo_shadowdata[13].Set(-32767.0f, 32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[14].Set(32767.0f, 32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[15].Set(32767.0f, 32767.0f, -32767.0f, 0, 0);
|
||||
|
||||
vbo_shadowdata[16].Set(-32767.0f, -32767.0f, -32767.0f, 0, 0);
|
||||
vbo_shadowdata[17].Set(-32767.0f, -32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[18].Set(32767.0f, -32767.0f, 32767.0f, 0, 0);
|
||||
vbo_shadowdata[19].Set(32767.0f, -32767.0f, -32767.0f, 0, 0);
|
||||
}
|
||||
|
||||
void FFlatVertexGenerator::OutputResized(int width, int height)
|
||||
{
|
||||
vbo_shadowdata[4].Set(0, 0, 0, 0, 0);
|
||||
vbo_shadowdata[5].Set(0, (float)height, 0, 0, 1);
|
||||
vbo_shadowdata[6].Set((float)width, 0, 0, 1, 0);
|
||||
vbo_shadowdata[7].Set((float)width, (float)height, 0, 1, 1);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Initialize a single vertex
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertex::SetFlatVertex(vertex_t *vt, const secplane_t & plane)
|
||||
{
|
||||
x = vt->fX();
|
||||
y = vt->fY();
|
||||
z = plane.ZatPoint(vt);
|
||||
u = vt->fX()/64.f;
|
||||
v = -vt->fY()/64.f;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Find a 3D floor
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static F3DFloor *Find3DFloor(sector_t *target, sector_t *model)
|
||||
{
|
||||
for(unsigned i=0; i<target->e->XFloor.ffloors.Size(); i++)
|
||||
{
|
||||
F3DFloor *ffloor = target->e->XFloor.ffloors[i];
|
||||
if (ffloor->model == model && !(ffloor->flags & FF_THISINSIDE)) return ffloor;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Creates the vertices for one plane in one subsector
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFlatVertexGenerator::CreateSubsectorVertices(subsector_t *sub, const secplane_t &plane, int floor)
|
||||
{
|
||||
int idx = vbo_shadowdata.Reserve(sub->numlines);
|
||||
for(unsigned int k=0; k<sub->numlines; k++, idx++)
|
||||
{
|
||||
vbo_shadowdata[idx].SetFlatVertex(sub->firstline[k].v1, plane);
|
||||
if (sub->sector->transdoor && floor) vbo_shadowdata[idx].z -= 1.f;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Creates the vertices for one plane in one subsector
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFlatVertexGenerator::CreateSectorVertices(sector_t *sec, const secplane_t &plane, int floor)
|
||||
{
|
||||
int rt = vbo_shadowdata.Size();
|
||||
// First calculate the vertices for the sector itself
|
||||
for(int j=0; j<sec->subsectorcount; j++)
|
||||
{
|
||||
subsector_t *sub = sec->subsectors[j];
|
||||
CreateSubsectorVertices(sub, plane, floor);
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFlatVertexGenerator::CreateVertices(int h, sector_t *sec, const secplane_t &plane, int floor)
|
||||
{
|
||||
// First calculate the vertices for the sector itself
|
||||
sec->vboheight[h] = sec->GetPlaneTexZ(h);
|
||||
sec->vboindex[h] = CreateSectorVertices(sec, plane, floor);
|
||||
|
||||
// Next are all sectors using this one as heightsec
|
||||
TArray<sector_t *> &fakes = sec->e->FakeFloor.Sectors;
|
||||
for (unsigned g=0; g<fakes.Size(); g++)
|
||||
{
|
||||
sector_t *fsec = fakes[g];
|
||||
fsec->vboindex[2+h] = CreateSectorVertices(fsec, plane, false);
|
||||
}
|
||||
|
||||
// and finally all attached 3D floors
|
||||
TArray<sector_t *> &xf = sec->e->XFloor.attached;
|
||||
for (unsigned g=0; g<xf.Size(); g++)
|
||||
{
|
||||
sector_t *fsec = xf[g];
|
||||
F3DFloor *ffloor = Find3DFloor(fsec, sec);
|
||||
|
||||
if (ffloor != NULL && ffloor->flags & FF_RENDERPLANES)
|
||||
{
|
||||
bool dotop = (ffloor->top.model == sec) && (ffloor->top.isceiling == h);
|
||||
bool dobottom = (ffloor->bottom.model == sec) && (ffloor->bottom.isceiling == h);
|
||||
|
||||
if (dotop || dobottom)
|
||||
{
|
||||
if (dotop) ffloor->top.vindex = vbo_shadowdata.Size();
|
||||
if (dobottom) ffloor->bottom.vindex = vbo_shadowdata.Size();
|
||||
|
||||
CreateSectorVertices(fsec, plane, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
sec->vbocount[h] = vbo_shadowdata.Size() - sec->vboindex[h];
|
||||
return sec->vboindex[h];
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexGenerator::CreateFlatVertices()
|
||||
{
|
||||
for (int h = sector_t::floor; h <= sector_t::ceiling; h++)
|
||||
{
|
||||
for(auto &sec : level.sectors)
|
||||
{
|
||||
CreateVertices(h, &sec, sec.GetSecPlane(h), h == sector_t::floor);
|
||||
}
|
||||
}
|
||||
|
||||
// We need to do a final check for Vavoom water and FF_FIX sectors.
|
||||
// No new vertices are needed here. The planes come from the actual sector
|
||||
for (auto &sec : level.sectors)
|
||||
{
|
||||
for(auto ff : sec.e->XFloor.ffloors)
|
||||
{
|
||||
if (ff->top.model == &sec)
|
||||
{
|
||||
ff->top.vindex = sec.vboindex[ff->top.isceiling];
|
||||
}
|
||||
if (ff->bottom.model == &sec)
|
||||
{
|
||||
ff->bottom.vindex = sec.vboindex[ff->top.isceiling];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexGenerator::UpdatePlaneVertices(sector_t *sec, int plane, FFlatVertex *map)
|
||||
{
|
||||
int startvt = sec->vboindex[plane];
|
||||
int countvt = sec->vbocount[plane];
|
||||
secplane_t &splane = sec->GetSecPlane(plane);
|
||||
FFlatVertex *vt = &vbo_shadowdata[startvt];
|
||||
FFlatVertex *mapvt = &map[startvt];
|
||||
for(int i=0; i<countvt; i++, vt++, mapvt++)
|
||||
{
|
||||
vt->z = splane.ZatPoint(vt->x, vt->y);
|
||||
if (plane == sector_t::floor && sec->transdoor) vt->z -= 1;
|
||||
mapvt->z = vt->z;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexGenerator::CreateVertices()
|
||||
{
|
||||
vbo_shadowdata.Resize(NUM_RESERVED);
|
||||
CreateFlatVertices();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexGenerator::CheckPlanes(sector_t *sector, FFlatVertex *map)
|
||||
{
|
||||
if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling])
|
||||
{
|
||||
UpdatePlaneVertices(sector, sector_t::ceiling, map);
|
||||
sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling);
|
||||
}
|
||||
if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor])
|
||||
{
|
||||
UpdatePlaneVertices(sector, sector_t::floor, map);
|
||||
sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor);
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// checks the validity of all planes attached to this sector
|
||||
// and updates them if possible.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexGenerator::CheckUpdate(sector_t *sector, FFlatVertex *map)
|
||||
{
|
||||
CheckPlanes(sector, map);
|
||||
sector_t *hs = sector->GetHeightSec();
|
||||
if (hs != NULL) CheckPlanes(hs, map);
|
||||
for (unsigned i = 0; i < sector->e->XFloor.ffloors.Size(); i++)
|
||||
CheckPlanes(sector->e->XFloor.ffloors[i]->model, map);
|
||||
}
|
81
src/hwrenderer/data/flatvertices.h
Normal file
81
src/hwrenderer/data/flatvertices.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2005-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/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#ifndef _HW__VERTEXBUFFER_H
|
||||
#define _HW__VERTEXBUFFER_H
|
||||
|
||||
#include "tarray.h"
|
||||
|
||||
struct FFlatVertex
|
||||
{
|
||||
float x, z, y; // world position
|
||||
float u, v; // texture coordinates
|
||||
|
||||
void SetFlatVertex(vertex_t *vt, const secplane_t &plane);
|
||||
void Set(float xx, float zz, float yy, float uu, float vv)
|
||||
{
|
||||
x = xx;
|
||||
z = zz;
|
||||
y = yy;
|
||||
u = uu;
|
||||
v = vv;
|
||||
}
|
||||
};
|
||||
|
||||
class FFlatVertexGenerator
|
||||
{
|
||||
protected:
|
||||
TArray<FFlatVertex> vbo_shadowdata;
|
||||
|
||||
|
||||
void CheckPlanes(sector_t *sector);
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
QUAD_INDEX = 0,
|
||||
FULLSCREEN_INDEX = 4,
|
||||
PRESENT_INDEX = 8,
|
||||
STENCILTOP_INDEX = 12,
|
||||
STENCILBOTTOM_INDEX = 16,
|
||||
|
||||
NUM_RESERVED = 20
|
||||
};
|
||||
|
||||
FFlatVertexGenerator(int width, int height);
|
||||
|
||||
void OutputResized(int width, int height);
|
||||
|
||||
private:
|
||||
int CreateSubsectorVertices(subsector_t *sub, const secplane_t &plane, int floor);
|
||||
int CreateSectorVertices(sector_t *sec, const secplane_t &plane, int floor);
|
||||
int CreateVertices(int h, sector_t *sec, const secplane_t &plane, int floor);
|
||||
void CreateFlatVertices();
|
||||
void UpdatePlaneVertices(sector_t *sec, int plane, FFlatVertex *map);
|
||||
protected:
|
||||
void CreateVertices();
|
||||
void CheckPlanes(sector_t *sector, FFlatVertex *map);
|
||||
void CheckUpdate(sector_t *sector, FFlatVertex *map);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -226,5 +226,5 @@ int FRawPageTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate,
|
|||
}
|
||||
bmp->CopyPixelData(x, y, source, 320, 200, 1, 320, 0, paldata, inf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue