- clean separation of vertex creation from map data and the buffer object.
This was yet another object with too broad scope, the vertex creation has been offloaded into out-of-class functions now.
This commit is contained in:
parent
cf41a0b1fb
commit
c5dca89e66
9 changed files with 279 additions and 294 deletions
110
src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp
Normal file
110
src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright(C) 2018 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/
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
/*
|
||||
** gl_viewpointbuffer.cpp
|
||||
** Buffer data maintenance for per viewpoint uniform data
|
||||
**
|
||||
**/
|
||||
|
||||
#include "hwrenderer/data/shaderuniforms.h"
|
||||
#include "hwrenderer/scene/hw_viewpointuniforms.h"
|
||||
#include "hw_renderstate.h"
|
||||
#include "hw_viewpointbuffer.h"
|
||||
|
||||
static const int INITIAL_BUFFER_SIZE = 100; // 100 viewpoints per frame should nearly always be enough
|
||||
|
||||
HWViewpointBuffer::HWViewpointBuffer()
|
||||
{
|
||||
mBufferSize = INITIAL_BUFFER_SIZE;
|
||||
mBlockAlign = ((sizeof(HWViewpointUniforms) / screen->uniformblockalignment) + 1) * screen->uniformblockalignment;
|
||||
mByteSize = mBufferSize * mBlockAlign;
|
||||
mBuffer = screen->CreateDataBuffer(VIEWPOINT_BINDINGPOINT, false, true);
|
||||
mBuffer->SetData(mByteSize, nullptr, false);
|
||||
Clear();
|
||||
mLastMappedIndex = UINT_MAX;
|
||||
mClipPlaneInfo.Push(0);
|
||||
}
|
||||
|
||||
HWViewpointBuffer::~HWViewpointBuffer()
|
||||
{
|
||||
delete mBuffer;
|
||||
}
|
||||
|
||||
|
||||
void HWViewpointBuffer::CheckSize()
|
||||
{
|
||||
if (mUploadIndex >= mBufferSize)
|
||||
{
|
||||
mBufferSize *= 2;
|
||||
mByteSize *= 2;
|
||||
mBuffer->Resize(mByteSize);
|
||||
m2DHeight = m2DWidth = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int HWViewpointBuffer::Bind(FRenderState &di, unsigned int index)
|
||||
{
|
||||
if (index != mLastMappedIndex)
|
||||
{
|
||||
mLastMappedIndex = index;
|
||||
mBuffer->BindRange(&di, index * mBlockAlign, mBlockAlign);
|
||||
di.EnableClipDistance(0, mClipPlaneInfo[index]);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
void HWViewpointBuffer::Set2D(FRenderState &di, int width, int height)
|
||||
{
|
||||
if (width != m2DWidth || height != m2DHeight)
|
||||
{
|
||||
HWViewpointUniforms matrices;
|
||||
matrices.SetDefaults(nullptr);
|
||||
matrices.mProjectionMatrix.ortho(0, (float)width, (float)height, 0, -1.0f, 1.0f);
|
||||
matrices.CalcDependencies();
|
||||
mBuffer->Map();
|
||||
memcpy(mBuffer->Memory(), &matrices, sizeof(matrices));
|
||||
mBuffer->Unmap();
|
||||
m2DWidth = width;
|
||||
m2DHeight = height;
|
||||
mLastMappedIndex = -1;
|
||||
}
|
||||
Bind(di, 0);
|
||||
}
|
||||
|
||||
int HWViewpointBuffer::SetViewpoint(FRenderState &di, HWViewpointUniforms *vp)
|
||||
{
|
||||
CheckSize();
|
||||
mBuffer->Map();
|
||||
memcpy(((char*)mBuffer->Memory()) + mUploadIndex * mBlockAlign, vp, sizeof(*vp));
|
||||
mBuffer->Unmap();
|
||||
|
||||
mClipPlaneInfo.Push(vp->mClipHeightDirection != 0.f || vp->mClipLine.X > -10000000.0f);
|
||||
return Bind(di, mUploadIndex++);
|
||||
}
|
||||
|
||||
void HWViewpointBuffer::Clear()
|
||||
{
|
||||
// Index 0 is reserved for the 2D projection.
|
||||
mUploadIndex = 1;
|
||||
mClipPlaneInfo.Resize(1);
|
||||
}
|
||||
|
||||
35
src/common/rendering/hwrenderer/data/hw_viewpointbuffer.h
Normal file
35
src/common/rendering/hwrenderer/data/hw_viewpointbuffer.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
#include "tarray.h"
|
||||
#include "hwrenderer/data/buffers.h"
|
||||
|
||||
struct HWViewpointUniforms;
|
||||
class FRenderState;
|
||||
|
||||
class HWViewpointBuffer
|
||||
{
|
||||
IDataBuffer *mBuffer;
|
||||
|
||||
unsigned int mBufferSize;
|
||||
unsigned int mBlockAlign;
|
||||
unsigned int mUploadIndex;
|
||||
unsigned int mLastMappedIndex;
|
||||
unsigned int mByteSize;
|
||||
TArray<bool> mClipPlaneInfo;
|
||||
|
||||
int m2DWidth = -1, m2DHeight = -1;
|
||||
|
||||
unsigned int mBlockSize;
|
||||
|
||||
void CheckSize();
|
||||
|
||||
public:
|
||||
|
||||
HWViewpointBuffer();
|
||||
~HWViewpointBuffer();
|
||||
void Clear();
|
||||
int Bind(FRenderState &di, unsigned int index);
|
||||
void Set2D(FRenderState &di, int width, int height);
|
||||
int SetViewpoint(FRenderState &di, HWViewpointUniforms *vp);
|
||||
unsigned int GetBlockSize() const { return mBlockSize; }
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue