MCPcopy
hub / github.com/zju3dv/4K4D / test_eglctx_auto_fbo_rbo

Function test_eglctx_auto_fbo_rbo

tests/headless_opengl_tests.py:244–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

242
243
244def 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
291if __name__ == '__main__':

Callers

nothing calls this directly

Calls 7

offscreen_renderMethod · 0.95
CameraClass · 0.90
MeshClass · 0.90
save_imageFunction · 0.90
linearize_depthFunction · 0.90
blueFunction · 0.85
logFunction · 0.50

Tested by

no test coverage detected