Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macos build #3

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
add_subdirectory(v4r EXCLUDE_FROM_ALL)

add_subdirectory(corrade EXCLUDE_FROM_ALL)
find_package(Corrade REQUIRED Main)

if (NOT CORRADE_TARGET_APPLE)
add_subdirectory(v4r EXCLUDE_FROM_ALL)
endif ()


if (BUILD_GUI_APPS)
set(WITH_SDL2APPLICATION ON CACHE BOOL "" FORCE)
else()
message(STATUS "Build without GUI apps!")
endif()

set(WITH_WINDOWLESSEGLAPPLICATION ON CACHE BOOL "" FORCE)
if (NOT CORRADE_TARGET_APPLE)
set(WITH_WINDOWLESSEGLAPPLICATION ON CACHE BOOL "" FORCE)
else ()
set(WITH_WINDOWLESSCGLAPPLICATION ON CACHE BOOL "WITH_WINDOWLESSCGLAPPLICATION" FORCE)
endif ()
set(WITH_TGAIMPORTER ON CACHE BOOL "" FORCE)
add_subdirectory(magnum EXCLUDE_FROM_ALL)

Expand All @@ -17,8 +25,7 @@ add_subdirectory(magnum EXCLUDE_FROM_ALL)
set(WITH_BULLET ON CACHE BOOL "" FORCE)
add_subdirectory(magnum-integration EXCLUDE_FROM_ALL)

find_package(Corrade REQUIRED Main)
find_package(Magnum REQUIRED GL MeshTools Primitives SceneGraph Shaders WindowlessEglApplication Trade)
find_package(Magnum REQUIRED GL MeshTools Primitives SceneGraph Shaders Trade)
if (BUILD_GUI_APPS)
find_package(Magnum REQUIRED Sdl2Application)
endif()
Expand All @@ -27,6 +34,8 @@ find_package(MagnumIntegration REQUIRED Bullet)
add_subdirectory(googletest-1.10.0)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})

add_subdirectory(glad)
if (NOT CORRADE_TARGET_APPLE)
add_subdirectory(glad)
endif ()

add_subdirectory(pybind11)
2 changes: 1 addition & 1 deletion src/3rdparty/pybind11
Submodule pybind11 updated 209 files
13 changes: 11 additions & 2 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
find_package(Corrade REQUIRED Main)
set(MAGNUM_DEPENDENCIES
Corrade::Main
Magnum::GL
Expand All @@ -10,11 +11,19 @@ set(MAGNUM_DEPENDENCIES

if (BUILD_GUI_APPS)
add_app_default(viewer viewer.cpp)
target_link_libraries(viewer PRIVATE scenarios magnum_rendering v4r_rendering ${MAGNUM_DEPENDENCIES} Magnum::Application Magnum::Trade ${OpenCV_LIBS})
target_link_libraries(viewer PRIVATE scenarios magnum_rendering ${MAGNUM_DEPENDENCIES} Magnum::Application Magnum::Trade ${OpenCV_LIBS})

if (NOT CORRADE_TARGET_APPLE)
target_link_libraries(viewer PRIVATE v4r_rendering)
endif ()
endif()

add_app_default(voxel_env_app voxel_env_app.cpp)
target_link_libraries(voxel_env_app PRIVATE scenarios magnum_rendering v4r_rendering ${MAGNUM_DEPENDENCIES} Magnum::WindowlessEglApplication ${OpenCV_LIBS})
target_link_libraries(voxel_env_app PRIVATE scenarios magnum_rendering ${MAGNUM_DEPENDENCIES} ${OpenCV_LIBS})

if (NOT CORRADE_TARGET_APPLE)
target_link_libraries(voxel_env_app PRIVATE v4r_rendering)
endif ()

# Make the executable a default target to build & run in Visual Studio
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT viewer)
Expand Down
29 changes: 22 additions & 7 deletions src/apps/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
#include <magnum_rendering/windowless_context.hpp>
#include <magnum_rendering/magnum_env_renderer.hpp>

#if !defined(CORRADE_TARGET_APPLE)
#include <v4r_rendering/v4r_env_renderer.hpp>
#endif



using namespace Magnum;
Expand All @@ -40,7 +43,13 @@ using namespace Magnum::Math::Literals;
using namespace VoxelWorld;

// TODO: CLI parameters
const bool useVulkan = false;
#if defined(CORRADE_TARGET_APPLE)
constexpr bool useVulkan = false;

static_assert(!useVulkan, "Vulkan not supported on MacOS");
#else
constexpr bool useVulkan = true;
#endif

// "main" envs
//const auto scenarioName = "ObstaclesHard"; // *
Expand Down Expand Up @@ -81,7 +90,7 @@ class Viewer: public Magnum::Platform::Application
void moveOverviewCamera();

private:
int width = 1800, height = 1000;
int width = 1280, height = 720;

Envs envs;
std::unique_ptr<EnvRenderer> renderer;
Expand Down Expand Up @@ -140,15 +149,20 @@ Viewer::Viewer(const Arguments& arguments)

ctx = std::make_unique<WindowRenderingContext>();

const Magnum::Vector2i fbSize = framebufferSize();
if (useVulkan) {
framebuffer = GL::Framebuffer{Range2Di{{}, Vector2i{width, height}}};
#if defined (CORRADE_TARGET_APPLE)
TLOG(ERROR) << "Vulkan not supported on MacOS";
#else
framebuffer = GL::Framebuffer{Range2Di{{}, fbSize}};
framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, colorBuffer);
framebuffer.mapForDraw({{0, GL::Framebuffer::ColorAttachment{0}}});
framebuffer.clearColor(0, Color3{0.125f}).clearDepth(1.0).bind();

renderer = std::make_unique<V4REnvRenderer>(envs, width, height, nullptr);
renderer = std::make_unique<V4REnvRenderer>(envs, fbSize[0], fbSize[1], nullptr);
#endif
} else {
renderer = std::make_unique<MagnumEnvRenderer>(envs, width, height, withDebugDraw, true, ctx.get());
renderer = std::make_unique<MagnumEnvRenderer>(envs, fbSize[0], fbSize[1], withDebugDraw, true, ctx.get());
dynamic_cast<MagnumEnvRenderer &>(*renderer).toggleDebugMode();
}

Expand All @@ -161,6 +175,7 @@ Viewer::Viewer(const Arguments& arguments)
void Viewer::drawEvent()
{
if (useVulkan) {
#if !defined(CORRADE_TARGET_APPLE)
for (int envIdx = 0; envIdx < int(envs.size()); ++envIdx)
renderer->preDraw(*envs[envIdx], envIdx);

Expand All @@ -187,7 +202,7 @@ void Viewer::drawEvent()
// blit color to window framebuffer
GL::defaultFramebuffer.bind();
GL::AbstractFramebuffer::blit(framebuffer, GL::defaultFramebuffer, {{}, framebuffer.viewport().size()}, GL::FramebufferBlit::Color);

#endif
} else {
auto &magnumRenderer = dynamic_cast<MagnumEnvRenderer &>(*renderer);

Expand Down Expand Up @@ -405,4 +420,4 @@ void Viewer::mouseMoveEvent(Magnum::Platform::Sdl2Application::MouseMoveEvent &e
redraw();
}

MAGNUM_APPLICATION_MAIN(Viewer)
MAGNUM_APPLICATION_MAIN(Viewer)
15 changes: 15 additions & 0 deletions src/apps/voxel_env_app.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <cstdlib>

#include <Corrade/configure.h>

#include <opencv2/core/mat.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
Expand All @@ -15,7 +17,9 @@

#include <scenarios/init.hpp>

#if !defined(CORRADE_TARGET_APPLE)
#include <v4r_rendering/v4r_env_renderer.hpp>
#endif

#include <magnum_rendering/magnum_env_renderer.hpp>

Expand All @@ -34,7 +38,14 @@ constexpr int delayMs = 1; // 1000 / 15;
//ConstStr scenario = "Rearrange";
ConstStr scenario = "HexMemory";


#if defined(CORRADE_TARGET_APPLE)
constexpr bool useVulkan = false;

static_assert(!useVulkan, "Vulkan not supported on MacOS");
#else
constexpr bool useVulkan = true;
#endif

constexpr bool viz = false;
constexpr bool hires = false;
Expand Down Expand Up @@ -210,7 +221,11 @@ int main(int argc, char** argv)

std::unique_ptr<EnvRenderer> renderer;
if constexpr (useVulkan)
#if defined (CORRADE_TARGET_APPLE)
TLOG(ERROR) << "Vulkan not supported on MacOS";
#else
renderer = std::make_unique<V4REnvRenderer>(envs, W, H, nullptr);
#endif
else {
const auto debugDraw = false;
renderer = std::make_unique<MagnumEnvRenderer>(envs, W, H, debugDraw);
Expand Down
6 changes: 5 additions & 1 deletion src/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
find_package(Corrade REQUIRED Main)

add_subdirectory(util)
add_subdirectory(rendering)
add_subdirectory(magnum_rendering)
add_subdirectory(v4r_rendering)
if (NOT CORRADE_TARGET_APPLE)
add_subdirectory(v4r_rendering)
endif ()
add_subdirectory(env)
add_subdirectory(mazes)
add_subdirectory(scenarios)
Expand Down
8 changes: 7 additions & 1 deletion src/libs/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
find_package(Corrade REQUIRED Main)

pybind11_add_module(voxel_env voxel_env.cpp)
target_link_libraries(voxel_env PUBLIC scenarios magnum_rendering v4r_rendering)
target_link_libraries(voxel_env PUBLIC scenarios magnum_rendering)

if (NOT CORRADE_TARGET_APPLE)
target_link_libraries(voxel_env PUBLIC v4r_rendering)
endif ()
12 changes: 11 additions & 1 deletion src/libs/bindings/voxel_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

#include <scenarios/init.hpp>

#include <v4r_rendering/v4r_env_renderer.hpp>
#include <magnum_rendering/magnum_env_renderer.hpp>
#if !defined(CORRADE_TARGET_APPLE)
#include <v4r_rendering/v4r_env_renderer.hpp>
#endif


namespace py = pybind11;
Expand Down Expand Up @@ -70,7 +72,11 @@ class VoxelEnvGym
{
if (!vectorEnv) {
if (useVulkan)
#if defined (CORRADE_TARGET_APPLE)
TLOG(ERROR) << "Vulkan not supported on MacOS";
#else
renderer = std::make_unique<V4REnvRenderer>(envs, w, h, nullptr);
#endif
else
renderer = std::make_unique<MagnumEnvRenderer>(envs, w, h);

Expand Down Expand Up @@ -148,7 +154,11 @@ class VoxelEnvGym
{
if (!hiresRenderer) {
if (useVulkan)
#if defined (CORRADE_TARGET_APPLE)
TLOG(ERROR) << "Vulkan not supported on MacOS";
#else
hiresRenderer = std::make_unique<V4REnvRenderer>(envs, renderW, renderH, dynamic_cast<V4REnvRenderer *>(renderer.get()));
#endif
else
hiresRenderer = std::make_unique<MagnumEnvRenderer>(envs, renderW, renderH);

Expand Down
11 changes: 10 additions & 1 deletion src/libs/magnum_rendering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ cmake_minimum_required(VERSION 3.10)
project(libgfx-magnum VERSION 0.1 LANGUAGES CXX)

add_library_default(magnum_rendering)
target_link_libraries(magnum_rendering PUBLIC env rendering glad Corrade::Main Magnum::GL Magnum::WindowlessEglApplication Magnum::Shaders Magnum::MeshTools Magnum::Primitives MagnumIntegration::Bullet)
target_link_libraries(magnum_rendering PUBLIC env rendering Corrade::Main Magnum::GL Magnum::Shaders Magnum::MeshTools Magnum::Primitives MagnumIntegration::Bullet)

find_package (Corrade REQUIRED Main)
if (NOT CORRADE_TARGET_APPLE)
find_package(Magnum REQUIRED WindowlessEglApplication)
target_link_libraries(magnum_rendering PUBLIC glad Magnum::WindowlessEglApplication)
else ()
find_package(Magnum REQUIRED WindowlessCglApplication)
target_link_libraries(magnum_rendering PUBLIC Magnum::WindowlessCglApplication)
endif ()
4 changes: 1 addition & 3 deletions src/libs/magnum_rendering/src/magnum_env_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <Magnum/GL/Framebuffer.h>
#include <Magnum/GL/Renderbuffer.h>
#include <Magnum/GL/Context.h>
#include <Magnum/Platform/WindowlessEglApplication.h>
#include <Magnum/PixelFormat.h>
#include <Magnum/BulletIntegration/DebugDraw.h>

Expand All @@ -26,9 +25,8 @@
#include <rendering/render_utils.hpp>

#include <magnum_rendering/windowless_context.hpp>
#include <magnum_rendering/magnum_env_renderer.hpp>


#include <magnum_rendering/magnum_env_renderer.hpp>

using namespace Magnum;
using namespace Magnum::Math::Literals;
Expand Down