mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
- moved the remaining parts of the main vertex buffer to hwrenderer.
This commit is contained in:
parent
dad3c50ebd
commit
5a4e5a8038
10 changed files with 158 additions and 163 deletions
|
@ -116,70 +116,3 @@ void FSkyVertexBuffer::BindVBO()
|
|||
glDisableVertexAttribArray(VATTR_NORMAL);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FGLFlatVertexBuffer::FGLFlatVertexBuffer(int width, int height)
|
||||
: FFlatVertexBuffer(width, height)
|
||||
{
|
||||
mVertexBuffer = screen->CreateVertexBuffer();
|
||||
mIndexBuffer = screen->CreateIndexBuffer();
|
||||
|
||||
unsigned int bytesize = BUFFER_SIZE * sizeof(FFlatVertex);
|
||||
mVertexBuffer->SetData(bytesize, nullptr, false);
|
||||
|
||||
static const FVertexBufferAttribute format[] = {
|
||||
{ 0, VATTR_VERTEX, VFmt_Float3, myoffsetof(FFlatVertex, x) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, myoffsetof(FFlatVertex, u) }
|
||||
};
|
||||
mVertexBuffer->SetFormat(1, 2, sizeof(FFlatVertex), format);
|
||||
|
||||
mIndex = mCurIndex = 0;
|
||||
mNumReserved = NUM_RESERVED;
|
||||
Copy(0, NUM_RESERVED);
|
||||
}
|
||||
|
||||
FGLFlatVertexBuffer::~FGLFlatVertexBuffer()
|
||||
{
|
||||
delete mIndexBuffer;
|
||||
delete mVertexBuffer;
|
||||
mIndexBuffer = nullptr;
|
||||
mVertexBuffer = nullptr;
|
||||
}
|
||||
|
||||
void FGLFlatVertexBuffer::Copy(int start, int count)
|
||||
{
|
||||
Map();
|
||||
memcpy(GetBuffer(start), &vbo_shadowdata[0], count * sizeof(FFlatVertex));
|
||||
Unmap();
|
||||
}
|
||||
|
||||
void FGLFlatVertexBuffer::OutputResized(int width, int height)
|
||||
{
|
||||
FFlatVertexBuffer::OutputResized(width, height);
|
||||
Copy(4, 4);
|
||||
}
|
||||
|
||||
void FGLFlatVertexBuffer::Bind(FRenderState &state)
|
||||
{
|
||||
state.SetVertexBuffer(mVertexBuffer, 0, 0);
|
||||
state.SetIndexBuffer(mIndexBuffer);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FGLFlatVertexBuffer::CreateVBO()
|
||||
{
|
||||
vbo_shadowdata.Resize(mNumReserved);
|
||||
FFlatVertexBuffer::CreateVertices();
|
||||
mCurIndex = mIndex = vbo_shadowdata.Size();
|
||||
Copy(0, mIndex);
|
||||
mIndexBuffer->SetData(ibo_data.Size() * sizeof(uint32_t), &ibo_data[0]);
|
||||
}
|
||||
|
|
|
@ -86,79 +86,6 @@ public:
|
|||
void EnableColorArray(bool on);
|
||||
};
|
||||
|
||||
class FGLFlatVertexBuffer : public FFlatVertexBuffer
|
||||
{
|
||||
IVertexBuffer *mVertexBuffer;
|
||||
IIndexBuffer *mIndexBuffer;
|
||||
|
||||
unsigned int mIndex;
|
||||
std::atomic<unsigned int> mCurIndex;
|
||||
std::mutex mBufferMutex;
|
||||
unsigned int mNumReserved;
|
||||
|
||||
|
||||
static const unsigned int BUFFER_SIZE = 2000000;
|
||||
static const unsigned int BUFFER_SIZE_TO_USE = 1999500;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
FGLFlatVertexBuffer(int width, int height);
|
||||
~FGLFlatVertexBuffer();
|
||||
|
||||
void OutputResized(int width, int height);
|
||||
void Bind(FRenderState &state);
|
||||
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);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
FFlatVertex *Alloc(int num, T *poffset)
|
||||
{
|
||||
again:
|
||||
FFlatVertex *p = GetBuffer();
|
||||
auto index = mCurIndex.fetch_add(num);
|
||||
*poffset = static_cast<T>(index);
|
||||
if (index + num >= BUFFER_SIZE_TO_USE)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mBufferMutex);
|
||||
if (mCurIndex >= BUFFER_SIZE_TO_USE) // retest condition, in case another thread got here first
|
||||
mCurIndex = mIndex;
|
||||
|
||||
if (index >= BUFFER_SIZE_TO_USE) goto again;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
mCurIndex = mIndex;
|
||||
}
|
||||
|
||||
void Map()
|
||||
{
|
||||
mVertexBuffer->Map();
|
||||
mMap = GetBuffer(0);
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
mMap = nullptr;
|
||||
mVertexBuffer->Unmap();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FSkyVertexBuffer : public FVertexBuffer, public FSkyDomeCreator
|
||||
{
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ void FGLRenderer::RenderScreenQuad()
|
|||
{
|
||||
mVBO->Bind(gl_RenderState);
|
||||
gl_RenderState.ApplyBuffers();
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, FGLFlatVertexBuffer::PRESENT_INDEX, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, FFlatVertexBuffer::PRESENT_INDEX, 4);
|
||||
}
|
||||
|
||||
void FGLRenderer::PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D)
|
||||
|
|
|
@ -99,7 +99,7 @@ void FGLRenderer::Initialize(int width, int height)
|
|||
glBindVertexArray(mVAOID);
|
||||
FGLDebug::LabelObject(GL_VERTEX_ARRAY, mVAOID, "FGLRenderer.mVAOID");
|
||||
|
||||
mVBO = new FGLFlatVertexBuffer(width, height);
|
||||
mVBO = new FFlatVertexBuffer(width, height);
|
||||
mSkyVBO = new FSkyVertexBuffer;
|
||||
mLights = new FLightBuffer();
|
||||
mViewpoints = new GLViewpointBuffer;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
struct particle_t;
|
||||
class FCanvasTexture;
|
||||
class FGLFlatVertexBuffer;
|
||||
class FFlatVertexBuffer;
|
||||
class FSkyVertexBuffer;
|
||||
class OpenGLFrameBuffer;
|
||||
struct FDrawInfo;
|
||||
|
@ -69,7 +69,7 @@ public:
|
|||
|
||||
//FRotator mAngles;
|
||||
|
||||
FGLFlatVertexBuffer *mVBO = nullptr;
|
||||
FFlatVertexBuffer *mVBO = nullptr;
|
||||
FSkyVertexBuffer *mSkyVBO = nullptr;
|
||||
FLightBuffer *mLights = nullptr;
|
||||
GLViewpointBuffer *mViewpoints = nullptr;
|
||||
|
|
|
@ -319,7 +319,7 @@ void FDrawInfo::ClearScreen()
|
|||
glDisable(GL_MULTISAMPLE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, FGLFlatVertexBuffer::FULLSCREEN_INDEX, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, FFlatVertexBuffer::FULLSCREEN_INDEX, 4);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
if (multi) glEnable(GL_MULTISAMPLE);
|
||||
|
|
|
@ -28,15 +28,6 @@
|
|||
|
||||
extern bool gl_shaderactive;
|
||||
|
||||
enum
|
||||
{
|
||||
VATTR_VERTEX = 0,
|
||||
VATTR_TEXCOORD = 1,
|
||||
VATTR_COLOR = 2,
|
||||
VATTR_VERTEX2 = 3,
|
||||
VATTR_NORMAL = 4
|
||||
};
|
||||
|
||||
class FShaderCollection;
|
||||
struct HWViewpointUniforms;
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#include "c_cvars.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "flatvertices.h"
|
||||
#include "cmdlib.h"
|
||||
#include "hwrenderer/data/vertexbuffer.h"
|
||||
#include "hwrenderer/scene/hw_renderstate.h"
|
||||
|
||||
|
||||
//==========================================================================
|
||||
|
@ -71,14 +74,51 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height)
|
|||
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);
|
||||
|
||||
mVertexBuffer = screen->CreateVertexBuffer();
|
||||
mIndexBuffer = screen->CreateIndexBuffer();
|
||||
|
||||
unsigned int bytesize = BUFFER_SIZE * sizeof(FFlatVertex);
|
||||
mVertexBuffer->SetData(bytesize, nullptr, false);
|
||||
|
||||
static const FVertexBufferAttribute format[] = {
|
||||
{ 0, VATTR_VERTEX, VFmt_Float3, myoffsetof(FFlatVertex, x) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, myoffsetof(FFlatVertex, u) }
|
||||
};
|
||||
mVertexBuffer->SetFormat(1, 2, sizeof(FFlatVertex), format);
|
||||
|
||||
mIndex = mCurIndex = 0;
|
||||
mNumReserved = NUM_RESERVED;
|
||||
Copy(0, NUM_RESERVED);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FFlatVertexBuffer::~FFlatVertexBuffer()
|
||||
{
|
||||
delete mIndexBuffer;
|
||||
delete mVertexBuffer;
|
||||
mIndexBuffer = nullptr;
|
||||
mVertexBuffer = nullptr;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
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);
|
||||
Copy(4, 4);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -276,7 +316,7 @@ void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane)
|
|||
int countvt = sec->vbocount[plane];
|
||||
secplane_t &splane = sec->GetSecPlane(plane);
|
||||
FFlatVertex *vt = &vbo_shadowdata[startvt];
|
||||
FFlatVertex *mapvt = &mMap[startvt];
|
||||
FFlatVertex *mapvt = GetBuffer(startvt);
|
||||
for(int i=0; i<countvt; i++, vt++, mapvt++)
|
||||
{
|
||||
vt->z = (float)splane.ZatPoint(vt->x, vt->y);
|
||||
|
@ -332,3 +372,43 @@ void FFlatVertexBuffer::CheckUpdate(sector_t *sector)
|
|||
for (unsigned i = 0; i < sector->e->XFloor.ffloors.Size(); i++)
|
||||
CheckPlanes(sector->e->XFloor.ffloors[i]->model);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexBuffer::Copy(int start, int count)
|
||||
{
|
||||
Map();
|
||||
memcpy(GetBuffer(start), &vbo_shadowdata[0], count * sizeof(FFlatVertex));
|
||||
Unmap();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexBuffer::Bind(FRenderState &state)
|
||||
{
|
||||
state.SetVertexBuffer(mVertexBuffer, 0, 0);
|
||||
state.SetIndexBuffer(mIndexBuffer);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexBuffer::CreateVBO()
|
||||
{
|
||||
vbo_shadowdata.Resize(mNumReserved);
|
||||
FFlatVertexBuffer::CreateVertices();
|
||||
mCurIndex = mIndex = vbo_shadowdata.Size();
|
||||
Copy(0, mIndex);
|
||||
mIndexBuffer->SetData(ibo_data.Size() * sizeof(uint32_t), &ibo_data[0]);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,11 @@
|
|||
#define _HW__VERTEXBUFFER_H
|
||||
|
||||
#include "tarray.h"
|
||||
#include "hwrenderer/data/vertexbuffer.h"
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
class FRenderState;
|
||||
|
||||
struct FFlatVertex
|
||||
{
|
||||
|
@ -43,10 +48,21 @@ struct FFlatVertex
|
|||
|
||||
class FFlatVertexBuffer
|
||||
{
|
||||
protected:
|
||||
TArray<FFlatVertex> vbo_shadowdata;
|
||||
TArray<uint32_t> ibo_data;
|
||||
FFlatVertex *mMap;
|
||||
|
||||
IVertexBuffer *mVertexBuffer;
|
||||
IIndexBuffer *mIndexBuffer;
|
||||
|
||||
unsigned int mIndex;
|
||||
std::atomic<unsigned int> mCurIndex;
|
||||
std::mutex mBufferMutex;
|
||||
unsigned int mNumReserved;
|
||||
|
||||
|
||||
static const unsigned int BUFFER_SIZE = 2000000;
|
||||
static const unsigned int BUFFER_SIZE_TO_USE = 1999500;
|
||||
|
||||
|
||||
// Temporary data for creating an indexed buffer
|
||||
struct FIndexGenerationInfo
|
||||
|
@ -85,8 +101,56 @@ public:
|
|||
};
|
||||
|
||||
FFlatVertexBuffer(int width, int height);
|
||||
~FFlatVertexBuffer();
|
||||
|
||||
void OutputResized(int width, int height);
|
||||
void Bind(FRenderState &state);
|
||||
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);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
FFlatVertex *Alloc(int num, T *poffset)
|
||||
{
|
||||
again:
|
||||
FFlatVertex *p = GetBuffer();
|
||||
auto index = mCurIndex.fetch_add(num);
|
||||
*poffset = static_cast<T>(index);
|
||||
if (index + num >= BUFFER_SIZE_TO_USE)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mBufferMutex);
|
||||
if (mCurIndex >= BUFFER_SIZE_TO_USE) // retest condition, in case another thread got here first
|
||||
mCurIndex = mIndex;
|
||||
|
||||
if (index >= BUFFER_SIZE_TO_USE) goto again;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
mCurIndex = mIndex;
|
||||
}
|
||||
|
||||
void Map()
|
||||
{
|
||||
mVertexBuffer->Map();
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
mVertexBuffer->Unmap();
|
||||
}
|
||||
|
||||
private:
|
||||
int CreateIndexedSubsectorVertices(subsector_t *sub, const secplane_t &plane, int floor, int vi, FIndexGenerationInfo &gen);
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
// VAOs are mostly useless for this because they lump buffer and binding state together which the model code does not want.
|
||||
enum
|
||||
{
|
||||
VATTR_VERTEX_BIT,
|
||||
VATTR_TEXCOORD_BIT,
|
||||
VATTR_COLOR_BIT,
|
||||
VATTR_VERTEX2_BIT,
|
||||
VATTR_NORMAL_BIT,
|
||||
VATTR_NORMAL2_BIT,
|
||||
VATTR_VERTEX,
|
||||
VATTR_TEXCOORD,
|
||||
VATTR_COLOR,
|
||||
VATTR_VERTEX2,
|
||||
VATTR_NORMAL,
|
||||
VATTR_NORMAL2,
|
||||
|
||||
VATTR_MAX
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue