From d2d8c501c2788d160b3ae89fe57e75549619edfe Mon Sep 17 00:00:00 2001 From: Igor Bogoslavskyi Date: Mon, 17 Oct 2022 21:32:07 +0200 Subject: [PATCH] Initial conversion to CMake --- .bazelignore | 1 + .clangd | 4 + .gitignore | 3 + .gitmodules | 21 ++++ CMakeLists.txt | 9 ++ WORKSPACE | 5 +- examples/3d_viewer/main.cpp | 8 +- gl/CMakeLists.txt | 2 + gl/core/CMakeLists.txt | 30 +++++ gl/core/init.h | 57 ++++++---- gl/core/opengl_object.h | 2 +- gl/core/test_shaders/shader.vert | 1 + gl/core/uniform.h | 5 +- gl/core/uniform_test.cpp | 53 ++++++--- gl/ui/CMakeLists.txt | 1 + gl/ui/core/user_input_handler.h | 1 + gl/ui/glfw/CMakeLists.txt | 26 +++++ gl/ui/glfw/glfw_user_input_handler.h | 4 +- gl/ui/glfw/viewer.cpp | 3 +- gl/ui/glfw/viewer.h | 2 +- readme.md | 2 + submodules/CMakeLists.txt | 21 ++++ submodules/abseil | 1 + submodules/eigen | 1 + submodules/glad | 1 + submodules/glfw | 1 + submodules/glog | 1 + submodules/googletest | 1 + submodules/stb | 1 + third_party/glfw/glfw.BUILD | 161 +++++++++++++++------------ utils/CMakeLists.txt | 28 +++++ utils/image_test.cpp | 1 + 32 files changed, 340 insertions(+), 118 deletions(-) create mode 100644 .bazelignore create mode 100644 .clangd create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 gl/CMakeLists.txt create mode 100644 gl/core/CMakeLists.txt create mode 100644 gl/ui/CMakeLists.txt create mode 100644 gl/ui/glfw/CMakeLists.txt create mode 100644 submodules/CMakeLists.txt create mode 160000 submodules/abseil create mode 160000 submodules/eigen create mode 160000 submodules/glad create mode 160000 submodules/glfw create mode 160000 submodules/glog create mode 160000 submodules/googletest create mode 160000 submodules/stb create mode 100644 utils/CMakeLists.txt diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 0000000..5efe132 --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +submodules/ \ No newline at end of file diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..3fe952f --- /dev/null +++ b/.clangd @@ -0,0 +1,4 @@ +InlayHints: + Enabled: No + ParameterNames: Yes + DeducedTypes: No \ No newline at end of file diff --git a/.gitignore b/.gitignore index b998c50..3b538b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ +.cache/ +.vscode/ build/ +build_*/ bazel-* /compile_commands.json /opengl_tutorial.sublime-workspace diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..14aa740 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,21 @@ +[submodule "submodules/glfw"] + path = submodules/glfw + url = https://github.com/glfw/glfw.git +[submodule "submodules/eigen"] + path = submodules/eigen + url = https://github.com/libigl/eigen.git +[submodule "submodules/abseil"] + path = submodules/abseil + url = https://github.com/abseil/abseil-cpp.git +[submodule "submodules/stb"] + path = submodules/stb + url = https://github.com/nothings/stb.git +[submodule "submodules/googletest"] + path = submodules/googletest + url = https://github.com/google/googletest.git +[submodule "submodules/glog"] + path = submodules/glog + url = https://github.com/google/glog.git +[submodule "submodules/glad"] + path = submodules/glad + url = https://github.com/Dav1dde/glad.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cd3c251 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.16...3.23) + +project(igloo VERSION 0.0.1 LANGUAGES C CXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_subdirectory(submodules) +add_subdirectory(utils) +add_subdirectory(gl) diff --git a/WORKSPACE b/WORKSPACE index 1eec500..14018c6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -33,9 +33,8 @@ pip_install( http_archive( name = "glfw", - urls = ["https://github.com/glfw/glfw/releases/download/3.3.2/glfw-3.3.2.zip"], - sha256 = "08a33a512f29d7dbf78eab39bd7858576adcc95228c9efe8e4bc5f0f3261efc7", - strip_prefix = "glfw-3.3.2", + urls = ["https://github.com/glfw/glfw/releases/download/3.3.8/glfw-3.3.8.zip"], + strip_prefix = "glfw-3.3.8", build_file = "@//:third_party/glfw/glfw.BUILD", ) diff --git a/examples/3d_viewer/main.cpp b/examples/3d_viewer/main.cpp index 063976a..64f0f70 100644 --- a/examples/3d_viewer/main.cpp +++ b/examples/3d_viewer/main.cpp @@ -3,12 +3,14 @@ #include "gl/scene/drawables/all.h" #include "gl/viewer/viewer.h" +#include #include #include #include #include #include +#include namespace { @@ -93,15 +95,15 @@ int main(int argc, char* argv[]) { texture_3d_drawable, Eigen::Translation3f{5.0F, 0.0F, 0.0F} * Eigen::AngleAxisf(0.0F, Eigen::Vector3f::UnitX()) * - Eigen::AngleAxisf(-0.5F * M_PIf32, Eigen::Vector3f::UnitY()) * - Eigen::AngleAxisf(-0.5F * M_PIf32, Eigen::Vector3f::UnitZ())); + Eigen::AngleAxisf(-0.5F * M_PI, Eigen::Vector3f::UnitY()) * + Eigen::AngleAxisf(-0.5F * M_PI, Eigen::Vector3f::UnitZ())); viewer.Attach( viewer.world_key(), texture_3d_drawable, Eigen::Translation3f{-1.0F, -1.0F, 2.0F} * Eigen::AngleAxisf(0.0F, Eigen::Vector3f::UnitX()) * Eigen::AngleAxisf(0.0, Eigen::Vector3f::UnitY()) * - Eigen::AngleAxisf(-0.5F * M_PIf32, Eigen::Vector3f::UnitZ())); + Eigen::AngleAxisf(-0.5F * M_PI, Eigen::Vector3f::UnitZ())); viewer.AttachToScreen(texture_2d_drawable, {0.5f, 0.5f}); viewer.camera().LookAt({0.0f, 0.0f, 0.0f}, {-10.0f, 0.0f, 3.0f}); diff --git a/gl/CMakeLists.txt b/gl/CMakeLists.txt new file mode 100644 index 0000000..872ddc3 --- /dev/null +++ b/gl/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(ui) +add_subdirectory(core) \ No newline at end of file diff --git a/gl/core/CMakeLists.txt b/gl/core/CMakeLists.txt new file mode 100644 index 0000000..622e4fa --- /dev/null +++ b/gl/core/CMakeLists.txt @@ -0,0 +1,30 @@ +add_library(core + shader.cpp + uniform.cpp + texture.cpp + program.cpp +) +target_link_libraries(core PUBLIC + file_utils + type_traits + macro_utils + image + glad_gl_core_33 + glog::glog + absl::strings + absl::str_format +) + +add_executable(core_test + buffer_test.cpp + shader_test.cpp + program_test.cpp + uniform_test.cpp + main_test.cpp +) +target_link_libraries(core_test PRIVATE + core + glfw_viewer + eigen_utils + GTest::gtest +) diff --git a/gl/core/init.h b/gl/core/init.h index 34fcfa9..8989bea 100644 --- a/gl/core/init.h +++ b/gl/core/init.h @@ -5,35 +5,52 @@ #ifndef CODE_OPENGL_TUTORIALS_GL_CORE_INIT_H_ #define CODE_OPENGL_TUTORIALS_GL_CORE_INIT_H_ +#include "glad/gl.h" #include "glog/logging.h" -#include "third_party/glad/glad.h" #include namespace gl { -void GLAPIENTRY MessageCallback(GLenum source, - GLenum type, - GLuint id, - GLenum severity, - GLsizei length, - const GLchar* message, - const void* userParam) { - if (type == GL_DEBUG_TYPE_ERROR) { - LOG(FATAL) << "GL ERROR message: '" << message << "'"; +inline std::string ErrorDescription(GLenum err) { + switch (err) { + case GL_NO_ERROR: + return "GL_NO_ERROR: No error has been recorded. The value of this " + "symbolic constant is guaranteed to be 0. "; + case GL_INVALID_ENUM: + return "GL_INVALID_ENUM: An unacceptable value is specified for an " + "enumerated argument. The offending command is ignored and has no " + "other side effect than to set the error flag. "; + case GL_INVALID_VALUE: + return "GL_INVALID_VALUE: A numeric argument is out of range. The " + "offending command is ignored and has no other side effect than " + "to set the error flag. "; + case GL_INVALID_OPERATION: + return "GL_INVALID_OPERATION: The specified operation is not allowed in " + "the current state. The offending command is ignored and has no " + "other side effect than to set the error flag. "; + case GL_INVALID_FRAMEBUFFER_OPERATION: + return "GL_INVALID_FRAMEBUFFER_OPERATION: The framebuffer object is not " + "complete." + "The offending command is ignored and has no other side effect " + "than to set the error flag."; + case GL_OUT_OF_MEMORY: + return "GL_OUT_OF_MEMORY: There is not enough memory left to execute the " + "command. The state of the GL is undefined, except for the state " + "of the error flags, after this error is recorded. . "; + case GL_STACK_UNDERFLOW: + return "GL_STACK_UNDERFLOW: An attempt has been made to perform an " + "operation that would cause an internal stack to underflow. "; + case GL_STACK_OVERFLOW: + return "GL_STACK_OVERFLOW: An attempt has been made to perform an " + "operation that would cause an internal stack to overflow. "; + default: return "No Description"; } } -template -void InitializeGlContext(FunctionT intialization_function) { - if (!gladLoadGLLoader( - reinterpret_cast(intialization_function))) { - LOG(FATAL) << "Cannot initialize OpenGL context with GLAD."; - } -#ifndef NDEBUG - glEnable(GL_DEBUG_OUTPUT); - glDebugMessageCallback(MessageCallback, 0); -#endif +inline void CheckGlError() { + const auto err = glGetError(); + if (err != GL_NO_ERROR) { LOG(FATAL) << ErrorDescription(err); } } } // namespace gl diff --git a/gl/core/opengl_object.h b/gl/core/opengl_object.h index 3ada036..d069df3 100644 --- a/gl/core/opengl_object.h +++ b/gl/core/opengl_object.h @@ -1,7 +1,7 @@ #ifndef CODE_OPENGL_TUTORIALS_GL_CORE_OPENGL_OBJECT_H_ #define CODE_OPENGL_TUTORIALS_GL_CORE_OPENGL_OBJECT_H_ -#include "third_party/glad/glad.h" +#include "glad/gl.h" #include diff --git a/gl/core/test_shaders/shader.vert b/gl/core/test_shaders/shader.vert index 0630205..49f383e 100644 --- a/gl/core/test_shaders/shader.vert +++ b/gl/core/test_shaders/shader.vert @@ -1,4 +1,5 @@ #version 330 core + uniform float dummy_value_dim_1; uniform vec2 dummy_value_dim_2; uniform vec3 dummy_value_dim_3; diff --git a/gl/core/uniform.h b/gl/core/uniform.h index cc6887d..e3d4655 100644 --- a/gl/core/uniform.h +++ b/gl/core/uniform.h @@ -1,6 +1,7 @@ #ifndef OPENGL_TUTORIALS_CORE_GL_UNIFORM_H_ #define OPENGL_TUTORIALS_CORE_GL_UNIFORM_H_ +#include "gl/core/init.h" #include "gl/core/opengl_object.h" #include "gl/core/traits.h" #include "utils/type_traits.h" @@ -17,7 +18,9 @@ class Uniform : public OpenGlObject { Uniform(const std::string& name, std::uint32_t program_id) : OpenGlObject{0}, name_{name}, - location_{glGetUniformLocation(program_id, name_.c_str())} {} + location_{glGetUniformLocation(program_id, name_.c_str())} { + CheckGlError(); + } GLint location() const noexcept { return location_; } diff --git a/gl/core/uniform_test.cpp b/gl/core/uniform_test.cpp index 1e27745..e84f2e0 100644 --- a/gl/core/uniform_test.cpp +++ b/gl/core/uniform_test.cpp @@ -30,48 +30,71 @@ class UniformTest : public ::testing::Test { TEST_F(UniformTest, Init) { Uniform uniform{"dummy_value_dim_1", program_->id()}; EXPECT_EQ("dummy_value_dim_1", uniform.name()); - EXPECT_EQ(uniform.location(), 0); + EXPECT_EQ(uniform.location(), + glGetUniformLocation(program_->id(), "dummy_value_dim_1")); } TEST_F(UniformTest, UpdateValueFromPack) { Uniform uniform_1{"dummy_value_dim_1", program_->id()}; - EXPECT_EQ(uniform_1.location(), 0); uniform_1.UpdateValue(1.0f); + float value[4] = {42.0f, 42.0f, 42.0f, 42.0f}; + glGetUniformfv(program_->id(), uniform_1.location(), value); + EXPECT_FLOAT_EQ(value[0], 1.0f); + EXPECT_FLOAT_EQ(value[1], 42.0f); Uniform uniform_2{"dummy_value_dim_2", program_->id()}; - EXPECT_EQ(uniform_2.location(), 1); - uniform_2.UpdateValue(1.0f, 2.0f); + uniform_2.UpdateValue(1.1f, 2.2f); + glGetUniformfv(program_->id(), uniform_2.location(), value); + EXPECT_FLOAT_EQ(value[0], 1.1f); + EXPECT_FLOAT_EQ(value[1], 2.2f); + EXPECT_FLOAT_EQ(value[2], 42.0f); Uniform uniform_3{"dummy_value_dim_3", program_->id()}; - EXPECT_EQ(uniform_3.location(), 2); - uniform_3.UpdateValue(1.0f, 2.0f, 3.0f); + uniform_3.UpdateValue(1.11f, 2.22f, 3.33f); + glGetUniformfv(program_->id(), uniform_3.location(), value); + EXPECT_FLOAT_EQ(value[0], 1.11f); + EXPECT_FLOAT_EQ(value[1], 2.22f); + EXPECT_FLOAT_EQ(value[2], 3.33f); + EXPECT_FLOAT_EQ(value[3], 42.0f); Uniform uniform_4{"dummy_value_dim_4", program_->id()}; - EXPECT_EQ(uniform_4.location(), 3); uniform_4.UpdateValue(1.0f, 2.0f, 3.0f, 4.0f); + glGetUniformfv(program_->id(), uniform_4.location(), value); + EXPECT_FLOAT_EQ(value[0], 1.0f); + EXPECT_FLOAT_EQ(value[1], 2.0f); + EXPECT_FLOAT_EQ(value[2], 3.0f); + EXPECT_FLOAT_EQ(value[3], 4.0f); } TEST_F(UniformTest, UpdateValueFromEigenMat) { Uniform uniform_2{"dummy_value_dim_2", program_->id()}; - EXPECT_EQ(uniform_2.location(), 1); uniform_2.UpdateValue(Eigen::Vector2f{1.0f, 2.0f}); + float values_2[2] = {42.0f, 42.0f}; + glGetUniformfv(program_->id(), uniform_2.location(), values_2); + EXPECT_FLOAT_EQ(values_2[0], 1.0f); + EXPECT_FLOAT_EQ(values_2[1], 2.0f); Uniform uniform_3{"dummy_value_dim_3", program_->id()}; - EXPECT_EQ(uniform_3.location(), 2); uniform_3.UpdateValue(Eigen::Vector3f{1.0f, 2.0f, 3.0f}); + float values_3[3] = {42.0f, 42.0f, 42.0f}; + glGetUniformfv(program_->id(), uniform_3.location(), values_3); + EXPECT_FLOAT_EQ(values_3[0], 1.0f); + EXPECT_FLOAT_EQ(values_3[1], 2.0f); + EXPECT_FLOAT_EQ(values_3[2], 3.0f); Uniform uniform_4{"dummy_value_dim_4", program_->id()}; - EXPECT_EQ(uniform_4.location(), 3); uniform_4.UpdateValue(Eigen::Vector4f{1.0f, 2.0f, 3.0f, 4.0f}); + float values_4[4] = {42.0f, 42.0f, 42.0f, 42.0f}; + glGetUniformfv(program_->id(), uniform_4.location(), values_4); + EXPECT_FLOAT_EQ(values_4[0], 1.0f); + EXPECT_FLOAT_EQ(values_4[1], 2.0f); + EXPECT_FLOAT_EQ(values_4[2], 3.0f); + EXPECT_FLOAT_EQ(values_4[3], 4.0f); } TEST_F(UniformTest, UpdateValueFromPackOfIntegers) { Uniform uniform_1{"i_dummy_value_dim_1", program_->id()}; - EXPECT_EQ(uniform_1.location(), 4); uniform_1.UpdateValue(1); Uniform uniform_2{"i_dummy_value_dim_2", program_->id()}; - EXPECT_EQ(uniform_2.location(), 5); uniform_2.UpdateValue(1, 2); Uniform uniform_3{"i_dummy_value_dim_3", program_->id()}; - EXPECT_EQ(uniform_3.location(), 6); uniform_3.UpdateValue(1, 2, 3); Uniform uniform_4{"i_dummy_value_dim_4", program_->id()}; - EXPECT_EQ(uniform_4.location(), 7); uniform_4.UpdateValue(1, 2, 3, 4); } @@ -134,5 +157,5 @@ TEST_F(UniformTest, EverythingIsPossibleWithNonExistingUniform) { TEST(UniformDeathTest, InitWithoutProgram) { ::testing::FLAGS_gtest_death_test_style = "threadsafe"; - EXPECT_DEBUG_DEATH(Uniform("some_name", 0), ".*GL_INVALID_VALUE.*"); + EXPECT_DEBUG_DEATH(Uniform("some_name", 666), ".*GL_INVALID_VALUE.*"); } diff --git a/gl/ui/CMakeLists.txt b/gl/ui/CMakeLists.txt new file mode 100644 index 0000000..9c198e8 --- /dev/null +++ b/gl/ui/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(glfw) \ No newline at end of file diff --git a/gl/ui/core/user_input_handler.h b/gl/ui/core/user_input_handler.h index eb91f6f..8e25ff3 100644 --- a/gl/ui/core/user_input_handler.h +++ b/gl/ui/core/user_input_handler.h @@ -6,6 +6,7 @@ #define OPENGL_TUTORIALS_GL_UI_CORE_UX_INPUT_INTERFACE_H_ #include +#include #include namespace gl { diff --git a/gl/ui/glfw/CMakeLists.txt b/gl/ui/glfw/CMakeLists.txt new file mode 100644 index 0000000..df95976 --- /dev/null +++ b/gl/ui/glfw/CMakeLists.txt @@ -0,0 +1,26 @@ +add_library(glfw_viewer + glfw_user_input_handler.cpp + viewer.cpp +) +target_include_directories(glfw_viewer PUBLIC ${PROJECT_SOURCE_DIR}) +target_link_libraries(glfw_viewer PUBLIC + glfw + glad_gl_core_33 + glog::glog) + +# cc_library( +# name = "viewer", +# srcs = [ +# "glfw_user_input_handler.cpp", +# "viewer.cpp", +# ], +# hdrs = [ +# "glfw_user_input_handler.h", +# "viewer.h" +# ], +# deps = [ +# "//gl/core:core", +# "//gl/ui/core:user_input_handler", +# "@glfw//:glfw", +# ], +# ) diff --git a/gl/ui/glfw/glfw_user_input_handler.h b/gl/ui/glfw/glfw_user_input_handler.h index 664ed3b..08e2ddc 100644 --- a/gl/ui/glfw/glfw_user_input_handler.h +++ b/gl/ui/glfw/glfw_user_input_handler.h @@ -1,8 +1,10 @@ #ifndef OPENGL_TUTORIALS_GL_UI_GLFW_MOUSE_EVENT_HANDLER_H_ #define OPENGL_TUTORIALS_GL_UI_GLFW_MOUSE_EVENT_HANDLER_H_ -#include "GLFW/glfw3.h" #include "gl/ui/core/user_input_handler.h" + +#include "glad/gl.h" +#include "GLFW/glfw3.h" #include "glog/logging.h" #include diff --git a/gl/ui/glfw/viewer.cpp b/gl/ui/glfw/viewer.cpp index 1ddfe0f..b26e66c 100644 --- a/gl/ui/glfw/viewer.cpp +++ b/gl/ui/glfw/viewer.cpp @@ -36,8 +36,7 @@ bool Viewer::Initialize(const WindowSize& window_size, nullptr); if (!window_) { return false; } glfwMakeContextCurrent(window_); - - InitializeGlContext(glfwGetProcAddress); + gladLoadGL(glfwGetProcAddress); glfwSetFramebufferSizeCallback(window_, Viewer::OnResize); Resize(window_size); diff --git a/gl/ui/glfw/viewer.h b/gl/ui/glfw/viewer.h index 267497c..90f1596 100644 --- a/gl/ui/glfw/viewer.h +++ b/gl/ui/glfw/viewer.h @@ -1,9 +1,9 @@ #ifndef OPENGL_TUTORIALS_UI_GLFW_VIEWER_H_ #define OPENGL_TUTORIALS_UI_GLFW_VIEWER_H_ -#include "gl/core/opengl_object.h" #include "gl/ui/glfw/glfw_user_input_handler.h" +#include "glad/gl.h" #include "GLFW/glfw3.h" #include diff --git a/readme.md b/readme.md index 66a56dd..d1433a8 100644 --- a/readme.md +++ b/readme.md @@ -33,6 +33,8 @@ bazel test --test_output=errors --test_env=DISPLAY=:0 //... # test ### Prerequisites +TODO: requires jinja2 to be installed + The build is not fully hermetic and relies on some libraries present on your system. On Ubuntu 20.04 you would need to install some libraries. You can find the list in the [build job script](.github/workflows/main.yml). diff --git a/submodules/CMakeLists.txt b/submodules/CMakeLists.txt new file mode 100644 index 0000000..77e99a0 --- /dev/null +++ b/submodules/CMakeLists.txt @@ -0,0 +1,21 @@ +add_subdirectory(eigen) + +set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +add_subdirectory(glfw) +target_include_directories(glfw PUBLIC + $ + $) + +add_subdirectory(glog) + +add_subdirectory(abseil) +add_subdirectory(googletest) + +add_library(stb_image INTERFACE stb/stb_image.h) +target_include_directories( + stb_image INTERFACE ${PROJECT_SOURCE_DIR}/submodules) + +add_subdirectory(glad/cmake glad_cmake) +glad_add_library(glad_gl_core_33 REPRODUCIBLE API gl:core=3.3) diff --git a/submodules/abseil b/submodules/abseil new file mode 160000 index 0000000..e225d0b --- /dev/null +++ b/submodules/abseil @@ -0,0 +1 @@ +Subproject commit e225d0b2c658e3bdd9295e4392ffb2d0767d9476 diff --git a/submodules/eigen b/submodules/eigen new file mode 160000 index 0000000..1f05f51 --- /dev/null +++ b/submodules/eigen @@ -0,0 +1 @@ +Subproject commit 1f05f51517ec4fd91eed711e0f89e97a7c028c0e diff --git a/submodules/glad b/submodules/glad new file mode 160000 index 0000000..b105140 --- /dev/null +++ b/submodules/glad @@ -0,0 +1 @@ +Subproject commit b1051403cf81b984f9fc11cc5916adb5afd34766 diff --git a/submodules/glfw b/submodules/glfw new file mode 160000 index 0000000..dd8a678 --- /dev/null +++ b/submodules/glfw @@ -0,0 +1 @@ +Subproject commit dd8a678a66f1967372e5a5e3deac41ebf65ee127 diff --git a/submodules/glog b/submodules/glog new file mode 160000 index 0000000..05fbc65 --- /dev/null +++ b/submodules/glog @@ -0,0 +1 @@ +Subproject commit 05fbc65278db1aa545ca5cb743c31bc717a48d0f diff --git a/submodules/googletest b/submodules/googletest new file mode 160000 index 0000000..8c4dc11 --- /dev/null +++ b/submodules/googletest @@ -0,0 +1 @@ +Subproject commit 8c4dc11539e814ad7e16f3063dd0e36c4fd5a9b4 diff --git a/submodules/stb b/submodules/stb new file mode 160000 index 0000000..8b5f1f3 --- /dev/null +++ b/submodules/stb @@ -0,0 +1 @@ +Subproject commit 8b5f1f37b5b75829fc72d38e7b5d4bcbf8a26d55 diff --git a/third_party/glfw/glfw.BUILD b/third_party/glfw/glfw.BUILD index b2b13bb..bd50420 100644 --- a/third_party/glfw/glfw.BUILD +++ b/third_party/glfw/glfw.BUILD @@ -1,68 +1,7 @@ -WIN32_DEFINES = [ - "_GLFW_WIN32", -] - -WIN32_HDRS = [ - "src/win32_joystick.h", - "src/win32_platform.h", - "src/wgl_context.h", -] - -WIN32_SRCS = [ - "src/win32_init.c", - "src/win32_joystick.c", - "src/win32_monitor.c", - "src/win32_thread.c", - "src/win32_time.c", - "src/win32_window.c", - "src/wgl_context.c", -] - -WIN32_LINKOPTS = [ - "-DEFAULTLIB:user32.lib", - "-DEFAULTLIB:gdi32.lib", - "-DEFAULTLIB:shell32.lib", -] - -LINUX_DEFINES = [ - "_GLFW_HAS_XF86VM", - "_GLFW_X11", -] - -LINUX_HDRS = [ - "src/glx_context.h", - "src/linux_joystick.h", - "src/posix_thread.h", - "src/posix_time.h", - "src/x11_platform.h", -] - -LINUX_SRCS = [ - "src/glx_context.c", - "src/linux_joystick.c", - "src/posix_thread.c", - "src/posix_time.c", - "src/x11_init.c", - "src/x11_monitor.c", - "src/x11_window.c", -] - -LINUX_LINKOPTS = ["-lX11 -ldl -lpthread"] +load("@rules_cc//cc:defs.bzl", "cc_library", "objc_library") cc_library( name = "glfw_src", - hdrs = [ - "include/GLFW/glfw3.h", - "include/GLFW/glfw3native.h", - "src/egl_context.h", - "src/internal.h", - "src/osmesa_context.h", - "src/mappings.h", - "src/xkb_unicode.h", - ] + select({ - "@bazel_tools//src/conditions:windows": WIN32_HDRS, - "@bazel_tools//src/conditions:linux_x86_64": LINUX_HDRS, - }), srcs = [ "src/context.c", "src/egl_context.c", @@ -74,13 +13,95 @@ cc_library( "src/window.c", "src/xkb_unicode.c", ] + select({ - "@bazel_tools//src/conditions:windows": WIN32_SRCS, - "@bazel_tools//src/conditions:linux_x86_64": LINUX_SRCS, + "@platforms//os:windows": [ + "src/win32_init.c", + "src/win32_joystick.c", + "src/win32_monitor.c", + "src/win32_thread.c", + "src/win32_time.c", + "src/win32_window.c", + "src/wgl_context.c", + ], + "@platforms//os:macos": [ + "src/cocoa_time.c", + "src/posix_thread.c", + ], + "//conditions:default": [ + "src/glx_context.c", + "src/linux_joystick.c", + "src/posix_thread.c", + "src/posix_time.c", + "src/x11_init.c", + "src/x11_monitor.c", + "src/x11_window.c", + ], + }), + hdrs = [ + "include/GLFW/glfw3.h", + "include/GLFW/glfw3native.h", + "src/egl_context.h", + "src/internal.h", + "src/osmesa_context.h", + "src/mappings.h", + "src/xkb_unicode.h" + ] + select({ + "@platforms//os:windows": [ + "src/win32_joystick.h", + "src/win32_platform.h", + "src/wgl_context.h", + ], + "@platforms//os:macos": [ + "src/cocoa_joystick.h", + "src/cocoa_platform.h", + "src/glx_context.h", + "src/nsgl_context.h", + "src/null_joystick.h", + "src/null_platform.h", + "src/posix_thread.h", + "src/wl_platform.h", + ], + "//conditions:default": [ + "src/glx_context.h", + "src/linux_joystick.h", + "src/posix_thread.h", + "src/posix_time.h", + "src/x11_platform.h", + ], }), defines = select({ - "@bazel_tools//src/conditions:windows": WIN32_DEFINES, - "@bazel_tools//src/conditions:linux_x86_64": LINUX_DEFINES, + "@platforms//os:windows": [ + "_GLFW_WIN32", + ], + "@platforms//os:macos": [ + "_GLFW_COCOA", + "_GLFW_NSGL", + "_GLFW_NO_DLOAD_WINMM", + "_GLFW_USE_OPENGL", + ], + "//conditions:default": [ + "_GLFW_HAS_XF86VM", + "_GLFW_X11", + ], + }), + linkopts = select({ + "@platforms//os:windows": [ + "-DEFAULTLIB:user32.lib", + "-DEFAULTLIB:gdi32.lib", + "-DEFAULTLIB:shell32.lib", + ], + "@platforms//os:macos": [ + "-framework OpenGL", + "-framework Cocoa", + "-framework IOKit", + "-framework CoreFoundation", + ], + "//conditions:default": [], + }), + deps = select({ + "@platforms//os:macos": [], + "//conditions:default": [], }), + visibility = ["//visibility:private"], ) cc_library( @@ -89,11 +110,9 @@ cc_library( "include/GLFW/glfw3.h", "include/GLFW/glfw3native.h", ], - linkopts = select({ - "@bazel_tools//src/conditions:windows": WIN32_LINKOPTS, - "@bazel_tools//src/conditions:linux_x86_64": LINUX_LINKOPTS, - }), - deps = [":glfw_src"], + deps = [ + ":glfw_src", + ], strip_include_prefix = "include", visibility = ["//visibility:public"], ) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt new file mode 100644 index 0000000..89ce57c --- /dev/null +++ b/utils/CMakeLists.txt @@ -0,0 +1,28 @@ +add_library(eigen_utils INTERFACE + eigen_utils.h +) +target_link_libraries(eigen_utils INTERFACE eigen) + + +add_library(file_utils INTERFACE + file_utils.h +) +target_link_libraries(file_utils INTERFACE absl::optional) + + +add_library(type_traits INTERFACE + type_traits.h +) + +add_library(image INTERFACE image.h) +target_include_directories(image INTERFACE ${PROJECT_SOURCE_DIR}) +target_link_libraries(image INTERFACE file_utils stb_image absl::optional) + +add_executable(image_test image_test.cpp) +target_link_libraries(image_test PRIVATE image GTest::gtest_main) + +add_library(macro_utils INTERFACE macro_utils.h) +target_include_directories(macro_utils INTERFACE ${PROJECT_SOURCE_DIR}) + +add_executable(macro_utils_test macro_utils_test.cpp) +target_link_libraries(macro_utils_test PRIVATE macro_utils GTest::gtest_main) diff --git a/utils/image_test.cpp b/utils/image_test.cpp index cefd656..e7492d8 100644 --- a/utils/image_test.cpp +++ b/utils/image_test.cpp @@ -1,3 +1,4 @@ +#define STB_IMAGE_IMPLEMENTATION #include "utils/image.h" #include "gtest/gtest.h"