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

Code before:
                raise
        frames_prev = frame_data

        # Add current frame to monitor video
        rgb_debug, *_ = cam_debug.render(rgb=True, depth=False, segmentation=False, colorize_seg=False, normal=False)
        assert isinstance(rgb_debug, np.ndarray)
        assert rgb_debug.shape == (480, 640, 3)

    assert len(cam_debug._recorded_imgs) == NUM_STEPS
    cam_debug.stop_recording(save_to_filename=(tmp_path / "video.mp4"))

    # Verify that the output is correct pixel-wise over multiple simulation steps
    try:
        for image_file in sorted(tmp_path.rglob("*.png")):
            with open(image_file, "rb") as f:
                assert f.read() == png_snapshot
    except AssertionError:
        if sys.platform == "darwin" and scene.visualizer._rasterizer._renderer._is_software:
            pytest.xfail("Flaky on MacOS with Apple Software Renderer. Pixel-matching failure.")
        raise


@pytest.mark.required
@pytest.mark.parametrize("renderer_type", [RENDERER_TYPE.BATCHRENDER_RASTERIZER, RENDERER_TYPE.BATCHRENDER_RAYTRACER])
@pytest.mark.parametrize("camera_model", ["pinhole", "fisheye"])
def test_madrona(show_viewer, png_snapshot, renderer, camera_model):
    CAM_RES = (128, 128)

    scene = gs.Scene(
        renderer=renderer,
        show_viewer=show_viewer,
        show_FPS=False,
    )
    scene.add_entity(
        gs.morphs.Plane(),
        surface=gs.surfaces.Default(  # Madrona use case 1: Batch Texture
            diffuse_texture=gs.textures.BatchTexture.from_images(image_folder="textures"),
        ),
    )

    scene.add_entity(
        gs.morphs.MJCF(file="xml/franka_emika_panda/panda.xml"),
    )
    cam = scene.add_camera(
        res=CAM_RES,
        pos=(1.5, -0.5, 1.5),
        lookat=(0.0, 0.0, 0.5),
        fov=45,
        model=camera_model,  # Madrona use case 2: Fisheye camera
        GUI=show_viewer,
    )

Review comment (bug):
I would suggest to define some helper method:

```python
def _create_scene_batch_render(show_viewer, renderer, camera_model):
    [...]
```

Then define 2 completely independent unit test for batch texture and camera types. This way, it would be easier to diagnose the issue in case of CI failure.

Code after:
                raise
        frames_prev = frame_data

        # Add current frame to monitor video
        rgb_debug, *_ = cam_debug.render(rgb=True, depth=False, segmentation=False, colorize_seg=False, normal=False)
        assert isinstance(rgb_debug, np.ndarray)
        assert rgb_debug.shape == (480, 640, 3)

    assert len(cam_debug._recorded_imgs) == NUM_STEPS
    cam_debug.stop_recording(save_to_filename=(tmp_path / "video.mp4"))

    # Verify that the output is correct pixel-wise over multiple simulation steps
    try:
        for image_file in sorted(tmp_path.rglob("*.png")):
            with open(image_file, "rb") as f:
                assert f.read() == png_snapshot
    except AssertionError:
        if sys.platform == "darwin" and scene.visualizer._rasterizer._renderer._is_software:
            pytest.xfail("Flaky on MacOS with Apple Software Renderer. Pixel-matching failure.")
        raise


def _test_madrona_scene(
    show_viewer,
    renderer,
    png_snapshot,
    use_batch_texture=False,
    use_fisheye_camera=False,
    use_directional_light=False,
    n_envs=2,
):
    CAM_RES = (128, 128)

    scene = gs.Scene(
        renderer=renderer,
        show_viewer=show_viewer,
        show_FPS=False,
    )

    # entities
    surface = (
        gs.surfaces.Default(diffuse_texture=gs.textures.BatchTexture.from_images(image_folder="textures"))
        if use_batch_texture
        else None
    )
    scene.add_entity(gs.morphs.Plane(), surface=surface)
    scene.add_entity(gs.morphs.MJCF(file="xml/franka_emika_panda/panda.xml"))

    # cameras
    cam = scene.add_camera(
        res=CAM_RES,