Skip to content
Snippets Groups Projects
Commit 649d964d authored by A Ray's avatar A Ray Committed by Million Integrals
Browse files

add option to suppress printing when creating context (#377)

parent 41a5fc26
No related branches found
No related tags found
No related merge requests found
...@@ -40,9 +40,9 @@ cdef class MjRenderContext(object): ...@@ -40,9 +40,9 @@ cdef class MjRenderContext(object):
mjv_defaultOption(&self._vopt) mjv_defaultOption(&self._vopt)
mjr_defaultContext(&self._con) mjr_defaultContext(&self._con)
def __init__(self, MjSim sim, bint offscreen=True, int device_id=-1, opengl_backend=None): def __init__(self, MjSim sim, bint offscreen=True, int device_id=-1, opengl_backend=None, quiet=False):
self.sim = sim self.sim = sim
self._setup_opengl_context(offscreen, device_id, opengl_backend) self._setup_opengl_context(offscreen, device_id, opengl_backend, quiet=quiet)
self.offscreen = offscreen self.offscreen = offscreen
# Ensure the model data has been updated so that there # Ensure the model data has been updated so that there
...@@ -92,13 +92,13 @@ cdef class MjRenderContext(object): ...@@ -92,13 +92,13 @@ cdef class MjRenderContext(object):
raise RuntimeError('Window rendering not supported') raise RuntimeError('Window rendering not supported')
self.con = WrapMjrContext(&self._con) self.con = WrapMjrContext(&self._con)
def _setup_opengl_context(self, offscreen, device_id, opengl_backend): def _setup_opengl_context(self, offscreen, device_id, opengl_backend, quiet=False):
if opengl_backend is None and (not offscreen or sys.platform == 'darwin'): if opengl_backend is None and (not offscreen or sys.platform == 'darwin'):
# default to glfw for onscreen viewing or mac (both offscreen/onscreen) # default to glfw for onscreen viewing or mac (both offscreen/onscreen)
opengl_backend = 'glfw' opengl_backend = 'glfw'
if opengl_backend == 'glfw': if opengl_backend == 'glfw':
self.opengl_context = GlfwContext(offscreen=offscreen) self.opengl_context = GlfwContext(offscreen=offscreen, quiet=quiet)
else: else:
if device_id < 0: if device_id < 0:
if "GPUS" in os.environ: if "GPUS" in os.environ:
......
...@@ -40,12 +40,12 @@ class GlfwContext(OpenGLContext): ...@@ -40,12 +40,12 @@ class GlfwContext(OpenGLContext):
_INIT_HEIGHT = 1000 _INIT_HEIGHT = 1000
_GLFW_IS_INITIALIZED = False _GLFW_IS_INITIALIZED = False
def __init__(self, offscreen=False): def __init__(self, offscreen=False, quiet=False):
GlfwContext._init_glfw() GlfwContext._init_glfw()
self._width = self._INIT_WIDTH self._width = self._INIT_WIDTH
self._height = self._INIT_HEIGHT self._height = self._INIT_HEIGHT
self.window = self._create_window(offscreen) self.window = self._create_window(offscreen, quiet=quiet)
self._set_window_size(self._width, self._height) self._set_window_size(self._width, self._height)
@staticmethod @staticmethod
...@@ -73,14 +73,16 @@ class GlfwContext(OpenGLContext): ...@@ -73,14 +73,16 @@ class GlfwContext(OpenGLContext):
self._width = width self._width = width
self._height = height self._height = height
def _create_window(self, offscreen): def _create_window(self, offscreen, quiet=False):
if offscreen: if offscreen:
print("Creating offscreen glfw") if not quiet:
print("Creating offscreen glfw")
glfw.window_hint(glfw.VISIBLE, 0) glfw.window_hint(glfw.VISIBLE, 0)
glfw.window_hint(glfw.DOUBLEBUFFER, 0) glfw.window_hint(glfw.DOUBLEBUFFER, 0)
init_width, init_height = self._INIT_WIDTH, self._INIT_HEIGHT init_width, init_height = self._INIT_WIDTH, self._INIT_HEIGHT
else: else:
print("Creating window glfw") if not quiet:
print("Creating window glfw")
glfw.window_hint(glfw.SAMPLES, 4) glfw.window_hint(glfw.SAMPLES, 4)
glfw.window_hint(glfw.VISIBLE, 1) glfw.window_hint(glfw.VISIBLE, 1)
glfw.window_hint(glfw.DOUBLEBUFFER, 1) glfw.window_hint(glfw.DOUBLEBUFFER, 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment