main
Brett 2025-06-08 01:38:19 -04:00
parent f2630fd153
commit 43303bc19a
4 changed files with 83 additions and 39 deletions

View File

@ -283,6 +283,7 @@
<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" />

View File

@ -2,6 +2,26 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug-addrsan/_deps/freetype-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug-addrsan/_deps/freetype-src/subprojects/dlg" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug-addrsan/_deps/glfw3-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug-addrsan/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/freetype-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/freetype-src/subprojects/dlg" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/glfw3-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/freetype-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/freetype-src/subprojects/dlg" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/glfw3-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo-addrsan/_deps/freetype-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo-addrsan/_deps/freetype-src/subprojects/dlg" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo-addrsan/_deps/glfw3-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo-addrsan/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/freetype-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/freetype-src/subprojects/dlg" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/glfw3-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/imgui-src" vcs="Git" />
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics" vcs="Git" />
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics/libraries/BLT" vcs="Git" />
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics/libraries/BLT/libraries/parallel-hashmap" vcs="Git" />

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
project(gpu-particles VERSION 0.0.5)
project(gpu-particles VERSION 0.0.6)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -19,6 +19,7 @@
#include "blt/gfx/renderer/batch_2d_renderer.h"
#include "blt/gfx/renderer/camera.h"
#include <blt/std/random.h>
#include <blt/debug.h>
#include <shaders/particle.frag>
#include <shaders/particle.vert>
#include <imgui.h>
@ -31,17 +32,39 @@ blt::gfx::resource_manager resources;
blt::gfx::batch_renderer_2d renderer_2d(resources, global_matrices);
blt::gfx::first_person_camera camera;
// use types for state that way you are not confused about what is happening?
class unique_vao_t
{
public:
unique_vao_t(): vaoID(0)
{}
void create()
{
#if blt_debug_has_flag(BLT_DEBUG_CONTRACTS)
BLT_CONTRACT(!vaoID, "VAO already created");
#endif
vaoID = 0;
glGenVertexArrays(1, &*vaoID);
}
private:
std::optional<GLuint> vaoID;
};
struct particle_t
{
blt::vec2 position;
blt::vec2 velocity;
blt::vec2 acceleration;
blt::vec2 position;
blt::vec2 velocity;
blt::vec2 acceleration;
static particle_t make_particle()
{
blt::random::random_t random{std::random_device()()};
return {blt::vec2{random.get(0.0f, 500.0f), random.get(0.0f, 500.0f)}, blt::vec2{}, blt::vec2{}};
}
static particle_t make_particle()
{
blt::random::random_t random{std::random_device()()};
return {blt::vec2{random.get(0.0f, 500.0f), random.get(0.0f, 500.0f)}, blt::vec2{}, blt::vec2{}};
}
};
std::unique_ptr<blt::gfx::vertex_array_t> particle_vao;
@ -55,53 +78,53 @@ std::vector<particle_t> particles;
void init(const blt::gfx::window_data&)
{
using namespace blt::gfx;
using namespace blt::gfx;
particle_shader = std::unique_ptr<shader_t>(shader_t::make(shader_particle_2d_vert, shader_particle_2d_frag));
particle_shader = std::unique_ptr<shader_t>(shader_t::make(shader_particle_2d_vert, shader_particle_2d_frag));
for (blt::size_t i = 0; i < PARTICLE_COUNT; i++)
{
particles.push_back(particle_t::make_particle());
alive_particles.push_back(i);
}
for (blt::size_t i = 0; i < PARTICLE_COUNT; i++)
{
particles.push_back(particle_t::make_particle());
alive_particles.push_back(i);
}
particle_vbo = std::make_unique<vertex_buffer_t>();
particle_vbo->create(GL_ARRAY_BUFFER);
particle_vbo->allocate(sizeof(particle_t) * particles.size(), GL_DYNAMIC_DRAW, particles.data());
particle_vbo = std::make_unique<vertex_buffer_t>();
particle_vbo->create(GL_ARRAY_BUFFER);
particle_vbo->allocate(sizeof(particle_t) * particles.size(), GL_DYNAMIC_DRAW, particles.data());
alive_particles_ebo = std::make_unique<element_buffer_t>();
alive_particles_ebo->create();
alive_particles_ebo->allocate(sizeof(blt::u32) * alive_particles.size(), GL_DYNAMIC_DRAW, alive_particles.data());
alive_particles_ebo = std::make_unique<element_buffer_t>();
alive_particles_ebo->create();
alive_particles_ebo->allocate(sizeof(blt::u32) * alive_particles.size(), GL_DYNAMIC_DRAW, alive_particles.data());
particle_vao = std::make_unique<vertex_array_t>();
particle_vao->bindVBO(*particle_vbo, 0, 2, GL_FLOAT, sizeof(particle_t), 0);
particle_vao->bindElement(*alive_particles_ebo);
particle_vao = std::make_unique<vertex_array_t>();
particle_vao->bindVBO(*particle_vbo, 0, 2, GL_FLOAT, sizeof(particle_t), 0);
particle_vao->bindElement(*alive_particles_ebo);
global_matrices.create_internals();
resources.load_resources();
renderer_2d.create();
global_matrices.create_internals();
resources.load_resources();
renderer_2d.create();
}
void update(const blt::gfx::window_data& data)
{
global_matrices.update_perspectives(data.width, data.height, 90, 0.1, 2000);
global_matrices.update_perspectives(data.width, data.height, 90, 0.1, 2000);
camera.update();
camera.update_view(global_matrices);
global_matrices.update();
camera.update();
camera.update_view(global_matrices);
global_matrices.update();
renderer_2d.render(data.width, data.height);
renderer_2d.render(data.width, data.height);
}
void destroy(const blt::gfx::window_data&)
{
global_matrices.cleanup();
resources.cleanup();
renderer_2d.cleanup();
blt::gfx::cleanup();
global_matrices.cleanup();
resources.cleanup();
renderer_2d.cleanup();
blt::gfx::cleanup();
}
int main()
{
blt::gfx::init(blt::gfx::window_data{"My Sexy Window", init, update, destroy}.setSyncInterval(1));
}
blt::gfx::init(blt::gfx::window_data{"My Sexy Window", init, update, destroy}.setSyncInterval(1));
}