Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 527357d

Browse files
committed
Texture; fix fetch; more explicit fbo creation for it because depth attachments on the render texture broke on WebGL
1 parent 1edd9c4 commit 527357d

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

phoenix/Texture.hx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,18 @@ class Texture extends Resource {
141141
//but we can read the pixels from a temporary frame buffer (render texture) instead
142142
//This way works on all targets the same.
143143

144-
var rt = new RenderTexture({
145-
width: _w,
146-
height: _h,
147-
texture: texture,
148-
id:'temp_fbo / $id'
149-
});
144+
var fb = GL.createFramebuffer();
150145

151-
//activate it and read the pixels out
146+
GL.bindFramebuffer(GL.FRAMEBUFFER, fb);
147+
GL.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
152148

153-
rt.bindBuffer();
149+
assert(GL.checkFramebufferStatus(GL.FRAMEBUFFER) == GL.FRAMEBUFFER_COMPLETE);
154150

155-
GL.readPixels(_x, _y, _w, _h, GL.RGBA, GL.UNSIGNED_BYTE, _into);
151+
GL.readPixels(_x, _y, _w, _h, GL.RGBA, GL.UNSIGNED_BYTE, _into);
156152

157-
rt.unbindBuffer();
158-
159-
//now, make sure that it's texture id is null,
160-
//otherwise destroy will nuke our texture id
161-
162-
rt.texture = null;
163-
rt.destroy();
164-
rt = null;
153+
GL.bindFramebuffer(GL.FRAMEBUFFER, null);
154+
GL.deleteFramebuffer(fb);
155+
fb = null;
165156

166157
return _into;
167158

0 commit comments

Comments
 (0)