Separated OpenGL specific code into its own "compilation unit"
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
#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::RendererType::OpenGL, BGFX_PCI_ID_NONE, 0, nullptr, nullptr);
|
||||
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);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << bgfx::getRendererName(bgfx::getRendererType());
|
||||
#ifdef DEBUG
|
||||
ss << " DEBUG";
|
||||
#endif
|
||||
LOG_INFO(ss.str().c_str());
|
||||
glfwSetWindowTitle(m_Window, ss.str().c_str());
|
||||
}
|
||||
|
||||
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
|
||||
@@ -21,12 +21,12 @@
|
||||
#include <Sound/CCollisionSound.h>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "OBJ.h"
|
||||
#include "Model.h"
|
||||
#include "Texture.h"
|
||||
#include "Rendering/OBJ.h"
|
||||
#include "Rendering/Model.h"
|
||||
#include "Rendering/Texture.h"
|
||||
#include "EventBroker.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "Renderer.h"
|
||||
#include "Rendering/RenderQueue.h"
|
||||
#include "Rendering/Renderer.h"
|
||||
#include "InputManager.h"
|
||||
//TODO: Remove includes that are only here for the temporary draw solution.
|
||||
#include "World.h"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include <forward_list>
|
||||
|
||||
#include "Core/Util/Rectangle.h"
|
||||
#include "Core/Texture.h"
|
||||
#include "Core/Model.h"
|
||||
#include "Rendering/Texture.h"
|
||||
#include "Rendering/Model.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -78,20 +78,6 @@ struct ModelJob : RenderJob
|
||||
}
|
||||
};
|
||||
|
||||
struct BlendMapModelJob : ModelJob
|
||||
{
|
||||
GLuint BlendMapTextureRed;
|
||||
GLuint BlendMapTextureRedNormal;
|
||||
GLuint BlendMapTextureRedSpecular;
|
||||
GLuint BlendMapTextureGreen;
|
||||
GLuint BlendMapTextureGreenNormal;
|
||||
GLuint BlendMapTextureGreenSpecular;
|
||||
GLuint BlendMapTextureBlue;
|
||||
GLuint BlendMapTextureBlueNormal;
|
||||
GLuint BlendMapTextureBlueSpecular;
|
||||
float TextureRepeat;
|
||||
};
|
||||
|
||||
struct SpriteJob : RenderJob
|
||||
{
|
||||
unsigned int ShaderID;
|
||||
|
||||
+3
-3
@@ -9,9 +9,9 @@
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/Renderer.h"
|
||||
#include "Core/RenderQueue.h"
|
||||
#include "Core/Texture.h"
|
||||
#include "Rendering/Renderer.h"
|
||||
#include "Rendering/RenderQueue.h"
|
||||
#include "Rendering/Texture.h"
|
||||
#include "Input/EInputCommand.h"
|
||||
|
||||
namespace dd
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define GUI_TextureFrame_h__
|
||||
|
||||
#include "GUI/Frame.h"
|
||||
#include "Core/Texture.h"
|
||||
#include "Rendering/Texture.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#define Components_PointLight_h__
|
||||
|
||||
#include "Core/Component.h"
|
||||
#include "Core/Color.h"
|
||||
#include "Rendering/Color.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
Executable → Regular
@@ -30,7 +30,7 @@
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -34,8 +34,8 @@
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/Texture.h"
|
||||
#include "Core/Skeleton.h"
|
||||
#include "Rendering/Texture.h"
|
||||
#include "Rendering/Skeleton.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -19,16 +19,16 @@
|
||||
#ifndef DD_RENDERER_H__
|
||||
#define DD_RENDERER_H__
|
||||
|
||||
#include "Util/Rectangle.h"
|
||||
#include "Core/Util/Rectangle.h"
|
||||
#include "Rendering/Camera.h"
|
||||
#include "Rendering/RenderQueue.h"
|
||||
#include "Rendering/ShaderProgram.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Core/CTemplate.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/World.h"
|
||||
#include "Game/EScreenShake.h"
|
||||
#include "Camera.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -23,8 +23,8 @@
|
||||
#include <unordered_map>
|
||||
#include <cstdio>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "PNG.h"
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Rendering/PNG.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RenderQueue_h__
|
||||
#define RenderQueue_h__
|
||||
|
||||
#include <cstdint>
|
||||
#include <forward_list>
|
||||
|
||||
#include "Core/Util/Rectangle.h"
|
||||
#include "Rendering/Texture.h"
|
||||
#include "Rendering/Model.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class RenderQueue;
|
||||
|
||||
struct RenderJob
|
||||
{
|
||||
friend class RenderQueue;
|
||||
|
||||
float Depth;
|
||||
|
||||
protected:
|
||||
uint64_t Hash;
|
||||
|
||||
virtual void CalculateHash() = 0;
|
||||
|
||||
bool operator<(const RenderJob& rhs)
|
||||
{
|
||||
return this->Hash < rhs.Hash;
|
||||
}
|
||||
};
|
||||
|
||||
struct ModelJob : RenderJob
|
||||
{
|
||||
unsigned int ShaderID;
|
||||
unsigned int TextureID;
|
||||
|
||||
glm::mat4 ProjectionMatrix;
|
||||
glm::mat4 ViewMatrix;
|
||||
glm::mat4 ModelMatrix;
|
||||
GLuint DiffuseTexture;
|
||||
GLuint NormalTexture;
|
||||
GLuint SpecularTexture;
|
||||
float Shininess;
|
||||
glm::vec4 Color;
|
||||
GLuint VAO;
|
||||
GLuint ElementBuffer;
|
||||
unsigned int StartIndex;
|
||||
unsigned int EndIndex;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = TextureID;
|
||||
}
|
||||
};
|
||||
|
||||
struct BlendMapModelJob : ModelJob
|
||||
{
|
||||
GLuint BlendMapTextureRed;
|
||||
GLuint BlendMapTextureRedNormal;
|
||||
GLuint BlendMapTextureRedSpecular;
|
||||
GLuint BlendMapTextureGreen;
|
||||
GLuint BlendMapTextureGreenNormal;
|
||||
GLuint BlendMapTextureGreenSpecular;
|
||||
GLuint BlendMapTextureBlue;
|
||||
GLuint BlendMapTextureBlueNormal;
|
||||
GLuint BlendMapTextureBlueSpecular;
|
||||
float TextureRepeat;
|
||||
};
|
||||
|
||||
struct SpriteJob : RenderJob
|
||||
{
|
||||
unsigned int ShaderID;
|
||||
unsigned int TextureID;
|
||||
|
||||
glm::mat4 ProjectionMatrix;
|
||||
glm::mat4 ViewMatrix;
|
||||
glm::mat4 ModelMatrix;
|
||||
GLuint DiffuseTexture;
|
||||
GLuint NormalTexture;
|
||||
GLuint SpecularTexture;
|
||||
glm::vec4 Color;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = TextureID;
|
||||
}
|
||||
};
|
||||
|
||||
struct PointLightJob : RenderJob
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 SpecularColor = glm::vec3(1, 1, 1);
|
||||
glm::vec3 DiffuseColor = glm::vec3(1, 1, 1);
|
||||
float Radius = 1.f;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct FrameJob : SpriteJob
|
||||
{
|
||||
Rectangle Scissor;
|
||||
Rectangle Viewport;
|
||||
std::string Name;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct WaterParticleJob : RenderJob
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec4 Color;
|
||||
glm::mat4 ModelMatrix;
|
||||
|
||||
void CalculateHash() override
|
||||
{
|
||||
Hash = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class RenderQueue
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
void Add(T &job)
|
||||
{
|
||||
job.CalculateHash();
|
||||
Jobs.push_back(std::shared_ptr<T>(new T(job)));
|
||||
m_Size++;
|
||||
}
|
||||
|
||||
void Sort()
|
||||
{
|
||||
Jobs.sort();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Jobs.clear();
|
||||
m_Size = 0;
|
||||
}
|
||||
|
||||
int Size() const { return m_Size; }
|
||||
std::list<std::shared_ptr<RenderJob>>::const_iterator begin()
|
||||
{
|
||||
return Jobs.begin();
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<RenderJob>>::const_iterator end()
|
||||
{
|
||||
return Jobs.end();
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<RenderJob>> Jobs;
|
||||
|
||||
private:
|
||||
int m_Size = 0;
|
||||
};
|
||||
|
||||
struct RenderQueueCollection
|
||||
{
|
||||
RenderQueue Deferred;
|
||||
RenderQueue Forward;
|
||||
RenderQueue Lights;
|
||||
RenderQueue GUI;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Deferred.Clear();
|
||||
Forward.Clear();
|
||||
Lights.Clear();
|
||||
GUI.Clear();
|
||||
}
|
||||
|
||||
void Sort()
|
||||
{
|
||||
Deferred.Sort();
|
||||
Forward.Sort();
|
||||
Lights.Sort();
|
||||
GUI.Sort();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // RenderQueue_h__
|
||||
Reference in New Issue
Block a user