Call GLFW functions via a dynamic dispatch table.
This allows us to use GLFW without needing to introduce a link-time dependency on the library, which in turn enables us to get GLFW through Python. PiperOrigin-RevId: 470100999 Change-Id: I27c84ad3310afdbebd582ab0033b6a963ba6307e
This commit is contained in:
committed by
Copybara-Service
parent
d26501c0f3
commit
3240596c3a
@@ -0,0 +1,66 @@
|
||||
// Copyright 2022 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_SIMULATE_GLFW_DISPATCH_H_
|
||||
#define MUJOCO_SIMULATE_GLFW_DISPATCH_H_
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace mujoco {
|
||||
// Dynamic dispatch table for GLFW functions required by Simulate.
|
||||
// This allows us to use GLFW without introducing a link-time dependency on the
|
||||
// library, which is useful e.g. when using GLFW via Python.
|
||||
struct Glfw {
|
||||
#define mjGLFW_DECLARE_SYMBOL(func) decltype(&func) func
|
||||
// go/keep-sorted start
|
||||
mjGLFW_DECLARE_SYMBOL(glfwCreateWindow);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetCursorPos);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetFramebufferSize);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetKey);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetMonitorPhysicalSize);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetMouseButton);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetPrimaryMonitor);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetTime);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetVideoMode);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetWindowMonitor);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetWindowPos);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetWindowSize);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwGetWindowUserPointer);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwInit);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwMakeContextCurrent);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwPollEvents);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetClipboardString);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetCursorPosCallback);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetDropCallback);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetKeyCallback);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetMouseButtonCallback);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetScrollCallback);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetWindowMonitor);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetWindowRefreshCallback);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetWindowSizeCallback);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetWindowTitle);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSetWindowUserPointer);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSwapBuffers);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwSwapInterval);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwTerminate);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwWindowHint);
|
||||
mjGLFW_DECLARE_SYMBOL(glfwWindowShouldClose);
|
||||
// go/keep-sorted end
|
||||
#undef mjGLFW_DECLARE_SYMBOL
|
||||
};
|
||||
|
||||
const struct Glfw& Glfw(void* dlhandle = nullptr);
|
||||
} // namespace mujoco
|
||||
|
||||
#endif // MUJOCO_SIMULATE_GLFW_DISPATCH_H_
|
||||
Reference in New Issue
Block a user