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

Function test_gl_quad_blit

tests/headless_opengl_tests.py:113–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

111
112
113def test_gl_quad_blit():
114 gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
115
116 quad = Quad(H=HEIGHT, W=WIDTH)
117 data = np.random.randint(0, 255, (HEIGHT, WIDTH, 4), dtype=np.uint8)
118
119 data[10:20, 10:20] = [255, 0, 0, 255]
120 data[20:30, 10:20] = [0, 255, 0, 255]
121 data[10:20, 20:30] = [0, 0, 255, 255]
122 data[20:30, 20:30] = [255, 255, 255, 255]
123 data = data[::-1] # flip 0
124 data = np.asarray(data, order='C')
125
126 quad.upload_to_texture(data) # upload the pointer
127 quad.blit() # no camera to render
128
129 # Read result
130 img_buf = gl.glReadPixels(0, 0, WIDTH, HEIGHT, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE)
131 img = np.frombuffer(img_buf, np.uint8).reshape(HEIGHT, WIDTH, 4)[::-1]
132
133 img_path = 'test_gl_quad_blit.png'
134 save_image(img_path, img)
135 log(f'Quad blit image saved at: {blue(img_path)}')
136
137 assert img[10, 10, :3].argmax() == 0 # red corner
138 assert img[20, 10, :3].argmax() == 1 # green corner
139 assert img[10, 20, :3].argmax() == 2 # blue corner
140 assert all(img[20, 20] == 255) # white corner
141
142
143def test_gl_quad_draw():

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected