-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
111 lines (101 loc) · 3.72 KB
/
state.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
// 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 (
"fmt"
"github.com/google/gapid/gapis/api"
)
// fbai is the result getFramebufferAttachmentInfo.
type fbai struct {
width uint32
height uint32
sizedFormat GLenum
internalFormat GLenum // These are GL_NONE, unless the attachement is a texture
format GLenum // that was initialized with a buffer of this internal
ty GLenum // format, format and type.
multisampled bool
}
func attachmentToEnum(a api.FramebufferAttachment) (GLenum, error) {
switch a {
case api.FramebufferAttachment_Color0:
return GLenum_GL_COLOR_ATTACHMENT0, nil
case api.FramebufferAttachment_Color1:
return GLenum_GL_COLOR_ATTACHMENT1, nil
case api.FramebufferAttachment_Color2:
return GLenum_GL_COLOR_ATTACHMENT2, nil
case api.FramebufferAttachment_Color3:
return GLenum_GL_COLOR_ATTACHMENT3, nil
case api.FramebufferAttachment_Depth:
return GLenum_GL_DEPTH_ATTACHMENT, nil
case api.FramebufferAttachment_Stencil:
return GLenum_GL_STENCIL_ATTACHMENT, nil
default:
return 0, fmt.Errorf("Framebuffer attachment %v unsupported by gles", a)
}
}
func (f Framebufferʳ) getAttachment(a GLenum) (FramebufferAttachment, error) {
switch a {
case GLenum_GL_DEPTH_ATTACHMENT, GLenum_GL_DEPTH_STENCIL_ATTACHMENT:
return f.DepthAttachment(), nil
case GLenum_GL_STENCIL_ATTACHMENT:
return f.StencilAttachment(), nil
default:
if a >= GLenum_GL_COLOR_ATTACHMENT0 && a < GLenum_GL_COLOR_ATTACHMENT0+64 {
return f.ColorAttachments().Get(GLint(a - GLenum_GL_COLOR_ATTACHMENT0)), nil
}
return FramebufferAttachment{}, fmt.Errorf("Unhandled attachment: %v", a)
}
}
// TODO: When gfx api macros produce functions instead of inlining, move this logic
// to the gles.api file.
func (s *State) getFramebufferAttachmentInfo(thread uint64, fb FramebufferId, att GLenum) (fbai, error) {
c := s.GetContext(thread)
if c.IsNil() {
return fbai{}, fmt.Errorf("No context bound")
}
if !c.Other().Initialized() {
return fbai{}, fmt.Errorf("Context not initialized")
}
framebuffer, ok := c.Objects().Framebuffers().Lookup(fb)
if !ok {
return fbai{}, fmt.Errorf("Invalid framebuffer %v", fb)
}
a, err := framebuffer.getAttachment(att)
if err != nil {
return fbai{}, err
}
switch a.Type() {
case GLenum_GL_NONE:
return fbai{}, fmt.Errorf("%s is not bound", att)
case GLenum_GL_TEXTURE:
t := a.Texture()
l := t.Levels().Get(a.TextureLevel()).Layers().Get(a.TextureLayer())
if l.IsNil() {
return fbai{}, fmt.Errorf("Texture %v does not have Level[%v].Layer[%v]",
t.ID(), a.TextureLevel(), a.TextureLayer())
}
multisampled := l.Samples() > 0
return fbai{uint32(l.Width()), uint32(l.Height()), l.SizedFormat(), l.InternalFormat(), l.DataFormat(), l.DataType(), multisampled}, nil
case GLenum_GL_RENDERBUFFER:
r := a.Renderbuffer()
l := r.Image()
if l.IsNil() {
return fbai{}, fmt.Errorf("Renderbuffer %v does not have any image date", r.ID())
}
multisampled := l.Samples() > 0
return fbai{uint32(l.Width()), uint32(l.Height()), l.SizedFormat(), GLenum_GL_NONE, GLenum_GL_NONE, GLenum_GL_NONE, multisampled}, nil
default:
return fbai{}, fmt.Errorf("Unknown framebuffer attachment type %T", a.Type())
}
}