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