Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/renderer/backend/gl/DeviceCommandContext.cpp
Show First 20 Lines • Show All 828 Lines • ▼ Show 20 Lines | |||||
void CDeviceCommandContext::SetViewports(const uint32_t viewportCount, const Rect* viewports) | void CDeviceCommandContext::SetViewports(const uint32_t viewportCount, const Rect* viewports) | ||||
{ | { | ||||
ENSURE(viewportCount == 1); | ENSURE(viewportCount == 1); | ||||
glViewport(viewports[0].x, viewports[0].y, viewports[0].width, viewports[0].height); | glViewport(viewports[0].x, viewports[0].y, viewports[0].width, viewports[0].height); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
} | } | ||||
void CDeviceCommandContext::SetVertexAttributeFormat( | void CDeviceCommandContext::SetVertexAttributeFormat( | ||||
const VertexAttributeStream stream, | const VertexAttributeStream stream, | ||||
const Format format, | const Format format, | ||||
const uint32_t offset, | const uint32_t offset, | ||||
const uint32_t stride, | const uint32_t stride, | ||||
const VertexAttributeRate rate, | |||||
const uint32_t bindingSlot) | const uint32_t bindingSlot) | ||||
{ | { | ||||
const uint32_t index = static_cast<uint32_t>(stream); | const uint32_t index = static_cast<uint32_t>(stream); | ||||
ENSURE(index < m_VertexAttributeFormat.size()); | ENSURE(index < m_VertexAttributeFormat.size()); | ||||
ENSURE(bindingSlot < m_VertexAttributeFormat.size()); | ENSURE(bindingSlot < m_VertexAttributeFormat.size()); | ||||
if (!m_VertexAttributeFormat[index].active) | if (!m_VertexAttributeFormat[index].active) | ||||
return; | return; | ||||
m_VertexAttributeFormat[index].format = format; | m_VertexAttributeFormat[index].format = format; | ||||
m_VertexAttributeFormat[index].offset = offset; | m_VertexAttributeFormat[index].offset = offset; | ||||
m_VertexAttributeFormat[index].stride = stride; | m_VertexAttributeFormat[index].stride = stride; | ||||
m_VertexAttributeFormat[index].rate = rate; | |||||
m_VertexAttributeFormat[index].bindingSlot = bindingSlot; | m_VertexAttributeFormat[index].bindingSlot = bindingSlot; | ||||
m_VertexAttributeFormat[index].initialized = true; | m_VertexAttributeFormat[index].initialized = true; | ||||
} | } | ||||
void CDeviceCommandContext::SetVertexBuffer( | void CDeviceCommandContext::SetVertexBuffer( | ||||
const uint32_t bindingSlot, IBuffer* buffer) | const uint32_t bindingSlot, IBuffer* buffer) | ||||
{ | { | ||||
ENSURE(buffer); | ENSURE(buffer); | ||||
ENSURE(buffer->GetType() == IBuffer::Type::VERTEX); | ENSURE(buffer->GetType() == IBuffer::Type::VERTEX); | ||||
ENSURE(m_ShaderProgram); | ENSURE(m_ShaderProgram); | ||||
BindBuffer(buffer->GetType(), buffer->As<CBuffer>()); | BindBuffer(buffer->GetType(), buffer->As<CBuffer>()); | ||||
for (size_t index = 0; index < m_VertexAttributeFormat.size(); ++index) | for (size_t index = 0; index < m_VertexAttributeFormat.size(); ++index) | ||||
{ | { | ||||
if (!m_VertexAttributeFormat[index].active || m_VertexAttributeFormat[index].bindingSlot != bindingSlot) | if (!m_VertexAttributeFormat[index].active || m_VertexAttributeFormat[index].bindingSlot != bindingSlot) | ||||
continue; | continue; | ||||
ENSURE(m_VertexAttributeFormat[index].initialized); | ENSURE(m_VertexAttributeFormat[index].initialized); | ||||
const VertexAttributeStream stream = static_cast<VertexAttributeStream>(index); | const VertexAttributeStream stream = static_cast<VertexAttributeStream>(index); | ||||
m_ShaderProgram->VertexAttribPointer(stream, | m_ShaderProgram->VertexAttribPointer(stream, | ||||
m_VertexAttributeFormat[index].format, | m_VertexAttributeFormat[index].format, | ||||
m_VertexAttributeFormat[index].offset, | m_VertexAttributeFormat[index].offset, | ||||
m_VertexAttributeFormat[index].stride, | m_VertexAttributeFormat[index].stride, | ||||
m_VertexAttributeFormat[index].rate, | |||||
nullptr); | nullptr); | ||||
} | } | ||||
} | } | ||||
void CDeviceCommandContext::SetVertexBufferData( | void CDeviceCommandContext::SetVertexBufferData( | ||||
const uint32_t bindingSlot, const void* data) | const uint32_t bindingSlot, const void* data, const uint32_t dataSize) | ||||
{ | { | ||||
ENSURE(data); | ENSURE(data); | ||||
ENSURE(m_ShaderProgram); | ENSURE(m_ShaderProgram); | ||||
ENSURE(dataSize > 0); | |||||
BindBuffer(CBuffer::Type::VERTEX, nullptr); | BindBuffer(CBuffer::Type::VERTEX, nullptr); | ||||
for (size_t index = 0; index < m_VertexAttributeFormat.size(); ++index) | for (size_t index = 0; index < m_VertexAttributeFormat.size(); ++index) | ||||
{ | { | ||||
if (!m_VertexAttributeFormat[index].active || m_VertexAttributeFormat[index].bindingSlot != bindingSlot) | if (!m_VertexAttributeFormat[index].active || m_VertexAttributeFormat[index].bindingSlot != bindingSlot) | ||||
continue; | continue; | ||||
ENSURE(m_VertexAttributeFormat[index].initialized); | ENSURE(m_VertexAttributeFormat[index].initialized); | ||||
const VertexAttributeStream stream = static_cast<VertexAttributeStream>(index); | const VertexAttributeStream stream = static_cast<VertexAttributeStream>(index); | ||||
// We don't know how many vertices will be used in a draw command, so we | |||||
// assume at least one vertex. | |||||
ENSURE(dataSize >= m_VertexAttributeFormat[index].offset + m_VertexAttributeFormat[index].stride); | |||||
m_ShaderProgram->VertexAttribPointer(stream, | m_ShaderProgram->VertexAttribPointer(stream, | ||||
m_VertexAttributeFormat[index].format, | m_VertexAttributeFormat[index].format, | ||||
m_VertexAttributeFormat[index].offset, | m_VertexAttributeFormat[index].offset, | ||||
m_VertexAttributeFormat[index].stride, | m_VertexAttributeFormat[index].stride, | ||||
m_VertexAttributeFormat[index].rate, | |||||
data); | data); | ||||
} | } | ||||
} | } | ||||
void CDeviceCommandContext::SetIndexBuffer(IBuffer* buffer) | void CDeviceCommandContext::SetIndexBuffer(IBuffer* buffer) | ||||
{ | { | ||||
ENSURE(buffer->GetType() == CBuffer::Type::INDEX); | ENSURE(buffer->GetType() == CBuffer::Type::INDEX); | ||||
m_IndexBuffer = buffer->As<CBuffer>(); | m_IndexBuffer = buffer->As<CBuffer>(); | ||||
m_IndexBufferData = nullptr; | m_IndexBufferData = nullptr; | ||||
BindBuffer(CBuffer::Type::INDEX, m_IndexBuffer); | BindBuffer(CBuffer::Type::INDEX, m_IndexBuffer); | ||||
} | } | ||||
void CDeviceCommandContext::SetIndexBufferData(const void* data) | void CDeviceCommandContext::SetIndexBufferData(const void* data, const uint32_t dataSize) | ||||
{ | { | ||||
ENSURE(dataSize > 0); | |||||
if (m_IndexBuffer) | if (m_IndexBuffer) | ||||
{ | { | ||||
BindBuffer(CBuffer::Type::INDEX, nullptr); | BindBuffer(CBuffer::Type::INDEX, nullptr); | ||||
m_IndexBuffer = nullptr; | m_IndexBuffer = nullptr; | ||||
} | } | ||||
m_IndexBufferData = data; | m_IndexBufferData = data; | ||||
} | } | ||||
Show All 40 Lines | void CDeviceCommandContext::DrawIndexed( | ||||
// Don't use glMultiDrawElements here since it doesn't have a significant | // Don't use glMultiDrawElements here since it doesn't have a significant | ||||
// performance impact and it suffers from various driver bugs (e.g. it breaks | // performance impact and it suffers from various driver bugs (e.g. it breaks | ||||
// in Mesa 7.10 swrast with index VBOs). | // in Mesa 7.10 swrast with index VBOs). | ||||
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, | glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, | ||||
static_cast<const void*>((static_cast<const uint8_t*>(m_IndexBufferData) + sizeof(uint16_t) * firstIndex))); | static_cast<const void*>((static_cast<const uint8_t*>(m_IndexBufferData) + sizeof(uint16_t) * firstIndex))); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
} | } | ||||
void CDeviceCommandContext::DrawInstanced( | |||||
const uint32_t firstVertex, const uint32_t vertexCount, | |||||
const uint32_t firstInstance, const uint32_t instanceCount) | |||||
{ | |||||
ENSURE(m_Device->GetCapabilities().instancing); | |||||
ENSURE(m_ShaderProgram); | |||||
ENSURE(m_InsidePass); | |||||
if (vertexCount == 0 || instanceCount == 0) | |||||
return; | |||||
ENSURE(firstInstance == 0); | |||||
m_ShaderProgram->AssertPointersBound(); | |||||
glDrawArraysInstancedARB(GL_TRIANGLES, firstVertex, vertexCount, instanceCount); | |||||
ogl_WarnIfError(); | |||||
} | |||||
void CDeviceCommandContext::DrawIndexedInstanced( | |||||
const uint32_t firstIndex, const uint32_t indexCount, | |||||
const uint32_t firstInstance, const uint32_t instanceCount, | |||||
const int32_t vertexOffset) | |||||
{ | |||||
ENSURE(m_Device->GetCapabilities().instancing); | |||||
ENSURE(m_ShaderProgram); | |||||
ENSURE(m_InsidePass); | |||||
ENSURE(m_IndexBuffer || m_IndexBufferData); | |||||
if (indexCount == 0) | |||||
return; | |||||
ENSURE(firstInstance == 0 && vertexOffset == 0); | |||||
if (m_IndexBuffer) | |||||
{ | |||||
ENSURE(sizeof(uint16_t) * (firstIndex + indexCount) <= m_IndexBuffer->GetSize()); | |||||
} | |||||
m_ShaderProgram->AssertPointersBound(); | |||||
// Don't use glMultiDrawElements here since it doesn't have a significant | |||||
// performance impact and it suffers from various driver bugs (e.g. it breaks | |||||
// in Mesa 7.10 swrast with index VBOs). | |||||
glDrawElementsInstancedARB(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, | |||||
static_cast<const void*>((static_cast<const uint8_t*>(m_IndexBufferData) + sizeof(uint16_t) * firstIndex)), | |||||
instanceCount); | |||||
ogl_WarnIfError(); | |||||
} | |||||
void CDeviceCommandContext::DrawIndexedInRange( | void CDeviceCommandContext::DrawIndexedInRange( | ||||
const uint32_t firstIndex, const uint32_t indexCount, | const uint32_t firstIndex, const uint32_t indexCount, | ||||
const uint32_t start, const uint32_t end) | const uint32_t start, const uint32_t end) | ||||
{ | { | ||||
ENSURE(m_ShaderProgram); | ENSURE(m_ShaderProgram); | ||||
ENSURE(m_InsidePass); | ENSURE(m_InsidePass); | ||||
if (indexCount == 0) | if (indexCount == 0) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator