Engine puzzle completed

This commit is contained in:
sippeangelo
2015-11-30 17:02:24 +01:00
parent 52278d7bc2
commit 872879c013
62 changed files with 5344 additions and 113 deletions
+1 -6
View File
@@ -1,12 +1,7 @@
#ifndef BaseTexture_h__
#define BaseTexture_h__
#include <string>
#include <unordered_map>
#include <cstdio>
#include "Core/ResourceManager.h"
#include "Rendering/PNG.h"
#include "../Core/ResourceManager.h"
class BaseTexture : public Resource
{
+65
View File
@@ -0,0 +1,65 @@
#ifndef Camera_h__
#define Camera_h__
#include "../GLM.h"
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);
float m_AspectRatio;
float m_FOV;
float m_NearClip;
float m_FarClip;
private:
void UpdateViewMatrix();
void UpdateProjectionMatrix();
glm::vec3 m_Position;
glm::quat m_Orientation;
glm::mat4 m_ProjectionMatrix;
glm::mat4 m_ViewMatrix;
};
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef DummyRenderer_h__
#define DummyRenderer_h__
#include <sstream>
#include "IRenderer.h"
class DummyRenderer : public IRenderer
{
public:
virtual void Initialize() override;
virtual void Draw(RenderQueueCollection& rq) override;
};
#endif
+44
View File
@@ -0,0 +1,44 @@
#ifndef IRenderer_h__
#define IRenderer_h__
#include "../Common.h"
#include "../OpenGL.h"
#include "../Core/Util/Rectangle.h"
#include "Camera.h"
#include "RenderQueue.h"
class IRenderer
{
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; }
::Camera* Camera() const { return m_Camera; }
void SetCamera(::Camera* camera)
{
if (camera == nullptr) {
m_Camera = m_DefaultCamera;
} else {
m_Camera = camera;
}
}
virtual void Initialize() = 0;
virtual void Draw(RenderQueueCollection& rq) = 0;
protected:
Rectangle m_Resolution = Rectangle(1280, 720);
bool m_Fullscreen = false;
bool m_VSYNC = false;
int m_GLVersion[2];
std::string m_GLVendor;
::Camera* m_DefaultCamera;
::Camera* m_Camera = nullptr;
GLFWwindow* m_Window = nullptr;
};
#endif // Renderer_h__
+2 -1
View File
@@ -1,7 +1,8 @@
#ifndef Model_h__
#define Model_h__
#include "Rendering/RawModel.h"
#include "RawModel.h"
#include "../OpenGL.h"
class Model : public RawModel
{
+1
View File
@@ -5,6 +5,7 @@
#include <png.h>
#include "../Common.h"
#include "Image.h"
class PNG : public Image
+5 -6
View File
@@ -1,12 +1,9 @@
#ifndef RawModel_h__
#define RawModel_h__
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <memory>
#include <cstdlib>
#include <stack>
@@ -15,9 +12,11 @@
#include <assimp/postprocess.h>
#include <boost/filesystem/path.hpp>
#include "Core/ResourceManager.h"
#include "Rendering/Texture.h"
#include "Rendering/Skeleton.h"
#include "../Common.h"
#include "../GLM.h"
#include "../Core/ResourceManager.h"
#include "Texture.h"
#include "Skeleton.h"
class RawModel : public Resource
{
+177
View File
@@ -0,0 +1,177 @@
#ifndef RenderQueue_h__
#define RenderQueue_h__
#include <cstdint>
#include <forward_list>
#include "../Common.h"
#include "../GLM.h"
#include "../Core/Util/Rectangle.h"
class Model;
class Skeleton;
class Texture;
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 = 0;
unsigned int TextureID = 0;
glm::mat4 ModelMatrix;
const Texture* DiffuseTexture;
const Texture* NormalTexture;
const Texture* SpecularTexture;
float Shininess = 0.f;
glm::vec4 Color;
const Model* Model = nullptr;
unsigned int StartIndex = 0;
unsigned int EndIndex = 0;
// Animation
Skeleton* Skeleton = nullptr;
bool NoRootMotion = true;
std::string AnimationName;
double AnimationTime = 0;
void CalculateHash() override
{
Hash = TextureID;
}
};
struct SpriteJob : RenderJob
{
unsigned int ShaderID = 0;
unsigned int TextureID = 0;
glm::mat4 ModelMatrix;
const Texture* DiffuseTexture = nullptr;
const Texture* NormalTexture = nullptr;
const Texture* SpecularTexture = nullptr;
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
+2
View File
@@ -2,6 +2,8 @@
#define Skeleton_h__
#include <sstream>
#include "Common.h"
#include "../GLM.h"
//struct Bone
//{
+3 -1
View File
@@ -1,7 +1,9 @@
#ifndef Texture_h__
#define Texture_h__
#include "Rendering/BaseTexture.h"
#include "../OpenGL.h"
#include "BaseTexture.h"
#include "PNG.h"
class Texture : public BaseTexture
{
+2 -20
View File
@@ -1,26 +1,8 @@
/*
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 GLError_h__
#define GLError_h__
#include "PrecompiledHeader.h"
#include <iostream>
#include "Common.h"
inline bool _GLERROR(const char* info, const char* file, const char* func, unsigned int line)
{
@@ -37,4 +19,4 @@ inline bool _GLERROR(const char* info, const char* file, const char* func, unsig
#define GLERROR(function) \
_GLERROR(function, __BASE_FILE__, __func__, __LINE__)
#endif // GLError_h__
#endif