mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
Implement primitive topology in OpenGL, Metal, and D3D12 backends
This commit is contained in:
@@ -236,11 +236,11 @@ namespace opengl {
|
||||
{
|
||||
DrawArraysCmd* draw = commands.NextCommand<DrawArraysCmd>();
|
||||
if (draw->firstInstance > 0) {
|
||||
glDrawArraysInstancedBaseInstance(GL_TRIANGLES,
|
||||
glDrawArraysInstancedBaseInstance(lastRenderPipeline->GetGLPrimitiveTopology(),
|
||||
draw->firstVertex, draw->vertexCount, draw->instanceCount, draw->firstInstance);
|
||||
} else {
|
||||
// This branch is only needed on OpenGL < 4.2
|
||||
glDrawArraysInstanced(GL_TRIANGLES,
|
||||
glDrawArraysInstanced(lastRenderPipeline->GetGLPrimitiveTopology(),
|
||||
draw->firstVertex, draw->vertexCount, draw->instanceCount);
|
||||
}
|
||||
}
|
||||
@@ -253,13 +253,13 @@ namespace opengl {
|
||||
GLenum formatType = IndexFormatType(indexBufferFormat);
|
||||
|
||||
if (draw->firstInstance > 0) {
|
||||
glDrawElementsInstancedBaseInstance(GL_TRIANGLES,
|
||||
glDrawElementsInstancedBaseInstance(lastRenderPipeline->GetGLPrimitiveTopology(),
|
||||
draw->indexCount, formatType,
|
||||
reinterpret_cast<void*>(draw->firstIndex * formatSize + indexBufferOffset),
|
||||
draw->instanceCount, draw->firstInstance);
|
||||
} else {
|
||||
// This branch is only needed on OpenGL < 4.2
|
||||
glDrawElementsInstanced(GL_TRIANGLES,
|
||||
glDrawElementsInstanced(lastRenderPipeline->GetGLPrimitiveTopology(),
|
||||
draw->indexCount, formatType,
|
||||
reinterpret_cast<void*>(draw->firstIndex * formatSize + indexBufferOffset),
|
||||
draw->instanceCount);
|
||||
|
||||
@@ -21,8 +21,32 @@
|
||||
namespace backend {
|
||||
namespace opengl {
|
||||
|
||||
namespace {
|
||||
GLenum GLPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) {
|
||||
switch (primitiveTopology) {
|
||||
case nxt::PrimitiveTopology::Point:
|
||||
return GL_POINTS;
|
||||
case nxt::PrimitiveTopology::Line:
|
||||
return GL_LINES;
|
||||
case nxt::PrimitiveTopology::LineStrip:
|
||||
return GL_LINE_STRIP;
|
||||
case nxt::PrimitiveTopology::Triangle:
|
||||
return GL_TRIANGLES;
|
||||
case nxt::PrimitiveTopology::TriangleStrip:
|
||||
return GL_TRIANGLE_STRIP;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
|
||||
: RenderPipelineBase(builder), PipelineGL(this, builder) {
|
||||
: RenderPipelineBase(builder), PipelineGL(this, builder),
|
||||
glPrimitiveTopology(GLPrimitiveTopology(GetPrimitiveTopology())) {
|
||||
}
|
||||
|
||||
GLenum RenderPipeline::GetGLPrimitiveTopology() const {
|
||||
return glPrimitiveTopology;
|
||||
}
|
||||
|
||||
void RenderPipeline::ApplyNow(PersistentPipelineState &persistentPipelineState) {
|
||||
|
||||
@@ -32,7 +32,12 @@ namespace opengl {
|
||||
public:
|
||||
RenderPipeline(RenderPipelineBuilder* builder);
|
||||
|
||||
GLenum GetGLPrimitiveTopology() const;
|
||||
|
||||
void ApplyNow(PersistentPipelineState &persistentPipelineState);
|
||||
|
||||
private:
|
||||
GLenum glPrimitiveTopology;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user