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

Merge dev to master #155

Merged
merged 4 commits into from
May 16, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
pull_request:
branches: [ "master" ]

env:
DISPLAY: ":99"
MESA_GL_VERSION_OVERRIDE: "4.6"

defaults:
run:
shell: bash
Expand Down Expand Up @@ -104,9 +108,15 @@ jobs:
- name: Analyze code
run: cmake -DPROJECT_BINARY_DIR=build -P cmake/run_clang_tidy.cmake

coverage:
name: coverage
runs-on: ubuntu-latest
unit-tests:
name: unit-tests ${{ matrix.platform.name }}
runs-on: ${{ matrix.platform.os }}

strategy:
matrix:
platform:
- { name: Windows, os: windows-latest, flags: -GNinja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug -DNOX_ENABLE_COVERAGE=ON -DNOX_BUILD_TESTS=ON }
- { name: Linux, os: ubuntu-latest, flags: -GNinja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug -DNOX_ENABLE_COVERAGE=ON -DNOX_BUILD_TESTS=ON }

steps:
- uses: actions/checkout@v4
Expand All @@ -121,12 +131,34 @@ jobs:

- name: Install dependencies
run: |
set -e

if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update && sudo apt-get install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev libgl1-mesa-dev gcovr
sudo apt-get update && sudo apt-get install xorg-dev libxrandr-dev libxcursor-dev libgl1-mesa-dev libegl1-mesa-dev libdrm-dev mesa-utils xvfb fluxbox gcovr
fi

if [ "$RUNNER_OS" == "Windows" ]; then
pip install gcovr
fi

- name: Create Display Linux
if: runner.os == 'Linux'
run: |
set -e

Xvfb $DISPLAY -screen 0 800x600x24 &
sleep 5
fluxbox > /dev/null 2>&1 &
sleep 5

- name: Install Windows Mesa3D
uses: ssciwr/setup-mesa-dist-win@v2
if: runner.os == 'Windows'
with:
build-type: 'release-msvc'

- name: Configure
run: cmake -S . -B build -GNinja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug -DNOX_ENABLE_COVERAGE=ON -DNOX_BUILD_TESTS=ON
run: cmake -S . -B build ${{ matrix.platform.flags }}

- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tools/__pycache__/
# Files
include/nox/export.h
src/opengl/nox_opengl_export.h
tests/utilities/config.h
cmake/nox_config.cmake
cmake/nox_config_version.cmake

scripts/custom_config.cmd
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "examples/third_party/glfw"]
path = examples/base/third_party/glfw
[submodule "third_party/glfw"]
path = third_party/glfw
url = https://github.com/glfw/glfw
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ endif()
# --------------------------------------------------
# Add subdirectories
# --------------------------------------------------
add_subdirectory(third_party)
add_subdirectory(src)

if(NOX_BUILD_EXAMPLES)
Expand Down
26 changes: 0 additions & 26 deletions examples/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
set(NOX_EXAMPLES_BASE_LIB_NAME "base")

set(NOX_EXAMPLES_BASE_DIR "${PROJECT_SOURCE_DIR}/examples/base")
set(NOX_EXAMPLES_BASE_THIRD_PARTY_DIR "${NOX_EXAMPLES_BASE_DIR}/third_party")

set(NOX_EXAMPLES_BASE_FOLDER_NAME "${NOX_EXAMPLES_FOLDER_NAME}/base")
set(NOX_EXAMPLES_BASE_THIRD_PARTY_FOLDER_NAME "${NOX_EXAMPLES_BASE_FOLDER_NAME}/third_party")

# --------------------------------------------------
# Create target
Expand Down Expand Up @@ -35,27 +30,6 @@ set_target_properties(
# --------------------------------------------------
# Link libraries
# --------------------------------------------------
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory(${NOX_EXAMPLES_BASE_THIRD_PARTY_DIR}/glfw glfw)
set_target_properties(
glfw
PROPERTIES
FOLDER "${NOX_EXAMPLES_BASE_THIRD_PARTY_FOLDER_NAME}/glfw"
)
set_target_properties(
update_mappings
PROPERTIES
FOLDER "${NOX_EXAMPLES_BASE_THIRD_PARTY_FOLDER_NAME}/glfw"
)

add_subdirectory(${NOX_EXAMPLES_BASE_THIRD_PARTY_DIR}/stb_image stb_image)
set_target_properties(
stb_image
PROPERTIES
FOLDER "${NOX_EXAMPLES_BASE_THIRD_PARTY_FOLDER_NAME}/stb_image"
)

target_link_libraries(
${NOX_EXAMPLES_BASE_LIB_NAME}
PUBLIC
Expand Down
1 change: 0 additions & 1 deletion examples/base/third_party/glfw
Submodule glfw deleted from a87acd
12 changes: 11 additions & 1 deletion src/asserts.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#pragma once

namespace nox {

inline bool assertDisabled = false;

[[nodiscard]] inline bool &getAssertDisabled() {
return assertDisabled;
}

} // namespace nox

// clang-format off

#if defined(NOX_DISABLE_ASSERTS) || !defined(NOX_DEBUG)
#define NOX_ASSERT(condition) (void)(condition)
#else
#include <cassert>
#define NOX_ASSERT(condition) assert(condition)
#define NOX_ASSERT(condition) assert((condition) || (assertDisabled))
#endif

#define NOX_ASSERT_MSG(condition, message) NOX_ASSERT((condition) && (message))
Expand Down
7 changes: 0 additions & 7 deletions src/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ generate_export_header(
# --------------------------------------------------
# Link libraries
# --------------------------------------------------
add_subdirectory(${NOX_THIRD_PARTY_DIR}/glad glad)
set_target_properties(
glad
PROPERTIES
FOLDER "${NOX_THIRD_PARTY_FOLDER_NAME}"
)

target_link_libraries(
${NOX_OPENGL_LIB_NAME}
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/opengl/gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GLContext : public Surface {
[[nodiscard]] static std::unique_ptr<GLContext> create(const SurfaceDescriptor &descriptor);

virtual void swapBuffers() const = 0;
virtual void setSwapInterval(bool value) const = 0;
virtual void setSwapInterval(bool interval) const = 0;

public:
GLContext() = default;
Expand Down
4 changes: 2 additions & 2 deletions src/opengl/linux/linux_gl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void LinuxGLContext::swapBuffers() const {
eglSwapBuffers(m_handleDisplay, m_handleSurface);
}

void LinuxGLContext::setSwapInterval(bool value) const {
eglSwapInterval(m_handleDisplay, static_cast<EGLint>(value));
void LinuxGLContext::setSwapInterval(bool interval) const {
eglSwapInterval(m_handleDisplay, static_cast<EGLint>(interval));
}

} // namespace nox
2 changes: 1 addition & 1 deletion src/opengl/linux/linux_gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LinuxGLContext : public GLContext {
[[nodiscard]] bool initialize(const OpenGLSurfaceAttributesDescriptor &descriptor);

void swapBuffers() const override;
void setSwapInterval(bool value) const override;
void setSwapInterval(bool interval) const override;

protected:
[[nodiscard]] virtual bool setDisplayHandle() = 0;
Expand Down
4 changes: 0 additions & 4 deletions src/opengl/linux/x11_gl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ X11GLContext::X11GLContext(const X11SurfaceBackendDescriptor &descriptor) {
}

X11GLContext::~X11GLContext() {
[[maybe_unused]] XWindowAttributes windowAttributes; // NOLINT
NOX_ASSERT_MSG(XGetWindowAttributes(m_handleDisplayX11, m_handleWindowX11, &windowAttributes),
"The window handle associated with OpenGL context is invalid");

m_handleDisplayX11 = nullptr;
m_handleWindowX11 = 0u;
}
Expand Down
13 changes: 5 additions & 8 deletions src/opengl/windows/windows_gl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ bool GLContext::validateInput(const SurfaceDescriptor &descriptor) {
}

std::unique_ptr<GLContext> GLContext::create(const SurfaceDescriptor &descriptor) {
if (!loadOpenGL()) {
return nullptr;
}
NOX_ENSURE_RETURN_NULLPTR_MSG(loadOpenGL(), "Couldn't preload WGL");

const auto *surfaceBackendDescriptor = std::get_if<WindowsSurfaceBackendDescriptor>(&descriptor.surfaceBackendDescriptor);
const auto *surfaceAttributesDescriptor = std::get_if<OpenGLSurfaceAttributesDescriptor>(&descriptor.surfaceAttributesDescriptor);
Expand All @@ -101,12 +99,9 @@ std::unique_ptr<GLContext> GLContext::create(const SurfaceDescriptor &descriptor
WindowsGLContext::WindowsGLContext(const WindowsSurfaceBackendDescriptor &descriptor) {
m_handleWindow = static_cast<HWND>(descriptor.windowHandle);
m_handleDeviceContext = GetDC(m_handleWindow);
NOX_ASSERT_MSG(m_handleDeviceContext != nullptr, "Couldn't get device context for given window handle");
}

WindowsGLContext::~WindowsGLContext() {
NOX_ASSERT_MSG(IsWindow(m_handleWindow), "The window handle associated with OpenGL context is invalid");

wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(m_handleRenderingContext);
ReleaseDC(m_handleWindow, m_handleDeviceContext);
Expand All @@ -119,6 +114,8 @@ WindowsGLContext::~WindowsGLContext() {
}

bool WindowsGLContext::initialize(const OpenGLSurfaceAttributesDescriptor &descriptor) {
NOX_ENSURE_RETURN_FALSE_MSG(m_handleDeviceContext != nullptr, "Couldn't get device context");

std::array<int32_t, 19> pixelFormatAttributes{WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
Expand Down Expand Up @@ -159,8 +156,8 @@ void WindowsGLContext::swapBuffers() const {
SwapBuffers(m_handleDeviceContext);
}

void WindowsGLContext::setSwapInterval(bool value) const {
wglSwapIntervalEXT(static_cast<int32_t>(value));
void WindowsGLContext::setSwapInterval(bool interval) const {
wglSwapIntervalEXT(static_cast<int32_t>(interval));
}

} // namespace nox
2 changes: 1 addition & 1 deletion src/opengl/windows/windows_gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WindowsGLContext final : public GLContext {
[[nodiscard]] bool initialize(const OpenGLSurfaceAttributesDescriptor &descriptor);

void swapBuffers() const override;
void setSwapInterval(bool value) const override;
void setSwapInterval(bool interval) const override;

private:
HWND m_handleWindow{nullptr};
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/linux/linux_dynamic_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

#include <dlfcn.h>

#include <filesystem>

namespace nox {

std::unique_ptr<Plugin> Plugin::create(std::string_view name) {
constexpr auto searchPath = "./";
constexpr auto extension = "so";
std::unique_ptr<Plugin> Plugin::create(const std::string &name) {
constexpr auto extension = ".so";

const auto filename = searchPath + createPluginFilename<usePrefix, usePostfix>(name, extension);
const auto filename = std::filesystem::absolute(name + extension).string();
auto plugin = std::make_unique<LinuxDynamicPlugin>();
NOX_ENSURE_RETURN_NULLPTR(plugin->load(filename));

Expand Down
29 changes: 0 additions & 29 deletions src/plugins/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "plugins/plugin.h"

#include <algorithm>

namespace nox {

bool Plugin::pluginRegister() const {
Expand All @@ -12,31 +10,4 @@ uint8_t Plugin::pluginVersion() const {
return m_pluginVersionFunction();
}

template <bool usePrefix, bool usePostfix>
std::string createPluginFilename(std::string_view name, std::string_view extension) {
constexpr auto prefix = (usePrefix ? "lib" : "");
constexpr auto infix = "nox-";
constexpr auto postfix = (usePostfix ? "-d" : "");
auto toLower = [](std::string str) {
std::transform(str.begin(), str.end(), str.begin(), [](auto c) {
return static_cast<char>(std::tolower(c));
});
return str;
};

std::string result;
result += prefix;
result += infix;
result += name.data();
result += postfix;
result += '.';
result += extension;
return toLower(result);
}

template std::string createPluginFilename<false, false>(std::string_view, std::string_view);
template std::string createPluginFilename<true, false>(std::string_view, std::string_view);
template std::string createPluginFilename<false, true>(std::string_view, std::string_view);
template std::string createPluginFilename<true, true>(std::string_view, std::string_view);

} // namespace nox
36 changes: 28 additions & 8 deletions src/plugins/plugin.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#pragma once

#include <nox/export.h>

#include <algorithm>
#include <cstdint>
#include <memory>
#include <string>

namespace nox {

class Plugin {
class NOX_EXPORT Plugin {
public:
[[nodiscard]] static std::unique_ptr<Plugin> create(std::string_view name);
[[nodiscard]] static std::unique_ptr<Plugin> create(const std::string &name);

[[nodiscard]] bool pluginRegister() const;
[[nodiscard]] uint8_t pluginVersion() const;
Expand All @@ -32,18 +35,35 @@ class Plugin {
};

#if defined(NOX_USE_PLUGIN_PREFIX)
inline constexpr auto usePrefix = true;
inline constexpr auto usePluginPrefix = true;
#else
inline constexpr auto usePrefix = false;
inline constexpr auto usePluginPrefix = false;
#endif

#if defined(NOX_USE_PLUGIN_POSTFIX)
inline constexpr auto usePostfix = true;
inline constexpr auto usePluginPostfix = true;
#else
inline constexpr auto usePostfix = false;
inline constexpr auto usePluginPostfix = false;
#endif

template <bool usePrefix, bool usePostfix>
[[nodiscard]] std::string createPluginFilename(std::string_view name, std::string_view extension);
template <bool usePrefix = usePluginPrefix, bool usePostfix = usePluginPostfix>
[[nodiscard]] inline std::string createPluginName(std::string_view name) {
constexpr auto prefix = (usePrefix ? "lib" : "");
constexpr auto infix = "nox-";
constexpr auto postfix = (usePostfix ? "-d" : "");
auto toLower = [](std::string str) {
std::transform(str.begin(), str.end(), str.begin(), [](auto c) {
return static_cast<char>(std::tolower(c));
});
return str;
};

std::string result;
result += prefix;
result += infix;
result += name.data();
result += postfix;
return toLower(result);
}

} // namespace nox
2 changes: 1 addition & 1 deletion src/plugins/plugin_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
#define NOX_PLUGIN_IMPORT(pluginName)

#define NOX_PLUGIN_CREATE(pluginName) \
nox::Plugin::create(#pluginName)
nox::Plugin::create(createPluginName(#pluginName))
#endif
Loading