Repository: Genesis-Embodied-AI/Genesis
File: tests/test_render.py (Python)

Code before:
                break
            time.sleep(0.1)
        else:
            raise AssertionError("Keyboard event not processed before timeout")
    else:
        pyrender_viewer.dispatch_pending_events()
        pyrender_viewer.dispatch_events()

    # Skip the rest of the test if necessary
    if sys.platform == "linux":
        glinfo = pyrender_viewer.context.get_info()
        renderer = glinfo.get_renderer()
        if "llvmpipe" in renderer:
            llvm_version = re.search(r"LLVM\s+([\d.]+)", renderer).group(1)
            if llvm_version < "20":
                pytest.xfail("Text is blurry on Linux using old CPU-based Mesa rendering driver.")

    # Make sure that the result is valid
    with open(IMAGE_FILENAME, "rb") as f:
        assert f.read() == png_snapshot


@pytest.mark.required
@pytest.mark.parametrize(
    "renderer_type",
    [RENDERER_TYPE.BATCHRENDER_RASTERIZER],
)
def test_render_planes(tmp_path, png_snapshot, renderer):
    # Manually run this test with different parameters to make sure they run sequentially
    # Running in parallel may crash the test OOM.
    sizes = [(1.5, 1.8), (10.0, 7.0)]
    n_tiles = [(0.5, 0.75), (5.0, 3.0), None]
    for test_idx, (size, n_tiles) in enumerate(itertools.product(sizes, n_tiles)):
        CAM_RES = (512, 512)
        NUM_STEPS = 1
        scene = gs.Scene(
            renderer=renderer,
        )
        plane = scene.add_entity(
            gs.morphs.Plane(size=size, n_tiles=n_tiles),
        )
        camera = scene.add_camera(
            res=CAM_RES,
            pos=(1.5, 0.5, 1.5),
            lookat=(0.0, 0.0, 0.5),
            fov=45,
            GUI=False,
        )
        scene.add_light(
            pos=[0.0, 0.0, 1.5],
            dir=[1.0, 1.0, -2.0],

Review comment (performance):
Use `RENDERER_TYPE.RASTERIZER` if possible, because it works on all platforms unlike `RENDERER_TYPE.BATCHRENDER_*`

Code after:
                break
            time.sleep(0.1)
        else:
            raise AssertionError("Keyboard event not processed before timeout")
    else:
        pyrender_viewer.dispatch_pending_events()
        pyrender_viewer.dispatch_events()

    # Skip the rest of the test if necessary
    if sys.platform == "linux":
        glinfo = pyrender_viewer.context.get_info()
        renderer = glinfo.get_renderer()
        if "llvmpipe" in renderer:
            llvm_version = re.search(r"LLVM\s+([\d.]+)", renderer).group(1)
            if llvm_version < "20":
                pytest.xfail("Text is blurry on Linux using old CPU-based Mesa rendering driver.")

    # Make sure that the result is valid
    with open(IMAGE_FILENAME, "rb") as f:
        assert f.read() == png_snapshot


@pytest.mark.parametrize(
    "renderer_type",
    [RENDERER_TYPE.RASTERIZER],
)
def test_render_planes(tmp_path, png_snapshot, renderer):
    for test_idx, (plane_size, tile_size) in enumerate(
        (
            ((3, 4.5), (0.5, 0.75)),
            ((3.0, 5.0), (5.0, 3.0)),
            ((4.0, 4.0), (1.0, 1.0)),
        )
    ):
        CAM_RES = (256, 256)
        scene = gs.Scene(
            renderer=renderer,
        )
        plane = scene.add_entity(
            gs.morphs.Plane(plane_size=plane_size, tile_size=tile_size),
        )
        camera = scene.add_camera(
            res=CAM_RES,
            pos=(0.0, 0.0, 8),
            lookat=(0.0, 0.0, 0.0),
            fov=45,
            GUI=False,
        )
        scene.build()

        exporter = FrameImageExporter(tmp_path)