Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 589ca45936 | |||
| 0cff07101c |
@@ -10,11 +10,10 @@ Libraries bundled along with binaries for Windows (MSVC14), available as a submo
|
||||
| **[zlib](http://www.zlib.net)** | 1.28 | [zlib License](http://www.zlib.net/zlib_license.html) |
|
||||
| **[libpng](http://www.libpng.org/pub/png/libpng.html)** | 1.6.19 | [libpng License](http://www.libpng.org/pub/png/src/libpng-LICENSE.txt) |
|
||||
| **[Xerces-C++](https://xerces.apache.org/xerces-c)** | 3.1.2 | [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0) |
|
||||
| **[ImGui](https://github.com/ocornut/imgui)** | 2015-12-12 | [MIT License](https://github.com/ocornut/imgui/blob/de3a154f3801de22c8e0bd2aeabf663a70c05972/LICENSE) |
|
||||
|
||||
#### External libraries
|
||||
Libraries that are too big to be bundled with the project.
|
||||
|
||||
| Project | Version | License | Root folder environment variable (Windows) |
|
||||
| ---------------------------------------------------------- | ----------- | --------------------------------------------------------------------------- | ------------------------------------------ |
|
||||
| **[Boost](http://www.boost.org)** | 1.60.0+ | [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt) | BOOST_ROOT |
|
||||
| **[Boost](http://www.boost.org)** | 1.59.0+ | [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt) | BOOST_ROOT |
|
||||
|
||||
+1
-1
Submodule assets updated: 673d4a4e4c...b37468222e
+1
-1
Submodule deps updated: 1ae6ba5b12...1b478d3159
@@ -54,8 +54,6 @@ public:
|
||||
ComponentWrapper Allocate(EntityID entity);
|
||||
// Get the component belonging to a specific entity
|
||||
ComponentWrapper GetByEntity(EntityID ent);
|
||||
// Returns true if the pool contains a component for the specified entity
|
||||
bool KnowsEntity(EntityID ent);
|
||||
// Delete a component and free its memory
|
||||
void Delete(ComponentWrapper& wrapper);
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef EFileDropped_h__
|
||||
#define EFileDropped_h__
|
||||
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct FileDropped : Event
|
||||
{
|
||||
std::string Path;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef Events_KeyboardChar_h__
|
||||
#define Events_KeyboardChar_h__
|
||||
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct KeyboardChar : Event
|
||||
{
|
||||
double Timestamp = 0.f;
|
||||
unsigned int Char = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef Events_MouseScroll_h__
|
||||
#define Events_MouseScroll_h__
|
||||
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct MouseScroll : Event
|
||||
{
|
||||
double DeltaX;
|
||||
double DeltaY;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,15 +8,12 @@
|
||||
#include "EventBroker.h"
|
||||
#include "EKeyDown.h"
|
||||
#include "EKeyUp.h"
|
||||
#include "EKeyboardChar.h"
|
||||
#include "EMousePress.h"
|
||||
#include "EMouseRelease.h"
|
||||
#include "EMouseMove.h"
|
||||
#include "EMouseScroll.h"
|
||||
#include "ELockMouse.h"
|
||||
#include "EGamepadAxis.h"
|
||||
#include "EGamepadButton.h"
|
||||
#include "EFileDropped.h"
|
||||
|
||||
class InputManager
|
||||
{
|
||||
@@ -36,7 +33,6 @@ public:
|
||||
|
||||
void Initialize();
|
||||
|
||||
static const short MAX_GAMEPADS = 4;
|
||||
|
||||
void Update(double dt);
|
||||
|
||||
@@ -53,12 +49,6 @@ private:
|
||||
std::array<int, GLFW_KEY_LAST+1> m_LastKeyState;
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState;
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_LastMouseState;
|
||||
typedef std::array<float, static_cast<int>(Gamepad::Axis::LAST) + 1> GamepadAxisState;
|
||||
std::array<GamepadAxisState, MAX_GAMEPADS> m_CurrentGamepadAxisState;
|
||||
std::array<GamepadAxisState, MAX_GAMEPADS> m_LastGamepadAxisState;
|
||||
typedef std::array<bool, static_cast<int>(Gamepad::Button::LAST) + 1> GamepadButtonState;
|
||||
std::array<GamepadButtonState, MAX_GAMEPADS> m_CurrentGamepadButtonState;
|
||||
std::array<GamepadButtonState, MAX_GAMEPADS> m_LastGamepadButtonState;
|
||||
|
||||
double m_CurrentMouseX, m_CurrentMouseY;
|
||||
double m_LastMouseX, m_LastMouseY;
|
||||
@@ -68,12 +58,10 @@ private:
|
||||
void PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis);
|
||||
void PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button);
|
||||
|
||||
static std::vector<unsigned int> GLFWCharCallbackQueue;
|
||||
static void GLFWCharCallback(GLFWwindow* window, unsigned int c);
|
||||
static std::vector<std::pair<double, double>> GLFWScrollCallbackQueue;
|
||||
static void GLFWScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
static std::vector<std::string> GLFWDropCallbackQueue;
|
||||
static void GLFWDropCallback(GLFWwindow* window, int count, const char* paths[]);
|
||||
static void GLFWMouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
LOG_DEBUG("Click! %i %i %i", button, action, mods);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,40 +6,20 @@
|
||||
#include "ComponentWrapper.h"
|
||||
|
||||
class System
|
||||
{
|
||||
protected:
|
||||
System(EventBroker* eventBroker)
|
||||
: m_EventBroker(eventBroker)
|
||||
{ }
|
||||
|
||||
EventBroker* m_EventBroker;
|
||||
};
|
||||
|
||||
class PureSystem : public System
|
||||
{
|
||||
friend class SystemPipeline;
|
||||
|
||||
protected:
|
||||
PureSystem(EventBroker* eventBroker, std::string componentType)
|
||||
: System(eventBroker)
|
||||
public:
|
||||
System(EventBroker* eventBroker, std::string componentType)
|
||||
: m_EventBroker(eventBroker)
|
||||
, m_ComponentType(componentType)
|
||||
{ }
|
||||
|
||||
const std::string m_ComponentType;
|
||||
|
||||
virtual void UpdateComponent(World* world, ComponentWrapper& component, double dt) = 0;
|
||||
};
|
||||
|
||||
class ImpureSystem : public System
|
||||
{
|
||||
friend class SystemPipeline;
|
||||
virtual void Update(World* world, ComponentWrapper& component, double dt) = 0;
|
||||
|
||||
protected:
|
||||
ImpureSystem(EventBroker* eventBroker)
|
||||
: System(eventBroker)
|
||||
{ }
|
||||
|
||||
virtual void Update(World* world, double dt) = 0;
|
||||
std::string m_ComponentType;
|
||||
EventBroker* m_EventBroker;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
{ }
|
||||
~SystemPipeline()
|
||||
{
|
||||
for (auto& pair : m_PureSystems) {
|
||||
for (auto& pair : m_Systems) {
|
||||
for (auto& system : pair.second) {
|
||||
delete system;
|
||||
}
|
||||
@@ -25,32 +25,17 @@ public:
|
||||
void AddSystem(Arguments... args)
|
||||
{
|
||||
System* system = new T(m_EventBroker, args...);
|
||||
m_Systems[typeid(T).name()] = system;
|
||||
|
||||
if (std::is_base_of<PureSystem, T>::value) {
|
||||
PureSystem* pureSystem = static_cast<PureSystem*>(system);
|
||||
if (!pureSystem->m_ComponentType.empty()) {
|
||||
m_PureSystems[pureSystem->m_ComponentType].push_back(pureSystem);
|
||||
} else {
|
||||
LOG_ERROR("Failed to add pure system \"%s\": Missing component type!", typeid(T).name());
|
||||
}
|
||||
}
|
||||
|
||||
if (std::is_base_of<ImpureSystem, T>::value) {
|
||||
ImpureSystem* impureSystem = static_cast<ImpureSystem*>(system);
|
||||
m_ImpureSystems.push_back(impureSystem);
|
||||
if (!system->m_ComponentType.empty()) {
|
||||
m_Systems[system->m_ComponentType].push_back(system);
|
||||
} else {
|
||||
LOG_ERROR("Failed to add system \"%s\": Missing component type!", typeid(T).name());
|
||||
delete system;
|
||||
}
|
||||
}
|
||||
|
||||
void Update(World* world, double dt)
|
||||
{
|
||||
// Process events
|
||||
for (auto& pair : m_Systems) {
|
||||
m_EventBroker->Process(pair.first);
|
||||
}
|
||||
|
||||
// Update
|
||||
for (auto& pair : m_PureSystems) {
|
||||
const std::string& componentName = pair.first;
|
||||
auto& systems = pair.second;
|
||||
const ComponentPool* pool = world->GetComponents(componentName);
|
||||
@@ -59,20 +44,15 @@ public:
|
||||
}
|
||||
for (auto& component : *pool) {
|
||||
for (auto& system : systems) {
|
||||
system->UpdateComponent(world, component, dt);
|
||||
system->Update(world, component, dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto& system : m_ImpureSystems) {
|
||||
system->Update(world, dt);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
EventBroker* m_EventBroker;
|
||||
std::map<std::string, System*> m_Systems;
|
||||
std::map<std::string, std::vector<PureSystem*>> m_PureSystems;
|
||||
std::vector<ImpureSystem*> m_ImpureSystems;
|
||||
std::unordered_map<std::string, std::vector<System*>> m_Systems;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -14,35 +14,22 @@ public:
|
||||
|
||||
// Create empty entity
|
||||
EntityID CreateEntity(EntityID parent = 0);
|
||||
// Delete entity and all components within
|
||||
void DeleteEntity(EntityID entity);
|
||||
|
||||
// Register a component type and allocate space for it
|
||||
void RegisterComponent(ComponentInfo& ci);
|
||||
// Attach a component to an entity and fill it with default values
|
||||
ComponentWrapper AttachComponent(EntityID entity, std::string componentType);
|
||||
// Check if an entity has a component
|
||||
bool HasComponent(EntityID entity, std::string componentType);
|
||||
// Get a component of an entity
|
||||
ComponentWrapper GetComponent(EntityID entity, std::string componentType);
|
||||
// Delete a component off an entity
|
||||
void DeleteComponent(EntityID entity, std::string componentType);
|
||||
// Get all components of the specified type
|
||||
const ComponentPool* GetComponents(std::string componentType);
|
||||
// Get entity parent
|
||||
EntityID GetParent(EntityID entity);
|
||||
// Change the parent of an entity
|
||||
void SetParent(EntityID entity, EntityID parent);
|
||||
// Get all component pools
|
||||
const std::unordered_map<std::string, ComponentPool*>& GetComponentPools() const { return m_ComponentPools; }
|
||||
// Get the entity children map
|
||||
const std::unordered_multimap<EntityID, EntityID>& GetEntityChildren() const { return m_EntityChildren; }
|
||||
|
||||
private:
|
||||
EntityID m_CurrentEntityID = 1;
|
||||
|
||||
std::unordered_map<EntityID, EntityID> m_EntityParents;
|
||||
// TODO: This should be a more effective structure
|
||||
std::unordered_multimap<EntityID, EntityID> m_EntityChildren;
|
||||
std::unordered_map<std::string, ComponentPool*> m_ComponentPools;
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#include <imgui/imgui.h>
|
||||
#include <glm/gtx/common.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include "../Core/System.h"
|
||||
#include "../Core/EMousePress.h"
|
||||
#include "../Core/EMouseRelease.h"
|
||||
#include "../Core/EMouseMove.h"
|
||||
#include "../Core/ConfigFile.h"
|
||||
#include "../Input/EInputCommand.h"
|
||||
#include "../Rendering/IRenderer.h"
|
||||
#include "../Rendering/EPicking.h"
|
||||
#include "../Core/EFileDropped.h"
|
||||
#include "../Rendering/RenderQueueFactory.h"
|
||||
|
||||
class EditorSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
EditorSystem(EventBroker* eventBroker, IRenderer* renderer);
|
||||
|
||||
virtual void Update(World* world, double dt) override;
|
||||
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
World* m_World = nullptr;
|
||||
|
||||
bool m_Enabled;
|
||||
bool m_Visible;
|
||||
std::vector<glm::vec2> m_PickingQueue;
|
||||
|
||||
enum class WidgetMode
|
||||
{
|
||||
None,
|
||||
Translate,
|
||||
Rotate,
|
||||
Scale
|
||||
} m_WidgetMode = WidgetMode::None;
|
||||
|
||||
enum class WidgetSpace
|
||||
{
|
||||
Local,
|
||||
Global
|
||||
} m_WidgetSpace = WidgetSpace::Global;
|
||||
|
||||
EntityID m_Widget = 0;
|
||||
EntityID m_WidgetX = 0;
|
||||
EntityID m_WidgetPlaneX = 0;
|
||||
EntityID m_WidgetY = 0;
|
||||
EntityID m_WidgetPlaneY = 0;
|
||||
EntityID m_WidgetZ = 0;
|
||||
EntityID m_WidgetPlaneZ = 0;
|
||||
EntityID m_WidgetOrigin = 0;
|
||||
glm::vec3 m_WidgetCurrentAxis;
|
||||
float m_WidgetPickingDepth = 0.f;
|
||||
|
||||
EntityID m_Selection = 0;
|
||||
EntityID m_LastSelection = 0;
|
||||
glm::vec3 m_Position;
|
||||
std::string m_LastDroppedFile;
|
||||
|
||||
EventRelay<EditorSystem, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand& e);
|
||||
EventRelay<EditorSystem, Events::MouseRelease> m_EMouseRelease;
|
||||
bool OnMouseRelease(const Events::MouseRelease& e);
|
||||
EventRelay<EditorSystem, Events::MousePress> m_EMousePress;
|
||||
bool OnMousePress(const Events::MousePress& e);
|
||||
EventRelay<EditorSystem, Events::MouseMove> m_EMouseMove;
|
||||
bool OnMouseMove(const Events::MouseMove& e);
|
||||
EventRelay<EditorSystem, Events::Picking> m_EPicking;
|
||||
bool OnPicking(const Events::Picking& e);
|
||||
EventRelay<EditorSystem, Events::FileDropped> m_EFileDropped;
|
||||
bool OnFileDropped(const Events::FileDropped& e);
|
||||
|
||||
void updateWidget();
|
||||
void setWidgetMode(WidgetMode newMode);
|
||||
void setWidgetSpace(WidgetSpace space);
|
||||
void drawUI(World* world, double dt);
|
||||
bool createDeleteButton(std::string componentType);
|
||||
void changeParent(EntityID entity, EntityID newParent);
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef XboxControllerInputHandler_h__
|
||||
#define XboxControllerInputHandler_h__
|
||||
|
||||
#include "InputHandler.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
|
||||
struct _XINPUT_STATE;
|
||||
typedef _XINPUT_STATE XINPUT_STATE;
|
||||
|
||||
class XboxControllerInputHandler : public InputHandler
|
||||
{
|
||||
public:
|
||||
XboxControllerInputHandler(EventBroker* eventBroker, InputProxy* inputProxy);
|
||||
|
||||
|
||||
bool BindOrigin(std::string origin, std::string command, float value) override;
|
||||
|
||||
void Update(double dt) override;
|
||||
|
||||
virtual float GetCommandValue(std::string command) override;
|
||||
private:
|
||||
std::unordered_map<std::string, int> m_OriginButtons;
|
||||
std::unordered_map<std::string, int> m_OriginAxes;
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_ButtonBindings; // GLFW_KEY... -> command string & value
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_AxisBindings; // GLFW_KEY... -> command string & value
|
||||
std::unordered_map<std::string, float> m_CommandValues;
|
||||
|
||||
static const short MAX_GAMEPADS = 4;
|
||||
|
||||
float getAxisValue(XINPUT_STATE& state, int axis);
|
||||
//typedef std::array<float, static_cast<int>(Gamepad::Axis::LAST) + 1> GamepadAxisState;
|
||||
//std::array<GamepadAxisState, MAX_GAMEPADS> m_CurrentGamepadAxisState;
|
||||
//std::array<GamepadAxisState, MAX_GAMEPADS> m_LastGamepadAxisState;
|
||||
//typedef std::array<bool, static_cast<int>(Gamepad::Button::LAST) + 1> GamepadButtonState;
|
||||
//std::array<GamepadButtonState, MAX_GAMEPADS> m_CurrentGamepadButtonState;
|
||||
//std::array<GamepadButtonState, MAX_GAMEPADS> m_LastGamepadButtonState;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <imgui/imgui.h>
|
||||
#include "../Input/FirstPersonInputController.h"
|
||||
|
||||
template <typename EventContext>
|
||||
@@ -14,35 +13,22 @@ public:
|
||||
|
||||
virtual bool OnCommand(const Events::InputCommand& e) override
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (e.Command == "PrimaryFire") {
|
||||
if (e.Value > 0) {
|
||||
if (!io.WantCaptureMouse) {
|
||||
LockMouse();
|
||||
}
|
||||
LockMouse();
|
||||
} else {
|
||||
UnlockMouse();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!io.WantCaptureKeyboard) {
|
||||
if (e.Command == "Right") {
|
||||
float value = std::max(-1.f, std::min(e.Value, 1.f));
|
||||
m_Velocity.x = value;
|
||||
}
|
||||
if (e.Command == "Forward") {
|
||||
float value = std::max(-1.f, std::min(e.Value, 1.f));
|
||||
m_Velocity.z = -value;
|
||||
}
|
||||
if (e.Command == "Sprint") {
|
||||
if (e.Value > 0.f) {
|
||||
m_Speed = m_BaseSpeed * 2.f * (e.Value);
|
||||
} else {
|
||||
m_Speed = m_BaseSpeed;
|
||||
}
|
||||
}
|
||||
if (e.Command == "Right") {
|
||||
float value = std::max(-1.f, std::min(e.Value, 1.f));
|
||||
m_Velocity.x = value;
|
||||
}
|
||||
if (e.Command == "Forward") {
|
||||
float value = std::max(-1.f, std::min(e.Value, 1.f));
|
||||
m_Velocity.z = -value;
|
||||
}
|
||||
|
||||
return FirstPersonInputController::OnCommand(e);
|
||||
@@ -51,7 +37,7 @@ public:
|
||||
void Update(double dt)
|
||||
{
|
||||
if (glm::length2(m_Velocity) > 0) {
|
||||
m_Position += m_Orientation * (glm::normalize(m_Velocity) * m_Speed * (float)dt);
|
||||
m_Position += (m_Orientation * (m_Velocity * m_BaseSpeed)) * (float)dt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,5 +45,4 @@ protected:
|
||||
glm::vec3 m_Position = glm::vec3(0, 0, 0);
|
||||
glm::vec3 m_Velocity = glm::vec3(0, 0, 0);
|
||||
float m_BaseSpeed = 2.0f;
|
||||
float m_Speed = m_BaseSpeed;
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
#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
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef DrawScenePassState_h__
|
||||
#define DrawScenePassState_h__
|
||||
|
||||
#include "Rendering/RenderState.h"
|
||||
|
||||
class DrawScenePassState : public RenderState
|
||||
{
|
||||
public:
|
||||
DrawScenePassState();
|
||||
~DrawScenePassState();
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -34,26 +34,21 @@ public:
|
||||
EntityID Entity;
|
||||
//World position of the "pick"
|
||||
glm::vec3 Position;
|
||||
// Depth
|
||||
float Depth;
|
||||
};
|
||||
|
||||
PickData Pick(glm::vec2 screenCoord) const
|
||||
{
|
||||
PickData pickData;
|
||||
|
||||
// Invert screen y coordinate
|
||||
screenCoord.y = Resolution.Height - screenCoord.y;
|
||||
ScreenCoords::PixelData data = ScreenCoords::ToPixelData(screenCoord, PickingBuffer, *DepthBuffer);
|
||||
pickData.Depth = data.Depth;
|
||||
|
||||
auto it = PickingColorsToEntity->find(glm::vec2(data.Color[0], data.Color[1]));
|
||||
if (it != PickingColorsToEntity->end()) {
|
||||
pickData.Entity = it->second;
|
||||
} else {
|
||||
pickData.Entity = 0;
|
||||
pickData.Entity = -1;
|
||||
}
|
||||
pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, screenCoord.y, data.Depth, Resolution, ProjectionMatrix, ViewMatrix);
|
||||
pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, Resolution.Width - screenCoord.y, data.Depth, Resolution, ProjectionMatrix, ViewMatrix);
|
||||
|
||||
return pickData;
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#include <imgui/imgui.h>
|
||||
#include "../OpenGL.h"
|
||||
#include "IRenderer.h"
|
||||
#include "RenderState.h"
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "../Core/EMousePress.h"
|
||||
#include "../Core/EMouseRelease.h"
|
||||
#include "../Core/EMouseMove.h"
|
||||
#include "../Core/EMouseScroll.h"
|
||||
#include "../Core/EKeyDown.h"
|
||||
#include "../Core/EKeyUp.h"
|
||||
#include "../Core/EKeyboardChar.h"
|
||||
|
||||
class ImGuiRenderState : public RenderState
|
||||
{
|
||||
public:
|
||||
ImGuiRenderState()
|
||||
: RenderState()
|
||||
{
|
||||
BindFramebuffer(0);
|
||||
Enable(GL_BLEND);
|
||||
BlendEquation(GL_FUNC_ADD);
|
||||
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Disable(GL_CULL_FACE);
|
||||
Disable(GL_DEPTH_TEST);
|
||||
Enable(GL_SCISSOR_TEST);
|
||||
}
|
||||
};
|
||||
|
||||
class ImGuiRenderPass
|
||||
{
|
||||
public:
|
||||
ImGuiRenderPass(IRenderer* renderer, EventBroker* eventBroker);
|
||||
|
||||
void Update(double dt);
|
||||
void Draw();
|
||||
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
GLFWwindow* g_Window;
|
||||
double g_DeltaTime = 0.0;
|
||||
float g_MouseWheel = 0.f;
|
||||
GLuint g_FontTexture;
|
||||
int g_ShaderHandle;
|
||||
int g_VertHandle;
|
||||
int g_FragHandle;
|
||||
int g_AttribLocationTex;
|
||||
int g_AttribLocationProjMtx;
|
||||
int g_AttribLocationPosition;
|
||||
int g_AttribLocationUV;
|
||||
int g_AttribLocationColor;
|
||||
GLuint g_VboHandle;
|
||||
GLuint g_VaoHandle;
|
||||
GLuint g_ElementsHandle;
|
||||
|
||||
EventRelay<ImGuiRenderPass, Events::MousePress> m_EMousePress;
|
||||
bool OnMousePress(const Events::MousePress& e);
|
||||
EventRelay<ImGuiRenderPass, Events::MouseRelease> m_EMouseRelease;
|
||||
bool OnMouseRelease(const Events::MouseRelease& e);
|
||||
EventRelay<ImGuiRenderPass, Events::MouseMove> m_EMouseMove;
|
||||
bool OnMouseMove(const Events::MouseMove& e);
|
||||
EventRelay<ImGuiRenderPass, Events::MouseScroll> m_EMouseScroll;
|
||||
bool OnMouseScroll(const Events::MouseScroll& e);
|
||||
EventRelay<ImGuiRenderPass, Events::KeyDown> m_EKeyDown;
|
||||
bool OnKeyDown(const Events::KeyDown& e);
|
||||
EventRelay<ImGuiRenderPass, Events::KeyUp> m_EKeyUp;
|
||||
bool OnKeyUp(const Events::KeyUp& e);
|
||||
EventRelay<ImGuiRenderPass, Events::KeyboardChar> m_EKeyboardChar;
|
||||
bool OnKeyboardChar(const Events::KeyboardChar& e);
|
||||
|
||||
bool createDeviceObjects();
|
||||
bool createFontsTexture();
|
||||
|
||||
void newFrame();
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
#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
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef PickingPassState_h__
|
||||
#define PickingPassState_h__
|
||||
|
||||
#include "Rendering/RenderState.h"
|
||||
|
||||
class PickingPassState : public RenderState
|
||||
{
|
||||
public:
|
||||
PickingPassState(GLuint frameBuffer);
|
||||
~PickingPassState();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -13,12 +13,8 @@ public:
|
||||
RenderQueueFactory();
|
||||
void Update(World* world);
|
||||
|
||||
|
||||
RenderQueueCollection RenderQueues() const { return m_RenderQueues; }
|
||||
|
||||
static glm::vec3 AbsolutePosition(World* world, EntityID entity);
|
||||
static glm::quat AbsoluteOrientation(World* world, EntityID entity);
|
||||
static glm::vec3 AbsoluteScale(World* world, EntityID entity);
|
||||
|
||||
private:
|
||||
RenderQueueCollection m_RenderQueues;
|
||||
|
||||
@@ -26,6 +22,10 @@ private:
|
||||
void FillLights(World* world, RenderQueue* renderQueue);
|
||||
|
||||
glm::mat4 ModelMatrix(World* world, EntityID entity);
|
||||
|
||||
glm::vec3 AbsolutePosition(World* world, EntityID entity);
|
||||
glm::quat AbsoluteOrientation(World* world, EntityID entity);
|
||||
glm::vec3 AbsoluteScale(World* world, EntityID entity);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef RenderState_h__
|
||||
#define RenderState_h__
|
||||
|
||||
#include <functional>
|
||||
#include "../Common.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "../GLM.h"
|
||||
|
||||
class RenderState
|
||||
{
|
||||
public:
|
||||
RenderState() = default;
|
||||
~RenderState();
|
||||
|
||||
bool Enable(GLenum cap);
|
||||
bool Disable(GLenum cap);
|
||||
bool CullFace(GLenum mode);
|
||||
bool ClearColor(glm::vec4 color);
|
||||
bool Clear(GLbitfield mask);
|
||||
bool BindFramebuffer(GLint framebuffer);
|
||||
bool BlendEquation(GLenum mode);
|
||||
bool BlendFunc(GLenum sfactor, GLenum dfactor);
|
||||
|
||||
private:
|
||||
std::vector<std::function<void(void)>> m_ResetFunctions;
|
||||
};
|
||||
#endif
|
||||
@@ -10,25 +10,9 @@
|
||||
#include "Util/UnorderedMapVec2.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "../Core/World.h"
|
||||
#include "PickingPass.h"
|
||||
#include "DrawScenePass.h"
|
||||
|
||||
|
||||
#define TILE_SIZE 16
|
||||
#define NUM_LIGHTS 3
|
||||
|
||||
|
||||
enum lightType
|
||||
{
|
||||
Point,
|
||||
Spot,
|
||||
Directional,
|
||||
Area
|
||||
};
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "EPicking.h"
|
||||
#include "ImGuiRenderPass.h"
|
||||
|
||||
class Renderer : public IRenderer
|
||||
{
|
||||
@@ -37,88 +21,44 @@ 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;
|
||||
Texture* m_ErrorTexture;
|
||||
Texture* m_WhiteTexture;
|
||||
float m_CameraMoveSpeed;
|
||||
FrameBuffer m_PickingBuffer;
|
||||
GLuint m_PickingTexture;
|
||||
GLuint m_DepthBuffer;
|
||||
|
||||
Model* m_ScreenQuad;
|
||||
Model* m_UnitQuad;
|
||||
Model* m_UnitSphere;
|
||||
|
||||
DrawScenePass* m_DrawScenePass;
|
||||
PickingPass* m_PickingPass;
|
||||
ImGuiRenderPass* m_ImGuiRenderPass;
|
||||
std::unordered_map<glm::vec2, EntityID> m_PickingColorsToEntity;
|
||||
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
void InitializeShaders();
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
void InitializeShaders();
|
||||
void InitializeTextures();
|
||||
void InitializeSSBOs();
|
||||
void InitializeRenderPasses();
|
||||
void InitializeFrameBuffers();
|
||||
//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();
|
||||
//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 {
|
||||
int Amount;
|
||||
int Start;
|
||||
glm::vec2 Padding;
|
||||
};
|
||||
LightGrid m_LightGrid[80*45];
|
||||
|
||||
int m_LightOffset = 0;
|
||||
|
||||
int m_LightIndex[80*45*200];
|
||||
|
||||
//-------------------------SSBO------------------------//
|
||||
GLuint m_FrustumSSBO = 0;
|
||||
GLuint m_LightSSBO = 1;
|
||||
GLuint m_LightGridSSBO = 2;
|
||||
GLuint m_LightOffsetSSBO = 3;
|
||||
GLuint m_LightIndexSSBO = 4;
|
||||
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
|
||||
//--------------------ShaderPrograms-------------------//
|
||||
ShaderProgram* m_BasicForwardProgram;
|
||||
ShaderProgram* m_DrawScreenQuadProgram;
|
||||
ShaderProgram* m_CalculateFrustumProgram;
|
||||
ShaderProgram* m_LightCullProgram;
|
||||
|
||||
ShaderProgram m_BasicForwardProgram;
|
||||
ShaderProgram m_PickingProgram;
|
||||
ShaderProgram m_DrawScreenQuadProgram;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,6 @@
|
||||
#ifndef ShaderProgram_h__
|
||||
#define ShaderProgram_h__
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../OpenGL.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include <fstream>
|
||||
|
||||
class Shader
|
||||
@@ -63,13 +60,11 @@ public:
|
||||
: ShaderType(fileName) { }
|
||||
};
|
||||
|
||||
class ShaderProgram : public Resource
|
||||
class ShaderProgram
|
||||
{
|
||||
friend class ResourceManager;
|
||||
private:
|
||||
ShaderProgram(std::string)
|
||||
: m_ShaderProgramHandle(0) { }
|
||||
public:
|
||||
ShaderProgram()
|
||||
: m_ShaderProgramHandle(0) { }
|
||||
~ShaderProgram();
|
||||
|
||||
void AddShader(std::shared_ptr<Shader> shader);
|
||||
@@ -84,5 +79,3 @@ 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
-1
@@ -12,12 +12,12 @@
|
||||
#include "Input/InputProxy.h"
|
||||
#include "Input/KeyboardInputHandler.h"
|
||||
#include "Input/MouseInputHandler.h"
|
||||
#include "Input/XboxControllerInputHandler.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EntityXMLFile.h"
|
||||
#include "Core/SystemPipeline.h"
|
||||
#include "RaptorCopterSystem.h"
|
||||
#include "PlayerSystem.h"
|
||||
#include "Editor/EditorSystem.h"
|
||||
|
||||
class Game
|
||||
{
|
||||
|
||||
@@ -18,17 +18,17 @@ struct KeyInput
|
||||
bool Right = false;
|
||||
};
|
||||
|
||||
class PlayerSystem : public PureSystem
|
||||
class PlayerSystem : public System
|
||||
{
|
||||
public:
|
||||
PlayerSystem(EventBroker* eventBroker)
|
||||
: PureSystem(eventBroker, "Player")
|
||||
: System(eventBroker, "Player")
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &PlayerSystem::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &PlayerSystem::OnKeyUp);
|
||||
}
|
||||
|
||||
virtual void UpdateComponent(World* world, ComponentWrapper& player, double dt) override;
|
||||
virtual void Update(World* world, ComponentWrapper& player, double dt) override;
|
||||
|
||||
private:
|
||||
float m_Speed = 5;
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#include "Common.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
class RaptorCopterSystem : public PureSystem
|
||||
class RaptorCopterSystem : public System
|
||||
{
|
||||
public:
|
||||
RaptorCopterSystem(EventBroker* eventBroker)
|
||||
: PureSystem(eventBroker, "RaptorCopter")
|
||||
: System(eventBroker, "RaptorCopter")
|
||||
{ }
|
||||
|
||||
virtual void UpdateComponent(World* world, ComponentWrapper& raptorCopter, double dt) override
|
||||
virtual void Initialize() { }
|
||||
|
||||
virtual void Update(World* world, ComponentWrapper& raptorCopter, double dt) override
|
||||
{
|
||||
ComponentWrapper& transform = world->GetComponent(raptorCopter.EntityID, "Transform");
|
||||
(glm::vec3&)transform["Orientation"] += (float)(double)raptorCopter["Speed"] * (float)dt * (glm::vec3)raptorCopter["Axis"];
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
[Debug]
|
||||
LogLevel=1
|
||||
LoadMap=
|
||||
EditorEnabled=false
|
||||
|
||||
[Video]
|
||||
Fullscreen=false
|
||||
VSYNC=false
|
||||
Width=1280
|
||||
Height=720
|
||||
FOV=45
|
||||
Height=720
|
||||
@@ -14,8 +14,11 @@ R=Reload
|
||||
Space=Jump
|
||||
LeftControl=Crouch
|
||||
LeftShift=Sprint
|
||||
F1=ToggleEditor
|
||||
1=EditorToolMove
|
||||
2=EditorToolRotate
|
||||
3=EditorToolScale
|
||||
X=EditorToggleTransformSpace
|
||||
|
||||
GamepadRightTrigger=PrimaryFire
|
||||
GamepadRightX=Yaw
|
||||
GamepadRightY=-Pitch
|
||||
GamepadA=TestGamepadA
|
||||
GamepadX=TestGamepadX
|
||||
GamepadLeftX=Right
|
||||
GamepadLeftY=Forward
|
||||
@@ -0,0 +1,6 @@
|
||||
<c:Test>
|
||||
<Integer>1</Integer>
|
||||
<Float>1.333</Float>
|
||||
<Vector X="1.33333" Y="2.33333" Z="3.33333"/>
|
||||
<Quaternion X="1.33333" Y="2.33333" Z="3.33333" W="4.44444"/>
|
||||
</c:Test>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?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="Test">
|
||||
<xs:annotation>
|
||||
<xs:documentation>ECS Test Component</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Integer" type="t:int" minOccurs="0"/>
|
||||
<xs:element name="Double" type="t:double" minOccurs="0"/>
|
||||
<xs:element name="String" type="t:string" minOccurs="0"/>
|
||||
<xs:element name="Vector" type="t:Vector" minOccurs="0"/>
|
||||
<xs:element name="Quaternion" type="t:Quaternion" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -1,5 +1,5 @@
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0" Z="0"/>
|
||||
<Orientation X="0" Y="0" Z="0"/>
|
||||
<Orientation X="0" Y="0" Z="0" W="0"/>
|
||||
<Scale X="1" Y="1" Z="1"/>
|
||||
</c:Transform>
|
||||
@@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<Entity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd" xmlns:c="components">
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0" Z="0"/>
|
||||
<Orientation X="0" Y="0" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0" Z="0"/>
|
||||
<Scale X="100" Y="1" Z="100"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitPlane.obj</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="1" Y="1" Z="0"/>
|
||||
<Orientation X="0" Y="0.78539" Z="0"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>An error</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="2" Y="0" Z="0"/>
|
||||
<Orientation X="0" Y="0.78539" Z="0"/>
|
||||
</c:Transform>
|
||||
<c:Model>
|
||||
<Resource>An error</Resource>
|
||||
</c:Model>
|
||||
</Components>
|
||||
<Children>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
@@ -1,73 +0,0 @@
|
||||
#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[3600];
|
||||
} 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 ()
|
||||
{
|
||||
if(gl_GlobalInvocationID.x * TILE_SIZE < ScreenDimensions.x && gl_GlobalInvocationID.y * TILE_SIZE < ScreenDimensions.y) {
|
||||
//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); // Z-axis might need to be 1
|
||||
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);
|
||||
|
||||
Frustum f;
|
||||
f.Planes[0] = ComputePlane(EyePos, ViewVectors[2], ViewVectors[0]);
|
||||
f.Planes[1] = ComputePlane(EyePos, ViewVectors[1], ViewVectors[3]);
|
||||
f.Planes[2] = ComputePlane(EyePos, ViewVectors[0], ViewVectors[1]);
|
||||
f.Planes[3] = ComputePlane(EyePos, ViewVectors[3], ViewVectors[2]);
|
||||
|
||||
|
||||
|
||||
|
||||
Frustums.Data[gl_GlobalInvocationID.x + gl_GlobalInvocationID.y*80] = f;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#version 430
|
||||
|
||||
//in uvec3 gl_NumWorkGroups;
|
||||
//in uvec3 gl_WorkGroupID;
|
||||
//in uvec3 gl_LocalInvocationID;
|
||||
//in uvec3 gl_GlobalInvocationID;
|
||||
//in uint gl_LocalInvocationIndex;
|
||||
|
||||
|
||||
|
||||
#define NUM_LIGHTS 3
|
||||
#define MAX_LIGHTS_PER_TILE 200
|
||||
#define NUM_TILES 3600
|
||||
|
||||
struct Plane {
|
||||
vec3 Normal;
|
||||
float d;
|
||||
};
|
||||
struct Frustum {
|
||||
Plane Planes[4];
|
||||
};
|
||||
|
||||
layout (std430, binding = 0) buffer FrustumBuffer
|
||||
{
|
||||
Frustum Data[3600];
|
||||
} Frustums;
|
||||
|
||||
|
||||
|
||||
layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
|
||||
void main ()
|
||||
{
|
||||
if(1 == 1) {
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@ file(GLOB SOURCE_FILES_Rendering_Util
|
||||
"${INCLUDE_PATH}/Rendering/Util/*.h"
|
||||
"Rendering/Util/*.cpp"
|
||||
)
|
||||
|
||||
source_group(Rendering FILES ${SOURCE_FILES_Rendering})
|
||||
source_group(Rendering\\Util FILES ${SOURCE_FILES_Rendering_Util})
|
||||
|
||||
@@ -69,12 +70,6 @@ file(GLOB SOURCE_FILES_GUI
|
||||
)
|
||||
source_group(GUI FILES ${SOURCE_FILES_GUI})
|
||||
|
||||
file(GLOB SOURCE_FILES_Editor
|
||||
"${INCLUDE_PATH}/Editor/*.h"
|
||||
"Editor/*.cpp"
|
||||
)
|
||||
source_group(Editor FILES ${SOURCE_FILES_Editor})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${SOURCE_FILES_Core}
|
||||
${SOURCE_FILES_Core_Util}
|
||||
@@ -83,10 +78,6 @@ set(SOURCE_FILES
|
||||
${SOURCE_FILES_GUI}
|
||||
${SOURCE_FILES_Rendering}
|
||||
${SOURCE_FILES_Rendering_Util}
|
||||
${CMAKE_SOURCE_DIR}/deps/include/imgui/imgui.cpp
|
||||
${CMAKE_SOURCE_DIR}/deps/include/imgui/imgui_draw.cpp
|
||||
${CMAKE_SOURCE_DIR}/deps/include/imgui/imgui_demo.cpp
|
||||
${SOURCE_FILES_Editor}
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
@@ -112,4 +103,4 @@ target_link_libraries(Engine
|
||||
${LIBRARIES}
|
||||
)
|
||||
#set_target_properties(Engine PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "${INCLUDE_PATH}/PrecompiledHeader.h")
|
||||
#cotire(Engine)
|
||||
#cotire(Engine)
|
||||
@@ -50,16 +50,10 @@ ComponentWrapper ComponentPool::GetByEntity(EntityID ent)
|
||||
return ComponentWrapper(m_ComponentInfo, m_EntityToComponent.at(ent));
|
||||
}
|
||||
|
||||
|
||||
bool ComponentPool::KnowsEntity(EntityID ent)
|
||||
{
|
||||
return m_EntityToComponent.find(ent) != m_EntityToComponent.end();
|
||||
}
|
||||
|
||||
void ComponentPool::Delete(ComponentWrapper& wrapper)
|
||||
{
|
||||
m_EntityToComponent.erase(wrapper.EntityID);
|
||||
m_Pool.Free(wrapper.Data - sizeof(EntityID));
|
||||
m_Pool.Free(wrapper.Data);
|
||||
}
|
||||
|
||||
ComponentPool::iterator ComponentPool::begin() const
|
||||
|
||||
@@ -415,7 +415,6 @@ std::size_t EntityXMLFile::getTypeStride(std::string typeName)
|
||||
std::map<std::string, size_t> typeStrides{
|
||||
{ "bool", sizeof(bool) },
|
||||
{ "int", sizeof(int) },
|
||||
{ "float", sizeof(float) },
|
||||
{ "double", sizeof(double) },
|
||||
{ "string", sizeof(std::string) },
|
||||
{ "Vector", sizeof(glm::vec3) },
|
||||
@@ -431,12 +430,12 @@ float EntityXMLFile::getFloatAttribute(const xercesc::DOMElement* element, const
|
||||
{
|
||||
using namespace xercesc;
|
||||
XSValue::Status status;
|
||||
XSValue* val = XSValue::getActualValue(element->getAttribute(XSTR(attribute)), xercesc::XSValue::DataType::dt_double, status);
|
||||
XSValue* val = XSValue::getActualValue(element->getAttribute(XSTR(attribute)), xercesc::XSValue::DataType::dt_float, status);
|
||||
if (val == nullptr) {
|
||||
LOG_ERROR("Element \"%s\" doesn't have an \"%s\" attribute!", XSTR(element->getTagName()), attribute);
|
||||
return 0.f;
|
||||
} else {
|
||||
return static_cast<float>(val->fData.fValue.f_double);
|
||||
return val->fData.fValue.f_float;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,52 +443,39 @@ void EntityXMLFile::writeData(const xercesc::DOMElement* element, std::string ty
|
||||
{
|
||||
using namespace xercesc;
|
||||
|
||||
if (typeName == "Vector") {
|
||||
glm::vec3 vec;
|
||||
vec.x = getFloatAttribute(element, "X");
|
||||
vec.y = getFloatAttribute(element, "Y");
|
||||
vec.z = getFloatAttribute(element, "Z");
|
||||
memcpy(outData, reinterpret_cast<char*>(&vec), getTypeStride(typeName));
|
||||
} else if (typeName == "Color") {
|
||||
glm::vec4 vec;
|
||||
vec.r = getFloatAttribute(element, "R");
|
||||
vec.g = getFloatAttribute(element, "G");
|
||||
vec.b = getFloatAttribute(element, "B");
|
||||
vec.a = getFloatAttribute(element, "A");
|
||||
memcpy(outData, reinterpret_cast<char*>(&vec), getTypeStride(typeName));
|
||||
} else if (typeName == "Quaternion") {
|
||||
glm::quat q;
|
||||
q.x = getFloatAttribute(element, "X");
|
||||
q.y = getFloatAttribute(element, "Y");
|
||||
q.z = getFloatAttribute(element, "Z");
|
||||
q.w = getFloatAttribute(element, "W");
|
||||
memcpy(outData, reinterpret_cast<char*>(&q), getTypeStride(typeName));
|
||||
} else if (typeName == "float") {
|
||||
XSValue::Status status;
|
||||
XSValue* val = XSValue::getActualValue(element->getTextContent(), xercesc::XSValue::DataType::dt_float, status);
|
||||
memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue.f_float), getTypeStride(typeName));
|
||||
} else if (typeName == "double") {
|
||||
XSValue::Status status;
|
||||
XSValue* val = XSValue::getActualValue(element->getTextContent(), xercesc::XSValue::DataType::dt_double, status);
|
||||
memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue.f_double), getTypeStride(typeName));
|
||||
} else if (typeName == "bool") {
|
||||
XSValue::Status status;
|
||||
XSValue* val = XSValue::getActualValue(element->getTextContent(), xercesc::XSValue::DataType::dt_boolean, status);
|
||||
memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue.f_bool), getTypeStride(typeName));
|
||||
} else {
|
||||
XSValue::DataType dataType = XSValue::getDataType(XSTR(typeName.c_str()));
|
||||
if (dataType == XSValue::DataType::dt_string) {
|
||||
char* str = XMLString::transcode(element->getTextContent());
|
||||
std::string standardString(str);
|
||||
new (outData) std::string(str);
|
||||
XMLString::release(&str);
|
||||
//memcpy(outData, reinterpret_cast<char*>(&standardString), getTypeStride(typeName));
|
||||
} else {
|
||||
//XSValue::Status status;
|
||||
//XSValue* val = XSValue::getActualValue(element->getTextContent(), dataType, status);
|
||||
//memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue), getTypeStride(typeName));
|
||||
LOG_WARNING("Unknown native data type: %s", typeName.c_str());
|
||||
XSValue::DataType dataType = XSValue::getDataType(XSTR(typeName.c_str()));
|
||||
if (dataType == XSValue::DataType::dt_MAXCOUNT) {
|
||||
if (typeName == "Vector") {
|
||||
glm::vec3 vec;
|
||||
vec.x = getFloatAttribute(element, "X");
|
||||
vec.y = getFloatAttribute(element, "Y");
|
||||
vec.z = getFloatAttribute(element, "Z");
|
||||
memcpy(outData, reinterpret_cast<char*>(&vec), getTypeStride(typeName));
|
||||
} else if (typeName == "Color") {
|
||||
glm::vec4 vec;
|
||||
vec.r = getFloatAttribute(element, "R");
|
||||
vec.g = getFloatAttribute(element, "G");
|
||||
vec.b = getFloatAttribute(element, "B");
|
||||
vec.a = getFloatAttribute(element, "A");
|
||||
memcpy(outData, reinterpret_cast<char*>(&vec), getTypeStride(typeName));
|
||||
} else if (typeName == "Quaternion") {
|
||||
glm::quat q;
|
||||
q.x = getFloatAttribute(element, "X");
|
||||
q.y = getFloatAttribute(element, "Y");
|
||||
q.z = getFloatAttribute(element, "Z");
|
||||
q.w = getFloatAttribute(element, "W");
|
||||
memcpy(outData, reinterpret_cast<char*>(&q), getTypeStride(typeName));
|
||||
}
|
||||
} else if (dataType == XSValue::DataType::dt_string) {
|
||||
char* str = XMLString::transcode(element->getTextContent());
|
||||
std::string standardString(str);
|
||||
new (outData) std::string(str);
|
||||
XMLString::release(&str);
|
||||
//memcpy(outData, reinterpret_cast<char*>(&standardString), getTypeStride(typeName));
|
||||
} else {
|
||||
XSValue::Status status;
|
||||
XSValue* val = XSValue::getActualValue(element->getTextContent(), dataType, status);
|
||||
memcpy(outData, reinterpret_cast<char*>(&val->fData.fValue), getTypeStride(typeName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
#include "Core/InputManager.h"
|
||||
|
||||
std::vector<unsigned int> InputManager::GLFWCharCallbackQueue;
|
||||
std::vector<std::pair<double, double>> InputManager::GLFWScrollCallbackQueue;
|
||||
std::vector<std::string> InputManager::GLFWDropCallbackQueue;
|
||||
|
||||
void InputManager::Initialize()
|
||||
{
|
||||
// TODO: Gamepad
|
||||
//m_LastGamepadAxisState = std::array<GamepadAxisState, XUSER_MAX_COUNT>();
|
||||
//m_LastGamepadButtonState = std::array<GamepadButtonState, XUSER_MAX_COUNT>();
|
||||
glfwSetCharCallback(m_GLFWWindow, &InputManager::GLFWCharCallback);
|
||||
glfwSetScrollCallback(m_GLFWWindow, &InputManager::GLFWScrollCallback);
|
||||
glfwSetDropCallback(m_GLFWWindow, &InputManager::GLFWDropCallback);
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ELockMouse, &InputManager::OnLockMouse);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EUnlockMouse, &InputManager::OnUnlockMouse);
|
||||
|
||||
//glfwSetMouseButtonCallback(m_GLFWWindow, &InputManager::GLFWMouseButtonCallback);
|
||||
}
|
||||
|
||||
void InputManager::Update(double dt)
|
||||
@@ -43,15 +38,6 @@ void InputManager::Update(double dt)
|
||||
}
|
||||
}
|
||||
|
||||
// Keyboard text input
|
||||
for (unsigned int& c : GLFWCharCallbackQueue) {
|
||||
Events::KeyboardChar e;
|
||||
e.Timestamp = glfwGetTime();
|
||||
e.Char = c;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
GLFWCharCallbackQueue.clear();
|
||||
|
||||
// Mouse buttons
|
||||
for (int i = 0; i <= GLFW_MOUSE_BUTTON_LAST; ++i) {
|
||||
m_CurrentMouseState[i] = glfwGetMouseButton(m_GLFWWindow, i);
|
||||
@@ -89,21 +75,20 @@ void InputManager::Update(double dt)
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
// Mouse scroll
|
||||
for (auto& pair : GLFWScrollCallbackQueue) {
|
||||
Events::MouseScroll e;
|
||||
std::tie(e.DeltaX, e.DeltaY) = pair;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
GLFWScrollCallbackQueue.clear();
|
||||
// Joysticks
|
||||
//for (int i = 0; i < GLFW_JOYSTICK_LAST; i++) {
|
||||
// if (glfwJoystickPresent(i) == GL_FALSE) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// File drop
|
||||
for (auto& path : GLFWDropCallbackQueue) {
|
||||
Events::FileDropped e;
|
||||
e.Path = path;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
GLFWDropCallbackQueue.clear();
|
||||
// int count;
|
||||
// const float* axes = glfwGetJoystickAxes(i, &count);
|
||||
// LOG_DEBUG("Controller %i NumAxes: %i", i, count);
|
||||
// m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftX)] = axes[0];
|
||||
// m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftY)] = axes[1];
|
||||
// m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightX)] = axes[2];
|
||||
// m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightY)] = axes[3];
|
||||
//}
|
||||
|
||||
// // Lock mouse while holding LMB
|
||||
// if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
@@ -123,128 +108,46 @@ void InputManager::Update(double dt)
|
||||
// }
|
||||
|
||||
// TODO: Xbox360 controller
|
||||
/*DWORD dwResult;
|
||||
for (int i = 0; i < MAX_GAMEPADS; i++)
|
||||
{
|
||||
XINPUT_STATE state = { 0 };
|
||||
// Simply get the state of the controller from XInput.
|
||||
dwResult = XInputGetState(i, &state);
|
||||
if (dwResult == 0)
|
||||
{
|
||||
if(std::abs(state.Gamepad.sThumbLX) <= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
|
||||
state.Gamepad.sThumbLX = 0;
|
||||
if(std::abs(state.Gamepad.sThumbLY) <= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
|
||||
state.Gamepad.sThumbLY = 0;
|
||||
if(std::abs(state.Gamepad.sThumbRX) <= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
|
||||
state.Gamepad.sThumbRX = 0;
|
||||
if(std::abs(state.Gamepad.sThumbRY) <= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
|
||||
state.Gamepad.sThumbRY = 0;
|
||||
if(std::abs(state.Gamepad.bLeftTrigger) <= XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
|
||||
state.Gamepad.bLeftTrigger = 0;
|
||||
if(std::abs(state.Gamepad.bRightTrigger) <= XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
|
||||
state.Gamepad.bRightTrigger = 0;
|
||||
|
||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftX)] = state.Gamepad.sThumbLX / 32767.f;
|
||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftY)] = state.Gamepad.sThumbLY / 32767.f;
|
||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightX)] = state.Gamepad.sThumbRX / 32767.f;
|
||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightY)] = state.Gamepad.sThumbRY / 32767.f;
|
||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftTrigger)] = state.Gamepad.bLeftTrigger / 255.f;
|
||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightTrigger)] = state.Gamepad.bRightTrigger / 255.f;
|
||||
PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftX);
|
||||
PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftY);
|
||||
PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightX);
|
||||
PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightY);
|
||||
PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftTrigger);
|
||||
PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightTrigger);
|
||||
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Up)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Down)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Left)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Right)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Start)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_START);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Back)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::LeftThumb)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::RightThumb)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::LeftShoulder)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::RightShoulder)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::A)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_A);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::B)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_B);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::X)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_X);
|
||||
m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Y)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::Up);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::Down);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::Left);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::Right);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::Start);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::Back);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::LeftThumb);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::RightThumb);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::LeftShoulder);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::RightShoulder);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::A);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::B);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::X);
|
||||
PublishGamepadButtonIfChanged(i, Gamepad::Button::Y);
|
||||
}
|
||||
}*/
|
||||
/**/
|
||||
|
||||
m_LastKeyState = m_CurrentKeyState;
|
||||
m_LastMouseState = m_CurrentMouseState;
|
||||
m_LastMouseX = m_CurrentMouseX;
|
||||
m_LastMouseY = m_CurrentMouseY;
|
||||
m_LastGamepadAxisState = m_CurrentGamepadAxisState;
|
||||
m_LastGamepadButtonState = m_CurrentGamepadButtonState;
|
||||
//m_LastGamepadAxisState = m_CurrentGamepadAxisState;
|
||||
//m_LastGamepadButtonState = m_CurrentGamepadButtonState;
|
||||
}
|
||||
|
||||
void InputManager::PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis)
|
||||
{
|
||||
float currentValue = m_CurrentGamepadAxisState[gamepadID][static_cast<int>(axis)];
|
||||
float lastValue = m_LastGamepadAxisState[gamepadID][static_cast<int>(axis)];
|
||||
if (currentValue != lastValue) {
|
||||
Events::GamepadAxis e;
|
||||
e.GamepadID = gamepadID;
|
||||
e.Axis = axis;
|
||||
e.Value = currentValue;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
//float currentValue = m_CurrentGamepadAxisState[gamepadID][static_cast<int>(axis)];
|
||||
//float lastValue = m_LastGamepadAxisState[gamepadID][static_cast<int>(axis)];
|
||||
//if (currentValue != lastValue) {
|
||||
// Events::GamepadAxis e;
|
||||
// e.GamepadID = gamepadID;
|
||||
// e.Axis = axis;
|
||||
// e.Value = currentValue;
|
||||
// m_EventBroker->Publish(e);
|
||||
//}
|
||||
}
|
||||
|
||||
void InputManager::PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button)
|
||||
{
|
||||
bool currentState = m_CurrentGamepadButtonState[gamepadID][static_cast<int>(button)];
|
||||
float lastState = m_LastGamepadButtonState[gamepadID][static_cast<int>(button)];
|
||||
if (currentState != lastState) {
|
||||
if (currentState == true) {
|
||||
Events::GamepadButtonDown e;
|
||||
e.GamepadID = gamepadID;
|
||||
e.Button = button;
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
Events::GamepadButtonUp e;
|
||||
e.GamepadID = gamepadID;
|
||||
e.Button = button;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InputManager::GLFWCharCallback(GLFWwindow* window, unsigned int c)
|
||||
{
|
||||
GLFWCharCallbackQueue.push_back(c);
|
||||
}
|
||||
|
||||
|
||||
void InputManager::GLFWScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
GLFWScrollCallbackQueue.push_back(std::make_pair(xoffset, yoffset));
|
||||
}
|
||||
|
||||
|
||||
void InputManager::GLFWDropCallback(GLFWwindow* window, int count, const char* paths[])
|
||||
{
|
||||
for (int i = 0; i < count; i++) {
|
||||
GLFWDropCallbackQueue.push_back(std::string(paths[i]));
|
||||
}
|
||||
//bool currentState = m_CurrentGamepadButtonState[gamepadID][static_cast<int>(button)];
|
||||
//float lastState = m_LastGamepadButtonState[gamepadID][static_cast<int>(button)];
|
||||
//if (currentState != lastState) {
|
||||
// if (currentState == true) {
|
||||
// Events::GamepadButtonDown e;
|
||||
// e.GamepadID = gamepadID;
|
||||
// e.Button = button;
|
||||
// m_EventBroker->Publish(e);
|
||||
// } else {
|
||||
// Events::GamepadButtonUp e;
|
||||
// e.GamepadID = gamepadID;
|
||||
// e.Button = button;
|
||||
// m_EventBroker->Publish(e);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
bool InputManager::OnLockMouse(const Events::LockMouse &event)
|
||||
|
||||
@@ -100,7 +100,7 @@ Resource* ResourceManager::Load(std::string resourceType, std::string resourceNa
|
||||
LOG_WARNING("Hot-loading resource \"%s\"", resourceName.c_str());
|
||||
}
|
||||
|
||||
return CreateResource(resourceType, resourceName, parent);
|
||||
return CreateResource(resourceType, resourceName, parent);
|
||||
}
|
||||
|
||||
Resource* ResourceManager::CreateResource(std::string resourceType, std::string resourceName, Resource* parent)
|
||||
@@ -112,16 +112,10 @@ Resource* ResourceManager::CreateResource(std::string resourceType, std::string
|
||||
}
|
||||
|
||||
// Call the factory function
|
||||
Resource* resource;
|
||||
try {
|
||||
resource = facIt->second(resourceName);
|
||||
// Store IDs
|
||||
resource->TypeID = GetTypeID(resourceType);
|
||||
resource->ResourceID = GetNewResourceID(resource->TypeID);
|
||||
} catch (const std::exception& e) {
|
||||
resource = nullptr;
|
||||
LOG_ERROR("Failed to load resource \"%s\" of type \"%s\": %s", resourceName.c_str(), resourceType.c_str(), e.what());
|
||||
}
|
||||
Resource* resource = facIt->second(resourceName);
|
||||
// Store IDs
|
||||
resource->TypeID = GetTypeID(resourceType);
|
||||
resource->ResourceID = GetNewResourceID(resource->TypeID);
|
||||
// Cache
|
||||
m_ResourceCache[std::make_pair(resourceType, resourceName)] = resource;
|
||||
m_ResourceFromName[resourceName] = resource;
|
||||
|
||||
@@ -11,43 +11,12 @@ EntityID World::CreateEntity(EntityID parent /*= 0*/)
|
||||
{
|
||||
EntityID newEntity = generateEntityID();
|
||||
m_EntityParents[newEntity] = parent;
|
||||
m_EntityChildren.insert(std::make_pair(parent, newEntity));
|
||||
if (parent != 0) {
|
||||
m_EntityChildren.insert(std::make_pair(parent, newEntity));
|
||||
}
|
||||
return newEntity;
|
||||
}
|
||||
|
||||
|
||||
void World::DeleteEntity(EntityID entity)
|
||||
{
|
||||
// Delete components
|
||||
for (auto& pair : m_ComponentPools) {
|
||||
auto& pool = pair.second;
|
||||
if (pool->KnowsEntity(entity)) {
|
||||
auto& c = pool->GetByEntity(entity);
|
||||
pool->Delete(c);
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through children
|
||||
std::vector<EntityID> childrenToDelete;
|
||||
auto children = m_EntityChildren.equal_range(entity);
|
||||
for (auto it = children.first; it != children.second; ++it) {
|
||||
childrenToDelete.push_back(it->second);
|
||||
}
|
||||
for (auto& child : childrenToDelete) {
|
||||
DeleteEntity(child);
|
||||
}
|
||||
|
||||
EntityID parent = m_EntityParents.at(entity);
|
||||
m_EntityParents.erase(entity);
|
||||
auto parentChildren = m_EntityChildren.equal_range(parent);
|
||||
for (auto it = parentChildren.first; it != parentChildren.second; ++it) {
|
||||
if (it->second == entity) {
|
||||
m_EntityChildren.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::RegisterComponent(ComponentInfo& ci)
|
||||
{
|
||||
m_ComponentPools[ci.Name] = new ComponentPool(ci);
|
||||
@@ -66,27 +35,12 @@ ComponentWrapper World::AttachComponent(EntityID entity, std::string componentTy
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
bool World::HasComponent(EntityID entity, std::string componentType)
|
||||
{
|
||||
ComponentPool* pool = m_ComponentPools.at(componentType);
|
||||
return pool->KnowsEntity(entity);
|
||||
}
|
||||
|
||||
ComponentWrapper World::GetComponent(EntityID entity, std::string componentType)
|
||||
{
|
||||
ComponentPool* pool = m_ComponentPools.at(componentType);
|
||||
return pool->GetByEntity(entity);
|
||||
}
|
||||
|
||||
|
||||
void World::DeleteComponent(EntityID entity, std::string componentType)
|
||||
{
|
||||
ComponentPool* pool = m_ComponentPools.at(componentType);
|
||||
ComponentWrapper c = pool->GetByEntity(entity);
|
||||
return pool->Delete(c);
|
||||
}
|
||||
|
||||
const ComponentPool* World::GetComponents(std::string componentType)
|
||||
{
|
||||
auto it = m_ComponentPools.find(componentType);
|
||||
@@ -99,22 +53,6 @@ EntityID World::GetParent(EntityID entity)
|
||||
return m_EntityParents.at(entity);
|
||||
}
|
||||
|
||||
|
||||
void World::SetParent(EntityID entity, EntityID parent)
|
||||
{
|
||||
EntityID lastParent = m_EntityParents.at(entity);
|
||||
auto parentChildren = m_EntityChildren.equal_range(lastParent);
|
||||
for (auto it = parentChildren.first; it != parentChildren.second; it++) {
|
||||
if (it->second == entity) {
|
||||
m_EntityChildren.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_EntityParents[entity] = parent;
|
||||
m_EntityChildren.insert(std::make_pair(parent, entity));
|
||||
}
|
||||
|
||||
EntityID World::generateEntityID()
|
||||
{
|
||||
// TODO: Make EntityID generation smarter
|
||||
|
||||
@@ -1,596 +0,0 @@
|
||||
#include "Editor/EditorSystem.h"
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
EditorSystem::EditorSystem(EventBroker* eventBroker, IRenderer* renderer)
|
||||
: ImpureSystem(eventBroker)
|
||||
, m_Renderer(renderer)
|
||||
{
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_Enabled = config->Get<bool>("Debug.EditorEnabled", false);
|
||||
m_Visible = m_Enabled;
|
||||
|
||||
if (!m_Enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &EditorSystem::OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &EditorSystem::OnMousePress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &EditorSystem::OnMouseRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &EditorSystem::OnMouseMove);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPicking, &EditorSystem::OnPicking);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EFileDropped, &EditorSystem::OnFileDropped);
|
||||
}
|
||||
|
||||
void EditorSystem::Update(World* world, double dt)
|
||||
{
|
||||
m_World = world;
|
||||
|
||||
if (!m_Enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_Visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateWidget();
|
||||
|
||||
drawUI(world, dt);
|
||||
|
||||
// Clear drop queue if it wasn't handled by any UI element
|
||||
if (!m_LastDroppedFile.empty()) {
|
||||
m_LastDroppedFile = "";
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorSystem::OnInputCommand(const Events::InputCommand& e)
|
||||
{
|
||||
if (e.Command == "ToggleEditor" && e.Value > 0) {
|
||||
m_Visible = !m_Visible;
|
||||
}
|
||||
|
||||
if (e.Command == "EditorToolMove" && e.Value > 0) {
|
||||
setWidgetMode(WidgetMode::Translate);
|
||||
}
|
||||
if (e.Command == "EditorToolRotate" && e.Value > 0) {
|
||||
setWidgetMode(WidgetMode::Rotate);
|
||||
}
|
||||
if (e.Command == "EditorToolScale" && e.Value > 0) {
|
||||
setWidgetMode(WidgetMode::Scale);
|
||||
}
|
||||
|
||||
if (e.Command == "EditorToggleTransformSpace" && e.Value > 0) {
|
||||
if (m_WidgetSpace == WidgetSpace::Global) {
|
||||
setWidgetSpace(WidgetSpace::Local);
|
||||
} else if (m_WidgetSpace == WidgetSpace::Local) {
|
||||
setWidgetSpace(WidgetSpace::Global);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorSystem::OnMousePress(const Events::MousePress& e)
|
||||
{
|
||||
if (e.Button == GLFW_MOUSE_BUTTON_RIGHT) {
|
||||
m_PickingQueue.push_back(glm::vec2((int)e.X, (int)e.Y));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorSystem::OnMouseMove(const Events::MouseMove& e)
|
||||
{
|
||||
if (m_Widget == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_Selection == 0) {
|
||||
return false;
|
||||
}
|
||||
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
||||
glm::vec3 widgetOrientation = widgetTransform["Orientation"];
|
||||
|
||||
glm::quat totalOrientation = m_Renderer->Camera()->Orientation() * glm::inverse(glm::quat(widgetOrientation));
|
||||
|
||||
int width;
|
||||
int height;
|
||||
glfwGetFramebufferSize(m_Renderer->Window(), &width, &height);
|
||||
Rectangle res(width, height);
|
||||
|
||||
glm::vec2 delta2(res.Width / 2.f + e.DeltaX, res.Height / 2.f + -e.DeltaY);
|
||||
glm::vec3 deltaWorld = ScreenCoords::ToWorldPos(
|
||||
delta2,
|
||||
m_WidgetPickingDepth,
|
||||
res,
|
||||
m_Renderer->Camera()->ProjectionMatrix(),
|
||||
glm::toMat4(glm::inverse(totalOrientation))
|
||||
);
|
||||
glm::vec3 origin = ScreenCoords::ToWorldPos(
|
||||
glm::vec2(res.Width / 2.f, res.Height / 2.f),
|
||||
m_WidgetPickingDepth,
|
||||
res,
|
||||
m_Renderer->Camera()->ProjectionMatrix(),
|
||||
glm::toMat4(glm::inverse(totalOrientation))
|
||||
);
|
||||
deltaWorld = deltaWorld - origin;
|
||||
glm::vec3 movement = deltaWorld * m_WidgetCurrentAxis;
|
||||
|
||||
if (glm::length2(m_WidgetCurrentAxis) > 0.f) {
|
||||
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
||||
if (m_WidgetMode == WidgetMode::Translate) {
|
||||
if (m_WidgetSpace == WidgetSpace::Global) {
|
||||
EntityID parent = m_World->GetParent(m_Selection);
|
||||
glm::quat inverseParentOrientation;
|
||||
if (parent != 0) {
|
||||
inverseParentOrientation = glm::inverse(RenderQueueFactory::AbsoluteOrientation(m_World, parent));
|
||||
}
|
||||
(glm::vec3&)m_World->GetComponent(m_Selection, "Transform")["Position"] += inverseParentOrientation * movement;
|
||||
} else if (m_WidgetSpace == WidgetSpace::Local) {
|
||||
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
||||
(glm::vec3&)selectionTransform["Position"] += glm::quat((glm::vec3)selectionTransform["Orientation"]) * movement;
|
||||
}
|
||||
} else if (m_WidgetMode == WidgetMode::Rotate) {
|
||||
glm::vec3 finalMovement;
|
||||
finalMovement.x = -deltaWorld.y * m_WidgetCurrentAxis.x;
|
||||
finalMovement.y = deltaWorld.x * m_WidgetCurrentAxis.y;
|
||||
finalMovement.z = deltaWorld.y * m_WidgetCurrentAxis.z;
|
||||
if (m_WidgetSpace == WidgetSpace::Global) {
|
||||
EntityID parent = m_World->GetParent(m_Selection);
|
||||
glm::quat parentOrientation;
|
||||
if (parent != 0) {
|
||||
parentOrientation = RenderQueueFactory::AbsoluteOrientation(m_World, parent);
|
||||
}
|
||||
glm::vec3& selectionOrientation = m_World->GetComponent(m_Selection, "Transform")["Orientation"];
|
||||
//glm::quat currentOrientation = RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection);
|
||||
glm::quat currentOrientation = parentOrientation * glm::quat(selectionOrientation);
|
||||
glm::quat deltaOrientation(finalMovement);
|
||||
selectionOrientation = glm::eulerAngles(glm::inverse(parentOrientation) * (deltaOrientation * currentOrientation));
|
||||
} else if (m_WidgetSpace == WidgetSpace::Local) {
|
||||
glm::vec3& selectionOrientation = m_World->GetComponent(m_Selection, "Transform")["Orientation"];
|
||||
glm::quat currentOrientation(selectionOrientation);
|
||||
glm::quat deltaOrientation(finalMovement);
|
||||
selectionOrientation = glm::eulerAngles(currentOrientation * deltaOrientation);
|
||||
}
|
||||
} else if (m_WidgetMode == WidgetMode::Scale) {
|
||||
glm::vec3& scaleX = m_World->GetComponent(m_WidgetX, "Transform")["Scale"];
|
||||
glm::vec3& scaleY = m_World->GetComponent(m_WidgetY, "Transform")["Scale"];
|
||||
glm::vec3& scaleZ = m_World->GetComponent(m_WidgetZ, "Transform")["Scale"];
|
||||
|
||||
if (m_WidgetCurrentAxis.x > 0 && m_WidgetCurrentAxis.y > 0 && m_WidgetCurrentAxis.z > 0) {
|
||||
float movementLength = glm::length(movement);
|
||||
float dot = glm::dot((glm::vec3)widgetOrientation, movement);
|
||||
movement = glm::vec3(movementLength) * glm::sign(dot);
|
||||
(glm::vec3&)m_World->GetComponent(m_WidgetOrigin, "Transform")["Scale"] += movement;
|
||||
}
|
||||
if (m_WidgetCurrentAxis.x > 0) {
|
||||
scaleX.x += movement.x;
|
||||
}
|
||||
if (m_WidgetCurrentAxis.y > 0) {
|
||||
scaleY.y += movement.y;
|
||||
}
|
||||
if (m_WidgetCurrentAxis.z > 0) {
|
||||
scaleZ.z += movement.z;
|
||||
}
|
||||
(glm::vec3&)m_World->GetComponent(m_Selection, "Transform")["Scale"] += movement;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*LOG_DEBUG("DELTA %f", e.DeltaX);
|
||||
if (e.X < 0) {
|
||||
glfwSetCursorPos(m_Renderer->Window(), width - 1, e.Y);
|
||||
}
|
||||
if (e.X >= width) {
|
||||
glfwSetCursorPos(m_Renderer->Window(), 0, e.Y);
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorSystem::OnMouseRelease(const Events::MouseRelease& e)
|
||||
{
|
||||
if (glm::length2(m_WidgetCurrentAxis) > 0.f) {
|
||||
m_WidgetCurrentAxis = glm::vec3(0.f);
|
||||
//setWidgetMode(m_WidgetMode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorSystem::OnPicking(const Events::Picking& e)
|
||||
{
|
||||
for (auto& pos : m_PickingQueue) {
|
||||
auto result = e.Pick(pos);
|
||||
EntityID entity = result.Entity;
|
||||
if (glm::length2(m_WidgetCurrentAxis) > 0.f) {
|
||||
} else {
|
||||
LOG_INFO("Selected %i", entity);
|
||||
if (entity != 0) {
|
||||
EntityID parent = m_World->GetParent(entity);
|
||||
if (parent == m_Widget) {
|
||||
m_WidgetCurrentAxis = glm::vec3(
|
||||
(entity == m_WidgetX) || (entity == m_WidgetOrigin) || (entity == m_WidgetPlaneY || entity == m_WidgetPlaneZ),
|
||||
(entity == m_WidgetY) || (entity == m_WidgetOrigin) || (entity == m_WidgetPlaneX || entity == m_WidgetPlaneZ),
|
||||
(entity == m_WidgetZ) || (entity == m_WidgetOrigin) || (entity == m_WidgetPlaneX || entity == m_WidgetPlaneY)
|
||||
);
|
||||
m_WidgetPickingDepth = result.Depth;
|
||||
|
||||
//auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
||||
//auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
||||
//widgetTransform["Position"] = (glm::vec3)selectionTransform["Position"];
|
||||
} else {
|
||||
ImGui::SetActiveID(0, nullptr);
|
||||
m_Selection = entity;
|
||||
setWidgetMode(m_WidgetMode);
|
||||
}
|
||||
} else {
|
||||
m_Selection = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_PickingQueue.clear();
|
||||
return true;
|
||||
};
|
||||
|
||||
bool EditorSystem::OnFileDropped(const Events::FileDropped& e)
|
||||
{
|
||||
m_LastDroppedFile = boost::filesystem::path(e.Path).lexically_relative(boost::filesystem::current_path()).string();
|
||||
std::replace(m_LastDroppedFile.begin(), m_LastDroppedFile.end(), '\\', '/');
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorSystem::updateWidget()
|
||||
{
|
||||
if (m_Widget == 0) {
|
||||
m_Widget = m_World->CreateEntity();
|
||||
m_World->AttachComponent(m_Widget, "Transform");
|
||||
m_WidgetX = m_World->CreateEntity(m_Widget);
|
||||
m_World->AttachComponent(m_WidgetX, "Transform");
|
||||
m_World->AttachComponent(m_WidgetX, "Model");
|
||||
m_WidgetPlaneX = m_World->CreateEntity(m_Widget);
|
||||
m_World->AttachComponent(m_WidgetPlaneX, "Transform");
|
||||
m_World->AttachComponent(m_WidgetPlaneX, "Model");
|
||||
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/WidgetPlaneX.obj";
|
||||
m_WidgetY = m_World->CreateEntity(m_Widget);
|
||||
m_World->AttachComponent(m_WidgetY, "Transform");
|
||||
m_World->AttachComponent(m_WidgetY, "Model");
|
||||
m_WidgetPlaneY = m_World->CreateEntity(m_Widget);
|
||||
m_World->AttachComponent(m_WidgetPlaneY, "Transform");
|
||||
m_World->AttachComponent(m_WidgetPlaneY, "Model");
|
||||
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/WidgetPlaneY.obj";
|
||||
m_WidgetZ = m_World->CreateEntity(m_Widget);
|
||||
m_World->AttachComponent(m_WidgetZ, "Transform");
|
||||
m_World->AttachComponent(m_WidgetZ, "Model");
|
||||
m_WidgetPlaneZ = m_World->CreateEntity(m_Widget);
|
||||
m_World->AttachComponent(m_WidgetPlaneZ, "Transform");
|
||||
m_World->AttachComponent(m_WidgetPlaneZ, "Model");
|
||||
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/WidgetPlaneZ.obj";
|
||||
m_WidgetOrigin = m_World->CreateEntity(m_Widget);
|
||||
m_World->AttachComponent(m_WidgetOrigin, "Transform");
|
||||
m_World->AttachComponent(m_WidgetOrigin, "Model");
|
||||
setWidgetMode(WidgetMode::Translate);
|
||||
}
|
||||
|
||||
if (m_Selection != 0) {
|
||||
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
||||
glm::vec3 selectionPosition = RenderQueueFactory::AbsolutePosition(m_World, m_Selection);
|
||||
widgetTransform["Position"] = selectionPosition;
|
||||
if (m_WidgetSpace == WidgetSpace::Local) {
|
||||
widgetTransform["Orientation"] = glm::eulerAngles(RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorSystem::setWidgetMode(WidgetMode newMode)
|
||||
{
|
||||
if (m_Widget == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
||||
widgetTransform["Orientation"] = glm::vec3(0.f);
|
||||
m_World->GetComponent(m_WidgetX, "Transform")["Scale"] = glm::vec3(1.f);
|
||||
m_World->GetComponent(m_WidgetPlaneX, "Model")["Visible"] = false;
|
||||
m_World->GetComponent(m_WidgetY, "Transform")["Scale"] = glm::vec3(1.f);
|
||||
m_World->GetComponent(m_WidgetPlaneY, "Model")["Visible"] = false;
|
||||
m_World->GetComponent(m_WidgetZ, "Transform")["Scale"] = glm::vec3(1.f);
|
||||
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Visible"] = false;
|
||||
m_World->GetComponent(m_WidgetOrigin, "Transform")["Scale"] = glm::vec3(1.f);
|
||||
m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = false;
|
||||
|
||||
if (newMode == WidgetMode::Translate) {
|
||||
m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.obj";
|
||||
m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/TranslationWidgetY.obj";
|
||||
m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/TranslationWidgetZ.obj";
|
||||
// Temporarily disabled for local space until I can figure out what's wrong with the math
|
||||
if (m_WidgetSpace != WidgetSpace::Local) {
|
||||
m_World->GetComponent(m_WidgetPlaneX, "Model")["Visible"] = true;
|
||||
m_World->GetComponent(m_WidgetPlaneY, "Model")["Visible"] = true;
|
||||
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Visible"] = true;
|
||||
}
|
||||
if (m_Selection != 0) {
|
||||
if (m_WidgetSpace == WidgetSpace::Local) {
|
||||
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
||||
widgetTransform["Orientation"] = glm::eulerAngles(RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection));
|
||||
}
|
||||
}
|
||||
} else if (newMode == WidgetMode::Scale) {
|
||||
m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.obj";
|
||||
m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/ScaleWidgetY.obj";
|
||||
m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/ScaleWidgetZ.obj";
|
||||
m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = true;
|
||||
m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj";
|
||||
if (m_Selection != 0) {
|
||||
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
||||
widgetTransform["Orientation"] = glm::eulerAngles(RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection));
|
||||
}
|
||||
} else if (newMode == WidgetMode::Rotate) {
|
||||
m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj";
|
||||
m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/RotationWidgetY.obj";
|
||||
m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/RotationWidgetZ.obj";
|
||||
if (m_Selection != 0) {
|
||||
auto selectionTransform = m_World->GetComponent(m_Selection, "Transform");
|
||||
if (m_WidgetSpace == WidgetSpace::Local) {
|
||||
widgetTransform["Orientation"] = glm::eulerAngles(RenderQueueFactory::AbsoluteOrientation(m_World, m_Selection));
|
||||
}
|
||||
}
|
||||
}
|
||||
m_WidgetMode = newMode;
|
||||
}
|
||||
|
||||
|
||||
void EditorSystem::setWidgetSpace(WidgetSpace space)
|
||||
{
|
||||
m_WidgetSpace = space;
|
||||
setWidgetMode(m_WidgetMode);
|
||||
}
|
||||
|
||||
void EditorSystem::drawUI(World* world, double dt)
|
||||
{
|
||||
ImGui::ShowTestWindow();
|
||||
//ImGui::ShowStyleEditor();
|
||||
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
|
||||
if (ImGui::MenuItem("New")) { }
|
||||
if (ImGui::MenuItem("Open", "Ctrl+O")) { }
|
||||
if (ImGui::MenuItem("Save", "Ctrl+S")) { }
|
||||
if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S")) { }
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Close Editor", "F1")) { }
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Move")) {
|
||||
setWidgetMode(WidgetMode::Translate);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Rotate")) {
|
||||
setWidgetMode(WidgetMode::Rotate);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Scale")) {
|
||||
setWidgetMode(WidgetMode::Scale);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (m_WidgetSpace == WidgetSpace::Global) {
|
||||
if (ImGui::Button("(Global)")) {
|
||||
setWidgetSpace(WidgetSpace::Local);
|
||||
}
|
||||
} else if (m_WidgetSpace == WidgetSpace::Local) {
|
||||
if (ImGui::Button("(Local)")) {
|
||||
setWidgetSpace(WidgetSpace::Global);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
std::string title = std::string("Components #") + std::to_string(m_Selection) + std::string("###Components");
|
||||
if (ImGui::Begin(title.c_str())) {
|
||||
if (m_Selection != 0) {
|
||||
auto& pools = world->GetComponentPools();
|
||||
|
||||
std::vector<const char*> componentTypes;
|
||||
for (auto& pair : pools) {
|
||||
// Only add components the entity doesn't already have
|
||||
if (!pair.second->KnowsEntity(m_Selection)) {
|
||||
componentTypes.push_back(pair.first.c_str());
|
||||
}
|
||||
}
|
||||
int item = -1;
|
||||
ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() - 5.f);
|
||||
if (ImGui::Combo("", &item, componentTypes.data(), componentTypes.size())) {
|
||||
if (item != -1) {
|
||||
std::string chosenType = std::string(componentTypes.at(item));
|
||||
world->AttachComponent(m_Selection, chosenType);
|
||||
}
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
for (auto& pair : pools) {
|
||||
const std::string& componentType = pair.first;
|
||||
auto pool = pair.second;
|
||||
if (!pool->KnowsEntity(m_Selection)) {
|
||||
continue;
|
||||
}
|
||||
auto& ci = pool->ComponentInfo();
|
||||
|
||||
bool deletePressed = createDeleteButton(componentType);
|
||||
if (deletePressed) {
|
||||
world->DeleteComponent(m_Selection, componentType);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader(componentType.c_str())) {
|
||||
if (!ci.Meta.Annotation.empty()) {
|
||||
ImGui::Text(ci.Meta.Annotation.c_str());
|
||||
}
|
||||
|
||||
auto& component = world->GetComponent(m_Selection, componentType);
|
||||
for (auto& pair : ci.FieldTypes) {
|
||||
const std::string& field = pair.first;
|
||||
const std::string& type = pair.second;
|
||||
|
||||
ImGui::PushID(field.c_str());
|
||||
if (type == "Vector") {
|
||||
auto& val = component.Property<glm::vec3>(field);
|
||||
if (field == "Scale") {
|
||||
ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, 0.f, std::numeric_limits<float>::max());
|
||||
} else if (field == "Orientation") {
|
||||
glm::vec3 tempVal = glm::fmod(val, glm::vec3(glm::two_pi<float>()));
|
||||
if (ImGui::SliderFloat3("", glm::value_ptr(tempVal), 0.f, glm::two_pi<float>())) {
|
||||
val = tempVal;
|
||||
}
|
||||
} else {
|
||||
ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max());
|
||||
}
|
||||
} else if (type == "Color") {
|
||||
auto& val = component.Property<glm::vec4>(field);
|
||||
ImGui::ColorEdit4("", glm::value_ptr(val), true);
|
||||
} else if (type == "string") {
|
||||
std::string& val = component.Property<std::string>(field);
|
||||
char tempString[1024];
|
||||
memcpy(tempString, val.c_str(), std::min(val.length() + 1, sizeof(tempString)));
|
||||
if (ImGui::InputText("", tempString, sizeof(tempString))) {
|
||||
val = std::string(tempString);
|
||||
LOG_DEBUG("%s::%s changed!", componentType.c_str(), field.c_str());
|
||||
}
|
||||
// DROP STUFF
|
||||
if (ImGui::IsItemHovered() && !m_LastDroppedFile.empty()) {
|
||||
val = m_LastDroppedFile;
|
||||
m_LastDroppedFile = "";
|
||||
}
|
||||
|
||||
} else if (type == "double") {
|
||||
float tempVal = static_cast<float>(component.Property<double>(field));
|
||||
if (ImGui::InputFloat("", &tempVal, 0.01f, 1.f)) {
|
||||
component.SetProperty(field, static_cast<double>(tempVal));
|
||||
}
|
||||
} else if (type == "bool") {
|
||||
auto& val = component.Property<bool>(field);
|
||||
ImGui::Checkbox("", &val);
|
||||
} else {
|
||||
ImGui::TextDisabled(type.c_str());
|
||||
}
|
||||
ImGui::PopID();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(field.c_str());
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("field annotation goes here");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
if (ImGui::Begin("Entitites")) {
|
||||
static EntityID draggingEntity = 0;
|
||||
auto entityChildren = world->GetEntityChildren();
|
||||
std::function<void(EntityID)> recurse = [&](EntityID parent) {
|
||||
auto range = entityChildren.equal_range(parent);
|
||||
for (auto it = range.first; it != range.second; it++) {
|
||||
|
||||
ImVec2 pos = ImGui::GetCursorScreenPos();
|
||||
float width = ImGui::GetContentRegionAvailWidth();
|
||||
ImRect bb(pos + ImVec2(20, 0), pos + ImVec2(width, 13));
|
||||
auto window = ImGui::GetCurrentWindow();
|
||||
if (m_Selection == it->second) {
|
||||
const ImU32 col = window->Color(ImGuiCol_HeaderActive);
|
||||
window->DrawList->AddRectFilled(bb.Min, bb.Max, col);
|
||||
}
|
||||
ImGuiID id = window->GetID((std::string("#SelectButton") + std::to_string(it->second)).c_str());
|
||||
bool hovered = false;
|
||||
bool held = false;
|
||||
if (ImGui::ButtonBehavior(bb, id, &hovered, &held)) {
|
||||
m_Selection = it->second;
|
||||
}
|
||||
if (held) {
|
||||
ImVec2 entityDragDelta = ImGui::GetMouseDragDelta(0);
|
||||
if (std::abs(entityDragDelta.x) > 0 && std::abs(entityDragDelta.y) > 0) {
|
||||
if (draggingEntity == 0) {
|
||||
draggingEntity = it->second;
|
||||
LOG_DEBUG("Started drag of entity %i", draggingEntity);
|
||||
}
|
||||
ImGui::SetNextWindowPos(ImGui::GetIO().MousePos + ImVec2(20, 0));
|
||||
ImGui::Begin("Change parent", nullptr, ImVec2(0, 0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings);
|
||||
ImGui::Text("#%i", draggingEntity);
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SetNextTreeNodeOpened(true, ImGuiSetCond_Once);
|
||||
if (ImGui::TreeNode((std::string("#") + std::to_string(it->second)).c_str())) {
|
||||
if (draggingEntity != 0 && ImGui::IsItemHoveredRect() && ImGui::IsMouseReleased(0)) {
|
||||
LOG_DEBUG("Changed parent of %i to %i", draggingEntity, it->second);
|
||||
changeParent(draggingEntity, it->second);
|
||||
draggingEntity = 0;
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupContextItem("item context menu")) {
|
||||
if (ImGui::Button("Add")) {
|
||||
EntityID entity = world->CreateEntity(it->second);
|
||||
world->AttachComponent(entity, "Transform");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Delete")) {
|
||||
world->DeleteEntity(it->second);
|
||||
ImGui::CloseCurrentPopup();
|
||||
if (m_Selection == it->second) {
|
||||
m_Selection = 0;
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
recurse(it->second);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
};
|
||||
recurse(0);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
bool EditorSystem::createDeleteButton(std::string componentType)
|
||||
{
|
||||
float width = ImGui::GetContentRegionAvailWidth();
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
auto pos = ImGui::GetCursorScreenPos() + ImVec2(width - 14.f, 1);
|
||||
ImRect bb = ImRect(pos, pos + ImVec2(14.f, 14.f));
|
||||
std::string idString = "#DELETE";
|
||||
idString += componentType;
|
||||
ImGuiID id = window->GetID(idString.c_str());
|
||||
bool hovered;
|
||||
bool held;
|
||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);
|
||||
//ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
|
||||
ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
|
||||
window->DrawList->AddCircleFilled(bb.GetCenter(), 7.f, col, 16);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
void EditorSystem::changeParent(EntityID entity, EntityID newParent)
|
||||
{
|
||||
if (entity == newParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// An entity can't be a child to one of its own children
|
||||
auto children = m_World->GetEntityChildren().equal_range(entity);
|
||||
for (auto it = children.first; it != children.second; it++) {
|
||||
if (it->second == newParent) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_World->SetParent(entity, newParent);
|
||||
}
|
||||
@@ -25,11 +25,13 @@ MouseInputHandler::MouseInputHandler(EventBroker* eventBroker, InputProxy* input
|
||||
|
||||
bool MouseInputHandler::BindOrigin(std::string origin, std::string command, float value)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
auto originCode = m_OriginCodes.find(origin);
|
||||
if (originCode != m_OriginCodes.end()) {
|
||||
int code = originCode->second;
|
||||
m_Bindings[code] = std::make_tuple(command, value);
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
auto originAxis = m_OriginAxes.find(origin);
|
||||
@@ -44,10 +46,10 @@ bool MouseInputHandler::BindOrigin(std::string origin, std::string command, floa
|
||||
}
|
||||
}
|
||||
m_Axes[axis] = std::make_tuple(command, value * multiplier);
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
float MouseInputHandler::GetCommandValue(std::string command)
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <Xinput.h>
|
||||
#pragma comment(lib, "Xinput.lib")
|
||||
#pragma comment(lib, "Xinput9_1_0.lib")
|
||||
#include "Input/XboxControllerInputHandler.h"
|
||||
|
||||
XboxControllerInputHandler::XboxControllerInputHandler(EventBroker* eventBroker, InputProxy* inputProxy)
|
||||
: InputHandler(eventBroker, inputProxy)
|
||||
{
|
||||
m_OriginButtons["GamepadUp"] = XINPUT_GAMEPAD_DPAD_UP;
|
||||
m_OriginButtons["GamepadDown"] = XINPUT_GAMEPAD_DPAD_DOWN;
|
||||
m_OriginButtons["GamepadLeft"] = XINPUT_GAMEPAD_DPAD_LEFT;
|
||||
m_OriginButtons["GamepadRight"] = XINPUT_GAMEPAD_DPAD_RIGHT;
|
||||
m_OriginButtons["GamepadStart"] = XINPUT_GAMEPAD_START;
|
||||
m_OriginButtons["GamepadBack"] = XINPUT_GAMEPAD_BACK;
|
||||
m_OriginButtons["GamepadLeftStick"] = XINPUT_GAMEPAD_LEFT_THUMB;
|
||||
m_OriginButtons["GamepadRightStick"] = XINPUT_GAMEPAD_RIGHT_THUMB;
|
||||
m_OriginButtons["GamepadLeftBumper"] = XINPUT_GAMEPAD_LEFT_SHOULDER;
|
||||
m_OriginButtons["GamepadRightBumper"] = XINPUT_GAMEPAD_RIGHT_SHOULDER;
|
||||
m_OriginButtons["GamepadA"] = XINPUT_GAMEPAD_A;
|
||||
m_OriginButtons["GamepadB"] = XINPUT_GAMEPAD_B;
|
||||
m_OriginButtons["GamepadX"] = XINPUT_GAMEPAD_X;
|
||||
m_OriginButtons["GamepadY"] = XINPUT_GAMEPAD_Y;
|
||||
m_OriginAxes["GamepadLeftX"] = 0;
|
||||
m_OriginAxes["GamepadLeftY"] = 1;
|
||||
m_OriginAxes["GamepadRightX"] = 2;
|
||||
m_OriginAxes["GamepadRightY"] = 3;
|
||||
m_OriginAxes["GamepadLeftTrigger"] = 4;
|
||||
m_OriginAxes["GamepadRightTrigger"] = 5;
|
||||
}
|
||||
|
||||
bool XboxControllerInputHandler::BindOrigin(std::string origin, std::string command, float value)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
auto originIt = m_OriginButtons.find(origin);
|
||||
if (originIt != m_OriginButtons.end()) {
|
||||
int button = originIt->second;
|
||||
m_ButtonBindings[button] = std::make_tuple(command, value);
|
||||
result = true;
|
||||
}
|
||||
|
||||
auto originAxis = m_OriginAxes.find(origin);
|
||||
if (originAxis != m_OriginAxes.end()) {
|
||||
char axis = originAxis->second;
|
||||
float multiplier = 0.5f;
|
||||
//// Sensitivity
|
||||
//multiplier *= ResourceManager::Load<ConfigFile>("Input.ini")->Get<float>("Mouse.Sensitivity", 1.f);
|
||||
//if (axis == 'Y') {
|
||||
// if (ResourceManager::Load<ConfigFile>("Input.ini")->Get<bool>("Mouse.InvertPitch", false)) {
|
||||
// multiplier *= -1.f;
|
||||
// }
|
||||
//}
|
||||
m_AxisBindings[axis] = std::make_tuple(command, value * multiplier);
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void XboxControllerInputHandler::Update(double dt)
|
||||
{
|
||||
DWORD dwResult;
|
||||
for (int i = 0; i < MAX_GAMEPADS; i++) {
|
||||
XINPUT_STATE state = { 0 };
|
||||
// Simply get the state of the controller from XInput.
|
||||
dwResult = XInputGetState(i, &state);
|
||||
if (dwResult == 0) {
|
||||
if (std::abs(state.Gamepad.sThumbLX) <= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
|
||||
state.Gamepad.sThumbLX = 0;
|
||||
if (std::abs(state.Gamepad.sThumbLY) <= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
|
||||
state.Gamepad.sThumbLY = 0;
|
||||
if (std::abs(state.Gamepad.sThumbRX) <= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
|
||||
state.Gamepad.sThumbRX = 0;
|
||||
if (std::abs(state.Gamepad.sThumbRY) <= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
|
||||
state.Gamepad.sThumbRY = 0;
|
||||
if (std::abs(state.Gamepad.bLeftTrigger) <= XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
|
||||
state.Gamepad.bLeftTrigger = 0;
|
||||
if (std::abs(state.Gamepad.bRightTrigger) <= XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
|
||||
state.Gamepad.bRightTrigger = 0;
|
||||
|
||||
//m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftX)] = state.Gamepad.sThumbLX / 32767.f;
|
||||
//m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftY)] = state.Gamepad.sThumbLY / 32767.f;
|
||||
//m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightX)] = state.Gamepad.sThumbRX / 32767.f;
|
||||
//m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightY)] = state.Gamepad.sThumbRY / 32767.f;
|
||||
//m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftTrigger)] = state.Gamepad.bLeftTrigger / 255.f;
|
||||
//m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightTrigger)] = state.Gamepad.bRightTrigger / 255.f;
|
||||
//PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftX);
|
||||
//PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftY);
|
||||
//PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightX);
|
||||
//PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightY);
|
||||
//PublishGamepadAxisIfChanged(i, Gamepad::Axis::LeftTrigger);
|
||||
//PublishGamepadAxisIfChanged(i, Gamepad::Axis::RightTrigger);
|
||||
|
||||
for (auto& pair : m_OriginAxes) {
|
||||
const std::string& origin = pair.first;
|
||||
int axis = pair.second;
|
||||
auto& binding = m_AxisBindings.find(axis);
|
||||
if (binding == m_AxisBindings.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = binding->second;
|
||||
|
||||
Events::InputCommand e;
|
||||
e.PlayerID = -1;
|
||||
e.Command = command;
|
||||
e.Value = value * getAxisValue(state, axis);
|
||||
m_InputProxy->Publish(e);
|
||||
}
|
||||
|
||||
for (auto& pair : m_OriginButtons) {
|
||||
auto& binding = m_ButtonBindings.find(pair.second);
|
||||
if (binding == m_ButtonBindings.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string command;
|
||||
float value;
|
||||
std::tie(command, value) = binding->second;
|
||||
bool pressed = static_cast<bool>(state.Gamepad.wButtons & binding->first);
|
||||
m_CommandValues[command] = (pressed) ? value : 0.f;
|
||||
}
|
||||
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Up)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Down)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Left)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Right)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Start)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_START);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Back)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::LeftThumb)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::RightThumb)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::LeftShoulder)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::RightShoulder)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::A)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_A);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::B)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_B);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::X)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_X);
|
||||
//m_CurrentGamepadButtonState[i][static_cast<int>(Gamepad::Button::Y)] = static_cast<bool>(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::Up);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::Down);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::Left);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::Right);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::Start);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::Back);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::LeftThumb);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::RightThumb);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::LeftShoulder);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::RightShoulder);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::A);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::B);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::X);
|
||||
//PublishGamepadButtonIfChanged(i, Gamepad::Button::Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float XboxControllerInputHandler::GetCommandValue(std::string command)
|
||||
{
|
||||
auto it = m_CommandValues.find(command);
|
||||
if (it != m_CommandValues.end()) {
|
||||
return m_CommandValues[command];
|
||||
} else {
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
float XboxControllerInputHandler::getAxisValue(XINPUT_STATE& state, int axis)
|
||||
{
|
||||
switch (axis) {
|
||||
case 0:
|
||||
return state.Gamepad.sThumbLX / 32767.f;
|
||||
case 1:
|
||||
return state.Gamepad.sThumbLY / 32767.f;
|
||||
case 2:
|
||||
return state.Gamepad.sThumbRX / 32767.f;
|
||||
case 3:
|
||||
return state.Gamepad.sThumbRY / 32767.f;
|
||||
case 4:
|
||||
return state.Gamepad.bLeftTrigger / 255.f;
|
||||
case 5:
|
||||
return state.Gamepad.bRightTrigger / 255.f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#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("Renderer::Draw PickingPass");
|
||||
|
||||
DrawScenePassState state;
|
||||
|
||||
|
||||
//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_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("DrawScene Error");
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "Rendering/DrawScenePassState.h"
|
||||
|
||||
|
||||
DrawScenePassState::DrawScenePassState()
|
||||
{
|
||||
GLERROR("---");
|
||||
BindFramebuffer(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,21 +48,13 @@ 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);
|
||||
|
||||
@@ -1,307 +0,0 @@
|
||||
#include "Rendering/ImGuiRenderPass.h"
|
||||
|
||||
ImGuiRenderPass::ImGuiRenderPass(IRenderer* renderer, EventBroker* eventBroker)
|
||||
: m_Renderer(renderer)
|
||||
, m_EventBroker(eventBroker)
|
||||
{
|
||||
g_Window = renderer->Window();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
|
||||
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
||||
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
||||
io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
|
||||
io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP;
|
||||
io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN;
|
||||
io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
|
||||
io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
|
||||
io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
|
||||
io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
|
||||
io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
|
||||
io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
|
||||
io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
|
||||
io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
|
||||
io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
|
||||
io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
|
||||
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
||||
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.Alpha = 1.f;
|
||||
style.WindowPadding = ImVec2(8.f, 7.f);
|
||||
style.WindowRounding = 4.f;
|
||||
style.ChildWindowRounding = 0.f;
|
||||
style.FramePadding = ImVec2(4.f, 2.f);
|
||||
style.FrameRounding = 2.f;
|
||||
style.ItemSpacing = ImVec2(6.f, 2.f);
|
||||
style.ItemInnerSpacing = ImVec2(3.f, 4.f);
|
||||
style.IndentSpacing = 16.f;
|
||||
style.ScrollbarSize = 12;
|
||||
style.ScrollbarRounding = 2.f;
|
||||
style.GrabMinSize = 13.f;
|
||||
style.GrabRounding = 3.f;
|
||||
|
||||
createDeviceObjects();
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &ImGuiRenderPass::OnMousePress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &ImGuiRenderPass::OnMouseRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &ImGuiRenderPass::OnMouseMove);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseScroll, &ImGuiRenderPass::OnMouseScroll);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &ImGuiRenderPass::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &ImGuiRenderPass::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyboardChar, &ImGuiRenderPass::OnKeyboardChar);
|
||||
|
||||
// Prime the first frame
|
||||
newFrame();
|
||||
}
|
||||
|
||||
void ImGuiRenderPass::Update(double dt)
|
||||
{
|
||||
g_DeltaTime = dt;
|
||||
}
|
||||
|
||||
void ImGuiRenderPass::Draw()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
ImDrawData* draw_data = ImGui::GetDrawData();
|
||||
|
||||
// Set up render state
|
||||
ImGuiRenderState state;
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
|
||||
float fb_height = io.DisplaySize.y * io.DisplayFramebufferScale.y;
|
||||
draw_data->ScaleClipRects(io.DisplayFramebufferScale);
|
||||
|
||||
// Setup viewport, orthographic projection matrix
|
||||
glViewport(0, 0, (GLsizei)io.DisplaySize.x, (GLsizei)io.DisplaySize.y);
|
||||
const float ortho_projection[4][4] =
|
||||
{
|
||||
{ 2.0f/io.DisplaySize.x, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 2.0f/-io.DisplaySize.y, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, -1.0f, 0.0f },
|
||||
{ -1.0f, 1.0f, 0.0f, 1.0f },
|
||||
};
|
||||
glUseProgram(g_ShaderHandle);
|
||||
glUniform1i(g_AttribLocationTex, 0);
|
||||
glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
|
||||
glBindVertexArray(g_VaoHandle);
|
||||
|
||||
for (int n = 0; n < draw_data->CmdListsCount; n++) {
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||||
const ImDrawIdx* idx_buffer_offset = 0;
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.size() * sizeof(ImDrawVert), (GLvoid*)&cmd_list->VtxBuffer.front(), GL_STREAM_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx), (GLvoid*)&cmd_list->IdxBuffer.front(), GL_STREAM_DRAW);
|
||||
|
||||
for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++) {
|
||||
if (pcmd->UserCallback) {
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
|
||||
glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
|
||||
}
|
||||
idx_buffer_offset += pcmd->ElemCount;
|
||||
}
|
||||
}
|
||||
|
||||
// Start next frame
|
||||
newFrame();
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::OnMousePress(const Events::MousePress& e)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.MouseDown[e.Button] = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::OnMouseRelease(const Events::MouseRelease& e)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.MouseDown[e.Button] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::OnMouseMove(const Events::MouseMove& e)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.MousePos.x = e.X;
|
||||
io.MousePos.y = e.Y;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::OnMouseScroll(const Events::MouseScroll& e)
|
||||
{
|
||||
g_MouseWheel += (float)e.DeltaY;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::OnKeyDown(const Events::KeyDown& e)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.KeysDown[e.KeyCode] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::OnKeyUp(const Events::KeyUp& e)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.KeysDown[e.KeyCode] = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::OnKeyboardChar(const Events::KeyboardChar& e)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (e.Char > 0 && e.Char < 0x10000) {
|
||||
io.AddInputCharacter((unsigned short)e.Char);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::createDeviceObjects()
|
||||
{
|
||||
// Backup GL state
|
||||
GLint last_texture, last_array_buffer, last_vertex_array;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
|
||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
|
||||
|
||||
const GLchar *vertex_shader =
|
||||
"#version 330\n"
|
||||
"uniform mat4 ProjMtx;\n"
|
||||
"in vec2 Position;\n"
|
||||
"in vec2 UV;\n"
|
||||
"in vec4 Color;\n"
|
||||
"out vec2 Frag_UV;\n"
|
||||
"out vec4 Frag_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Frag_UV = UV;\n"
|
||||
" Frag_Color = Color;\n"
|
||||
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar* fragment_shader =
|
||||
"#version 330\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec2 Frag_UV;\n"
|
||||
"in vec4 Frag_Color;\n"
|
||||
"out vec4 Out_Color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" Out_Color = Frag_Color * texture( Texture, Frag_UV.st);\n"
|
||||
"}\n";
|
||||
|
||||
g_ShaderHandle = glCreateProgram();
|
||||
g_VertHandle = glCreateShader(GL_VERTEX_SHADER);
|
||||
g_FragHandle = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(g_VertHandle, 1, &vertex_shader, 0);
|
||||
glShaderSource(g_FragHandle, 1, &fragment_shader, 0);
|
||||
glCompileShader(g_VertHandle);
|
||||
glCompileShader(g_FragHandle);
|
||||
glAttachShader(g_ShaderHandle, g_VertHandle);
|
||||
glAttachShader(g_ShaderHandle, g_FragHandle);
|
||||
glLinkProgram(g_ShaderHandle);
|
||||
|
||||
g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture");
|
||||
g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx");
|
||||
g_AttribLocationPosition = glGetAttribLocation(g_ShaderHandle, "Position");
|
||||
g_AttribLocationUV = glGetAttribLocation(g_ShaderHandle, "UV");
|
||||
g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color");
|
||||
|
||||
glGenBuffers(1, &g_VboHandle);
|
||||
glGenBuffers(1, &g_ElementsHandle);
|
||||
|
||||
glGenVertexArrays(1, &g_VaoHandle);
|
||||
glBindVertexArray(g_VaoHandle);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
|
||||
glEnableVertexAttribArray(g_AttribLocationPosition);
|
||||
glEnableVertexAttribArray(g_AttribLocationUV);
|
||||
glEnableVertexAttribArray(g_AttribLocationColor);
|
||||
|
||||
#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
|
||||
glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos));
|
||||
glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv));
|
||||
glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col));
|
||||
#undef OFFSETOF
|
||||
|
||||
createFontsTexture();
|
||||
|
||||
// Restore modified GL state
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
|
||||
glBindVertexArray(last_vertex_array);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGuiRenderPass::createFontsTexture()
|
||||
{
|
||||
// Build texture atlas
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
io.Fonts->AddFontFromFileTTF("Fonts/DroidSans.ttf", 13.f);
|
||||
//io.Fonts->AddFontFromFileTTF("Fonts/ProggyClean.ttf", 13.f);
|
||||
//io.Fonts->AddFontFromFileTTF("Fonts/ProggyTiny.ttf", 10.f);
|
||||
//io.Fonts->AddFontFromFileTTF("Fonts/Karla-Regular.ttf", 15.0f);
|
||||
|
||||
unsigned char* pixels;
|
||||
int width, height;
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader.
|
||||
|
||||
// Upload texture to graphics system
|
||||
GLint last_texture;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
|
||||
glGenTextures(1, &g_FontTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
|
||||
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_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
// Store our identifier
|
||||
io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
|
||||
|
||||
// Restore state
|
||||
glBindTexture(GL_TEXTURE_2D, last_texture);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImGuiRenderPass::newFrame()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// Setup display size (every frame to accommodate for window resizing)
|
||||
int w, h;
|
||||
int display_w, display_h;
|
||||
glfwGetWindowSize(g_Window, &w, &h);
|
||||
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
|
||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
||||
|
||||
io.DeltaTime = g_DeltaTime;
|
||||
|
||||
io.KeyCtrl = glfwGetKey(g_Window, GLFW_KEY_LEFT_CONTROL) || glfwGetKey(g_Window, GLFW_KEY_RIGHT_CONTROL);
|
||||
io.KeyShift = glfwGetKey(g_Window, GLFW_KEY_LEFT_SHIFT) || glfwGetKey(g_Window, GLFW_KEY_RIGHT_SHIFT);
|
||||
io.KeyAlt = glfwGetKey(g_Window, GLFW_KEY_LEFT_ALT) || glfwGetKey(g_Window, GLFW_KEY_RIGHT_ALT);
|
||||
|
||||
io.MouseWheel = g_MouseWheel;
|
||||
g_MouseWheel = 0;
|
||||
|
||||
m_EventBroker->Process<ImGuiRenderPass>();
|
||||
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
#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 = 0;
|
||||
int g = 0;
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
|
||||
GLuint ShaderHandle = m_PickingProgram->GetHandle();
|
||||
m_PickingProgram->Bind();
|
||||
|
||||
std::map<EntityID, glm::vec2> entityColors;
|
||||
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
|
||||
if (modelJob) {
|
||||
int pickColor[2] = { r, g };
|
||||
auto color = entityColors.find(modelJob->Entity);
|
||||
if (color != entityColors.end()) {
|
||||
pickColor[0] = color->second[0];
|
||||
pickColor[1] = color->second[1];
|
||||
} else {
|
||||
entityColors[modelJob->Entity] = glm::vec2(pickColor[0], pickColor[1]);
|
||||
if (r + 10 > 255) {
|
||||
r = 0;
|
||||
g += 1;
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
m_PickingBuffer.Unbind();
|
||||
GLERROR("PickingPass Error");
|
||||
|
||||
//Publish pick event every frame with the pick data that can be picked by the event
|
||||
int fbWidth;
|
||||
int fbHeight;
|
||||
glfwGetFramebufferSize(m_Renderer->Window(), &fbWidth, &fbHeight);
|
||||
Events::Picking pickEvent = Events::Picking(
|
||||
&m_PickingBuffer,
|
||||
&m_DepthBuffer,
|
||||
m_Renderer->Camera()->ProjectionMatrix(),
|
||||
m_Renderer->Camera()->ViewMatrix(),
|
||||
Rectangle(fbWidth, fbHeight),
|
||||
&m_PickingColorsToEntity);
|
||||
|
||||
m_EventBroker->Publish(pickEvent);
|
||||
|
||||
delete state;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "Rendering/PickingPassState.h"
|
||||
|
||||
|
||||
PickingPassState::PickingPassState(GLuint frameBuffer)
|
||||
{
|
||||
GLERROR("---2");
|
||||
BindFramebuffer(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()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ RawModel::RawModel(std::string fileName)
|
||||
if (scene == nullptr) {
|
||||
LOG_ERROR("Failed to load model \"%s\"", fileName.c_str());
|
||||
LOG_ERROR("Assimp error: %s", importer.GetErrorString());
|
||||
throw std::runtime_error("Failed to open model file.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto m = scene->mRootNode->mTransformation;
|
||||
@@ -76,15 +76,13 @@ RawModel::RawModel(std::string fileName)
|
||||
}
|
||||
|
||||
// Material diffuse color
|
||||
aiColor3D diffuse;
|
||||
aiColor4D diffuse;
|
||||
material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse);
|
||||
float opacity;
|
||||
material->Get(AI_MATKEY_OPACITY, opacity);
|
||||
desc.DiffuseVertexColor = glm::vec4(diffuse.r, diffuse.g, diffuse.b, opacity);
|
||||
desc.DiffuseVertexColor = glm::vec4(diffuse.r, diffuse.g, diffuse.b, diffuse.a);
|
||||
// Material specular color
|
||||
aiColor3D specular;
|
||||
aiColor4D specular;
|
||||
material->Get(AI_MATKEY_COLOR_SPECULAR, specular);
|
||||
desc.SpecularVertexColor = glm::vec4(specular.r, specular.g, specular.b, 1.f);
|
||||
desc.SpecularVertexColor = glm::vec4(specular.r, specular.g, specular.b, specular.a);
|
||||
|
||||
m_Vertices.push_back(desc);
|
||||
}
|
||||
|
||||
@@ -23,19 +23,15 @@ glm::mat4 RenderQueueFactory::ModelMatrix(World* world, EntityID entity)
|
||||
return modelMatrix;
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 RenderQueueFactory::AbsolutePosition(World* world, EntityID entity)
|
||||
{
|
||||
glm::vec3 position;
|
||||
|
||||
do {
|
||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||
EntityID parent = world->GetParent(entity);
|
||||
if (parent != 0) {
|
||||
position += AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
|
||||
} else {
|
||||
position += (glm::vec3)transform["Position"];
|
||||
}
|
||||
entity = parent;
|
||||
position += (glm::vec3)transform["Position"];
|
||||
entity = world->GetParent(entity);
|
||||
} while (entity != 0);
|
||||
|
||||
return position;
|
||||
@@ -56,15 +52,15 @@ glm::quat RenderQueueFactory::AbsoluteOrientation(World* world, EntityID entity)
|
||||
|
||||
glm::vec3 RenderQueueFactory::AbsoluteScale(World* world, EntityID entity)
|
||||
{
|
||||
glm::vec3 scale(1.f);
|
||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||
glm::vec3 scale = (glm::vec3)transform["Scale"];
|
||||
|
||||
do {
|
||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||
scale *= (glm::vec3)transform["Scale"];
|
||||
entity = world->GetParent(entity);
|
||||
} while (entity != 0);
|
||||
|
||||
return scale;
|
||||
EntityID parent = world->GetParent(entity);
|
||||
if (parent != 0) {
|
||||
return AbsoluteScale(world, parent) * scale;
|
||||
} else {
|
||||
return scale;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
|
||||
@@ -75,19 +71,12 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
|
||||
}
|
||||
|
||||
for (auto& modelC : *models) {
|
||||
bool visible = modelC["Visible"];
|
||||
if (!visible) {
|
||||
continue;
|
||||
}
|
||||
std::string resource = modelC["Resource"];
|
||||
if (resource.empty()) {
|
||||
continue;
|
||||
}
|
||||
glm::vec4 color = modelC["Color"];
|
||||
Model* model = ResourceManager::Load<Model>(resource);
|
||||
if (model == nullptr) {
|
||||
model = ResourceManager::Load<Model>("Models/Core/Error.obj");
|
||||
}
|
||||
|
||||
for (auto texGroup : model->TextureGroups) {
|
||||
ModelJob job;
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
#include "Rendering/RenderState.h"
|
||||
|
||||
bool RenderState::Enable(GLenum cap)
|
||||
{
|
||||
if (glIsEnabled(cap)) {
|
||||
return false;
|
||||
}
|
||||
m_ResetFunctions.push_back(std::bind(glDisable, cap));
|
||||
glEnable(cap);
|
||||
return !GLERROR("RenderState::Enable");
|
||||
}
|
||||
|
||||
bool RenderState::Disable(GLenum cap)
|
||||
{
|
||||
if (!glIsEnabled(cap)) {
|
||||
return false;
|
||||
}
|
||||
m_ResetFunctions.push_back(std::bind(glEnable, cap));
|
||||
glDisable(cap);
|
||||
return !GLERROR("RenderState::Disable");
|
||||
}
|
||||
|
||||
bool RenderState::CullFace(GLenum mode)
|
||||
{
|
||||
if (!glIsEnabled(GL_CULL_FACE)) {
|
||||
LOG_ERROR("Setting GL_CULL_FACE without enabling it.");
|
||||
return false;
|
||||
}
|
||||
|
||||
GLint original;
|
||||
glGetIntegerv(GL_CULL_FACE_MODE, &original);
|
||||
m_ResetFunctions.push_back(std::bind(glCullFace, original));
|
||||
glCullFace(mode);
|
||||
return !GLERROR("RenderState::CullFace");
|
||||
}
|
||||
|
||||
bool RenderState::ClearColor(glm::vec4 color)
|
||||
{
|
||||
GLfloat original[4];
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, &original[0]);
|
||||
m_ResetFunctions.push_back(std::bind(glClearColor, original[0], original[1], original[2], original[3]));
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
return !GLERROR("RenderState::ClearColor");
|
||||
}
|
||||
|
||||
bool RenderState::Clear(GLbitfield mask)
|
||||
{
|
||||
glClear(mask);
|
||||
return !GLERROR("RenderState::Clear");
|
||||
}
|
||||
|
||||
bool RenderState::BindFramebuffer(GLint framebuffer)
|
||||
{
|
||||
GLint originalRead;
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &originalRead);
|
||||
GLint originalDraw;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &originalDraw);
|
||||
m_ResetFunctions.push_back([originalRead, originalDraw]() {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, originalRead);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, originalDraw);
|
||||
});
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
return !GLERROR("RenderState::BindBuffer");
|
||||
}
|
||||
|
||||
|
||||
bool RenderState::BlendEquation(GLenum mode)
|
||||
{
|
||||
GLint originalRGB;
|
||||
glGetIntegerv(GL_BLEND_EQUATION_RGB, &originalRGB);
|
||||
GLint originalAlpha;
|
||||
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &originalAlpha);
|
||||
m_ResetFunctions.push_back(std::bind(glBlendEquationSeparate, originalRGB, originalAlpha));
|
||||
glBlendEquation(mode);
|
||||
return !GLERROR("RenderState::BlendEquation");
|
||||
}
|
||||
|
||||
bool RenderState::BlendFunc(GLenum sfactor, GLenum dfactor)
|
||||
{
|
||||
GLint originalSrcRGB;
|
||||
glGetIntegerv(GL_BLEND_SRC_RGB, &originalSrcRGB);
|
||||
GLint originalSrcAlpha;
|
||||
glGetIntegerv(GL_BLEND_SRC_ALPHA, &originalSrcAlpha);
|
||||
GLint originalDestRGB;
|
||||
glGetIntegerv(GL_BLEND_DST_RGB, &originalDestRGB);
|
||||
GLint originalDestAlpha;
|
||||
glGetIntegerv(GL_BLEND_DST_ALPHA, &originalDestAlpha);
|
||||
m_ResetFunctions.push_back(std::bind(glBlendFuncSeparate, originalSrcRGB, originalSrcAlpha, originalDestRGB, originalDestAlpha));
|
||||
glBlendFunc(sfactor, dfactor);
|
||||
return !GLERROR("RenderState::BlendFunc");
|
||||
}
|
||||
|
||||
RenderState::~RenderState()
|
||||
{
|
||||
for (auto& f : m_ResetFunctions) {
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
||||
+159
-120
@@ -10,20 +10,16 @@ void Renderer::Initialize()
|
||||
if (m_Camera == nullptr) {
|
||||
m_Camera = m_DefaultCamera;
|
||||
}
|
||||
TEMPCreateLights();
|
||||
InitializeRenderPasses();
|
||||
|
||||
glfwSwapInterval(m_VSYNC);
|
||||
InitializeShaders();
|
||||
InitializeTextures();
|
||||
InitializeSSBOs();
|
||||
//CalculateFrustum();
|
||||
InitializeFrameBuffers();
|
||||
|
||||
|
||||
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.obj");
|
||||
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
|
||||
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
||||
|
||||
m_ImGuiRenderPass = new ImGuiRenderPass(this, m_EventBroker);
|
||||
}
|
||||
|
||||
void Renderer::InitializeWindow()
|
||||
@@ -68,23 +64,22 @@ void Renderer::InitializeWindow()
|
||||
|
||||
void Renderer::InitializeShaders()
|
||||
{
|
||||
m_BasicForwardProgram = ResourceManager::Load<ShaderProgram>("#m_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();
|
||||
|
||||
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_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_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_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_LightCullProgram = ResourceManager::Load<ShaderProgram>("#LightCullProgram");
|
||||
//m_LightCullProgram.AddShader(std::shared_ptr<Shader>(new ComputeShader("Shaders/cullLights.comp.glsl")));
|
||||
//m_LightCullProgram.Compile();
|
||||
//m_LightCullProgram.Link();
|
||||
}
|
||||
|
||||
void Renderer::InputUpdate(double dt)
|
||||
@@ -129,23 +124,133 @@ void Renderer::Update(double dt)
|
||||
{
|
||||
m_EventBroker->Process<Renderer>();
|
||||
InputUpdate(dt);
|
||||
m_ImGuiRenderPass->Update(dt);
|
||||
}
|
||||
|
||||
void Renderer::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
m_PickingPass->Draw(rq);
|
||||
//DrawScreenQuad(m_PickingPass->PickingTexture());
|
||||
//CullLights();
|
||||
//TODO: Renderer: Kanske borde vara längst upp i update.
|
||||
PickingPass(rq);
|
||||
DrawScreenQuad(m_PickingTexture);
|
||||
|
||||
glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 1.f);
|
||||
|
||||
m_DrawScenePass->Draw(rq);
|
||||
GLERROR("Renderer::Draw m_DrawScenePass->Draw");
|
||||
m_ImGuiRenderPass->Draw();
|
||||
DrawScene(rq);
|
||||
glfwSwapBuffers(m_Window);
|
||||
}
|
||||
|
||||
void Renderer::DrawScene(RenderQueueCollection& rq)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
//TODO: Render: Clean up draw code
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//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()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_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("DrawScene Error");
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -157,7 +262,7 @@ void Renderer::DrawScreenQuad(GLuint textureToDraw)
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
||||
m_DrawScreenQuadProgram->Bind();
|
||||
m_DrawScreenQuadProgram.Bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, textureToDraw);
|
||||
|
||||
@@ -167,10 +272,24 @@ void Renderer::DrawScreenQuad(GLuint textureToDraw)
|
||||
, 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)
|
||||
@@ -185,95 +304,15 @@ void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filterin
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
void Renderer::InitializeSSBOs()
|
||||
|
||||
|
||||
void Renderer::InitializeFrameBuffers()//TODO: Renderer: Get this to a better location, as its really big
|
||||
{
|
||||
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);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
|
||||
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);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightSSBO);
|
||||
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);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO);
|
||||
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);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO);
|
||||
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);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO);
|
||||
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-1");
|
||||
m_CalculateFrustumProgram->Bind();
|
||||
glGenRenderbuffers(1, &m_DepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Resolution.Width, m_Resolution.Height);
|
||||
|
||||
GLERROR("CalculateFrustum Error1");
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO);
|
||||
GLERROR("CalculateFrustum Error2");
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "P"), 1, false, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||
GLERROR("CalculateFrustum Error3");
|
||||
glUniform2f(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "ScreenDimensions"), m_Resolution.Width, m_Resolution.Height);
|
||||
GLERROR("CalculateFrustum Error4");
|
||||
glDispatchCompute(5, 3, 1);
|
||||
GLERROR("CalculateFrustum Error5");
|
||||
|
||||
}
|
||||
|
||||
void Renderer::TEMPCreateLights()
|
||||
{
|
||||
for (int i = 0; i < NUM_LIGHTS; i++) {
|
||||
m_PointLights[i].Position = glm::vec4(i, 0.f, 0.f, 0.f);
|
||||
m_PointLights[i].Color = glm::vec4(1.f, 0.5f, 0.f + i*0.1f, 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::CullLights()
|
||||
{
|
||||
m_LightCullProgram->Bind();
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -32,10 +32,11 @@ glm::vec3 ScreenCoords::ToWorldPos(glm::vec2 screenCoord, float depth, float scr
|
||||
ScreenCoords::PixelData ScreenCoords::ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
|
||||
{
|
||||
PickDataBuffer->Bind();
|
||||
unsigned char pdata[3];
|
||||
glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pdata);
|
||||
unsigned char pdata[2];
|
||||
glReadPixels(x, y, 1, 1, GL_RG, GL_UNSIGNED_BYTE, &pdata);
|
||||
PickDataBuffer->Unbind();
|
||||
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
|
||||
float depthData;
|
||||
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depthData);
|
||||
|
||||
+7
-7
@@ -6,7 +6,6 @@ Game::Game(int argc, char* argv[])
|
||||
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));
|
||||
@@ -27,13 +26,13 @@ Game::Game(int argc, char* argv[])
|
||||
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<MouseInputHandler>();
|
||||
m_InputProxy->AddHandler<XboxControllerInputHandler>();
|
||||
m_InputProxy->LoadBindings("Input.ini");
|
||||
|
||||
// Create the root level GUI frame
|
||||
@@ -52,7 +51,8 @@ Game::Game(int argc, char* argv[])
|
||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
|
||||
m_SystemPipeline->AddSystem<PlayerSystem>();
|
||||
m_SystemPipeline->AddSystem<EditorSystem>(m_Renderer);
|
||||
|
||||
|
||||
|
||||
m_LastTime = glfwGetTime();
|
||||
|
||||
@@ -67,8 +67,6 @@ Game::~Game()
|
||||
|
||||
void Game::Tick()
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
double currentTime = glfwGetTime();
|
||||
double dt = currentTime - m_LastTime;
|
||||
m_LastTime = currentTime;
|
||||
@@ -80,6 +78,7 @@ void Game::Tick()
|
||||
m_EventBroker->Swap();
|
||||
m_InputProxy->Update(dt);
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
m_InputProxy->Process();
|
||||
m_EventBroker->Swap();
|
||||
|
||||
@@ -89,11 +88,12 @@ void Game::Tick()
|
||||
m_Renderer->Update(dt);
|
||||
|
||||
m_RenderQueueFactory->Update(m_World);
|
||||
GLERROR("Game::Tick m_RenderQueueFactory->Update");
|
||||
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
|
||||
GLERROR("Game::Tick m_Renderer->Draw");
|
||||
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "PlayerSystem.h"
|
||||
|
||||
void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, double dt)
|
||||
|
||||
void PlayerSystem::Update(World * world, ComponentWrapper & player, double dt)
|
||||
{
|
||||
if (input.Forward) {
|
||||
m_Direction.z = -1;
|
||||
|
||||
@@ -11,8 +11,6 @@ RMDIR "%DeployLocation%\Textures"
|
||||
MKLINK "%DeployLocation%\Textures\" "assets\Textures\" /J
|
||||
RMDIR "%DeployLocation%\Audio"
|
||||
MKLINK "%DeployLocation%\Audio\" "assets\Audio\" /J
|
||||
RMDIR "%DeployLocation%\Fonts"
|
||||
MKLINK "%DeployLocation%\Fonts\" "assets\Fonts\" /J
|
||||
|
||||
ECHO Deploying resources to %DeployLocation%
|
||||
:: Schemas
|
||||
|
||||
Reference in New Issue
Block a user