()
| 242 | |
| 243 | |
| 244 | def test_eglctx_auto_fbo_rbo(): |
| 245 | render_w = 1024 |
| 246 | render_h = 1024 |
| 247 | gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) |
| 248 | |
| 249 | mesh_path = 'assets/meshes/bunny.ply' |
| 250 | img_path = 'test_eglctx_auto_fbo_rbo.png' |
| 251 | dpt_path = 'test_eglctx_auto_fbo_rbo_dpt.png' |
| 252 | camera = Camera(H=render_h, W=render_w, |
| 253 | K=torch.tensor([[render_w * 592 / 512, 0., render_w / 2], |
| 254 | [0., render_h * 592 / 512, render_h / 2], |
| 255 | [0., 0., 1.]]), |
| 256 | R=torch.tensor([[0.9908, -0.1353, 0.0000], |
| 257 | [-0.1341, -0.9815, -0.1365], |
| 258 | [0.0185, 0.1353, -0.9906]]), |
| 259 | T=torch.tensor([[0.0178], |
| 260 | [0.0953], |
| 261 | [0.3137]]), |
| 262 | n=0.02, |
| 263 | f=1, |
| 264 | ) |
| 265 | mesh = Mesh(filename=mesh_path, shade_flat=False) |
| 266 | mesh.offscreen_render(eglctx, camera) |
| 267 | |
| 268 | # Read result |
| 269 | gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT0) |
| 270 | img_buf = gl.glReadPixels(0, 0, render_w, render_h, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE) |
| 271 | img = np.frombuffer(img_buf, np.uint8).reshape(render_h, render_w, 4)[::-1] |
| 272 | save_image(img_path, img) |
| 273 | log(f'Rendered image saved at: {blue(img_path)}') |
| 274 | |
| 275 | # Read result |
| 276 | # gl.glReadBuffer(gl.GL_COLOR_ATTACHMENT1) |
| 277 | # dpt_buf = gl.glReadPixels(0, 0, render_w, render_h, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE) # lost precision... |
| 278 | # dpt = np.frombuffer(dpt_buf, np.uint8).reshape(render_h, render_w, 4)[::-1] |
| 279 | # dpt = dpt[..., 0] / 1 + dpt[..., 0] / 256 + dpt[..., 0] / 65536 + dpt[..., 0] / 16777216 |
| 280 | dpt_buf = gl.glReadPixels(0, 0, render_w, render_h, gl.GL_DEPTH_COMPONENT, gl.GL_FLOAT) # lost precision... # MARK: SYNC |
| 281 | # gl.glBindTexture(gl.GL_TEXTURE_2D, eglctx.tex_dpt) |
| 282 | # dpt_buf = gl.glGetTexImage(gl.GL_TEXTURE_2D, 0, gl.GL_DEPTH_COMPONENT, gl.GL_FLOAT) |
| 283 | dpt = np.frombuffer(dpt_buf, np.float32).reshape(render_h, render_w, 1)[::-1] |
| 284 | dpt = linearize_depth(dpt, camera.n, camera.f) # this is the z component in camera coordinates |
| 285 | dpt = (dpt.min() - dpt) / (dpt.min() - dpt.max()) |
| 286 | |
| 287 | save_image(dpt_path, dpt) |
| 288 | log(f'Rendered depth saved at: {blue(dpt_path)}') |
| 289 | |
| 290 | |
| 291 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected