Provide option to disable keyboard events for SDL.
PiperOrigin-RevId: 822154396 Change-Id: Ie4c8537de2c4b01437aae00ed6d6af1a8f419a73
This commit is contained in:
committed by
Copybara-Service
parent
9e1ed0720b
commit
25f5be82ff
@@ -56,14 +56,16 @@ namespace mujoco::studio {
|
|||||||
// - "passive" mode
|
// - "passive" mode
|
||||||
// - async physics
|
// - async physics
|
||||||
|
|
||||||
static constexpr toolbox::Window::Config kWindowConfig =
|
static constexpr toolbox::Window::Config kWindowConfig = {
|
||||||
#if defined(USE_FILAMENT_VULKAN)
|
#if defined(USE_FILAMENT_VULKAN)
|
||||||
toolbox::Window::Config::kFilamentVulkan;
|
.render_config = toolbox::Window::RenderConfig::kFilamentVulkan,
|
||||||
#elif defined(USE_FILAMENT_OPENGL)
|
#elif defined(USE_FILAMENT_OPENGL)
|
||||||
toolbox::Window::Config::kFilamentOpenGL;
|
.render_config = toolbox::Window::RenderConfig::kFilamentOpenGL,
|
||||||
#elif defined(USE_CLASSIC_OPENGL)
|
#elif defined(USE_CLASSIC_OPENGL)
|
||||||
toolbox::Window::Config::kClassicOpenGL;
|
.render_config = toolbox::Window::RenderConfig::kClassicOpenGL,
|
||||||
#endif
|
#endif
|
||||||
|
.enable_keyboard = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static void ToggleWindow(bool& window) {
|
static void ToggleWindow(bool& window) {
|
||||||
|
|||||||
@@ -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;
|
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;
|
window_flags |= SDL_WINDOW_VULKAN;
|
||||||
} else if (config == kFilamentWebGL) {
|
} else if (render_config == kFilamentWebGL) {
|
||||||
window_flags |= SDL_WINDOW_OPENGL;
|
window_flags |= SDL_WINDOW_OPENGL;
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
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;
|
window_flags |= SDL_WINDOW_OPENGL;
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
} else {
|
} else {
|
||||||
mju_error("Unsupported window config: %d", config);
|
mju_error("Unsupported window config: %d", render_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
sdl_window_ =
|
sdl_window_ =
|
||||||
@@ -107,7 +114,7 @@ Window::Window(std::string_view title, int width, int height, Config config,
|
|||||||
|
|
||||||
InitImGui(sdl_window_, load_asset_fn);
|
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_GLContext gl_context = SDL_GL_CreateContext(sdl_window_);
|
||||||
SDL_GL_MakeCurrent(sdl_window_, gl_context);
|
SDL_GL_MakeCurrent(sdl_window_, gl_context);
|
||||||
}
|
}
|
||||||
@@ -174,7 +181,8 @@ void Window::EndFrame() {
|
|||||||
|
|
||||||
void Window::Present() {
|
void Window::Present() {
|
||||||
// Filament (with the exception of WebGL) handles the swapchain internally.
|
// 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_);
|
SDL_GL_SwapWindow(sdl_window_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,13 +30,18 @@ namespace mujoco::toolbox {
|
|||||||
class Window {
|
class Window {
|
||||||
public:
|
public:
|
||||||
// Configures the window for the specified rendering backend.
|
// Configures the window for the specified rendering backend.
|
||||||
enum Config {
|
enum RenderConfig {
|
||||||
kClassicOpenGL,
|
kClassicOpenGL,
|
||||||
kFilamentVulkan,
|
kFilamentVulkan,
|
||||||
kFilamentOpenGL,
|
kFilamentOpenGL,
|
||||||
kFilamentWebGL,
|
kFilamentWebGL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Config {
|
||||||
|
RenderConfig render_config = kClassicOpenGL;
|
||||||
|
bool enable_keyboard = true;
|
||||||
|
};
|
||||||
|
|
||||||
Window(std::string_view title, int width, int height, Config config,
|
Window(std::string_view title, int width, int height, Config config,
|
||||||
const LoadAssetFn& load_asset_fn);
|
const LoadAssetFn& load_asset_fn);
|
||||||
~Window();
|
~Window();
|
||||||
|
|||||||
Reference in New Issue
Block a user