def test_init(self): mock_context = mock.MagicMock() with mock.patch(CONTEXT_PATH) as mock_osmesa: mock_osmesa.OSMesaCreateContextExt.return_value = mock_context renderer = _render.Renderer(MAX_WIDTH, MAX_HEIGHT) self.assertIs(renderer._context, mock_context) renderer.free()
def test_freeing(self): mock_context = mock.MagicMock() with mock.patch(CONTEXT_PATH) as mock_osmesa: mock_osmesa.OSMesaCreateContextExt.return_value = mock_context renderer = _render.Renderer(MAX_WIDTH, MAX_HEIGHT) renderer.free() mock_osmesa.OSMesaDestroyContext.assert_called_once_with(mock_context) self.assertIsNone(renderer._context)
def test_freeing(self): mock_context = mock.MagicMock() with mock.patch(CONTEXT_PATH) as mock_glfw: mock_glfw.create_window.return_value = mock_context renderer = _render.Renderer(MAX_WIDTH, MAX_HEIGHT) renderer.free() mock_glfw.destroy_window.assert_called_once_with(mock_context) self.assertIsNone(renderer._context)
def test_make_current(self): mock_context = mock.MagicMock() with mock.patch(CONTEXT_PATH) as mock_glfw: mock_glfw.create_window.return_value = mock_context renderer = _render.Renderer(MAX_WIDTH, MAX_HEIGHT) with renderer.make_current(): pass mock_glfw.make_context_current.assert_called_once_with(mock_context)
def _make_rendering_contexts(self): """Creates the OpenGL and MuJoCo rendering contexts.""" # Get the offscreen framebuffer size, as specified in the model XML. max_width = self.model.vis.global_.offwidth max_height = self.model.vis.global_.offheight # Create the OpenGL context. render_context = _render.Renderer(max_width=max_width, max_height=max_height) # Create the MuJoCo context. mujoco_context = wrapper.MjrContext(self.model, render_context) self._contexts = Contexts(gl=render_context, mujoco=mujoco_context)
def load_model(self, physics): """Loads the given Physics object to render.""" self._viewer.deinitialize() self._draw_surface = dm_render.Renderer( max_width=_MAX_RENDERBUFFER_SIZE, max_height=_MAX_RENDERBUFFER_SIZE) self._renderer = dm_viewer.renderer.OffScreenRenderer( physics.model, self._draw_surface) self._viewer.initialize(physics, self._renderer, touchpad=False)
def test_make_current(self): mock_context = mock.MagicMock() mock_buffer = mock.MagicMock() with mock.patch(CONTEXT_PATH) as mock_osmesa: with mock.patch(GL_ARRAYS_PATH) as mock_glarrays: mock_osmesa.OSMesaCreateContextExt.return_value = mock_context mock_glarrays.GLfloatArray.zeros.return_value = mock_buffer renderer = _render.Renderer(MAX_WIDTH, MAX_HEIGHT) with renderer.make_current(): pass mock_osmesa.OSMesaMakeCurrent.assert_called_once_with( mock_context, mock_buffer, GL.GL_FLOAT, MAX_WIDTH, MAX_HEIGHT) renderer.free()
def _make_rendering_contexts(self): """Creates the OpenGL and MuJoCo rendering contexts.""" # Forcibly clear the previous GL context to avoid problems with GL # implementations which do not support multiple contexts on a given device. if self._contexts: self._contexts.mujoco.free() self._contexts.gl.free() # Get the offscreen framebuffer size, as specified in the model XML. max_width = self.model.vis.global_.offwidth max_height = self.model.vis.global_.offheight # Create the OpenGL context. render_context = _render.Renderer(max_width=max_width, max_height=max_height) # Create the MuJoCo context. mujoco_context = wrapper.MjrContext(self.model, render_context) self._contexts = Contexts(gl=render_context, mujoco=mujoco_context)
def testFreeMjrContext(self): for _ in range(5): renderer = _render.Renderer(640, 480) with mock.patch.object( core.mjlib, "mjr_freeContext", wraps=mjlib.mjr_freeContext) as mock_destructor: mjr_context = core.MjrContext(self.model, renderer) expected_address = ctypes.addressof(mjr_context.ptr.contents) mjr_context.free() self.assertIsNone(mjr_context.ptr) mock_destructor.assert_called_once() pointer = mock_destructor.call_args[0][0] actual_address = ctypes.addressof(pointer.contents) self.assertEqual(expected_address, actual_address) # Explicit freeing should not break any automatic GC triggered later. del mjr_context renderer.free() del renderer gc.collect()
def _perform_deferred_reload(self, params): """Performs the deferred part of initialization related to Physics reload. Args: params: Deferred reload parameters, an instance of ReloadParams. """ if self._render_surface: self._render_surface.free() if self._renderer: self._renderer.release() self._render_surface = _render.Renderer( max_width=_MAX_FRONTBUFFER_SIZE, max_height=_MAX_FRONTBUFFER_SIZE) self._renderer = renderer.OffScreenRenderer( self._environment.physics.model, self._render_surface) self._renderer.components += self._viewer_layout self._viewer.initialize(self._environment.physics, self._renderer, touchpad=False) self._status.set_camera(self._viewer.camera) if params.zoom_to_scene: self._viewer.zoom_to_scene()
def test_repeatedly_create_and_destroy_context(self): renderer = _render.Renderer(MAX_WIDTH, MAX_HEIGHT) wrapper.MjrContext(wrapper.MjModel.from_xml_string('<mujoco/>'), renderer)
def test_init(self): mock_context = mock.MagicMock() with mock.patch(CONTEXT_PATH) as mock_glfw: mock_glfw.create_window.return_value = mock_context renderer = _render.Renderer(MAX_WIDTH, MAX_HEIGHT) self.assertIs(renderer._context, mock_context)