|
|
|
|
@@ -58,11 +58,35 @@ bool GetOpenGLVertexAttribFormat(Format format, OpenGLVertexAttribFormat& attrib
|
|
|
|
|
case Format::R32G32B32A32_UInt:
|
|
|
|
|
attributeFormat = { 4, GL_UNSIGNED_INT, GL_FALSE, true };
|
|
|
|
|
return true;
|
|
|
|
|
case Format::R16_UInt:
|
|
|
|
|
attributeFormat = { 1, GL_UNSIGNED_SHORT, GL_FALSE, true };
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GLenum ResolveOpenGLIndexType(Format format) {
|
|
|
|
|
switch (format) {
|
|
|
|
|
case Format::R16_UInt:
|
|
|
|
|
return GL_UNSIGNED_SHORT;
|
|
|
|
|
case Format::R32_UInt:
|
|
|
|
|
case Format::Unknown:
|
|
|
|
|
default:
|
|
|
|
|
return GL_UNSIGNED_INT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t GetIndexTypeSize(GLenum indexType) {
|
|
|
|
|
switch (indexType) {
|
|
|
|
|
case GL_UNSIGNED_SHORT:
|
|
|
|
|
return sizeof(GLushort);
|
|
|
|
|
case GL_UNSIGNED_INT:
|
|
|
|
|
default:
|
|
|
|
|
return sizeof(GLuint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
OpenGLCommandList::OpenGLCommandList()
|
|
|
|
|
@@ -70,6 +94,8 @@ OpenGLCommandList::OpenGLCommandList()
|
|
|
|
|
, m_currentVAO(0)
|
|
|
|
|
, m_currentProgram(0)
|
|
|
|
|
, m_internalVAO(0)
|
|
|
|
|
, m_currentIndexType(GL_UNSIGNED_INT)
|
|
|
|
|
, m_currentIndexOffset(0)
|
|
|
|
|
, m_currentPipelineState(nullptr)
|
|
|
|
|
, m_currentShader(nullptr)
|
|
|
|
|
, m_composedFramebuffer(nullptr) {
|
|
|
|
|
@@ -120,12 +146,13 @@ void OpenGLCommandList::SetVertexBuffers(unsigned int startSlot, unsigned int co
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::SetIndexBuffer(unsigned int buffer, unsigned int type) {
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
|
|
|
|
|
SetIndexBuffer(buffer, type, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::SetIndexBuffer(unsigned int buffer, unsigned int type, size_t offset) {
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
|
|
|
|
|
(void)offset;
|
|
|
|
|
m_currentIndexType = type;
|
|
|
|
|
m_currentIndexOffset = static_cast<uint64_t>(offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::BindVertexArray(unsigned int vao) {
|
|
|
|
|
@@ -137,7 +164,8 @@ void OpenGLCommandList::BindVertexArray(unsigned int vao, unsigned int indexBuff
|
|
|
|
|
m_currentVAO = vao;
|
|
|
|
|
glBindVertexArray(vao);
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
|
|
|
|
|
(void)indexType;
|
|
|
|
|
m_currentIndexType = indexType;
|
|
|
|
|
m_currentIndexOffset = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::UseShader(unsigned int program) {
|
|
|
|
|
@@ -261,13 +289,22 @@ void OpenGLCommandList::DrawInstanced(PrimitiveType type, unsigned int vertexCou
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::DrawIndexed(PrimitiveType type, unsigned int indexCount, unsigned int startIndex, int baseVertex) {
|
|
|
|
|
m_primitiveType = ToOpenGL(type);
|
|
|
|
|
glDrawElements(m_primitiveType, indexCount, GL_UNSIGNED_INT, (void*)(startIndex * sizeof(unsigned int)));
|
|
|
|
|
const uint64_t indexOffset = m_currentIndexOffset + static_cast<uint64_t>(startIndex) * GetIndexTypeSize(m_currentIndexType);
|
|
|
|
|
glDrawElements(m_primitiveType,
|
|
|
|
|
indexCount,
|
|
|
|
|
m_currentIndexType,
|
|
|
|
|
reinterpret_cast<const void*>(static_cast<uintptr_t>(indexOffset)));
|
|
|
|
|
(void)baseVertex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::DrawIndexedInstanced(PrimitiveType type, unsigned int indexCount, unsigned int instanceCount, unsigned int startIndex, int baseVertex, unsigned int startInstance) {
|
|
|
|
|
m_primitiveType = ToOpenGL(type);
|
|
|
|
|
glDrawElementsInstanced(m_primitiveType, indexCount, GL_UNSIGNED_INT, (void*)(startIndex * sizeof(unsigned int)), instanceCount);
|
|
|
|
|
const uint64_t indexOffset = m_currentIndexOffset + static_cast<uint64_t>(startIndex) * GetIndexTypeSize(m_currentIndexType);
|
|
|
|
|
glDrawElementsInstanced(m_primitiveType,
|
|
|
|
|
indexCount,
|
|
|
|
|
m_currentIndexType,
|
|
|
|
|
reinterpret_cast<const void*>(static_cast<uintptr_t>(indexOffset)),
|
|
|
|
|
instanceCount);
|
|
|
|
|
(void)baseVertex;
|
|
|
|
|
(void)startInstance;
|
|
|
|
|
}
|
|
|
|
|
@@ -284,7 +321,7 @@ void OpenGLCommandList::DrawIndirect(PrimitiveType type, unsigned int buffer, si
|
|
|
|
|
void OpenGLCommandList::DrawIndexedIndirect(PrimitiveType type, unsigned int buffer, size_t offset, unsigned int drawCount, unsigned int stride) {
|
|
|
|
|
m_primitiveType = ToOpenGL(type);
|
|
|
|
|
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffer);
|
|
|
|
|
glDrawElementsIndirect(m_primitiveType, GL_UNSIGNED_INT, (void*)offset);
|
|
|
|
|
glDrawElementsIndirect(m_primitiveType, m_currentIndexType, (void*)offset);
|
|
|
|
|
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
|
|
|
|
|
(void)drawCount;
|
|
|
|
|
(void)stride;
|
|
|
|
|
@@ -477,6 +514,8 @@ void OpenGLCommandList::Shutdown() {
|
|
|
|
|
void OpenGLCommandList::Reset() {
|
|
|
|
|
ReleaseComposedFramebuffer();
|
|
|
|
|
m_currentPipelineState = nullptr;
|
|
|
|
|
m_currentIndexOffset = 0;
|
|
|
|
|
m_currentIndexType = GL_UNSIGNED_INT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::Close() {
|
|
|
|
|
@@ -827,7 +866,8 @@ void OpenGLCommandList::SetIndexBuffer(RHIResourceView* buffer, uint64_t offset)
|
|
|
|
|
|
|
|
|
|
GLuint glBuffer = view->GetBuffer();
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glBuffer);
|
|
|
|
|
(void)offset;
|
|
|
|
|
m_currentIndexType = ResolveOpenGLIndexType(view->GetFormat());
|
|
|
|
|
m_currentIndexOffset = view->GetBufferOffset() + offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::CopyResource(RHIResourceView* dst, RHIResourceView* src) {
|
|
|
|
|
@@ -853,12 +893,22 @@ void OpenGLCommandList::CopyResource(RHIResourceView* dst, RHIResourceView* src)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t startVertex, uint32_t startInstance) {
|
|
|
|
|
glDrawArraysInstanced(GL_TRIANGLES, static_cast<GLint>(startVertex), static_cast<GLsizei>(vertexCount), static_cast<GLsizei>(instanceCount));
|
|
|
|
|
glDrawArraysInstanced(m_primitiveType,
|
|
|
|
|
static_cast<GLint>(startVertex),
|
|
|
|
|
static_cast<GLsizei>(vertexCount),
|
|
|
|
|
static_cast<GLsizei>(instanceCount));
|
|
|
|
|
(void)startInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t startIndex, int32_t baseVertex, uint32_t startInstance) {
|
|
|
|
|
glDrawElementsInstanced(GL_TRIANGLES, static_cast<GLsizei>(indexCount), GL_UNSIGNED_INT,
|
|
|
|
|
reinterpret_cast<const void*>(startIndex * sizeof(GLuint)), static_cast<GLsizei>(instanceCount));
|
|
|
|
|
const uint64_t indexOffset = m_currentIndexOffset + static_cast<uint64_t>(startIndex) * GetIndexTypeSize(m_currentIndexType);
|
|
|
|
|
glDrawElementsInstanced(m_primitiveType,
|
|
|
|
|
static_cast<GLsizei>(indexCount),
|
|
|
|
|
m_currentIndexType,
|
|
|
|
|
reinterpret_cast<const void*>(static_cast<uintptr_t>(indexOffset)),
|
|
|
|
|
static_cast<GLsizei>(instanceCount));
|
|
|
|
|
(void)baseVertex;
|
|
|
|
|
(void)startInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLCommandList::SetPrimitiveTopology(PrimitiveTopology topology) {
|
|
|
|
|
|