diff --git a/.gitignore b/.gitignore index db160bd..87df6fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .idea/ cmake-build-*/ bin/* +build/ +*.DS_Store src/core/Config.h src/core/Exported.h \ No newline at end of file diff --git a/README.md b/README.md index 4d1ec76..9879604 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Blackengine - YET another home grown 3D game engine. - Simple API for developers ## Building using cmake and conan -This instruction is for Linux users. Windows user should do naturally same things. +This instruction is for Linux users. Windows user should do naturally same things. Instructions for Mac users can be found below. You need to install Conan package manager to build the project. @@ -46,9 +46,36 @@ cmake -DCMAKE_INSTALL_PREFIX= .. ``` make -j2 install ``` - After this step blackengine will be installed at . + +## Build using Xcode on MacOS + +### Step 1 - 2 same as on Linux and Windows (see above) + +### Step 3. Generate Xcode project +``` +cmake -DCMAKE_INSTALL_PREFIX= -G Xcode.. +``` + +If you get following error +``` +No CMAKE_C_COMPILER could be found +No CMAKE_CXX_COMPILER could be found. +``` + +try run this command + +``` +sudo xcode-select --reset +``` + +then repeat step + +### Step 4. Open project in Xcode + +Now you can work with project like with any other Xcode project. + ## Examples There is examples of using blackengine in /examples folder of installation directory. Look for it. diff --git a/cmake/Libraries.cmake b/cmake/Libraries.cmake index e3bd2ba..ff7be32 100644 --- a/cmake/Libraries.cmake +++ b/cmake/Libraries.cmake @@ -14,6 +14,10 @@ if(UNIX) set(LINKLIBS_LIBRARIES ${LINKLIBS_LIBRARIES} ${CMAKE_DL_LIBS}) endif() +if(UNIX AND APPLE) + set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo") +endif() + list(APPEND LINKLIBS_SOURCES ${BLACKENGINE_LIBRARY_DIR}/glad/src/glad.c) set(CONAN_DISABLE_CHECK_COMPILER ON) diff --git a/src/core/PlatformHeaders.h b/src/core/PlatformHeaders.h index ac949f1..66ee0eb 100644 --- a/src/core/PlatformHeaders.h +++ b/src/core/PlatformHeaders.h @@ -11,6 +11,8 @@ #include #elif defined(BLACK_PLATFORM_LINUX) #include +#elif defined(BLACK_PLATFORM_MACOSX) +#include #endif #endif //BLACKENGINE_PLATFORMHEADERS_H diff --git a/src/core/Types.h b/src/core/Types.h index 7c496b9..69b1e84 100644 --- a/src/core/Types.h +++ b/src/core/Types.h @@ -14,6 +14,8 @@ #include #elif defined(BLACK_PLATFORM_LINUX) #include +#elif defined(BLACK_PLATFORM_MACOSX) +#include #endif @@ -23,7 +25,7 @@ using SharedLibrary = os::WindowsSharedLibrary; #elif defined(BLACK_PLATFORM_LINUX) using SharedLibrary = os::LinuxSharedLibrary; #elif defined(BLACK_PLATFORM_MACOSX) -using SharedLibrary = os::MacOSSharedLibrary; +using SharedLibrary = os::MacSharedLibrary; #endif /** diff --git a/src/core/plugins/macos/MacSharedLibrary.cpp b/src/core/plugins/macos/MacSharedLibrary.cpp new file mode 100644 index 0000000..d167240 --- /dev/null +++ b/src/core/plugins/macos/MacSharedLibrary.cpp @@ -0,0 +1,33 @@ +// +// Created by apopov on 16.07.2019. +// + +#include "MacSharedLibrary.h" + +namespace black::os { + +MacSharedLibrary::MacSharedLibrary(const std::string &name) + : AbstractSharedLibrary(name) { + +} + +void MacSharedLibrary::load() { + auto name = this->name + ".dylib"; + + this->handle = dlopen(name.c_str(), RTLD_LAZY); + + if (!this->handle) { + throw LibraryNotFoundException(name); + } +} + +void MacSharedLibrary::unload() { + if (this->handle) { + dlclose(this->handle); + } +} + +void *MacSharedLibrary::getFunctionPointer(std::string name) { + return dlsym(this->handle, name.c_str()); +} +} diff --git a/src/core/plugins/macos/MacSharedLibrary.h b/src/core/plugins/macos/MacSharedLibrary.h new file mode 100644 index 0000000..07598b4 --- /dev/null +++ b/src/core/plugins/macos/MacSharedLibrary.h @@ -0,0 +1,30 @@ +// +// Created by apopov on 16.07.2019. +// + +#ifndef BLACKENGINE_MACSHAREDLIBRARY_H +#define BLACKENGINE_MACSHAREDLIBRARY_H + +#include +#include + +namespace black::os { +/** + * MacOS dynamic library class + */ +class MacSharedLibrary : public AbstractSharedLibrary { +private: + void *handle; + +public: + explicit MacSharedLibrary(const std::string &name); + + void load() override; + void unload() override; + +private: + void *getFunctionPointer(std::string name) override; +}; +} + +#endif //BLACKENGINE_MACSHAREDLIBRARY_H diff --git a/src/plugins/gl/src/GLSLShaderProgram.cpp b/src/plugins/gl/src/GLSLShaderProgram.cpp index 681aca0..42a97b3 100644 --- a/src/plugins/gl/src/GLSLShaderProgram.cpp +++ b/src/plugins/gl/src/GLSLShaderProgram.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace black { @@ -117,4 +118,4 @@ void GLSLShaderProgram::setUniformVariable(const std::string &name, glm::vec4 ve glUniform4f(glGetUniformLocation(this->program, name.c_str()), vector.r, vector.g, vector.b, vector.a); } -} \ No newline at end of file +}