gpu: rename DrawMode to Topology and move it to pipeline descriptors

Vulkan needs the topology stated in its pipeline descriptor, not at
draw time.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-09-08 09:48:48 +02:00
parent 41e812d5e8
commit 3d1e9b0856
8 changed files with 82 additions and 65 deletions
+17 -15
View File
@@ -113,10 +113,11 @@ type framebuffer struct {
}
type pipeline struct {
prog *program
inputs []shader.InputLocation
layout driver.VertexLayout
blend driver.BlendDesc
prog *program
inputs []shader.InputLocation
layout driver.VertexLayout
blend driver.BlendDesc
topology driver.Topology
}
type buffer struct {
@@ -822,16 +823,16 @@ func (b *Backend) SetBlend(enable bool) {
b.glstate.set(b.funcs, gl.BLEND, enable)
}
func (b *Backend) DrawElements(mode driver.DrawMode, off, count int) {
func (b *Backend) DrawElements(off, count int) {
b.prepareDraw()
// off is in 16-bit indices, but DrawElements take a byte offset.
byteOff := off * 2
b.funcs.DrawElements(toGLDrawMode(mode), count, gl.UNSIGNED_SHORT, byteOff)
b.funcs.DrawElements(toGLDrawMode(b.state.pipeline.topology), count, gl.UNSIGNED_SHORT, byteOff)
}
func (b *Backend) DrawArrays(mode driver.DrawMode, off, count int) {
func (b *Backend) DrawArrays(off, count int) {
b.prepareDraw()
b.funcs.DrawArrays(toGLDrawMode(mode), off, count)
b.funcs.DrawArrays(toGLDrawMode(b.state.pipeline.topology), off, count)
}
func (b *Backend) prepareDraw() {
@@ -843,11 +844,11 @@ func (b *Backend) prepareDraw() {
p.prog.updateUniforms()
}
func toGLDrawMode(mode driver.DrawMode) gl.Enum {
func toGLDrawMode(mode driver.Topology) gl.Enum {
switch mode {
case driver.DrawModeTriangleStrip:
case driver.TopologyTriangleStrip:
return gl.TRIANGLE_STRIP
case driver.DrawModeTriangles:
case driver.TopologyTriangles:
return gl.TRIANGLES
default:
panic("unsupported draw mode")
@@ -918,10 +919,11 @@ func (b *Backend) NewPipeline(desc driver.PipelineDesc) (driver.Pipeline, error)
}
}
return &pipeline{
prog: p,
inputs: vsrc.Inputs,
layout: layout,
blend: desc.BlendDesc,
prog: p,
inputs: vsrc.Inputs,
layout: layout,
blend: desc.BlendDesc,
topology: desc.Topology,
}, nil
}