-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline_regular.go
79 lines (70 loc) · 1.62 KB
/
pipeline_regular.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
_ "embed"
"unsafe"
"github.com/rajveermalviya/go-webgpu/wgpu"
)
type RegularPipeline struct {
Pipeline
vbo_layout wgpu.VertexBufferLayout
}
//go:embed shaders/regular.wgsl
var regular_shader_src string
func NewRegularPipeline(state *State) (*RegularPipeline, error) {
vbo_layout := wgpu.VertexBufferLayout{
ArrayStride: uint64(unsafe.Sizeof(Vertex{})),
StepMode: wgpu.VertexStepMode_Vertex,
Attributes: []wgpu.VertexAttribute{
{
Format: wgpu.VertexFormat_Float32x3,
Offset: 0,
ShaderLocation: 0,
},
{
Format: wgpu.VertexFormat_Float32x2,
Offset: 4 * 3,
ShaderLocation: 1,
},
},
}
pipeline, err := NewPipeline(state, "Regular", regular_shader_src,
[]wgpu.BindGroupLayoutEntry{
{ // texture
Binding: 0,
Visibility: wgpu.ShaderStage_Fragment,
Texture: wgpu.TextureBindingLayout{
Multisampled: false,
ViewDimension: wgpu.TextureViewDimension_2D,
SampleType: wgpu.TextureSampleType_Float,
},
},
{ // sampler
Binding: 1,
Visibility: wgpu.ShaderStage_Fragment,
Sampler: wgpu.SamplerBindingLayout{
Type: wgpu.SamplerBindingType_Filtering,
},
},
{ // MVP matrix
Binding: 2,
Visibility: wgpu.ShaderStage_Vertex,
Buffer: wgpu.BufferBindingLayout{
Type: wgpu.BufferBindingType_Uniform,
},
},
},
[]wgpu.VertexBufferLayout{
vbo_layout,
},
)
if err != nil {
return nil, err
}
return &RegularPipeline{
Pipeline: *pipeline,
vbo_layout: vbo_layout,
}, nil
}
func (pipeline *RegularPipeline) Release() {
pipeline.Pipeline.Release()
}