MCPcopy Create free account
hub / github.com/google/gapid / copyDepthToColorGLES

Function copyDepthToColorGLES

gapis/api/gles/read_depth.go:29–147  ·  view source on GitHub ↗

copyDepthToColorGLES emmits commands that will copy the depth data of the current read framebuffer into an new framebuffer (which is left bound as the read framebuffer upon exit) as the color attachment in R32F format, allowing it to be read via glReadPixels.

(ctx context.Context, dID api.CmdID, thread uint64, s *api.GlobalState, out transform.Writer, t *tweaker, fbai fbai, width, height int32)

Source from the content-addressed store, hash-verified

27// read framebuffer upon exit) as the color attachment in R32F format, allowing
28// it to be read via glReadPixels.
29func copyDepthToColorGLES(ctx context.Context, dID api.CmdID, thread uint64, s *api.GlobalState, out transform.Writer, t *tweaker, fbai fbai, width, height int32) {
30 const (
31 aScreenCoordsLocation AttributeLocation = 0
32 aScreenCoords = "aScreenCoords"
33 uTextureLocation UniformLocation = 0
34 uTexture = "uTexture"
35
36 vertexShaderSource string = `
37 #version 300 es
38
39 precision highp float;
40 in vec2 aScreenCoords;
41 out vec2 uv;
42
43 void main() {
44 uv = (aScreenCoords + 1.0) / 2.0;
45 gl_Position = vec4(aScreenCoords.xy, 0., 1.);
46 }`
47 fragmentShaderSource string = `
48 #version 300 es
49
50 precision highp float;
51 uniform sampler2D uTexture;
52 in vec2 uv;
53 out vec4 fragColor;
54
55 void main() {
56 fragColor = texture(uTexture, uv);
57 }`
58 )
59
60 // 2D vertices positions for a full screen 2D triangle strip.
61 positions := []float32{-1., -1., 1., -1., -1., 1., 1., 1.}
62 ws, hs := GLsizei(width), GLsizei(height)
63 wi, hi := GLint(width), GLint(height)
64
65 cb := CommandBuilder{Thread: thread, Arena: s.Arena}
66
67 // Create a framebuffer with a depth texture and blit.
68 fb := t.glGenFramebuffer(ctx)
69 tex := t.glGenTexture(ctx)
70 t.glActiveTexture(ctx, GLenum_GL_TEXTURE0)
71 t.glBindTexture_2D(ctx, tex)
72 out.MutateAndWrite(ctx, dID, cb.GlTexParameteri(GLenum_GL_TEXTURE_2D, GLenum_GL_TEXTURE_MIN_FILTER, GLint(GLenum_GL_NEAREST)))
73 out.MutateAndWrite(ctx, dID, cb.GlTexParameteri(GLenum_GL_TEXTURE_2D, GLenum_GL_TEXTURE_MAG_FILTER, GLint(GLenum_GL_NEAREST)))
74 if fbai.internalFormat != GLenum_GL_NONE && fbai.internalFormat != fbai.sizedFormat {
75 out.MutateAndWrite(ctx, dID, cb.GlTexImage2D(GLenum_GL_TEXTURE_2D, 0, GLint(fbai.internalFormat), ws, hs, 0, fbai.format, fbai.ty, memory.Nullptr))
76 } else {
77 out.MutateAndWrite(ctx, dID, cb.GlTexStorage2D(GLenum_GL_TEXTURE_2D, 1, fbai.sizedFormat, ws, hs))
78 }
79 t.glBindFramebuffer_Draw(ctx, fb)
80 out.MutateAndWrite(ctx, dID, cb.GlFramebufferTexture2D(GLenum_GL_DRAW_FRAMEBUFFER, GLenum_GL_DEPTH_ATTACHMENT, GLenum_GL_TEXTURE_2D, tex, 0))
81 out.MutateAndWrite(ctx, dID, cb.GlBlitFramebuffer(0, 0, wi, hi, 0, 0, wi, hi, GLbitfield_GL_DEPTH_BUFFER_BIT, GLenum_GL_NEAREST))
82
83 // Detach the depth texture from the FB and attach a color renderbuffer.
84 out.MutateAndWrite(ctx, dID, cb.GlFramebufferTexture2D(GLenum_GL_DRAW_FRAMEBUFFER, GLenum_GL_DEPTH_ATTACHMENT, GLenum_GL_TEXTURE_2D, 0, 0))
85 rb := t.glGenRenderbuffer(ctx)
86 t.glBindRenderbuffer(ctx, rb)

Callers 1

postFBDataFunction · 0.85

Calls 15

glGenFramebufferMethod · 0.80
glGenTextureMethod · 0.80
glActiveTextureMethod · 0.80
glBindTexture_2DMethod · 0.80
glGenRenderbufferMethod · 0.80
glBindRenderbufferMethod · 0.80
glDisableMethod · 0.80
makeVertexArrayMethod · 0.80
glViewportMethod · 0.80
makeProgramMethod · 0.80
PtrMethod · 0.80

Tested by

no test coverage detected