Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- create a renderer backend based on softpoly's drawers
- Loading branch information
Showing
21 changed files
with
1,317 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
|
||
#include "poly_buffers.h" | ||
#include "poly_framebuffer.h" | ||
#include "poly_renderstate.h" | ||
#include "doomerrors.h" | ||
|
||
PolyBuffer *PolyBuffer::First = nullptr; | ||
|
||
PolyBuffer::PolyBuffer() | ||
{ | ||
Next = First; | ||
First = this; | ||
if (Next) Next->Prev = this; | ||
} | ||
|
||
PolyBuffer::~PolyBuffer() | ||
{ | ||
if (Next) Next->Prev = Prev; | ||
if (Prev) Prev->Next = Next; | ||
else First = Next; | ||
} | ||
|
||
void PolyBuffer::ResetAll() | ||
{ | ||
for (PolyBuffer *cur = PolyBuffer::First; cur; cur = cur->Next) | ||
cur->Reset(); | ||
} | ||
|
||
void PolyBuffer::Reset() | ||
{ | ||
} | ||
|
||
void PolyBuffer::SetData(size_t size, const void *data, bool staticdata) | ||
{ | ||
mData.resize(size); | ||
map = mData.data(); | ||
if (data) | ||
memcpy(map, data, size); | ||
buffersize = size; | ||
} | ||
|
||
void PolyBuffer::SetSubData(size_t offset, size_t size, const void *data) | ||
{ | ||
memcpy(static_cast<uint8_t*>(map) + offset, data, size); | ||
} | ||
|
||
void PolyBuffer::Resize(size_t newsize) | ||
{ | ||
mData.resize(newsize); | ||
buffersize = newsize; | ||
map = mData.data(); | ||
} | ||
|
||
void PolyBuffer::Map() | ||
{ | ||
} | ||
|
||
void PolyBuffer::Unmap() | ||
{ | ||
} | ||
|
||
void *PolyBuffer::Lock(unsigned int size) | ||
{ | ||
return map; | ||
} | ||
|
||
void PolyBuffer::Unlock() | ||
{ | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
void PolyVertexBuffer::SetFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs) | ||
{ | ||
for (int j = 0; j < numAttributes; j++) | ||
{ | ||
mOffsets[attrs[j].location] = attrs[j].offset; | ||
} | ||
mStride = stride; | ||
} | ||
|
||
void PolyVertexBuffer::CopyVertices(TriVertex *dst, int count, int index) | ||
{ | ||
size_t stride = mStride; | ||
size_t offsetVertex = mOffsets[VATTR_VERTEX]; | ||
size_t offsetTexcoord = mOffsets[VATTR_TEXCOORD]; | ||
uint8_t *vertex = static_cast<uint8_t*>(map) + stride * index; | ||
|
||
for (int i = 0; i < count; i++) | ||
{ | ||
dst[i].x = *reinterpret_cast<float*>(vertex + offsetVertex); | ||
dst[i].y = *reinterpret_cast<float*>(vertex + offsetVertex + 4); | ||
dst[i].z = *reinterpret_cast<float*>(vertex + offsetVertex + 8); | ||
dst[i].w = 1.0f; | ||
dst[i].v = *reinterpret_cast<float*>(vertex + offsetTexcoord); | ||
dst[i].u = *reinterpret_cast<float*>(vertex + offsetTexcoord + 4); | ||
vertex += stride; | ||
} | ||
} | ||
|
||
void PolyVertexBuffer::CopyIndexed(TriVertex *dst, uint32_t *elements, int count, int index) | ||
{ | ||
size_t stride = mStride; | ||
size_t offsetVertex = mOffsets[VATTR_VERTEX]; | ||
size_t offsetTexcoord = mOffsets[VATTR_TEXCOORD]; | ||
uint8_t *vertices = static_cast<uint8_t*>(map); | ||
|
||
elements += index; | ||
for (int i = 0; i < count; i++) | ||
{ | ||
uint8_t *vertex = vertices + stride * elements[i]; | ||
dst[i].x = *reinterpret_cast<float*>(vertex + offsetVertex); | ||
dst[i].y = *reinterpret_cast<float*>(vertex + offsetVertex + 4); | ||
dst[i].z = *reinterpret_cast<float*>(vertex + offsetVertex + 8); | ||
dst[i].w = 1.0f; | ||
dst[i].v = *reinterpret_cast<float*>(vertex + offsetTexcoord); | ||
dst[i].u = *reinterpret_cast<float*>(vertex + offsetTexcoord + 4); | ||
} | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
void PolyDataBuffer::BindRange(size_t start, size_t length) | ||
{ | ||
GetPolyFrameBuffer()->GetRenderState()->Bind(this, (uint32_t)start, (uint32_t)length); | ||
} | ||
|
||
void PolyDataBuffer::BindBase() | ||
{ | ||
GetPolyFrameBuffer()->GetRenderState()->Bind(this, 0, (uint32_t)buffersize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#pragma once | ||
|
||
#include "hwrenderer/data/buffers.h" | ||
#include "utility/tarray.h" | ||
#include <vector> | ||
|
||
#ifdef _MSC_VER | ||
// silence bogus warning C4250: 'PolyVertexBuffer': inherits 'PolyBuffer::PolyBuffer::SetData' via dominance | ||
// According to internet infos, the warning is erroneously emitted in this case. | ||
#pragma warning(disable:4250) | ||
#endif | ||
|
||
struct TriVertex; | ||
|
||
class PolyBuffer : virtual public IBuffer | ||
{ | ||
public: | ||
PolyBuffer(); | ||
~PolyBuffer(); | ||
|
||
static void ResetAll(); | ||
void Reset(); | ||
|
||
void SetData(size_t size, const void *data, bool staticdata) override; | ||
void SetSubData(size_t offset, size_t size, const void *data) override; | ||
void Resize(size_t newsize) override; | ||
|
||
void Map() override; | ||
void Unmap() override; | ||
|
||
void *Lock(unsigned int size) override; | ||
void Unlock() override; | ||
|
||
private: | ||
static PolyBuffer *First; | ||
PolyBuffer *Prev = nullptr; | ||
PolyBuffer *Next = nullptr; | ||
std::vector<uint32_t> mData; | ||
}; | ||
|
||
class PolyVertexBuffer : public IVertexBuffer, public PolyBuffer | ||
{ | ||
public: | ||
PolyVertexBuffer() { } | ||
void SetFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs) override; | ||
|
||
void CopyVertices(TriVertex *dst, int count, int index); | ||
void CopyIndexed(TriVertex *dst, uint32_t *elements, int count, int index); | ||
|
||
private: | ||
size_t mOffsets[VATTR_MAX] = {}; | ||
size_t mStride = 0; | ||
}; | ||
|
||
class PolyIndexBuffer : public IIndexBuffer, public PolyBuffer | ||
{ | ||
public: | ||
PolyIndexBuffer() { } | ||
}; | ||
|
||
class PolyDataBuffer : public IDataBuffer, public PolyBuffer | ||
{ | ||
public: | ||
PolyDataBuffer(int bindingpoint, bool ssbo, bool needresize) : bindingpoint(bindingpoint) | ||
{ | ||
} | ||
|
||
void BindRange(size_t start, size_t length) override; | ||
void BindBase() override; | ||
|
||
int bindingpoint; | ||
}; |
Oops, something went wrong.