Commit 81a9a181 authored by Johannes Braun's avatar Johannes Braun
Browse files

Removed annoyingly unuseful gl::BufferType template from Buffer class

parent 74252eee
#include "buffer.h"
#include <cassert>
namespace glare::core
{
Buffer::~Buffer()
{
makeNonResident();
}
void Buffer::bind(gl::BufferType target, unsigned point) const
{
gl::bindBufferBase(target, point, m_handle);
}
unsigned Buffer::id() const
{
return m_handle;
}
uint64_t Buffer::residentAddress() const
{
return m_resident_address;
}
bool Buffer::resident() const
{
return gl::isNamedBufferResident(m_handle);
}
uint64_t Buffer::makeResident(gl::Access access)
{
if (!resident())
{
gl::makeNamedBufferResident(m_handle, access);
gl::getNamedBufferParameterui64v(m_handle, gl::GetNamedBufferParameters::eGPUAddress, &m_resident_address);
}
assert(resident());
return m_resident_address;
}
void Buffer::makeNonResident() const
{
if (resident())
{
gl::makeNamedBufferNonResident(m_handle);
}
}
void Buffer::unmap() const
{
gl::unmapNamedBuffer(m_handle);
}
}
\ No newline at end of file
......@@ -16,11 +16,10 @@ namespace glare::core
* \brief An objectified OpenGL buffer representation. Uses the bindless buffer approach from later OpenGL Versions (4.5+)
* \tparam TBuffer The OpenGL buffer type. May be any of those in gl::BufferType.
*/
template<gl::BufferType TBuffer>
class Buffer
{
public:
Buffer();
Buffer() = default;
Buffer(Buffer& other) = delete;
Buffer& operator=(Buffer& other) = delete;
Buffer(Buffer&& other) = default;
......@@ -30,7 +29,7 @@ namespace glare::core
/**
* \brief Binds the shader to a defined shader storage binding point retrieved from the shader program itself.
*/
void bind(unsigned point) const;
void bind(gl::BufferType target, unsigned point) const;
/**
* \return The buffer handle id
......@@ -90,84 +89,27 @@ namespace glare::core
// -------------------------------------------------------------------------------------------------------------------------
// --- IMPLEMENTATIONS -----------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
template<gl::BufferType TBuffer> Buffer<TBuffer>::Buffer() {}
template<gl::BufferType TBuffer>
Buffer<TBuffer>::~Buffer()
{
makeNonResident();
}
template<gl::BufferType TBuffer>
void Buffer<TBuffer>::bind(unsigned point) const
{
gl::bindBufferBase(TBuffer, point, 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>
bool Buffer<TBuffer>::resident() const
{
return gl::isNamedBufferResident(m_handle);
}
template<gl::BufferType TBuffer>
uint64_t Buffer<TBuffer>::makeResident(gl::Access access)
{
if (!resident())
{
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
{
if (resident())
{
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
void Buffer::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
void Buffer::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
void Buffer::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> Buffer::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));
......@@ -175,27 +117,19 @@ namespace glare::core
return out;
}
template<gl::BufferType TBuffer>
template<typename TReturn>
TReturn* Buffer<TBuffer>::map(size_t count, size_t offset, gl::BufferMapBit flags) const
TReturn* Buffer::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
TReturn* Buffer::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);
}
}
#endif //INCLUDE_BUFFER_H
......@@ -171,9 +171,9 @@ namespace glare::core
}
}
void Program::storageBuffer(const std::string& name, const Buffer<gl::BufferType::eShaderStorage> &buffer) const
void Program::storageBuffer(const std::string& name, const Buffer &buffer) const
{
buffer.bind(bufferBlock(name));
buffer.bind(gl::BufferType::eShaderStorage, bufferBlock(name));
}
int Program::attributeLocation(const std::string &attribute) const
......
......@@ -51,7 +51,7 @@ namespace glare::core
void bindSubroutine(gl::ShaderType stage, const std::string& uniform, const std::string& subroutine);
// buffers
void storageBuffer(const std::string& name, const Buffer<gl::BufferType::eShaderStorage> &buffer) const;
void storageBuffer(const std::string& name, const Buffer &buffer) const;
// can be set for all structs which have a uniformUpdate(const Program&, const std::string&) method.
template<typename T> void uniformStruct(const std::string& name, const T& object);
......
......@@ -113,8 +113,8 @@ namespace glare::core
{
computeTangents();
m_array_buffer = std::make_unique<Buffer<gl::BufferType::eArray>>();
m_element_array_buffer = std::make_unique<Buffer<gl::BufferType::eElementArray>>();
m_array_buffer = std::make_unique<Buffer>();
m_element_array_buffer = std::make_unique<Buffer>();
m_vertex_array = std::make_unique<VertexArray>();
m_array_buffer->upload(m_vertices, gl::BufferUsage::eStaticDraw);
......
......@@ -42,8 +42,8 @@ namespace glare::core
std::vector<math::Vertex> m_vertices;
std::vector<unsigned int> m_indices;
std::unique_ptr<Buffer<gl::BufferType::eArray>> m_array_buffer;
std::unique_ptr<Buffer<gl::BufferType::eElementArray>> m_element_array_buffer;
std::unique_ptr<Buffer> m_array_buffer;
std::unique_ptr<Buffer> m_element_array_buffer;
std::unique_ptr<VertexArray> m_vertex_array;
};
......
......@@ -42,7 +42,7 @@ namespace glare::core
m_temporary_framebuffer_02 = std::make_shared<Framebuffer<Texture>>(static_cast<unsigned>(mode->width), static_cast<unsigned>(mode->height));
m_temporary_framebuffer_02->attach(gl::Attachment::eColor0);
m_lights_buffer = std::make_unique<Buffer<gl::BufferType::eShaderStorage>>();
m_lights_buffer = std::make_unique<Buffer>();
//Update all uniforms that won't change anymore...
m_texture_renderer->shader().uniform("u_gbuffer.base_ior", m_gbuffer_framebuffer->colorAttachment(gl::Attachment::eColor0).makeTextureResident());
......
......@@ -46,7 +46,7 @@ namespace glare::core
int m_width;
int m_height;
std::unique_ptr<Buffer<gl::BufferType::eShaderStorage>> m_lights_buffer;
std::unique_ptr<Buffer> m_lights_buffer;
std::map<uint64_t, size_t> m_light_to_index;
std::vector<LightShadow> m_lights;
std::shared_ptr<Skybox> m_skybox;
......
......@@ -434,7 +434,7 @@ namespace glare::core
Text::Text() : m_length(0)
{
m_text_buffer = std::make_unique<Buffer<gl::BufferType::eShaderStorage>>();
m_text_buffer = std::make_unique<Buffer>();
}
Text::~Text()
......@@ -516,7 +516,7 @@ namespace glare::core
set(txt, max_dimensions);
}
const Buffer<gl::BufferType::eShaderStorage>& Text::getBuffer() const
const Buffer& Text::getBuffer() const
{
return *m_text_buffer;
}
......
......@@ -129,7 +129,7 @@ namespace glare::core
void set(const std::wstring &text, glm::vec2 max_dimensions = glm::vec2(-1));
const Buffer<gl::BufferType::eShaderStorage>& getBuffer() const;
const Buffer& getBuffer() const;
const color::rgba32f& getColor() const;
......@@ -144,7 +144,7 @@ namespace glare::core
private:
Align m_align = Align::eLeft;
std::wstring m_text;
std::unique_ptr<Buffer<gl::BufferType::eShaderStorage>> m_text_buffer;
std::unique_ptr<Buffer> m_text_buffer;
std::shared_ptr<Font> m_current_font;
glm::vec2 m_max_dimensions = glm::vec2(-1);
......
......@@ -82,6 +82,8 @@ namespace glare::core
eWireframe = 2,
};
~Context();
// Only make current context mutable
template<typename... Args>
static id_type create(Args&&... args);
......@@ -122,7 +124,6 @@ namespace glare::core
// Private constructor! You shall not own this object or define your own context lifetime!
Context();
~Context();
void initialize(const fs::path& preferences);
void initialize(unsigned width, unsigned height, unsigned samples, std::string title);
......
......@@ -42,8 +42,8 @@ namespace ImGui {
int m_attrib_texture = 0;
int m_attrib_projection = 0;
glare::core::Buffer<gl::BufferType::eArray> m_vertex_buffer;
glare::core::Buffer<gl::BufferType::eElementArray> m_element_buffer;
glare::core::Buffer m_vertex_buffer;
glare::core::Buffer m_element_buffer;
glare::core::VertexArray m_vertex_array;
std::unique_ptr<glare::core::TextureRGBA_UB> m_font_texture;
std::unique_ptr<glare::core::Program> m_program;
......
......@@ -220,7 +220,7 @@ namespace glare::raytrace
return 2 * (patchCount(Face::ePosX) + patchCount(Face::ePosY) + patchCount(Face::ePosZ)) * linesPerPatch();
}
const core::Buffer<gl::BufferType::eShaderStorage> &AngularLinespace::lineBuffer() const
const core::Buffer &AngularLinespace::lineBuffer() const
{
return m_line_buffer;
}
......
......@@ -31,7 +31,7 @@ namespace glare::raytrace
const math::Subdivision& subdivision() const;
LinespaceData data() const;
const core::Buffer<gl::BufferType::eShaderStorage> &lineBuffer() const;
const core::Buffer &lineBuffer() const;
private:
void generateCPU(const LocalCollector &collector);
void generateGPU(const LocalCollector &collector);
......@@ -42,7 +42,7 @@ namespace glare::raytrace
glm::vec3 patchCenter(const SurfacePatch &patch);
unsigned patchCount(Face face) const;
core::Buffer<gl::BufferType::eShaderStorage> m_line_buffer;
core::Buffer m_line_buffer;
math::Bounds m_bounds;
math::Subdivision m_subdivision;
......
......@@ -77,7 +77,7 @@ namespace glare::raytrace
*/
bool traverse(const Ray &ray, float max_distance, bool finish_after_hit, std::function<bool(const Ray &, float, bool, int)> check_traversal_primitive) const;
const core::Buffer<gl::BufferType::eShaderStorage>& buffer() const;
const core::Buffer& buffer() const;
const std::vector<Node> &nodes() const;
private:
......@@ -91,7 +91,7 @@ namespace glare::raytrace
const int32_t m_plane_count = m_bin_count - 1;
const float m_bin_epsilon = 0.01f;
core::Buffer<gl::BufferType::eShaderStorage> m_node_buffer;
core::Buffer m_node_buffer;
std::vector<Node> m_nodes;
......@@ -111,7 +111,7 @@ namespace glare::raytrace
};
template<typename TPrimitive>
const core::Buffer<gl::BufferType::eShaderStorage>& BVH<TPrimitive>::buffer() const
const core::Buffer& BVH<TPrimitive>::buffer() const
{
return m_node_buffer;
}
......
......@@ -32,7 +32,7 @@ namespace glare::raytrace
void apply(core::Program &program) override;
private:
core::Buffer<gl::BufferType::eShaderStorage> m_light_buffer;
core::Buffer m_light_buffer;
std::vector<Light> m_lights;
};
......
......@@ -42,9 +42,9 @@ namespace glare::raytrace
void assign();
core::Buffer<gl::BufferType::eShaderStorage> m_mesh_buffer;
core::Buffer<gl::BufferType::eShaderStorage> m_material_buffer;
core::Buffer<gl::BufferType::eShaderStorage> m_bvh_id_buffer;
core::Buffer m_mesh_buffer;
core::Buffer m_material_buffer;
core::Buffer m_bvh_id_buffer;
std::map<size_t, std::unique_ptr<LocalCollector>> m_local_collectors; //!< mesh renderer id to mesh collector
std::map<size_t, size_t> m_material_filter;
......
......@@ -266,7 +266,7 @@ namespace glare::raytrace
return data;
}
const core::Buffer<gl::BufferType::eShaderStorage> &Linespace::lineBuffer() const
const core::Buffer &Linespace::lineBuffer() const
{
return m_line_buffer;
}
......
......@@ -97,7 +97,7 @@ namespace glare::raytrace
void generate(const LocalCollector &collector, int max_subdivisions, const Platform generator = Platform::eCPU);
LinespaceData data() const;
const core::Buffer<gl::BufferType::eShaderStorage> &lineBuffer() const;
const core::Buffer &lineBuffer() const;
const math::Bounds &bounds() const;
const math::Subdivision &subdivision() const;
......@@ -116,7 +116,7 @@ namespace glare::raytrace
math::Bounds m_bounds;
math::Subdivision m_subdivision;
core::Buffer<gl::BufferType::eShaderStorage> m_line_buffer;
core::Buffer m_line_buffer;
//Collection of startpatch-endpatch configurations for merging two loops
//in the generation process into one parallel loop.
......
......@@ -34,7 +34,7 @@ namespace glare::raytrace
});
}
const core::Buffer<gl::BufferType::eShaderStorage>& LocalBVH::buffer() const
const core::Buffer& LocalBVH::buffer() const
{
return m_base_bvh.buffer();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment