Skip to content

Commit 4f2ef4c

Browse files
quaglacopybara-github
authored andcommitted
Move image flipping to render context base class.
PiperOrigin-RevId: 734072160 Change-Id: I8735d9619f3a344a9eef607ef2423c6b1b1c9b4a
1 parent 13c9be9 commit 4f2ef4c

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

dm_control/_render/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def _import_glfw():
4545
def _import_osmesa():
4646
from dm_control._render.pyopengl.osmesa_renderer import OSMesaContext
4747
return OSMesaContext
48+
49+
50+
# Import removed.
4851
# pylint: enable=g-import-not-at-top
4952

5053

@@ -59,6 +62,7 @@ def no_renderer(*args, **kwargs):
5962
(constants.GLFW, _import_glfw),
6063
(constants.EGL, _import_egl),
6164
(constants.OSMESA, _import_osmesa),
65+
# Option removed.
6266
)
6367

6468
_NO_RENDERER = (

dm_control/_render/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
from absl import logging
3737
from dm_control._render import executor
38+
import numpy as np
39+
3840

3941
_CURRENT_CONTEXT_FOR_THREAD = collections.defaultdict(lambda: None)
4042
_CURRENT_THREAD_FOR_CONTEXT = collections.defaultdict(lambda: None)
@@ -147,6 +149,10 @@ def make_current(self):
147149
ctx.call(self._platform_make_current)
148150
yield ctx
149151

152+
def to_pixels(self, buffer):
153+
"""Converts the buffer to pixels."""
154+
return np.flipud(buffer)
155+
150156
@abc.abstractmethod
151157
def _platform_init(self, max_width, max_height):
152158
"""Performs an implementation-specific context initialization."""

dm_control/_render/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828
OSMESA = ('osmesa',)
2929
GLFW = ('glfw', 'on', 'enable', 'enabled', 'true', '1', '')
3030
EGL = ('egl',)
31+
# Constant removed.
3132
NO_RENDERER = ('off', 'disable', 'disabled', 'false', '0')
3233

dm_control/mujoco/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def render(
921921
image = self._rgb_buffer
922922

923923
# The first row in the buffer is the bottom row of pixels in the image.
924-
return np.flipud(image)
924+
return self._physics.contexts.gl.to_pixels(image)
925925

926926
def select(self, cursor_position):
927927
"""Returns bodies and geoms visible at given coordinates in the frame.

dm_control/viewer/renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def render(self, viewport, scene):
181181

182182
with self._surface.make_current() as ctx:
183183
ctx.call(self._render_on_gl_thread, viewport, scene)
184-
self._pixels = np.flipud(self._rgb_buffer)
184+
self._pixels = self._surface.to_pixels(self._rgb_buffer)
185185

186186
def _render_on_gl_thread(self, viewport, scene):
187187
mujoco.mjr_setBuffer(mujoco.mjtFramebuffer.mjFB_OFFSCREEN,

0 commit comments

Comments
 (0)