#define TEST_GL_ABSTRACTION_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
inline void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount) override
{
+ std::stringstream out;
+ out << mode << ", " << first << ", " << count << ", " << instanceCount;
+ TraceCallStack::NamedParams namedParams;
+ namedParams["mode"] << std::hex << mode;
+ namedParams["first"] << first;
+ namedParams["count"] << count;
+ namedParams["instanceCount"] << instanceCount;
+ mDrawTrace.PushCall("DrawArraysInstanced", out.str(), namedParams);
}
inline void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount) override
{
+ std::stringstream out;
+ out << mode << ", " << count << ", " << type << ", " << instanceCount;
+ TraceCallStack::NamedParams namedParams;
+ namedParams["mode"] << std::hex << mode;
+ namedParams["count"] << count;
+ namedParams["type"] << std::hex << type;
+ namedParams["indexCount"] << instanceCount;
+ mDrawTrace.PushCall("DrawElementsInstanced", out.str(), namedParams);
}
inline GLsync FenceSync(GLenum condition, GLbitfield flags) override
inline void VertexAttribDivisor(GLuint index, GLuint divisor) override
{
+ std::stringstream out;
+ out << index << ", " << divisor;
+ TraceCallStack::NamedParams namedParams;
+ namedParams["index"] << index;
+ namedParams["divisor"] << divisor;
+ mBufferTrace.PushCall("VertexAttribDivisor", out.str(), namedParams);
}
inline void BindTransformFeedback(GLenum target, GLuint id) override
{
if(currentPipeline)
{
- mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology),
- 0,
- cmd.data.draw.draw.vertexCount);
+ if(cmd.data.draw.draw.instanceCount == 0)
+ {
+ mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology),
+ 0,
+ cmd.data.draw.draw.vertexCount);
+ }
+ else
+ {
+ mGl.DrawArraysInstanced(GetTopology(currentPipeline->inputAssemblyState.topology),
+ 0,
+ cmd.data.draw.draw.vertexCount,
+ cmd.data.draw.draw.instanceCount);
+ }
}
break;
}
{
if(currentPipeline)
{
- mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
- static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
- GL_UNSIGNED_SHORT,
- reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
+ if(cmd.data.draw.draw.instanceCount == 0)
+ {
+ mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
+ static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
+ GL_UNSIGNED_SHORT,
+ reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
+ }
+ else
+ {
+ mGl.DrawElementsInstanced(GetTopology(currentPipeline->inputAssemblyState.topology),
+ static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
+ GL_UNSIGNED_SHORT,
+ reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex),
+ cmd.data.draw.drawIndexed.instanceCount);
+ }
}
break;
}
uint32_t attributeOffset = attribute.offset;
GLsizei stride = vi.bufferBindings[attribute.binding].stride;
+ auto rate = vi.bufferBindings[attribute.binding].inputRate;
+
mGl.VertexAttribPointer(attribute.location,
GetNumComponents(attribute.format),
GetGlType(attribute.format),
GL_FALSE, // Not normalized
stride,
reinterpret_cast<void*>(attributeOffset));
+ if(rate == Graphics::VertexInputRate::PER_VERTEX)
+ {
+ mGl.VertexAttribDivisor(attribute.location, 0);
+ }
+ else if(rate == Graphics::VertexInputRate::PER_INSTANCE)
+ {
+ mGl.VertexAttribDivisor(attribute.location, 1);
+ }
}
// Cull face setup
GL_FALSE,
bufferBinding.stride,
reinterpret_cast<void*>(attr.offset));
+
+ switch(bufferBinding.inputRate)
+ {
+ case Graphics::VertexInputRate::PER_VERTEX:
+ {
+ gl.VertexAttribDivisor(attr.location, 0);
+ break;
+ }
+ case Graphics::VertexInputRate::PER_INSTANCE:
+ {
+ //@todo Get actual instance rate...
+ gl.VertexAttribDivisor(attr.location, 1);
+ break;
+ }
+ }
}
// Resolve topology
mImpl->FlushVertexAttributeLocations();
}
- gl.DrawArrays(GLESTopology(ia->topology),
- drawCall.draw.firstVertex,
- drawCall.draw.vertexCount);
+ if(drawCall.draw.instanceCount == 0)
+ {
+ gl.DrawArrays(GLESTopology(ia->topology),
+ drawCall.draw.firstVertex,
+ drawCall.draw.vertexCount);
+ }
+ else
+ {
+ gl.DrawArraysInstanced(GLESTopology(ia->topology),
+ drawCall.draw.firstVertex,
+ drawCall.draw.vertexCount,
+ drawCall.draw.instanceCount);
+ }
break;
}
case DrawCallDescriptor::Type::DRAW_INDEXED:
}
auto indexBufferFormat = GLIndexFormat(binding.format).format;
- gl.DrawElements(GLESTopology(ia->topology),
- drawCall.drawIndexed.indexCount,
- indexBufferFormat,
- reinterpret_cast<void*>(binding.offset));
+ if(drawCall.drawIndexed.instanceCount == 0)
+ {
+ gl.DrawElements(GLESTopology(ia->topology),
+ drawCall.drawIndexed.indexCount,
+ indexBufferFormat,
+ reinterpret_cast<void*>(binding.offset));
+ }
+ else
+ {
+ gl.DrawElementsInstanced(GLESTopology(ia->topology),
+ drawCall.drawIndexed.indexCount,
+ indexBufferFormat,
+ reinterpret_cast<void*>(binding.offset),
+ drawCall.drawIndexed.instanceCount);
+ }
break;
}
case DrawCallDescriptor::Type::DRAW_INDEXED_INDIRECT: