gpu,gpu/gl: introduce InputLayout and use shader reflection data

InputLayout is the abstraction for the mapping between vertex data and
shader inputs. The mapping is implicit in OpenGL but explicit in
Direct3D.

Infer the attribute name location index using shader reflection data,
and get rid of a parameter to NewProgram.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-02-19 17:16:55 +01:00
parent ac7029fa24
commit 9cdc8e6182
4 changed files with 158 additions and 61 deletions
+18 -2
View File
@@ -23,8 +23,8 @@ type Backend interface {
NilTexture() Texture
NewFramebuffer() Framebuffer
NewBuffer(typ BufferType, data []byte) Buffer
NewProgram(vertexShader, fragmentShader ShaderSources, attribMap []string) (Program, error)
SetupVertexArray(slot int, size int, dataType DataType, stride, offset int)
NewProgram(vertexShader, fragmentShader ShaderSources) (Program, error)
NewInputLayout(vertexShader ShaderSources, layout []InputDesc) (InputLayout, error)
DepthFunc(f DepthFunc)
ClearColor(r, g, b, a float32)
@@ -65,6 +65,21 @@ type InputLocation struct {
Size int
}
// InputDesc describes a vertex attribute as laid out in a Buffer.
type InputDesc struct {
Type DataType
Size int
Offset int
}
// InputLayout is the backend specific representation of the mapping
// between Buffers and shader attributes.
type InputLayout interface {
Bind()
Release()
}
type BlendFactor uint8
type DrawMode uint8
@@ -100,6 +115,7 @@ type Program interface {
type Uniform interface{}
type Buffer interface {
BindVertex(stride, offset int)
Bind()
Release()
}