mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Make all header files use #pragma once
This commit is contained in:
parent
16357675a7
commit
d2223a7b45
@ -10,8 +10,6 @@ a random game engine thing. Now finally with ECS!
|
||||
|
||||
- Support dynamic shadow mapping (at least for shadows cast from the scene's sun)
|
||||
|
||||
- Sort out LOG_X calls and ensure DEBUG, TRACE, INFO, etc are being used appropriately
|
||||
|
||||
## Medium priority (next week)
|
||||
|
||||
- UI generator exposed at the Application level (Scene UI Systems could use this to draw menus every frame)
|
||||
@ -58,3 +56,5 @@ Added the BVH AABB tree made in Summer to start a much better Collision system.
|
||||
The CameraControllerSystem now uses raycasting to enable FPS-style player movement.
|
||||
|
||||
Added static soft shadows.
|
||||
|
||||
Sort out LOG_X calls and ensure DEBUG, TRACE, INFO, etc are being used appropriately
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_APPLICATION_H_
|
||||
#define ENGINE_INCLUDE_APPLICATION_H_
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
@ -96,5 +95,3 @@ class Application {
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,15 +1,12 @@
|
||||
#ifndef ENGINE_INCLUDE_COMPONENTS_CUSTOM_H_
|
||||
#define ENGINE_INCLUDE_COMPONENTS_CUSTOM_H_
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace engine {
|
||||
|
||||
struct CustomComponent {
|
||||
std::function<void(void)> onInit; // void onInit(void);
|
||||
std::function<void(float)> onUpdate; // void onUpdate(float ts);
|
||||
std::function<void(void)> onInit; // void onInit(void);
|
||||
std::function<void(float)> onUpdate; // void onUpdate(float ts);
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_COMPONENTS_MESH_RENDERABLE_H_
|
||||
#define ENGINE_INCLUDE_COMPONENTS_MESH_RENDERABLE_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -9,11 +8,9 @@
|
||||
namespace engine {
|
||||
|
||||
struct MeshRenderableComponent {
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
std::shared_ptr<Material> material;
|
||||
bool visible = true; // for static meshes, changes to this may require the static render list to be rebuilt
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
std::shared_ptr<Material> material;
|
||||
bool visible = true; // for static meshes, changes to this may require the static render list to be rebuilt
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
||||
#define ENGINE_INCLUDE_COMPONENTS_TRANSFORM_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -12,19 +11,17 @@
|
||||
namespace engine {
|
||||
|
||||
struct TransformComponent {
|
||||
std::string tag;
|
||||
std::string tag;
|
||||
|
||||
glm::mat4 world_matrix;
|
||||
glm::mat4 world_matrix;
|
||||
|
||||
glm::quat rotation;
|
||||
glm::vec3 position;
|
||||
glm::vec3 scale;
|
||||
glm::quat rotation;
|
||||
glm::vec3 position;
|
||||
glm::vec3 scale;
|
||||
|
||||
Entity parent;
|
||||
Entity parent;
|
||||
|
||||
bool is_static;
|
||||
bool is_static;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace engine {
|
||||
|
||||
struct UIRenderableComponent {
|
||||
int x;
|
||||
};
|
||||
struct UIRenderableComponent {
|
||||
int x;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_ECS_H_
|
||||
#define ENGINE_INCLUDE_ECS_H_
|
||||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
#include <cassert>
|
||||
@ -18,54 +17,55 @@ using Entity = uint32_t; // ECS entity
|
||||
constexpr size_t kMaxComponents = 10;
|
||||
|
||||
class IComponentArray {
|
||||
public:
|
||||
virtual ~IComponentArray() = default;
|
||||
public:
|
||||
virtual ~IComponentArray() = default;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ComponentArray : public IComponentArray {
|
||||
public:
|
||||
void InsertData(Entity entity, const T& component) {
|
||||
if (component_array_.size() < entity + 1) {
|
||||
component_array_.resize(entity + 1);
|
||||
public:
|
||||
void InsertData(Entity entity, const T& component)
|
||||
{
|
||||
if (component_array_.size() < entity + 1) {
|
||||
component_array_.resize(entity + 1);
|
||||
}
|
||||
// bounds checking here as not performance critical
|
||||
component_array_.at(entity) = component;
|
||||
}
|
||||
// bounds checking here as not performance critical
|
||||
component_array_.at(entity) = component;
|
||||
}
|
||||
|
||||
void DeleteData(Entity entity) {
|
||||
(void)entity; // TODO
|
||||
}
|
||||
void DeleteData(Entity entity)
|
||||
{
|
||||
(void)entity; // TODO
|
||||
}
|
||||
|
||||
T* GetData(Entity entity) {
|
||||
assert(entity < component_array_.size());
|
||||
return &component_array_[entity];
|
||||
}
|
||||
T* GetData(Entity entity)
|
||||
{
|
||||
assert(entity < component_array_.size());
|
||||
return &component_array_[entity];
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<T> component_array_{};
|
||||
private:
|
||||
std::vector<T> component_array_{};
|
||||
};
|
||||
|
||||
class System {
|
||||
public:
|
||||
System(Scene* scene, std::set<size_t> required_component_hashes);
|
||||
virtual ~System() {}
|
||||
System(const System&) = delete;
|
||||
System& operator=(const System&) = delete;
|
||||
public:
|
||||
System(Scene* scene, std::set<size_t> required_component_hashes);
|
||||
virtual ~System() {}
|
||||
System(const System&) = delete;
|
||||
System& operator=(const System&) = delete;
|
||||
|
||||
virtual void OnUpdate(float ts) = 0;
|
||||
virtual void OnUpdate(float ts) = 0;
|
||||
|
||||
virtual void OnComponentInsert(Entity) {}
|
||||
virtual void OnComponentRemove(Entity) {}
|
||||
virtual void OnComponentInsert(Entity) {}
|
||||
virtual void OnComponentRemove(Entity) {}
|
||||
|
||||
Scene* const scene_;
|
||||
Scene* const scene_;
|
||||
|
||||
std::bitset<kMaxComponents> signature_;
|
||||
std::bitset<kMaxComponents> signature_;
|
||||
|
||||
// entities that contain the needed components
|
||||
std::set<Entity> entities_{};
|
||||
// entities that contain the needed components
|
||||
std::set<Entity> entities_{};
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,6 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_ENGINE_API_H_
|
||||
#define ENGINE_INCLUDE_ENGINE_API_H_
|
||||
|
||||
#pragma once
|
||||
/*
|
||||
#ifndef ENGINE_API
|
||||
# ifdef _MSC_VER
|
||||
@ -16,5 +14,3 @@
|
||||
*/
|
||||
|
||||
#define ENGINE_API
|
||||
|
||||
#endif
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_EVENT_SYSTEM_H_
|
||||
#define ENGINE_INCLUDE_EVENT_SYSTEM_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@ -10,115 +9,110 @@
|
||||
namespace engine {
|
||||
|
||||
enum class EventSubscriberKind {
|
||||
kEntity,
|
||||
kEntity,
|
||||
};
|
||||
|
||||
// Event handler base-class
|
||||
template <typename T>
|
||||
class EventHandler {
|
||||
public:
|
||||
virtual void OnEvent(T data) = 0;
|
||||
public:
|
||||
virtual void OnEvent(T data) = 0;
|
||||
};
|
||||
|
||||
// Event queue interface to allow for different type queues to be in the map
|
||||
class IEventQueue {
|
||||
public:
|
||||
virtual ~IEventQueue() {}
|
||||
virtual void DespatchEvents() = 0;
|
||||
public:
|
||||
virtual ~IEventQueue() {}
|
||||
virtual void DespatchEvents() = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class EventQueue : public IEventQueue {
|
||||
// holds events of type T and subscribers to those events
|
||||
// holds events of type T and subscribers to those events
|
||||
|
||||
public:
|
||||
void Subscribe(EventSubscriberKind kind, uint32_t id,
|
||||
EventHandler<T>* handler) {
|
||||
// For the time being, ignore kind (TODO)
|
||||
(void)kind;
|
||||
assert(subscribers_.contains(id) == false &&
|
||||
"subscribing to an event with ID that's already in use!");
|
||||
subscribers_.emplace(id, handler);
|
||||
}
|
||||
|
||||
void QueueEvent(EventSubscriberKind kind, uint32_t id, T event) {
|
||||
// For the time being, ignore kind (TODO)
|
||||
(void)kind;
|
||||
assert(subscribers_.contains(id) &&
|
||||
"Attempt to submit event to non-existing subscriber!");
|
||||
EventHandler<T>* handler = subscribers_.at(id);
|
||||
event_queue_.emplace(handler, event);
|
||||
}
|
||||
|
||||
void DespatchEvents() override {
|
||||
while (event_queue_.empty() == false) {
|
||||
auto [handler, event] = event_queue_.front();
|
||||
handler->OnEvent(event);
|
||||
event_queue_.pop();
|
||||
public:
|
||||
void Subscribe(EventSubscriberKind kind, uint32_t id, EventHandler<T>* handler)
|
||||
{
|
||||
// For the time being, ignore kind (TODO)
|
||||
(void)kind;
|
||||
assert(subscribers_.contains(id) == false && "subscribing to an event with ID that's already in use!");
|
||||
subscribers_.emplace(id, handler);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<uint32_t, EventHandler<T>*> subscribers_;
|
||||
void QueueEvent(EventSubscriberKind kind, uint32_t id, T event)
|
||||
{
|
||||
// For the time being, ignore kind (TODO)
|
||||
(void)kind;
|
||||
assert(subscribers_.contains(id) && "Attempt to submit event to non-existing subscriber!");
|
||||
EventHandler<T>* handler = subscribers_.at(id);
|
||||
event_queue_.emplace(handler, event);
|
||||
}
|
||||
|
||||
struct QueuedEvent {
|
||||
QueuedEvent(EventHandler<T>* handler, T event)
|
||||
: handler(handler), event(event) {}
|
||||
void DespatchEvents() override
|
||||
{
|
||||
while (event_queue_.empty() == false) {
|
||||
auto [handler, event] = event_queue_.front();
|
||||
handler->OnEvent(event);
|
||||
event_queue_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
EventHandler<T>* handler;
|
||||
T event;
|
||||
};
|
||||
std::queue<QueuedEvent> event_queue_{};
|
||||
private:
|
||||
std::unordered_map<uint32_t, EventHandler<T>*> subscribers_;
|
||||
|
||||
struct QueuedEvent {
|
||||
QueuedEvent(EventHandler<T>* handler, T event) : handler(handler), event(event) {}
|
||||
|
||||
EventHandler<T>* handler;
|
||||
T event;
|
||||
};
|
||||
std::queue<QueuedEvent> event_queue_{};
|
||||
};
|
||||
|
||||
class EventSystem {
|
||||
public:
|
||||
EventSystem() {}
|
||||
EventSystem(const EventSystem&) = delete;
|
||||
EventSystem& operator=(const EventSystem&) = delete;
|
||||
~EventSystem() {}
|
||||
public:
|
||||
EventSystem() {}
|
||||
EventSystem(const EventSystem&) = delete;
|
||||
EventSystem& operator=(const EventSystem&) = delete;
|
||||
~EventSystem() {}
|
||||
|
||||
template <typename T>
|
||||
void RegisterEventType() {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) == false &&
|
||||
"Registering an event queue more than once!");
|
||||
event_queues_.emplace(hash, std::make_unique<EventQueue<T>>());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SubscribeToEventType(EventSubscriberKind kind, uint32_t id,
|
||||
EventHandler<T>* handler) {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) &&
|
||||
"Subscribing to event type that isn't registered!");
|
||||
EventQueue<T>* queue =
|
||||
dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
|
||||
assert(queue != nullptr && "This cast should work?!! wot");
|
||||
queue->Subscribe(kind, id, handler);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void QueueEvent(EventSubscriberKind kind, uint32_t subscriber_id, T event) {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) &&
|
||||
"Subscribing to event type that isn't registered!");
|
||||
EventQueue<T>* queue =
|
||||
dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
|
||||
assert(queue != nullptr && "This cast should work?!! wot");
|
||||
queue->QueueEvent(kind, subscriber_id, event);
|
||||
}
|
||||
|
||||
void DespatchEvents() {
|
||||
for (auto& [hash, queue] : event_queues_) {
|
||||
queue->DespatchEvents();
|
||||
template <typename T>
|
||||
void RegisterEventType()
|
||||
{
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) == false && "Registering an event queue more than once!");
|
||||
event_queues_.emplace(hash, std::make_unique<EventQueue<T>>());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<size_t, std::unique_ptr<IEventQueue>> event_queues_{};
|
||||
template <typename T>
|
||||
void SubscribeToEventType(EventSubscriberKind kind, uint32_t id, EventHandler<T>* handler)
|
||||
{
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) && "Subscribing to event type that isn't registered!");
|
||||
EventQueue<T>* queue = dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
|
||||
assert(queue != nullptr && "This cast should work?!! wot");
|
||||
queue->Subscribe(kind, id, handler);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void QueueEvent(EventSubscriberKind kind, uint32_t subscriber_id, T event)
|
||||
{
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) && "Subscribing to event type that isn't registered!");
|
||||
EventQueue<T>* queue = dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
|
||||
assert(queue != nullptr && "This cast should work?!! wot");
|
||||
queue->QueueEvent(kind, subscriber_id, event);
|
||||
}
|
||||
|
||||
void DespatchEvents()
|
||||
{
|
||||
for (auto& [hash, queue] : event_queues_) {
|
||||
queue->DespatchEvents();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<size_t, std::unique_ptr<IEventQueue>> event_queues_{};
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_GFX_H_
|
||||
#define ENGINE_INCLUDE_GFX_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
@ -123,7 +122,7 @@ struct PipelineInfo {
|
||||
CullMode face_cull_mode;
|
||||
bool alpha_blending;
|
||||
bool write_z;
|
||||
bool line_primitives; // false for triangles, true for lines
|
||||
bool line_primitives; // false for triangles, true for lines
|
||||
bool depth_attachment_only; // false 99% of the time
|
||||
std::vector<const DescriptorSetLayout*> descriptor_set_layouts;
|
||||
};
|
||||
@ -169,5 +168,3 @@ struct hash<engine::gfx::SamplerInfo> {
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif
|
@ -1,133 +1,108 @@
|
||||
#ifndef ENGINE_INCLUDE_GFX_DEVICE_H_
|
||||
#define ENGINE_INCLUDE_GFX_DEVICE_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "gfx.h"
|
||||
|
||||
struct SDL_Window; // <SDL_video.h>
|
||||
struct ImDrawData; // "imgui/imgui.h"
|
||||
struct SDL_Window; // <SDL_video.h>
|
||||
struct ImDrawData; // "imgui/imgui.h"
|
||||
|
||||
namespace engine {
|
||||
|
||||
class GFXDevice {
|
||||
public:
|
||||
GFXDevice(const char* app_name, const char* app_version, SDL_Window* window,
|
||||
gfx::GraphicsSettings settings);
|
||||
public:
|
||||
GFXDevice(const char* app_name, const char* app_version, SDL_Window* window, gfx::GraphicsSettings settings);
|
||||
|
||||
GFXDevice(const GFXDevice&) = delete;
|
||||
GFXDevice& operator=(const GFXDevice&) = delete;
|
||||
~GFXDevice();
|
||||
GFXDevice(const GFXDevice&) = delete;
|
||||
GFXDevice& operator=(const GFXDevice&) = delete;
|
||||
~GFXDevice();
|
||||
|
||||
void GetViewportSize(uint32_t* w, uint32_t* h);
|
||||
void GetViewportSize(uint32_t* w, uint32_t* h);
|
||||
|
||||
void SetupImguiBackend();
|
||||
void ShutdownImguiBackend();
|
||||
void CmdRenderImguiDrawData(gfx::DrawBuffer* draw_buffer, ImDrawData* draw_data);
|
||||
void SetupImguiBackend();
|
||||
void ShutdownImguiBackend();
|
||||
void CmdRenderImguiDrawData(gfx::DrawBuffer* draw_buffer, ImDrawData* draw_data);
|
||||
|
||||
gfx::DrawBuffer* BeginRender();
|
||||
gfx::DrawBuffer* BeginRender();
|
||||
|
||||
/* - draw_buffer MUST be a valid pointer returned by BeginRender().
|
||||
- draw_buffer is invalid after this function has been called. */
|
||||
void FinishRender(gfx::DrawBuffer* draw_buffer);
|
||||
/* - draw_buffer MUST be a valid pointer returned by BeginRender().
|
||||
- draw_buffer is invalid after this function has been called. */
|
||||
void FinishRender(gfx::DrawBuffer* draw_buffer);
|
||||
|
||||
gfx::Image* CreateShadowmapImage();
|
||||
gfx::DrawBuffer* BeginShadowmapRender(gfx::Image* image);
|
||||
void FinishShadowmapRender(gfx::DrawBuffer* draw_buffer, gfx::Image* image);
|
||||
gfx::Image* CreateShadowmapImage();
|
||||
gfx::DrawBuffer* BeginShadowmapRender(gfx::Image* image);
|
||||
void FinishShadowmapRender(gfx::DrawBuffer* draw_buffer, gfx::Image* image);
|
||||
|
||||
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
|
||||
- pipeline MUST be a valid pointer returned by CreatePipeline() */
|
||||
void CmdBindPipeline(gfx::DrawBuffer* draw_buffer,
|
||||
const gfx::Pipeline* pipeline);
|
||||
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
|
||||
- pipeline MUST be a valid pointer returned by CreatePipeline() */
|
||||
void CmdBindPipeline(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline);
|
||||
|
||||
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
|
||||
- buffer MUST be a valid pointer returned by CreateBuffer */
|
||||
void CmdBindVertexBuffer(gfx::DrawBuffer* draw_buffer, uint32_t binding,
|
||||
const gfx::Buffer* buffer);
|
||||
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
|
||||
- buffer MUST be a valid pointer returned by CreateBuffer */
|
||||
void CmdBindVertexBuffer(gfx::DrawBuffer* draw_buffer, uint32_t binding, const gfx::Buffer* buffer);
|
||||
|
||||
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
|
||||
- buffer MUST be a valid pointer returned by CreateBuffer */
|
||||
void CmdBindIndexBuffer(gfx::DrawBuffer* draw_buffer,
|
||||
const gfx::Buffer* buffer);
|
||||
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
|
||||
- buffer MUST be a valid pointer returned by CreateBuffer */
|
||||
void CmdBindIndexBuffer(gfx::DrawBuffer* draw_buffer, const gfx::Buffer* buffer);
|
||||
|
||||
void CmdDrawIndexed(gfx::DrawBuffer* draw_buffer, uint32_t index_count,
|
||||
uint32_t instance_count, uint32_t first_index,
|
||||
int32_t vertex_offset, uint32_t first_instance);
|
||||
void CmdDrawIndexed(gfx::DrawBuffer* draw_buffer, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t vertex_offset,
|
||||
uint32_t first_instance);
|
||||
|
||||
void CmdDraw(gfx::DrawBuffer* drawBuffer, uint32_t vertex_count,
|
||||
uint32_t instance_count, uint32_t first_vertex,
|
||||
uint32_t first_instance);
|
||||
void CmdDraw(gfx::DrawBuffer* drawBuffer, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance);
|
||||
|
||||
void CmdPushConstants(gfx::DrawBuffer* draw_buffer,
|
||||
const gfx::Pipeline* pipeline, uint32_t offset,
|
||||
uint32_t size, const void* data);
|
||||
void CmdPushConstants(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline, uint32_t offset, uint32_t size, const void* data);
|
||||
|
||||
void CmdBindDescriptorSet(gfx::DrawBuffer* draw_buffer,
|
||||
const gfx::Pipeline* pipeline,
|
||||
const gfx::DescriptorSet* set, uint32_t set_number);
|
||||
void CmdBindDescriptorSet(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline, const gfx::DescriptorSet* set, uint32_t set_number);
|
||||
|
||||
gfx::Pipeline* CreatePipeline(const gfx::PipelineInfo& info);
|
||||
gfx::Pipeline* CreatePipeline(const gfx::PipelineInfo& info);
|
||||
|
||||
void DestroyPipeline(const gfx::Pipeline* pipeline);
|
||||
void DestroyPipeline(const gfx::Pipeline* pipeline);
|
||||
|
||||
gfx::DescriptorSetLayout* CreateDescriptorSetLayout(
|
||||
const std::vector<gfx::DescriptorSetLayoutBinding>& bindings);
|
||||
gfx::DescriptorSetLayout* CreateDescriptorSetLayout(const std::vector<gfx::DescriptorSetLayoutBinding>& bindings);
|
||||
|
||||
void DestroyDescriptorSetLayout(const gfx::DescriptorSetLayout* layout);
|
||||
void DestroyDescriptorSetLayout(const gfx::DescriptorSetLayout* layout);
|
||||
|
||||
gfx::DescriptorSet* AllocateDescriptorSet(
|
||||
const gfx::DescriptorSetLayout* layout);
|
||||
gfx::DescriptorSet* AllocateDescriptorSet(const gfx::DescriptorSetLayout* layout);
|
||||
|
||||
void FreeDescriptorSet(const gfx::DescriptorSet* set);
|
||||
void FreeDescriptorSet(const gfx::DescriptorSet* set);
|
||||
|
||||
// This updates all copies of the descriptor.
|
||||
// This cannot be used after any frames have been renderered
|
||||
void UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set,
|
||||
uint32_t binding,
|
||||
const gfx::UniformBuffer* buffer,
|
||||
size_t offset, size_t range);
|
||||
// This updates all copies of the descriptor.
|
||||
// This cannot be used after any frames have been renderered
|
||||
void UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set, uint32_t binding, const gfx::UniformBuffer* buffer, size_t offset, size_t range);
|
||||
|
||||
void UpdateDescriptorCombinedImageSampler(const gfx::DescriptorSet* set,
|
||||
uint32_t binding,
|
||||
const gfx::Image* image,
|
||||
const gfx::Sampler* sampler);
|
||||
void UpdateDescriptorCombinedImageSampler(const gfx::DescriptorSet* set, uint32_t binding, const gfx::Image* image, const gfx::Sampler* sampler);
|
||||
|
||||
gfx::UniformBuffer* CreateUniformBuffer(uint64_t size,
|
||||
const void* initial_data);
|
||||
gfx::UniformBuffer* CreateUniformBuffer(uint64_t size, const void* initial_data);
|
||||
|
||||
void DestroyUniformBuffer(const gfx::UniformBuffer* descriptor_buffer);
|
||||
void DestroyUniformBuffer(const gfx::UniformBuffer* descriptor_buffer);
|
||||
|
||||
void WriteUniformBuffer(gfx::UniformBuffer* buffer, uint64_t offset,
|
||||
uint64_t size, const void* data);
|
||||
void WriteUniformBuffer(gfx::UniformBuffer* buffer, uint64_t offset, uint64_t size, const void* data);
|
||||
|
||||
// Loads data into staging buffer and copies that into a single GPU buffer.
|
||||
gfx::Buffer* CreateBuffer(gfx::BufferType type, uint64_t size,
|
||||
const void* data);
|
||||
// Loads data into staging buffer and copies that into a single GPU buffer.
|
||||
gfx::Buffer* CreateBuffer(gfx::BufferType type, uint64_t size, const void* data);
|
||||
|
||||
void DestroyBuffer(const gfx::Buffer* buffer);
|
||||
void DestroyBuffer(const gfx::Buffer* buffer);
|
||||
|
||||
gfx::Image* CreateImage(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const void* image_data);
|
||||
gfx::Image* CreateImage(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const void* image_data);
|
||||
|
||||
gfx::Image* CreateImageCubemap(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const std::array<const void*, 6>& image_data);
|
||||
gfx::Image* CreateImageCubemap(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const std::array<const void*, 6>& image_data);
|
||||
|
||||
void DestroyImage(const gfx::Image* image);
|
||||
void DestroyImage(const gfx::Image* image);
|
||||
|
||||
const gfx::Sampler* CreateSampler(const gfx::SamplerInfo& info);
|
||||
const gfx::Sampler* CreateSampler(const gfx::SamplerInfo& info);
|
||||
|
||||
void DestroySampler(const gfx::Sampler* sampler);
|
||||
void DestroySampler(const gfx::Sampler* sampler);
|
||||
|
||||
uint64_t GetFrameCount();
|
||||
uint64_t GetFrameCount();
|
||||
|
||||
void LogPerformanceInfo();
|
||||
void LogPerformanceInfo();
|
||||
|
||||
// wait until all the active GPU queues have finished working
|
||||
void WaitIdle();
|
||||
// wait until all the active GPU queues have finished working
|
||||
void WaitIdle();
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> pimpl;
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> pimpl;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_INPUT_MANAGER_H_
|
||||
#define ENGINE_INCLUDE_INPUT_MANAGER_H_
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
@ -15,130 +14,113 @@ enum class InputDevice : int { kMouse, kKeyboard, kController, kSize };
|
||||
|
||||
// This class should be used to get platform/input-device independent input
|
||||
class InputManager {
|
||||
public:
|
||||
/* The Window object here is stored for the duration of the InputManager.
|
||||
* 'win' must point to a valid Window object. */
|
||||
InputManager(const Window* win) : win_(win) {
|
||||
assert(win != nullptr);
|
||||
enabled_devices_.fill(true);
|
||||
}
|
||||
InputManager(const InputManager&) = delete;
|
||||
|
||||
InputManager& operator=(const InputManager&) = delete;
|
||||
|
||||
~InputManager() {}
|
||||
|
||||
void AddInputButton(const std::string& name, inputs::MouseButton button) {
|
||||
AddInputDeviceButton(name, InputDevice::kMouse, static_cast<int>(button));
|
||||
}
|
||||
|
||||
void AddInputButton(const std::string& name, inputs::Key button) {
|
||||
AddInputDeviceButton(name, InputDevice::kKeyboard,
|
||||
static_cast<int>(button));
|
||||
}
|
||||
|
||||
void AddInputAxis(const std::string& name, inputs::MouseAxis axis) {
|
||||
AddInputDeviceAxis(name, InputDevice::kMouse, static_cast<int>(axis));
|
||||
}
|
||||
|
||||
void AddInputButtonAsAxis(const std::string& name, inputs::MouseButton high,
|
||||
inputs::MouseButton low) {
|
||||
AddInputDeviceButtonAsAxis(name, InputDevice::kMouse,
|
||||
static_cast<int>(high), static_cast<int>(low));
|
||||
}
|
||||
|
||||
void AddInputButtonAsAxis(const std::string& name, inputs::Key high,
|
||||
inputs::Key low) {
|
||||
AddInputDeviceButtonAsAxis(name, InputDevice::kKeyboard,
|
||||
static_cast<int>(high), static_cast<int>(low));
|
||||
}
|
||||
|
||||
void DelInputButton(int index) {
|
||||
std::vector<struct ButtonEntry>::iterator it = button_entries_.begin();
|
||||
std::advance(it, index);
|
||||
button_entries_.erase(it);
|
||||
}
|
||||
|
||||
void DelInputAxis(int index) {
|
||||
std::vector<struct AxisEntry>::iterator it = axis_entries_.begin();
|
||||
std::advance(it, index);
|
||||
axis_entries_.erase(it);
|
||||
}
|
||||
|
||||
void SetDeviceActive(enum InputDevice device, bool active) {
|
||||
enabled_devices_[static_cast<int>(device)] = active;
|
||||
}
|
||||
|
||||
bool GetDeviceActive(enum InputDevice device) const {
|
||||
return enabled_devices_[static_cast<int>(device)];
|
||||
}
|
||||
|
||||
float GetAxis(const std::string& axis_name) const;
|
||||
|
||||
bool GetButton(const std::string& button_name) const;
|
||||
|
||||
bool GetButtonPress(const std::string& button_name) const;
|
||||
|
||||
bool GetButtonRelease(const std::string& button_name) const;
|
||||
|
||||
private:
|
||||
struct ButtonEntry {
|
||||
std::string name;
|
||||
enum InputDevice device;
|
||||
int button; // enumeration of device buttons or axes
|
||||
};
|
||||
|
||||
struct AxisEntry {
|
||||
std::string name;
|
||||
enum InputDevice device;
|
||||
int axis;
|
||||
bool is_button_axis;
|
||||
int high;
|
||||
int low;
|
||||
};
|
||||
|
||||
const Window* win_;
|
||||
|
||||
std::vector<struct ButtonEntry> button_entries_;
|
||||
std::vector<struct AxisEntry> axis_entries_;
|
||||
|
||||
std::array<bool, static_cast<int>(InputDevice::kSize)> enabled_devices_;
|
||||
|
||||
// private methods
|
||||
|
||||
float GetDeviceAxis(enum InputDevice device, int axis) const;
|
||||
|
||||
bool GetDeviceButton(enum InputDevice device, int button) const;
|
||||
|
||||
bool getDeviceButtonDown(enum InputDevice device, int button) const;
|
||||
|
||||
bool GetDeviceButtonUp(enum InputDevice device, int button) const;
|
||||
|
||||
float GetButtonAxis(enum InputDevice device, int high, int low) const {
|
||||
float value = 0.0f;
|
||||
if (GetDeviceButton(device, high)) value += 1.0f;
|
||||
if (low != 0) {
|
||||
if (GetDeviceButton(device, low)) value += -1.0f;
|
||||
public:
|
||||
/* The Window object here is stored for the duration of the InputManager.
|
||||
* 'win' must point to a valid Window object. */
|
||||
InputManager(const Window* win) : win_(win)
|
||||
{
|
||||
assert(win != nullptr);
|
||||
enabled_devices_.fill(true);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
InputManager(const InputManager&) = delete;
|
||||
|
||||
void AddInputDeviceButton(const std::string& name, InputDevice device,
|
||||
int button) {
|
||||
button_entries_.push_back({name, device, button});
|
||||
}
|
||||
InputManager& operator=(const InputManager&) = delete;
|
||||
|
||||
void AddInputDeviceAxis(const std::string& name, InputDevice device,
|
||||
int axis) {
|
||||
axis_entries_.push_back({name, device, axis, false, 0, 0});
|
||||
}
|
||||
~InputManager() {}
|
||||
|
||||
void AddInputDeviceButtonAsAxis(const std::string& name, InputDevice device,
|
||||
int high, int low) {
|
||||
axis_entries_.push_back({name, device, 0, true, high, low});
|
||||
}
|
||||
void AddInputButton(const std::string& name, inputs::MouseButton button) { AddInputDeviceButton(name, InputDevice::kMouse, static_cast<int>(button)); }
|
||||
|
||||
void AddInputButton(const std::string& name, inputs::Key button) { AddInputDeviceButton(name, InputDevice::kKeyboard, static_cast<int>(button)); }
|
||||
|
||||
void AddInputAxis(const std::string& name, inputs::MouseAxis axis) { AddInputDeviceAxis(name, InputDevice::kMouse, static_cast<int>(axis)); }
|
||||
|
||||
void AddInputButtonAsAxis(const std::string& name, inputs::MouseButton high, inputs::MouseButton low)
|
||||
{
|
||||
AddInputDeviceButtonAsAxis(name, InputDevice::kMouse, static_cast<int>(high), static_cast<int>(low));
|
||||
}
|
||||
|
||||
void AddInputButtonAsAxis(const std::string& name, inputs::Key high, inputs::Key low)
|
||||
{
|
||||
AddInputDeviceButtonAsAxis(name, InputDevice::kKeyboard, static_cast<int>(high), static_cast<int>(low));
|
||||
}
|
||||
|
||||
void DelInputButton(int index)
|
||||
{
|
||||
std::vector<struct ButtonEntry>::iterator it = button_entries_.begin();
|
||||
std::advance(it, index);
|
||||
button_entries_.erase(it);
|
||||
}
|
||||
|
||||
void DelInputAxis(int index)
|
||||
{
|
||||
std::vector<struct AxisEntry>::iterator it = axis_entries_.begin();
|
||||
std::advance(it, index);
|
||||
axis_entries_.erase(it);
|
||||
}
|
||||
|
||||
void SetDeviceActive(enum InputDevice device, bool active) { enabled_devices_[static_cast<int>(device)] = active; }
|
||||
|
||||
bool GetDeviceActive(enum InputDevice device) const { return enabled_devices_[static_cast<int>(device)]; }
|
||||
|
||||
float GetAxis(const std::string& axis_name) const;
|
||||
|
||||
bool GetButton(const std::string& button_name) const;
|
||||
|
||||
bool GetButtonPress(const std::string& button_name) const;
|
||||
|
||||
bool GetButtonRelease(const std::string& button_name) const;
|
||||
|
||||
private:
|
||||
struct ButtonEntry {
|
||||
std::string name;
|
||||
enum InputDevice device;
|
||||
int button; // enumeration of device buttons or axes
|
||||
};
|
||||
|
||||
struct AxisEntry {
|
||||
std::string name;
|
||||
enum InputDevice device;
|
||||
int axis;
|
||||
bool is_button_axis;
|
||||
int high;
|
||||
int low;
|
||||
};
|
||||
|
||||
const Window* win_;
|
||||
|
||||
std::vector<struct ButtonEntry> button_entries_;
|
||||
std::vector<struct AxisEntry> axis_entries_;
|
||||
|
||||
std::array<bool, static_cast<int>(InputDevice::kSize)> enabled_devices_;
|
||||
|
||||
// private methods
|
||||
|
||||
float GetDeviceAxis(enum InputDevice device, int axis) const;
|
||||
|
||||
bool GetDeviceButton(enum InputDevice device, int button) const;
|
||||
|
||||
bool getDeviceButtonDown(enum InputDevice device, int button) const;
|
||||
|
||||
bool GetDeviceButtonUp(enum InputDevice device, int button) const;
|
||||
|
||||
float GetButtonAxis(enum InputDevice device, int high, int low) const
|
||||
{
|
||||
float value = 0.0f;
|
||||
if (GetDeviceButton(device, high)) value += 1.0f;
|
||||
if (low != 0) {
|
||||
if (GetDeviceButton(device, low)) value += -1.0f;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void AddInputDeviceButton(const std::string& name, InputDevice device, int button) { button_entries_.push_back({name, device, button}); }
|
||||
|
||||
void AddInputDeviceAxis(const std::string& name, InputDevice device, int axis) { axis_entries_.push_back({name, device, axis, false, 0, 0}); }
|
||||
|
||||
void AddInputDeviceButtonAsAxis(const std::string& name, InputDevice device, int high, int low)
|
||||
{
|
||||
axis_entries_.push_back({name, device, 0, true, high, low});
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_INPUTS_KEYBOARD_H_
|
||||
#define ENGINE_INCLUDE_INPUTS_KEYBOARD_H_
|
||||
#pragma once
|
||||
|
||||
// Keyboard scancodes, taken from SDL_scancode.h
|
||||
|
||||
@ -7,373 +6,371 @@ namespace engine {
|
||||
namespace inputs {
|
||||
|
||||
enum class Key : int {
|
||||
K_UNKNOWN = 0,
|
||||
K_UNKNOWN = 0,
|
||||
|
||||
/**
|
||||
* \name Usage page 0x07
|
||||
*
|
||||
* These values are from usage page 0x07 (USB keyboard page).
|
||||
*/
|
||||
/* @{ */
|
||||
/**
|
||||
* \name Usage page 0x07
|
||||
*
|
||||
* These values are from usage page 0x07 (USB keyboard page).
|
||||
*/
|
||||
/* @{ */
|
||||
|
||||
K_A = 4,
|
||||
K_B = 5,
|
||||
K_C = 6,
|
||||
K_D = 7,
|
||||
K_E = 8,
|
||||
K_F = 9,
|
||||
K_G = 10,
|
||||
K_H = 11,
|
||||
K_I = 12,
|
||||
K_J = 13,
|
||||
K_K = 14,
|
||||
K_L = 15,
|
||||
K_M = 16,
|
||||
K_N = 17,
|
||||
K_O = 18,
|
||||
K_P = 19,
|
||||
K_Q = 20,
|
||||
K_R = 21,
|
||||
K_S = 22,
|
||||
K_T = 23,
|
||||
K_U = 24,
|
||||
K_V = 25,
|
||||
K_W = 26,
|
||||
K_X = 27,
|
||||
K_Y = 28,
|
||||
K_Z = 29,
|
||||
K_A = 4,
|
||||
K_B = 5,
|
||||
K_C = 6,
|
||||
K_D = 7,
|
||||
K_E = 8,
|
||||
K_F = 9,
|
||||
K_G = 10,
|
||||
K_H = 11,
|
||||
K_I = 12,
|
||||
K_J = 13,
|
||||
K_K = 14,
|
||||
K_L = 15,
|
||||
K_M = 16,
|
||||
K_N = 17,
|
||||
K_O = 18,
|
||||
K_P = 19,
|
||||
K_Q = 20,
|
||||
K_R = 21,
|
||||
K_S = 22,
|
||||
K_T = 23,
|
||||
K_U = 24,
|
||||
K_V = 25,
|
||||
K_W = 26,
|
||||
K_X = 27,
|
||||
K_Y = 28,
|
||||
K_Z = 29,
|
||||
|
||||
K_1 = 30,
|
||||
K_2 = 31,
|
||||
K_3 = 32,
|
||||
K_4 = 33,
|
||||
K_5 = 34,
|
||||
K_6 = 35,
|
||||
K_7 = 36,
|
||||
K_8 = 37,
|
||||
K_9 = 38,
|
||||
K_0 = 39,
|
||||
K_1 = 30,
|
||||
K_2 = 31,
|
||||
K_3 = 32,
|
||||
K_4 = 33,
|
||||
K_5 = 34,
|
||||
K_6 = 35,
|
||||
K_7 = 36,
|
||||
K_8 = 37,
|
||||
K_9 = 38,
|
||||
K_0 = 39,
|
||||
|
||||
K_RETURN = 40,
|
||||
K_ESCAPE = 41,
|
||||
K_BACKSPACE = 42,
|
||||
K_TAB = 43,
|
||||
K_SPACE = 44,
|
||||
K_RETURN = 40,
|
||||
K_ESCAPE = 41,
|
||||
K_BACKSPACE = 42,
|
||||
K_TAB = 43,
|
||||
K_SPACE = 44,
|
||||
|
||||
K_MINUS = 45,
|
||||
K_EQUALS = 46,
|
||||
K_LEFTBRACKET = 47,
|
||||
K_RIGHTBRACKET = 48,
|
||||
K_BACKSLASH = 49, /**< Located at the lower left of the return
|
||||
* key on ISO keyboards and at the right end
|
||||
* of the QWERTY row on ANSI keyboards.
|
||||
* Produces REVERSE SOLIDUS (backslash) and
|
||||
* VERTICAL LINE in a US layout, REVERSE
|
||||
* SOLIDUS and VERTICAL LINE in a UK Mac
|
||||
* layout, NUMBER SIGN and TILDE in a UK
|
||||
* Windows layout, DOLLAR SIGN and POUND SIGN
|
||||
* in a Swiss German layout, NUMBER SIGN and
|
||||
* APOSTROPHE in a German layout, GRAVE
|
||||
* ACCENT and POUND SIGN in a French Mac
|
||||
* layout, and ASTERISK and MICRO SIGN in a
|
||||
* French Windows layout.
|
||||
*/
|
||||
K_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
|
||||
* instead of 49 for the same key, but all
|
||||
* OSes I've seen treat the two codes
|
||||
* identically. So, as an implementor, unless
|
||||
* your keyboard generates both of those
|
||||
* codes and your OS treats them differently,
|
||||
* you should generate BACKSLASH
|
||||
* instead of this code. As a user, you
|
||||
* should not rely on this code because SDL
|
||||
* will never generate it with most (all?)
|
||||
* keyboards.
|
||||
*/
|
||||
K_SEMICOLON = 51,
|
||||
K_APOSTROPHE = 52,
|
||||
K_GRAVE = 53, /**< Located in the top left corner (on both ANSI
|
||||
* and ISO keyboards). Produces GRAVE ACCENT and
|
||||
* TILDE in a US Windows layout and in US and UK
|
||||
* Mac layouts on ANSI keyboards, GRAVE ACCENT
|
||||
* and NOT SIGN in a UK Windows layout, SECTION
|
||||
* SIGN and PLUS-MINUS SIGN in US and UK Mac
|
||||
* layouts on ISO keyboards, SECTION SIGN and
|
||||
* DEGREE SIGN in a Swiss German layout (Mac:
|
||||
* only on ISO keyboards), CIRCUMFLEX ACCENT and
|
||||
* DEGREE SIGN in a German layout (Mac: only on
|
||||
* ISO keyboards), SUPERSCRIPT TWO and TILDE in a
|
||||
* French Windows layout, COMMERCIAL AT and
|
||||
* NUMBER SIGN in a French Mac layout on ISO
|
||||
* keyboards, and LESS-THAN SIGN and GREATER-THAN
|
||||
* SIGN in a Swiss German, German, or French Mac
|
||||
* layout on ANSI keyboards.
|
||||
*/
|
||||
K_COMMA = 54,
|
||||
K_PERIOD = 55,
|
||||
K_SLASH = 56,
|
||||
K_MINUS = 45,
|
||||
K_EQUALS = 46,
|
||||
K_LEFTBRACKET = 47,
|
||||
K_RIGHTBRACKET = 48,
|
||||
K_BACKSLASH = 49, /**< Located at the lower left of the return
|
||||
* key on ISO keyboards and at the right end
|
||||
* of the QWERTY row on ANSI keyboards.
|
||||
* Produces REVERSE SOLIDUS (backslash) and
|
||||
* VERTICAL LINE in a US layout, REVERSE
|
||||
* SOLIDUS and VERTICAL LINE in a UK Mac
|
||||
* layout, NUMBER SIGN and TILDE in a UK
|
||||
* Windows layout, DOLLAR SIGN and POUND SIGN
|
||||
* in a Swiss German layout, NUMBER SIGN and
|
||||
* APOSTROPHE in a German layout, GRAVE
|
||||
* ACCENT and POUND SIGN in a French Mac
|
||||
* layout, and ASTERISK and MICRO SIGN in a
|
||||
* French Windows layout.
|
||||
*/
|
||||
K_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
|
||||
* instead of 49 for the same key, but all
|
||||
* OSes I've seen treat the two codes
|
||||
* identically. So, as an implementor, unless
|
||||
* your keyboard generates both of those
|
||||
* codes and your OS treats them differently,
|
||||
* you should generate BACKSLASH
|
||||
* instead of this code. As a user, you
|
||||
* should not rely on this code because SDL
|
||||
* will never generate it with most (all?)
|
||||
* keyboards.
|
||||
*/
|
||||
K_SEMICOLON = 51,
|
||||
K_APOSTROPHE = 52,
|
||||
K_GRAVE = 53, /**< Located in the top left corner (on both ANSI
|
||||
* and ISO keyboards). Produces GRAVE ACCENT and
|
||||
* TILDE in a US Windows layout and in US and UK
|
||||
* Mac layouts on ANSI keyboards, GRAVE ACCENT
|
||||
* and NOT SIGN in a UK Windows layout, SECTION
|
||||
* SIGN and PLUS-MINUS SIGN in US and UK Mac
|
||||
* layouts on ISO keyboards, SECTION SIGN and
|
||||
* DEGREE SIGN in a Swiss German layout (Mac:
|
||||
* only on ISO keyboards), CIRCUMFLEX ACCENT and
|
||||
* DEGREE SIGN in a German layout (Mac: only on
|
||||
* ISO keyboards), SUPERSCRIPT TWO and TILDE in a
|
||||
* French Windows layout, COMMERCIAL AT and
|
||||
* NUMBER SIGN in a French Mac layout on ISO
|
||||
* keyboards, and LESS-THAN SIGN and GREATER-THAN
|
||||
* SIGN in a Swiss German, German, or French Mac
|
||||
* layout on ANSI keyboards.
|
||||
*/
|
||||
K_COMMA = 54,
|
||||
K_PERIOD = 55,
|
||||
K_SLASH = 56,
|
||||
|
||||
K_CAPSLOCK = 57,
|
||||
K_CAPSLOCK = 57,
|
||||
|
||||
K_F1 = 58,
|
||||
K_F2 = 59,
|
||||
K_F3 = 60,
|
||||
K_F4 = 61,
|
||||
K_F5 = 62,
|
||||
K_F6 = 63,
|
||||
K_F7 = 64,
|
||||
K_F8 = 65,
|
||||
K_F9 = 66,
|
||||
K_F10 = 67,
|
||||
K_F11 = 68,
|
||||
K_F12 = 69,
|
||||
K_F1 = 58,
|
||||
K_F2 = 59,
|
||||
K_F3 = 60,
|
||||
K_F4 = 61,
|
||||
K_F5 = 62,
|
||||
K_F6 = 63,
|
||||
K_F7 = 64,
|
||||
K_F8 = 65,
|
||||
K_F9 = 66,
|
||||
K_F10 = 67,
|
||||
K_F11 = 68,
|
||||
K_F12 = 69,
|
||||
|
||||
K_PRINTSCREEN = 70,
|
||||
K_SCROLLLOCK = 71,
|
||||
K_PAUSE = 72,
|
||||
K_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
|
||||
does send code 73, not 117) */
|
||||
K_HOME = 74,
|
||||
K_PAGEUP = 75,
|
||||
K_DELETE = 76,
|
||||
K_END = 77,
|
||||
K_PAGEDOWN = 78,
|
||||
K_RIGHT = 79,
|
||||
K_LEFT = 80,
|
||||
K_DOWN = 81,
|
||||
K_UP = 82,
|
||||
K_PRINTSCREEN = 70,
|
||||
K_SCROLLLOCK = 71,
|
||||
K_PAUSE = 72,
|
||||
K_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
|
||||
does send code 73, not 117) */
|
||||
K_HOME = 74,
|
||||
K_PAGEUP = 75,
|
||||
K_DELETE = 76,
|
||||
K_END = 77,
|
||||
K_PAGEDOWN = 78,
|
||||
K_RIGHT = 79,
|
||||
K_LEFT = 80,
|
||||
K_DOWN = 81,
|
||||
K_UP = 82,
|
||||
|
||||
K_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
|
||||
*/
|
||||
K_KP_DIVIDE = 84,
|
||||
K_KP_MULTIPLY = 85,
|
||||
K_KP_MINUS = 86,
|
||||
K_KP_PLUS = 87,
|
||||
K_KP_ENTER = 88,
|
||||
K_KP_1 = 89,
|
||||
K_KP_2 = 90,
|
||||
K_KP_3 = 91,
|
||||
K_KP_4 = 92,
|
||||
K_KP_5 = 93,
|
||||
K_KP_6 = 94,
|
||||
K_KP_7 = 95,
|
||||
K_KP_8 = 96,
|
||||
K_KP_9 = 97,
|
||||
K_KP_0 = 98,
|
||||
K_KP_PERIOD = 99,
|
||||
K_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
|
||||
*/
|
||||
K_KP_DIVIDE = 84,
|
||||
K_KP_MULTIPLY = 85,
|
||||
K_KP_MINUS = 86,
|
||||
K_KP_PLUS = 87,
|
||||
K_KP_ENTER = 88,
|
||||
K_KP_1 = 89,
|
||||
K_KP_2 = 90,
|
||||
K_KP_3 = 91,
|
||||
K_KP_4 = 92,
|
||||
K_KP_5 = 93,
|
||||
K_KP_6 = 94,
|
||||
K_KP_7 = 95,
|
||||
K_KP_8 = 96,
|
||||
K_KP_9 = 97,
|
||||
K_KP_0 = 98,
|
||||
K_KP_PERIOD = 99,
|
||||
|
||||
K_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
|
||||
* keyboards have over ANSI ones,
|
||||
* located between left shift and Y.
|
||||
* Produces GRAVE ACCENT and TILDE in a
|
||||
* US or UK Mac layout, REVERSE SOLIDUS
|
||||
* (backslash) and VERTICAL LINE in a
|
||||
* US or UK Windows layout, and
|
||||
* LESS-THAN SIGN and GREATER-THAN SIGN
|
||||
* in a Swiss German, German, or French
|
||||
* layout. */
|
||||
K_APPLICATION = 101, /**< windows contextual menu, compose */
|
||||
K_POWER = 102, /**< The USB document says this is a status flag,
|
||||
* not a physical key - but some Mac keyboards
|
||||
* do have a power key. */
|
||||
K_KP_EQUALS = 103,
|
||||
K_F13 = 104,
|
||||
K_F14 = 105,
|
||||
K_F15 = 106,
|
||||
K_F16 = 107,
|
||||
K_F17 = 108,
|
||||
K_F18 = 109,
|
||||
K_F19 = 110,
|
||||
K_F20 = 111,
|
||||
K_F21 = 112,
|
||||
K_F22 = 113,
|
||||
K_F23 = 114,
|
||||
K_F24 = 115,
|
||||
K_EXECUTE = 116,
|
||||
K_HELP = 117,
|
||||
K_MENU = 118,
|
||||
K_SELECT = 119,
|
||||
K_STOP = 120,
|
||||
K_AGAIN = 121, /**< redo */
|
||||
K_UNDO = 122,
|
||||
K_CUT = 123,
|
||||
K_COPY = 124,
|
||||
K_PASTE = 125,
|
||||
K_FIND = 126,
|
||||
K_MUTE = 127,
|
||||
K_VOLUMEUP = 128,
|
||||
K_VOLUMEDOWN = 129,
|
||||
/* not sure whether there's a reason to enable these */
|
||||
/* LOCKINGCAPSLOCK = 130, */
|
||||
/* LOCKINGNUMLOCK = 131, */
|
||||
/* LOCKINGSCROLLLOCK = 132, */
|
||||
K_KP_COMMA = 133,
|
||||
K_KP_EQUALSAS400 = 134,
|
||||
K_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
|
||||
* keyboards have over ANSI ones,
|
||||
* located between left shift and Y.
|
||||
* Produces GRAVE ACCENT and TILDE in a
|
||||
* US or UK Mac layout, REVERSE SOLIDUS
|
||||
* (backslash) and VERTICAL LINE in a
|
||||
* US or UK Windows layout, and
|
||||
* LESS-THAN SIGN and GREATER-THAN SIGN
|
||||
* in a Swiss German, German, or French
|
||||
* layout. */
|
||||
K_APPLICATION = 101, /**< windows contextual menu, compose */
|
||||
K_POWER = 102, /**< The USB document says this is a status flag,
|
||||
* not a physical key - but some Mac keyboards
|
||||
* do have a power key. */
|
||||
K_KP_EQUALS = 103,
|
||||
K_F13 = 104,
|
||||
K_F14 = 105,
|
||||
K_F15 = 106,
|
||||
K_F16 = 107,
|
||||
K_F17 = 108,
|
||||
K_F18 = 109,
|
||||
K_F19 = 110,
|
||||
K_F20 = 111,
|
||||
K_F21 = 112,
|
||||
K_F22 = 113,
|
||||
K_F23 = 114,
|
||||
K_F24 = 115,
|
||||
K_EXECUTE = 116,
|
||||
K_HELP = 117,
|
||||
K_MENU = 118,
|
||||
K_SELECT = 119,
|
||||
K_STOP = 120,
|
||||
K_AGAIN = 121, /**< redo */
|
||||
K_UNDO = 122,
|
||||
K_CUT = 123,
|
||||
K_COPY = 124,
|
||||
K_PASTE = 125,
|
||||
K_FIND = 126,
|
||||
K_MUTE = 127,
|
||||
K_VOLUMEUP = 128,
|
||||
K_VOLUMEDOWN = 129,
|
||||
/* not sure whether there's a reason to enable these */
|
||||
/* LOCKINGCAPSLOCK = 130, */
|
||||
/* LOCKINGNUMLOCK = 131, */
|
||||
/* LOCKINGSCROLLLOCK = 132, */
|
||||
K_KP_COMMA = 133,
|
||||
K_KP_EQUALSAS400 = 134,
|
||||
|
||||
K_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
|
||||
footnotes in USB doc */
|
||||
K_INTERNATIONAL2 = 136,
|
||||
K_INTERNATIONAL3 = 137, /**< Yen */
|
||||
K_INTERNATIONAL4 = 138,
|
||||
K_INTERNATIONAL5 = 139,
|
||||
K_INTERNATIONAL6 = 140,
|
||||
K_INTERNATIONAL7 = 141,
|
||||
K_INTERNATIONAL8 = 142,
|
||||
K_INTERNATIONAL9 = 143,
|
||||
K_LANG1 = 144, /**< Hangul/English toggle */
|
||||
K_LANG2 = 145, /**< Hanja conversion */
|
||||
K_LANG3 = 146, /**< Katakana */
|
||||
K_LANG4 = 147, /**< Hiragana */
|
||||
K_LANG5 = 148, /**< Zenkaku/Hankaku */
|
||||
K_LANG6 = 149, /**< reserved */
|
||||
K_LANG7 = 150, /**< reserved */
|
||||
K_LANG8 = 151, /**< reserved */
|
||||
K_LANG9 = 152, /**< reserved */
|
||||
K_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
|
||||
footnotes in USB doc */
|
||||
K_INTERNATIONAL2 = 136,
|
||||
K_INTERNATIONAL3 = 137, /**< Yen */
|
||||
K_INTERNATIONAL4 = 138,
|
||||
K_INTERNATIONAL5 = 139,
|
||||
K_INTERNATIONAL6 = 140,
|
||||
K_INTERNATIONAL7 = 141,
|
||||
K_INTERNATIONAL8 = 142,
|
||||
K_INTERNATIONAL9 = 143,
|
||||
K_LANG1 = 144, /**< Hangul/English toggle */
|
||||
K_LANG2 = 145, /**< Hanja conversion */
|
||||
K_LANG3 = 146, /**< Katakana */
|
||||
K_LANG4 = 147, /**< Hiragana */
|
||||
K_LANG5 = 148, /**< Zenkaku/Hankaku */
|
||||
K_LANG6 = 149, /**< reserved */
|
||||
K_LANG7 = 150, /**< reserved */
|
||||
K_LANG8 = 151, /**< reserved */
|
||||
K_LANG9 = 152, /**< reserved */
|
||||
|
||||
K_ALTERASE = 153, /**< Erase-Eaze */
|
||||
K_SYSREQ = 154,
|
||||
K_CANCEL = 155,
|
||||
K_CLEAR = 156,
|
||||
K_PRIOR = 157,
|
||||
K_RETURN2 = 158,
|
||||
K_SEPARATOR = 159,
|
||||
K_OUT = 160,
|
||||
K_OPER = 161,
|
||||
K_CLEARAGAIN = 162,
|
||||
K_CRSEL = 163,
|
||||
K_EXSEL = 164,
|
||||
K_ALTERASE = 153, /**< Erase-Eaze */
|
||||
K_SYSREQ = 154,
|
||||
K_CANCEL = 155,
|
||||
K_CLEAR = 156,
|
||||
K_PRIOR = 157,
|
||||
K_RETURN2 = 158,
|
||||
K_SEPARATOR = 159,
|
||||
K_OUT = 160,
|
||||
K_OPER = 161,
|
||||
K_CLEARAGAIN = 162,
|
||||
K_CRSEL = 163,
|
||||
K_EXSEL = 164,
|
||||
|
||||
K_KP_00 = 176,
|
||||
K_KP_000 = 177,
|
||||
K_THOUSANDSSEPARATOR = 178,
|
||||
K_DECIMALSEPARATOR = 179,
|
||||
K_CURRENCYUNIT = 180,
|
||||
K_CURRENCYSUBUNIT = 181,
|
||||
K_KP_LEFTPAREN = 182,
|
||||
K_KP_RIGHTPAREN = 183,
|
||||
K_KP_LEFTBRACE = 184,
|
||||
K_KP_RIGHTBRACE = 185,
|
||||
K_KP_TAB = 186,
|
||||
K_KP_BACKSPACE = 187,
|
||||
K_KP_A = 188,
|
||||
K_KP_B = 189,
|
||||
K_KP_C = 190,
|
||||
K_KP_D = 191,
|
||||
K_KP_E = 192,
|
||||
K_KP_F = 193,
|
||||
K_KP_XOR = 194,
|
||||
K_KP_POWER = 195,
|
||||
K_KP_PERCENT = 196,
|
||||
K_KP_LESS = 197,
|
||||
K_KP_GREATER = 198,
|
||||
K_KP_AMPERSAND = 199,
|
||||
K_KP_DBLAMPERSAND = 200,
|
||||
K_KP_VERTICALBAR = 201,
|
||||
K_KP_DBLVERTICALBAR = 202,
|
||||
K_KP_COLON = 203,
|
||||
K_KP_HASH = 204,
|
||||
K_KP_SPACE = 205,
|
||||
K_KP_AT = 206,
|
||||
K_KP_EXCLAM = 207,
|
||||
K_KP_MEMSTORE = 208,
|
||||
K_KP_MEMRECALL = 209,
|
||||
K_KP_MEMCLEAR = 210,
|
||||
K_KP_MEMADD = 211,
|
||||
K_KP_MEMSUBTRACT = 212,
|
||||
K_KP_MEMMULTIPLY = 213,
|
||||
K_KP_MEMDIVIDE = 214,
|
||||
K_KP_PLUSMINUS = 215,
|
||||
K_KP_CLEAR = 216,
|
||||
K_KP_CLEARENTRY = 217,
|
||||
K_KP_BINARY = 218,
|
||||
K_KP_OCTAL = 219,
|
||||
K_KP_DECIMAL = 220,
|
||||
K_KP_HEXADECIMAL = 221,
|
||||
K_KP_00 = 176,
|
||||
K_KP_000 = 177,
|
||||
K_THOUSANDSSEPARATOR = 178,
|
||||
K_DECIMALSEPARATOR = 179,
|
||||
K_CURRENCYUNIT = 180,
|
||||
K_CURRENCYSUBUNIT = 181,
|
||||
K_KP_LEFTPAREN = 182,
|
||||
K_KP_RIGHTPAREN = 183,
|
||||
K_KP_LEFTBRACE = 184,
|
||||
K_KP_RIGHTBRACE = 185,
|
||||
K_KP_TAB = 186,
|
||||
K_KP_BACKSPACE = 187,
|
||||
K_KP_A = 188,
|
||||
K_KP_B = 189,
|
||||
K_KP_C = 190,
|
||||
K_KP_D = 191,
|
||||
K_KP_E = 192,
|
||||
K_KP_F = 193,
|
||||
K_KP_XOR = 194,
|
||||
K_KP_POWER = 195,
|
||||
K_KP_PERCENT = 196,
|
||||
K_KP_LESS = 197,
|
||||
K_KP_GREATER = 198,
|
||||
K_KP_AMPERSAND = 199,
|
||||
K_KP_DBLAMPERSAND = 200,
|
||||
K_KP_VERTICALBAR = 201,
|
||||
K_KP_DBLVERTICALBAR = 202,
|
||||
K_KP_COLON = 203,
|
||||
K_KP_HASH = 204,
|
||||
K_KP_SPACE = 205,
|
||||
K_KP_AT = 206,
|
||||
K_KP_EXCLAM = 207,
|
||||
K_KP_MEMSTORE = 208,
|
||||
K_KP_MEMRECALL = 209,
|
||||
K_KP_MEMCLEAR = 210,
|
||||
K_KP_MEMADD = 211,
|
||||
K_KP_MEMSUBTRACT = 212,
|
||||
K_KP_MEMMULTIPLY = 213,
|
||||
K_KP_MEMDIVIDE = 214,
|
||||
K_KP_PLUSMINUS = 215,
|
||||
K_KP_CLEAR = 216,
|
||||
K_KP_CLEARENTRY = 217,
|
||||
K_KP_BINARY = 218,
|
||||
K_KP_OCTAL = 219,
|
||||
K_KP_DECIMAL = 220,
|
||||
K_KP_HEXADECIMAL = 221,
|
||||
|
||||
K_LCTRL = 224,
|
||||
K_LSHIFT = 225,
|
||||
K_LALT = 226, /**< alt, option */
|
||||
K_LGUI = 227, /**< windows, command (apple), meta */
|
||||
K_RCTRL = 228,
|
||||
K_RSHIFT = 229,
|
||||
K_RALT = 230, /**< alt gr, option */
|
||||
K_RGUI = 231, /**< windows, command (apple), meta */
|
||||
K_LCTRL = 224,
|
||||
K_LSHIFT = 225,
|
||||
K_LALT = 226, /**< alt, option */
|
||||
K_LGUI = 227, /**< windows, command (apple), meta */
|
||||
K_RCTRL = 228,
|
||||
K_RSHIFT = 229,
|
||||
K_RALT = 230, /**< alt gr, option */
|
||||
K_RGUI = 231, /**< windows, command (apple), meta */
|
||||
|
||||
K_MODE = 257, /**< I'm not sure if this is really not covered
|
||||
* by any of the above, but since there's a
|
||||
* special KMOD_MODE for it I'm adding it here
|
||||
*/
|
||||
K_MODE = 257, /**< I'm not sure if this is really not covered
|
||||
* by any of the above, but since there's a
|
||||
* special KMOD_MODE for it I'm adding it here
|
||||
*/
|
||||
|
||||
/* @} */ /* Usage page 0x07 */
|
||||
/* @} */ /* Usage page 0x07 */
|
||||
|
||||
/**
|
||||
* \name Usage page 0x0C
|
||||
*
|
||||
* These values are mapped from usage page 0x0C (USB consumer page).
|
||||
*/
|
||||
/* @{ */
|
||||
/**
|
||||
* \name Usage page 0x0C
|
||||
*
|
||||
* These values are mapped from usage page 0x0C (USB consumer page).
|
||||
*/
|
||||
/* @{ */
|
||||
|
||||
K_AUDIONEXT = 258,
|
||||
K_AUDIOPREV = 259,
|
||||
K_AUDIOSTOP = 260,
|
||||
K_AUDIOPLAY = 261,
|
||||
K_AUDIOMUTE = 262,
|
||||
K_MEDIASELECT = 263,
|
||||
K_WWW = 264,
|
||||
K_MAIL = 265,
|
||||
K_CALCULATOR = 266,
|
||||
K_COMPUTER = 267,
|
||||
K_AC_SEARCH = 268,
|
||||
K_AC_HOME = 269,
|
||||
K_AC_BACK = 270,
|
||||
K_AC_FORWARD = 271,
|
||||
K_AC_STOP = 272,
|
||||
K_AC_REFRESH = 273,
|
||||
K_AC_BOOKMARKS = 274,
|
||||
K_AUDIONEXT = 258,
|
||||
K_AUDIOPREV = 259,
|
||||
K_AUDIOSTOP = 260,
|
||||
K_AUDIOPLAY = 261,
|
||||
K_AUDIOMUTE = 262,
|
||||
K_MEDIASELECT = 263,
|
||||
K_WWW = 264,
|
||||
K_MAIL = 265,
|
||||
K_CALCULATOR = 266,
|
||||
K_COMPUTER = 267,
|
||||
K_AC_SEARCH = 268,
|
||||
K_AC_HOME = 269,
|
||||
K_AC_BACK = 270,
|
||||
K_AC_FORWARD = 271,
|
||||
K_AC_STOP = 272,
|
||||
K_AC_REFRESH = 273,
|
||||
K_AC_BOOKMARKS = 274,
|
||||
|
||||
/* @} */ /* Usage page 0x0C */
|
||||
/* @} */ /* Usage page 0x0C */
|
||||
|
||||
/**
|
||||
* \name Walther keys
|
||||
*
|
||||
* These are values that Christian Walther added (for mac keyboard?).
|
||||
*/
|
||||
/* @{ */
|
||||
/**
|
||||
* \name Walther keys
|
||||
*
|
||||
* These are values that Christian Walther added (for mac keyboard?).
|
||||
*/
|
||||
/* @{ */
|
||||
|
||||
K_BRIGHTNESSDOWN = 275,
|
||||
K_BRIGHTNESSUP = 276,
|
||||
K_DISPLAYSWITCH = 277, /**< display mirroring/dual display
|
||||
switch, video mode switch */
|
||||
K_KBDILLUMTOGGLE = 278,
|
||||
K_KBDILLUMDOWN = 279,
|
||||
K_KBDILLUMUP = 280,
|
||||
K_EJECT = 281,
|
||||
K_SLEEP = 282,
|
||||
K_BRIGHTNESSDOWN = 275,
|
||||
K_BRIGHTNESSUP = 276,
|
||||
K_DISPLAYSWITCH = 277, /**< display mirroring/dual display
|
||||
switch, video mode switch */
|
||||
K_KBDILLUMTOGGLE = 278,
|
||||
K_KBDILLUMDOWN = 279,
|
||||
K_KBDILLUMUP = 280,
|
||||
K_EJECT = 281,
|
||||
K_SLEEP = 282,
|
||||
|
||||
K_APP1 = 283,
|
||||
K_APP2 = 284,
|
||||
K_APP1 = 283,
|
||||
K_APP2 = 284,
|
||||
|
||||
/* @} */ /* Walther keys */
|
||||
/* @} */ /* Walther keys */
|
||||
|
||||
/**
|
||||
* \name Usage page 0x0C (additional media keys)
|
||||
*
|
||||
* These values are mapped from usage page 0x0C (USB consumer page).
|
||||
*/
|
||||
/* @{ */
|
||||
/**
|
||||
* \name Usage page 0x0C (additional media keys)
|
||||
*
|
||||
* These values are mapped from usage page 0x0C (USB consumer page).
|
||||
*/
|
||||
/* @{ */
|
||||
|
||||
K_AUDIOREWIND = 285,
|
||||
K_AUDIOFASTFORWARD = 286,
|
||||
K_AUDIOREWIND = 285,
|
||||
K_AUDIOFASTFORWARD = 286,
|
||||
|
||||
/* @} */ /* Usage page 0x0C (additional media keys) */
|
||||
/* @} */ /* Usage page 0x0C (additional media keys) */
|
||||
|
||||
/* Add any other keys here. */
|
||||
/* Add any other keys here. */
|
||||
|
||||
NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
|
||||
for array bounds */
|
||||
NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
|
||||
for array bounds */
|
||||
};
|
||||
|
||||
} // namespace inputs
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace inputs
|
||||
} // namespace engine
|
@ -1,22 +1,11 @@
|
||||
#ifndef ENGINE_INCLUDE_INPUTS_MOUSE_H_
|
||||
#define ENGINE_INCLUDE_INPUTS_MOUSE_H_
|
||||
#pragma once
|
||||
|
||||
namespace engine {
|
||||
namespace inputs {
|
||||
|
||||
enum class MouseButton : int {
|
||||
M_LEFT,
|
||||
M_MIDDLE,
|
||||
M_RIGHT,
|
||||
M_X1,
|
||||
M_X2,
|
||||
M_INVALID = 7,
|
||||
M_SIZE = 7
|
||||
};
|
||||
enum class MouseButton : int { M_LEFT, M_MIDDLE, M_RIGHT, M_X1, M_X2, M_INVALID = 7, M_SIZE = 7 };
|
||||
|
||||
enum class MouseAxis : int { X, Y, X_SCR, Y_SCR };
|
||||
|
||||
} // namespace inputs
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace inputs
|
||||
} // namespace engine
|
@ -1,11 +1,10 @@
|
||||
#ifndef ENGINE_INCLUDE_LOG_H_
|
||||
#define ENGINE_INCLUDE_LOG_H_
|
||||
#pragma once
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define SPDLOG_ACTIVE_LEVEL 2 // info, warn, error, critical
|
||||
//#define SPDLOG_ACTIVE_LEVEL 0 // trace, debug, info, warn, error, critical
|
||||
#define SPDLOG_ACTIVE_LEVEL 2 // info, warn, error, critical
|
||||
// #define SPDLOG_ACTIVE_LEVEL 0 // trace, debug, info, warn, error, critical
|
||||
#else
|
||||
#define SPDLOG_ACTIVE_LEVEL 0 // trace, debug, info, warn, error, critical
|
||||
#define SPDLOG_ACTIVE_LEVEL 0 // trace, debug, info, warn, error, critical
|
||||
#endif
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
@ -16,5 +15,3 @@
|
||||
#define LOG_WARN SPDLOG_WARN
|
||||
#define LOG_ERROR SPDLOG_ERROR
|
||||
#define LOG_CRITICAL SPDLOG_CRITICAL
|
||||
|
||||
#endif
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_LOGGER_H_
|
||||
#define ENGINE_INCLUDE_LOGGER_H_
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
@ -12,40 +11,36 @@
|
||||
namespace engine {
|
||||
|
||||
// To be executed in the target application, NOT engine.dll
|
||||
void SetupLog(const char* appName) {
|
||||
const std::string LOG_FILENAME{std::string(appName) + ".log"};
|
||||
void SetupLog(const char* appName)
|
||||
{
|
||||
const std::string LOG_FILENAME{std::string(appName) + ".log"};
|
||||
|
||||
#ifdef NDEBUG
|
||||
// RELEASE
|
||||
const std::filesystem::path log_path{std::filesystem::temp_directory_path() /
|
||||
LOG_FILENAME};
|
||||
// RELEASE
|
||||
const std::filesystem::path log_path{std::filesystem::temp_directory_path() / LOG_FILENAME};
|
||||
#else
|
||||
// DEBUG
|
||||
const std::filesystem::path log_path{LOG_FILENAME};
|
||||
// DEBUG
|
||||
const std::filesystem::path log_path{LOG_FILENAME};
|
||||
#endif
|
||||
|
||||
std::vector<spdlog::sink_ptr> sinks;
|
||||
std::vector<spdlog::sink_ptr> sinks;
|
||||
|
||||
sinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(
|
||||
log_path.string(), true));
|
||||
sinks.back()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
|
||||
sinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(log_path.string(), true));
|
||||
sinks.back()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
|
||||
|
||||
sinks.emplace_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
|
||||
sinks.back()->set_pattern("[%H:%M:%S.%e] [%l] %v");
|
||||
sinks.emplace_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
|
||||
sinks.back()->set_pattern("[%H:%M:%S.%e] [%l] %v");
|
||||
|
||||
auto logger =
|
||||
std::make_shared<spdlog::logger>(appName, sinks.begin(), sinks.end());
|
||||
auto logger = std::make_shared<spdlog::logger>(appName, sinks.begin(), sinks.end());
|
||||
|
||||
// Logs below INFO are ignored through macros in release (see log.hpp)
|
||||
logger->set_level(spdlog::level::trace);
|
||||
// Logs below INFO are ignored through macros in release (see log.hpp)
|
||||
logger->set_level(spdlog::level::trace);
|
||||
|
||||
spdlog::register_logger(logger);
|
||||
spdlog::set_default_logger(logger);
|
||||
spdlog::flush_every(std::chrono::seconds(60));
|
||||
spdlog::register_logger(logger);
|
||||
spdlog::set_default_logger(logger);
|
||||
spdlog::flush_every(std::chrono::seconds(60));
|
||||
|
||||
LOG_INFO("Created log with path: {}", log_path.string());
|
||||
LOG_INFO("Created log with path: {}", log_path.string());
|
||||
}
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_RENDERER_H_
|
||||
#define ENGINE_INCLUDE_RENDERER_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
@ -90,7 +89,7 @@ class Renderer : private ApplicationComponent {
|
||||
glm::mat4 lightSpaceMatrix;
|
||||
};
|
||||
UniformDescriptor<GlobalUniformData> global_uniform; // rarely updates; set 0 binding 0
|
||||
UniformDescriptor<glm::mat4> frame_uniform; // updates once per frame; set 1 binding 0
|
||||
UniformDescriptor<glm::mat4> frame_uniform; // updates once per frame; set 1 binding 0
|
||||
// in fragment shader
|
||||
const gfx::DescriptorSetLayout* material_set_layout; // set 2; set bound per material
|
||||
|
||||
@ -120,5 +119,3 @@ class Renderer : private ApplicationComponent {
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_RESOURCE_MANAGER_H_
|
||||
#define ENGINE_INCLUDE_RESOURCE_MANAGER_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
@ -15,52 +14,49 @@
|
||||
namespace engine {
|
||||
|
||||
class IResourceManager {
|
||||
public:
|
||||
virtual ~IResourceManager(){};
|
||||
public:
|
||||
virtual ~IResourceManager(){};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class ResourceManager : public IResourceManager {
|
||||
public:
|
||||
~ResourceManager() override {
|
||||
LOG_DEBUG("Destroying resource manager... '{}'", typeid(T).name());
|
||||
}
|
||||
public:
|
||||
~ResourceManager() override { LOG_DEBUG("Destroying resource manager... '{}'", typeid(T).name()); }
|
||||
|
||||
std::shared_ptr<T> Add(const std::string& name,
|
||||
std::unique_ptr<T>&& resource) {
|
||||
if (resources_.contains(name) == false) {
|
||||
std::shared_ptr<T> resource_shared(std::move(resource));
|
||||
resources_.emplace(name, resource_shared);
|
||||
return resource_shared;
|
||||
} else {
|
||||
throw std::runtime_error("Cannot add a resource which already exists");
|
||||
std::shared_ptr<T> Add(const std::string& name, std::unique_ptr<T>&& resource)
|
||||
{
|
||||
if (resources_.contains(name) == false) {
|
||||
std::shared_ptr<T> resource_shared(std::move(resource));
|
||||
resources_.emplace(name, resource_shared);
|
||||
return resource_shared;
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Cannot add a resource which already exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddPersistent(const std::string& name, std::unique_ptr<T>&& resource) {
|
||||
persistent_resources_.push_back(Add(name, std::move(resource)));
|
||||
}
|
||||
void AddPersistent(const std::string& name, std::unique_ptr<T>&& resource) { persistent_resources_.push_back(Add(name, std::move(resource))); }
|
||||
|
||||
std::shared_ptr<T> Get(const std::string& name) {
|
||||
if (resources_.contains(name)) {
|
||||
std::weak_ptr<T> ptr = resources_.at(name);
|
||||
if (ptr.expired() == false) {
|
||||
return ptr.lock();
|
||||
} else {
|
||||
resources_.erase(name);
|
||||
}
|
||||
std::shared_ptr<T> Get(const std::string& name)
|
||||
{
|
||||
if (resources_.contains(name)) {
|
||||
std::weak_ptr<T> ptr = resources_.at(name);
|
||||
if (ptr.expired() == false) {
|
||||
return ptr.lock();
|
||||
}
|
||||
else {
|
||||
resources_.erase(name);
|
||||
}
|
||||
}
|
||||
// resource doesn't exist:
|
||||
throw std::runtime_error("Resource doesn't exist: " + name);
|
||||
return {};
|
||||
}
|
||||
// resource doesn't exist:
|
||||
throw std::runtime_error("Resource doesn't exist: " + name);
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::weak_ptr<T>> resources_{};
|
||||
// This array owns persistent resources
|
||||
std::vector<std::shared_ptr<T>> persistent_resources_{};
|
||||
private:
|
||||
std::unordered_map<std::string, std::weak_ptr<T>> resources_{};
|
||||
// This array owns persistent resources
|
||||
std::vector<std::shared_ptr<T>> persistent_resources_{};
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_FONT_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_FONT_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
@ -11,25 +10,20 @@
|
||||
namespace engine {
|
||||
|
||||
class Font {
|
||||
public:
|
||||
Font(const std::string& path);
|
||||
~Font();
|
||||
Font(const Font&) = delete;
|
||||
Font& operator=(const Font&) = delete;
|
||||
public:
|
||||
Font(const std::string& path);
|
||||
~Font();
|
||||
Font(const Font&) = delete;
|
||||
Font& operator=(const Font&) = delete;
|
||||
|
||||
std::unique_ptr<std::vector<uint8_t>> GetTextBitmap(const std::string& text,
|
||||
float height_px,
|
||||
int& width_out,
|
||||
int& height_out);
|
||||
std::unique_ptr<std::vector<uint8_t>> GetTextBitmap(const std::string& text, float height_px, int& width_out, int& height_out);
|
||||
|
||||
private:
|
||||
std::unique_ptr<stbtt_fontinfo> font_info_{};
|
||||
std::unique_ptr<std::vector<uint8_t>> font_buffer_{};
|
||||
std::map<int, int> unicode_to_glyph_{};
|
||||
private:
|
||||
std::unique_ptr<stbtt_fontinfo> font_info_{};
|
||||
std::unique_ptr<std::vector<uint8_t>> font_buffer_{};
|
||||
std::map<int, int> unicode_to_glyph_{};
|
||||
|
||||
int GetGlyphIndex(int unicode_codepoint);
|
||||
int GetGlyphIndex(int unicode_codepoint);
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_MATERIAL_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_MATERIAL_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -36,5 +35,3 @@ class Material {
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,6 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
@ -47,5 +45,3 @@ class Mesh {
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -7,38 +7,37 @@
|
||||
namespace engine {
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
// defines what vertex inputs are defined, position is always vec3
|
||||
struct VertexParams {
|
||||
bool has_normal; // vec3
|
||||
bool has_tangent; // vec3
|
||||
bool has_color; // vec3
|
||||
bool has_uv0; // vec2
|
||||
};
|
||||
public:
|
||||
// defines what vertex inputs are defined, position is always vec3
|
||||
struct VertexParams {
|
||||
bool has_normal; // vec3
|
||||
bool has_tangent; // vec3
|
||||
bool has_color; // vec3
|
||||
bool has_uv0; // vec2
|
||||
};
|
||||
|
||||
struct ShaderSettings {
|
||||
VertexParams vertexParams;
|
||||
bool alpha_blending;
|
||||
bool cull_backface;
|
||||
bool write_z;
|
||||
int render_order;
|
||||
};
|
||||
struct ShaderSettings {
|
||||
VertexParams vertexParams;
|
||||
bool alpha_blending;
|
||||
bool cull_backface;
|
||||
bool write_z;
|
||||
int render_order;
|
||||
};
|
||||
|
||||
static constexpr int kHighestRenderOrder = 1;
|
||||
static constexpr int kHighestRenderOrder = 1;
|
||||
|
||||
Shader(Renderer* renderer, const std::string& vert_path, const std::string& frag_path,
|
||||
const ShaderSettings& settings);
|
||||
~Shader();
|
||||
Shader(const Shader&) = delete;
|
||||
Shader& operator=(const Shader&) = delete;
|
||||
Shader(Renderer* renderer, const std::string& vert_path, const std::string& frag_path, const ShaderSettings& settings);
|
||||
~Shader();
|
||||
Shader(const Shader&) = delete;
|
||||
Shader& operator=(const Shader&) = delete;
|
||||
|
||||
const gfx::Pipeline* GetPipeline();
|
||||
int GetRenderOrder() { return render_order_; }
|
||||
const gfx::Pipeline* GetPipeline();
|
||||
int GetRenderOrder() { return render_order_; }
|
||||
|
||||
private:
|
||||
GFXDevice* const gfx_;
|
||||
const gfx::Pipeline* pipeline_;
|
||||
const int render_order_;
|
||||
private:
|
||||
GFXDevice* const gfx_;
|
||||
const gfx::Pipeline* pipeline_;
|
||||
const int render_order_;
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_TEXTURE_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_TEXTURE_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -10,7 +9,6 @@ namespace engine {
|
||||
|
||||
class Texture {
|
||||
public:
|
||||
|
||||
Texture(Renderer* renderer, const uint8_t* bitmap, int width, int height, gfx::SamplerInfo samplerInfo, bool srgb);
|
||||
|
||||
~Texture();
|
||||
@ -29,5 +27,3 @@ class Texture {
|
||||
std::unique_ptr<Texture> LoadTextureFromFile(const std::string& path, gfx::SamplerInfo samplerInfo, Renderer* renderer, bool srgb = true);
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_SCENE_H_
|
||||
#define ENGINE_INCLUDE_SCENE_H_
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
@ -70,21 +69,13 @@ class Scene {
|
||||
}
|
||||
|
||||
// because GetComponent<Transformzzzzzz takes too long
|
||||
TransformComponent* GetTransform(Entity entity) {
|
||||
return GetComponent<TransformComponent>(entity);
|
||||
}
|
||||
TransformComponent* GetTransform(Entity entity) { return GetComponent<TransformComponent>(entity); }
|
||||
|
||||
glm::vec3& GetPosition(Entity entity) {
|
||||
return GetTransform(entity)->position;
|
||||
}
|
||||
glm::vec3& GetPosition(Entity entity) { return GetTransform(entity)->position; }
|
||||
|
||||
glm::quat& GetRotation(Entity entity) {
|
||||
return GetTransform(entity)->rotation;
|
||||
}
|
||||
glm::quat& GetRotation(Entity entity) { return GetTransform(entity)->rotation; }
|
||||
|
||||
glm::vec3& GetScale(Entity entity) {
|
||||
return GetTransform(entity)->scale;
|
||||
}
|
||||
glm::vec3& GetScale(Entity entity) { return GetTransform(entity)->scale; }
|
||||
|
||||
template <typename T>
|
||||
T* AddComponent(Entity entity, const T& comp = T{})
|
||||
@ -174,5 +165,3 @@ class Scene {
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_SCENE_MANAGER_H_
|
||||
#define ENGINE_INCLUDE_SCENE_MANAGER_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@ -57,5 +56,3 @@ class SceneManager {
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_
|
||||
#define ENGINE_INCLUDE_SYSTEMS_COLLISIONS_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
@ -75,5 +74,3 @@ class CollisionSystem : public System {
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_CUSTOM_BEHAVIOUR_H_
|
||||
#define ENGINE_INCLUDE_CUSTOM_BEHAVIOUR_H_
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
@ -11,17 +10,15 @@
|
||||
namespace engine {
|
||||
|
||||
class CustomBehaviourSystem : public System {
|
||||
public:
|
||||
CustomBehaviourSystem(Scene* scene);
|
||||
~CustomBehaviourSystem();
|
||||
public:
|
||||
CustomBehaviourSystem(Scene* scene);
|
||||
~CustomBehaviourSystem();
|
||||
|
||||
void OnUpdate(float ts) override;
|
||||
void OnComponentInsert(Entity entity) override;
|
||||
void OnUpdate(float ts) override;
|
||||
void OnComponentInsert(Entity entity) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<Entity, bool> entity_is_initialised_{};
|
||||
private:
|
||||
std::unordered_map<Entity, bool> entity_is_initialised_{};
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -9,37 +9,36 @@
|
||||
namespace engine {
|
||||
|
||||
struct RenderListEntry {
|
||||
const gfx::Pipeline* pipeline;
|
||||
const gfx::Buffer* vertex_buffer;
|
||||
const gfx::Buffer* index_buffer;
|
||||
const gfx::DescriptorSet* material_set;
|
||||
glm::mat4 model_matrix;
|
||||
uint32_t index_count;
|
||||
const gfx::Pipeline* pipeline;
|
||||
const gfx::Buffer* vertex_buffer;
|
||||
const gfx::Buffer* index_buffer;
|
||||
const gfx::DescriptorSet* material_set;
|
||||
glm::mat4 model_matrix;
|
||||
uint32_t index_count;
|
||||
};
|
||||
|
||||
using RenderList = std::vector<RenderListEntry>;
|
||||
|
||||
class MeshRenderSystem : public System {
|
||||
public:
|
||||
MeshRenderSystem(Scene* scene);
|
||||
~MeshRenderSystem();
|
||||
public:
|
||||
MeshRenderSystem(Scene* scene);
|
||||
~MeshRenderSystem();
|
||||
|
||||
void RebuildStaticRenderList();
|
||||
const RenderList* GetStaticRenderList() const { return &static_render_list_; }
|
||||
const RenderList* GetDynamicRenderList() const { return &dynamic_render_list_; }
|
||||
void RebuildStaticRenderList();
|
||||
const RenderList* GetStaticRenderList() const { return &static_render_list_; }
|
||||
const RenderList* GetDynamicRenderList() const { return &dynamic_render_list_; }
|
||||
|
||||
void OnComponentInsert(Entity entity) override;
|
||||
void OnUpdate(float ts) override;
|
||||
void OnComponentInsert(Entity entity) override;
|
||||
void OnUpdate(float ts) override;
|
||||
|
||||
private:
|
||||
RenderList static_render_list_;
|
||||
RenderList dynamic_render_list_;
|
||||
bool list_needs_rebuild_ = false;
|
||||
|
||||
// with_static_entities = false, build list of dynamic meshes
|
||||
// with_static_entities = true, build list of static meshes
|
||||
void BuildRenderList(RenderList& render_list, bool with_static_entities);
|
||||
private:
|
||||
RenderList static_render_list_;
|
||||
RenderList dynamic_render_list_;
|
||||
bool list_needs_rebuild_ = false;
|
||||
|
||||
// with_static_entities = false, build list of dynamic meshes
|
||||
// with_static_entities = true, build list of static meshes
|
||||
void BuildRenderList(RenderList& render_list, bool with_static_entities);
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_
|
||||
#define ENGINE_INCLUDE_SYSTEMS_TRANSFORM_H_
|
||||
#pragma once
|
||||
|
||||
#include "ecs.h"
|
||||
|
||||
@ -20,5 +19,3 @@ class TransformSystem : public System {
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -8,16 +8,15 @@
|
||||
|
||||
namespace engine {
|
||||
|
||||
class UIRenderSystem : public System {
|
||||
public:
|
||||
UIRenderSystem(Scene* scene);
|
||||
~UIRenderSystem();
|
||||
class UIRenderSystem : public System {
|
||||
public:
|
||||
UIRenderSystem(Scene* scene);
|
||||
~UIRenderSystem();
|
||||
|
||||
void OnComponentInsert(Entity entity) override;
|
||||
void OnUpdate(float ts) override;
|
||||
void OnComponentInsert(Entity entity) override;
|
||||
void OnUpdate(float ts) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
} // namespace engine
|
||||
|
@ -1,22 +1,20 @@
|
||||
#ifndef ENGINE_INCLUDE_UTIL_H_
|
||||
#define ENGINE_INCLUDE_UTIL_H_
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace engine {
|
||||
|
||||
inline bool VersionFromCharArray(const char* version, int* major, int* minor,
|
||||
int* patch) {
|
||||
if (sscanf(version, "%d.%d.%d", major, minor, patch) != 3) {
|
||||
*major = 0;
|
||||
*minor = 0;
|
||||
*patch = 0;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
inline bool VersionFromCharArray(const char* version, int* major, int* minor, int* patch)
|
||||
{
|
||||
if (sscanf(version, "%d.%d.%d", major, minor, patch) != 3) {
|
||||
*major = 0;
|
||||
*minor = 0;
|
||||
*patch = 0;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_UTIL_FILES_H_
|
||||
#define ENGINE_INCLUDE_UTIL_FILES_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -13,10 +12,7 @@ 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);
|
||||
std::unique_ptr<std::vector<uint8_t>> ReadImageFile(const std::string& path, int& width, int& height);
|
||||
|
||||
} // namespace util
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace util
|
||||
} // namespace engine
|
@ -17,4 +17,4 @@ namespace engine::util {
|
||||
*/
|
||||
engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic = false);
|
||||
|
||||
}
|
||||
} // namespace engine::util
|
272
include/window.h
272
include/window.h
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_INCLUDE_WINDOW_H_
|
||||
#define ENGINE_INCLUDE_WINDOW_H_
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
@ -13,180 +12,177 @@
|
||||
namespace engine {
|
||||
|
||||
class Window {
|
||||
public:
|
||||
Window(const std::string& title, bool resizable = true,
|
||||
bool fullscreen = true);
|
||||
Window(const Window&) = delete;
|
||||
Window& operator=(const Window&) = delete;
|
||||
~Window();
|
||||
public:
|
||||
Window(const std::string& title, bool resizable = true, bool fullscreen = true);
|
||||
Window(const Window&) = delete;
|
||||
Window& operator=(const Window&) = delete;
|
||||
~Window();
|
||||
|
||||
SDL_Window* GetHandle() const;
|
||||
SDL_Window* GetHandle() const;
|
||||
|
||||
// Return the title name
|
||||
std::string GetTitle() const;
|
||||
// Return the title name
|
||||
std::string GetTitle() const;
|
||||
|
||||
// Update the window state to capture any events that have occurred.
|
||||
// Run this on every frame.
|
||||
void GetInputAndEvents();
|
||||
// Update the window state to capture any events that have occurred.
|
||||
// Run this on every frame.
|
||||
void GetInputAndEvents();
|
||||
|
||||
void SetTitle(std::string title);
|
||||
void SetTitle(std::string title);
|
||||
|
||||
// Hides the window (it will appear closed to the user).
|
||||
void Hide();
|
||||
// Shows the window again.
|
||||
void Show();
|
||||
// Raises the window above other windows and sets the input focus
|
||||
void Focus();
|
||||
// Returns true if the window has focus
|
||||
bool HasFocus() const;
|
||||
// Hides the window (it will appear closed to the user).
|
||||
void Hide();
|
||||
// Shows the window again.
|
||||
void Show();
|
||||
// Raises the window above other windows and sets the input focus
|
||||
void Focus();
|
||||
// Returns true if the window has focus
|
||||
bool HasFocus() const;
|
||||
|
||||
// Sets the close flag, check this with shouldClose()
|
||||
void SetCloseFlag();
|
||||
// Returns true if the window should remain open
|
||||
bool IsRunning() const;
|
||||
// Sets the close flag, check this with shouldClose()
|
||||
void SetCloseFlag();
|
||||
// Returns true if the window should remain open
|
||||
bool IsRunning() const;
|
||||
|
||||
void SetFullscreen(bool fullscreen, bool exclusive = false);
|
||||
void ToggleFullscreen();
|
||||
void SetFullscreen(bool fullscreen, bool exclusive = false);
|
||||
void ToggleFullscreen();
|
||||
|
||||
bool IsFullscreen() const;
|
||||
bool IsFullscreen() const;
|
||||
|
||||
// Relative mouse mode captures the cursor for FPS style use.
|
||||
// Returns false if unsupported.
|
||||
bool SetRelativeMouseMode(bool enabled);
|
||||
// Relative mouse mode captures the cursor for FPS style use.
|
||||
// Returns false if unsupported.
|
||||
bool SetRelativeMouseMode(bool enabled);
|
||||
|
||||
// returns true if relative mouse mode is enabled
|
||||
bool MouseCaptured();
|
||||
// returns true if relative mouse mode is enabled
|
||||
bool MouseCaptured();
|
||||
|
||||
// window events
|
||||
// window events
|
||||
|
||||
// Returns true if the window was just resized during the previous frame
|
||||
bool GetWindowResized() const;
|
||||
// Set the window resized flag (to recalculate aspect ratios and such)
|
||||
void SetResizedFlag();
|
||||
// Returns true if the window was just resized during the previous frame
|
||||
bool GetWindowResized() const;
|
||||
// Set the window resized flag (to recalculate aspect ratios and such)
|
||||
void SetResizedFlag();
|
||||
|
||||
// keyboard events
|
||||
// keyboard events
|
||||
|
||||
// returns true if key is down
|
||||
bool GetKey(inputs::Key key) const;
|
||||
// returns true if key was just pressed
|
||||
bool GetKeyPress(inputs::Key key) const;
|
||||
// returns true if key was just released
|
||||
bool GetKeyRelease(inputs::Key key) const;
|
||||
// returns true if key is down
|
||||
bool GetKey(inputs::Key key) const;
|
||||
// returns true if key was just pressed
|
||||
bool GetKeyPress(inputs::Key key) const;
|
||||
// returns true if key was just released
|
||||
bool GetKeyRelease(inputs::Key key) const;
|
||||
|
||||
// mouse events
|
||||
// mouse events
|
||||
|
||||
// returns true if button is down
|
||||
bool GetButton(inputs::MouseButton button) const;
|
||||
// returns true if button was just pressed
|
||||
bool GetButtonPress(inputs::MouseButton button) const;
|
||||
// returns true if button was just released
|
||||
bool GetButtonRelease(inputs::MouseButton button) const;
|
||||
// returns true if button is down
|
||||
bool GetButton(inputs::MouseButton button) const;
|
||||
// returns true if button was just pressed
|
||||
bool GetButtonPress(inputs::MouseButton button) const;
|
||||
// returns true if button was just released
|
||||
bool GetButtonRelease(inputs::MouseButton button) const;
|
||||
|
||||
// retrieves x coordinate of the mouse
|
||||
int GetMouseX() const;
|
||||
// retrieves y coordinate of the mouse
|
||||
int GetMouseY() const;
|
||||
// retrieves mouse x coordinate normalised for OpenGL
|
||||
float GetMouseNormX() const;
|
||||
// retrieves mouse y coordinate normalised for OpenGL
|
||||
float GetMouseNormY() const;
|
||||
// retrieves dx of the mouse since the last frame
|
||||
int GetMouseDX() const;
|
||||
// retrieves dy of the mouse since the last frame
|
||||
int GetMouseDY() const;
|
||||
// retrieves amount scrolled vertically
|
||||
float GetMouseScrollX() const;
|
||||
// retrieves amount scrolled horizontally
|
||||
float GetMouseScrollY() const;
|
||||
// retrieves x coordinate of the mouse
|
||||
int GetMouseX() const;
|
||||
// retrieves y coordinate of the mouse
|
||||
int GetMouseY() const;
|
||||
// retrieves mouse x coordinate normalised for OpenGL
|
||||
float GetMouseNormX() const;
|
||||
// retrieves mouse y coordinate normalised for OpenGL
|
||||
float GetMouseNormY() const;
|
||||
// retrieves dx of the mouse since the last frame
|
||||
int GetMouseDX() const;
|
||||
// retrieves dy of the mouse since the last frame
|
||||
int GetMouseDY() const;
|
||||
// retrieves amount scrolled vertically
|
||||
float GetMouseScrollX() const;
|
||||
// retrieves amount scrolled horizontally
|
||||
float GetMouseScrollY() const;
|
||||
|
||||
// joystick/gamepad events (maybe), other misc events
|
||||
// joystick/gamepad events (maybe), other misc events
|
||||
|
||||
// returns the performance counter value in nanoseconds;
|
||||
uint64_t GetNanos() const;
|
||||
// get the time recorded at the end of the last frame
|
||||
uint64_t GetLastFrameStamp() const;
|
||||
// returns the performance counter value in nanoseconds;
|
||||
uint64_t GetNanos() const;
|
||||
// get the time recorded at the end of the last frame
|
||||
uint64_t GetLastFrameStamp() const;
|
||||
|
||||
// returns the number of frames elapsed since window creation
|
||||
uint64_t GetFrameCount() const;
|
||||
uint64_t GetStartTime() const;
|
||||
float dt() const; // returns delta time in seconds
|
||||
uint64_t GetFPS() const;
|
||||
uint64_t GetAvgFPS() const;
|
||||
// returns the number of frames elapsed since window creation
|
||||
uint64_t GetFrameCount() const;
|
||||
uint64_t GetStartTime() const;
|
||||
float dt() const; // returns delta time in seconds
|
||||
uint64_t GetFPS() const;
|
||||
uint64_t GetAvgFPS() const;
|
||||
|
||||
void ResetAvgFPS();
|
||||
void ResetAvgFPS();
|
||||
|
||||
bool InfoBox(const std::string& title, const std::string& msg);
|
||||
bool InfoBox(const std::string& title, const std::string& msg);
|
||||
|
||||
/* STATIC METHODS */
|
||||
static void ErrorBox(const std::string& message);
|
||||
/* STATIC METHODS */
|
||||
static void ErrorBox(const std::string& message);
|
||||
|
||||
private:
|
||||
SDL_Window* handle_;
|
||||
private:
|
||||
SDL_Window* handle_;
|
||||
|
||||
bool should_close_ = false;
|
||||
bool should_close_ = false;
|
||||
|
||||
std::string title_;
|
||||
std::string title_;
|
||||
|
||||
bool resizable_;
|
||||
bool resizable_;
|
||||
|
||||
bool fullscreen_ = false;
|
||||
bool just_resized_ = false;
|
||||
bool keyboard_focus_ = true;
|
||||
bool fullscreen_ = false;
|
||||
bool just_resized_ = false;
|
||||
bool keyboard_focus_ = true;
|
||||
|
||||
// size in screen coordinates
|
||||
glm::ivec2 win_size_ = glm::vec2(1024, 768);
|
||||
// size in screen coordinates
|
||||
glm::ivec2 win_size_ = glm::vec2(1024, 768);
|
||||
|
||||
// performance counter frequency
|
||||
uint64_t counter_freq_;
|
||||
// performance counter frequency
|
||||
uint64_t counter_freq_;
|
||||
|
||||
// number of frames swapped
|
||||
uint64_t frames_ = 0;
|
||||
// frame count offset for fpsAvg
|
||||
uint64_t avg_fps_start_count_ = 0;
|
||||
// in nanoseconds
|
||||
uint64_t start_time_;
|
||||
// in nanoseconds
|
||||
uint64_t last_frame_stamp_;
|
||||
// in nanoseconds; elapsed time between frames
|
||||
uint64_t last_frame_time_ = 1; // not 0 to avoid division by zero
|
||||
// in nanoseconds
|
||||
uint64_t avg_fps_start_;
|
||||
// number of frames swapped
|
||||
uint64_t frames_ = 0;
|
||||
// frame count offset for fpsAvg
|
||||
uint64_t avg_fps_start_count_ = 0;
|
||||
// in nanoseconds
|
||||
uint64_t start_time_;
|
||||
// in nanoseconds
|
||||
uint64_t last_frame_stamp_;
|
||||
// in nanoseconds; elapsed time between frames
|
||||
uint64_t last_frame_time_ = 1; // not 0 to avoid division by zero
|
||||
// in nanoseconds
|
||||
uint64_t avg_fps_start_;
|
||||
|
||||
// input stuff
|
||||
// input stuff
|
||||
|
||||
enum class ButtonDelta { kSame = 0, kPressed, kReleased };
|
||||
enum class ButtonDelta { kSame = 0, kPressed, kReleased };
|
||||
|
||||
struct {
|
||||
std::array<bool, SDL_NUM_SCANCODES> keys;
|
||||
std::array<enum ButtonDelta, SDL_NUM_SCANCODES> deltas;
|
||||
} keyboard_{};
|
||||
struct {
|
||||
std::array<bool, SDL_NUM_SCANCODES> keys;
|
||||
std::array<enum ButtonDelta, SDL_NUM_SCANCODES> deltas;
|
||||
} keyboard_{};
|
||||
|
||||
struct {
|
||||
std::array<bool, static_cast<int>(inputs::MouseButton::M_SIZE)> buttons;
|
||||
std::array<enum ButtonDelta, 8> deltas;
|
||||
Sint32 x;
|
||||
Sint32 y;
|
||||
Sint32 dx;
|
||||
Sint32 dy;
|
||||
float xscroll;
|
||||
float yscroll;
|
||||
bool captured = false;
|
||||
} mouse_{};
|
||||
struct {
|
||||
std::array<bool, static_cast<int>(inputs::MouseButton::M_SIZE)> buttons;
|
||||
std::array<enum ButtonDelta, 8> deltas;
|
||||
Sint32 x;
|
||||
Sint32 y;
|
||||
Sint32 dx;
|
||||
Sint32 dy;
|
||||
float xscroll;
|
||||
float yscroll;
|
||||
bool captured = false;
|
||||
} mouse_{};
|
||||
|
||||
// private methods
|
||||
// private methods
|
||||
|
||||
void OnResize(Sint32 width, Sint32 height);
|
||||
void ResetInputDeltas();
|
||||
void OnResize(Sint32 width, Sint32 height);
|
||||
void ResetInputDeltas();
|
||||
|
||||
// event methods (like callbacks)
|
||||
// event methods (like callbacks)
|
||||
|
||||
void OnWindowEvent(SDL_WindowEvent& e);
|
||||
void OnKeyEvent(SDL_KeyboardEvent& e);
|
||||
void OnMouseButtonEvent(SDL_MouseButtonEvent& e);
|
||||
void OnMouseMotionEvent(SDL_MouseMotionEvent& e);
|
||||
void OnMouseWheelEvent(SDL_MouseWheelEvent& e);
|
||||
void OnWindowEvent(SDL_WindowEvent& e);
|
||||
void OnKeyEvent(SDL_KeyboardEvent& e);
|
||||
void OnMouseButtonEvent(SDL_MouseButtonEvent& e);
|
||||
void OnMouseMotionEvent(SDL_MouseMotionEvent& e);
|
||||
void OnMouseWheelEvent(SDL_MouseWheelEvent& e);
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
||||
} // namespace engine
|
@ -49,7 +49,7 @@ float InterleavedGradientNoise(vec2 position_screen)
|
||||
void main() {
|
||||
|
||||
const vec4 albedo_alpha = texture(materialSetAlbedoSampler, fragUV);
|
||||
if (albedo_alpha.a < 0.9) discard; // discard fragments without alpha = 1.0
|
||||
if (albedo_alpha.a < 0.9) discard;
|
||||
const vec3 albedo = albedo_alpha.xyz;
|
||||
|
||||
const vec3 occlusion_roughness_metallic = vec3(texture(materialSetOcclusionRoughnessMetallic, fragUV));
|
||||
|
@ -1,13 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 2, binding = 0) uniform sampler2D materialSetSampler;
|
||||
|
||||
layout(location = 0) in vec2 fragUV;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
|
||||
outColor = texture(materialSetSampler, fragUV);
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform GlobalSetUniformBuffer {
|
||||
mat4 proj;
|
||||
} globalSetUniformBuffer;
|
||||
|
||||
layout(set = 1, binding = 0) uniform FrameSetUniformBuffer {
|
||||
mat4 view;
|
||||
} frameSetUniformBuffer;
|
||||
|
||||
layout( push_constant ) uniform Constants {
|
||||
mat4 model;
|
||||
} constants;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inNorm;
|
||||
layout(location = 2) in vec4 inTangent;
|
||||
layout(location = 3) in vec2 inUV;
|
||||
|
||||
layout(location = 0) out vec2 fragUV;
|
||||
|
||||
vec2 positions[6] = vec2[](
|
||||
vec2( 1.0, 1.0),
|
||||
vec2(-1.0, 1.0),
|
||||
vec2(-1.0, -1.0),
|
||||
vec2( 1.0, 1.0),
|
||||
vec2(-1.0, -1.0),
|
||||
vec2( 1.0, -1.0)
|
||||
);
|
||||
|
||||
vec2 uvs[6] = vec2[](
|
||||
vec2(1.0, 0.0),
|
||||
vec2(0.0, 0.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(1.0, 0.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(1.0, 1.0)
|
||||
);
|
||||
|
||||
void main() {
|
||||
gl_Position = constants.model * vec4(positions[gl_VertexIndex], 0.0, 1.0);
|
||||
fragUV = uvs[gl_VertexIndex];
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 2, binding = 0) uniform sampler2D materialSetAlbedoSampler;
|
||||
layout(set = 2, binding = 1) uniform sampler2D materialSetNormalSampler;
|
||||
layout(set = 2, binding = 2) uniform sampler2D materialSetOcclusionSampler;
|
||||
layout(set = 2, binding = 3) uniform sampler2D materialSetMetallicRoughnessSampler;
|
||||
|
||||
layout(location = 0) in vec2 fragUV;
|
||||
layout(location = 1) in vec3 fragPosTangentSpace;
|
||||
layout(location = 2) in vec3 fragViewPosTangentSpace;
|
||||
layout(location = 3) in vec3 fragLightPosTangentSpace;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 norm = vec3(texture(materialSetNormalSampler, fragUV));
|
||||
//norm.y = 1.0 - norm.y;
|
||||
norm = normalize(norm * 2.0 - 1.0);
|
||||
norm.b = 0.0;
|
||||
norm *= 100.0;
|
||||
norm = clamp(norm, 0.0, 1.0);
|
||||
outColor = vec4(norm, 1.0);
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform GlobalSetUniformBuffer {
|
||||
mat4 proj;
|
||||
} globalSetUniformBuffer;
|
||||
|
||||
layout(set = 1, binding = 0) uniform FrameSetUniformBuffer {
|
||||
mat4 view;
|
||||
} frameSetUniformBuffer;
|
||||
|
||||
layout( push_constant ) uniform Constants {
|
||||
mat4 model;
|
||||
} constants;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inNorm;
|
||||
layout(location = 2) in vec4 inTangent;
|
||||
layout(location = 3) in vec2 inUV;
|
||||
|
||||
layout(location = 0) out vec2 fragUV;
|
||||
layout(location = 1) out vec3 fragPosTangentSpace;
|
||||
layout(location = 2) out vec3 fragViewPosTangentSpace;
|
||||
layout(location = 3) out vec3 fragLightPosTangentSpace;
|
||||
|
||||
void main() {
|
||||
vec4 worldPosition = constants.model * vec4(inPosition, 1.0);
|
||||
gl_Position = globalSetUniformBuffer.proj * frameSetUniformBuffer.view * worldPosition;
|
||||
|
||||
vec3 T = normalize(vec3(constants.model * vec4(inTangent.xyz, 0.0)));
|
||||
vec3 N = normalize(vec3(constants.model * vec4(inNorm, 0.0)));
|
||||
vec3 B = cross(T, N) * inTangent.w;
|
||||
mat3 worldToTangentSpace = transpose(mat3(T, B, N));
|
||||
|
||||
fragUV = inUV;
|
||||
fragPosTangentSpace = worldToTangentSpace * vec3(worldPosition);
|
||||
fragViewPosTangentSpace = worldToTangentSpace * vec3(inverse(frameSetUniformBuffer.view) * vec4(0.0, 0.0, 0.0, 1.0));
|
||||
fragLightPosTangentSpace = worldToTangentSpace * vec3(59000.0, 0000.0, 10000.0);
|
||||
|
||||
gl_Position.y *= -1.0;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 fragUV;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
vec3 baseColor = vec3(fragUV, 0.0);
|
||||
outColor = vec4(baseColor, 1.0);
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout( push_constant ) uniform Constants {
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
} constants;
|
||||
|
||||
layout(set = 0, binding = 0) uniform SetZeroBuffer {
|
||||
mat4 proj;
|
||||
vec2 myValue;
|
||||
} setZeroBuffer;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inNorm;
|
||||
layout(location = 2) in vec4 inTangent;
|
||||
layout(location = 3) in vec2 inUV;
|
||||
|
||||
layout(location = 0) out vec2 fragUV;
|
||||
|
||||
void main() {
|
||||
gl_Position = setZeroBuffer.proj * constants.view * constants.model * vec4(inPosition, 1.0);
|
||||
fragUV = inUV;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 2, binding = 0) uniform sampler2D materialSetAlbedoSampler;
|
||||
layout(set = 2, binding = 1) uniform sampler2D materialSetNormalSampler;
|
||||
layout(set = 2, binding = 2) uniform sampler2D materialSetOcclusionSampler;
|
||||
layout(set = 2, binding = 3) uniform sampler2D materialSetMetallicRoughnessSampler;
|
||||
|
||||
layout(location = 0) in vec3 fragPos;
|
||||
layout(location = 1) in vec3 fragNorm;
|
||||
layout(location = 2) in vec2 fragUV;
|
||||
layout(location = 3) in vec3 fragLightPos;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
|
||||
// constants
|
||||
vec3 lightColor = vec3(1.0, 1.0, 1.0);
|
||||
vec3 ambientColor = vec3(1.0, 1.0, 1.0);
|
||||
float ambientStrength = 0.05;
|
||||
vec3 baseColor = vec3(texture(materialSetAlbedoSampler, fragUV));
|
||||
vec3 emission = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
// code
|
||||
|
||||
vec3 norm = normalize(fragNorm);
|
||||
vec3 lightDir = normalize(fragLightPos - fragPos);
|
||||
|
||||
vec3 diffuse = max(dot(norm, lightDir), 0.0) * lightColor;
|
||||
vec3 ambient = ambientColor * ambientStrength;
|
||||
|
||||
vec3 viewDir = normalize(-fragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||
vec3 specular = 0.5 * spec * lightColor;
|
||||
|
||||
vec3 lighting = min(diffuse + ambient + specular, 1.0);
|
||||
outColor = min( ( vec4(baseColor, 1.0) ) * vec4(lighting + emission, 1.0), vec4(1.0));
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout(set = 0, binding = 0) uniform GlobalSetUniformBuffer {
|
||||
mat4 proj;
|
||||
} globalSetUniformBuffer;
|
||||
|
||||
layout(set = 1, binding = 0) uniform FrameSetUniformBuffer {
|
||||
mat4 view;
|
||||
} frameSetUniformBuffer;
|
||||
|
||||
layout( push_constant ) uniform Constants {
|
||||
mat4 model;
|
||||
} constants;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inNorm;
|
||||
layout(location = 2) in vec4 inTangent;
|
||||
layout(location = 3) in vec2 inUV;
|
||||
|
||||
layout(location = 0) out vec3 fragPos;
|
||||
layout(location = 1) out vec3 fragNorm;
|
||||
layout(location = 2) out vec2 fragUV;
|
||||
layout(location = 3) out vec3 fragLightPos;
|
||||
|
||||
void main() {
|
||||
gl_Position = globalSetUniformBuffer.proj * frameSetUniformBuffer.view * constants.model * vec4(inPosition, 1.0);
|
||||
|
||||
fragPos = vec3(frameSetUniformBuffer.view * constants.model * vec4(inPosition, 1.0));
|
||||
fragNorm = mat3(transpose(inverse(frameSetUniformBuffer.view * constants.model))) * inNorm;
|
||||
fragUV = inUV;
|
||||
|
||||
vec3 lightPos = vec3(5900.0, -2000.0, 1000.0);
|
||||
fragLightPos = vec3(frameSetUniformBuffer.view * vec4(lightPos, 1.0));
|
||||
|
||||
gl_Position.y *= -1.0;
|
||||
}
|
@ -75,7 +75,7 @@ namespace engine {
|
||||
LOG_DEBUG("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
|
||||
break;
|
||||
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
|
||||
LOG_INFO("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
|
||||
LOG_TRACE("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
|
||||
break;
|
||||
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT:
|
||||
LOG_WARN("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
|
||||
|
@ -19,7 +19,7 @@ namespace engine {
|
||||
sc->device = info.device;
|
||||
sc->allocator = info.allocator;
|
||||
|
||||
LOG_INFO("Recreating swapchain!\n");
|
||||
LOG_DEBUG("Recreating swapchain!\n");
|
||||
|
||||
// get surface caps and features
|
||||
VkResult res;
|
||||
|
@ -184,7 +184,7 @@ void CameraControllerSystem::OnUpdate(float ts)
|
||||
/* user interface inputs */
|
||||
|
||||
if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_R) || glm::length(t->position) > CameraControllerComponent::kMaxDistanceFromOrigin) {
|
||||
t->position = {0.0f, 0.0f, 100.0f};
|
||||
t->position = {0.0f, 0.0f, 10.0f};
|
||||
c->vel = {0.0f, 0.0f, 0.0f};
|
||||
c->pitch = glm::half_pi<float>();
|
||||
c->yaw = 0.0f;
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef ENGINE_TEST_SRC_CAMERA_CONTROLLER_H_
|
||||
#define ENGINE_TEST_SRC_CAMERA_CONTROLLER_H_
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
@ -20,13 +19,13 @@ struct CameraControllerComponent {
|
||||
static constexpr float kJumpHeight = /*4.4f*/ 8.8f;
|
||||
|
||||
// collision
|
||||
static constexpr float kPlayerHeight = 2.0f; // 71.0f * 25.4f / 1000.0f;
|
||||
static constexpr float kPlayerHeight = 2.0f; // 71.0f * 25.4f / 1000.0f;
|
||||
static constexpr float kPlayerCollisionRadius = 0.2f; // this should be greater than z_near
|
||||
static constexpr float kMaxStairHeight = 0.2f;
|
||||
static constexpr size_t kNumHorizontalRays = 20;
|
||||
|
||||
static constexpr float kGravAccel = -9.81f;
|
||||
static constexpr float kMaxDistanceFromOrigin = 1000.0f;
|
||||
static constexpr float kMaxDistanceFromOrigin = 200.0f;
|
||||
|
||||
bool noclip = false;
|
||||
|
||||
@ -50,5 +49,3 @@ class CameraControllerSystem : public engine::System {
|
||||
|
||||
engine::Scene* next_scene_ = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
@ -16,7 +16,6 @@
|
||||
#include "systems/mesh_render_system.h"
|
||||
#include "systems/transform.h"
|
||||
#include "util/gltf_loader.h"
|
||||
#include "util/model_loader.h"
|
||||
#include "log.h"
|
||||
#include "window.h"
|
||||
|
||||
@ -47,8 +46,8 @@ void PlayGame(GameSettings settings)
|
||||
|
||||
engine::gfx::GraphicsSettings graphics_settings{};
|
||||
graphics_settings.enable_validation = settings.enable_validation;
|
||||
graphics_settings.vsync = true;
|
||||
graphics_settings.wait_for_present = true;
|
||||
graphics_settings.vsync = false;
|
||||
graphics_settings.wait_for_present = false;
|
||||
graphics_settings.msaa_level = engine::gfx::MSAALevel::kOff;
|
||||
graphics_settings.enable_anisotropy = true;
|
||||
|
||||
|
@ -1,11 +1,8 @@
|
||||
#ifndef ENGINE_TEST_SRC_GAME_H_
|
||||
#define ENGINE_TEST_SRC_GAME_H_
|
||||
#pragma once
|
||||
|
||||
struct GameSettings {
|
||||
bool enable_frame_limiter;
|
||||
bool enable_validation;
|
||||
bool enable_frame_limiter;
|
||||
bool enable_validation;
|
||||
};
|
||||
|
||||
void PlayGame(GameSettings settings);
|
||||
|
||||
#endif
|
@ -1,16 +1,9 @@
|
||||
#ifndef ENGINE_TEST_SRC_MESHGEN_H_
|
||||
#define ENGINE_TEST_SRC_MESHGEN_H_
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "resources/mesh.h"
|
||||
|
||||
std::unique_ptr<engine::Mesh> GenSphereMesh(
|
||||
engine::GFXDevice* gfx, float r, int detail, bool wind_inside = false,
|
||||
bool flip_normals = false);
|
||||
std::unique_ptr<engine::Mesh> GenSphereMesh(engine::GFXDevice* gfx, float r, int detail, bool wind_inside = false, bool flip_normals = false);
|
||||
|
||||
std::unique_ptr<engine::Mesh> GenCuboidMesh(
|
||||
engine::GFXDevice* gfx, float x, float y, float z, float tiling = 1.0f,
|
||||
bool wind_inside = false);
|
||||
|
||||
#endif
|
||||
std::unique_ptr<engine::Mesh> GenCuboidMesh(engine::GFXDevice* gfx, float x, float y, float z, float tiling = 1.0f, bool wind_inside = false);
|
Loading…
Reference in New Issue
Block a user