Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<Filter>Header Files\Platform\OGL</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\renderer\hal\ogl\AlphaStateOGL.hpp">
<Filter>Header Files</Filter>
<Filter>Header Files\HAL\OGL</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
Expand Down
70 changes: 57 additions & 13 deletions source/renderer/hal/base/BufferBase.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include <utility>
#include <assert.h>
#include <cstring>
#include "BufferBase.hpp"
#include "compat/LegacyCPP.hpp"
#include "renderer/hal/interface/RenderContext.hpp"

using namespace mce;

BufferBase::BufferBase()
{
m_clientData = nullptr;
m_internalSize = 0;
m_bufferOffset = 0;

Expand All @@ -19,31 +23,70 @@ BufferBase::~BufferBase()

void BufferBase::_init(BufferBase& other)
{
// this might not be the right order to call this in, but this function is never called anyways
_move(other);
releaseBuffer();
}

void BufferBase::_move(BufferBase& other)
{
unsigned int stride = m_stride;
this->m_stride = other.m_stride;
other.m_stride = stride;
std::swap(this->m_clientData, other.m_clientData);
std::swap(this->m_bufferType, other.m_bufferType);
std::swap(this->m_stride, other.m_stride);
std::swap(this->m_count, other.m_count);
std::swap(this->m_internalSize, other.m_internalSize);
std::swap(this->m_bufferOffset, other.m_bufferOffset);
}

BufferType bufferType = m_bufferType;
this->m_bufferType = other.m_bufferType;
other.m_bufferType = bufferType;

unsigned int internalSize = m_internalSize;
this->m_internalSize = other.m_internalSize;
other.m_internalSize = internalSize;
void BufferBase::_createClientBuffer(RenderContext& context, const void* data, BufferType bufferType)
{
assert(m_clientData == nullptr);
m_clientData = new int8_t[m_internalSize];
if (data)
memcpy(m_clientData, data, m_internalSize);

unsigned int count = m_count;
this->m_count = other.m_count;
other.m_count = count;
_bindClientBuffer(context);
}

void BufferBase::_bindClientBuffer(RenderContext& context)
{
void*& activeBuffer = context.getActiveClientBuffer(m_bufferType);
if (activeBuffer == m_clientData)
return;

activeBuffer = m_clientData;
}

void BufferBase::_resizeClientBuffer(RenderContext& context, const void* data, unsigned int size)
{
if (m_clientData)
delete[] m_clientData;

int8_t* newBuffer = new int8_t[size];
memcpy(newBuffer, data, size);

m_clientData = newBuffer;
m_internalSize = size;
}

void BufferBase::_updateClientBuffer(RenderContext& context, unsigned int stride, void*& data, unsigned int count)
{
const unsigned int size = count * stride;

if (size <= m_internalSize)
memcpy(m_clientData, (int8_t*)data + m_bufferOffset, size);
else
_resizeClientBuffer(context, data, size);
}

void BufferBase::releaseBuffer()
{
if (m_clientData)
{
delete[] m_clientData;
m_clientData = nullptr;
}

m_stride = 0;
m_bufferType = BUFFER_TYPE_NONE;
m_count = 0;
Expand All @@ -70,6 +113,7 @@ void BufferBase::updateBuffer(RenderContext& context, unsigned int stride, void*

void BufferBase::copy(BufferBase& other)
{
// make sure this works, this function is never called
other.m_bufferType = this->m_bufferType;
other.m_stride = this->m_stride;
other.m_count = this->m_count;
Expand Down
8 changes: 8 additions & 0 deletions source/renderer/hal/base/BufferBase.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <stdint.h>

#include "compat/LegacyCPP.hpp"
#include "renderer/hal/enums/BufferType.hpp"

Expand All @@ -9,6 +11,7 @@ namespace mce
class BufferBase
{
public:
int8_t* m_clientData;
BufferType m_bufferType;
unsigned int m_stride;
unsigned int m_count;
Expand All @@ -18,6 +21,11 @@ namespace mce
protected:
void _init(BufferBase& other);
void _move(BufferBase& other);
void _createClientBuffer(RenderContext& context, const void* data, BufferType bufferType);
void _bindClientBuffer(RenderContext& context);
void _resizeClientBuffer(RenderContext& context, const void* data, unsigned int size);
void _updateClientBuffer(RenderContext& context, unsigned int stride, void*& data, unsigned int count);
bool _isClientBuffer() const { return m_clientData != nullptr; }

public:
BufferBase();
Expand Down
126 changes: 21 additions & 105 deletions source/renderer/hal/base/RenderContextBase.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
#include <cstring>
#include "RenderContextBase.hpp"

using namespace mce;

RenderContextBase::RenderContextBase()
{
m_pRenderDevice = nullptr;
_clearArrays();
}

void RenderContextBase::loadMatrix(MatrixType matrixType, const Matrix& matrix)
{
}

void RenderContextBase::setVertexState(const VertexFormat& vertexFormat)
{
m_lastVertexFormat = vertexFormat;
}

void RenderContextBase::clearVertexState(const VertexFormat& vertexFormat)
{
}

void RenderContextBase::enableFixedLighting(bool init)
{
}

void RenderContextBase::disableFixedLighting(bool teardown)
void RenderContextBase::_clearArrays()
{
memset(m_lastShaderPrograms, 0, sizeof(ShaderProgram*) * SHADER_TYPES_COUNT);
memset(m_activeClientBuffers, 0, sizeof(void*) * BUFFER_TYPES_COUNT);
}

bool RenderContextBase::setShadeMode(ShadeMode mode)
Expand All @@ -34,6 +21,7 @@ bool RenderContextBase::setShadeMode(ShadeMode mode)
return false;

m_currentState.m_shadeMode = mode;
m_currentState.m_bBoundShadeMode = true;

return true;
}
Expand All @@ -44,6 +32,7 @@ bool RenderContextBase::setCurrentColor(const Color& color)
return false;

m_currentState.m_color = color;
m_currentState.m_bBoundColor = true;

return true;
}
Expand All @@ -54,113 +43,40 @@ bool RenderContextBase::setGamma(Gamma gamma)
return false;

m_currentState.m_gamma = gamma;
m_currentState.m_bBoundGamma = true;

return true;
}

void RenderContextBase::draw(PrimitiveMode primitiveMode, unsigned int startOffset, unsigned int count)
{
}

void RenderContextBase::drawIndexed(PrimitiveMode primitiveMode, unsigned int count, uint8_t indexSize)
{
}

void RenderContextBase::drawIndexed(PrimitiveMode primitiveMode, unsigned int count, unsigned int startOffset, uint8_t indexSize)
{
}

void RenderContextBase::setDepthRange(float nearVal, float farVal)
{
}

void RenderContextBase::setViewport(unsigned int width, unsigned int height, float nearVal, float farVal, const ViewportOrigin& origin)
{
}

void RenderContextBase::clearFrameBuffer(const Color& color)
{
}

void RenderContextBase::clearStencilBuffer()
{
}

void RenderContextBase::clearDepthStencilBuffer()
{
}

void RenderContextBase::clearContextState()
{
m_currentState.clear();
m_immediateBuffer = ImmediateBuffer();

for (int i = 0; i < SHADER_TYPES_COUNT; i++)
{
m_lastShaderPrograms[i] = nullptr;
}
}

void RenderContextBase::setRenderTarget()
{
}

void RenderContextBase::beginRender()
{
}

void RenderContextBase::endRender()
{
}

void RenderContextBase::suspend()
{
}

void RenderContextBase::resume()
{
}

void RenderContextBase::swapBuffers()
{
_clearArrays();
}

void RenderContextBase::lostContext()
{
clearContextState();
}

RenderDevice* RenderContextBase::getDevice()
void*& RenderContextBase::getActiveClientBuffer(BufferType bufferType)
{
return m_pRenderDevice;
}
#ifdef _DEBUG
if (bufferType < BUFFER_TYPES_MIN || bufferType > BUFFER_TYPES_MAX)
throw std::out_of_range("m_activeClientBuffers[]");
#endif

void RenderContextBase::setStencilReference(uint8_t value)
{
m_stencilReference = value;
return m_activeClientBuffers[bufferType];
}

uint8_t RenderContextBase::getStencilReference() const
const void* RenderContextBase::getActiveClientBuffer(BufferType bufferType) const
{
return m_stencilReference;
}
#ifdef _DEBUG
if (bufferType < BUFFER_TYPES_MIN || bufferType > BUFFER_TYPES_MAX)
throw std::out_of_range("m_activeClientBuffers[]");
#endif

int RenderContextBase::getMaxVertexCount() const
{
return -1;
}

bool RenderContextBase::supports8BitIndices() const
{
return true;
}

bool RenderContextBase::supports32BitIndices() const
{
return true;
}

bool RenderContextBase::supports16BitUnsignedUVs() const
{
return true;
return m_activeClientBuffers[bufferType];
}
Loading
Loading