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

Function test_gl_quad_draw

tests/headless_opengl_tests.py:143–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141
142
143def test_gl_quad_draw():
144 gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
145
146 quad = Quad(H=HEIGHT, W=WIDTH)
147 data = np.random.randint(0, 255, (HEIGHT, WIDTH, 4), dtype=np.uint8)
148
149 data[-20:-10, -20:-10] = [255, 0, 0, 255]
150 data[-30:-20, -20:-10] = [0, 255, 0, 255]
151 data[-20:-10, -30:-20] = [0, 0, 255, 255]
152 data[-30:-20, -30:-20] = [255, 255, 255, 255]
153 data = data[::-1] # flip 0
154 data = np.asarray(data, order='C')
155
156 quad.upload_to_texture(data) # upload the pointer
157 quad.draw() # no camera to render
158
159 # Read result
160 img_buf = gl.glReadPixels(0, 0, WIDTH, HEIGHT, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE)
161 img = np.frombuffer(img_buf, np.uint8).reshape(HEIGHT, WIDTH, 4)[::-1]
162
163 img_path = 'test_gl_quad_draw.png'
164 save_image(img_path, img)
165 log(f'Quad draw image saved at: {blue(img_path)}')
166
167 assert img[-20, -20, :3].argmax() == 0 # red corner
168 assert img[-30, -20, :3].argmax() == 1 # green corner
169 assert img[-20, -30, :3].argmax() == 2 # blue corner
170 assert all(img[-30, -30] == 255) # white corner
171
172
173def test_eglctx_manual_fbo_rbo(): # TODO: BLACK RESULTS ON WSL (BUT COULD RENDER WITHOUT RESIZING)

Callers

nothing calls this directly

Calls 6

upload_to_textureMethod · 0.95
drawMethod · 0.95
QuadClass · 0.90
save_imageFunction · 0.90
blueFunction · 0.85
logFunction · 0.50

Tested by

no test coverage detected