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
+114
View File
@@ -0,0 +1,114 @@
/*
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 "Rendering/Texture.h"
#include "Rendering/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__
+127
View File
@@ -0,0 +1,127 @@
/*
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 "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"
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__
@@ -0,0 +1,124 @@
/*
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 "Core/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__
@@ -0,0 +1,56 @@
/*
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 "Core/ResourceManager.h"
#include "Rendering/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__