Merge remote-tracking branch 'origin/master' into ecs

This commit is contained in:
sippeangelo
2015-12-04 09:46:30 +01:00
22 changed files with 937 additions and 9 deletions
+6 -4
View File
@@ -46,10 +46,7 @@ public:
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();
@@ -60,6 +57,11 @@ private:
glm::mat4 m_ProjectionMatrix;
glm::mat4 m_ViewMatrix;
float m_AspectRatio;
float m_FOV;
float m_NearClip;
float m_FarClip;
};
#endif
+4
View File
@@ -3,9 +3,12 @@
#include "../Common.h"
#include "../OpenGL.h"
#include "../GLM.h"
#include "../Core/Util/Rectangle.h"
#include "Util/ScreenCoords.h"
#include "Camera.h"
#include "RenderQueue.h"
#include "Model.h"
class IRenderer
{
@@ -28,6 +31,7 @@ public:
}
virtual void Initialize() = 0;
virtual void Update(double dt) = 0;
virtual void Draw(RenderQueueCollection& rq) = 0;
protected:
+2
View File
@@ -13,6 +13,8 @@ class Skeleton;
class Texture;
class RenderQueue;
//TODO: Render: Remove obsolete RenderJobs and fix standard values on variables.
struct RenderJob
{
friend class RenderQueue;
+62
View File
@@ -0,0 +1,62 @@
#ifndef Renderer_h__
#define Renderer_h__
#include <sstream>
#include "IRenderer.h"
#include "ShaderProgram.h"
//TODO: Temp resourceManager
#include "../Core/ResourceManager.h"
#include "Util/UnorderedMapVec2.h"
class Renderer : public IRenderer
{
public:
virtual void Initialize() override;
virtual void Update(double dt) override;
virtual void Draw(RenderQueueCollection& rq) override;
private:
//----------------------Variables----------------------//
RenderQueueCollection m_TempRQ;
Texture* m_ErrorTexture;
Texture* m_WhiteTexture;
float m_CameraMoveSpeed;
GLuint m_PickingBuffer;
GLuint m_PickingTexture;
GLuint m_DepthBuffer;
Model* m_ScreenQuad;
Model* m_UnitQuad;
Model* m_UnitSphere;
//Temporary
Model* m;
Model* m2;
Model* m3;
Model* MapModel;
std::unordered_map<glm::vec2, const Model*> m_PickingColorsToModels;
//----------------------Functions----------------------//
void InitializeWindow();
void InitializeShaders();
void InitializeTextures();
void InitializeFrameBuffers();
//TODO: Renderer: Remove ModelsToDraw from Renderer.
void ModelsToDraw();
//TODO: Renderer: Get EnqueueModel and InputUpdate out of renderer
void EnqueueModel(Model* model);
void InputUpdate(double dt);
void PickingPass();
void DrawScreenQuad(GLuint textureToDraw);
void DrawScene(RenderQueueCollection& rq);
//--------------------ShaderPrograms-------------------//
ShaderProgram m_BasicForwardProgram;
ShaderProgram m_PickingProgram;
ShaderProgram m_DrawScreenQuadProgram;
};
#endif
+81
View File
@@ -0,0 +1,81 @@
#include "../Common.h"
#include "../OpenGL.h"
#include <fstream>
class Shader
{
public:
static GLuint CompileShader(GLenum shaderType, std::string fileName);
Shader(GLenum shaderType, std::string fileName);
virtual ~Shader();
GLuint Compile();
GLenum GetType() const;
std::string GetFileName() const;
GLuint GetHandle() const;
bool IsCompiled() const;
protected:
GLenum m_ShaderType;
std::string m_FileName;
GLint m_ShaderHandle;
};
template <int SHADERTYPE>
class ShaderType : public Shader
{
public:
ShaderType(std::string fileName)
: Shader(SHADERTYPE, fileName) { }
};
class VertexShader : public ShaderType<GL_VERTEX_SHADER>
{
public:
VertexShader(std::string fileName)
: ShaderType(fileName) { }
};
class FragmentShader : public ShaderType<GL_FRAGMENT_SHADER>
{
public:
FragmentShader(std::string fileName)
: ShaderType(fileName) { }
};
class GeometryShader : public ShaderType<GL_GEOMETRY_SHADER>
{
public:
GeometryShader(std::string fileName)
: ShaderType(fileName) { }
};
class ComputeShader : public ShaderType<GL_COMPUTE_SHADER>
{
public:
ComputeShader(std::string fileName)
: ShaderType(fileName) { }
};
class ShaderProgram
{
public:
ShaderProgram()
: m_ShaderProgramHandle(0) { }
~ShaderProgram();
void AddShader(std::shared_ptr<Shader> shader);
void Compile();
GLuint Link();
GLuint GetHandle();
void Bind();
void Unbind();
void BindFragDataLocation(int index, std::string name);
private:
GLuint m_ShaderProgramHandle;
std::vector<std::shared_ptr<Shader>> m_Shaders;
};
@@ -0,0 +1,29 @@
#ifndef ScreenCoords_h__
#define ScreenCoords_h__
#include "../../Common.h"
#include "../../OpenGL.h"
#include "../../GLM.h"
#include "../../Core/Util/Rectangle.h"
class ScreenCoords
{
public:
ScreenCoords() = delete;
//Return world position from given screenspace coordinates and depth value in viewspace.
static glm::vec3 ToWorldPos(glm::vec2 screenCoord, float depth, Rectangle resolution, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
static glm::vec3 ToWorldPos(float x, float y, float depth, Rectangle resolution, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
static glm::vec3 ToWorldPos(glm::vec2 screenCoord, float depth, float screenWidth, float screenHeight, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
static glm::vec3 ToWorldPos(float x, float y, float depth, float screenWidth, float screenHeight, glm::mat4 cameraProjectionMat, glm::mat4 cameraViewMat);
//Return data from the given buffers at the coordinates given in screenspace. Buffer should probably have a texture that covers the screen.
//Data is given as R = x, B = y, and
static glm::vec3 ToPixelData(glm::vec2 screenCoord, GLuint PickDataBuffer, GLuint DepthBuffer);
static glm::vec3 ToPixelData(float x, float y, GLuint PickDataBuffer, GLuint DepthBuffer);
//Return EntityID of the clicked coordinate in given screenspace coordinates.
//EntityID ScreenCoordsToEntityID(glm::vec2 screenCoord, float depth);
private:
};
#endif
@@ -0,0 +1,23 @@
#ifndef UnorderedMapVec2_h__
#define UnorderedMapVec2_h__
#include <functional>
#include <boost/functional/hash.hpp>
#include <glm/vec2.hpp>
template<>
struct std::hash<glm::vec2>
{
inline std::size_t operator()(const glm::vec2 &v) const
{
return boost::hash<float>()(v.x) ^ boost::hash<float>()(v.y);
}
inline bool operator()(const glm::vec2& a, const glm::vec2& b)const
{
return a.x == b.x && a.y == b.y;
}
};
#endif