Get some basic stuff compiling
This commit is contained in:
parent
2bb3827a83
commit
f5ee4a13bf
|
@ -7,6 +7,6 @@ namespace orange
|
|||
template <size_t Length, size_t Alignment>
|
||||
struct AlignedStorage
|
||||
{
|
||||
alignas(Alignment) unsigned char data[Length];
|
||||
alignas(Alignment) uint8_t data[Length];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -53,12 +53,12 @@ namespace orange
|
|||
Result() = default;
|
||||
|
||||
template <typename... Args>
|
||||
T& Create(Args&&... args)
|
||||
Result& Create(Args&&... args)
|
||||
{
|
||||
Assert(!m_created);
|
||||
m_created = true;
|
||||
new(&m_data) T(Forward<Args>(args)...);
|
||||
return RefUnsafe();
|
||||
new(reinterpret_cast<void*>(&m_data)) T{ Forward<Args>(args)... };
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Destroy()
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <Orange/Core/Types.h>
|
||||
|
||||
// Needed for placement new/delete.
|
||||
#include <new>
|
||||
|
||||
namespace orange
|
||||
{
|
||||
struct FalseType { static constexpr bool Value = false; };
|
||||
|
@ -30,4 +35,4 @@ namespace orange
|
|||
{
|
||||
return static_cast<RemoveReference<T>&&>(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <Orange/Core/Result.h>
|
||||
#include <Orange/Render/Renderer.h>
|
||||
|
||||
namespace orange
|
||||
{
|
||||
class ForwardRenderer : public Renderer
|
||||
{
|
||||
public:
|
||||
~ForwardRenderer() = default;
|
||||
|
||||
static Result<ForwardRenderer> create(SDL_Window* window, const char* name)
|
||||
{
|
||||
Result<ForwardRenderer> result;
|
||||
|
||||
ForwardRenderer& renderer = result.Create();
|
||||
|
||||
if ((renderer.m_instance = createInstance(window, name)) == VK_NULL_HANDLE)
|
||||
return result.Error(BasicErrorCode::Failed);
|
||||
|
||||
return result.Success();
|
||||
}
|
||||
protected:
|
||||
friend Result<ForwardRenderer>;
|
||||
ForwardRenderer() = default;
|
||||
};
|
||||
}
|
|
@ -1,14 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <Orange/Core/Types.h>
|
||||
#include <Orange/Core/Result.h>
|
||||
#include <Orange/Core/SmallVector.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_vulkan.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
namespace orange
|
||||
{
|
||||
class Window;
|
||||
|
||||
class Instance
|
||||
{
|
||||
public:
|
||||
~Instance();
|
||||
|
||||
static Result<Instance> Create(Window& window, const char* name);
|
||||
protected:
|
||||
friend Result<Instance>;
|
||||
Instance(VkInstance instance);
|
||||
private:
|
||||
VkInstance m_instance = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
|
||||
class Renderer
|
||||
{
|
||||
|
@ -16,53 +30,9 @@ namespace orange
|
|||
~Renderer() = default;
|
||||
|
||||
protected:
|
||||
friend Result<Renderer>;
|
||||
Renderer() = default;
|
||||
|
||||
static VkInstance createInstance(SDL_Window* window, const char* name)
|
||||
{
|
||||
uint32_t instanceExtensionCount = {};
|
||||
if (SDL_Vulkan_GetInstanceExtensions(window, &instanceExtensionCount, nullptr) != SDL_TRUE)
|
||||
{
|
||||
//std::cerr << "Failed to get SDL instance extension count.\n";
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
SmallVector<const char *, 8> instanceExtensions{ instanceExtensionCount };
|
||||
if (SDL_Vulkan_GetInstanceExtensions(window, &instanceExtensionCount, instanceExtensions.Data()) != SDL_TRUE)
|
||||
{
|
||||
//std::cerr << "Failed to get SDL instance extensions.\n";
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
VkApplicationInfo appInfo =
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
.pApplicationName = name,
|
||||
.applicationVersion = VK_MAKE_VERSION(1, 0, 0),
|
||||
.pEngineName = "Orange",
|
||||
.engineVersion = VK_MAKE_VERSION(1, 0, 0),
|
||||
.apiVersion = VK_API_VERSION_1_3,
|
||||
};
|
||||
|
||||
VkInstanceCreateInfo instanceInfo =
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||
.pApplicationInfo = &appInfo,
|
||||
.enabledExtensionCount = instanceExtensionCount,
|
||||
.ppEnabledExtensionNames = instanceExtensions.Data(),
|
||||
};
|
||||
|
||||
VkResult result = VK_SUCCESS;
|
||||
VkInstance instance;
|
||||
if ((result = vkCreateInstance(&instanceInfo, nullptr, &instance)) != VK_SUCCESS)
|
||||
{
|
||||
//std::cerr << "Failed to create Vulkan instance.\n";
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private:
|
||||
VkInstance m_instance = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice m_device = VK_NULL_HANDLE;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <Orange/Core/Result.h>
|
||||
|
||||
struct SDL_Window;
|
||||
|
||||
namespace orange
|
||||
{
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
~Window();
|
||||
|
||||
bool GetInstanceExtensions(uint32_t *count, const char **extensions);
|
||||
|
||||
static Result<Window> Create();
|
||||
protected:
|
||||
friend Result<Window>;
|
||||
Window(SDL_Window* window);
|
||||
private:
|
||||
SDL_Window* m_window = nullptr;
|
||||
};
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
#include <Orange/Core/Result.h>
|
||||
#include <Orange/Render/ForwardRenderer.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
(void)argc; (void)argv;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#include <Orange/Core/Result.h>
|
||||
|
||||
#include <Orange/Render/Window.h>
|
||||
#include <Orange/Render/Renderer.h>
|
||||
|
||||
using namespace orange;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
(void)argc; (void)argv;
|
||||
|
||||
Result<Window> r_window = Window::Create();
|
||||
if (!r_window)
|
||||
return 1;
|
||||
|
||||
Window& window = *r_window;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,3 +1,9 @@
|
|||
executable('CubeTest', 'CubeTest.cpp',
|
||||
dependencies : [ sdl2_dep, vulkan_dep, orange_dep ],
|
||||
include_directories : [ orange_include ]
|
||||
)
|
||||
|
||||
executable('BSPViewer', 'BSPViewer.cpp',
|
||||
dependencies : [sdl2_dep, vulkan_dep],
|
||||
include_directories : [orange_include])
|
||||
dependencies : [ sdl2_dep, vulkan_dep, orange_dep ],
|
||||
include_directories : [ orange_include ]
|
||||
)
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
#include <Orange/Render/Renderer.h>
|
||||
#include <Orange/Render/Window.h>
|
||||
|
||||
namespace orange
|
||||
{
|
||||
static VkInstance CreateVkInstance(Window& window, const char* name)
|
||||
{
|
||||
#if 0
|
||||
uint32_t instanceExtensionCount = {};
|
||||
if (!window.GetInstanceExtensions(&instanceExtensionCount, nullptr))
|
||||
{
|
||||
//std::cerr << "Failed to get SDL instance extension count.\n";
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
SmallVector<const char *, 8> instanceExtensions{ instanceExtensionCount };
|
||||
if (!window.GetInstanceExtensions(&instanceExtensionCount, instanceExtensions.Data()))
|
||||
{
|
||||
//std::cerr << "Failed to get SDL instance extensions.\n";
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
VkApplicationInfo appInfo =
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
.pApplicationName = name,
|
||||
.applicationVersion = VK_MAKE_VERSION(1, 0, 0),
|
||||
.pEngineName = "Orange",
|
||||
.engineVersion = VK_MAKE_VERSION(1, 0, 0),
|
||||
.apiVersion = VK_API_VERSION_1_3,
|
||||
};
|
||||
|
||||
VkInstanceCreateInfo instanceInfo =
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||
.pApplicationInfo = &appInfo,
|
||||
.enabledExtensionCount = instanceExtensionCount,
|
||||
.ppEnabledExtensionNames = instanceExtensions.Data(),
|
||||
};
|
||||
|
||||
VkResult result = VK_SUCCESS;
|
||||
VkInstance instance;
|
||||
if ((result = vkCreateInstance(&instanceInfo, nullptr, &instance)) != VK_SUCCESS)
|
||||
{
|
||||
//std::cerr << "Failed to create Vulkan instance.\n";
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
return instance;
|
||||
#else
|
||||
return VK_NULL_HANDLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
Result<Instance> Instance::Create(Window& window, const char* name)
|
||||
{
|
||||
Result<Instance> result;
|
||||
|
||||
if (VkInstance instance = CreateVkInstance(window, name))
|
||||
return result.Create(instance).Success();
|
||||
|
||||
return result.Error(BasicErrorCode::Failed);
|
||||
}
|
||||
|
||||
Instance::Instance(VkInstance instance)
|
||||
: m_instance{ instance }
|
||||
{}
|
||||
|
||||
Instance::~Instance()
|
||||
{
|
||||
vkDestroyInstance(m_instance, nullptr);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#include "Orange/Core/Result.h"
|
||||
#include <Orange/Render/Window.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_vulkan.h>
|
||||
|
||||
namespace orange
|
||||
{
|
||||
Result<Window> Window::Create()
|
||||
{
|
||||
Result<Window> result;
|
||||
|
||||
if (!SDL_InitSubSystem(SDL_INIT_VIDEO))
|
||||
return result.Error(BasicErrorCode::Failed);
|
||||
|
||||
if (SDL_Window* window = SDL_CreateWindow("Orange", 0, 0, 1280, 720, SDL_WINDOW_VULKAN))
|
||||
return result.Create(window).Success();
|
||||
|
||||
return result.Error(BasicErrorCode::Failed);
|
||||
}
|
||||
|
||||
Window::Window(SDL_Window* window)
|
||||
: m_window{ window }
|
||||
{}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
SDL_DestroyWindow(m_window);
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
}
|
||||
|
||||
bool Window::GetInstanceExtensions(uint32_t *count, const char **extensions)
|
||||
{
|
||||
return SDL_Vulkan_GetInstanceExtensions(m_window, count, extensions) == SDL_TRUE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
orange_src = [
|
||||
'Render/Instance.cpp',
|
||||
'Render/Window.cpp',
|
||||
]
|
||||
|
||||
orange_lib = static_library('orange', orange_src,
|
||||
include_directories : [ orange_include ]
|
||||
)
|
||||
|
||||
orange_dep = declare_dependency(
|
||||
link_with : [ orange_lib ],
|
||||
include_directories : [ orange_include ]
|
||||
)
|
|
@ -1,2 +1,2 @@
|
|||
subdir('Core')
|
||||
subdir('Orange')
|
||||
subdir('Apps')
|
Loading…
Reference in New Issue