Semi-working base for bgfx renderer

This commit is contained in:
2015-09-08 16:13:59 +02:00
parent c7f17c8ef0
commit c24b039005
47 changed files with 11176 additions and 43 deletions
+94
View File
@@ -0,0 +1,94 @@
#ifndef BGFXRenderer_h__
#define BGFXRenderer_h__
#include <bgfx.h>
#include <bgfxplatform.h>
#include "Util/Rectangle.h"
#include "Core/Camera.h"
#include "Core/RenderQueue.h"
namespace dd
{
class BGFXRenderer
{
public:
GLFWwindow* Window() const { return m_Window; }
Rectangle Resolution() const { return m_Resolution; }
void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; }
bool Fullscreen() { return m_Fullscreen; }
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
bool VSYNC() const { return m_VSYNC; }
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
//void SetViewport(const Rectangle& viewport) { m_Viewport = viewport; }
//void SetScissor(const Rectangle& scissor) { m_Scissor = scissor; }
const dd::Camera* Camera() const { return m_Camera; }
void SetCamera(const dd::Camera* camera)
{
if (camera == nullptr) {
m_Camera = m_DefaultCamera.get();
} else {
m_Camera = camera;
}
}
void Initialize()
{
// Initialize GLFW
if (!glfwInit()) {
LOG_ERROR("GLFW: Initialization failed");
exit(EXIT_FAILURE);
}
// Create a window
GLFWmonitor* monitor = nullptr;
if (m_Fullscreen) {
monitor = glfwGetPrimaryMonitor();
}
glfwWindowHint(GLFW_SAMPLES, 8);
m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height, "daydream", monitor, nullptr);
if (!m_Window) {
LOG_ERROR("GLFW: Failed to create window");
exit(EXIT_FAILURE);
}
//glfwMakeContextCurrent(m_Window);
// Initialize GLEW
// if (glewInit() != GLEW_OK) {
// LOG_ERROR("GLEW: Initialization failed");
// exit(EXIT_FAILURE);
// }
//LOG_ERROR("STUFF");
// Initialize bgfx
bgfx::glfwSetWindow(m_Window);
bgfx::init();
bgfx::reset(m_Resolution.Width, m_Resolution.Height, BGFX_RESET_NONE);
bgfx::setDebug(BGFX_DEBUG_TEXT);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030ff, 1.0f, 0);
}
void Draw(RenderQueueCollection& rq)
{
bgfx::touch(0);
bgfx::dbgTextClear();
bgfx::dbgTextPrintf(0, 1, 0x4f, "daydream");
bgfx::frame();
}
private:
Rectangle m_Resolution = Rectangle(1280, 720);
bool m_Fullscreen = false;
bool m_VSYNC = false;
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
const dd::Camera* m_Camera = nullptr;
GLFWwindow* m_Window = nullptr;
};
}
#endif
+38 -38
View File
@@ -25,7 +25,7 @@
#include "Texture.h"
#include "EventBroker.h"
#include "RenderQueue.h"
#include "Renderer.h"
#include "BGFXRenderer.h"
#include "InputManager.h"
//TODO: Remove includes that are only here for the temporary draw solution.
#include "World.h"
@@ -42,30 +42,30 @@ class Engine
public:
Engine(int argc, char* argv[])
{
m_EventBroker = std::make_shared<EventBroker>();
// m_EventBroker = std::make_shared<EventBroker>();
m_Renderer = std::make_shared<Renderer>();
m_Renderer = std::make_shared<BGFXRenderer>();
m_Renderer->SetFullscreen(false);
m_Renderer->SetResolution(Rectangle(0, 0, 1920, 1080));
m_Renderer->SetResolution(Rectangle(0, 0, 1280, 720));
m_Renderer->Initialize();
m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
// m_InputManager = std::make_shared<InputManager>(m_Renderer->Window(), m_EventBroker);
//
// m_World = std::make_shared<World>(m_EventBroker);
//
// //TODO: Move this out of engine.h
// m_World->ComponentFactory.Register<Components::Transform>();
// m_World->SystemFactory.Register<Systems::TransformSystem>([this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
// m_World->AddSystem<Systems::TransformSystem>();
// m_World->ComponentFactory.Register<Components::Model>();
// m_World->ComponentFactory.Register<Components::Template>();
// m_World->Initialize();
m_World = std::make_shared<World>(m_EventBroker);
//TODO: Move this out of engine.h
m_World->ComponentFactory.Register<Components::Transform>();
m_World->SystemFactory.Register<Systems::TransformSystem>([this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::TransformSystem>();
m_World->ComponentFactory.Register<Components::Model>();
m_World->ComponentFactory.Register<Components::Template>();
m_World->Initialize();
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.f, 0.f, -10.f);
std::shared_ptr<Components::Model> model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Core/UnitSphere.obj";
// auto ent = m_World->CreateEntity();
// std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
// transform->Position = glm::vec3(0.f, 0.f, -10.f);
// std::shared_ptr<Components::Model> model = m_World->AddComponent<Components::Model>(ent);
// model->ModelFile = "Models/Core/UnitSphere.obj";
m_LastTime = glfwGetTime();
@@ -79,26 +79,26 @@ public:
double dt = currentTime - m_LastTime;
m_LastTime = currentTime;
ResourceManager::Update();
// Update input
m_InputManager->Update(dt);
m_World->Update(dt);
if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
}
//TODO Fill up the renderQueue with models (Temp fix)
TEMPAddToRenderQueue();
// Render scene
//TODO send renderqueue to draw.
// ResourceManager::Update();
//
// // Update input
// m_InputManager->Update(dt);
//
// m_World->Update(dt);
//
// if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
// ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
// }
//
// //TODO Fill up the renderQueue with models (Temp fix)
// TEMPAddToRenderQueue();
//
// // Render scene
// //TODO send renderqueue to draw.
m_Renderer->Draw(m_RendererQueue);
// Swap event queues
m_EventBroker->Clear();
// m_EventBroker->Clear();
glfwPollEvents();
}
@@ -170,7 +170,7 @@ public:
private:
//std::shared_ptr<ResourceManager> m_ResourceManager;
std::shared_ptr<EventBroker> m_EventBroker;
std::shared_ptr<Renderer> m_Renderer;
std::shared_ptr<BGFXRenderer> m_Renderer;
RenderQueueCollection m_RendererQueue;
std::shared_ptr<InputManager> m_InputManager;
std::shared_ptr<World> m_World;
+3 -2
View File
@@ -47,12 +47,13 @@ namespace dd
enum class FileWatcher::FileEventFlags
{
None = 0,
Nothing = 0,
Created = 1 << 0,
SizeChanged = 1 << 1,
TimestampChanged = 1 << 2,
Deleted = 1 << 3,
Deleted = 1 << 3
};
inline FileWatcher::FileEventFlags operator|(FileWatcher::FileEventFlags a, FileWatcher::FileEventFlags b) { return static_cast<FileWatcher::FileEventFlags>(static_cast<int>(a) | static_cast<int>(b)); }
inline bool operator&(FileWatcher::FileEventFlags a, FileWatcher::FileEventFlags b) { return static_cast<int>(a)& static_cast<int>(b); }