add optimisations

This commit is contained in:
Jay Robson 2024-03-17 13:07:44 +11:00
parent 25861bbf16
commit ddec7eeb9d
8 changed files with 91 additions and 33 deletions

BIN
assets/scene.blend (Stored with Git LFS)

Binary file not shown.

BIN
assets/scene.glb (Stored with Git LFS)

Binary file not shown.

View File

@ -5,6 +5,7 @@
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include "../shader.hpp" #include "../shader.hpp"
#include "../../util/streams.hpp"
#include "arrays.hpp" #include "arrays.hpp"
#include "font.hpp" #include "font.hpp"
@ -41,3 +42,17 @@ void Arrays::vertex_attrib_pointers()
glEnableVertexAttribArray(6); glEnableVertexAttribArray(6);
} }
std::ostream& Arrays::operator<<(std::ostream& os, const Vertex& v)
{
os << "Vertex{";
os << "texid=" << v.texid << ", ";
os << "texpos=" << v.texpos << ", ";
os << "pos=" << v.pos << ", ";
os << "normal=" << v.normal << ", ";
os << "colour=" << v.colour << ", ";
os << "material=" << v.material << ", ";
os << "transform_id=" << v.transform_id;
os << "}";
return os;
}

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <glm/matrix.hpp> #include <glm/matrix.hpp>
#include <ostream>
namespace Sim::Graphics::Arrays namespace Sim::Graphics::Arrays
{ {
@ -18,6 +19,8 @@ struct Vertex
constexpr bool operator==(const Vertex&) const = default; constexpr bool operator==(const Vertex&) const = default;
friend std::ostream& operator<<(std::ostream& os, const Vertex& v);
} __attribute__((packed)); } __attribute__((packed));
void vertex_attrib_pointers(); void vertex_attrib_pointers();

View File

@ -5,6 +5,7 @@
#include "../camera.hpp" #include "../camera.hpp"
#include "../input/focus.hpp" #include "../input/focus.hpp"
#include "../../util/math.hpp" #include "../../util/math.hpp"
#include "../../util/streams.hpp"
#include <iostream> #include <iostream>
@ -328,3 +329,33 @@ Mesh Mesh::to_lines() const
return m; return m;
} }
std::ostream& Sim::Graphics::operator<<(std::ostream& os, const Mesh& m)
{
os << "Mesh(\n";
os << " Vertices(\n";
for(int i = 0; i < m.vertices.size(); i++)
{
os << " " << m.vertices[i] << "\n";
}
os << " )\n";
for(int i = 0; i < m.indices.size(); i += 3)
{
os << " " << m.indices[i] << " " << m.indices[i + 1] << " " << m.indices[i + 2] << "\n";
}
os << " Transforms(\n";
for(int i = 0; i < m.transforms.size(); i++)
{
os << " " << m.transforms[i] << "\n";
}
os << " )\n";
os << ")\n";
return os;
}

View File

@ -45,6 +45,8 @@ struct Mesh
ss << header << item; ss << header << item;
load_text(ss.str().c_str(), size); load_text(ss.str().c_str(), size);
} }
friend std::ostream& operator<<(std::ostream& os, const Mesh& m);
}; };
}; };

View File

@ -94,7 +94,7 @@ void remesh_static()
gm_scene.set(mesh, GL_STATIC_DRAW, false); gm_scene.set(mesh, GL_STATIC_DRAW, false);
g_scene_transforms = std::move(mesh.transforms); g_scene_transforms = std::move(mesh.transforms);
std::cout << "Remeshed static\n"; std::cout << "Total triangles: " << mesh.indices.size() / 3 << "\n";
} }
void render_shadow_map() void render_shadow_map()
@ -178,6 +178,8 @@ void Window::create()
g_scene.add(model.load("hw")); g_scene.add(model.load("hw"));
g_scene.bake_transforms(); g_scene.bake_transforms();
std::cout << "Static scene triangles: " << g_scene.indices.size() / 3 << "\n";
Camera::init(model); Camera::init(model);
// send all the light data // send all the light data

View File

@ -5,6 +5,39 @@
#include <ostream> #include <ostream>
#include <glm/matrix.hpp> #include <glm/matrix.hpp>
namespace glm
{
template <int N, typename T, glm::qualifier Q>
std::ostream& operator<<(std::ostream& o, const glm::vec<N, T, Q>& v)
{
o << "{";
for(int i = 0; i < N - 1; i++)
{
o << v[i] << ", ";
}
o << v[N - 1] << "}";
return o;
}
template <int N, int M, typename T, glm::qualifier Q>
std::ostream& operator<<(std::ostream& o, const glm::mat<N, M, T, Q>& m)
{
o << "{";
for(int i = 0; i < N - 1; i++)
{
o << " " << m[i] << ", ";
}
o << " " << m[N - 1] << "}";
return o;
}
};
namespace Sim::Util::Streams namespace Sim::Util::Streams
{ {
@ -23,31 +56,3 @@ std::ostream& show_units(std::ostream& o, double v);
}; };
template <int N, typename T>
std::ostream& operator<<(std::ostream& o, const glm::vec<N, T>& v)
{
o << "{";
for(int i = 0; i < N - 1; i++)
{
o << v[i] << ", ";
}
o << v[N - 1] << "}";
return o;
}
template <int N, int M, typename T>
std::ostream& operator<<(std::ostream& o, const glm::mat<N, M, T>& m)
{
o << "{\n";
for(int i = 0; i < N - 1; i++)
{
o << " " << m[i] << ",\n";
}
o << " " << m[N - 1] << "}";
return o;
}