Add OSX and WIN32 support for getting the native window pointer.
PiperOrigin-RevId: 838720433 Change-Id: Id7123bcf456d0c2d32e67b204564fe8c495004cd
This commit is contained in:
committed by
Copybara-Service
parent
ad24889bb9
commit
9b7134b15b
@@ -39,6 +39,15 @@ target_sources(${MUJOCO_PLATFORM_TARGET_NAME}
|
|||||||
window.cc
|
window.cc
|
||||||
window.h
|
window.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
set_source_files_properties(window_osx.mm PROPERTIES
|
||||||
|
COMPILE_FLAGS "-x objective-c++")
|
||||||
|
target_sources(${MUJOCO_PLATFORM_TARGET_NAME} PUBLIC
|
||||||
|
window_osx.mm
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(${MUJOCO_PLATFORM_TARGET_NAME}
|
target_include_directories(${MUJOCO_PLATFORM_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${PROJECT_SOURCE_DIR}/include
|
${PROJECT_SOURCE_DIR}/include
|
||||||
|
|||||||
@@ -34,6 +34,10 @@
|
|||||||
#undef Status
|
#undef Status
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
extern void* GetNativeWindowOsx(void* window);
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mujoco::platform {
|
namespace mujoco::platform {
|
||||||
|
|
||||||
static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn,
|
static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn,
|
||||||
@@ -117,11 +121,17 @@ Window::Window(std::string_view title, int width, int height, Config config,
|
|||||||
SDL_GL_MakeCurrent(sdl_window_, gl_context);
|
SDL_GL_MakeCurrent(sdl_window_, gl_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
SDL_SysWMinfo wmi;
|
||||||
SDL_SysWMinfo wmi;
|
SDL_VERSION(&wmi.version);
|
||||||
SDL_VERSION(&wmi.version);
|
SDL_GetWindowWMInfo(sdl_window_, &wmi);
|
||||||
SDL_GetWindowWMInfo(sdl_window_, &wmi);
|
|
||||||
|
#if defined(__linux__)
|
||||||
native_window_ = reinterpret_cast<void*>(wmi.info.x11.window);
|
native_window_ = reinterpret_cast<void*>(wmi.info.x11.window);
|
||||||
|
#elif defined(__WIN32__)
|
||||||
|
native_window_ = reinterpret_cast<void*>(wmi.info.win.window);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
native_window_ =
|
||||||
|
GetNativeWindowOsx(reinterpret_cast<void*>(wmi.info.cocoa.window));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2025 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.
|
||||||
|
|
||||||
|
#import <AppKit/NSWindow.h>
|
||||||
|
#import <AppKit/NSView.h>
|
||||||
|
|
||||||
|
void* GetNativeWindowOsx(void* window) {
|
||||||
|
NSWindow* ns_window = (__bridge NSWindow*)window;
|
||||||
|
NSView* ns_view = [ns_window contentView];
|
||||||
|
return (__bridge void*)ns_view;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user