1
- // Copyright (c) 2022, The Goki Authors . All rights reserved.
1
+ // Copyright (c) 2022, Cogent Core . All rights reserved.
2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
@@ -13,9 +13,9 @@ import (
13
13
14
14
vk "github.com/goki/vulkan"
15
15
16
+ "cogentcore.org/core/math32"
17
+ "cogentcore.org/core/vgpu"
16
18
"github.com/go-gl/glfw/v3.3/glfw"
17
- "goki.dev/mat32/v2"
18
- "goki.dev/vgpu/v2/vgpu"
19
19
)
20
20
21
21
func init () {
@@ -24,9 +24,9 @@ func init() {
24
24
}
25
25
26
26
type CamView struct {
27
- Model mat32. Mat4
28
- View mat32. Mat4
29
- Prjn mat32. Mat4
27
+ Model math32. Matrix4
28
+ View math32. Matrix4
29
+ Projection math32. Matrix4
30
30
}
31
31
32
32
func main () {
@@ -45,7 +45,7 @@ func main() {
45
45
vgpu .Debug = true
46
46
gp .Config ("drawidx" )
47
47
48
- // gp.PropsString (true) // print
48
+ // gp.PropertiesString (true) // print
49
49
50
50
surfPtr , err := window .CreateWindowSurface (gp .Instance , nil )
51
51
if err != nil {
@@ -83,47 +83,47 @@ func main() {
83
83
84
84
nPts := 3
85
85
86
- posv := vset .Add ("Pos" , vgpu .Float32Vec3 , nPts , vgpu .Vertex , vgpu .VertexShader )
87
- clrv := vset .Add ("Color" , vgpu .Float32Vec3 , nPts , vgpu .Vertex , vgpu .VertexShader )
86
+ posv := vset .Add ("Pos" , vgpu .Float32Vector3 , nPts , vgpu .Vertex , vgpu .VertexShader )
87
+ clrv := vset .Add ("Color" , vgpu .Float32Vector3 , nPts , vgpu .Vertex , vgpu .VertexShader )
88
88
// note: always put indexes last so there isn't a gap in the location indexes!
89
89
// just the fact of adding one (and only one) Index type triggers indexed render
90
90
idxv := vset .Add ("Index" , vgpu .Uint16 , nPts , vgpu .Index , vgpu .VertexShader )
91
91
92
92
camv := set .Add ("Camera" , vgpu .Struct , 1 , vgpu .Uniform , vgpu .VertexShader )
93
- camv .SizeOf = vgpu .Float32Mat4 .Bytes () * 3 // no padding for these
93
+ camv .SizeOf = vgpu .Float32Matrix4 .Bytes () * 3 // no padding for these
94
94
95
- vset .ConfigVals (1 ) // one val per var
96
- set .ConfigVals (1 ) // one val per var
95
+ vset .ConfigValues (1 ) // one val per var
96
+ set .ConfigValues (1 ) // one val per var
97
97
sy .Config ()
98
98
99
- triPos , _ := posv .Vals . ValByIdxTry (0 )
99
+ triPos , _ := posv .Values . ValueByIndexTry (0 )
100
100
triPosA := triPos .Floats32 ()
101
101
triPosA .Set (0 ,
102
102
- 0.5 , 0.5 , 0.0 ,
103
103
0.5 , 0.5 , 0.0 ,
104
104
0.0 , - 0.5 , 0.0 ) // negative point is UP in native Vulkan
105
105
triPos .SetMod ()
106
106
107
- triClr , _ := clrv .Vals . ValByIdxTry (0 )
107
+ triClr , _ := clrv .Values . ValueByIndexTry (0 )
108
108
triClrA := triClr .Floats32 ()
109
109
triClrA .Set (0 ,
110
110
1.0 , 0.0 , 0.0 ,
111
111
0.0 , 1.0 , 0.0 ,
112
112
0.0 , 0.0 , 1.0 )
113
113
triClr .SetMod ()
114
114
115
- triIdx , _ := idxv .Vals . ValByIdxTry (0 )
115
+ triIndex , _ := idxv .Values . ValueByIndexTry (0 )
116
116
idxs := []uint16 {0 , 1 , 2 }
117
- triIdx .CopyFromBytes (unsafe .Pointer (& idxs [0 ]))
117
+ triIndex .CopyFromBytes (unsafe .Pointer (& idxs [0 ]))
118
118
119
119
// This is the standard camera view projection computation
120
- cam , _ := camv .Vals . ValByIdxTry (0 )
121
- campos := mat32 . V3 (0 , 0 , 2 )
122
- target := mat32 . V3 (0 , 0 , 0 )
123
- var lookq mat32 .Quat
124
- lookq .SetFromRotationMatrix (mat32 .NewLookAt (campos , target , mat32 . V3 (0 , 1 , 0 )))
125
- scale := mat32 . V3 (1 , 1 , 1 )
126
- var cview mat32. Mat4
120
+ cam , _ := camv .Values . ValueByIndexTry (0 )
121
+ campos := math32 . Vec3 (0 , 0 , 2 )
122
+ target := math32 . Vec3 (0 , 0 , 0 )
123
+ var lookq math32 .Quat
124
+ lookq .SetFromRotationMatrix (math32 .NewLookAt (campos , target , math32 . Vec3 (0 , 1 , 0 )))
125
+ scale := math32 . Vec3 (1 , 1 , 1 )
126
+ var cview math32. Matrix4
127
127
cview .SetTransform (campos , lookq , scale )
128
128
view , _ := cview .Inverse ()
129
129
@@ -132,16 +132,13 @@ func main() {
132
132
camo .View .CopyFrom (view )
133
133
aspect := float32 (sf .Format .Size .X ) / float32 (sf .Format .Size .Y )
134
134
fmt .Printf ("aspect: %g\n " , aspect )
135
- // VkPerspective version automatically flips Y axis and shifts depth
136
- // into a 0..1 range instead of -1..1, so original GL based geometry
137
- // will render identically here.
138
- camo .Prjn .SetVkPerspective (45 , aspect , 0.01 , 100 )
135
+ camo .Projection .SetPerspective (45 , aspect , 0.01 , 100 )
139
136
140
137
cam .CopyFromBytes (unsafe .Pointer (& camo )) // sets mod
141
138
142
139
sy .Mem .SyncToGPU ()
143
140
144
- vars .BindDynVal (0 , camv , cam )
141
+ vars .BindDynamicValue (0 , camv , cam )
145
142
146
143
frameCount := 0
147
144
stTime := time .Now ()
@@ -153,12 +150,15 @@ func main() {
153
150
cam .CopyFromBytes (unsafe .Pointer (& camo )) // sets mod
154
151
sy .Mem .SyncToGPU ()
155
152
156
- idx := sf .AcquireNextImage ()
153
+ idx , ok := sf .AcquireNextImage ()
154
+ if ! ok {
155
+ return
156
+ }
157
157
// fmt.Printf("\nacq: %v\n", time.Now().Sub(rt))
158
- descIdx := 0 // if running multiple frames in parallel, need diff sets
158
+ descIndex := 0 // if running multiple frames in parallel, need diff sets
159
159
cmd := sy .CmdPool .Buff
160
- sy .ResetBeginRenderPass (cmd , sf .Frames [idx ], descIdx )
161
- pl .BindDrawVertex (cmd , descIdx )
160
+ sy .ResetBeginRenderPass (cmd , sf .Frames [idx ], descIndex )
161
+ pl .BindDrawVertex (cmd , descIndex )
162
162
sy .EndRenderPass (cmd )
163
163
// fmt.Printf("cmd %v\n", time.Now().Sub(rt))
164
164
sf .SubmitRender (cmd ) // this is where it waits for the 16 msec
0 commit comments