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

Code before:

    # 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],
            directional=1,
            castshadow=1,
            cutoff=45.0,
            intensity=0.5,
        )
        scene.build()


Review comment (suggestion):
Are you sure you need a full grid? What about:
```
for test_idx, (size, n_tiles) in enumerate((
    ((1.5, 1.8), (0.5, 0.75)),
    ((10.0, 7.0), (5.0, 3.0)),
    ((10.0, 7.0), None),
)):
```

Code after:

    # 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)
        rgba, depth, _, _ = camera.render(rgb=True, depth=False)
        exporter.export_frame_single_camera(test_idx, camera.idx, rgb=rgba, depth=depth)

    for image_file in sorted(tmp_path.rglob("*.png")):
        with open(image_file, "rb") as f:
            assert f.read() == png_snapshot