Commit c7e5ace7 authored by Johannes Braun's avatar Johannes Braun
Browse files

Transformed nested namespaces to c++17 conformity

parent 79a4a0b2
......@@ -10,7 +10,7 @@ include(${CMAKE_MODULE_PATH}/setup/macros.cmake)
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest")
endif()
if(SYS_WINDOWS)
......
#include <any>
#include <vector>
#include <algorithm>
std::vector<std::any> anystuff;
void[[deprecated]] bla()
constexpr int bla()
{
return 4;
}
int main()
{
anystuff.push_back(std::make_any<int>(10));
bla();
bool b = true;
......
......@@ -3,7 +3,8 @@
#include <core/objects/skybox.h>
#include <core/rendering/batch_renderer.h>
#include <components/PlayerController.h>
#include <components/PlayerController.h>
#include <core/objects/camera.h>
#include "imgui/imgui.h"
#include "imgui/imgui_glfw.h"
......
......@@ -5,7 +5,8 @@
#include <core/rendering/mesh_drawable.h>
#include <core/rendering/batch_renderer.h>
#include <core/rendering/batch_render_list.h>
#include <core/rendering/batch_render_list.h>
#include <core/objects/camera.h>
using namespace glare;
......
......@@ -2,6 +2,7 @@
#include <core/state.h>
#include <core/control.h>
#include <core/objects/camera.h>
#include <core/time.h>
#include <imgui/imgui_glfw.h>
#include <core/message_tags.h>
......
......@@ -10,169 +10,166 @@
// --- INTERN ---------------------------------------------
namespace glare
namespace glare::core
{
namespace core
template<gl::BufferType TBuffer>
class Buffer
{
template<gl::BufferType TBuffer>
class Buffer
{
public:
Buffer();
Buffer(Buffer& other) = delete;
Buffer& operator=(Buffer& other) = delete;
Buffer(Buffer&& other) = default;
Buffer& operator=(Buffer&& other) = default;
~Buffer();
void bind() const;
void bind(unsigned point) const;
void unbind() const;
unsigned id() const;
uint64_t residentAddress() const;
bool resident() const;
uint64_t makeResident(gl::Access access);
void makeNonResident() const;
template<typename T> void upload(size_t count, const T* data, gl::BufferUsage usage) const;
template<typename T> void upload(const std::vector<T>& data, gl::BufferUsage usage) const;
template<typename T = uint8_t> void reserve(size_t count, gl::BufferUsage usage) const;
template<typename T> std::vector<T> download(size_t count, size_t offset = 0) const;
template<typename TReturn = void> TReturn* map(size_t count, size_t offset, gl::BufferMapBit flags) const;
template<typename TReturn = void> TReturn* map(size_t count, gl::BufferMapBit flags) const;
void unmap() const;
protected:
gl::handle::buffer m_handle;
uint64_t m_resident_address = 0;
};
// -------------------------------------------------------------------------------------------------------------------------
// --- IMPLEMENTATIONS -----------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
template<gl::BufferType TBuffer> Buffer<TBuffer>::Buffer() {}
template<gl::BufferType TBuffer>
Buffer<TBuffer>::~Buffer()
{
makeNonResident();
}
public:
Buffer();
Buffer(Buffer& other) = delete;
Buffer& operator=(Buffer& other) = delete;
Buffer(Buffer&& other) = default;
Buffer& operator=(Buffer&& other) = default;
~Buffer();
void bind() const;
void bind(unsigned point) const;
void unbind() const;
unsigned id() const;
uint64_t residentAddress() const;
bool resident() const;
uint64_t makeResident(gl::Access access);
void makeNonResident() const;
template<typename T> void upload(size_t count, const T* data, gl::BufferUsage usage) const;
template<typename T> void upload(const std::vector<T>& data, gl::BufferUsage usage) const;
template<typename T = uint8_t> void reserve(size_t count, gl::BufferUsage usage) const;
template<typename T> std::vector<T> download(size_t count, size_t offset = 0) const;
template<typename TReturn = void> TReturn* map(size_t count, size_t offset, gl::BufferMapBit flags) const;
template<typename TReturn = void> TReturn* map(size_t count, gl::BufferMapBit flags) const;
void unmap() const;
protected:
gl::handle::buffer m_handle;
uint64_t m_resident_address = 0;
};
// -------------------------------------------------------------------------------------------------------------------------
// --- IMPLEMENTATIONS -----------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
template<gl::BufferType TBuffer> Buffer<TBuffer>::Buffer() {}
template<gl::BufferType TBuffer>
Buffer<TBuffer>::~Buffer()
{
makeNonResident();
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::bind() const
{
gl::bindBuffer(TBuffer, m_handle);
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::bind() const
{
gl::bindBuffer(TBuffer, m_handle);
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::bind(unsigned point) const
{
bind();
gl::bindBufferBase(TBuffer, point, m_handle);
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::bind(unsigned point) const
{
bind();
gl::bindBufferBase(TBuffer, point, m_handle);
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::unbind() const
{
gl::bindBuffer(TBuffer, 0);
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::unbind() const
{
gl::bindBuffer(TBuffer, 0);
}
template<gl::BufferType TBuffer>
unsigned Buffer<TBuffer>::id() const
{
return m_handle;
}
template<gl::BufferType TBuffer>
unsigned Buffer<TBuffer>::id() const
{
return m_handle;
}
template<gl::BufferType TBuffer>
uint64_t Buffer<TBuffer>::residentAddress() const
{
return m_resident_address;
}
template<gl::BufferType TBuffer>
uint64_t Buffer<TBuffer>::residentAddress() const
{
return m_resident_address;
}
template<gl::BufferType TBuffer>
bool Buffer<TBuffer>::resident() const
{
return gl::isNamedBufferResident(m_handle);
}
template<gl::BufferType TBuffer>
bool Buffer<TBuffer>::resident() const
{
return gl::isNamedBufferResident(m_handle);
}
template<gl::BufferType TBuffer>
uint64_t Buffer<TBuffer>::makeResident(gl::Access access)
template<gl::BufferType TBuffer>
uint64_t Buffer<TBuffer>::makeResident(gl::Access access)
{
if (!resident())
{
if (!resident())
{
bind();
gl::makeNamedBufferResident(m_handle, access);
gl::getNamedBufferParameterui64v(m_handle, gl::GetNamedBufferParameters::eGPUAddress, &m_resident_address);
}
assert(resident());
return m_resident_address;
bind();
gl::makeNamedBufferResident(m_handle, access);
gl::getNamedBufferParameterui64v(m_handle, gl::GetNamedBufferParameters::eGPUAddress, &m_resident_address);
}
assert(resident());
return m_resident_address;
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::makeNonResident() const
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::makeNonResident() const
{
if (resident())
{
if (resident())
{
gl::makeNamedBufferNonResident(m_handle);
}
gl::makeNamedBufferNonResident(m_handle);
}
}
template<gl::BufferType TBuffer>
template<typename T>
void Buffer<TBuffer>::upload(size_t count, const T* data, gl::BufferUsage usage) const
{
gl::namedBufferData(m_handle, sizeof(T) * count, data, usage);
}
template<gl::BufferType TBuffer>
template<typename T>
void Buffer<TBuffer>::upload(size_t count, const T* data, gl::BufferUsage usage) const
{
gl::namedBufferData(m_handle, sizeof(T) * count, data, usage);
}
template<gl::BufferType TBuffer>
template<typename T>
void Buffer<TBuffer>::upload(const std::vector<T>& data, gl::BufferUsage usage) const
{
gl::namedBufferData(m_handle, sizeof(T) * data.size(), data.data(), usage);
}
template<gl::BufferType TBuffer>
template<typename T>
void Buffer<TBuffer>::upload(const std::vector<T>& data, gl::BufferUsage usage) const
{
gl::namedBufferData(m_handle, sizeof(T) * data.size(), data.data(), usage);
}
template<gl::BufferType TBuffer>
template<typename T>
void Buffer<TBuffer>::reserve(size_t count, gl::BufferUsage usage) const
{
upload<T>(count, nullptr, usage);
}
template<gl::BufferType TBuffer>
template<typename T>
void Buffer<TBuffer>::reserve(size_t count, gl::BufferUsage usage) const
{
upload<T>(count, nullptr, usage);
}
template<gl::BufferType TBuffer>
template<typename T>
std::vector<T> Buffer<TBuffer>::download(size_t count, size_t offset) const
{
std::vector<T> out(count);
memcpy(out.data(), map(count, offset, gl::BufferMapBit::eRead), count * sizeof(T));
unmap();
return out;
}
template<gl::BufferType TBuffer>
template<typename T>
std::vector<T> Buffer<TBuffer>::download(size_t count, size_t offset) const
{
std::vector<T> out(count);
memcpy(out.data(), map(count, offset, gl::BufferMapBit::eRead), count * sizeof(T));
unmap();
return out;
}
template<gl::BufferType TBuffer>
template<typename TReturn>
TReturn* Buffer<TBuffer>::map(size_t count, size_t offset, gl::BufferMapBit flags) const
{
// as you can't do sizeof(void), you can set it equivalent to 8 bit.
using measure_t = templates::decide_on_t<std::is_same<void, TReturn>::value, uint8_t, TReturn>;
return reinterpret_cast<TReturn*>(gl::mapNamedBufferRange(m_handle, offset * sizeof(measure_t), count * sizeof(measure_t), flags));
}
template<gl::BufferType TBuffer>
template<typename TReturn>
TReturn* Buffer<TBuffer>::map(size_t count, size_t offset, gl::BufferMapBit flags) const
{
// as you can't do sizeof(void), you can set it equivalent to 8 bit.
using measure_t = templates::decide_on_t<std::is_same<void, TReturn>::value, uint8_t, TReturn>;
return reinterpret_cast<TReturn*>(gl::mapNamedBufferRange(m_handle, offset * sizeof(measure_t), count * sizeof(measure_t), flags));
}
template<gl::BufferType TBuffer>
template<typename TReturn>
TReturn* Buffer<TBuffer>::map(size_t count, gl::BufferMapBit flags) const
{
return map<TReturn>(count, 0, flags);
}
template<gl::BufferType TBuffer>
template<typename TReturn>
TReturn* Buffer<TBuffer>::map(size_t count, gl::BufferMapBit flags) const
{
return map<TReturn>(count, 0, flags);
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::unmap() const
{
gl::unmapNamedBuffer(m_handle);
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::unmap() const
{
gl::unmapNamedBuffer(m_handle);
}
}
......
......@@ -11,159 +11,156 @@
// --- INTERN ---------------------------------------------
namespace glare
namespace glare::core
{
namespace core
{
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
class Framebuffer
{
public:
using texture_color_type = TTextureBase<gl::TextureFormat::eRGBA, gl::TextureInternalFormat::eRGBA32Float, gl::Type::eFloat>;
using texture_depth_type = TTextureBase<gl::TextureFormat::eDepthComponent, gl::TextureInternalFormat::eDepthComponent32Float, gl::Type::eFloat>;
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
class Framebuffer
{
public:
using texture_color_type = TTextureBase<gl::TextureFormat::eRGBA, gl::TextureInternalFormat::eRGBA32Float, gl::Type::eFloat>;
using texture_depth_type = TTextureBase<gl::TextureFormat::eDepthComponent, gl::TextureInternalFormat::eDepthComponent32Float, gl::Type::eFloat>;
static constexpr bool is_multisampled = texture_color_type::is_multisampled;
static constexpr bool is_multisampled = texture_color_type::is_multisampled;
Framebuffer(unsigned width, unsigned height, unsigned samples = 1);
Framebuffer(Framebuffer& other) = delete;
Framebuffer& operator=(Framebuffer& other) = delete;
Framebuffer(Framebuffer&& other) = default;
Framebuffer& operator=(Framebuffer&& other) = default;
~Framebuffer();
Framebuffer(unsigned width, unsigned height, unsigned samples = 1);
Framebuffer(Framebuffer& other) = delete;
Framebuffer& operator=(Framebuffer& other) = delete;
Framebuffer(Framebuffer&& other) = default;
Framebuffer& operator=(Framebuffer&& other) = default;
~Framebuffer();
void resize(unsigned width, unsigned height, unsigned samples);
void resize(unsigned width, unsigned height, unsigned samples);
void activate() const;
void deactivate() const;
void activate() const;
void deactivate() const;
void attach(gl::Attachment attachment);
const texture_color_type &colorAttachment(gl::Attachment attachment) const;
const texture_depth_type &depthAttachment() const;
void attach(gl::Attachment attachment);
const texture_color_type &colorAttachment(gl::Attachment attachment) const;
const texture_depth_type &depthAttachment() const;
unsigned attachments() const;
unsigned samples() const;
unsigned attachments() const;
unsigned samples() const;
private:
void putAttachment(gl::Attachment attachment, unsigned texture);
private:
void putAttachment(gl::Attachment attachment, unsigned texture);
gl::handle::framebuffer m_handle;
gl::handle::framebuffer m_handle;
unsigned m_width;
unsigned m_height;
unsigned m_samples;
unsigned m_width;
unsigned m_height;
unsigned m_samples;
std::vector<gl::Attachment> m_draw_buffers;
std::map<gl::Attachment, std::shared_ptr<texture_color_type>> m_color_attachments;
std::shared_ptr<texture_depth_type> m_depth_attachment;
};
std::vector<gl::Attachment> m_draw_buffers;
std::map<gl::Attachment, std::shared_ptr<texture_color_type>> m_color_attachments;
std::shared_ptr<texture_depth_type> m_depth_attachment;
};
// -------------------------------------------------------------------------------------------------------------------------
// --- IMPLEMENTATIONS -----------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
// --- IMPLEMENTATIONS -----------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
Framebuffer<TTextureBase>::Framebuffer(unsigned width, unsigned height, unsigned samples)
: m_width(width), m_height(height), m_samples(samples) {}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
Framebuffer<TTextureBase>::Framebuffer(unsigned width, unsigned height, unsigned samples)
: m_width(width), m_height(height), m_samples(samples) {}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
Framebuffer<TTextureBase>::~Framebuffer() {}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
Framebuffer<TTextureBase>::~Framebuffer() {}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
void Framebuffer<TTextureBase>::resize(unsigned width, unsigned height, unsigned samples)
{
if (width == m_width && height == m_height)
return;
m_width = width;
m_height = height;
m_samples = samples;
for (auto &&texture : m_color_attachments) {
is_multisampled ? texture.second->resize(width, height, m_samples) : texture.second->resize(width, height);
}
if (m_depth_attachment) {
is_multisampled ? m_depth_attachment->resize(width, height, m_samples) : m_depth_attachment->resize(width, height);
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
void Framebuffer<TTextureBase>::resize(unsigned width, unsigned height, unsigned samples)
{
if (width == m_width && height == m_height)
return;
m_width = width;
m_height = height;
m_samples = samples;
for (auto &&texture : m_color_attachments) {
is_multisampled ? texture.second->resize(width, height, m_samples) : texture.second->resize(width, height);
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
void Framebuffer<TTextureBase>::activate() const
{
gl::bindFramebuffer(gl::FramebufferTarget::eDefault, m_handle);
if (m_depth_attachment) {
is_multisampled ? m_depth_attachment->resize(width, height, m_samples) : m_depth_attachment->resize(width, height);
}
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
void Framebuffer<TTextureBase>::deactivate() const
{
gl::bindFramebuffer(gl::FramebufferTarget::eDefault, 0);
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
void Framebuffer<TTextureBase>::activate() const
{
gl::bindFramebuffer(gl::FramebufferTarget::eDefault, m_handle);
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
void Framebuffer<TTextureBase>::attach(gl::Attachment attachment)
{
switch (attachment)
{
case gl::Attachment::eDepth:
case gl::Attachment::eDepthStencil:
if (is_multisampled)
m_depth_attachment = std::make_shared<texture_depth_type>(m_width, m_height, m_samples);
else
m_depth_attachment = std::make_shared<texture_depth_type>(m_width, m_height);
gl::namedFramebufferTexture(m_handle, attachment, m_depth_attachment->id(), 0);
break;
default:
{
std::shared_ptr<texture_color_type> new_attachment;
if (is_multisampled)
new_attachment = std::make_shared<texture_color_type>(m_width, m_height, m_samples);
else
new_attachment = std::make_shared<texture_color_type>(m_width, m_height);
m_color_attachments.emplace(attachment, new_attachment);
putAttachment(attachment, new_attachment->id());
} break;
}
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
void Framebuffer<TTextureBase>::deactivate() const
{
gl::bindFramebuffer(gl::FramebufferTarget::eDefault, 0);
}
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
const typename Framebuffer<TTextureBase>::texture_color_type &Framebuffer<TTextureBase>::colorAttachment(gl::Attachment attachment) const
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
void Framebuffer<TTextureBase>::attach(gl::Attachment attachment)
{
switch (attachment)
{
return *(m_color_attachments.at(attachment));
}
case gl::Attachment::eDepth:
case gl::Attachment::eDepthStencil:
if (is_multisampled)
m_depth_attachment = std::make_shared<texture_depth_type>(m_width, m_height, m_samples);
else
m_depth_attachment = std::make_shared<texture_depth_type>(m_width, m_height);
gl::namedFramebufferTexture(m_handle, attachment, m_depth_attachment->id(), 0);
break;
default:
{
std::shared_ptr<texture_color_type> new_attachment;
if (is_multisampled)
new_attachment = std::make_shared<texture_color_type>(m_width, m_height, m_samples);
else
new_attachment = std::make_shared<texture_color_type>(m_width, m_height);
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
const typename Framebuffer<TTextureBase>::texture_depth_type &Framebuffer<TTextureBase>::depthAttachment() const
{
return *m_depth_attachment;
}
m_color_attachments.emplace(attachment, new_attachment);
template<template<gl::TextureFormat, gl::TextureInternalFormat, gl::Type> typename TTextureBase>
unsigned Framebuffer<TTextureBase>::attachments() const