in mujoco_py/mjbatchrenderer.pyx [0:0]
def render(self, sim, camera_id=None, batch_offset=None):
"""
Render current scene from the MjSim into the buffer. By
default the batch offset is automatically incremented with
each call. It can be reset with the batch_offset parameter.
This method doesn't return anything. Use the `.read` method
to read the buffer, or access the buffer pointer directly with
e.g. `.cuda_rgb_buffer_pointer` accessor.
Args:
- sim (MjSim): The simulator to use for rendering.
- camera_id (int): MuJoCo id for the camera, from
`sim.model.camera_name2id()`.
- batch_offset (int): offset in batch to render to.
"""
if self._use_cuda and self._cuda_buffers_are_mapped:
raise CudaBufferMappedError(
"CUDA buffers must be unmapped before calling render.")
if batch_offset is not None:
if batch_offset < 0 or batch_offset >= self._batch_size:
raise ValueError("batch_offset out of range")
self._current_batch_offset = batch_offset
# Ensure the correct device context is used (this takes ~1 µs)
makeOpenGLContextCurrent(self._device_id)
render_context = self.prepare_render_context(sim)
render_context.update_offscreen_size(self._width, self._height)
render_context.render(self._width, self._height, camera_id=camera_id)
cdef mjrRect viewport
viewport.left = 0
viewport.bottom = 0
viewport.width = self._width
viewport.height = self._height
cdef PyMjrContext con = <PyMjrContext> render_context.con
copyFBOToPBO(con.ptr, self.pbo_rgb, self.pbo_depth,
viewport, self._current_batch_offset)
self._current_batch_offset = (self._current_batch_offset + 1) % self._batch_size