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)
| 27 | // read framebuffer upon exit) as the color attachment in R32F format, allowing |
| 28 | // it to be read via glReadPixels. |
| 29 | func 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) |
no test coverage detected