2018-04-14 10:04:37 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// 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"
|
2018-10-28 11:00:25 +00:00
|
|
|
#include "hwrenderer/data/buffers.h"
|
2018-10-27 12:42:24 +00:00
|
|
|
#include <atomic>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
class FRenderState;
|
2018-04-14 10:04:37 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-27 12:27:43 +00:00
|
|
|
class FFlatVertexBuffer
|
2018-04-14 10:04:37 +00:00
|
|
|
{
|
|
|
|
TArray<FFlatVertex> vbo_shadowdata;
|
2018-05-19 11:33:28 +00:00
|
|
|
TArray<uint32_t> ibo_data;
|
2018-10-27 12:42:24 +00:00
|
|
|
|
|
|
|
IVertexBuffer *mVertexBuffer;
|
|
|
|
IIndexBuffer *mIndexBuffer;
|
|
|
|
|
|
|
|
unsigned int mIndex;
|
|
|
|
std::atomic<unsigned int> mCurIndex;
|
|
|
|
unsigned int mNumReserved;
|
|
|
|
|
|
|
|
|
|
|
|
static const unsigned int BUFFER_SIZE = 2000000;
|
|
|
|
static const unsigned int BUFFER_SIZE_TO_USE = 1999500;
|
|
|
|
|
2018-04-14 10:04:37 +00:00
|
|
|
|
2018-05-19 11:33:28 +00:00
|
|
|
// Temporary data for creating an indexed buffer
|
|
|
|
struct FIndexGenerationInfo
|
|
|
|
{
|
|
|
|
TArray<vertex_t *> vertices;
|
|
|
|
TMap<vertex_t*, uint32_t> vertexmap;
|
|
|
|
|
|
|
|
uint32_t AddVertex(vertex_t *vert)
|
|
|
|
{
|
|
|
|
auto check = vertexmap.CheckKey(vert);
|
|
|
|
if (check != nullptr) return *check;
|
|
|
|
auto index = vertices.Push(vert);
|
|
|
|
vertexmap[vert] = index;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GetIndex(vertex_t *vert)
|
|
|
|
{
|
|
|
|
auto check = vertexmap.CheckKey(vert);
|
|
|
|
if (check != nullptr) return *check;
|
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
};
|
2018-04-14 10:04:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
QUAD_INDEX = 0,
|
|
|
|
FULLSCREEN_INDEX = 4,
|
|
|
|
PRESENT_INDEX = 8,
|
|
|
|
STENCILTOP_INDEX = 12,
|
|
|
|
STENCILBOTTOM_INDEX = 16,
|
|
|
|
|
|
|
|
NUM_RESERVED = 20
|
|
|
|
};
|
|
|
|
|
2018-10-27 12:27:43 +00:00
|
|
|
FFlatVertexBuffer(int width, int height);
|
2018-10-27 12:42:24 +00:00
|
|
|
~FFlatVertexBuffer();
|
2018-04-14 10:04:37 +00:00
|
|
|
|
|
|
|
void OutputResized(int width, int height);
|
2018-10-30 18:28:47 +00:00
|
|
|
std::pair<IVertexBuffer *, IIndexBuffer *> GetBufferObjects() const
|
|
|
|
{
|
|
|
|
return std::make_pair(mVertexBuffer, mIndexBuffer);
|
|
|
|
}
|
|
|
|
|
2018-10-27 12:42:24 +00:00
|
|
|
void CreateVBO();
|
|
|
|
void Copy(int start, int count);
|
|
|
|
|
|
|
|
FFlatVertex *GetBuffer(int index) const
|
|
|
|
{
|
|
|
|
FFlatVertex *ff = (FFlatVertex*)mVertexBuffer->Memory();
|
|
|
|
return &ff[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
FFlatVertex *GetBuffer() const
|
|
|
|
{
|
|
|
|
return GetBuffer(mCurIndex);
|
|
|
|
}
|
|
|
|
|
2018-10-28 13:25:29 +00:00
|
|
|
std::pair<FFlatVertex *, unsigned int> AllocVertices(unsigned int count);
|
2018-10-27 12:42:24 +00:00
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
mCurIndex = mIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map()
|
|
|
|
{
|
|
|
|
mVertexBuffer->Map();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Unmap()
|
|
|
|
{
|
|
|
|
mVertexBuffer->Unmap();
|
|
|
|
}
|
2018-04-14 10:04:37 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-19 11:33:28 +00:00
|
|
|
int CreateIndexedSubsectorVertices(subsector_t *sub, const secplane_t &plane, int floor, int vi, FIndexGenerationInfo &gen);
|
|
|
|
int CreateIndexedSectorVertices(sector_t *sec, const secplane_t &plane, int floor, FIndexGenerationInfo &gen);
|
|
|
|
int CreateIndexedVertices(int h, sector_t *sec, const secplane_t &plane, int floor, TArray<FIndexGenerationInfo> &gen);
|
|
|
|
void CreateIndexedFlatVertices();
|
|
|
|
|
2018-05-22 16:48:10 +00:00
|
|
|
void UpdatePlaneVertices(sector_t *sec, int plane);
|
2018-04-14 10:04:37 +00:00
|
|
|
protected:
|
|
|
|
void CreateVertices();
|
2018-05-22 16:48:10 +00:00
|
|
|
void CheckPlanes(sector_t *sector);
|
|
|
|
public:
|
|
|
|
void CheckUpdate(sector_t *sector);
|
2018-10-30 18:28:47 +00:00
|
|
|
|
2018-04-14 10:04:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|