Skip to content

Commit

Permalink
WIP refactor Apple
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri committed Aug 7, 2023
1 parent 668b60d commit 49e0120
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// Object factories should never have deprecation warnings.
#define VTK_DEPRECATION_LEVEL 0

#include "vtkRenderingOpenGLConfigure.h"
#include "vtkRenderingOpenGL2ObjectFactory.h"
#include "vtkVersion.h"

Expand Down Expand Up @@ -44,7 +45,14 @@
#include "vtkOpenGLTextActor3D.h"
#include "vtkOpenGLTextMapper.h"
#include "vtkOpenGLTexture.h"

#ifdef VTK_USE_COCOA
#include "vtkCocoaRenderWindow.h"
#endif

#ifdef VTK_USE_X
#include "vtkXOpenGLRenderWindow.h"
#endif


VTK_ABI_NAMESPACE_BEGIN
Expand Down Expand Up @@ -76,8 +84,13 @@ VTK_CREATE_CREATE_FUNCTION(vtkOpenGLTextActor)
VTK_CREATE_CREATE_FUNCTION(vtkOpenGLTextActor3D)
VTK_CREATE_CREATE_FUNCTION(vtkOpenGLTextMapper)
VTK_CREATE_CREATE_FUNCTION(vtkOpenGLTexture)
VTK_CREATE_CREATE_FUNCTION(vtkXOpenGLRenderWindow)

#ifdef VTK_USE_COCOA
VTK_CREATE_CREATE_FUNCTION(vtkCocoaRenderWindow)
#endif
#ifdef VTK_USE_X
VTK_CREATE_CREATE_FUNCTION(vtkXOpenGLRenderWindow)
#endif

vtkRenderingOpenGL2ObjectFactory::vtkRenderingOpenGL2ObjectFactory()
{
Expand Down Expand Up @@ -105,8 +118,14 @@ this->RegisterOverride("vtkTextActor", "vtkOpenGLTextActor", "Override for VTK::
this->RegisterOverride("vtkTextActor3D", "vtkOpenGLTextActor3D", "Override for VTK::RenderingOpenGL2 module", 1, vtkObjectFactoryCreatevtkOpenGLTextActor3D);
this->RegisterOverride("vtkTextMapper", "vtkOpenGLTextMapper", "Override for VTK::RenderingOpenGL2 module", 1, vtkObjectFactoryCreatevtkOpenGLTextMapper);
this->RegisterOverride("vtkTexture", "vtkOpenGLTexture", "Override for VTK::RenderingOpenGL2 module", 1, vtkObjectFactoryCreatevtkOpenGLTexture);
this->RegisterOverride("vtkRenderWindow", "vtkXOpenGLRenderWindow", "Override for VTK::RenderingOpenGL2 module", 1, vtkObjectFactoryCreatevtkXOpenGLRenderWindow);

#ifdef VTK_USE_COCOA
this->RegisterOverride("vtkRenderWindow", "vtkCocoaGLRenderWindow", "Override for VTK::RenderingOpenGL2 module", 1, vtkObjectFactoryCreatevtkCocoaGLRenderWindow);
#endif

#ifdef VTK_USE_X
this->RegisterOverride("vtkRenderWindow", "vtkXOpenGLRenderWindow", "Override for VTK::RenderingOpenGL2 module", 1, vtkObjectFactoryCreatevtkXOpenGLRenderWindow);
#endif
}

const char * vtkRenderingOpenGL2ObjectFactory::GetVTKSourceVersion()
Expand Down
23 changes: 0 additions & 23 deletions tools/workspace/vtk_internal/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ config_setting(
constraint_values = ["@platforms//os:osx"],
)

objc_library(
name = "rendering_opengl2_vtkCocoaRenderWindow",
non_arc_srcs = [
"Rendering/OpenGL2/vtkCocoaGLView.mm",
"Rendering/OpenGL2/vtkCocoaRenderWindow.mm",
],
hdrs = [
"Rendering/OpenGL2/vtkCocoaGLView.h",
"Rendering/OpenGL2/vtkCocoaRenderWindow.h",
"Rendering/OpenGL2/vtkOpenGLRenderWindow.h",
"Rendering/OpenGL2/vtkOpenGLState.h",
"Rendering/OpenGL2/vtkOpenGLVertexBufferObjectCache.h",
"Rendering/OpenGL2/vtkRenderingOpenGL2Module.h",
],
includes = ["Rendering/OpenGL2"],
sdk_frameworks = ["Cocoa"],
copts = ["-w"],
deps = [
":VTK__RenderingUI",
":VTK__glew",
],
)

# Generate some source files on the fly, using Bazel re-implementations of
# various CMake scripts.

Expand Down
6 changes: 5 additions & 1 deletion tools/workspace/vtk_internal/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ def create_modules_bzl(repo_ctx):
# Encode the output. Because we lean on json encoding, this will not work
# correctly if anything in the data structure is None, True, or False.
# We rely on parse_module() to avoid that situation.
bzl_content = "MODULES = " + json.encode(modules)
bzl_content = "MODULES = " + json.encode(modules) + "\n"

# Pass along the os.name for convenience.
platform = dict(name = repo_ctx.os.name, arch = repo_ctx.os.arch)
bzl_content += "PLATFORM = " + json.encode(platform) + "\n"

# Write the output.
repo_ctx.file("modules.bzl", content = bzl_content)
Expand Down
23 changes: 22 additions & 1 deletion tools/workspace/vtk_internal/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load(
"@drake//tools/workspace:cmake_configure_file.bzl",
"cmake_configure_files",
)
load("@vtk_internal//:modules.bzl", "MODULES")
load("@vtk_internal//:modules.bzl", "MODULES", "PLATFORM")
load("@vtk_internal//:settings.bzl", "MODULE_SETTINGS")

def _bazelize_module_name(name):
Expand All @@ -28,11 +28,13 @@ def _vtk_cc_module_impl(
srcs_extra = [],
srcs_glob_extra = [],
srcs_glob_exclude = [],
srcs_objc_non_arc = [],
cmake_defines_cmakelists = [],
cmake_defines = [],
cmake_undefines = [],
defines_extra = [],
copts_extra = [],
linkopts_extra = [],
deps_extra = [],
visibility = []):
"""See vtk_cc_module() for documentation."""
Expand Down Expand Up @@ -117,6 +119,7 @@ def _vtk_cc_module_impl(
allow_empty = True,
)
copts = ["-w"] + copts_extra
linkopts = linkopts_extra
deps = []
if "ThirdParty" not in subdir:
deps.append(":vtkABINamespace")
Expand All @@ -125,6 +128,21 @@ def _vtk_cc_module_impl(
deps = deps + module_deps_private
deps = deps + deps_extra

# Deal with objc code.
if PLATFORM["name"] != "linux" and srcs_objc_non_arc:
objc_lib_name = "_" + module_name + "_objc"
native.objc_library(
name = objc_lib_name,
non_arc_srcs = srcs_objc_non_arc,
hdrs = hdrs,
includes = [subdir],
defines = defines_extra,
copts = copts,
linkopts = linkopts,
deps = deps,
)
deps = deps + [objc_lib_name]

# Declare the library using its upstream module name.
native.cc_library(
name = module_name,
Expand All @@ -133,6 +151,7 @@ def _vtk_cc_module_impl(
strip_include_prefix = subdir,
defines = defines_extra,
copts = copts,
linkopts = linkopts,
deps = deps,
linkstatic = True,
)
Expand Down Expand Up @@ -185,12 +204,14 @@ def vtk_cc_module(
this is used to match files from from deeper subdirectories.
srcs_glob_exclude: Skips these patterns. Typically this is used to skip
classes that are unwanted or not necessary.
srcs_objc_non_arc: Adds the given Objective-C sources to this library.
cmake_defines: When generating a header file (e.g., foo.h.in => foo.h),
uses these definitions. See cmake_configure_file() for details.
cmake_undefines: When generating a header file, sets these definitions
to be undefined. See cmake_configure_file() for details.
defines_extra: Adds `defines = []` to the cc_library.
copts_extra: Adds `copts = []` to the cc_library.
linkopts_extra: Adds `linkopts = []` to the cc_library.
deps_extra: Adds `deps = []` to the cc_library.
visibility: Sets `visibility = []` on the cc_library.
"""
Expand Down
41 changes: 31 additions & 10 deletions tools/workspace/vtk_internal/settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ MODULE_SETTINGS = {
},
"VTK::RenderingOpenGL2": {
"visibility": ["//visibility:public"],
"cmake_defines": select({
":osx": [
"VTK_USE_COCOA",
],
"//conditions:default": [
"VTK_USE_X",
],
}),
"cmake_undefines": [
"VTK_DEFAULT_RENDER_WINDOW_OFFSCREEN",
"VTK_OPENGL_ENABLE_STREAM_ANNOTATIONS",
Expand All @@ -320,10 +328,14 @@ MODULE_SETTINGS = {
"VTK_USE_CORE_GRAPHICS",
"VTK_USE_DIRECTX",
"VTK_USE_NVCONTROL",
# We could try to set these, but they don't appear to matter.
"VTK_USE_COCOA",
"VTK_USE_X",
],
] + select({
":osx": [
"VTK_USE_X",
],
"//conditions:default": [
"VTK_USE_COCOA",
],
}),
"hdrs_extra": [
":generated_rendering_opengl2_sources",
],
Expand All @@ -339,11 +351,15 @@ MODULE_SETTINGS = {
"**/vtkWin32OpenGL*",
"**/vtkXOpenGL*",
],
"srcs_extra": select({
"srcs_objc_non_arc": select({
":osx": [
# "Rendering/OpenGL2/vtkCocoaGLView.mm",
# "Rendering/OpenGL2/vtkCocoaRenderWindow.mm",
"Rendering/OpenGL2/vtkCocoaGLView.mm",
"Rendering/OpenGL2/vtkCocoaRenderWindow.mm",
],
"//conditions:default": [],
}),
"srcs_extra": select({
":osx": [],
"//conditions:default": [
"Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx",
],
Expand All @@ -354,12 +370,17 @@ MODULE_SETTINGS = {
"@drake//tools/workspace/vtk_internal:gen/vtkRenderingOpenGL2ObjectFactory.h", # noqa
"@drake//tools/workspace/vtk_internal:gen/vtkRenderingOpenGL2ObjectFactory.cxx", # noqa
],
"deps_extra": select({
"linkopts_extra": select({
":osx": [
":rendering_opengl2_vtkCocoaRenderWindow",
# Mimic vtk_module_link(... "-framework Cocoa").
"-framework Cocoa",
],
"//conditions:default": [],
}),
"deps_extra": select({
":osx": [],
"//conditions:default": [
# Mimic vtk_module_link(VTK::RenderingOpenGL2 PUBLIC X11::X11).
# Mimic vtk_module_link(... X11::X11).
"@x11",
],
}),
Expand Down

0 comments on commit 49e0120

Please sign in to comment.