Provide option to disable keyboard events for SDL.

PiperOrigin-RevId: 822154396
Change-Id: Ie4c8537de2c4b01437aae00ed6d6af1a8f419a73
This commit is contained in:
Kyle Bayes
2025-10-21 09:35:20 -07:00
committed by Copybara-Service
parent 9e1ed0720b
commit 25f5be82ff
3 changed files with 26 additions and 11 deletions
+6 -4
View File
@@ -56,14 +56,16 @@ namespace mujoco::studio {
// - "passive" mode
// - async physics
static constexpr toolbox::Window::Config kWindowConfig =
static constexpr toolbox::Window::Config kWindowConfig = {
#if defined(USE_FILAMENT_VULKAN)
toolbox::Window::Config::kFilamentVulkan;
.render_config = toolbox::Window::RenderConfig::kFilamentVulkan,
#elif defined(USE_FILAMENT_OPENGL)
toolbox::Window::Config::kFilamentOpenGL;
.render_config = toolbox::Window::RenderConfig::kFilamentOpenGL,
#elif defined(USE_CLASSIC_OPENGL)
toolbox::Window::Config::kClassicOpenGL;
.render_config = toolbox::Window::RenderConfig::kClassicOpenGL,
#endif
.enable_keyboard = true,
};
static void ToggleWindow(bool& window) {
+14 -6
View File
@@ -83,19 +83,26 @@ Window::Window(std::string_view title, int width, int height, Config config,
int window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
if (config == kFilamentVulkan) {
if (!config_.enable_keyboard) {
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
SDL_EventState(SDL_KEYDOWN, SDL_DISABLE);
SDL_EventState(SDL_KEYUP, SDL_DISABLE);
}
RenderConfig render_config = config_.render_config;
if (render_config == kFilamentVulkan) {
window_flags |= SDL_WINDOW_VULKAN;
} else if (config == kFilamentWebGL) {
} else if (render_config == kFilamentWebGL) {
window_flags |= SDL_WINDOW_OPENGL;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
} else if (config == kClassicOpenGL || config == kFilamentOpenGL) {
} else if (render_config == kClassicOpenGL || render_config == kFilamentOpenGL) {
window_flags |= SDL_WINDOW_OPENGL;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
} else {
mju_error("Unsupported window config: %d", config);
mju_error("Unsupported window config: %d", render_config);
}
sdl_window_ =
@@ -107,7 +114,7 @@ Window::Window(std::string_view title, int width, int height, Config config,
InitImGui(sdl_window_, load_asset_fn);
if (config == kFilamentWebGL || config == kClassicOpenGL) {
if (render_config == kFilamentWebGL || render_config == kClassicOpenGL) {
SDL_GLContext gl_context = SDL_GL_CreateContext(sdl_window_);
SDL_GL_MakeCurrent(sdl_window_, gl_context);
}
@@ -174,7 +181,8 @@ void Window::EndFrame() {
void Window::Present() {
// Filament (with the exception of WebGL) handles the swapchain internally.
if (config_ != kFilamentVulkan && config_ != kFilamentOpenGL) {
if (config_.render_config != kFilamentVulkan
&& config_.render_config != kFilamentOpenGL) {
SDL_GL_SwapWindow(sdl_window_);
}
}
+6 -1
View File
@@ -30,13 +30,18 @@ namespace mujoco::toolbox {
class Window {
public:
// Configures the window for the specified rendering backend.
enum Config {
enum RenderConfig {
kClassicOpenGL,
kFilamentVulkan,
kFilamentOpenGL,
kFilamentWebGL,
};
struct Config {
RenderConfig render_config = kClassicOpenGL;
bool enable_keyboard = true;
};
Window(std::string_view title, int width, int height, Config config,
const LoadAssetFn& load_asset_fn);
~Window();