Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6cf7c12d34 | |||
| 4a817613e3 | |||
| 6a3c14540d | |||
| 5602b32507 | |||
| 1431bd1a11 | |||
| 1e370bac13 | |||
| 7c714d1f98 | |||
| d182e6c453 | |||
| e76a6b74a3 | |||
| e82911cb8b | |||
| 7464facab9 | |||
| f14c62f3d3 | |||
| d406059c79 | |||
| 59b261534a | |||
| 45b87ed6b1 | |||
| 53d5736420 | |||
| 3da69c8a1b | |||
| 16d636a87c | |||
| 4da33ff4ec | |||
| c2435fda2d | |||
| 433331e752 | |||
| 094c7fbb44 | |||
| 0b60979c7b | |||
| 2366cd3520 | |||
| 725a8896ce | |||
| 80f028edf2 | |||
| 8c563a2d76 | |||
| 91edab34bc | |||
| cefc4e5257 | |||
| 37cf42527b | |||
| 9d3313e3ed | |||
| de6e74c0b1 | |||
| 393a774140 |
+1
-1
Submodule deps updated: 9861acd762...1b478d3159
@@ -17,119 +17,119 @@ class EventBroker;
|
||||
|
||||
class BaseEventRelay
|
||||
{
|
||||
friend class EventBroker;
|
||||
friend class EventBroker;
|
||||
|
||||
protected:
|
||||
BaseEventRelay(std::string contextTypeName, std::string eventTypeName)
|
||||
: m_ContextTypeName(contextTypeName)
|
||||
, m_EventTypeName(eventTypeName)
|
||||
, m_Broker(nullptr)
|
||||
{ }
|
||||
~BaseEventRelay();
|
||||
BaseEventRelay(std::string contextTypeName, std::string eventTypeName)
|
||||
: m_ContextTypeName(contextTypeName)
|
||||
, m_EventTypeName(eventTypeName)
|
||||
, m_Broker(nullptr)
|
||||
{ }
|
||||
~BaseEventRelay();
|
||||
|
||||
public:
|
||||
virtual bool Receive(const std::shared_ptr<Event> event) = 0;
|
||||
virtual bool Receive(const std::shared_ptr<Event> event) = 0;
|
||||
|
||||
protected:
|
||||
std::string m_ContextTypeName;
|
||||
std::string m_EventTypeName;
|
||||
EventBroker* m_Broker;
|
||||
std::string m_ContextTypeName;
|
||||
std::string m_EventTypeName;
|
||||
EventBroker* m_Broker;
|
||||
};
|
||||
|
||||
template <typename ContextType, typename EventType>
|
||||
class EventRelay : public BaseEventRelay
|
||||
{
|
||||
public:
|
||||
typedef std::function<bool(const EventType&)> CallbackType;
|
||||
typedef std::function<bool(const EventType&)> CallbackType;
|
||||
|
||||
EventRelay()
|
||||
: m_Callback(nullptr)
|
||||
, BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name())
|
||||
{ }
|
||||
EventRelay(CallbackType callback)
|
||||
: m_Callback(callback)
|
||||
, BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name())
|
||||
{ }
|
||||
EventRelay()
|
||||
: m_Callback(nullptr)
|
||||
, BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name())
|
||||
{ }
|
||||
EventRelay(CallbackType callback)
|
||||
: m_Callback(callback)
|
||||
, BaseEventRelay(typeid(ContextType).name(), typeid(EventType).name())
|
||||
{ }
|
||||
|
||||
protected:
|
||||
bool Receive(const std::shared_ptr<Event> event) override;
|
||||
bool Receive(const std::shared_ptr<Event> event) override;
|
||||
|
||||
private:
|
||||
CallbackType m_Callback;
|
||||
CallbackType m_Callback;
|
||||
};
|
||||
|
||||
template <typename ContextType, typename EventType>
|
||||
bool EventRelay<ContextType, EventType>::Receive(const std::shared_ptr<Event> event)
|
||||
{
|
||||
if (m_Callback != nullptr) {
|
||||
return m_Callback(*static_cast<const EventType*>(event.get()));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (m_Callback != nullptr) {
|
||||
return m_Callback(*static_cast<const EventType*>(event.get()));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class EventBroker
|
||||
{
|
||||
template <typename ContextType, typename EventType> friend class EventRelay;
|
||||
template <typename ContextType, typename EventType> friend class EventRelay;
|
||||
|
||||
public:
|
||||
EventBroker()
|
||||
{
|
||||
m_EventQueueRead = std::make_shared<EventQueue_t>();
|
||||
m_EventQueueWrite = std::make_shared<EventQueue_t>();
|
||||
}
|
||||
EventBroker()
|
||||
{
|
||||
m_EventQueueRead = std::make_shared<EventQueue_t>();
|
||||
m_EventQueueWrite = std::make_shared<EventQueue_t>();
|
||||
}
|
||||
|
||||
void Subscribe(BaseEventRelay &relay);
|
||||
template <typename EventType>
|
||||
void Publish(const EventType &event);
|
||||
/*
|
||||
Process all events in a given context.
|
||||
Returns: Number of events processed
|
||||
*/
|
||||
template <typename ContextType>
|
||||
int Process();
|
||||
int Process(std::string contextTypeName);
|
||||
void Swap();
|
||||
void Clear();
|
||||
void Unsubscribe(BaseEventRelay &relay);
|
||||
void Subscribe(BaseEventRelay &relay);
|
||||
template <typename EventType>
|
||||
void Publish(const EventType &event);
|
||||
/*
|
||||
Process all events in a given context.
|
||||
Returns: Number of events processed
|
||||
*/
|
||||
template <typename ContextType>
|
||||
int Process();
|
||||
int Process(std::string contextTypeName);
|
||||
void Swap();
|
||||
void Clear();
|
||||
void Unsubscribe(BaseEventRelay &relay);
|
||||
|
||||
private:
|
||||
bool m_IsProcessing = false;
|
||||
bool m_IsProcessing = false;
|
||||
|
||||
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
|
||||
typedef std::string EventTypeName_t; // typeid(EventType).name()
|
||||
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
|
||||
typedef std::string EventTypeName_t; // typeid(EventType).name()
|
||||
|
||||
typedef std::unordered_multimap<EventTypeName_t, BaseEventRelay*> EventRelays_t;
|
||||
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
|
||||
ContextRelays_t m_ContextRelays;
|
||||
std::vector<BaseEventRelay*> m_RelaysToSubscribe;
|
||||
std::vector<BaseEventRelay*> m_RelaysToUnsubscribe;
|
||||
typedef std::unordered_multimap<EventTypeName_t, BaseEventRelay*> EventRelays_t;
|
||||
typedef std::unordered_map<ContextTypeName_t, EventRelays_t> ContextRelays_t;
|
||||
ContextRelays_t m_ContextRelays;
|
||||
std::vector<BaseEventRelay*> m_RelaysToSubscribe;
|
||||
std::vector<BaseEventRelay*> m_RelaysToUnsubscribe;
|
||||
|
||||
typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t;
|
||||
std::shared_ptr<EventQueue_t> m_EventQueueRead;
|
||||
std::shared_ptr<EventQueue_t> m_EventQueueWrite;
|
||||
typedef std::list<std::pair<EventTypeName_t, std::shared_ptr<Event>>> EventQueue_t;
|
||||
std::shared_ptr<EventQueue_t> m_EventQueueRead;
|
||||
std::shared_ptr<EventQueue_t> m_EventQueueWrite;
|
||||
|
||||
void subscribeImmediate(BaseEventRelay& relay);
|
||||
void unsubscribeImmediate(BaseEventRelay& relay);
|
||||
void subscribeImmediate(BaseEventRelay& relay);
|
||||
void unsubscribeImmediate(BaseEventRelay& relay);
|
||||
};
|
||||
|
||||
template <typename EventType>
|
||||
void EventBroker::Publish(const EventType &event)
|
||||
{
|
||||
/*auto itpair = m_Subscribers.equal_range(typeid(EventType).name());
|
||||
for (auto it = itpair.first; it != itpair.second; ++it)
|
||||
{
|
||||
it->second->Receive(event);
|
||||
}*/
|
||||
/*auto itpair = m_Subscribers.equal_range(typeid(EventType).name());
|
||||
for (auto it = itpair.first; it != itpair.second; ++it)
|
||||
{
|
||||
it->second->Receive(event);
|
||||
}*/
|
||||
|
||||
m_EventQueueWrite->push_back(std::make_pair(typeid(EventType).name(), std::shared_ptr<EventType>(new EventType(event))));
|
||||
m_EventQueueWrite->push_back(std::make_pair(typeid(EventType).name(), std::shared_ptr<EventType>(new EventType(event))));
|
||||
}
|
||||
|
||||
template <typename ContextType>
|
||||
int EventBroker::Process()
|
||||
{
|
||||
const std::string contextTypeName = typeid(ContextType).name();
|
||||
return Process(contextTypeName);
|
||||
const std::string contextTypeName = typeid(ContextType).name();
|
||||
return Process(contextTypeName);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,16 +10,16 @@ class System
|
||||
friend class SystemPipeline;
|
||||
|
||||
public:
|
||||
System(const EventBroker* eventBroker, std::string componentType)
|
||||
System(EventBroker* eventBroker, std::string componentType)
|
||||
: m_EventBroker(eventBroker)
|
||||
, m_ComponentType(componentType)
|
||||
{ }
|
||||
|
||||
virtual void Update(World* world, ComponentWrapper& component, double dt) = 0;
|
||||
|
||||
private:
|
||||
const EventBroker* m_EventBroker;
|
||||
protected:
|
||||
std::string m_ComponentType;
|
||||
EventBroker* m_EventBroker;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@
|
||||
class SystemPipeline
|
||||
{
|
||||
public:
|
||||
SystemPipeline(const EventBroker* eventBroker)
|
||||
SystemPipeline(EventBroker* eventBroker)
|
||||
: m_EventBroker(eventBroker)
|
||||
{ }
|
||||
~SystemPipeline()
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const EventBroker* m_EventBroker;
|
||||
EventBroker* m_EventBroker;
|
||||
std::unordered_map<std::string, std::vector<System*>> m_Systems;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef Events_BindOrigin_h__
|
||||
#define Events_BindOrigin_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Called to bind an input origin to an input command. */
|
||||
struct BindOrigin : Event
|
||||
{
|
||||
/** The input origin to bind. */
|
||||
std::string Origin;
|
||||
/** The command to send. */
|
||||
std::string Command;
|
||||
/** The value to send for positive stimulation. */
|
||||
float Value = 1.f;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -13,7 +13,7 @@ struct InputCommand : Event
|
||||
/** The command that was sent. */
|
||||
std::string Command;
|
||||
/** The value of the command. */
|
||||
float Value = 0;
|
||||
float Value;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
#ifndef InputSystem_h__
|
||||
#define InputSystem_h__
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <steam/steam_api.h>
|
||||
|
||||
#include "Core/EKeyUp.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EMousePress.h"
|
||||
#include "Core/EMouseRelease.h"
|
||||
#include "Core/EGamepadAxis.h"
|
||||
#include "Core/EGamepadButton.h"
|
||||
#include "Core/Util/EnumClassHash.h"
|
||||
#include "EBindKey.h"
|
||||
#include "EBindMouseButton.h"
|
||||
#include "EBindGamepadAxis.h"
|
||||
#include "EBindGamepadButton.h"
|
||||
#include "EInputCommand.h"
|
||||
#include "EBindOrigin.h"
|
||||
|
||||
class InputProxy;
|
||||
|
||||
class InputHandler
|
||||
{
|
||||
public:
|
||||
InputHandler(EventBroker* eventBroker, InputProxy* inputProxy)
|
||||
: m_EventBroker(eventBroker)
|
||||
, m_InputProxy(inputProxy)
|
||||
{ }
|
||||
|
||||
virtual void Update(double dt) { }
|
||||
virtual bool BindOrigin(std::string origin, std::string command, float value) = 0;
|
||||
|
||||
protected:
|
||||
EventBroker* m_EventBroker;
|
||||
InputProxy* m_InputProxy;
|
||||
};
|
||||
|
||||
class InputProxy
|
||||
{
|
||||
public:
|
||||
InputProxy(EventBroker* eventBroker)
|
||||
: m_EventBroker(eventBroker)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindOrigin, &InputProxy::OnBindOrigin);
|
||||
}
|
||||
|
||||
void Update(double dt)
|
||||
{
|
||||
m_EventBroker->Process<InputProxy>();
|
||||
m_EventBroker->Process<InputHandler>();
|
||||
for (auto& handler : m_Handlers) {
|
||||
handler->Update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
void Process()
|
||||
{
|
||||
// Accumulate the input values of all unique commands published by input handlers
|
||||
for (auto& pair : m_CommandQueue) {
|
||||
Events::InputCommand e;
|
||||
e.PlayerID = pair.first.first;
|
||||
e.Command = pair.first.second;
|
||||
e.Value = 0;
|
||||
for (auto& value : pair.second) {
|
||||
e.Value += value;
|
||||
}
|
||||
e.Value = std::max(-1.f, std::min(e.Value, 1.f));
|
||||
m_EventBroker->Publish(e);
|
||||
LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, e.PlayerID);
|
||||
}
|
||||
m_CommandQueue.clear();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AddHandler()
|
||||
{
|
||||
m_Handlers.push_back(new T(m_EventBroker, this));
|
||||
}
|
||||
|
||||
void Publish(const Events::InputCommand& e)
|
||||
{
|
||||
auto key = std::make_pair(e.PlayerID, e.Command);
|
||||
m_CommandQueue[key].push_back(e.Value);
|
||||
}
|
||||
|
||||
protected:
|
||||
EventBroker* m_EventBroker;
|
||||
std::vector<InputHandler*> m_Handlers;
|
||||
// Represents every unique command (has of PlayerID & Command) and all values reported for that command
|
||||
std::map<std::pair<unsigned int, std::string>, std::vector<float>> m_CommandQueue;
|
||||
|
||||
EventRelay<InputProxy, Events::BindOrigin> m_EBindOrigin;
|
||||
bool OnBindOrigin(const Events::BindOrigin& e)
|
||||
{
|
||||
bool originBound = false;
|
||||
for (auto& handler : m_Handlers) {
|
||||
bool result = handler->BindOrigin(e.Origin, e.Command, e.Value);
|
||||
if (result) {
|
||||
if (originBound) {
|
||||
LOG_WARNING("Multiple handlers responded to binding input origin \"%s\"!", e.Origin.c_str());
|
||||
}
|
||||
originBound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!originBound) {
|
||||
LOG_ERROR("No input handler responded to binding input origin \"%s\"!", e.Origin.c_str());
|
||||
}
|
||||
|
||||
return originBound;
|
||||
}
|
||||
//std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandMouseButtonValues; // command string -> mouse button value for command
|
||||
//std::unordered_map<std::string, std::unordered_map<Gamepad::Axis, float, EnumClassHash>> m_CommandGamepadAxisValues; // command string -> gamepad axis value for command
|
||||
//std::unordered_map<std::string, std::unordered_map<Gamepad::Button, float, EnumClassHash>> m_CommandGamepadButtonValues; // command string -> gamepad button value for command
|
||||
//// Input binding tables
|
||||
//std::unordered_multimap<int, std::tuple<std::string, float>> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
||||
//std::unordered_multimap<Gamepad::Axis, std::tuple<std::string, float>, EnumClassHash> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
|
||||
//std::unordered_multimap<Gamepad::Button, std::tuple<std::string, float>, EnumClassHash> m_GamepadButtonBindings; // Gamepad::Button -> command string
|
||||
|
||||
//// Input events
|
||||
//EventRelay<InputProxy, Events::MousePress> m_EMousePress;
|
||||
//bool OnMousePress(const Events::MousePress &event);
|
||||
//EventRelay<InputProxy, Events::MouseRelease> m_EMouseRelease;
|
||||
//bool OnMouseRelease(const Events::MouseRelease &event);
|
||||
//EventRelay<InputProxy, Events::GamepadAxis> m_EGamepadAxis;
|
||||
//bool OnGamepadAxis(const Events::GamepadAxis &event);
|
||||
//EventRelay<InputProxy, Events::GamepadButtonDown> m_EGamepadButtonDown;
|
||||
//bool OnGamepadButtonDown(const Events::GamepadButtonDown &event);
|
||||
//EventRelay<InputProxy, Events::GamepadButtonUp> m_EGamepadButtonUp;
|
||||
//bool OnGamepadButtonUp(const Events::GamepadButtonUp &event);
|
||||
//// Input binding events
|
||||
//EventRelay<InputProxy, Events::BindMouseButton> m_EBindMouseButton;
|
||||
//bool OnBindMouseButton(const Events::BindMouseButton &event);
|
||||
//EventRelay<InputProxy, Events::BindGamepadAxis> m_EBindGamepadAxis;
|
||||
//bool OnBindGamepadAxis(const Events::BindGamepadAxis &event);
|
||||
//EventRelay<InputProxy, Events::BindGamepadButton> m_EBindGamepadButton;
|
||||
//bool OnBindGamepadButton(const Events::BindGamepadButton &event);
|
||||
|
||||
//float GetCommandTotalValue(std::string command);
|
||||
//void PublishCommand(int playerID, std::string command, float value);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,78 @@
|
||||
#ifndef InputSystem_h__
|
||||
#define InputSystem_h__
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EMousePress.h"
|
||||
#include "Core/EMouseRelease.h"
|
||||
#include "Core/EGamepadAxis.h"
|
||||
#include "Core/EGamepadButton.h"
|
||||
#include "Core/Util/EnumClassHash.h"
|
||||
#include "EBindKey.h"
|
||||
#include "EBindMouseButton.h"
|
||||
#include "EBindGamepadAxis.h"
|
||||
#include "EBindGamepadButton.h"
|
||||
#include "EInputCommand.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class InputSystem : public System
|
||||
{
|
||||
public:
|
||||
InputSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker)
|
||||
{ }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void Initialize() override;
|
||||
|
||||
void Update(double dt) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandKeyboardValues; // command string -> keyboard key value for command
|
||||
std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandMouseButtonValues; // command string -> mouse button value for command
|
||||
std::unordered_map<std::string, std::unordered_map<Gamepad::Axis, float, EnumClassHash>> m_CommandGamepadAxisValues; // command string -> gamepad axis value for command
|
||||
std::unordered_map<std::string, std::unordered_map<Gamepad::Button, float, EnumClassHash>> m_CommandGamepadButtonValues; // command string -> gamepad button value for command
|
||||
// Input binding tables
|
||||
std::unordered_multimap<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
|
||||
std::unordered_multimap<int, std::tuple<std::string, float>> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
|
||||
std::unordered_multimap<Gamepad::Axis, std::tuple<std::string, float>, EnumClassHash> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
|
||||
std::unordered_multimap<Gamepad::Button, std::tuple<std::string, float>, EnumClassHash> m_GamepadButtonBindings; // Gamepad::Button -> command string
|
||||
|
||||
// Input events
|
||||
EventRelay<InputSystem, Events::KeyDown> m_EKeyDown;
|
||||
bool OnKeyDown(const Events::KeyDown &event);
|
||||
EventRelay<InputSystem, Events::KeyUp> m_EKeyUp;
|
||||
bool OnKeyUp(const Events::KeyUp &event);
|
||||
EventRelay<InputSystem, Events::MousePress> m_EMousePress;
|
||||
bool OnMousePress(const Events::MousePress &event);
|
||||
EventRelay<InputSystem, Events::MouseRelease> m_EMouseRelease;
|
||||
bool OnMouseRelease(const Events::MouseRelease &event);
|
||||
EventRelay<InputSystem, Events::GamepadAxis> m_EGamepadAxis;
|
||||
bool OnGamepadAxis(const Events::GamepadAxis &event);
|
||||
EventRelay<InputSystem, Events::GamepadButtonDown> m_EGamepadButtonDown;
|
||||
bool OnGamepadButtonDown(const Events::GamepadButtonDown &event);
|
||||
EventRelay<InputSystem, Events::GamepadButtonUp> m_EGamepadButtonUp;
|
||||
bool OnGamepadButtonUp(const Events::GamepadButtonUp &event);
|
||||
// Input binding events
|
||||
EventRelay<InputSystem, Events::BindKey> m_EBindKey;
|
||||
bool OnBindKey(const Events::BindKey &event);
|
||||
EventRelay<InputSystem, Events::BindMouseButton> m_EBindMouseButton;
|
||||
bool OnBindMouseButton(const Events::BindMouseButton &event);
|
||||
EventRelay<InputSystem, Events::BindGamepadAxis> m_EBindGamepadAxis;
|
||||
bool OnBindGamepadAxis(const Events::BindGamepadAxis &event);
|
||||
EventRelay<InputSystem, Events::BindGamepadButton> m_EBindGamepadButton;
|
||||
bool OnBindGamepadButton(const Events::BindGamepadButton &event);
|
||||
|
||||
float GetCommandTotalValue(std::string command);
|
||||
void PublishCommand(int playerID, std::string command, float value);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,67 +0,0 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "InputProxy.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
|
||||
class KeyboardInputHandler : public InputHandler
|
||||
{
|
||||
public:
|
||||
KeyboardInputHandler(EventBroker* eventBroker, InputProxy* inputProxy)
|
||||
: InputHandler(eventBroker, inputProxy)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &KeyboardInputHandler::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &KeyboardInputHandler::OnKeyUp);
|
||||
|
||||
m_OriginKeyCodes["R"] = GLFW_KEY_R;
|
||||
}
|
||||
|
||||
bool BindOrigin(std::string origin, std::string command, float value) override
|
||||
{
|
||||
auto originIt = m_OriginKeyCodes.find(origin);
|
||||
if (originIt == m_OriginKeyCodes.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int keyCode = originIt->second;
|
||||
m_KeyBindings[keyCode] = std::make_tuple(command, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, int> m_OriginKeyCodes;
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
|
||||
|
||||
EventRelay<InputHandler, Events::KeyDown> m_EKeyDown;
|
||||
bool OnKeyDown(const Events::KeyDown& e)
|
||||
{
|
||||
auto it = m_KeyBindings.find(e.KeyCode);
|
||||
if (it == m_KeyBindings.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Events::InputCommand ic;
|
||||
ic.PlayerID = 0;
|
||||
std::tie(ic.Command, ic.Value) = it->second;
|
||||
m_InputProxy->Publish(ic);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EventRelay<InputHandler, Events::KeyUp> m_EKeyUp;
|
||||
bool OnKeyUp(const Events::KeyUp& e)
|
||||
{
|
||||
auto it = m_KeyBindings.find(e.KeyCode);
|
||||
if (it == m_KeyBindings.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Events::InputCommand ic;
|
||||
ic.PlayerID = 0;
|
||||
std::tie(ic.Command, std::ignore) = it->second;
|
||||
ic.Value = 0;
|
||||
m_InputProxy->Publish(ic);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -1,98 +0,0 @@
|
||||
#include <steam/steam_api.h>
|
||||
#include "InputProxy.h"
|
||||
|
||||
class SteamControllerInputHandler : public InputHandler
|
||||
{
|
||||
public:
|
||||
SteamControllerInputHandler(EventBroker* eventBroker, InputProxy* inputProxy)
|
||||
: InputHandler(eventBroker, inputProxy)
|
||||
{
|
||||
SteamController()->Init();
|
||||
}
|
||||
|
||||
~SteamControllerInputHandler()
|
||||
{
|
||||
SteamController()->Shutdown();
|
||||
}
|
||||
|
||||
void Update(double dt) override
|
||||
{
|
||||
std::array<ControllerHandle_t, STEAM_CONTROLLER_MAX_COUNT> controllers;
|
||||
int numControllers = SteamController()->GetConnectedControllers(controllers.data());
|
||||
for (int i = 0; i < numControllers; i++) {
|
||||
auto controllerHandle = controllers.at(i);
|
||||
auto actionSetHandle = SteamController()->GetActionSetHandle("InGameControls");
|
||||
//SteamController()->ShowBindingPanel(controllerHandle);
|
||||
SteamController()->ActivateActionSet(controllerHandle, actionSetHandle);
|
||||
for (auto& command : m_Commands) {
|
||||
Events::InputCommand ic;
|
||||
ic.PlayerID = i + 1;
|
||||
ic.Command = command.first;
|
||||
|
||||
auto digitalActionHandle = m_DigitalActionHandles.at(ic.Command);
|
||||
auto handle = SteamController()->GetDigitalActionHandle("DebugReload");
|
||||
auto data = SteamController()->GetDigitalActionData(controllerHandle, handle);
|
||||
LOG_DEBUG("Controller %i, active %i, value %i", i, data.bActive, data.bState);
|
||||
if (data.bState) {
|
||||
ic.Value = command.second;
|
||||
} else {
|
||||
ic.Value = 0.f;
|
||||
}
|
||||
//m_InputProxy->Publish(ic);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool BindOrigin(std::string origin, std::string command, float value) override
|
||||
{
|
||||
if (origin != "SteamController") {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Commands[command] = value;
|
||||
m_DigitalActionHandles[command] = SteamController()->GetDigitalActionHandle(command.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, float> m_Commands;
|
||||
std::map<std::string, ControllerDigitalActionHandle_t> m_DigitalActionHandles;
|
||||
|
||||
//std::unordered_map<std::string, std::unordered_map<int, float>> m_CommandKeyboardValues; // command string -> keyboard key value for command
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
|
||||
|
||||
EventRelay<InputHandler, Events::KeyDown> m_EKeyDown;
|
||||
bool OnKeyDown(const Events::KeyDown& e)
|
||||
{
|
||||
auto it = m_KeyBindings.find(e.KeyCode);
|
||||
if (it == m_KeyBindings.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Events::InputCommand ic;
|
||||
ic.PlayerID = 0;
|
||||
std::tie(ic.Command, ic.Value) = it->second;
|
||||
m_InputProxy->Publish(ic);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EventRelay<InputHandler, Events::KeyUp> m_EKeyUp;
|
||||
bool OnKeyUp(const Events::KeyUp& e)
|
||||
{
|
||||
auto it = m_KeyBindings.find(e.KeyCode);
|
||||
if (it == m_KeyBindings.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Events::InputCommand ic;
|
||||
ic.PlayerID = 0;
|
||||
std::tie(ic.Command, std::ignore) = it->second;
|
||||
ic.Value = 0;
|
||||
m_InputProxy->Publish(ic);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef DrawScenePass_h__
|
||||
#define DrawScenePass_h__
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "DrawScenePassState.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Util/UnorderedMapVec2.h"
|
||||
#include "Texture.h"
|
||||
|
||||
class DrawScenePass
|
||||
{
|
||||
public:
|
||||
DrawScenePass(IRenderer* renderer);
|
||||
~DrawScenePass() { }
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
|
||||
void Draw(RenderQueueCollection& rq);
|
||||
|
||||
//Getters
|
||||
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
Texture* m_WhiteTexture;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
|
||||
ShaderProgram* m_BasicForwardProgram;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef DrawScenePassState_h__
|
||||
#define DrawScenePassState_h__
|
||||
|
||||
#include "Rendering/RenderState.h"
|
||||
|
||||
class DrawScenePassState : public RenderState
|
||||
{
|
||||
public:
|
||||
DrawScenePassState();
|
||||
~DrawScenePassState();
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef PickingPass_h__
|
||||
#define PickingPass_h__
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "PickingPassState.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Util/UnorderedMapVec2.h"
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "EPicking.h"
|
||||
|
||||
class PickingPass
|
||||
{
|
||||
public:
|
||||
PickingPass(IRenderer* renderer, EventBroker* eb);
|
||||
~PickingPass();
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
|
||||
void Draw(RenderQueueCollection& rq);
|
||||
|
||||
|
||||
//Getters
|
||||
const ShaderProgram& PickingProgram() const { return *m_PickingProgram; }
|
||||
const std::unordered_map<glm::vec2, EntityID>& PickingColorsToEntity() const { return m_PickingColorsToEntity; }
|
||||
GLuint PickingTexture() const { return m_PickingTexture; }
|
||||
GLuint DepthBuffer() const { return m_DepthBuffer; }
|
||||
const FrameBuffer& PickingBuffer() const { return m_PickingBuffer; }
|
||||
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
|
||||
ShaderProgram* m_PickingProgram;
|
||||
|
||||
std::unordered_map<glm::vec2, EntityID> m_PickingColorsToEntity;
|
||||
|
||||
GLuint m_PickingTexture;
|
||||
GLuint m_DepthBuffer;
|
||||
|
||||
FrameBuffer m_PickingBuffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef PickingPassState_h__
|
||||
#define PickingPassState_h__
|
||||
|
||||
#include "Rendering/RenderState.h"
|
||||
|
||||
class PickingPassState : public RenderState
|
||||
{
|
||||
public:
|
||||
PickingPassState(GLuint frameBuffer);
|
||||
~PickingPassState();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef RenderState_h__
|
||||
#define RenderState_h__
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "../GLM.h"
|
||||
|
||||
class RenderState
|
||||
{
|
||||
public:
|
||||
RenderState();
|
||||
~RenderState();
|
||||
bool Enable(GLenum GLEnable);
|
||||
bool CullFace(GLenum GlFaceToCull);
|
||||
bool ClearColor(glm::vec4 color);
|
||||
bool Clear(GLbitfield mask);
|
||||
bool BindBuffer(GLint buffer);
|
||||
private:
|
||||
std::vector<GLenum> m_Enables;
|
||||
float m_preClearColor[4];
|
||||
int m_preBuffer;
|
||||
};
|
||||
#endif
|
||||
@@ -10,6 +10,13 @@
|
||||
#include "Util/UnorderedMapVec2.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "../Core/World.h"
|
||||
#include "PickingPass.h"
|
||||
#include "DrawScenePass.h"
|
||||
|
||||
|
||||
#define TILE_SIZE 16
|
||||
#define NUM_LIGHTS 5000
|
||||
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "EPicking.h"
|
||||
@@ -21,44 +28,91 @@ public:
|
||||
: m_EventBroker(eventBroker)
|
||||
{ }
|
||||
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(double dt) override;
|
||||
virtual void Draw(RenderQueueCollection& rq) override;
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(double dt) override;
|
||||
virtual void Draw(RenderQueueCollection& rq) override;
|
||||
|
||||
private:
|
||||
//----------------------Variables----------------------//
|
||||
//----------------------Variables----------------------//
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
Texture* m_ErrorTexture;
|
||||
Texture* m_WhiteTexture;
|
||||
float m_CameraMoveSpeed;
|
||||
FrameBuffer m_PickingBuffer;
|
||||
GLuint m_PickingTexture;
|
||||
GLuint m_DepthBuffer;
|
||||
Texture* m_ErrorTexture;
|
||||
Texture* m_WhiteTexture;
|
||||
float m_CameraMoveSpeed;
|
||||
|
||||
Model* m_ScreenQuad;
|
||||
Model* m_UnitQuad;
|
||||
Model* m_UnitSphere;
|
||||
|
||||
std::unordered_map<glm::vec2, EntityID> m_PickingColorsToEntity;
|
||||
DrawScenePass* m_DrawScenePass;
|
||||
PickingPass* m_PickingPass;
|
||||
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
void InitializeShaders();
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
void InitializeShaders();
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeSSBOs();
|
||||
void InitializeRenderPasses();
|
||||
//TODO: Renderer: Get InputUpdate out of renderer
|
||||
void InputUpdate(double dt);
|
||||
void PickingPass(RenderQueueCollection& rq);
|
||||
void InputUpdate(double dt);
|
||||
//void PickingPass(RenderQueueCollection& rq);
|
||||
void DrawScreenQuad(GLuint textureToDraw);
|
||||
void DrawScene(RenderQueueCollection& rq);
|
||||
|
||||
//----------------------Forward+-----------------------//
|
||||
void CalculateFrustum();
|
||||
void CullLights();
|
||||
void DrawForwardPlus(RenderQueueCollection& rq);
|
||||
//Frustum
|
||||
struct Plane {
|
||||
glm::vec3 Normal;
|
||||
float d;
|
||||
};
|
||||
|
||||
struct Frustum {
|
||||
Plane Planes[4];
|
||||
};
|
||||
Frustum m_Frustums[80*45]; //TODO: Renderer: Make this change with resolution
|
||||
|
||||
//Lights
|
||||
void TEMPCreateLights();
|
||||
//TODO: Renderer: Add Directionllights, spotlights and area lights to this as type.
|
||||
struct PointLight {
|
||||
glm::vec4 Position = glm::vec4(0.f);
|
||||
glm::vec4 Color = glm::vec4(1.f);
|
||||
float Radius = 5.f;
|
||||
float Intensity = 0.8f;
|
||||
float Falloff = 0.3f;
|
||||
float Padding = 1337;
|
||||
};
|
||||
PointLight m_PointLights[NUM_LIGHTS];
|
||||
|
||||
struct LightGrid {
|
||||
float Start;
|
||||
float Amount;
|
||||
glm::vec2 Padding;
|
||||
};
|
||||
|
||||
LightGrid m_LightGrid[80*45];
|
||||
|
||||
int m_LightOffset = 0;
|
||||
|
||||
float m_LightIndex[80*45*200];
|
||||
|
||||
//-------------------------SSBO------------------------//
|
||||
GLuint m_FrustumSSBO = 0;
|
||||
GLuint m_LightSSBO = 0;
|
||||
GLuint m_LightGridSSBO = 0;
|
||||
GLuint m_LightOffsetSSBO = 0;
|
||||
GLuint m_LightIndexSSBO = 0;
|
||||
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
|
||||
//--------------------ShaderPrograms-------------------//
|
||||
ShaderProgram m_BasicForwardProgram;
|
||||
ShaderProgram m_PickingProgram;
|
||||
ShaderProgram m_DrawScreenQuadProgram;
|
||||
ShaderProgram* m_BasicForwardProgram;
|
||||
ShaderProgram* m_DrawScreenQuadProgram;
|
||||
ShaderProgram* m_CalculateFrustumProgram;
|
||||
ShaderProgram* m_LightCullProgram;
|
||||
ShaderProgram* m_ForwardPlusProgram;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef ShaderProgram_h__
|
||||
#define ShaderProgram_h__
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include <fstream>
|
||||
|
||||
class Shader
|
||||
@@ -60,11 +63,13 @@ public:
|
||||
: ShaderType(fileName) { }
|
||||
};
|
||||
|
||||
class ShaderProgram
|
||||
class ShaderProgram : public Resource
|
||||
{
|
||||
public:
|
||||
ShaderProgram()
|
||||
friend class ResourceManager;
|
||||
private:
|
||||
ShaderProgram(std::string)
|
||||
: m_ShaderProgramHandle(0) { }
|
||||
public:
|
||||
~ShaderProgram();
|
||||
|
||||
void AddShader(std::shared_ptr<Shader> shader);
|
||||
@@ -79,3 +84,5 @@ private:
|
||||
GLuint m_ShaderProgramHandle;
|
||||
std::vector<std::shared_ptr<Shader>> m_Shaders;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@ inline bool _GLERROR(const char* info, const char* file, const char* func, unsig
|
||||
GLenum error = glGetError();
|
||||
if (error != GL_NO_ERROR)
|
||||
{
|
||||
_LOG(LOG_LEVEL_ERROR, file, func, line, "GL Error: %s %i %s", info, error, gluErrorString(error));
|
||||
_LOG(LOG_LEVEL_ERROR, file, func, line, "GL Error: %s, %i, %s", info, error, gluErrorString(error));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -9,13 +9,11 @@
|
||||
#include "GUI/Frame.h"
|
||||
#include "Core/World.h"
|
||||
#include "Rendering/RenderQueueFactory.h"
|
||||
#include "Input/InputProxy.h"
|
||||
#include "Input/KeyboardInputHandler.h"
|
||||
#include "Input/SteamControllerInputHandler.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EntityXMLFile.h"
|
||||
#include "Core/SystemPipeline.h"
|
||||
#include "RaptorCopterSystem.h"
|
||||
#include "PlayerSystem.h"
|
||||
|
||||
class Game
|
||||
{
|
||||
@@ -32,7 +30,6 @@ private:
|
||||
EventBroker* m_EventBroker;
|
||||
IRenderer* m_Renderer;
|
||||
InputManager* m_InputManager;
|
||||
InputProxy* m_InputProxy;
|
||||
GUI::Frame* m_FrameStack;
|
||||
World* m_World;
|
||||
SystemPipeline* m_SystemPipeline;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef PlayerSystem_h__
|
||||
#define PlayerSystem_h__
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/common.hpp>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
|
||||
struct KeyInput
|
||||
{
|
||||
bool Forward = false;
|
||||
bool Left = false;
|
||||
bool Back = false;
|
||||
bool Right = false;
|
||||
};
|
||||
|
||||
class PlayerSystem : public System
|
||||
{
|
||||
public:
|
||||
PlayerSystem(EventBroker* eventBroker)
|
||||
: System(eventBroker, "Player")
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &PlayerSystem::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PlayerSystem::OnKeyUp);
|
||||
}
|
||||
|
||||
virtual void Update(World* world, ComponentWrapper& player, double dt) override;
|
||||
|
||||
private:
|
||||
float m_Speed = 5;
|
||||
glm::vec3 m_Direction;
|
||||
KeyInput input;
|
||||
|
||||
EventRelay<PlayerSystem, Events::KeyDown> m_EKeyDown;
|
||||
bool OnKeyDown(const Events::KeyDown &event);
|
||||
EventRelay<PlayerSystem, Events::KeyUp> m_EKeyUp;
|
||||
bool OnKeyUp(const Events::KeyUp &event);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,10 +4,12 @@
|
||||
class RaptorCopterSystem : public System
|
||||
{
|
||||
public:
|
||||
RaptorCopterSystem(const EventBroker* eventBroker)
|
||||
RaptorCopterSystem(EventBroker* eventBroker)
|
||||
: System(eventBroker, "RaptorCopter")
|
||||
{ }
|
||||
|
||||
virtual void Initialize() { }
|
||||
|
||||
virtual void Update(World* world, ComponentWrapper& raptorCopter, double dt) override
|
||||
{
|
||||
ComponentWrapper& transform = world->GetComponent(raptorCopter.EntityID, "Transform");
|
||||
|
||||
@@ -6,4 +6,5 @@ LoadMap=
|
||||
Fullscreen=false
|
||||
VSYNC=false
|
||||
Width=1280
|
||||
Height=720
|
||||
Height=720
|
||||
FOV=45
|
||||
@@ -5,4 +5,5 @@
|
||||
<xs:include schemaLocation="Components/Model.xsd"/>
|
||||
<xs:include schemaLocation="Components/Test.xsd"/>
|
||||
<xs:include schemaLocation="Components/RaptorCopter.xsd"/>
|
||||
<xs:include schemaLocation="Components/Player.xsd"/>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,3 @@
|
||||
<c:Player>
|
||||
<Velocity X="0" Y="0" Z="0"/>
|
||||
</c:Player>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||
|
||||
<xs:element name="Player">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Velocity" type="t:Vector" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -5,11 +5,18 @@
|
||||
<c:Transform>
|
||||
<Orientation X="0" Y="0" Z="0"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/DummyScene.obj</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Scale X="10000" Y="10000" Z="10000"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitPlane.obj</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
@@ -31,6 +38,19 @@
|
||||
</c:Model>
|
||||
</Components>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Player>
|
||||
<Velocity X="0" Y="0" Z="0"/>
|
||||
</c:Player>
|
||||
<c:Transform>
|
||||
<Position X="2.5"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitCube.obj</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
@@ -48,7 +68,7 @@
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0"/>
|
||||
<Orientation X="0.0" Y="0" Z="0.0"/>
|
||||
<Orientation X="0.0" Y="0" Z="1.0"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitRaptor.obj</Resource>
|
||||
@@ -59,8 +79,8 @@
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0"/>
|
||||
<Orientation X="0" Y="0" Z="0"/>
|
||||
<Position X="-0.01" Y="0.55"/>
|
||||
<Orientation X="0" Y="0" Z="-1"/>
|
||||
</c:Transform>
|
||||
<c:RaptorCopter>
|
||||
<Speed>20</Speed>
|
||||
@@ -71,19 +91,7 @@
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0.4"/>
|
||||
<Scale X="0.1" Y="0.4" Z="0.1"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitCylinder.obj</Resource>
|
||||
<Color R="1" G="0.4" B="0.8"/>
|
||||
</c:Model>
|
||||
</Components>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0.6"/>
|
||||
<Position X="0" Y="0"/>
|
||||
<Scale X="1.7" Y="0.03" Z="0.1"/>
|
||||
<Orientation X="0" Y="0" Z="0"/>
|
||||
</c:Transform>
|
||||
@@ -96,7 +104,7 @@
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0.6"/>
|
||||
<Position X="0" Y="0"/>
|
||||
<Scale X="1.7" Y="0.03" Z="0.1"/>
|
||||
<Orientation X="0" Y="1.57" Z="0"/>
|
||||
</c:Transform>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<xs:element ref="c:Model" minOccurs="0"/>
|
||||
<xs:element ref="c:Test" minOccurs="0"/>
|
||||
<xs:element ref="c:RaptorCopter" minOccurs="0"/>
|
||||
<xs:element ref="c:Player" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec4 Color;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
|
||||
#define TILE_SIZE 16
|
||||
|
||||
struct PointLight {
|
||||
vec4 Position;
|
||||
vec4 Color;
|
||||
float Radius;
|
||||
float Intensity;
|
||||
float Falloff;
|
||||
float Padding;
|
||||
};
|
||||
|
||||
layout (std430, binding = 1) buffer LightBuffer
|
||||
{
|
||||
PointLight List[];
|
||||
} PointLights;
|
||||
|
||||
struct LightGrid {
|
||||
float Start;
|
||||
float Amount;
|
||||
vec2 Padding;
|
||||
};
|
||||
|
||||
layout (std430, binding = 2) buffer LightGridBuffer
|
||||
{
|
||||
LightGrid Data[];
|
||||
} LightGrids;
|
||||
|
||||
layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
{
|
||||
float LightIndex[];
|
||||
};
|
||||
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoordinate;
|
||||
vec4 DiffuseColor;
|
||||
}Input;
|
||||
|
||||
out vec4 fragmentColor;
|
||||
|
||||
vec4 scene_ambient = vec4(0.3,0.3,0.3,1);
|
||||
|
||||
struct LightResult {
|
||||
vec4 Diffuse;
|
||||
vec4 Specular;
|
||||
};
|
||||
|
||||
float CalcAttenuation(float radius, float dist) {
|
||||
return 1.0 - smoothstep(radius * 0.3, radius, dist);
|
||||
}
|
||||
|
||||
vec4 CalcSpecular(vec4 lightColor, vec4 viewVec, vec4 lightVec, vec4 normal) {
|
||||
vec4 R = normalize( reflect(-lightVec, normal));
|
||||
float RdotV = max( dot(R, viewVec), 0.0);
|
||||
return lightColor * pow(RdotV, 90.0);
|
||||
}
|
||||
|
||||
vec4 CalcDiffuse(vec4 lightColor, vec4 lightVec, vec4 normal) {
|
||||
float power = max( dot(normal, lightVec), 0.0);
|
||||
return lightColor * power;
|
||||
}
|
||||
|
||||
LightResult CalcPointLight(vec4 lightPos, float lightRadius, vec4 lightColor, float intensity, vec4 viewVec, vec4 position, vec4 normal)
|
||||
{
|
||||
vec4 L = lightPos - position;
|
||||
float dist = length(L);
|
||||
L = normalize(L);
|
||||
|
||||
float attenuation = CalcAttenuation(lightRadius, dist);
|
||||
|
||||
LightResult result;
|
||||
result.Diffuse = CalcDiffuse(lightColor, L, normal) * attenuation * intensity;
|
||||
result.Specular = CalcSpecular(lightColor, viewVec, L, normal) * attenuation * intensity;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texel = texture2D(texture0, Input.TextureCoordinate);
|
||||
vec4 position = V * M * vec4(Input.Position, 1.0);
|
||||
vec4 normal = V * vec4(Input.Normal, 0.0);
|
||||
vec4 viewVec = normalize(-position);
|
||||
|
||||
vec2 tilePos;
|
||||
tilePos.x = int(gl_FragCoord.x/16);
|
||||
tilePos.y = int(gl_FragCoord.y/16);
|
||||
|
||||
LightResult totalLighting;
|
||||
totalLighting.Diffuse = scene_ambient;
|
||||
int currentTile = int(floor(gl_FragCoord.x/TILE_SIZE) + (floor(gl_FragCoord.y/TILE_SIZE) * 80));
|
||||
|
||||
int start = int(LightGrids.Data[currentTile].Start);
|
||||
int amount = int(LightGrids.Data[currentTile].Amount);
|
||||
//for(int i = 0; i < 3; i++)
|
||||
for(int i = start; i < start + amount; i++)
|
||||
{
|
||||
int l = int(LightIndex[i]);
|
||||
|
||||
LightResult result = CalcPointLight(V * PointLights.List[l].Position, PointLights.List[l].Radius, PointLights.List[l].Color, PointLights.List[l].Intensity, viewVec, position, normal);
|
||||
|
||||
totalLighting.Diffuse += result.Diffuse;
|
||||
totalLighting.Specular += result.Specular;
|
||||
}
|
||||
|
||||
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
|
||||
//fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1);
|
||||
//fragmentColor = texel * Input.DiffuseColor * Color;
|
||||
if(int(gl_FragCoord.x)%16 == 0 || int(gl_FragCoord.y)%16 == 0 )
|
||||
{
|
||||
//fragmentColor += vec4(0.5, 0, 0, 0);
|
||||
} else {
|
||||
//fragmentColor += vec4(LightGrids.Data[int(tilePos.x + tilePos.y*80)].Amount/3.0, 0, 0, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 1) in vec3 Normal;
|
||||
layout(location = 2) in vec3 Tangent;
|
||||
layout(location = 3) in vec3 BiTangent;
|
||||
layout(location = 4) in vec2 TextureCoords;
|
||||
layout(location = 5) in vec4 DiffuseVertexColor;
|
||||
layout(location = 6) in vec4 SpecularVertexColor;
|
||||
layout(location = 7) in vec4 BoneIndices1;
|
||||
layout(location = 8) in vec4 BoneIndices2;
|
||||
layout(location = 9) in vec4 BoneWeights1;
|
||||
layout(location = 10) in vec4 BoneWeights2;
|
||||
|
||||
out VertexData{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoordinate;
|
||||
vec4 DiffuseColor;
|
||||
}Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = P*V*M * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = Position;
|
||||
Output.TextureCoordinate = TextureCoords;
|
||||
Output.Normal = Normal;
|
||||
Output.DiffuseColor = DiffuseVertexColor;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#version 430
|
||||
|
||||
#define TILE_SIZE 16
|
||||
#define NUM_TILES 3600
|
||||
|
||||
uniform mat4 P;
|
||||
uniform vec2 ScreenDimensions;
|
||||
|
||||
struct Plane {
|
||||
vec3 Normal;
|
||||
float d;
|
||||
};
|
||||
struct Frustum {
|
||||
Plane Planes[4];
|
||||
};
|
||||
|
||||
layout (std430, binding = 0) buffer FrustumBuffer
|
||||
{
|
||||
Frustum Data[];
|
||||
} Frustums;
|
||||
|
||||
vec4 ConvertToView(vec4 ScreenCoords)
|
||||
{
|
||||
vec2 normalizedScreenCoords = ScreenCoords.xy / ScreenDimensions;
|
||||
vec4 clipSpace = vec4( vec2(normalizedScreenCoords.x, normalizedScreenCoords.y) * 2.0 - 1.0, ScreenCoords.z, ScreenCoords.w);
|
||||
vec4 view = inverse(P) * clipSpace;
|
||||
view = view / view.w;
|
||||
return view;
|
||||
}
|
||||
|
||||
Plane ComputePlane( vec3 p0, vec3 p1, vec3 p2 )
|
||||
{
|
||||
Plane plane;
|
||||
|
||||
vec3 v0 = p1 - p0;
|
||||
vec3 v2 = p2 - p0;
|
||||
|
||||
plane.Normal = normalize( cross( v0, v2 ) );
|
||||
plane.d = dot( vec3(plane.Normal), p0 ); // Always 0 probably
|
||||
return plane;
|
||||
}
|
||||
|
||||
layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main ()
|
||||
{
|
||||
//Top-Left = 0 | Top-Right = 1
|
||||
//Bottom-Left = 2 | Bottom-Right = 3
|
||||
vec4 ScreenCoords[4];
|
||||
ScreenCoords[0] = vec4(gl_GlobalInvocationID.x * TILE_SIZE, (gl_GlobalInvocationID.y + 1) * TILE_SIZE, -1.0, 1.0);
|
||||
ScreenCoords[1] = vec4((gl_GlobalInvocationID.x + 1) * TILE_SIZE, (gl_GlobalInvocationID.y + 1) * TILE_SIZE, -1.0, 1.0);
|
||||
ScreenCoords[2] = vec4(gl_GlobalInvocationID.x * TILE_SIZE, (gl_GlobalInvocationID.y) * TILE_SIZE, -1.0, 1.0);
|
||||
ScreenCoords[3] = vec4((gl_GlobalInvocationID.x + 1) * TILE_SIZE, (gl_GlobalInvocationID.y) * TILE_SIZE, -1.0, 1.0);
|
||||
|
||||
|
||||
|
||||
vec3 ViewVectors[4];
|
||||
for(int i = 0; i < 4; i++) {
|
||||
ViewVectors[i] = vec3(ConvertToView(ScreenCoords[i]));
|
||||
}
|
||||
|
||||
vec3 EyePos = vec3(0.0, 0.0 ,0.0);
|
||||
|
||||
Frustum f;
|
||||
f.Planes[0] = ComputePlane(EyePos, ViewVectors[2], ViewVectors[0]); // left plane
|
||||
f.Planes[1] = ComputePlane(EyePos, ViewVectors[1], ViewVectors[3]); // right plane
|
||||
f.Planes[2] = ComputePlane(EyePos, ViewVectors[0], ViewVectors[1]); // top plane
|
||||
f.Planes[3] = ComputePlane(EyePos, ViewVectors[3], ViewVectors[2]); // bottom plane
|
||||
|
||||
|
||||
|
||||
|
||||
if ( gl_GlobalInvocationID.x < ScreenDimensions.x / TILE_SIZE && gl_GlobalInvocationID.y < ScreenDimensions.y / TILE_SIZE ) { // inside the screen
|
||||
Frustums.Data[gl_GlobalInvocationID.x + gl_GlobalInvocationID.y*80] = f;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
#version 430
|
||||
|
||||
//in uvec3 gl_NumWorkGroups; //contains the number of workgroups that have been dispatched to a compute shader
|
||||
//in uvec3 gl_WorkGroupID; //contains the index of the workgroup currently being operated on by a compute shader
|
||||
//in uvec3 gl_LocalInvocationID; //contains the index of work item currently being operated on by a compute shader
|
||||
//in uvec3 gl_GlobalInvocationID; //contains the global index of work item currently being operated on by a compute shader
|
||||
//in uint gl_LocalInvocationIndex; //contains the local linear index of work item currently being operated on by a compute shader
|
||||
|
||||
|
||||
|
||||
#define MAX_LIGHTS_PER_TILE 1024
|
||||
#define NUM_TILES 3600
|
||||
#define TILE_SIZE 16
|
||||
|
||||
uniform mat4 V;
|
||||
|
||||
struct Plane {
|
||||
vec3 Normal;
|
||||
float d;
|
||||
};
|
||||
struct Frustum {
|
||||
Plane Planes[4];
|
||||
};
|
||||
|
||||
layout (std430, binding = 0) buffer FrustumBuffer
|
||||
{
|
||||
Frustum Data[];
|
||||
} Frustums;
|
||||
|
||||
struct PointLight {
|
||||
vec4 Position;
|
||||
vec4 Color;
|
||||
float Radius;
|
||||
float Intensity;
|
||||
float Falloff;
|
||||
float Padding;
|
||||
};
|
||||
|
||||
layout (std430, binding = 1) buffer LightBuffer
|
||||
{
|
||||
PointLight List[];
|
||||
} PointLights;
|
||||
|
||||
struct LightGrid {
|
||||
float Start;
|
||||
float Amount;
|
||||
vec2 Padding;
|
||||
};
|
||||
|
||||
layout (std430, binding = 2) buffer LightGridBuffer
|
||||
{
|
||||
LightGrid Data[];
|
||||
} LightGrids;
|
||||
|
||||
layout (std430, binding = 3) buffer LightOffsetBuffer
|
||||
{
|
||||
int LightOffset[];
|
||||
};
|
||||
|
||||
layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
{
|
||||
float LightIndex[];
|
||||
};
|
||||
|
||||
shared int GroupLightCount;
|
||||
shared int GroupLightIndexStartOffset;
|
||||
shared int GroupLightIndex[MAX_LIGHTS_PER_TILE];
|
||||
shared Frustum GroupFrustum;
|
||||
int GroupIndex;
|
||||
|
||||
bool SphereInsidePlane(vec3 center, float radius, Plane plane)
|
||||
{
|
||||
return dot(plane.Normal, center) - plane.d > -radius;
|
||||
}
|
||||
|
||||
bool SphereInsideFrustrum(vec3 center, float radius, Frustum frustum/*, float zNear, float zFar*/)
|
||||
{
|
||||
|
||||
//Check depth here
|
||||
//if ( sphere.c.z - sphere.r > zNear || sphere.c.z + sphere.r < zFar )
|
||||
//{
|
||||
// result = false;
|
||||
//}
|
||||
|
||||
for (int i =0; i < 4; i++)
|
||||
{
|
||||
if(! SphereInsidePlane(center, radius, frustum.Planes[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AppendLight(int li)
|
||||
{
|
||||
int index;
|
||||
index = atomicAdd(GroupLightCount, 1);
|
||||
if( index < MAX_LIGHTS_PER_TILE )
|
||||
{
|
||||
GroupLightIndex[index] = int(li);
|
||||
}
|
||||
}
|
||||
|
||||
layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main ()
|
||||
{
|
||||
GroupIndex = int(gl_WorkGroupID.x + (gl_WorkGroupID.y * 80));
|
||||
if(gl_LocalInvocationIndex == 0)
|
||||
{
|
||||
GroupLightCount = 0;
|
||||
GroupFrustum = Frustums.Data[GroupIndex];
|
||||
}
|
||||
|
||||
barrier();
|
||||
memoryBarrierShared();
|
||||
|
||||
for(int i = int(gl_LocalInvocationIndex); i < PointLights.List.length(); i += TILE_SIZE*TILE_SIZE)
|
||||
{
|
||||
PointLight light = PointLights.List[i];
|
||||
|
||||
//if pointlight
|
||||
//Pos i view antagligen
|
||||
if(SphereInsideFrustrum( vec3(V * light.Position), light.Radius, GroupFrustum))
|
||||
{
|
||||
//TODO: Fix transparent and opaque list, and depth test.
|
||||
AppendLight( i );
|
||||
}
|
||||
|
||||
|
||||
//if conelight
|
||||
|
||||
//if directional
|
||||
|
||||
}
|
||||
|
||||
barrier();
|
||||
memoryBarrierShared();
|
||||
|
||||
if(gl_LocalInvocationIndex == 0)
|
||||
{
|
||||
GroupLightIndexStartOffset = atomicAdd(LightOffset[0], GroupLightCount);
|
||||
LightGrids.Data[GroupIndex].Start = GroupLightIndexStartOffset;
|
||||
LightGrids.Data[GroupIndex].Amount = GroupLightCount;
|
||||
}
|
||||
|
||||
barrier();
|
||||
|
||||
|
||||
for (uint i = gl_LocalInvocationIndex; i < GroupLightCount; i += TILE_SIZE * TILE_SIZE )
|
||||
{
|
||||
LightIndex[GroupLightIndexStartOffset + i] = GroupLightIndex[i];
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ source_group(GUI FILES ${SOURCE_FILES_GUI})
|
||||
set(SOURCE_FILES
|
||||
${SOURCE_FILES_Core}
|
||||
${SOURCE_FILES_Core_Util}
|
||||
${SOURCE_FILES_Input}
|
||||
#${SOURCE_FILES_Input}
|
||||
${SOURCE_FILES_Network}
|
||||
${SOURCE_FILES_GUI}
|
||||
${SOURCE_FILES_Rendering}
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
#include "Input/InputProxy.h"
|
||||
#include "Core/World.h"
|
||||
|
||||
//InputProxy::InputProxy(EventBroker* eventBroker)
|
||||
// : m_EventBroker(eventBroker)
|
||||
//{
|
||||
// // Subscribe to events
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &InputProxy::OnMousePress);
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &InputProxy::OnMouseRelease);
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EGamepadAxis, &InputProxy::OnGamepadAxis);
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonDown, &InputProxy::OnGamepadButtonDown);
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonUp, &InputProxy::OnGamepadButtonUp);
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &InputProxy::OnBindKey);
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EBindMouseButton, &InputProxy::OnBindMouseButton);
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadAxis, &InputProxy::OnBindGamepadAxis);
|
||||
// EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadButton, &InputProxy::OnBindGamepadButton);
|
||||
//
|
||||
// SteamController()->Init();
|
||||
//
|
||||
//}
|
||||
//
|
||||
//void InputProxy::Update(double dt)
|
||||
//{
|
||||
// std::array<ControllerHandle_t, STEAM_CONTROLLER_MAX_COUNT> controllers;
|
||||
// int numControllers = SteamController()->GetConnectedControllers(controllers.data());
|
||||
//
|
||||
// ControllerDigitalActionHandle_t debug_reload_handle = SteamController()->GetDigitalActionHandle("debug_reload");
|
||||
// SteamController()->
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnKeyDown(const Events::KeyDown &event)
|
||||
//{
|
||||
// auto range = m_KeyBindings.equal_range(event.KeyCode);
|
||||
// for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
// std::string command;
|
||||
// float value;
|
||||
// std::tie(command, value) = bindingIt->second;
|
||||
// m_CommandKeyboardValues[command][event.KeyCode] = value;
|
||||
// PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnKeyUp(const Events::KeyUp &event)
|
||||
//{
|
||||
// auto range = m_KeyBindings.equal_range(event.KeyCode);
|
||||
// for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
// std::string command;
|
||||
// float value;
|
||||
// std::tie(command, value) = bindingIt->second;
|
||||
// m_CommandKeyboardValues[command][event.KeyCode] = 0;
|
||||
// PublishCommand(1, command, GetCommandTotalValue(command));;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnMousePress(const Events::MousePress &event)
|
||||
//{
|
||||
// auto range = m_MouseButtonBindings.equal_range(event.Button);
|
||||
// for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
// std::string command;
|
||||
// float value;
|
||||
// std::tie(command, value) = bindingIt->second;
|
||||
// m_CommandMouseButtonValues[command][event.Button] = value;
|
||||
// PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnMouseRelease(const Events::MouseRelease &event)
|
||||
//{
|
||||
// auto range = m_MouseButtonBindings.equal_range(event.Button);
|
||||
// for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
// std::string command;
|
||||
// float value;
|
||||
// std::tie(command, value) = bindingIt->second;
|
||||
// m_CommandMouseButtonValues[command][event.Button] = 0;
|
||||
// PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnGamepadAxis(const Events::GamepadAxis &event)
|
||||
//{
|
||||
// auto range = m_GamepadAxisBindings.equal_range(event.Axis);
|
||||
// for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
// std::string command;
|
||||
// float value;
|
||||
// std::tie(command, value) = bindingIt->second;
|
||||
// m_CommandGamepadAxisValues[command][event.Axis] = event.Value * value;
|
||||
// PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnGamepadButtonDown(const Events::GamepadButtonDown &event)
|
||||
//{
|
||||
// auto range = m_GamepadButtonBindings.equal_range(event.Button);
|
||||
// for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
// std::string command;
|
||||
// float value;
|
||||
// std::tie(command, value) = bindingIt->second;
|
||||
// m_CommandGamepadButtonValues[command][event.Button] = value;
|
||||
// PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnGamepadButtonUp(const Events::GamepadButtonUp &event)
|
||||
//{
|
||||
// auto range = m_GamepadButtonBindings.equal_range(event.Button);
|
||||
// for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
// std::string command;
|
||||
// float value;
|
||||
// std::tie(command, value) = bindingIt->second;
|
||||
// m_CommandGamepadButtonValues[command][event.Button] = 0;
|
||||
// PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnBindKey(const Events::BindKey &event)
|
||||
//{
|
||||
// if (event.Command.empty()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// m_KeyBindings.insert(std::make_pair(event.KeyCode, std::make_tuple(event.Command, event.Value)));
|
||||
// LOG_DEBUG("Input: Bound key %i to %s", event.KeyCode, event.Command.c_str());
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnBindMouseButton(const Events::BindMouseButton &event)
|
||||
//{
|
||||
// if (event.Command.empty()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// m_MouseButtonBindings.insert(std::make_pair(event.Button, std::make_tuple(event.Command, event.Value)));
|
||||
// LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str());
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnBindGamepadAxis(const Events::BindGamepadAxis &event)
|
||||
//{
|
||||
// if (event.Command.empty()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// m_GamepadAxisBindings.insert(std::make_pair(event.Axis, std::make_tuple(event.Command, event.Value)));
|
||||
// LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str());
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//bool InputProxy::OnBindGamepadButton(const Events::BindGamepadButton &event)
|
||||
//{
|
||||
// if (event.Command.empty()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// m_GamepadButtonBindings.insert(std::make_pair(event.Button, std::make_tuple(event.Command, event.Value)));
|
||||
// LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str());
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//float InputProxy::GetCommandTotalValue(std::string command)
|
||||
//{
|
||||
// float value = 0.f;
|
||||
//
|
||||
// auto keyboardIt = m_CommandKeyboardValues.find(command);
|
||||
// if (keyboardIt != m_CommandKeyboardValues.end()) {
|
||||
// for (auto &key : keyboardIt->second) {
|
||||
// value += key.second;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// auto mouseButtonIt = m_CommandMouseButtonValues.find(command);
|
||||
// if (mouseButtonIt != m_CommandMouseButtonValues.end()) {
|
||||
// for (auto &button : mouseButtonIt->second) {
|
||||
// value += button.second;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// auto gamepadAxisIt = m_CommandGamepadAxisValues.find(command);
|
||||
// if (gamepadAxisIt != m_CommandGamepadAxisValues.end()) {
|
||||
// for (auto &axis : gamepadAxisIt->second) {
|
||||
// value += axis.second;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// auto gamepadButtonIt = m_CommandGamepadButtonValues.find(command);
|
||||
// if (gamepadButtonIt != m_CommandGamepadButtonValues.end()) {
|
||||
// for (auto &button : gamepadButtonIt->second) {
|
||||
// value += button.second;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return std::max(-1.f, std::min(value, 1.f));
|
||||
//}
|
||||
//
|
||||
//void InputProxy::PublishCommand(int playerID, std::string command, float value)
|
||||
//{
|
||||
// Events::InputCommand e;
|
||||
// e.PlayerID = playerID;
|
||||
// e.Command = command;
|
||||
// e.Value = value;
|
||||
// m_EventBroker->Publish(e);
|
||||
//
|
||||
// LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, playerID);
|
||||
//}
|
||||
@@ -0,0 +1,221 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Input/InputSystem.h"
|
||||
#include "Core/World.h"
|
||||
|
||||
void Systems::InputSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::InputSystem::Initialize()
|
||||
{
|
||||
// Subscribe to events
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Systems::InputSystem::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::InputSystem::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Systems::InputSystem::OnMousePress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Systems::InputSystem::OnMouseRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadAxis, &Systems::InputSystem::OnGamepadAxis);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonDown, &Systems::InputSystem::OnGamepadButtonDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGamepadButtonUp, &Systems::InputSystem::OnGamepadButtonUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindKey, &Systems::InputSystem::OnBindKey);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindMouseButton, &Systems::InputSystem::OnBindMouseButton);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadAxis, &Systems::InputSystem::OnBindGamepadAxis);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EBindGamepadButton, &Systems::InputSystem::OnBindGamepadButton);
|
||||
}
|
||||
|
||||
void Systems::InputSystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
|
||||
{
|
||||
auto range = m_KeyBindings.equal_range(event.KeyCode);
|
||||
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandKeyboardValues[command][event.KeyCode] = value;
|
||||
PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
|
||||
{
|
||||
auto range = m_KeyBindings.equal_range(event.KeyCode);
|
||||
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandKeyboardValues[command][event.KeyCode] = 0;
|
||||
PublishCommand(1, command, GetCommandTotalValue(command));;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
|
||||
{
|
||||
auto range = m_MouseButtonBindings.equal_range(event.Button);
|
||||
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandMouseButtonValues[command][event.Button] = value;
|
||||
PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
|
||||
{
|
||||
auto range = m_MouseButtonBindings.equal_range(event.Button);
|
||||
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandMouseButtonValues[command][event.Button] = 0;
|
||||
PublishCommand(1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event)
|
||||
{
|
||||
auto range = m_GamepadAxisBindings.equal_range(event.Axis);
|
||||
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandGamepadAxisValues[command][event.Axis] = event.Value * value;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &event)
|
||||
{
|
||||
auto range = m_GamepadButtonBindings.equal_range(event.Button);
|
||||
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandGamepadButtonValues[command][event.Button] = value;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &event)
|
||||
{
|
||||
auto range = m_GamepadButtonBindings.equal_range(event.Button);
|
||||
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++) {
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = bindingIt->second;
|
||||
m_CommandGamepadButtonValues[command][event.Button] = 0;
|
||||
PublishCommand(event.GamepadID + 1, command, GetCommandTotalValue(command));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
|
||||
{
|
||||
if (event.Command.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_KeyBindings.insert(std::make_pair(event.KeyCode, std::make_tuple(event.Command, event.Value)));
|
||||
LOG_DEBUG("Input: Bound key %i to %s", event.KeyCode, event.Command.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &event)
|
||||
{
|
||||
if (event.Command.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_MouseButtonBindings.insert(std::make_pair(event.Button, std::make_tuple(event.Command, event.Value)));
|
||||
LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnBindGamepadAxis(const Events::BindGamepadAxis &event)
|
||||
{
|
||||
if (event.Command.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_GamepadAxisBindings.insert(std::make_pair(event.Axis, std::make_tuple(event.Command, event.Value)));
|
||||
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::InputSystem::OnBindGamepadButton(const Events::BindGamepadButton &event)
|
||||
{
|
||||
if (event.Command.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_GamepadButtonBindings.insert(std::make_pair(event.Button, std::make_tuple(event.Command, event.Value)));
|
||||
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float Systems::InputSystem::GetCommandTotalValue(std::string command)
|
||||
{
|
||||
float value = 0.f;
|
||||
|
||||
auto keyboardIt = m_CommandKeyboardValues.find(command);
|
||||
if (keyboardIt != m_CommandKeyboardValues.end()) {
|
||||
for (auto &key : keyboardIt->second) {
|
||||
value += key.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto mouseButtonIt = m_CommandMouseButtonValues.find(command);
|
||||
if (mouseButtonIt != m_CommandMouseButtonValues.end()) {
|
||||
for (auto &button : mouseButtonIt->second) {
|
||||
value += button.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto gamepadAxisIt = m_CommandGamepadAxisValues.find(command);
|
||||
if (gamepadAxisIt != m_CommandGamepadAxisValues.end()) {
|
||||
for (auto &axis : gamepadAxisIt->second) {
|
||||
value += axis.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto gamepadButtonIt = m_CommandGamepadButtonValues.find(command);
|
||||
if (gamepadButtonIt != m_CommandGamepadButtonValues.end()) {
|
||||
for (auto &button : gamepadButtonIt->second) {
|
||||
value += button.second;
|
||||
}
|
||||
}
|
||||
|
||||
return std::max(-1.f, std::min(value, 1.f));
|
||||
}
|
||||
|
||||
void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value)
|
||||
{
|
||||
Events::InputCommand e;
|
||||
e.PlayerID = playerID;
|
||||
e.Command = command;
|
||||
e.Value = value;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, playerID);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "Rendering/DrawScenePass.h"
|
||||
|
||||
DrawScenePass::DrawScenePass(IRenderer* renderer)
|
||||
{
|
||||
m_Renderer = renderer;
|
||||
InitializeTextures();
|
||||
InitializeShaderPrograms();
|
||||
}
|
||||
|
||||
void DrawScenePass::InitializeTextures()
|
||||
{
|
||||
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png");
|
||||
}
|
||||
|
||||
void DrawScenePass::InitializeShaderPrograms()
|
||||
{
|
||||
//Gör så att shaders är en resource, tex som texture classen. Konstruktorn måste vara privat.
|
||||
m_BasicForwardProgram = ResourceManager::Load<ShaderProgram>("#BasicForwardProgram");
|
||||
|
||||
m_BasicForwardProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/BasicForward.vert.glsl")));
|
||||
m_BasicForwardProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/BasicForward.frag.glsl")));
|
||||
m_BasicForwardProgram->Compile();
|
||||
m_BasicForwardProgram->Link();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DrawScenePass::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
GLERROR("DrawScenePass::Draw: Pre");
|
||||
|
||||
DrawScenePassState state;
|
||||
m_BasicForwardProgram->Bind();
|
||||
|
||||
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
if (modelJob) {
|
||||
GLuint ShaderHandle = m_BasicForwardProgram->GetHandle();
|
||||
|
||||
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->ModelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix()));
|
||||
glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||
|
||||
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
|
||||
if (modelJob->DiffuseTexture != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
}
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
GLERROR("DrawScenePass::Draw: End");
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "Rendering/DrawScenePassState.h"
|
||||
|
||||
|
||||
DrawScenePassState::DrawScenePassState()
|
||||
{
|
||||
GLERROR("---");
|
||||
BindBuffer(0);
|
||||
GLERROR("---");
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
ClearColor(glm::vec4(255.f / 255, 163.f / 255, 176.f / 255, 0.f));
|
||||
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
DrawScenePassState::~DrawScenePassState()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -48,13 +48,21 @@ void FrameBuffer::Generate()
|
||||
switch ((*it)->m_ResourceType) {
|
||||
case GL_TEXTURE_2D:
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0);
|
||||
GLERROR("FrameBuffer generate: glFramebufferTexture2D");
|
||||
|
||||
break;
|
||||
case GL_RENDERBUFFER:
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle);
|
||||
GLERROR("FrameBuffer generate: glFramebufferRenderbuffer");
|
||||
if ( (*it)->m_Attachment != GL_COLOR_ATTACHMENT0 ||
|
||||
(*it)->m_Attachment != GL_DEPTH_ATTACHMENT ||
|
||||
(*it)->m_Attachment != GL_STENCIL_ATTACHMENT)
|
||||
{
|
||||
LOG_ERROR("RenderBuffer Attachment not valid.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
GLERROR("FrameBuffer generate");
|
||||
|
||||
if ((*it)->m_Attachment != GL_DEPTH_ATTACHMENT) {
|
||||
attachments.push_back((*it)->m_Attachment);
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
#include "Rendering/PickingPass.h"
|
||||
|
||||
PickingPass::PickingPass(IRenderer* renderer, EventBroker* eb)
|
||||
{
|
||||
m_Renderer = renderer;
|
||||
m_EventBroker = eb;
|
||||
|
||||
InitializeTextures();
|
||||
InitializeFrameBuffers();
|
||||
InitializeShaderPrograms();
|
||||
}
|
||||
|
||||
PickingPass::~PickingPass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PickingPass::InitializeTextures()
|
||||
{
|
||||
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
||||
glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
|
||||
}
|
||||
|
||||
void PickingPass::InitializeFrameBuffers()
|
||||
{
|
||||
glGenRenderbuffers(1, &m_DepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
|
||||
|
||||
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_PickingTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_PickingBuffer.Generate();
|
||||
}
|
||||
|
||||
void PickingPass::InitializeShaderPrograms()
|
||||
{
|
||||
m_PickingProgram = ResourceManager::Load<ShaderProgram>("#PickingProgram");
|
||||
|
||||
m_PickingProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Picking.vert.glsl")));
|
||||
m_PickingProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Picking.frag.glsl")));
|
||||
m_PickingProgram->Compile();
|
||||
m_PickingProgram->BindFragDataLocation(0, "TextureFragment");
|
||||
m_PickingProgram->Link();
|
||||
}
|
||||
|
||||
void PickingPass::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
m_PickingColorsToEntity.clear();
|
||||
PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle());
|
||||
|
||||
int r = 1;
|
||||
int g = 0;
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
|
||||
GLuint ShaderHandle = m_PickingProgram->GetHandle();
|
||||
m_PickingProgram->Bind();
|
||||
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
|
||||
if (modelJob) {
|
||||
//---------------
|
||||
//TODO: Renderer: IMPORTANT: Fixa detta så det inte loopar igenom listan varje frame.
|
||||
//---------------
|
||||
int pickColor[2] = { r, g };
|
||||
for (auto i : m_PickingColorsToEntity) {
|
||||
if (modelJob->Entity == i.second) {
|
||||
pickColor[0] = i.first.x;
|
||||
pickColor[1] = i.first.y;
|
||||
r -= 1;
|
||||
}
|
||||
}
|
||||
m_PickingColorsToEntity[glm::vec2(pickColor[0], pickColor[1])] = modelJob->Entity;
|
||||
|
||||
//Render picking stuff
|
||||
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->ModelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, nullptr, modelJob->StartIndex);
|
||||
r += 1;
|
||||
if (r > 255) {
|
||||
r = 0;
|
||||
g += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_PickingBuffer.Unbind();
|
||||
GLERROR("PickingPass Error");
|
||||
|
||||
//Publish pick event every frame with the pick data that can be picked by the event
|
||||
Events::Picking pickEvent = Events::Picking(
|
||||
&m_PickingBuffer,
|
||||
&m_DepthBuffer,
|
||||
m_Renderer->Camera()->ProjectionMatrix(),
|
||||
m_Renderer->Camera()->ViewMatrix(),
|
||||
m_Renderer->Resolution(),
|
||||
&m_PickingColorsToEntity);
|
||||
|
||||
m_EventBroker->Publish(pickEvent);
|
||||
}
|
||||
|
||||
void PickingPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
|
||||
{
|
||||
//TODO: Renderer: Make this in a sparate class
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);//TODO: Renderer: Fix the precision and Resolution
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "Rendering/PickingPassState.h"
|
||||
|
||||
|
||||
PickingPassState::PickingPassState(GLuint frameBuffer)
|
||||
{
|
||||
GLERROR("---2");
|
||||
BindBuffer(frameBuffer);
|
||||
GLERROR("---3");
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
|
||||
glm::vec4 clearColor = glm::vec4(0.f);
|
||||
ClearColor(clearColor);
|
||||
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
PickingPassState::~PickingPassState()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ glm::vec3 RenderQueueFactory::AbsolutePosition(World* world, EntityID entity)
|
||||
|
||||
do {
|
||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||
position += AbsoluteOrientation(world, entity) * (glm::vec3)transform["Position"];
|
||||
position += (glm::vec3)transform["Position"];
|
||||
entity = world->GetParent(entity);
|
||||
} while (entity != 0);
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
#include "Rendering/RenderState.h"
|
||||
|
||||
RenderState::RenderState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool RenderState::Enable(GLenum GLEnable)
|
||||
{
|
||||
if(glIsEnabled(GLEnable))
|
||||
{
|
||||
//LOG_WARNING("Trying to enable somthing that is already enabled.");
|
||||
return false;
|
||||
}
|
||||
m_Enables.push_back(GLEnable);
|
||||
glEnable(GLEnable);
|
||||
if (GLERROR("RenderState::Enable"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderState::CullFace(GLenum GLCullFace)
|
||||
{
|
||||
if(!glIsEnabled(GL_CULL_FACE))
|
||||
{
|
||||
//LOG_ERROR("Setting GL_CULL_FACE without enabling it.");
|
||||
Enable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
glCullFace(GLCullFace);
|
||||
if (GLERROR("RenderState::CullFace"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderState::ClearColor(glm::vec4 color)
|
||||
{
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, &m_preClearColor[0]);
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
if (GLERROR("RenderState::ClearColor")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderState::Clear(GLbitfield mask)
|
||||
{
|
||||
glClear(mask);
|
||||
if (GLERROR("RenderState::Clear")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderState::BindBuffer(GLint buffer)
|
||||
{
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_preBuffer);
|
||||
if (buffer == m_preBuffer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, buffer);
|
||||
if (GLERROR("RenderState::BindBuffer"))
|
||||
{
|
||||
printf("BufferID: %i\npreBufferID: %i\n", buffer, m_preBuffer);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderState::~RenderState()
|
||||
{
|
||||
GLERROR("RenderState::~RenderState Pre");
|
||||
GLint n_buffer = -1;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &n_buffer);
|
||||
|
||||
//Set cullface to default
|
||||
if (glIsEnabled(GL_CULL_FACE)) {
|
||||
glCullFace(GL_BACK);
|
||||
}
|
||||
GLERROR("RenderState::~RenderState glCullFace");
|
||||
|
||||
//Set color to default
|
||||
glClearColor(m_preClearColor[0], m_preClearColor[1], m_preClearColor[2], m_preClearColor[3]);
|
||||
GLERROR("RenderState::~RenderState glClearColor");
|
||||
|
||||
//Disable Enables
|
||||
for (auto i : m_Enables)
|
||||
{
|
||||
glDisable(i);
|
||||
}
|
||||
GLERROR("RenderState::~RenderState glDisable");
|
||||
|
||||
if(m_preBuffer != 0)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
m_Enables.clear();
|
||||
GLERROR("RenderState::~RenderState glBindFramebuffer");
|
||||
}
|
||||
|
||||
+175
-167
@@ -4,17 +4,19 @@ void Renderer::Initialize()
|
||||
{
|
||||
InitializeWindow();
|
||||
// Create default camera
|
||||
m_DefaultCamera = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 10));
|
||||
m_DefaultCamera = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(90.0f), 0.01f, 5000.f);
|
||||
m_DefaultCamera->SetPosition(glm::vec3(0, 1, 10));
|
||||
if (m_Camera == nullptr) {
|
||||
m_Camera = m_DefaultCamera;
|
||||
}
|
||||
TEMPCreateLights();
|
||||
InitializeRenderPasses();
|
||||
|
||||
glfwSwapInterval(m_VSYNC);
|
||||
InitializeShaders();
|
||||
InitializeTextures();
|
||||
InitializeFrameBuffers();
|
||||
|
||||
InitializeSSBOs();
|
||||
CalculateFrustum();
|
||||
|
||||
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.obj");
|
||||
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
|
||||
@@ -63,22 +65,29 @@ void Renderer::InitializeWindow()
|
||||
|
||||
void Renderer::InitializeShaders()
|
||||
{
|
||||
m_BasicForwardProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/BasicForward.vert.glsl")));
|
||||
m_BasicForwardProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/BasicForward.frag.glsl")));
|
||||
m_BasicForwardProgram.Compile();
|
||||
m_BasicForwardProgram.Link();
|
||||
m_BasicForwardProgram = ResourceManager::Load<ShaderProgram>("#m_BasicForwardProgram");
|
||||
|
||||
m_PickingProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Picking.vert.glsl")));
|
||||
m_PickingProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Picking.frag.glsl")));
|
||||
m_PickingProgram.Compile();
|
||||
m_PickingProgram.BindFragDataLocation(0, "TextureFragment");
|
||||
m_PickingProgram.Link();
|
||||
m_DrawScreenQuadProgram = ResourceManager::Load<ShaderProgram>("#DrawScreenQuadProgram");
|
||||
m_DrawScreenQuadProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/DrawScreenQuad.vert.glsl")));
|
||||
m_DrawScreenQuadProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/DrawScreenQuad.frag.glsl")));
|
||||
m_DrawScreenQuadProgram->Compile();
|
||||
m_DrawScreenQuadProgram->Link();
|
||||
|
||||
m_DrawScreenQuadProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/DrawScreenQuad.vert.glsl")));
|
||||
m_DrawScreenQuadProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/DrawScreenQuad.frag.glsl")));
|
||||
m_DrawScreenQuadProgram.Compile();
|
||||
m_DrawScreenQuadProgram.Link();
|
||||
m_CalculateFrustumProgram = ResourceManager::Load<ShaderProgram>("#CalculateFrustumProgram");
|
||||
m_CalculateFrustumProgram->AddShader(std::shared_ptr<Shader>(new ComputeShader("Shaders/GridFrustum.comp.glsl")));
|
||||
m_CalculateFrustumProgram->Compile();
|
||||
m_CalculateFrustumProgram->Link();
|
||||
|
||||
m_LightCullProgram = ResourceManager::Load<ShaderProgram>("#LightCullProgram");
|
||||
m_LightCullProgram->AddShader(std::shared_ptr<Shader>(new ComputeShader("Shaders/cullLights.comp.glsl")));
|
||||
m_LightCullProgram->Compile();
|
||||
m_LightCullProgram->Link();
|
||||
|
||||
m_ForwardPlusProgram = ResourceManager::Load<ShaderProgram>("#ForwardPlusProgram");
|
||||
m_ForwardPlusProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlus.vert.glsl")));
|
||||
m_ForwardPlusProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlus.frag.glsl")));
|
||||
m_ForwardPlusProgram->Compile();
|
||||
m_ForwardPlusProgram->Link();
|
||||
}
|
||||
|
||||
void Renderer::InputUpdate(double dt)
|
||||
@@ -112,7 +121,6 @@ void Renderer::InputUpdate(double dt)
|
||||
m_CameraMoveSpeed = 0.5f;
|
||||
}
|
||||
|
||||
|
||||
static double mousePosX, mousePosY;
|
||||
glfwGetCursorPos(m_Window, &mousePosX, &mousePosY);
|
||||
|
||||
@@ -142,38 +150,174 @@ void Renderer::Update(double dt)
|
||||
{
|
||||
m_EventBroker->Process<Renderer>();
|
||||
InputUpdate(dt);
|
||||
|
||||
}
|
||||
|
||||
void Renderer::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
//TODO: Renderer: Kanske borde vara längst upp i update.
|
||||
PickingPass(rq);
|
||||
DrawScreenQuad(m_PickingTexture);
|
||||
m_PickingPass->Draw(rq);
|
||||
//DrawScreenQuad(m_PickingPass->PickingTexture());
|
||||
CullLights();
|
||||
|
||||
DrawScene(rq);
|
||||
//m_DrawScenePass->Draw(rq);
|
||||
DrawForwardPlus(rq);
|
||||
GLERROR("Renderer::Draw m_DrawScenePass->Draw");
|
||||
glfwSwapBuffers(m_Window);
|
||||
}
|
||||
|
||||
void Renderer::DrawScene(RenderQueueCollection& rq)
|
||||
void Renderer::DrawScreenQuad(GLuint textureToDraw)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
//TODO: Render: Clean up draw code
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
||||
m_DrawScreenQuadProgram->Bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, textureToDraw);
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->TextureGroups[0].EndIndex - m_ScreenQuad->TextureGroups[0].StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->TextureGroups[0].StartIndex);
|
||||
}
|
||||
|
||||
void Renderer::InitializeTextures()
|
||||
{
|
||||
m_ErrorTexture=ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
||||
m_WhiteTexture=ResourceManager::Load<Texture>("Textures/Core/Blank.png");
|
||||
}
|
||||
|
||||
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, NULL);//TODO: Renderer: Fix the precision and Resolution
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
void Renderer::InitializeSSBOs()
|
||||
{
|
||||
printf("Size: %i\n", sizeof(m_Frustums));
|
||||
glGenBuffers(1, &m_FrustumSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_FrustumSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_Frustums), &m_Frustums, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
GLERROR("m_FrustumSSBO");
|
||||
|
||||
glGenBuffers(1, &m_LightSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_PointLights), &m_PointLights, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
GLERROR("m_LightSSBO");
|
||||
|
||||
|
||||
|
||||
glGenBuffers(1, &m_LightGridSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightGridSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightGrid), &m_LightGrid, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
GLERROR("m_LightGridSSBO");
|
||||
|
||||
|
||||
glGenBuffers(1, &m_LightOffsetSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
GLERROR("m_LightOffsetSSBO");
|
||||
|
||||
|
||||
glGenBuffers(1, &m_LightIndexSSBO);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightIndexSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightIndex), &m_LightIndex, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
GLERROR("m_LightIndexSSBO");
|
||||
|
||||
}
|
||||
|
||||
void Renderer::InitializeRenderPasses()
|
||||
{
|
||||
m_DrawScenePass = new DrawScenePass(this);
|
||||
m_PickingPass = new PickingPass(this, m_EventBroker);
|
||||
}
|
||||
|
||||
void Renderer::CalculateFrustum()
|
||||
{
|
||||
GLERROR("CalculateFrustum Error: Pre");
|
||||
|
||||
m_CalculateFrustumProgram->Bind();
|
||||
|
||||
|
||||
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "P"), 1, false, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||
glUniform2f(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "ScreenDimensions"), m_Resolution.Width, m_Resolution.Height);
|
||||
glDispatchCompute(5, 3, 1);
|
||||
|
||||
GLERROR("CalculateFrustum Error: End");
|
||||
}
|
||||
|
||||
void Renderer::TEMPCreateLights()
|
||||
{
|
||||
for (int i = 0; i < NUM_LIGHTS; i++)
|
||||
{
|
||||
glm::vec3 pos = glm::vec3(cos(i) * i/10.f , 0.5f, sin(i) * i/10.f);
|
||||
m_PointLights[i].Position = glm::vec4(pos, 1.f);
|
||||
m_PointLights[i].Color = glm::vec4(rand()%255 / 255.f, rand()%255 / 255.f, rand()%255 / 255.f, 1.f);
|
||||
m_PointLights[i].Radius = 5.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::CullLights()
|
||||
{
|
||||
GLERROR("CullLights Error: Pre");
|
||||
m_LightOffset = 0;
|
||||
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_LightOffsetSSBO);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_LightOffset), &m_LightOffset, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
|
||||
|
||||
m_LightCullProgram->Bind();
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_LightCullProgram->GetHandle(), "V"), 1, false, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightSSBO);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
|
||||
glDispatchCompute(m_Resolution.Width / TILE_SIZE, m_Resolution.Height / TILE_SIZE, 1);
|
||||
|
||||
GLERROR("CullLights Error: End");
|
||||
|
||||
}
|
||||
|
||||
void Renderer::DrawForwardPlus(RenderQueueCollection& rq)
|
||||
{
|
||||
GLERROR("Renderer::DrawForwardPlus: Pre");
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 0.f);
|
||||
glClearColor(200.f / 255, 0.f / 255, 200.f / 255, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_ForwardPlusProgram->Bind();
|
||||
GLuint ShaderHandle = m_ForwardPlusProgram->GetHandle();
|
||||
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightSSBO);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
if (modelJob) {
|
||||
GLuint ShaderHandle = m_BasicForwardProgram.GetHandle();
|
||||
|
||||
m_BasicForwardProgram.Bind();
|
||||
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->ModelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||
@@ -196,142 +340,6 @@ void Renderer::DrawScene(RenderQueueCollection& rq)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
GLERROR("DrawScene Error");
|
||||
GLERROR("Renderer::DrawForwardPlus: End");
|
||||
}
|
||||
|
||||
void Renderer::PickingPass(RenderQueueCollection& rq)
|
||||
{
|
||||
m_PickingColorsToEntity.clear();
|
||||
m_PickingBuffer.Bind();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
int r = 1;
|
||||
int g = 0;
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
|
||||
|
||||
GLuint ShaderHandle = m_PickingProgram.GetHandle();
|
||||
m_PickingProgram.Bind();
|
||||
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
|
||||
if (modelJob) {
|
||||
//---------------
|
||||
//TODO: Renderer: IMPORTANT: Fixa detta så det inte loopar igenom listan varje frame.
|
||||
//---------------
|
||||
int pickColor[2] = { r, g };
|
||||
for (auto i : m_PickingColorsToEntity) {
|
||||
if(modelJob->Entity == i.second) {
|
||||
pickColor[0] = i.first.x;
|
||||
pickColor[1] = i.first.y;
|
||||
r -= 1;
|
||||
}
|
||||
}
|
||||
m_PickingColorsToEntity[glm::vec2(pickColor[0], pickColor[1])] = modelJob->Entity;
|
||||
|
||||
|
||||
//Render picking stuff
|
||||
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->ModelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
r += 1;
|
||||
if(r > 255) {
|
||||
r = 0;
|
||||
g += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_PickingBuffer.Unbind();
|
||||
GLERROR("PickingPass Error");
|
||||
|
||||
//Publish pick event every frame with the pick data that can be picked by the event
|
||||
Events::Picking pickEvent = Events::Picking(
|
||||
&m_PickingBuffer,
|
||||
&m_DepthBuffer,
|
||||
m_Camera->ProjectionMatrix(),
|
||||
m_Camera->ViewMatrix(),
|
||||
m_Resolution,
|
||||
&m_PickingColorsToEntity);
|
||||
|
||||
m_EventBroker->Publish(pickEvent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Renderer::DrawScreenQuad(GLuint textureToDraw)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
||||
m_DrawScreenQuadProgram.Bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, textureToDraw);
|
||||
|
||||
glBindVertexArray(m_ScreenQuad->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->TextureGroups[0].EndIndex - m_ScreenQuad->TextureGroups[0].StartIndex +1
|
||||
, GL_UNSIGNED_INT, 0, m_ScreenQuad->TextureGroups[0].StartIndex);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::InitializeTextures()
|
||||
{
|
||||
m_ErrorTexture=ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
||||
m_WhiteTexture=ResourceManager::Load<Texture>("Textures/Core/Blank.png");
|
||||
/*
|
||||
glGenTextures(1, &m_PickingTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_PickingTexture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, m_Resolution.Width, m_Resolution.Height, 0, GL_RG, GL_FLOAT, NULL);//TODO: Renderer: Fix the precision and Resolution
|
||||
GLERROR("m_PickingTexture initialization failed");
|
||||
*/
|
||||
|
||||
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
||||
glm::vec2(m_Resolution.Width, m_Resolution.Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
|
||||
}
|
||||
|
||||
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, NULL);//TODO: Renderer: Fix the precision and Resolution
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Renderer::InitializeFrameBuffers()//TODO: Renderer: Get this to a better location, as its really big
|
||||
{
|
||||
glGenRenderbuffers(1, &m_DepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Resolution.Width, m_Resolution.Height);
|
||||
|
||||
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_PickingTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_PickingBuffer.Generate();
|
||||
}
|
||||
@@ -19,6 +19,7 @@ file(GLOB SOURCE_FILES
|
||||
set(SOURCE_FILES
|
||||
${SOURCE_FILES}
|
||||
"Game.cpp"
|
||||
"PlayerSystem.cpp"
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
|
||||
+43
-71
@@ -2,43 +2,40 @@
|
||||
|
||||
Game::Game(int argc, char* argv[])
|
||||
{
|
||||
bool steamResult = SteamAPI_Init();
|
||||
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
ResourceManager::RegisterType<Model>("Model");
|
||||
ResourceManager::RegisterType<Texture>("Texture");
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
ResourceManager::RegisterType<Model>("Model");
|
||||
ResourceManager::RegisterType<Texture>("Texture");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
|
||||
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||
|
||||
// Create the core event broker
|
||||
m_EventBroker = new EventBroker();
|
||||
// Create the core event broker
|
||||
m_EventBroker = new EventBroker();
|
||||
|
||||
m_RenderQueueFactory = new RenderQueueFactory();
|
||||
|
||||
// Create the renderer
|
||||
m_Renderer = new Renderer(m_EventBroker);
|
||||
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
||||
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
||||
m_Renderer->SetResolution(Rectangle(
|
||||
0,
|
||||
0,
|
||||
m_Config->Get<int>("Video.Width", 1280),
|
||||
m_Config->Get<int>("Video.Height", 720)
|
||||
));
|
||||
m_Renderer->Initialize();
|
||||
// Create the renderer
|
||||
m_Renderer = new Renderer(m_EventBroker);
|
||||
m_Renderer->SetFullscreen(m_Config->Get<bool>("Video.Fullscreen", false));
|
||||
m_Renderer->SetVSYNC(m_Config->Get<bool>("Video.VSYNC", false));
|
||||
m_Renderer->SetResolution(Rectangle(
|
||||
0,
|
||||
0,
|
||||
m_Config->Get<int>("Video.Width", 1280),
|
||||
m_Config->Get<int>("Video.Height", 720)
|
||||
));
|
||||
m_Renderer->Initialize();
|
||||
m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
|
||||
|
||||
// Create input manager
|
||||
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
|
||||
m_InputProxy = new InputProxy(m_EventBroker);
|
||||
m_InputProxy->AddHandler<KeyboardInputHandler>();
|
||||
m_InputProxy->AddHandler<SteamControllerInputHandler>();
|
||||
// Create input manager
|
||||
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
|
||||
|
||||
// Create the root level GUI frame
|
||||
m_FrameStack = new GUI::Frame(m_EventBroker);
|
||||
m_FrameStack->Width = m_Renderer->Resolution().Width;
|
||||
m_FrameStack->Height = m_Renderer->Resolution().Height;
|
||||
// Create the root level GUI frame
|
||||
m_FrameStack = new GUI::Frame(m_EventBroker);
|
||||
m_FrameStack->Width = m_Renderer->Resolution().Width;
|
||||
m_FrameStack->Height = m_Renderer->Resolution().Height;
|
||||
|
||||
// Create a world
|
||||
m_World = new World();
|
||||
@@ -46,38 +43,34 @@ Game::Game(int argc, char* argv[])
|
||||
if (!mapToLoad.empty()) {
|
||||
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
|
||||
}
|
||||
|
||||
|
||||
// Create system pipeline
|
||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
|
||||
m_SystemPipeline->AddSystem<PlayerSystem>();
|
||||
|
||||
m_LastTime = glfwGetTime();
|
||||
|
||||
|
||||
m_LastTime = glfwGetTime();
|
||||
|
||||
testIntialize();
|
||||
}
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
delete m_FrameStack;
|
||||
delete m_EventBroker;
|
||||
delete m_FrameStack;
|
||||
delete m_EventBroker;
|
||||
}
|
||||
|
||||
void Game::Tick()
|
||||
{
|
||||
double currentTime = glfwGetTime();
|
||||
double dt = currentTime - m_LastTime;
|
||||
m_LastTime = currentTime;
|
||||
double currentTime = glfwGetTime();
|
||||
double dt = currentTime - m_LastTime;
|
||||
m_LastTime = currentTime;
|
||||
|
||||
SteamAPI_RunCallbacks();
|
||||
|
||||
// Handle input in a weird looking but responsive way
|
||||
m_EventBroker->Swap();
|
||||
m_InputManager->Update(dt);
|
||||
m_EventBroker->Swap();
|
||||
m_InputProxy->Update(dt);
|
||||
m_InputManager->Update(dt);
|
||||
m_EventBroker->Swap();
|
||||
m_InputProxy->Process();
|
||||
m_EventBroker->Swap();
|
||||
|
||||
// Iterate through systems and update world!
|
||||
m_SystemPipeline->Update(m_World, dt);
|
||||
@@ -85,12 +78,13 @@ void Game::Tick()
|
||||
m_Renderer->Update(dt);
|
||||
|
||||
m_RenderQueueFactory->Update(m_World);
|
||||
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
|
||||
GLERROR("Game::Tick m_RenderQueueFactory->Update");
|
||||
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
|
||||
GLERROR("Game::Tick m_Renderer->Draw");
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
glfwPollEvents();
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
|
||||
@@ -112,28 +106,6 @@ bool Game::testOnKeyUp(const Events::KeyUp& e)
|
||||
void Game::testIntialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Game::testOnKeyUp);
|
||||
|
||||
{
|
||||
Events::BindOrigin e;
|
||||
e.Origin = "R";
|
||||
e.Command = "DebugReload";
|
||||
e.Value = 1.f;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
{
|
||||
Events::BindOrigin e;
|
||||
e.Origin = "SteamController";
|
||||
e.Command = "DebugReload";
|
||||
e.Value = 1.f;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
{
|
||||
Events::BindOrigin e;
|
||||
e.Origin = "X";
|
||||
e.Command = "DebugReload";
|
||||
e.Value = 1.f;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Game::testTick(double dt)
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "PlayerSystem.h"
|
||||
|
||||
|
||||
void PlayerSystem::Update(World * world, ComponentWrapper & player, double dt)
|
||||
{
|
||||
if (input.Forward) {
|
||||
m_Direction.z = -1;
|
||||
} else if (input.Back) {
|
||||
m_Direction.z = 1;
|
||||
} else {
|
||||
m_Direction.z = 0;
|
||||
}
|
||||
if (input.Left) {
|
||||
m_Direction.x = -1;
|
||||
} else if (input.Right) {
|
||||
m_Direction.x = 1;
|
||||
} else {
|
||||
m_Direction.x = 0;
|
||||
}
|
||||
m_EventBroker->Process<PlayerSystem>();
|
||||
ComponentWrapper& transform = world->GetComponent(player.EntityID, "Transform");
|
||||
(glm::vec3&)player["Velocity"] = m_Speed * float(dt) * m_Direction;
|
||||
(glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"];
|
||||
}
|
||||
|
||||
bool PlayerSystem::OnKeyDown(const Events::KeyDown & event)
|
||||
{
|
||||
if (event.KeyCode == GLFW_KEY_W) {
|
||||
input.Forward = true;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_A) {
|
||||
input.Left = true;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_S) {
|
||||
input.Back = true;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_D) {
|
||||
input.Right = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlayerSystem::OnKeyUp(const Events::KeyUp & event)
|
||||
{
|
||||
if (event.KeyCode == GLFW_KEY_W) {
|
||||
input.Forward = false;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_A) {
|
||||
input.Left = false;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_S) {
|
||||
input.Back = false;
|
||||
}
|
||||
if (event.KeyCode == GLFW_KEY_D) {
|
||||
input.Right = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user