Skip to content

Commit

Permalink
[pydrake] Bind RenderEngineGlParams (#16201)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Cousineau <[email protected]>
  • Loading branch information
jwnimmer-tri and EricCousineau-TRI authored Dec 10, 2021
1 parent feedf5d commit 5357d9a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
18 changes: 16 additions & 2 deletions bindings/pydrake/geometry_py_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,25 @@ void DoScalarIndependentDefinitions(py::module m) {
.def_readwrite("default_diffuse", &RenderEngineVtkParams::default_diffuse,
doc.RenderEngineVtkParams.default_diffuse.doc);

m.def("MakeRenderEngineGl", &MakeRenderEngineGl, doc.MakeRenderEngineGl.doc);

m.def("MakeRenderEngineVtk", &MakeRenderEngineVtk, py::arg("params"),
doc.MakeRenderEngineVtk.doc);

{
using Class = RenderEngineGlParams;
constexpr auto& cls_doc = doc.RenderEngineGlParams;
py::class_<Class>(m, "RenderEngineGlParams", cls_doc.doc)
.def(ParamInit<Class>())
.def_readwrite(
"default_label", &Class::default_label, cls_doc.default_label.doc)
.def_readwrite("default_diffuse", &Class::default_diffuse,
cls_doc.default_diffuse.doc)
.def_readwrite("default_clear_color", &Class::default_clear_color,
cls_doc.default_clear_color.doc);
}

m.def("MakeRenderEngineGl", &MakeRenderEngineGl,
py::arg("params") = RenderEngineGlParams(), doc.MakeRenderEngineGl.doc);

{
py::class_<RenderLabel> render_label(m, "RenderLabel", doc.RenderLabel.doc);
render_label
Expand Down
5 changes: 4 additions & 1 deletion bindings/pydrake/test/geometry_render_engine_gl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ class TestGeometry(unittest.TestCase):
def test_render_engine_gl_api(self, T):
SceneGraph = mut.SceneGraph_[T]
scene_graph = SceneGraph()
label = mut.render.RenderLabel(10)
params = mut.render.RenderEngineGlParams(label=label)
if 'darwin' in sys.platform: # OpenGL is not supported on macOS.
self.assertRaises(RuntimeError, mut.render.MakeRenderEngineGl)
else:
scene_graph.AddRenderer("gl_renderer",
mut.render.MakeRenderEngineGl())
mut.render.MakeRenderEngineGl(
params=params))
self.assertTrue(scene_graph.HasRenderer("gl_renderer"))
self.assertEqual(scene_graph.RendererCount(), 1)
16 changes: 16 additions & 0 deletions bindings/pydrake/test/geometry_render_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def test_render_engine_vtk_params(self):
self.assertEqual(params.default_label, label)
self.assertTrue((params.default_diffuse == diffuse).all())

def test_render_engine_gl_params(self):
# A default constructor exists.
mut.render.RenderEngineGlParams()

# The kwarg constructor also works.
label = mut.render.RenderLabel(10)
diffuse = mut.Rgba(1.0, 0.0, 0.0, 0.0)
params = mut.render.RenderEngineGlParams(
default_clear_color=diffuse,
default_label=label,
default_diffuse=diffuse,
)
self.assertEqual(params.default_clear_color, diffuse)
self.assertEqual(params.default_label, label)
self.assertEqual(params.default_diffuse, diffuse)

def test_render_label(self):
RenderLabel = mut.render.RenderLabel
value = 10
Expand Down
3 changes: 2 additions & 1 deletion bindings/pydrake/test/geometry_scene_graph_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ def test_query_object(self, T):
render_params = mut.render.RenderEngineVtkParams()
renderer_name = "test_renderer"
scene_graph.AddRenderer(renderer_name,
mut.render.MakeRenderEngineVtk(render_params))
mut.render.MakeRenderEngineVtk(
params=render_params))

context = scene_graph.CreateDefaultContext()
pose_vector = FramePoseVector()
Expand Down

0 comments on commit 5357d9a

Please sign in to comment.