Skip to content

Commit

Permalink
- create a renderer backend based on softpoly's drawers
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed May 22, 2019
1 parent 8a90946 commit 0eda298
Show file tree
Hide file tree
Showing 21 changed files with 1,317 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -510,7 +510,8 @@ set( PLAT_WIN32_SOURCES
win32/gl_sysfb.cpp
win32/base_sysfb.cpp
win32/win32basevideo.cpp
win32/win32glvideo.cpp)
win32/win32glvideo.cpp
win32/win32polyvideo.cpp)

if (HAVE_VULKAN)
set (PLAT_WIN32_SOURCES ${PLAT_WIN32_SOURCES} win32/win32vulkanvideo.cpp )
Expand Down Expand Up @@ -713,6 +714,7 @@ file( GLOB HEADER_FILES
rendering/polyrenderer/math/*.h
rendering/polyrenderer/drawers/*.h
rendering/polyrenderer/scene/*.h
rendering/polyrenderer/backend/*.h
rendering/hwrenderer/data/*.h
rendering/hwrenderer/dynlights/*.h
rendering/hwrenderer/models/*.h
Expand Down Expand Up @@ -927,6 +929,14 @@ if (HAVE_VULKAN)
set (FASTMATH_SOURCES ${FASTMATH_SOURCES} ${VULKAN_SOURCES})
endif()

set (POLYBACKEND_SOURCES
rendering/polyrenderer/backend/poly_framebuffer.cpp
rendering/polyrenderer/backend/poly_buffers.cpp
rendering/polyrenderer/backend/poly_hwtexture.cpp
rendering/polyrenderer/backend/poly_renderstate.cpp
)
set (FASTMATH_SOURCES ${FASTMATH_SOURCES} ${POLYBACKEND_SOURCES})

set (PCH_SOURCES
am_map.cpp
b_bot.cpp
Expand Down Expand Up @@ -1555,6 +1565,7 @@ source_group("Rendering\\Poly Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOU
source_group("Rendering\\Poly Renderer\\Math" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/math/.+")
source_group("Rendering\\Poly Renderer\\Drawers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/drawers/.+")
source_group("Rendering\\Poly Renderer\\Scene" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/scene/.+")
source_group("Rendering\\Poly Renderer\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/backend/.+")
source_group("Render Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r_data/.+")
source_group("Render Data\\Models" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r_data/models/.+")
source_group("Render Interface" FILES r_defs.h r_renderer.h r_sky.cpp r_sky.h r_state.h r_utility.cpp r_utility.h)
Expand Down
2 changes: 2 additions & 0 deletions src/gamedata/textures/textures.h
Expand Up @@ -294,9 +294,11 @@ class FTexture
friend class FMaterial;
friend class OpenGLRenderer::FGLRenderState; // For now this needs access to some fields in ApplyMaterial. This should be rerouted through the Material class
friend class VkRenderState;
friend class PolyRenderState;
friend struct FTexCoordInfo;
friend class OpenGLRenderer::FHardwareTexture;
friend class VkHardwareTexture;
friend class PolyHardwareTexture;
friend class FMultiPatchTexture;
friend class FSkyBox;
friend class FBrightmapTexture;
Expand Down
131 changes: 131 additions & 0 deletions src/rendering/polyrenderer/backend/poly_buffers.cpp
@@ -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);
}
72 changes: 72 additions & 0 deletions src/rendering/polyrenderer/backend/poly_buffers.h
@@ -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;
};

0 comments on commit 0eda298

Please sign in to comment.