Separated OpenGL specific code into its own "compilation unit"

This commit is contained in:
2015-10-06 19:11:19 +02:00
parent 116cfb5759
commit 13360856f9
28 changed files with 258 additions and 152 deletions
+4 -1
View File
@@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.0)
project(daydream)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/deps/include")
@@ -24,6 +23,10 @@ endif()
set(BUILD_SHARED_LIBS FALSE)
include_directories(${PROJECT_SOURCE_DIR}/include)
# Compiling for OpenGL target
include_directories(${PROJECT_SOURCE_DIR}/include/Rendering/OpenGL)
# Compiling for DirectX target
#include_directories(${PROJECT_SOURCE_DIR}/include/Rendering/DirectX)
#set(GLEW_INCLUDE_DIR ${daydream_SOURCE_DIR}/libs/glew-1.11.0/include)
#set(GLEW_LIBRARY ${daydream_SOURCE_DIR}/libs/glew-1.11.0/lib/Release/glew32.lib)
-102
View File
@@ -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
+5 -5
View File
@@ -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"
+2 -16
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -2,7 +2,7 @@
#define GUI_TextureFrame_h__
#include "GUI/Frame.h"
#include "Core/Texture.h"
#include "Rendering/Texture.h"
namespace dd
{
+1 -1
View File
@@ -20,7 +20,7 @@
#define Components_PointLight_h__
#include "Core/Component.h"
#include "Core/Color.h"
#include "Rendering/Color.h"
namespace dd
{
View File
@@ -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
{
+210
View File
@@ -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__
+14 -2
View File
@@ -53,6 +53,16 @@ file(GLOB SOURCE_FILES_Rendering
"Rendering/*.cpp"
)
source_group(Rendering FILES ${SOURCE_FILES_Rendering})
file(GLOB SOURCE_FILES_Rendering_OpenGL
"${INCLUDE_PATH}/Rendering/OpenGL/Rendering/*.h"
"Rendering/OpenGL/*.cpp"
)
source_group(Rendering\\OpenGL FILES ${SOURCE_FILES_Rendering_OpenGL})
file(GLOB SOURCE_FILES_Rendering_DirectX
"${INCLUDE_PATH}/Rendering/DirectX/Rendering/*.h"
"Rendering/DirectX/*.cpp"
)
source_group(Rendering\\DirectX FILES ${SOURCE_FILES_Rendering_DirectX})
file(GLOB SOURCE_FILES_Transform
"${INCLUDE_PATH}/Transform/*.h"
@@ -61,8 +71,8 @@ file(GLOB SOURCE_FILES_Transform
source_group(Transform FILES ${SOURCE_FILES_Transform})
file(GLOB SOURCE_FILES_Physics
"${INCLUDE_PATH}/Physics/*.h"
"Physics/*.cpp"
"${INCLUDE_PATH}/Physics/*.h"
"Physics/*.cpp"
)
source_group(Physics FILES ${SOURCE_FILES_Physics})
@@ -94,6 +104,8 @@ set(SOURCE_FILES
${SOURCE_FILES_Core_Util}
${SOURCE_FILES_Input}
${SOURCE_FILES_Rendering}
${SOURCE_FILES_Rendering_OpenGL}
${SOURCE_FILES_Rendering_DirectX}
${SOURCE_FILES_Transform}
${SOURCE_FILES_Physics}
${SOURCE_FILES_Game}
-3
View File
@@ -1,3 +0,0 @@
#include "PrecompiledHeader.h"
#include "Core/BGFXRenderer.h"
+1 -1
View File
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/Camera.h"
#include "Rendering/Camera.h"
dd::Camera::Camera(float aspectRatio, float yFOV, float nearClip, float farClip)
{
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/OBJ.h"
#include "Rendering/OBJ.h"
bool dd::OBJ::LoadFromFile(std::string filename)
{
+1 -1
View File
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/Model.h"
#include "Rendering/Model.h"
dd::Model::Model(std::string fileName)
{
+1 -1
View File
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/Renderer.h"
#include "Rendering/Renderer.h"
void dd::Renderer::Initialize()
{
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/ShaderProgram.h"
#include "Rendering/ShaderProgram.h"
void dd::Shader::Compile()
{
+1 -1
View File
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/Texture.h"
#include "Rendering/Texture.h"
dd::Texture::Texture(std::string path)
{
+1 -1
View File
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/PNG.h"
#include "Rendering/PNG.h"
dd::PNG::PNG(std::string path)
{
@@ -17,7 +17,7 @@
*/
#include "PrecompiledHeader.h"
#include "Core/Skeleton.h"
#include "Rendering/Skeleton.h"
int dd::Skeleton::CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix)
{