mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
finish reformatting header files
This commit is contained in:
parent
3ad0b8b6f8
commit
e1b0b79d32
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_COMPONENTS_COLLIDER_H_
|
||||
#define ENGINE_INCLUDE_COMPONENTS_COLLIDER_H_
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace engine {
|
||||
@ -15,11 +17,12 @@ namespace engine {
|
||||
struct ColliderComponent {
|
||||
friend PhysicsSystem;
|
||||
|
||||
bool isStatic = true;
|
||||
bool isTrigger = false; // entity receives an event on collision enter and exit
|
||||
bool is_static = true;
|
||||
bool is_trigger =
|
||||
false; // entity receives an event on collision enter and exit
|
||||
AABB aabb{}; // broad phase
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_COMPONENTS_RENDERABLE_H_
|
||||
#define ENGINE_INCLUDE_COMPONENTS_RENDERABLE_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace engine {
|
||||
#include "resources/material.hpp"
|
||||
#include "resources/mesh.hpp"
|
||||
|
||||
namespace resources {
|
||||
class Mesh;
|
||||
class Material;
|
||||
}
|
||||
namespace engine {
|
||||
|
||||
struct RenderableComponent {
|
||||
std::shared_ptr<resources::Mesh> mesh;
|
||||
@ -15,4 +14,6 @@ namespace engine {
|
||||
bool shown = true;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
||||
#define ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -13,10 +14,12 @@ namespace engine {
|
||||
glm::quat rotation;
|
||||
glm::vec3 scale;
|
||||
|
||||
glm::mat4 worldMatrix;
|
||||
glm::mat4 world_matrix;
|
||||
|
||||
std::string tag;
|
||||
uint32_t parent;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_COMPONENTS_UI_ELEMENT_H_
|
||||
#define ENGINE_INCLUDE_COMPONENTS_UI_ELEMENT_H_
|
||||
|
||||
namespace engine {
|
||||
|
||||
@ -6,4 +7,6 @@ namespace engine {
|
||||
int n;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_INPUTS_KEYBOARD_H_
|
||||
#define ENGINE_INCLUDE_INPUTS_KEYBOARD_H_
|
||||
|
||||
// Keyboard scancodes, taken from SDL_scancode.h
|
||||
|
||||
namespace engine::inputs {
|
||||
namespace engine {
|
||||
namespace inputs {
|
||||
|
||||
enum class Key : int {
|
||||
K_UNKNOWN = 0,
|
||||
@ -371,4 +373,7 @@ enum class Key : int {
|
||||
for array bounds */
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace inputs
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_INPUTS_MOUSE_H_
|
||||
#define ENGINE_INCLUDE_INPUTS_MOUSE_H_
|
||||
|
||||
namespace engine::inputs {
|
||||
namespace engine {
|
||||
namespace inputs {
|
||||
|
||||
enum class MouseButton : int {
|
||||
M_LEFT,
|
||||
@ -12,11 +14,9 @@ enum class MouseButton : int {
|
||||
M_SIZE = 7
|
||||
};
|
||||
|
||||
enum class MouseAxis : int {
|
||||
X,
|
||||
Y,
|
||||
X_SCR,
|
||||
Y_SCR
|
||||
};
|
||||
enum class MouseAxis : int { X, Y, X_SCR, Y_SCR };
|
||||
|
||||
}
|
||||
} // namespace inputs
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -4,11 +4,11 @@
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
// To be executed in the target application, NOT engine.dll
|
||||
|
@ -1,28 +1,31 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_MATERIAL_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_MATERIAL_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace engine::resources {
|
||||
#include "resources/shader.hpp"
|
||||
#include "resources/texture.hpp"
|
||||
|
||||
class Shader;
|
||||
class Texture;
|
||||
namespace engine {
|
||||
namespace resources {
|
||||
|
||||
// copyable
|
||||
class Material {
|
||||
|
||||
public:
|
||||
Material(std::shared_ptr<Shader> shader);
|
||||
~Material() = default;
|
||||
Material(const Material&);
|
||||
Material& operator=(const Material&) = delete;
|
||||
|
||||
auto getShader() { return m_shader.get(); }
|
||||
auto GetShader() { return shader_.get(); }
|
||||
|
||||
std::shared_ptr<Texture> m_texture;
|
||||
std::shared_ptr<Texture> texture_;
|
||||
|
||||
private:
|
||||
const std::shared_ptr<Shader> m_shader;
|
||||
|
||||
const std::shared_ptr<Shader> shader_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace resources
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,51 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "gfx.hpp"
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace engine {
|
||||
#include "gfx.hpp"
|
||||
#include "gfx_device.hpp"
|
||||
|
||||
class GFXDevice;
|
||||
namespace engine {
|
||||
|
||||
struct Vertex {
|
||||
glm::vec3 pos;
|
||||
glm::vec3 norm;
|
||||
glm::vec2 uv;
|
||||
};
|
||||
}
|
||||
|
||||
namespace engine::resources {
|
||||
} // namespace engine
|
||||
|
||||
namespace engine {
|
||||
namespace resources {
|
||||
|
||||
class Mesh {
|
||||
|
||||
public:
|
||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices);
|
||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||
: m_gfx(gfx)
|
||||
{
|
||||
initMesh(vertices, indices);
|
||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices,
|
||||
const std::vector<uint32_t>& indices)
|
||||
: gfx_(gfx) {
|
||||
InitMesh(vertices, indices);
|
||||
}
|
||||
~Mesh();
|
||||
Mesh(const Mesh&) = delete;
|
||||
Mesh& operator=(const Mesh&) = delete;
|
||||
|
||||
const gfx::Buffer* getVB();
|
||||
const gfx::Buffer* getIB();
|
||||
uint32_t getCount();
|
||||
const gfx::Buffer* GetVB();
|
||||
const gfx::Buffer* GetIB();
|
||||
uint32_t GetCount();
|
||||
|
||||
private:
|
||||
GFXDevice* const m_gfx;
|
||||
GFXDevice* const gfx_;
|
||||
|
||||
const gfx::Buffer* m_vb;
|
||||
const gfx::Buffer* m_ib;
|
||||
uint32_t m_count;
|
||||
|
||||
void initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
|
||||
const gfx::Buffer* vb_;
|
||||
const gfx::Buffer* ib_;
|
||||
uint32_t count_;
|
||||
|
||||
void InitMesh(const std::vector<Vertex>& vertices,
|
||||
const std::vector<uint32_t>& indices);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace resources
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,37 +1,38 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_SHADER_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_SHADER_H_
|
||||
|
||||
#include "application.hpp"
|
||||
#include "gfx.hpp"
|
||||
#include "gfx_device.hpp"
|
||||
|
||||
namespace engine {
|
||||
class GFXDevice;
|
||||
struct RenderData;
|
||||
}
|
||||
|
||||
namespace engine::resources {
|
||||
namespace resources {
|
||||
|
||||
class Shader {
|
||||
|
||||
public:
|
||||
|
||||
// defines what vertex inputs are defined, position is always vec3
|
||||
struct VertexParams {
|
||||
bool hasNormal; // vec3
|
||||
bool hasTangent; // vec3
|
||||
bool hasColor; // vec3
|
||||
bool hasUV0; // vec2
|
||||
bool has_normal; // vec3
|
||||
bool has_tangent; // vec3
|
||||
bool has_color; // vec3
|
||||
bool has_uv0; // vec2
|
||||
};
|
||||
|
||||
Shader(RenderData* renderData, const char* vertPath, const char* fragPath, const VertexParams& vertexParams, bool alphaBlending, bool cullBackFace);
|
||||
Shader(RenderData* render_data, const char* vert_path, const char* frag_path,
|
||||
const VertexParams& vertex_params, bool alpha_blending,
|
||||
bool cull_backface);
|
||||
~Shader();
|
||||
Shader(const Shader&) = delete;
|
||||
Shader& operator=(const Shader&) = delete;
|
||||
|
||||
const gfx::Pipeline* getPipeline();
|
||||
const gfx::Pipeline* GetPipeline();
|
||||
|
||||
private:
|
||||
GFXDevice* const m_gfx;
|
||||
const gfx::Pipeline* m_pipeline;
|
||||
|
||||
GFXDevice* const gfx_;
|
||||
const gfx::Pipeline* pipeline_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace resources
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,37 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "gfx_device.hpp"
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_TEXTURE_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_TEXTURE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace engine {
|
||||
struct RenderData;
|
||||
}
|
||||
#include "application.hpp"
|
||||
#include "gfx_device.hpp"
|
||||
|
||||
namespace engine::resources {
|
||||
namespace engine {
|
||||
namespace resources {
|
||||
|
||||
class Texture {
|
||||
|
||||
public:
|
||||
enum class Filtering {
|
||||
OFF,
|
||||
BILINEAR,
|
||||
TRILINEAR,
|
||||
ANISOTROPIC,
|
||||
kOff,
|
||||
kBilinear,
|
||||
kTrilinear,
|
||||
kAnisotropic,
|
||||
};
|
||||
|
||||
Texture(RenderData* renderData, const std::string& path, Filtering filtering);
|
||||
Texture(RenderData* render_data, const std::string& path,
|
||||
Filtering filtering);
|
||||
~Texture();
|
||||
Texture(const Texture&) = delete;
|
||||
Texture& operator=(const Texture&) = delete;
|
||||
|
||||
const gfx::Image* getImage() { return m_image; }
|
||||
const gfx::DescriptorSet* getDescriptorSet() { return m_descriptorSet; }
|
||||
const gfx::Image* GetImage() { return image_; }
|
||||
const gfx::DescriptorSet* GetDescriptorSet() { return descriptor_set_; }
|
||||
|
||||
private:
|
||||
GFXDevice* m_gfxDevice;
|
||||
const gfx::Image* m_image;
|
||||
const gfx::DescriptorSet* m_descriptorSet;
|
||||
GFXDevice* gfx_;
|
||||
const gfx::Image* image_;
|
||||
const gfx::DescriptorSet* descriptor_set_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace resources
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_
|
||||
#define ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "components/collider.hpp"
|
||||
#include "ecs_system.hpp"
|
||||
@ -11,7 +11,6 @@
|
||||
namespace engine {
|
||||
|
||||
class PhysicsSystem : public System {
|
||||
|
||||
public:
|
||||
PhysicsSystem(Scene* scene);
|
||||
|
||||
@ -20,41 +19,43 @@ namespace engine {
|
||||
void OnComponentInsert(uint32_t entity) override;
|
||||
|
||||
struct CollisionEvent {
|
||||
bool isCollisionEnter; // false == collision exit
|
||||
uint32_t collidedEntity; // the entity that this entity collided with
|
||||
glm::vec3 normal; // the normal of the surface this entity collided with; ignored on collision exit
|
||||
bool is_collision_enter; // false == collision exit
|
||||
uint32_t collided_entity; // the entity that this entity collided with
|
||||
glm::vec3 normal; // the normal of the surface this entity collided with;
|
||||
// ignored on collision exit
|
||||
glm::vec3 point; // where the collision was detected
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// dynamic arrays to avoid realloc on every frame
|
||||
|
||||
// entity, aabb, isTrigger
|
||||
std::vector<std::tuple<uint32_t, AABB, bool>> m_staticAABBs{};
|
||||
std::vector<std::tuple<uint32_t, AABB, bool>> m_dynamicAABBs{};
|
||||
// entity, aabb, is_trigger
|
||||
std::vector<std::tuple<uint32_t, AABB, bool>> static_aabbs_{};
|
||||
std::vector<std::tuple<uint32_t, AABB, bool>> dynamic_aabbs_{};
|
||||
|
||||
struct PossibleCollision {
|
||||
PossibleCollision(uint32_t static_entity, AABB static_aabb,
|
||||
bool static_trigger, uint32_t dynamic_entity,
|
||||
AABB dynamic_aabb, bool dynamic_trigger)
|
||||
: static_entity(static_entity),
|
||||
static_aabb(static_aabb),
|
||||
static_trigger(static_trigger),
|
||||
dynamic_entity(dynamic_entity),
|
||||
dynamic_aabb(dynamic_aabb),
|
||||
dynamic_trigger(dynamic_trigger) {}
|
||||
|
||||
PossibleCollision(uint32_t staticEntity, AABB staticAABB, bool staticTrigger, uint32_t dynamicEntity, AABB dynamicAABB, bool dynamicTrigger) :
|
||||
staticEntity(staticEntity),
|
||||
staticAABB(staticAABB),
|
||||
staticTrigger(staticTrigger),
|
||||
dynamicEntity(dynamicEntity),
|
||||
dynamicAABB(dynamicAABB),
|
||||
dynamicTrigger(dynamicTrigger) {}
|
||||
|
||||
uint32_t staticEntity;
|
||||
AABB staticAABB;
|
||||
bool staticTrigger;
|
||||
uint32_t dynamicEntity;
|
||||
AABB dynamicAABB;
|
||||
bool dynamicTrigger;
|
||||
uint32_t static_entity;
|
||||
AABB static_aabb;
|
||||
bool static_trigger;
|
||||
uint32_t dynamic_entity;
|
||||
AABB dynamic_aabb;
|
||||
bool dynamic_trigger;
|
||||
};
|
||||
std::vector<PossibleCollision> m_possibleCollisions{};
|
||||
std::vector<std::pair<uint32_t, CollisionEvent>> m_collisionInfos{}; // target entity, event info
|
||||
|
||||
std::vector<PossibleCollision> possible_collisions_{};
|
||||
std::vector<std::pair<uint32_t, CollisionEvent>>
|
||||
collision_infos_{}; // target entity, event info
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,43 +1,39 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_SYSTEMS_RENDER_H_
|
||||
#define ENGINE_INCLUDE_SYSTEMS_RENDER_H_
|
||||
|
||||
#include "ecs_system.hpp"
|
||||
#include "scene.hpp"
|
||||
#include "log.hpp"
|
||||
|
||||
#include "components/transform.hpp"
|
||||
#include "components/renderable.hpp"
|
||||
|
||||
#include "components/transform.hpp"
|
||||
#include "ecs_system.hpp"
|
||||
#include "gfx.hpp"
|
||||
#include "gfx_device.hpp"
|
||||
#include "log.hpp"
|
||||
#include "scene.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
class RenderSystem : public System {
|
||||
|
||||
public:
|
||||
RenderSystem(Scene* scene);
|
||||
~RenderSystem();
|
||||
|
||||
void OnUpdate(float ts) override;
|
||||
|
||||
void setCameraEntity(uint32_t entity);
|
||||
void SetCameraEntity(uint32_t entity);
|
||||
|
||||
private:
|
||||
GFXDevice* const m_gfx;
|
||||
GFXDevice* const gfx_;
|
||||
|
||||
struct {
|
||||
// only uses transform component, which is required for all entities anyway
|
||||
uint32_t camEntity = 0;
|
||||
float verticalFovDegrees = 70.0f;
|
||||
float clipNear = 0.5f;
|
||||
float clipFar = 10000.0f;
|
||||
} m_camera;
|
||||
|
||||
float m_viewportAspectRatio = 1.0f;
|
||||
|
||||
float m_value = 0.0f;
|
||||
uint32_t cam_entity = 0;
|
||||
float vertical_fov_degrees = 70.0f;
|
||||
float clip_near = 0.5f;
|
||||
float clip_far = 10000.0f;
|
||||
} camera_;
|
||||
|
||||
float viewport_aspect_ratio_ = 1.0f;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_SYSTEMS_RENDER2D_H_
|
||||
#define ENGINE_INCLUDE_SYSTEMS_RENDER2D_H_
|
||||
|
||||
#include "ecs_system.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
class Render2DSystem : public System {
|
||||
|
||||
public:
|
||||
Render2DSystem(Scene* scene);
|
||||
~Render2DSystem();
|
||||
@ -13,8 +13,8 @@ namespace engine {
|
||||
void OnUpdate(float ts) override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_
|
||||
#define ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_
|
||||
|
||||
#include "ecs_system.hpp"
|
||||
|
||||
@ -11,9 +12,10 @@ namespace engine {
|
||||
|
||||
void OnUpdate(float ts) override;
|
||||
|
||||
uint32_t getChildEntity(uint32_t parent, const std::string& tag);
|
||||
uint32_t GetChildEntity(uint32_t parent, const std::string& tag);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_SYSTEMS_UI_H_
|
||||
#define ENGINE_INCLUDE_SYSTEMS_UI_H_
|
||||
|
||||
#include "ecs_system.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
class UISystem : public System {
|
||||
|
||||
public:
|
||||
UISystem(Scene* scene);
|
||||
|
||||
void OnUpdate(float ts) override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,16 +1,22 @@
|
||||
#pragma once
|
||||
#ifndef ENGINE_INCLUDE_UTIL_FILES_H_
|
||||
#define ENGINE_INCLUDE_UTIL_FILES_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace engine::util {
|
||||
namespace engine {
|
||||
namespace util {
|
||||
|
||||
std::unique_ptr<std::vector<char>> readTextFile(const std::string& path);
|
||||
std::unique_ptr<std::vector<uint8_t>> readBinaryFile(const std::string& path);
|
||||
std::unique_ptr<std::vector<char>> ReadTextFile(const std::string& path);
|
||||
std::unique_ptr<std::vector<uint8_t>> ReadBinaryFile(const std::string& path);
|
||||
|
||||
// Read an image file into a vector byte buffer. PNG and JPG support at a minimum.
|
||||
// Output format is R8G8B8A8_UINT
|
||||
std::unique_ptr<std::vector<uint8_t>> readImageFile(const std::string& path, int *width, int *height);
|
||||
// Read an image file into a vector byte buffer. PNG and JPG support at a
|
||||
// minimum. Output format is R8G8B8A8_UINT
|
||||
std::unique_ptr<std::vector<uint8_t>> ReadImageFile(const std::string& path,
|
||||
int* width, int* height);
|
||||
|
||||
}
|
||||
} // namespace util
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,13 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "scene.hpp"
|
||||
|
||||
#include "resources/shader.hpp"
|
||||
#ifndef ENGINE_INCLUDE_UTIL_MODEL_LOADER_H_
|
||||
#define ENGINE_INCLUDE_UTIL_MODEL_LOADER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace engine::util {
|
||||
#include "scene.hpp"
|
||||
|
||||
uint32_t loadMeshFromFile(Scene* parent, const std::string& path);
|
||||
namespace engine {
|
||||
namespace util {
|
||||
|
||||
}
|
||||
uint32_t LoadMeshFromFile(Scene* parent, const std::string& path);
|
||||
|
||||
} // namespace util
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -116,8 +116,8 @@ namespace engine {
|
||||
// default resources
|
||||
{
|
||||
resources::Shader::VertexParams vertParams{};
|
||||
vertParams.hasNormal = true;
|
||||
vertParams.hasUV0 = true;
|
||||
vertParams.has_normal = true;
|
||||
vertParams.has_uv0 = true;
|
||||
auto texturedShader = std::make_unique<resources::Shader>(
|
||||
&render_data_,
|
||||
GetResourcePath("engine/shaders/standard.vert").c_str(),
|
||||
@ -130,8 +130,8 @@ namespace engine {
|
||||
}
|
||||
{
|
||||
resources::Shader::VertexParams vertParams{};
|
||||
vertParams.hasNormal = true;
|
||||
vertParams.hasUV0 = true;
|
||||
vertParams.has_normal = true;
|
||||
vertParams.has_uv0 = true;
|
||||
auto skyboxShader = std::make_unique<resources::Shader>(
|
||||
&render_data_,
|
||||
GetResourcePath("engine/shaders/skybox.vert").c_str(),
|
||||
@ -146,7 +146,7 @@ namespace engine {
|
||||
auto whiteTexture = std::make_unique<resources::Texture>(
|
||||
&render_data_,
|
||||
GetResourcePath("engine/textures/white.png"),
|
||||
resources::Texture::Filtering::OFF
|
||||
resources::Texture::Filtering::kOff
|
||||
);
|
||||
GetResourceManager<resources::Texture>()->AddPersistent("builtin.white", std::move(whiteTexture));
|
||||
}
|
||||
|
@ -832,8 +832,8 @@ namespace engine {
|
||||
|
||||
gfx::Pipeline* pipeline = new gfx::Pipeline;
|
||||
|
||||
auto vertShaderCode = util::readTextFile(info.vert_shader_path);
|
||||
auto fragShaderCode = util::readTextFile(info.frag_shader_path);
|
||||
auto vertShaderCode = util::ReadTextFile(info.vert_shader_path);
|
||||
auto fragShaderCode = util::ReadTextFile(info.frag_shader_path);
|
||||
|
||||
VkShaderModule vertShaderModule = compileShader(pimpl->device.device, shaderc_vertex_shader, vertShaderCode->data(), info.vert_shader_path);
|
||||
VkShaderModule fragShaderModule = compileShader(pimpl->device.device, shaderc_fragment_shader, fragShaderCode->data(), info.frag_shader_path);
|
||||
|
@ -5,13 +5,13 @@
|
||||
namespace engine::resources {
|
||||
|
||||
Material::Material(std::shared_ptr<Shader> shader)
|
||||
: m_shader(shader)
|
||||
: shader_(shader)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Material::Material(const Material& original)
|
||||
: m_texture(original.m_texture), m_shader(original.m_shader)
|
||||
: texture_(original.texture_), shader_(original.shader_)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -6,41 +6,41 @@
|
||||
namespace engine::resources {
|
||||
|
||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices)
|
||||
: m_gfx(gfx)
|
||||
: gfx_(gfx)
|
||||
{
|
||||
std::vector<uint32_t> indices(vertices.size());
|
||||
for (uint32_t i = 0; i < indices.size(); i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
initMesh(vertices, indices);
|
||||
InitMesh(vertices, indices);
|
||||
}
|
||||
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
m_gfx->DestroyBuffer(m_ib);
|
||||
m_gfx->DestroyBuffer(m_vb);
|
||||
gfx_->DestroyBuffer(ib_);
|
||||
gfx_->DestroyBuffer(vb_);
|
||||
}
|
||||
|
||||
const gfx::Buffer* Mesh::getVB()
|
||||
const gfx::Buffer* Mesh::GetVB()
|
||||
{
|
||||
return m_vb;
|
||||
return vb_;
|
||||
}
|
||||
|
||||
const gfx::Buffer* Mesh::getIB()
|
||||
const gfx::Buffer* Mesh::GetIB()
|
||||
{
|
||||
return m_ib;
|
||||
return ib_;
|
||||
}
|
||||
|
||||
uint32_t Mesh::getCount()
|
||||
uint32_t Mesh::GetCount()
|
||||
{
|
||||
return m_count;
|
||||
return count_;
|
||||
}
|
||||
|
||||
void Mesh::initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||
void Mesh::InitMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||
{
|
||||
m_vb = m_gfx->CreateBuffer(gfx::BufferType::kVertex, vertices.size() * sizeof(Vertex), vertices.data());
|
||||
m_ib = m_gfx->CreateBuffer(gfx::BufferType::kIndex, indices.size() * sizeof(uint32_t), indices.data());
|
||||
m_count = (uint32_t)indices.size();
|
||||
vb_ = gfx_->CreateBuffer(gfx::BufferType::kVertex, vertices.size() * sizeof(Vertex), vertices.data());
|
||||
ib_ = gfx_->CreateBuffer(gfx::BufferType::kIndex, indices.size() * sizeof(uint32_t), indices.data());
|
||||
count_ = (uint32_t)indices.size();
|
||||
LOG_INFO("Loaded mesh, vertices: {}, indices: {}", vertices.size(), indices.size());
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ namespace engine::resources {
|
||||
|
||||
|
||||
Shader::Shader(RenderData* renderData, const char* vertPath, const char* fragPath, const VertexParams& vertexParams, bool alphaBlending, bool cullBackFace)
|
||||
: m_gfx(renderData->gfxdev.get())
|
||||
: gfx_(renderData->gfxdev.get())
|
||||
{
|
||||
|
||||
uint32_t index = 0;
|
||||
@ -20,19 +20,19 @@ namespace engine::resources {
|
||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat3, stride);
|
||||
stride += 3 * sizeof(float);
|
||||
|
||||
if (vertexParams.hasNormal) {
|
||||
if (vertexParams.has_normal) {
|
||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat3, stride);
|
||||
stride += 3 * sizeof(float);
|
||||
}
|
||||
if (vertexParams.hasTangent) {
|
||||
if (vertexParams.has_tangent) {
|
||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat4, stride);
|
||||
stride += 4 * sizeof(float);
|
||||
}
|
||||
if (vertexParams.hasColor) {
|
||||
if (vertexParams.has_color) {
|
||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat4, stride);
|
||||
stride += 4 * sizeof(float);
|
||||
}
|
||||
if (vertexParams.hasUV0) {
|
||||
if (vertexParams.has_uv0) {
|
||||
vertFormat.attribute_descriptions.emplace_back(index++, gfx::VertexAttribFormat::kFloat2, stride);
|
||||
stride += 2 * sizeof(float);
|
||||
}
|
||||
@ -48,7 +48,7 @@ namespace engine::resources {
|
||||
info.descriptor_set_layouts.push_back(renderData->frame_set_layout);
|
||||
info.descriptor_set_layouts.push_back(renderData->material_set_layout);
|
||||
|
||||
m_pipeline = m_gfx->CreatePipeline(info);
|
||||
pipeline_ = gfx_->CreatePipeline(info);
|
||||
|
||||
LOG_INFO("Loaded shader: {}, vertex attribs: {}", vertPath, vertFormat.attribute_descriptions.size());
|
||||
|
||||
@ -56,12 +56,12 @@ namespace engine::resources {
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
m_gfx->DestroyPipeline(m_pipeline);
|
||||
gfx_->DestroyPipeline(pipeline_);
|
||||
}
|
||||
|
||||
const gfx::Pipeline* Shader::getPipeline()
|
||||
const gfx::Pipeline* Shader::GetPipeline()
|
||||
{
|
||||
return m_pipeline;
|
||||
return pipeline_;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,45 +9,45 @@
|
||||
namespace engine::resources {
|
||||
|
||||
Texture::Texture(RenderData* renderData, const std::string& path, Filtering filtering)
|
||||
: m_gfxDevice(renderData->gfxdev.get())
|
||||
: gfx_(renderData->gfxdev.get())
|
||||
{
|
||||
|
||||
int width, height;
|
||||
std::unique_ptr<std::vector<uint8_t>> texbuf = util::readImageFile(path, &width, &height);
|
||||
std::unique_ptr<std::vector<uint8_t>> texbuf = util::ReadImageFile(path, &width, &height);
|
||||
|
||||
gfx::SamplerInfo samplerInfo{};
|
||||
|
||||
samplerInfo.magnify = gfx::Filter::kLinear;
|
||||
|
||||
switch (filtering) {
|
||||
case Filtering::OFF:
|
||||
case Filtering::kOff:
|
||||
samplerInfo.minify = gfx::Filter::kNearest;
|
||||
samplerInfo.mipmap = gfx::Filter::kNearest;
|
||||
samplerInfo.anisotropic_filtering = false;
|
||||
break;
|
||||
case Filtering::BILINEAR:
|
||||
case Filtering::kBilinear:
|
||||
samplerInfo.minify = gfx::Filter::kLinear;
|
||||
samplerInfo.mipmap = gfx::Filter::kNearest;
|
||||
samplerInfo.anisotropic_filtering = false;
|
||||
break;
|
||||
case Filtering::TRILINEAR:
|
||||
case Filtering::kTrilinear:
|
||||
samplerInfo.minify = gfx::Filter::kLinear;
|
||||
samplerInfo.mipmap = gfx::Filter::kLinear;
|
||||
samplerInfo.anisotropic_filtering = false;
|
||||
break;
|
||||
case Filtering::ANISOTROPIC:
|
||||
case Filtering::kAnisotropic:
|
||||
samplerInfo.minify = gfx::Filter::kLinear;
|
||||
samplerInfo.mipmap = gfx::Filter::kLinear;
|
||||
samplerInfo.anisotropic_filtering = true;
|
||||
}
|
||||
|
||||
if (renderData->samplers.contains(samplerInfo) == false) {
|
||||
renderData->samplers.insert(std::make_pair(samplerInfo, m_gfxDevice->CreateSampler(samplerInfo)));
|
||||
renderData->samplers.insert(std::make_pair(samplerInfo, gfx_->CreateSampler(samplerInfo)));
|
||||
}
|
||||
|
||||
m_image = m_gfxDevice->CreateImage(width, height, texbuf->data());
|
||||
m_descriptorSet = m_gfxDevice->AllocateDescriptorSet(renderData->material_set_layout);
|
||||
m_gfxDevice->UpdateDescriptorCombinedImageSampler(m_descriptorSet, 0, m_image, renderData->samplers.at(samplerInfo));
|
||||
image_ = gfx_->CreateImage(width, height, texbuf->data());
|
||||
descriptor_set_ = gfx_->AllocateDescriptorSet(renderData->material_set_layout);
|
||||
gfx_->UpdateDescriptorCombinedImageSampler(descriptor_set_, 0, image_, renderData->samplers.at(samplerInfo));
|
||||
|
||||
LOG_INFO("Loaded texture: {}, width: {} height: {}", path, width, height);
|
||||
|
||||
@ -55,7 +55,7 @@ Texture::Texture(RenderData* renderData, const std::string& path, Filtering filt
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
m_gfxDevice->DestroyImage(m_image);
|
||||
gfx_->DestroyImage(image_);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace engine {
|
||||
|
||||
uint32_t Scene::getEntity(const std::string& tag, uint32_t parent)
|
||||
{
|
||||
return GetSystem<TransformSystem>()->getChildEntity(parent, tag);
|
||||
return GetSystem<TransformSystem>()->GetChildEntity(parent, tag);
|
||||
}
|
||||
|
||||
size_t Scene::GetComponentSignaturePosition(size_t hash)
|
||||
|
@ -75,10 +75,10 @@ namespace engine {
|
||||
{
|
||||
(void)entity;
|
||||
const size_t size = entities_.size();
|
||||
m_staticAABBs.reserve(size);
|
||||
m_dynamicAABBs.reserve(size);
|
||||
m_possibleCollisions.reserve(size);
|
||||
m_collisionInfos.reserve(size);
|
||||
static_aabbs_.reserve(size);
|
||||
dynamic_aabbs_.reserve(size);
|
||||
possible_collisions_.reserve(size);
|
||||
collision_infos_.reserve(size);
|
||||
LOG_TRACE("added entity {} to collider system", entity);
|
||||
}
|
||||
|
||||
@ -86,16 +86,16 @@ namespace engine {
|
||||
{
|
||||
(void)ts;
|
||||
|
||||
m_staticAABBs.clear();
|
||||
m_dynamicAABBs.clear();
|
||||
m_possibleCollisions.clear();
|
||||
m_collisionInfos.clear();
|
||||
static_aabbs_.clear();
|
||||
dynamic_aabbs_.clear();
|
||||
possible_collisions_.clear();
|
||||
collision_infos_.clear();
|
||||
|
||||
for (uint32_t entity : entities_) {
|
||||
const auto t = scene_->GetComponent<TransformComponent>(entity);
|
||||
const auto c = scene_->GetComponent<ColliderComponent>(entity);
|
||||
|
||||
const glm::vec3 globalPosition = t->worldMatrix[3];
|
||||
const glm::vec3 globalPosition = t->world_matrix[3];
|
||||
const AABB localBoundingBox = c->aabb;
|
||||
AABB globalBoundingBox{};
|
||||
globalBoundingBox.pos1 = globalPosition + localBoundingBox.pos1;
|
||||
@ -106,10 +106,10 @@ namespace engine {
|
||||
if (a.pos1.y > a.pos2.y) std::swap(a.pos1.y, a.pos2.y);
|
||||
if (a.pos1.z > a.pos2.z) std::swap(a.pos1.z, a.pos2.z);
|
||||
|
||||
if (c->isStatic) {
|
||||
m_staticAABBs.emplace_back(std::make_tuple(entity, globalBoundingBox, c->isTrigger));
|
||||
if (c->is_static) {
|
||||
static_aabbs_.emplace_back(std::make_tuple(entity, globalBoundingBox, c->is_trigger));
|
||||
} else {
|
||||
m_dynamicAABBs.emplace_back(std::make_tuple(entity, globalBoundingBox, c->isTrigger));
|
||||
dynamic_aabbs_.emplace_back(std::make_tuple(entity, globalBoundingBox, c->is_trigger));
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,11 +117,11 @@ namespace engine {
|
||||
|
||||
// Check every static collider against every dynamic collider, and every dynamic collider against every other one
|
||||
// This technique is inefficient for many entities.
|
||||
for (const auto& [staticEntity, staticAABB, staticTrigger] : m_staticAABBs) {
|
||||
for (const auto& [dynamicEntity, dynamicAABB, dynamicTrigger] : m_dynamicAABBs) {
|
||||
for (const auto& [staticEntity, staticAABB, staticTrigger] : static_aabbs_) {
|
||||
for (const auto& [dynamicEntity, dynamicAABB, dynamicTrigger] : dynamic_aabbs_) {
|
||||
if (checkCollisionFast(staticAABB, dynamicAABB)) {
|
||||
if (staticTrigger || dynamicTrigger) { // only check collisions involved with triggers
|
||||
m_possibleCollisions.emplace_back(
|
||||
possible_collisions_.emplace_back(
|
||||
staticEntity, staticAABB, staticTrigger,
|
||||
dynamicEntity, dynamicAABB, dynamicTrigger
|
||||
);
|
||||
@ -131,32 +131,32 @@ namespace engine {
|
||||
}
|
||||
|
||||
// get collision details and submit events
|
||||
for (const auto& possibleCollision : m_possibleCollisions) {
|
||||
if (possibleCollision.staticTrigger) {
|
||||
for (const auto& possibleCollision : possible_collisions_) {
|
||||
if (possibleCollision.static_trigger) {
|
||||
CollisionEvent info{};
|
||||
info.isCollisionEnter = true;
|
||||
info.collidedEntity = possibleCollision.dynamicEntity;
|
||||
info.normal = getAABBNormal(possibleCollision.staticAABB, possibleCollision.dynamicAABB);
|
||||
info.is_collision_enter = true;
|
||||
info.collided_entity = possibleCollision.dynamic_entity;
|
||||
info.normal = getAABBNormal(possibleCollision.static_aabb, possibleCollision.dynamic_aabb);
|
||||
|
||||
AABB object = possibleCollision.dynamicAABB;
|
||||
AABB object = possibleCollision.dynamic_aabb;
|
||||
info.point = object.pos2;
|
||||
|
||||
m_collisionInfos.emplace_back(possibleCollision.staticEntity, info);
|
||||
collision_infos_.emplace_back(possibleCollision.static_entity, info);
|
||||
}
|
||||
if (possibleCollision.dynamicTrigger) {
|
||||
if (possibleCollision.dynamic_trigger) {
|
||||
CollisionEvent info{};
|
||||
info.isCollisionEnter = true;
|
||||
info.collidedEntity = possibleCollision.staticEntity;
|
||||
info.normal = getAABBNormal(possibleCollision.dynamicAABB, possibleCollision.staticAABB);
|
||||
info.is_collision_enter = true;
|
||||
info.collided_entity = possibleCollision.static_entity;
|
||||
info.normal = getAABBNormal(possibleCollision.dynamic_aabb, possibleCollision.static_aabb);
|
||||
|
||||
AABB object = possibleCollision.staticAABB;
|
||||
AABB object = possibleCollision.static_aabb;
|
||||
info.point = object.pos2;
|
||||
|
||||
m_collisionInfos.emplace_back(possibleCollision.dynamicEntity, info);
|
||||
collision_infos_.emplace_back(possibleCollision.dynamic_entity, info);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& [entity, info] : m_collisionInfos) {
|
||||
for (const auto& [entity, info] : collision_infos_) {
|
||||
scene_->event_system()->QueueEvent<CollisionEvent>(EventSubscriberKind::kEntity, entity, info);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace engine {
|
||||
|
||||
RenderSystem::RenderSystem(Scene* scene)
|
||||
: System(scene, { typeid(TransformComponent).hash_code(), typeid(RenderableComponent).hash_code() }),
|
||||
m_gfx(scene_->app()->gfxdev())
|
||||
gfx_(scene_->app()->gfxdev())
|
||||
{
|
||||
}
|
||||
|
||||
@ -31,30 +31,30 @@ namespace engine {
|
||||
RenderData& renderData = scene_->app()->render_data_;
|
||||
|
||||
/* camera stuff */
|
||||
const auto cameraTransform = scene_->GetComponent<TransformComponent>(m_camera.camEntity);
|
||||
const auto cameraTransform = scene_->GetComponent<TransformComponent>(camera_.cam_entity);
|
||||
|
||||
// do not render if camera is not set
|
||||
if (cameraTransform == nullptr) return;
|
||||
|
||||
glm::mat4 viewMatrix = glm::inverse(cameraTransform->worldMatrix);
|
||||
glm::mat4 viewMatrix = glm::inverse(cameraTransform->world_matrix);
|
||||
|
||||
if (scene_->app()->window()->GetWindowResized()) {
|
||||
uint32_t w, h;
|
||||
m_gfx->GetViewportSize(&w, &h);
|
||||
m_viewportAspectRatio = (float)w / (float)h;
|
||||
const float verticalFovRadians = glm::radians(m_camera.verticalFovDegrees);
|
||||
const glm::mat4 projMatrix = glm::perspectiveZO(verticalFovRadians, m_viewportAspectRatio, m_camera.clipNear, m_camera.clipFar);
|
||||
gfx_->GetViewportSize(&w, &h);
|
||||
viewport_aspect_ratio_ = (float)w / (float)h;
|
||||
const float verticalFovRadians = glm::radians(camera_.vertical_fov_degrees);
|
||||
const glm::mat4 projMatrix = glm::perspectiveZO(verticalFovRadians, viewport_aspect_ratio_, camera_.clip_near, camera_.clip_far);
|
||||
/* update SET 0 */
|
||||
RenderData::GlobalSetUniformBuffer globalSetUniformBuffer{
|
||||
.proj = projMatrix
|
||||
};
|
||||
m_gfx->WriteUniformBuffer(renderData.global_set_uniform_buffer, 0, sizeof(RenderData::GlobalSetUniformBuffer), &globalSetUniformBuffer);
|
||||
gfx_->WriteUniformBuffer(renderData.global_set_uniform_buffer, 0, sizeof(RenderData::GlobalSetUniformBuffer), &globalSetUniformBuffer);
|
||||
}
|
||||
|
||||
RenderData::FrameSetUniformBuffer frameSetUniformBuffer{
|
||||
.view = viewMatrix
|
||||
};
|
||||
m_gfx->WriteUniformBuffer(renderData.frame_set_uniform_buffer, 0, sizeof(RenderData::FrameSetUniformBuffer), &frameSetUniformBuffer);
|
||||
gfx_->WriteUniformBuffer(renderData.frame_set_uniform_buffer, 0, sizeof(RenderData::FrameSetUniformBuffer), &frameSetUniformBuffer);
|
||||
|
||||
/* render all renderable entities */
|
||||
|
||||
@ -76,52 +76,52 @@ namespace engine {
|
||||
auto r = scene_->GetComponent<RenderableComponent>(entity);
|
||||
assert(r != nullptr);
|
||||
assert(r->material != nullptr);
|
||||
assert(r->material->m_texture != nullptr);
|
||||
assert(r->material->texture_ != nullptr);
|
||||
assert(r->mesh != nullptr);
|
||||
if (r->shown == false) continue;
|
||||
|
||||
auto t = scene_->GetComponent<TransformComponent>(entity);
|
||||
assert(t != nullptr);
|
||||
|
||||
const gfx::Pipeline* pipeline = r->material->getShader()->getPipeline();
|
||||
const gfx::Pipeline* pipeline = r->material->GetShader()->GetPipeline();
|
||||
DrawCallData data{};
|
||||
data.vb = r->mesh->getVB();
|
||||
data.ib = r->mesh->getIB();
|
||||
data.materialSet = r->material->m_texture->getDescriptorSet();
|
||||
data.indexCount = r->mesh->getCount();
|
||||
data.pushConsts.model = t->worldMatrix;
|
||||
data.vb = r->mesh->GetVB();
|
||||
data.ib = r->mesh->GetIB();
|
||||
data.materialSet = r->material->texture_->GetDescriptorSet();
|
||||
data.indexCount = r->mesh->GetCount();
|
||||
data.pushConsts.model = t->world_matrix;
|
||||
|
||||
pipelineDrawCalls[pipeline].push_back(data);
|
||||
|
||||
}
|
||||
|
||||
/* begin rendering */
|
||||
renderData.draw_buffer = m_gfx->BeginRender();
|
||||
renderData.draw_buffer = gfx_->BeginRender();
|
||||
|
||||
/* these descriptor set bindings should persist across pipeline changes */
|
||||
const gfx::Pipeline* firstPipeline = pipelineDrawCalls.begin()->first;
|
||||
m_gfx->CmdBindDescriptorSet(renderData.draw_buffer, firstPipeline, renderData.global_set, 0);
|
||||
m_gfx->CmdBindDescriptorSet(renderData.draw_buffer, firstPipeline, renderData.frame_set, 1);
|
||||
gfx_->CmdBindDescriptorSet(renderData.draw_buffer, firstPipeline, renderData.global_set, 0);
|
||||
gfx_->CmdBindDescriptorSet(renderData.draw_buffer, firstPipeline, renderData.frame_set, 1);
|
||||
|
||||
for (const auto& [pipeline, drawCalls] : pipelineDrawCalls) {
|
||||
m_gfx->CmdBindPipeline(renderData.draw_buffer, pipeline);
|
||||
gfx_->CmdBindPipeline(renderData.draw_buffer, pipeline);
|
||||
for (const auto& drawCall : drawCalls) {
|
||||
m_gfx->CmdBindDescriptorSet(renderData.draw_buffer, pipeline, drawCall.materialSet, 2);
|
||||
m_gfx->CmdPushConstants(renderData.draw_buffer, pipeline, 0, sizeof(PushConstants), &drawCall.pushConsts);
|
||||
m_gfx->CmdBindVertexBuffer(renderData.draw_buffer, 0, drawCall.vb);
|
||||
m_gfx->CmdBindIndexBuffer(renderData.draw_buffer, drawCall.ib);
|
||||
m_gfx->CmdDrawIndexed(renderData.draw_buffer, drawCall.indexCount, 1, 0, 0, 0);
|
||||
gfx_->CmdBindDescriptorSet(renderData.draw_buffer, pipeline, drawCall.materialSet, 2);
|
||||
gfx_->CmdPushConstants(renderData.draw_buffer, pipeline, 0, sizeof(PushConstants), &drawCall.pushConsts);
|
||||
gfx_->CmdBindVertexBuffer(renderData.draw_buffer, 0, drawCall.vb);
|
||||
gfx_->CmdBindIndexBuffer(renderData.draw_buffer, drawCall.ib);
|
||||
gfx_->CmdDrawIndexed(renderData.draw_buffer, drawCall.indexCount, 1, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* draw */
|
||||
m_gfx->FinishRender(renderData.draw_buffer);
|
||||
gfx_->FinishRender(renderData.draw_buffer);
|
||||
|
||||
}
|
||||
|
||||
void RenderSystem::setCameraEntity(uint32_t entity)
|
||||
void RenderSystem::SetCameraEntity(uint32_t entity)
|
||||
{
|
||||
m_camera.camEntity = entity;
|
||||
camera_.cam_entity = entity;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,14 +30,14 @@ namespace engine {
|
||||
transform = glm::scale(transform, t->scale);
|
||||
|
||||
if (t->parent != 0) {
|
||||
transform = scene_->GetComponent<TransformComponent>(t->parent)->worldMatrix * transform;
|
||||
transform = scene_->GetComponent<TransformComponent>(t->parent)->world_matrix * transform;
|
||||
}
|
||||
|
||||
t->worldMatrix = transform;
|
||||
t->world_matrix = transform;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t TransformSystem::getChildEntity(uint32_t parent, const std::string& tag)
|
||||
uint32_t TransformSystem::GetChildEntity(uint32_t parent, const std::string& tag)
|
||||
{
|
||||
for (uint32_t entity : entities_) {
|
||||
auto t = scene_->GetComponent<TransformComponent>(entity);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
namespace engine::util {
|
||||
|
||||
std::unique_ptr<std::vector<char>> readTextFile(const std::string& path)
|
||||
std::unique_ptr<std::vector<char>> ReadTextFile(const std::string& path)
|
||||
{
|
||||
auto buffer = std::make_unique<std::vector<char>>();
|
||||
|
||||
@ -33,7 +33,7 @@ namespace engine::util {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::unique_ptr<std::vector<uint8_t>> readBinaryFile(const std::string& path)
|
||||
std::unique_ptr<std::vector<uint8_t>> ReadBinaryFile(const std::string& path)
|
||||
{
|
||||
std::ifstream file(path, std::ios::ate | std::ios::binary);
|
||||
if (file.is_open() == false) {
|
||||
@ -51,7 +51,7 @@ namespace engine::util {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::unique_ptr<std::vector<uint8_t>> readImageFile(const std::string& path, int *width, int *height)
|
||||
std::unique_ptr<std::vector<uint8_t>> ReadImageFile(const std::string& path, int *width, int *height)
|
||||
{
|
||||
int x, y, n;
|
||||
unsigned char *data = stbi_load(path.c_str(), &x, &y, &n, STBI_rgb_alpha);
|
||||
|
@ -79,9 +79,9 @@ namespace engine::util {
|
||||
childRenderer->mesh = meshes[parentNode->mMeshes[i]];
|
||||
childRenderer->material = std::make_shared<resources::Material>(scene->app()->GetResource<resources::Shader>("builtin.standard"));
|
||||
if (textures.contains(meshTextureIndices[parentNode->mMeshes[i]])) {
|
||||
childRenderer->material->m_texture = textures.at(meshTextureIndices[parentNode->mMeshes[i]]);
|
||||
childRenderer->material->texture_ = textures.at(meshTextureIndices[parentNode->mMeshes[i]]);
|
||||
} else {
|
||||
childRenderer->material->m_texture = scene->app()->GetResource<resources::Texture>("builtin.white");
|
||||
childRenderer->material->texture_ = scene->app()->GetResource<resources::Texture>("builtin.white");
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ namespace engine::util {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t loadMeshFromFile(Scene* parent, const std::string& path)
|
||||
uint32_t LoadMeshFromFile(Scene* parent, const std::string& path)
|
||||
{
|
||||
Assimp::Importer importer;
|
||||
|
||||
@ -183,7 +183,7 @@ namespace engine::util {
|
||||
try {
|
||||
textures[i] = std::make_shared<resources::Texture>(
|
||||
&parent->app()->render_data_, absPath.string(),
|
||||
resources::Texture::Filtering::TRILINEAR);
|
||||
resources::Texture::Filtering::kTrilinear);
|
||||
} catch (const std::runtime_error&) {
|
||||
textures[i] = parent->app()->GetResource<resources::Texture>("builtin.white");
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ void CameraControllerSystem::OnUpdate(float ts)
|
||||
// called once per frame
|
||||
void CameraControllerSystem::OnEvent(engine::PhysicsSystem::CollisionEvent info)
|
||||
{
|
||||
c->justCollided = info.isCollisionEnter;
|
||||
c->justCollided = info.is_collision_enter;
|
||||
c->lastCollisionNormal = info.normal;
|
||||
c->lastCollisionPoint = info.point;
|
||||
}
|
||||
|
@ -70,8 +70,8 @@ void playGame(GameSettings settings)
|
||||
auto camera = myScene->CreateEntity("camera");
|
||||
myScene->GetComponent<engine::TransformComponent>(camera)->position = { 0.0f, 10.0f, 0.0f };
|
||||
auto cameraCollider = myScene->AddComponent<engine::ColliderComponent>(camera);
|
||||
cameraCollider->isStatic = false;
|
||||
cameraCollider->isTrigger = true;
|
||||
cameraCollider->is_static = false;
|
||||
cameraCollider->is_trigger = true;
|
||||
cameraCollider->aabb = { { -0.2f, -1.5f, -0.2f }, { 0.2f, 0.2f, 0.2f} }; // Origin is at eye level
|
||||
myScene->AddComponent<CameraControllerComponent>(camera);
|
||||
myScene->event_system()->SubscribeToEventType<engine::PhysicsSystem::CollisionEvent>(
|
||||
@ -79,19 +79,19 @@ void playGame(GameSettings settings)
|
||||
);
|
||||
|
||||
auto renderSystem = myScene->GetSystem<engine::RenderSystem>();
|
||||
renderSystem->setCameraEntity(camera);
|
||||
renderSystem->SetCameraEntity(camera);
|
||||
}
|
||||
|
||||
/* shared resources */
|
||||
auto grassTexture = std::make_shared<engine::resources::Texture>(
|
||||
&app.render_data_,
|
||||
app.GetResourcePath("textures/grass.jpg"),
|
||||
engine::resources::Texture::Filtering::ANISOTROPIC
|
||||
engine::resources::Texture::Filtering::kAnisotropic
|
||||
);
|
||||
auto spaceTexture = std::make_shared<engine::resources::Texture>(
|
||||
&app.render_data_,
|
||||
app.GetResourcePath("textures/space2.png"),
|
||||
engine::resources::Texture::Filtering::ANISOTROPIC
|
||||
engine::resources::Texture::Filtering::kAnisotropic
|
||||
);
|
||||
|
||||
/* cube */
|
||||
@ -100,10 +100,10 @@ void playGame(GameSettings settings)
|
||||
myScene->GetComponent<engine::TransformComponent>(cube)->position = glm::vec3{ -0.5f + 5.0f, -0.5f + 5.0f, -0.5f + 5.0f };
|
||||
auto cubeRenderable = myScene->AddComponent<engine::RenderableComponent>(cube);
|
||||
cubeRenderable->material = std::make_shared<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.standard"));
|
||||
cubeRenderable->material->m_texture = app.GetResource<engine::resources::Texture>("builtin.white");
|
||||
cubeRenderable->material->texture_ = app.GetResource<engine::resources::Texture>("builtin.white");
|
||||
cubeRenderable->mesh = genCuboidMesh(app.gfxdev(), 1.0f, 1.0f, 1.0f, 1);
|
||||
auto cubeCollider = myScene->AddComponent<engine::ColliderComponent>(cube);
|
||||
cubeCollider->isStatic = true;
|
||||
cubeCollider->is_static = true;
|
||||
cubeCollider->aabb = { { 0.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 1.0f } };
|
||||
}
|
||||
|
||||
@ -113,22 +113,22 @@ void playGame(GameSettings settings)
|
||||
myScene->GetComponent<engine::TransformComponent>(floor)->position = glm::vec3{-5000.0f, -1.0f, -5000.0f};
|
||||
auto floorRenderable = myScene->AddComponent<engine::RenderableComponent>(floor);
|
||||
floorRenderable->material = std::make_shared<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.standard"));
|
||||
floorRenderable->material->m_texture = grassTexture;
|
||||
floorRenderable->material->texture_ = grassTexture;
|
||||
floorRenderable->mesh = genCuboidMesh(app.gfxdev(), 10000.0f, 1.0f, 10000.0f, 5000.0f);
|
||||
floorRenderable->shown = true;
|
||||
auto floorCollider = myScene->AddComponent<engine::ColliderComponent>(floor);
|
||||
floorCollider->isStatic = true;
|
||||
floorCollider->is_static = true;
|
||||
floorCollider->aabb = { { 0.0f, 0.0f, 0.0f }, { 10000.0f, 1.0f, 10000.0f } };
|
||||
}
|
||||
|
||||
//engine::util::loadMeshFromFile(myScene, app.GetResourcePath("models/astronaut/astronaut.dae"));
|
||||
//engine::util::LoadMeshFromFile(myScene, app.GetResourcePath("models/astronaut/astronaut.dae"));
|
||||
|
||||
/* skybox */
|
||||
{
|
||||
uint32_t skybox = myScene->CreateEntity("skybox");
|
||||
auto skyboxRenderable = myScene->AddComponent<engine::RenderableComponent>(skybox);
|
||||
skyboxRenderable->material = std::make_unique<engine::resources::Material>(app.GetResource<engine::resources::Shader>("builtin.skybox"));
|
||||
skyboxRenderable->material->m_texture = spaceTexture;
|
||||
skyboxRenderable->material->texture_ = spaceTexture;
|
||||
skyboxRenderable->mesh = genCuboidMesh(app.gfxdev(), 10.0f, 10.0f, 10.0f, 1.0f, true);
|
||||
myScene->GetComponent<engine::TransformComponent>(skybox)->position = { -5.0f, -5.0f, -5.0f };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user