more files
parent
9e62497cae
commit
03136cdd9e
|
@ -283,11 +283,8 @@
|
|||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TOPLEVEL_FUNCTION_DECLARATION_RETURN_TYPE_STYLE/@EntryValue" value="ON_SINGLE_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TOPLEVEL_FUNCTION_DEFINITION_RETURN_TYPE_STYLE/@EntryValue" value="ON_SINGLE_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BRACED_INIT_LIST_STYLE/@EntryValue" value="CHOP_IF_LONG" type="string" />
|
||||
<option name="/Default/CodeStyle/CppIncludeDirective/SortIncludeDirectives/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CppIncludeDirective/UseAngleBracketsInsteadOfQuotes/@EntryValue" value="WhenPossible" type="string" />
|
||||
<option name="/Default/CodeStyle/CppIncludeDirective/UseRelativePaths/@EntryValue" value="Never" type="string" />
|
||||
<option name="/Default/CodeStyle/Generate/=CppDefinitions/@KeyIndexDefined" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/Generate/=CppDefinitions/Options/=GenerateInlineDefinitions/@EntryIndexedValue" value="False" type="string" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
project(gpu-particles VERSION 0.0.9)
|
||||
project(gpu-particles VERSION 0.0.10)
|
||||
|
||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
#pragma once
|
||||
/*
|
||||
* Copyright (C) 2024 Brett Terpstra
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BLT_GFX_VAO_H
|
||||
#define BLT_GFX_VAO_H
|
||||
|
||||
#include <vbo.h>
|
||||
|
||||
namespace blt::gfx
|
||||
{
|
||||
|
||||
class unique_vao_t
|
||||
{
|
||||
public:
|
||||
unique_vao_t(): vaoID(0)
|
||||
{
|
||||
glGenVertexArrays(1, &*vaoID);
|
||||
}
|
||||
|
||||
unique_vao_t(const unique_vao_t&) = delete;
|
||||
|
||||
unique_vao_t& operator=(const unique_vao_t&) = delete;
|
||||
|
||||
unique_vao_t(unique_vao_t&& other) noexcept: vaoID(std::exchange(other.vaoID, std::nullopt))
|
||||
{}
|
||||
|
||||
unique_vao_t& operator=(unique_vao_t&& other) noexcept
|
||||
{
|
||||
vaoID = std::exchange(other.vaoID, vaoID);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~unique_vao_t()
|
||||
{
|
||||
if (vaoID)
|
||||
glDeleteVertexArrays(1, &*vaoID);
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<GLuint> vaoID;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //BLT_GFX_VAO_H
|
|
@ -0,0 +1,147 @@
|
|||
#pragma once
|
||||
/*
|
||||
* Copyright (C) 2024 Brett Terpstra
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BLT_GFX_VBO_H
|
||||
#define BLT_GFX_VBO_H
|
||||
|
||||
#include <vbo.h>
|
||||
#include <vbo.h>
|
||||
#include <vbo.h>
|
||||
#include <blt/gfx/gl_includes.h>
|
||||
|
||||
namespace blt::gfx
|
||||
{
|
||||
class unique_vbo_t;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
class vbo_context_t
|
||||
{
|
||||
public:
|
||||
explicit vbo_context_t(unique_vbo_t& vbo): vbo(vbo)
|
||||
{
|
||||
bind();
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, the VBO is bound when this class is constructed (this class should only be constructed through the VBO bind() method)
|
||||
*
|
||||
* It is very unlikely that you need this method!
|
||||
*/
|
||||
vbo_context_t& bind();
|
||||
|
||||
vbo_context_t& unbind();
|
||||
|
||||
vbo_context_t& reserve(GLsizeiptr size, GLint mem_type);
|
||||
|
||||
vbo_context_t& reserve(const size_t size, const GLint mem_type)
|
||||
{
|
||||
return reserve(static_cast<GLsizeiptr>(size), mem_type);
|
||||
}
|
||||
|
||||
vbo_context_t& upload(size_t size, void* ptr, GLint mem_type);
|
||||
|
||||
template <typename T>
|
||||
vbo_context_t& upload(const size_t size, T* ptr, const GLint mem_type)
|
||||
{
|
||||
return upload(size, static_cast<void*>(ptr), mem_type);
|
||||
}
|
||||
|
||||
vbo_context_t& update(size_t offset, size_t size, const void* ptr);
|
||||
|
||||
template <typename T>
|
||||
vbo_context_t& update(size_t offset, const size_t size, T* ptr)
|
||||
{
|
||||
return upload(offset, size, static_cast<void*>(ptr));
|
||||
}
|
||||
|
||||
private:
|
||||
unique_vbo_t& vbo;
|
||||
};
|
||||
}
|
||||
|
||||
class unique_vbo_t
|
||||
{
|
||||
friend class detail::vbo_context_t;
|
||||
|
||||
public:
|
||||
explicit unique_vbo_t(const GLuint type): buffer_type(type)
|
||||
{
|
||||
glGenBuffers(1, &*vboID);
|
||||
}
|
||||
|
||||
unique_vbo_t(const unique_vbo_t&) = delete;
|
||||
|
||||
unique_vbo_t& operator=(const unique_vbo_t&) = delete;
|
||||
|
||||
unique_vbo_t(unique_vbo_t&& other) noexcept: vboID(std::exchange(other.vboID, std::nullopt)), buffer_type(other.buffer_type),
|
||||
size(other.size), memory_type(other.memory_type)
|
||||
{}
|
||||
|
||||
unique_vbo_t& operator=(unique_vbo_t&& other) noexcept
|
||||
{
|
||||
vboID = std::exchange(other.vboID, vboID);
|
||||
buffer_type = std::exchange(other.buffer_type, buffer_type);
|
||||
size = std::exchange(other.size, size);
|
||||
memory_type = std::exchange(other.memory_type, memory_type);
|
||||
return *this;
|
||||
}
|
||||
|
||||
GLuint change_type(const GLuint type)
|
||||
{
|
||||
return std::exchange(this->buffer_type, type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto bind();
|
||||
|
||||
~unique_vbo_t()
|
||||
{
|
||||
if (vboID)
|
||||
glDeleteBuffers(1, &*vboID);
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<GLuint> vboID;
|
||||
GLuint buffer_type;
|
||||
GLsizeiptr size = 0;
|
||||
GLint memory_type = 0;
|
||||
};
|
||||
|
||||
class unique_ssbo_t : public unique_vbo_t
|
||||
{
|
||||
public:
|
||||
unique_ssbo_t(): unique_vbo_t{GL_SHADER_STORAGE_BUFFER}
|
||||
{}
|
||||
};
|
||||
|
||||
class unique_ebo_t : public unique_vbo_t
|
||||
{
|
||||
public:
|
||||
unique_ebo_t(): unique_vbo_t{GL_ELEMENT_ARRAY_BUFFER}
|
||||
{}
|
||||
};
|
||||
|
||||
class unique_ubo_t : public unique_vbo_t
|
||||
{
|
||||
public:
|
||||
unique_ubo_t(): unique_vbo_t{GL_UNIFORM_BUFFER}
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //BLT_GFX_VBO_H
|
119
src/main.cpp
119
src/main.cpp
|
@ -19,7 +19,8 @@
|
|||
#include "blt/gfx/renderer/batch_2d_renderer.h"
|
||||
#include "blt/gfx/renderer/camera.h"
|
||||
#include <blt/std/random.h>
|
||||
#include <blt/debug.h>
|
||||
#include <vao.h>
|
||||
#include <vbo.h>
|
||||
#include <shaders/particle.frag>
|
||||
#include <shaders/particle.vert>
|
||||
#include <imgui.h>
|
||||
|
@ -34,122 +35,6 @@ blt::gfx::first_person_camera camera;
|
|||
|
||||
// use types for state that way you are not confused about what is happening?
|
||||
|
||||
class unique_vbo_t;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
class vbo_context_t
|
||||
{
|
||||
public:
|
||||
explicit vbo_context_t(unique_vbo_t& vbo): vbo(vbo)
|
||||
{
|
||||
bind();
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, the VBO is bound when this class is constructed (this class should only be constructed through the VBO bind() method)
|
||||
* This function is provided in case you need to rebind the VBO
|
||||
*/
|
||||
vbo_context_t& bind();
|
||||
|
||||
vbo_context_t& unbind();
|
||||
|
||||
private:
|
||||
unique_vbo_t& vbo;
|
||||
};
|
||||
}
|
||||
|
||||
class unique_vbo_t
|
||||
{
|
||||
friend class detail::vbo_context_t;
|
||||
|
||||
public:
|
||||
explicit unique_vbo_t(const GLuint type): type(type)
|
||||
{
|
||||
glGenBuffers(1, &*vboID);
|
||||
}
|
||||
|
||||
unique_vbo_t(const unique_vbo_t&) = delete;
|
||||
|
||||
unique_vbo_t& operator=(const unique_vbo_t&) = delete;
|
||||
|
||||
unique_vbo_t(unique_vbo_t&& other) noexcept: vboID(std::exchange(other.vboID, std::nullopt)), type(other.type)
|
||||
{}
|
||||
|
||||
unique_vbo_t& operator=(unique_vbo_t&& other) noexcept
|
||||
{
|
||||
vboID = std::exchange(other.vboID, vboID);
|
||||
type = std::exchange(other.type, type);
|
||||
return *this;
|
||||
}
|
||||
|
||||
GLuint change_type(const GLuint type)
|
||||
{
|
||||
return std::exchange(this->type, type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto bind()
|
||||
{
|
||||
return detail::vbo_context_t{*this};
|
||||
}
|
||||
|
||||
~unique_vbo_t()
|
||||
{
|
||||
if (vboID)
|
||||
glDeleteBuffers(1, &*vboID);
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<GLuint> vboID;
|
||||
GLuint type;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
vbo_context_t& vbo_context_t::bind()
|
||||
{
|
||||
glBindBuffer(vbo.type, *vbo.vboID);
|
||||
return *this;
|
||||
}
|
||||
|
||||
vbo_context_t& vbo_context_t::unbind()
|
||||
{
|
||||
glBindBuffer(vbo.type, 0);
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
class unique_vao_t
|
||||
{
|
||||
public:
|
||||
unique_vao_t(): vaoID(0)
|
||||
{
|
||||
glGenVertexArrays(1, &*vaoID);
|
||||
}
|
||||
|
||||
unique_vao_t(const unique_vao_t&) = delete;
|
||||
|
||||
unique_vao_t& operator=(const unique_vao_t&) = delete;
|
||||
|
||||
unique_vao_t(unique_vao_t&& other) noexcept: vaoID(std::exchange(other.vaoID, std::nullopt))
|
||||
{}
|
||||
|
||||
unique_vao_t& operator=(unique_vao_t&& other) noexcept
|
||||
{
|
||||
vaoID = std::exchange(other.vaoID, vaoID);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~unique_vao_t()
|
||||
{
|
||||
if (vaoID)
|
||||
glDeleteVertexArrays(1, &*vaoID);
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<GLuint> vaoID;
|
||||
};
|
||||
|
||||
struct particle_t
|
||||
{
|
||||
blt::vec2 position;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* <Short Description>
|
||||
* Copyright (C) 2025 Brett Terpstra
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <vao.h>
|
||||
|
||||
namespace blt::gfx
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* <Short Description>
|
||||
* Copyright (C) 2025 Brett Terpstra
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <vbo.h>
|
||||
#include <blt/gfx/window.h>
|
||||
#include <blt/std/assert.h>
|
||||
|
||||
namespace blt::gfx
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
vbo_context_t& vbo_context_t::bind()
|
||||
{
|
||||
BLT_CONTRACT(vbo.vboID, "Expected VBO to have an assoicated VBO ID!");
|
||||
glBindBuffer(vbo.type, *vbo.vboID);
|
||||
return *this;
|
||||
}
|
||||
|
||||
vbo_context_t& vbo_context_t::unbind()
|
||||
{
|
||||
glBindBuffer(vbo.type, 0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
vbo_context_t& vbo_context_t::reserve(const GLsizeiptr size, const GLint mem_type)
|
||||
{
|
||||
vbo.size = size;
|
||||
vbo.memory_type = mem_type;
|
||||
glBufferData(vbo.buffer_type, size, nullptr, mem_type);
|
||||
return *this;
|
||||
}
|
||||
|
||||
vbo_context_t& vbo_context_t::upload(const size_t size, void* ptr, const GLint mem_type)
|
||||
{
|
||||
if (mem_type != vbo.memory_type || vbo.size < size)
|
||||
{
|
||||
vbo.size = static_cast<GLsizeiptr>(size);
|
||||
vbo.memory_type = mem_type;
|
||||
glBufferData(vbo.buffer_type, vbo.size, ptr, mem_type);
|
||||
} else
|
||||
{
|
||||
update(0, size, ptr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
vbo_context_t& vbo_context_t::update(const size_t offset, const size_t size, const void* ptr)
|
||||
{
|
||||
glBufferSubData(vbo.buffer_type, static_cast<GLsizeiptr>(offset), static_cast<GLsizeiptr>(size), ptr);
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
auto unique_vbo_t::bind()
|
||||
{
|
||||
BLT_CONTRACT(glfwGetCurrentContext() != nullptr, "Expected active OpenGL context!");
|
||||
return detail::vbo_context_t{*this};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue