-
Notifications
You must be signed in to change notification settings - Fork 327
/
resources.go
639 lines (587 loc) · 19.8 KB
/
resources.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
// Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gles
import (
"context"
"fmt"
"sort"
"github.com/google/gapid/core/data/id"
"github.com/google/gapid/core/image"
"github.com/google/gapid/core/log"
"github.com/google/gapid/gapis/api"
"github.com/google/gapid/gapis/capture"
"github.com/google/gapid/gapis/database"
"github.com/google/gapid/gapis/messages"
"github.com/google/gapid/gapis/resolve"
"github.com/google/gapid/gapis/service"
"github.com/google/gapid/gapis/service/box"
"github.com/google/gapid/gapis/service/path"
)
var _ api.Resource = Textureʳ{}
// IsResource returns true if this instance should be considered as a resource.
func (t Textureʳ) IsResource() bool {
return t.ID() != 0
}
// ResourceHandle returns the UI identity for the resource.
func (t Textureʳ) ResourceHandle() string {
return fmt.Sprintf("Texture<%d>", t.ID())
}
// ResourceLabel returns an optional debug label for the resource.
func (t Textureʳ) ResourceLabel() string {
return t.Label()
}
// Order returns an integer used to sort the resources for presentation.
func (t Textureʳ) Order() uint64 {
return uint64(t.ID())
}
// ResourceType returns the type of this resource.
func (t Textureʳ) ResourceType(ctx context.Context) api.ResourceType {
return api.ResourceType_TextureResource
}
// ResourceData returns the resource data given the current state.
func (t Textureʳ) ResourceData(ctx context.Context, s *api.GlobalState) (*api.ResourceData, error) {
ctx = log.Enter(ctx, "Texture.ResourceData()")
switch t.Kind() {
case GLenum_GL_TEXTURE_1D, GLenum_GL_TEXTURE_2D, GLenum_GL_TEXTURE_2D_MULTISAMPLE:
count := GLint(0)
for i := range t.Levels().All() {
if i >= count {
count = i + 1
}
}
levels := make([]*image.Info, count)
for i, level := range t.Levels().All() {
img, err := level.Layers().Get(0).ImageInfo(ctx, s)
if err != nil {
return nil, err
}
levels[i] = img
}
switch t.Kind() {
case GLenum_GL_TEXTURE_1D:
return api.NewResourceData(api.NewTexture(&api.Texture1D{Levels: levels})), nil
case GLenum_GL_TEXTURE_2D:
return api.NewResourceData(api.NewTexture(&api.Texture2D{Levels: levels})), nil
case GLenum_GL_TEXTURE_2D_MULTISAMPLE:
return api.NewResourceData(api.NewTexture(&api.Texture2D{Levels: levels, Multisampled: true})), nil
default:
panic(fmt.Errorf("Unhandled texture kind %v", t.Kind()))
}
case GLenum_GL_TEXTURE_EXTERNAL_OES:
ei := t.EGLImage()
if ei.IsNil() {
return api.NewResourceData(api.NewTexture(&api.Texture2D{})), nil
}
levels := make([]*image.Info, ei.Images().Len())
for i, img := range ei.Images().All() {
ii, err := img.ImageInfo(ctx, s)
if err != nil {
return nil, err
}
levels[i] = ii
}
return api.NewResourceData(api.NewTexture(&api.Texture2D{Levels: levels})), nil
case GLenum_GL_TEXTURE_1D_ARRAY:
numLayers := t.LayerCount()
layers := make([]*api.Texture1D, numLayers)
for layer := range layers {
levels := make([]*image.Info, t.Levels().Len())
for level := range levels {
img, err := t.Levels().Get(GLint(level)).Layers().Get(GLint(layer)).ImageInfo(ctx, s)
if err != nil {
return nil, err
}
levels[level] = img
}
layers[layer] = &api.Texture1D{Levels: levels}
}
return api.NewResourceData(api.NewTexture(&api.Texture1DArray{Layers: layers})), nil
case GLenum_GL_TEXTURE_2D_ARRAY, GLenum_GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
numLayers := t.LayerCount()
layers := make([]*api.Texture2D, numLayers)
for layer := range layers {
levels := make([]*image.Info, t.Levels().Len())
for level := range levels {
img, err := t.Levels().Get(GLint(level)).Layers().Get(GLint(layer)).ImageInfo(ctx, s)
if err != nil {
return nil, err
}
levels[level] = img
}
layers[layer] = &api.Texture2D{Levels: levels}
}
switch t.Kind() {
case GLenum_GL_TEXTURE_2D_ARRAY:
return api.NewResourceData(api.NewTexture(&api.Texture2DArray{Layers: layers})), nil
case GLenum_GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
return api.NewResourceData(api.NewTexture(&api.Texture2DArray{Layers: layers, Multisampled: true})), nil
default:
panic(fmt.Errorf("Unhandled texture kind %v", t.Kind()))
}
case GLenum_GL_TEXTURE_3D:
levels := make([]*image.Info, t.Levels().Len())
for i, level := range t.Levels().All() {
img := level.Layers().Get(0)
l := &image.Info{
Width: uint32(img.Width()),
Height: uint32(img.Height()),
Depth: uint32(level.Layers().Len()),
}
levels[i] = l
if img.Data().Size() == 0 {
continue
}
bytes := []byte{}
for i, c := 0, level.Layers().Len(); i < c; i++ {
l := level.Layers().Get(GLint(i))
if l.IsNil() {
continue
}
pool, err := s.Memory.Get(l.Data().Pool())
if err != nil {
return nil, err
}
data := pool.Slice(l.Data().Range())
buf := make([]byte, data.Size())
if err := data.Get(ctx, 0, buf); err != nil {
return nil, err
}
bytes = append(bytes, buf...)
}
id, err := database.Store(ctx, bytes)
if err != nil {
return nil, err
}
format, err := getImageFormat(img.DataFormat(), img.DataType())
if err != nil {
return nil, err
}
l.Format = format
l.Bytes = image.NewID(id)
}
return api.NewResourceData(api.NewTexture(&api.Texture3D{Levels: levels})), nil
case GLenum_GL_TEXTURE_CUBE_MAP:
levels := make([]*api.CubemapLevel, t.Levels().Len())
for i, level := range t.Levels().All() {
levels[i] = &api.CubemapLevel{}
for j, face := range level.Layers().All() {
img, err := face.ImageInfo(ctx, s)
if err != nil {
return nil, err
}
switch GLenum(j) + GLenum_GL_TEXTURE_CUBE_MAP_POSITIVE_X {
case GLenum_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
levels[i].NegativeX = img
case GLenum_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
levels[i].PositiveX = img
case GLenum_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
levels[i].NegativeY = img
case GLenum_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
levels[i].PositiveY = img
case GLenum_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
levels[i].NegativeZ = img
case GLenum_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
levels[i].PositiveZ = img
}
}
}
return api.NewResourceData(api.NewTexture(&api.Cubemap{Levels: levels})), nil
}
return nil, &service.ErrDataUnavailable{Reason: messages.ErrNoTextureData(t.ResourceHandle())}
}
func (t Textureʳ) SetResourceData(
ctx context.Context,
at *path.Command,
data *api.ResourceData,
resources api.ResourceMap,
edits api.ReplaceCallback,
mutate api.MutateInitialState,
r *path.ResolveConfig) error {
return fmt.Errorf("SetResourceData is not supported for Texture")
}
// ImageInfo returns the Image as a image.Info.
func (i Imageʳ) ImageInfo(ctx context.Context, s *api.GlobalState) (*image.Info, error) {
out := &image.Info{
Width: uint32(i.Width()),
Height: uint32(i.Height()),
Depth: 1,
}
if i.Data().Size() == 0 {
return out, nil
}
dataFormat, dataType := i.getUnsizedFormatAndType()
format, err := getImageFormat(dataFormat, dataType)
if err != nil {
return nil, err
}
out.Format = format
out.Bytes = image.NewID(i.Data().ResourceID(ctx, s))
return out, nil
}
// LayerCount returns the maximum number of layers across all levels.
func (t Textureʳ) LayerCount() int {
max := 0
for _, l := range t.Levels().All() {
if l.Layers().Len() > max {
max = l.Layers().Len()
}
}
return max
}
var _ api.Resource = Shaderʳ{}
// IsResource returns true if this instance should be considered as a resource.
func (s Shaderʳ) IsResource() bool {
return s.ID() != 0
}
// ResourceHandle returns the UI identity for the resource.
func (s Shaderʳ) ResourceHandle() string {
return fmt.Sprintf("Shader<%d>", s.ID())
}
// ResourceLabel returns an optional debug label for the resource.
func (s Shaderʳ) ResourceLabel() string {
return s.Label()
}
// Order returns an integer used to sort the resources for presentation.
func (s Shaderʳ) Order() uint64 {
return uint64(s.ID())
}
// ResourceType returns the type of this resource.
func (s Shaderʳ) ResourceType(ctx context.Context) api.ResourceType {
return api.ResourceType_ShaderResource
}
// ResourceData returns the resource data given the current state.
func (s Shaderʳ) ResourceData(ctx context.Context, t *api.GlobalState) (*api.ResourceData, error) {
ctx = log.Enter(ctx, "Shader.ResourceData()")
var ty api.ShaderType
switch s.Type() {
case GLenum_GL_VERTEX_SHADER:
ty = api.ShaderType_Vertex
case GLenum_GL_GEOMETRY_SHADER:
ty = api.ShaderType_Geometry
case GLenum_GL_TESS_CONTROL_SHADER:
ty = api.ShaderType_TessControl
case GLenum_GL_TESS_EVALUATION_SHADER:
ty = api.ShaderType_TessEvaluation
case GLenum_GL_FRAGMENT_SHADER:
ty = api.ShaderType_Fragment
case GLenum_GL_COMPUTE_SHADER:
ty = api.ShaderType_Compute
}
return api.NewResourceData(&api.Shader{Type: ty, Source: s.Source()}), nil
}
func (s Shaderʳ) SetResourceData(
ctx context.Context,
at *path.Command,
data *api.ResourceData,
resourceIDs api.ResourceMap,
edits api.ReplaceCallback,
mutate api.MutateInitialState,
r *path.ResolveConfig) error {
cmdIdx := at.Indices[0]
if len(at.Indices) > 1 {
return fmt.Errorf("Subcommands currently not supported for GLES resources") // TODO: Subcommands
}
// Dirty. TODO: Make separate type for getting info for a single resource.
capturePath := at.Capture
resources, err := resolve.Resources(ctx, capturePath, r)
if err != nil {
return err
}
resourceID := resourceIDs[s]
resource, err := resources.Find(s.ResourceType(ctx), resourceID)
if err != nil {
return err
}
c, err := capture.ResolveGraphicsFromPath(ctx, capturePath)
if err != nil {
return err
}
index := len(resource.Accesses) - 1
for resource.Accesses[index].Indices[0] > cmdIdx && index >= 0 { // TODO: Subcommands
index--
}
for j := index; j >= 0; j-- {
i := resource.Accesses[j].Indices[0] // TODO: Subcommands
if a, ok := c.Commands[i].(*GlShaderSource); ok {
edits(uint64(i), a.Replace(ctx, c, data))
return nil
}
}
// Reached the beginning of the trace, attempt to modify the shader in the initial state.
if state, ok := mutate(API{}).(*State); ok {
for _, c := range state.EGLContexts().All() {
if id.ID(c.ID()) == resource.Context.GetID().ID() {
if shader, ok := c.Objects().Shaders().Lookup(s.ID()); ok {
src := data.GetShader().Source
shader.SetSource(src)
if e := shader.CompileExtra(); !e.IsNil() {
e.SetSource(src)
}
return nil
}
break
}
}
}
return fmt.Errorf("No command to set data in")
}
func (a *GlShaderSource) Replace(ctx context.Context, c *capture.GraphicsCapture, data *api.ResourceData) interface{} {
state := c.NewState(ctx)
shader := data.GetShader()
source := shader.Source
src := state.AllocDataOrPanic(ctx, source)
srcLen := state.AllocDataOrPanic(ctx, GLint(len(source)))
srcPtr := state.AllocDataOrPanic(ctx, src.Ptr())
cb := CommandBuilder{Thread: a.Thread(), Arena: state.Arena}
return cb.GlShaderSource(a.Shader(), 1, srcPtr.Ptr(), srcLen.Ptr()).
AddRead(srcPtr.Data()).
AddRead(srcLen.Data()).
AddRead(src.Data())
}
var _ api.Resource = Programʳ{}
// IsResource returns true if this instance should be considered as a resource.
func (p Programʳ) IsResource() bool {
return p.ID() != 0
}
// ResourceHandle returns the UI identity for the resource.
func (p Programʳ) ResourceHandle() string {
return fmt.Sprintf("Program<%d>", p.ID())
}
// ResourceLabel returns an optional debug label for the resource.
func (p Programʳ) ResourceLabel() string {
return p.Label()
}
// Order returns an integer used to sort the resources for presentation.
func (p Programʳ) Order() uint64 {
return uint64(p.ID())
}
// ResourceType returns the type of this resource.
func (p Programʳ) ResourceType(ctx context.Context) api.ResourceType {
return api.ResourceType_ProgramResource
}
// ResourceData returns the resource data given the current state.
func (p Programʳ) ResourceData(ctx context.Context, s *api.GlobalState) (*api.ResourceData, error) {
ctx = log.Enter(ctx, "Program.ResourceData()")
shaders := make([]*api.Shader, 0, p.Shaders().Len())
for shaderType, shader := range p.Shaders().All() {
var ty api.ShaderType
switch shaderType {
case GLenum_GL_VERTEX_SHADER:
ty = api.ShaderType_Vertex
case GLenum_GL_GEOMETRY_SHADER:
ty = api.ShaderType_Geometry
case GLenum_GL_TESS_CONTROL_SHADER:
ty = api.ShaderType_TessControl
case GLenum_GL_TESS_EVALUATION_SHADER:
ty = api.ShaderType_TessEvaluation
case GLenum_GL_FRAGMENT_SHADER:
ty = api.ShaderType_Fragment
case GLenum_GL_COMPUTE_SHADER:
ty = api.ShaderType_Compute
}
shaders = append(shaders, &api.Shader{
Type: ty,
Source: shader.Source(),
})
}
uniforms := []*api.Uniform{}
if res := p.ActiveResources(); !res.IsNil() {
for _, activeUniform := range res.DefaultUniformBlock().All() {
var uniformFormat api.UniformFormat
var uniformType api.UniformType
switch activeUniform.Type() {
case GLenum_GL_FLOAT:
uniformFormat = api.UniformFormat_Scalar
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_VEC2:
uniformFormat = api.UniformFormat_Vec2
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_VEC3:
uniformFormat = api.UniformFormat_Vec3
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_VEC4:
uniformFormat = api.UniformFormat_Vec4
uniformType = api.UniformType_Float
case GLenum_GL_INT:
uniformFormat = api.UniformFormat_Scalar
uniformType = api.UniformType_Int32
case GLenum_GL_INT_VEC2:
uniformFormat = api.UniformFormat_Vec2
uniformType = api.UniformType_Int32
case GLenum_GL_INT_VEC3:
uniformFormat = api.UniformFormat_Vec3
uniformType = api.UniformType_Int32
case GLenum_GL_INT_VEC4:
uniformFormat = api.UniformFormat_Vec4
uniformType = api.UniformType_Int32
case GLenum_GL_UNSIGNED_INT:
uniformFormat = api.UniformFormat_Scalar
uniformType = api.UniformType_Uint32
case GLenum_GL_UNSIGNED_INT_VEC2:
uniformFormat = api.UniformFormat_Vec2
uniformType = api.UniformType_Uint32
case GLenum_GL_UNSIGNED_INT_VEC3:
uniformFormat = api.UniformFormat_Vec3
uniformType = api.UniformType_Uint32
case GLenum_GL_UNSIGNED_INT_VEC4:
uniformFormat = api.UniformFormat_Vec4
uniformType = api.UniformType_Uint32
case GLenum_GL_BOOL:
uniformFormat = api.UniformFormat_Scalar
uniformType = api.UniformType_Bool
case GLenum_GL_BOOL_VEC2:
uniformFormat = api.UniformFormat_Vec2
uniformType = api.UniformType_Bool
case GLenum_GL_BOOL_VEC3:
uniformFormat = api.UniformFormat_Vec3
uniformType = api.UniformType_Bool
case GLenum_GL_BOOL_VEC4:
uniformFormat = api.UniformFormat_Vec4
uniformType = api.UniformType_Bool
case GLenum_GL_FLOAT_MAT2:
uniformFormat = api.UniformFormat_Mat2
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_MAT3:
uniformFormat = api.UniformFormat_Mat3
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_MAT4:
uniformFormat = api.UniformFormat_Mat4
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_MAT2x3:
uniformFormat = api.UniformFormat_Mat2x3
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_MAT2x4:
uniformFormat = api.UniformFormat_Mat2x4
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_MAT3x2:
uniformFormat = api.UniformFormat_Mat3x2
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_MAT3x4:
uniformFormat = api.UniformFormat_Mat3x4
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_MAT4x2:
uniformFormat = api.UniformFormat_Mat4x2
uniformType = api.UniformType_Float
case GLenum_GL_FLOAT_MAT4x3:
uniformFormat = api.UniformFormat_Mat4x3
uniformType = api.UniformType_Float
case GLenum_GL_SAMPLER_2D:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_SAMPLER_3D:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_SAMPLER_CUBE:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_SAMPLER_2D_SHADOW:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_SAMPLER_2D_ARRAY:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_SAMPLER_2D_ARRAY_SHADOW:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_SAMPLER_CUBE_SHADOW:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_INT_SAMPLER_2D:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_INT_SAMPLER_3D:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_INT_SAMPLER_CUBE:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_INT_SAMPLER_2D_ARRAY:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_UNSIGNED_INT_SAMPLER_2D:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_UNSIGNED_INT_SAMPLER_3D:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_UNSIGNED_INT_SAMPLER_CUBE:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
case GLenum_GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
uniformFormat = api.UniformFormat_Sampler
uniformType = api.UniformType_Uint32
default:
uniformFormat = api.UniformFormat_Scalar
uniformType = api.UniformType_Float
}
uniforms = append(uniforms, &api.Uniform{
UniformLocation: uint32(activeUniform.Locations().Get(0)),
Name: activeUniform.Name(),
Format: uniformFormat,
Type: uniformType,
Value: box.NewValue(uniformValue(ctx, s, uniformType, activeUniform.Value())),
})
}
}
sort.Slice(shaders, func(i, j int) bool { return shaders[i].Type < shaders[j].Type })
sort.Slice(uniforms, func(i, j int) bool { return uniforms[i].UniformLocation < uniforms[j].UniformLocation })
return api.NewResourceData(&api.Program{Shaders: shaders, Uniforms: uniforms}), nil
}
func uniformValue(ctx context.Context, s *api.GlobalState, kind api.UniformType, data U8ˢ) interface{} {
r := data.Reader(ctx, s)
switch kind {
case api.UniformType_Int32:
a := make([]int32, data.Size()/4)
for i := 0; i < len(a); i++ {
a[i] = r.Int32()
}
return a
case api.UniformType_Uint32:
a := make([]uint32, data.Size()/4)
for i := 0; i < len(a); i++ {
a[i] = r.Uint32()
}
return a
case api.UniformType_Bool:
a := make([]bool, data.Size()/4)
for i := 0; i < len(a); i++ {
a[i] = r.Int32() != 0
}
return a
case api.UniformType_Float:
a := make([]float32, data.Size()/4)
for i := 0; i < len(a); i++ {
a[i] = r.Float32()
}
return a
case api.UniformType_Double:
a := make([]float64, data.Size()/8)
for i := 0; i < len(a); i++ {
a[i] = r.Float64()
}
return a
default:
panic(fmt.Errorf("Can't box uniform data type %v", kind))
}
}
func (p Programʳ) SetResourceData(
ctx context.Context,
at *path.Command,
data *api.ResourceData,
resources api.ResourceMap,
edits api.ReplaceCallback,
mutate api.MutateInitialState,
r *path.ResolveConfig) error {
return fmt.Errorf("SetResourceData is not supported for Program")
}