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
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
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 Camera_h__
|
||||
#define Camera_h__
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
/** Camera constructor.
|
||||
|
||||
@param aspectRatio Aspect ratio.
|
||||
@param yFOV Vertical FOV.
|
||||
@param nearClip Near clipping plane in meters.
|
||||
@param farClip Far clipping plane in meters.
|
||||
*/
|
||||
Camera(float aspectRatio, float yFOV, float nearClip, float farClip);
|
||||
|
||||
/** Forward vector of the camera */
|
||||
glm::vec3 Forward();
|
||||
/** Right vector of the camera */
|
||||
glm::vec3 Right();
|
||||
|
||||
glm::vec3 Position() const { return m_Position; }
|
||||
void SetPosition(glm::vec3 val);
|
||||
|
||||
glm::quat Orientation() const { return m_Orientation; }
|
||||
void SetOrientation(glm::quat val);
|
||||
|
||||
/*float Pitch() const { return m_Pitch; }
|
||||
void Pitch(float val);
|
||||
float Yaw() const { return m_Yaw; }
|
||||
void Yaw(float val);*/
|
||||
|
||||
glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; }
|
||||
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
|
||||
|
||||
float AspectRatio() const { return m_AspectRatio; }
|
||||
void SetAspectRatio(float val);
|
||||
|
||||
float FOV() const { return m_FOV; }
|
||||
void SetFOV(float val);
|
||||
|
||||
float NearClip() const { return m_NearClip; }
|
||||
void SetNearClip(float val);
|
||||
|
||||
float FarClip() const { return m_FarClip; }
|
||||
void SetFarClip(float val);
|
||||
|
||||
private:
|
||||
void UpdateViewMatrix();
|
||||
void UpdateProjectionMatrix();
|
||||
|
||||
float m_AspectRatio;
|
||||
float m_FOV;
|
||||
float m_NearClip;
|
||||
float m_FarClip;
|
||||
|
||||
glm::vec3 m_Position;
|
||||
glm::quat m_Orientation;
|
||||
|
||||
glm::mat4 m_ProjectionMatrix;
|
||||
glm::mat4 m_ViewMatrix;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // Camera_h__
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
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 Color_h__
|
||||
#define Color_h__
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
struct Color
|
||||
{
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // !Color_h__
|
||||
@@ -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"
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
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 Image_h
|
||||
#define Image_h
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
struct Image
|
||||
{
|
||||
enum class ImageFormat
|
||||
{
|
||||
Unknown,
|
||||
RGB,
|
||||
RGBA
|
||||
};
|
||||
|
||||
unsigned int Width = 0;
|
||||
unsigned int Height = 0;
|
||||
ImageFormat Format = ImageFormat::Unknown;
|
||||
unsigned char* Data = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
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 Model_h__
|
||||
#define Model_h__
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
#include <stack>
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Core/Texture.h"
|
||||
#include "Core/Skeleton.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class Model : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
private:
|
||||
Model(std::string fileName);
|
||||
|
||||
public:
|
||||
~Model();
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Normal;
|
||||
glm::vec3 Tangent;
|
||||
glm::vec3 BiTangent;
|
||||
glm::vec2 TextureCoords;
|
||||
glm::vec4 DiffuseVertexColor;
|
||||
glm::vec4 SpecularVertexColor;
|
||||
glm::vec4 BoneIndices1;
|
||||
glm::vec4 BoneIndices2;
|
||||
glm::vec4 BoneWeights1;
|
||||
glm::vec4 BoneWeights2;
|
||||
};
|
||||
|
||||
struct MaterialGroup
|
||||
{
|
||||
float Shininess;
|
||||
std::shared_ptr<dd::Texture> Texture;
|
||||
std::shared_ptr<dd::Texture> NormalMap;
|
||||
std::shared_ptr<dd::Texture> SpecularMap;
|
||||
unsigned int StartIndex;
|
||||
unsigned int EndIndex;
|
||||
};
|
||||
|
||||
GLuint VAO;
|
||||
GLuint ElementBuffer;
|
||||
std::vector<MaterialGroup> TextureGroups;
|
||||
|
||||
std::vector<std::shared_ptr<Texture>> texture;
|
||||
glm::mat4 GetMatrix();
|
||||
std::vector<glm::vec3> Vertices;
|
||||
std::vector<Vertex> m_Vertices;
|
||||
std::vector<unsigned int> m_Indices;
|
||||
Skeleton* m_Skeleton = nullptr;
|
||||
|
||||
glm::mat4 m_Matrix;
|
||||
|
||||
private:
|
||||
std::vector<glm::ivec2> BoneIndices;
|
||||
std::vector<glm::vec2> BoneWeights;
|
||||
std::vector<glm::vec3> Normals;
|
||||
std::vector<glm::vec4> DiffuseVertexColor;
|
||||
std::vector<glm::vec4> SpecularVertexColor;
|
||||
std::vector<glm::vec3> TangentNormals;
|
||||
std::vector<glm::vec3> BiTangentNormals;
|
||||
std::vector<glm::vec2> TextureCoords;
|
||||
|
||||
GLuint VertexBuffer;
|
||||
GLuint DiffuseVertexColorBuffer;
|
||||
GLuint SpecularVertexColorBuffer;
|
||||
GLuint NormalBuffer;
|
||||
GLuint TangentNormalsBuffer;
|
||||
GLuint BiTangentNormalsBuffer;
|
||||
GLuint TextureCoordBuffer;
|
||||
|
||||
void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // Model_h__
|
||||
@@ -1,150 +0,0 @@
|
||||
/*
|
||||
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 OBJ_h__
|
||||
#define OBJ_h__
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <map>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class OBJ : public Resource
|
||||
{
|
||||
public:
|
||||
struct MaterialInfo
|
||||
{
|
||||
struct TextureMap
|
||||
{
|
||||
TextureMap()
|
||||
: blendu(true)
|
||||
, blendv(true)
|
||||
, clamp(false)
|
||||
, o(std::make_tuple(0.f, 0.f, 0.f))
|
||||
, s(std::make_tuple(1.f, 1.f, 1.f)) { }
|
||||
|
||||
std::string FileName;
|
||||
|
||||
// http://paulbourke.net/dataformats/mtl/
|
||||
// "These options are described in detail in 'Options for texture map statements' on page 5-18."
|
||||
|
||||
// Horizontal texture blending
|
||||
bool blendu; // = true
|
||||
// Vertical texture blending
|
||||
bool blendv; // = true
|
||||
// Clamping
|
||||
bool clamp; // = false
|
||||
// Offset
|
||||
std::tuple<float, float, float> o; // = (0, 0, 0)
|
||||
// Scale
|
||||
std::tuple<float, float, float> s; // = (1, 1, 1)
|
||||
};
|
||||
|
||||
struct ColorMap : public TextureMap
|
||||
{
|
||||
ColorMap()
|
||||
: cc(false) { }
|
||||
|
||||
// Color correction
|
||||
bool cc; // = false
|
||||
};
|
||||
|
||||
struct BumpMap : public TextureMap
|
||||
{
|
||||
BumpMap()
|
||||
: bm(1.f) { }
|
||||
|
||||
// Bump multiplier
|
||||
float bm; // = 1?
|
||||
};
|
||||
|
||||
MaterialInfo()
|
||||
: AmbientColor(std::make_tuple(0.2f, 0.2f, 0.2f))
|
||||
, DiffuseColor(std::make_tuple(0.8f, 0.8f, 0.8f))
|
||||
, SpecularColor(std::make_tuple(1.0f, 1.0f, 1.0f))
|
||||
, TransmissionFilter(std::make_tuple(1.0f, 1.0f, 1.0f))
|
||||
, OpticalDensity(1.0f)
|
||||
, Alpha(1.0f)
|
||||
, Shininess(0.0f)
|
||||
, IlluminationModel(0) { }
|
||||
|
||||
ColorMap DiffuseTexture;
|
||||
ColorMap SpecularMap;
|
||||
BumpMap NormalMap;
|
||||
std::tuple<float, float, float> AmbientColor; // = (0.2, 0.2, 0.2)
|
||||
std::tuple<float, float, float> DiffuseColor; // = (0.8, 0.8, 0.8)
|
||||
std::tuple<float, float, float> SpecularColor; // = (1, 1, 1)
|
||||
std::tuple<float, float, float> TransmissionFilter; // = (1, 1, 1)
|
||||
float OpticalDensity; // = 1
|
||||
float Alpha; // = 1
|
||||
float Shininess; // = 0
|
||||
int IlluminationModel; // = 0
|
||||
};
|
||||
|
||||
struct FaceDefinition
|
||||
{
|
||||
int VertexIndex;
|
||||
int TextureCoordIndex;
|
||||
int NormalIndex;
|
||||
};
|
||||
|
||||
struct Face
|
||||
{
|
||||
Face() : Material(nullptr) { }
|
||||
std::vector<FaceDefinition> Definitions;
|
||||
MaterialInfo* Material;
|
||||
};
|
||||
|
||||
OBJ() : m_CurrentMaterial(nullptr) { }
|
||||
OBJ(std::string filename) : m_CurrentMaterial(nullptr) { LoadFromFile(filename); }
|
||||
static OBJ* Create(std::string resourceName) { return new OBJ(resourceName); }
|
||||
|
||||
std::vector<std::tuple<float, float, float>> Vertices;
|
||||
std::vector<std::tuple<float, float, float>> Normals;
|
||||
std::vector<std::tuple<float, float, float>> TextureCoords;
|
||||
std::vector<Face> Faces;
|
||||
std::map<std::string, MaterialInfo> Materials;
|
||||
|
||||
bool LoadFromFile(std::string filename);
|
||||
boost::filesystem::path Path() const { return m_Path; }
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_Path;
|
||||
boost::filesystem::path m_MaterialPath;
|
||||
MaterialInfo* m_CurrentMaterial;
|
||||
|
||||
void ParseMaterial();
|
||||
void ParseTextureMap(unsigned int line, std::stringstream &ss, std::string prefix, std::string arg, MaterialInfo::TextureMap &textureMap);
|
||||
void ParseColorMap(unsigned int line, std::stringstream &ss, std::string prefix, std::string arg, MaterialInfo::ColorMap &textureMap);
|
||||
void ParseBumpMap(unsigned int line, std::stringstream &ss, std::string prefix, std::string arg, MaterialInfo::BumpMap &textureMap);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OBJ_h__
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
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 PNG_h_
|
||||
#define PNG_h_
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class PNG : public Image
|
||||
{
|
||||
public:
|
||||
PNG(std::string path);
|
||||
~PNG();
|
||||
|
||||
private:
|
||||
static void pngErrorFunction(png_structp png_ptr, png_const_charp error_msg);
|
||||
static void pngWarningFunction(png_structp png_ptr, png_const_charp warning_msg);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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;
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
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 DD_RENDERER_H__
|
||||
#define DD_RENDERER_H__
|
||||
|
||||
#include "Util/Rectangle.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
|
||||
{
|
||||
|
||||
class Renderer
|
||||
{
|
||||
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; }
|
||||
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();
|
||||
void Draw(RenderQueueCollection& rq);
|
||||
void PlaceCamera(glm::vec3 position);
|
||||
|
||||
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;
|
||||
|
||||
int m_GLVersion[2];
|
||||
std::string m_GLVendor;
|
||||
GLFWwindow* m_Window = nullptr;
|
||||
|
||||
ShaderProgram* m_SpDeferred1;
|
||||
ShaderProgram* m_SpDeferred2;
|
||||
ShaderProgram* m_SpDeferred3;
|
||||
ShaderProgram* m_SpForward;
|
||||
ShaderProgram* m_SpScreen;
|
||||
ShaderProgram* m_SpWater;
|
||||
ShaderProgram* m_SpWater2;
|
||||
|
||||
GLuint m_ScreenQuad = 0;
|
||||
Model* m_UnitSphere = nullptr;
|
||||
Model* m_UnitQuad = nullptr;
|
||||
Texture* m_StandardNormal;
|
||||
Texture* m_StandardSpecular;
|
||||
Texture* m_WhiteSphereTexture;
|
||||
|
||||
GLuint m_RbDepthBuffer = 0; //DepthBuffer Texture
|
||||
GLuint m_FbDeferred1 = 0; //Framebuffer for first pass
|
||||
GLuint m_GDiffuse = 0; //Texture for diffuseColors
|
||||
GLuint m_GPosition = 0; //Texture for positions
|
||||
GLuint m_GNormal = 0; //Texture for normals
|
||||
GLuint m_GSpecular = 0; //Texture for specular
|
||||
GLuint m_FbDeferred2 = 0; //Framebuffer that handles the lighting pass
|
||||
GLuint m_TLighting = 0; //Texture for the lighting pass
|
||||
GLuint m_FbDeferred3 = 0; //Frambuffer for handling the last pass.
|
||||
GLuint m_TFinal = 0; //Final Texture to be printed to screen
|
||||
GLuint m_Gwater = 0; //Water Color Texture
|
||||
GLuint m_BWater; //Water blur texture
|
||||
GLuint m_BWater2; //Water blur texture
|
||||
GLuint m_FbWater; //Waterpass Framebuffer
|
||||
GLuint m_FbWaterBlur; //Waterpass Framebuffer
|
||||
GLuint m_FbWaterBlur2; //Waterpass Framebuffer
|
||||
|
||||
GLuint m_CurrentScreenBuffer = 0;
|
||||
void LoadShaders();
|
||||
void CreateBuffers();
|
||||
GLuint CreateQuad();
|
||||
GLuint CreateWaterParticleVAO(RenderQueue &particles);
|
||||
|
||||
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
|
||||
|
||||
void DrawDeferred(RenderQueue &objects, RenderQueue &lights);
|
||||
void DrawForward(RenderQueue &objects, RenderQueue &lights);
|
||||
void DrawScene(RenderQueue &objects, ShaderProgram &program);
|
||||
void DrawLightSpheres(RenderQueue &lights);
|
||||
void DrawWater(RenderQueue &objects);
|
||||
void DrawGUI(RenderQueue& rq);
|
||||
void DebugKeys();
|
||||
|
||||
dd::EventRelay<Renderer, dd::Events::ScreenShake> m_EScreenShake;
|
||||
bool OnScreenShake(dd::Events::ScreenShake &event);
|
||||
bool m_ScreenShake = false;
|
||||
float m_ShakeIntensity = 0;
|
||||
float m_ShakeTimer = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // Renderer_h__
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
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 ShaderProgram_h__
|
||||
#define ShaderProgram_h__
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
Shader(GLenum shaderType, std::string resourceName);
|
||||
virtual ~Shader();
|
||||
|
||||
GLenum GetType() const;
|
||||
std::string GetFileName() const;
|
||||
GLuint GetHandle() const;
|
||||
|
||||
protected:
|
||||
GLenum m_ShaderType;
|
||||
std::string m_FileName;
|
||||
GLuint m_ShaderHandle;
|
||||
|
||||
void Compile();
|
||||
};
|
||||
|
||||
template <int SHADERTYPE>
|
||||
class ShaderType : public Shader, public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
public:
|
||||
ShaderType(std::string resourceName)
|
||||
: Shader(SHADERTYPE, resourceName)
|
||||
{ }
|
||||
|
||||
private:
|
||||
virtual void Reload() override;
|
||||
};
|
||||
|
||||
template <int SHADERTYPE>
|
||||
void ShaderType<SHADERTYPE>::Reload()
|
||||
{
|
||||
Compile();
|
||||
|
||||
Resource::Reload();
|
||||
}
|
||||
|
||||
class VertexShader : public ShaderType<GL_VERTEX_SHADER>
|
||||
{
|
||||
public:
|
||||
VertexShader(std::string resourceName)
|
||||
: ShaderType(resourceName)
|
||||
{ }
|
||||
};
|
||||
|
||||
class FragmentShader : public ShaderType<GL_FRAGMENT_SHADER>
|
||||
{
|
||||
public:
|
||||
FragmentShader(std::string resourceName)
|
||||
: ShaderType(resourceName)
|
||||
{ }
|
||||
};
|
||||
|
||||
class GeometryShader : public ShaderType<GL_GEOMETRY_SHADER>
|
||||
{
|
||||
public:
|
||||
GeometryShader(std::string resourceName)
|
||||
: ShaderType(resourceName)
|
||||
{ }
|
||||
};
|
||||
|
||||
class ShaderProgram : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
protected:
|
||||
ShaderProgram(std::string resourceName);
|
||||
~ShaderProgram();
|
||||
|
||||
public:
|
||||
void BindFragDataLocation(int colorNumber, std::string name);
|
||||
GLuint Link();
|
||||
GLuint GetHandle();
|
||||
operator GLuint() const { return m_ShaderProgramHandle; }
|
||||
void Bind();
|
||||
void Unbind();
|
||||
|
||||
virtual void OnChildReloaded(Resource *child) override;
|
||||
|
||||
private:
|
||||
GLuint m_ShaderProgramHandle = 0;
|
||||
std::vector<Shader*> m_Shaders;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // ShaderProgram_h__
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
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 Skeleton_h__
|
||||
#define Skeleton_h__
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
//struct Bone
|
||||
//{
|
||||
// Bone(std::string name, glm::mat4 offsetMatrix)
|
||||
// : Name(name)
|
||||
// , OffsetMatrix(offsetMatrix)
|
||||
// { }
|
||||
//
|
||||
// ~Bone()
|
||||
// {
|
||||
// for (auto kv : Children) {
|
||||
// delete kv.second;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// std::string Name;
|
||||
// glm::mat4 OffsetMatrix;
|
||||
// glm::mat4 LocalMatrix;
|
||||
//
|
||||
// std::map<std::string, Bone*> Children;
|
||||
//};
|
||||
|
||||
class Skeleton
|
||||
{
|
||||
public:
|
||||
struct Bone
|
||||
{
|
||||
Bone(int id, Bone* parent, std::string name, glm::mat4 offsetMatrix)
|
||||
: ID(id)
|
||||
, Parent(parent)
|
||||
, Name(name)
|
||||
, OffsetMatrix(offsetMatrix)
|
||||
{ }
|
||||
|
||||
int ID;
|
||||
std::string Name;
|
||||
glm::mat4 OffsetMatrix;
|
||||
|
||||
Bone* Parent;
|
||||
std::vector<Bone*> Children;
|
||||
};
|
||||
|
||||
struct Animation
|
||||
{
|
||||
struct Keyframe
|
||||
{
|
||||
struct BoneProperty
|
||||
{
|
||||
int ID;
|
||||
glm::vec3 Position;
|
||||
glm::quat Rotation;
|
||||
glm::vec3 Scale = glm::vec3(1);
|
||||
};
|
||||
|
||||
int Index = 0;
|
||||
double Time = 0.0;
|
||||
std::map<int, Keyframe::BoneProperty> BoneProperties;
|
||||
};
|
||||
|
||||
std::string Name;
|
||||
double Duration;
|
||||
std::vector<Keyframe> Keyframes;
|
||||
};
|
||||
|
||||
Skeleton() { }
|
||||
~Skeleton();
|
||||
|
||||
Bone* RootBone;
|
||||
|
||||
std::map<int, Bone*> Bones;
|
||||
|
||||
// Attach a new bone to the skeleton
|
||||
// Returns: New bone index
|
||||
int CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix);
|
||||
|
||||
int GetBoneID(std::string name);
|
||||
|
||||
const Animation* GetAnimation(std::string name);
|
||||
std::vector<glm::mat4> GetFrameBones(const Animation& animation, double time, bool noRootMotion = false);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyframe& currentFrame, const Animation::Keyframe& nextFrame, float progress, std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
||||
void PrintSkeleton();
|
||||
void PrintSkeleton(const Bone* parent, int depthCount);
|
||||
std::map<std::string, Animation> Animations;
|
||||
|
||||
private:
|
||||
std::map<std::string, Bone*> m_BonesByName;
|
||||
|
||||
int GetKeyframe(const Animation& animation, double time);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // Skeleton_h__
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
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 Texture_h__
|
||||
#define Texture_h__
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <cstdio>
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "PNG.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
class Texture : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
private:
|
||||
Texture(std::string path);
|
||||
|
||||
public:
|
||||
~Texture();
|
||||
|
||||
void Bind(GLenum textureUnit = GL_TEXTURE0);
|
||||
|
||||
operator GLuint() const { return m_Texture; }
|
||||
|
||||
unsigned int Width = 0;
|
||||
unsigned int Height = 0;
|
||||
|
||||
private:
|
||||
GLuint m_Texture = 0;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // Texture_h__
|
||||
Reference in New Issue
Block a user