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

This commit is contained in:
stiffly
2015-12-08 10:41:04 +01:00
13 changed files with 349 additions and 132 deletions
+64
View File
@@ -0,0 +1,64 @@
#ifndef FrameBuffer_h__
#define FrameBuffer_h__
#include "../OpenGL.h"
#include "Util/GLError.h"
class BufferResource
{
public:
BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment);
GLuint* m_ResourceHandle;
GLenum m_ResourceType;
GLenum m_Attachment;
private:
};
template <GLenum RESOURCETYPE>
class ResourceType : public BufferResource
{
public:
ResourceType(GLuint* resourceHandle, GLenum attachment)
: BufferResource(resourceHandle, RESOURCETYPE, attachment) { }
};
class Texture2D : public ResourceType<GL_TEXTURE_2D>
{
public:
Texture2D(GLuint* resourceHandle, GLenum attachment)
: ResourceType(resourceHandle, attachment) { };
~Texture2D();
};
class RenderBuffer : public ResourceType<GL_RENDERBUFFER>
{
public:
RenderBuffer(GLuint* resourceHandle, GLenum attachment)
: ResourceType(resourceHandle, attachment)
{ };
~RenderBuffer();
};
class FrameBuffer
{
public:
FrameBuffer()
: m_BufferHandle(0) { }
~FrameBuffer();
void AddResource(std::shared_ptr<BufferResource> resource);
void Generate();
void Bind();
void Unbind();
GLuint GetHandle();
private:
GLuint m_BufferHandle;
std::vector<std::shared_ptr<BufferResource>> m_Resources;
};
#endif
+5 -30
View File
@@ -7,6 +7,7 @@
#include "../Common.h"
#include "../GLM.h"
#include "../Core/Util/Rectangle.h"
#include "../Core/EntityWrapper.h"
class Model;
class Skeleton;
@@ -37,6 +38,9 @@ struct ModelJob : RenderJob
unsigned int ShaderID = 0;
unsigned int TextureID = 0;
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
EntityID Entity;
glm::mat4 ModelMatrix;
const Texture* DiffuseTexture;
const Texture* NormalTexture;
@@ -82,30 +86,7 @@ struct PointLightJob : RenderJob
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;
float Intensity = 0.8f;
void CalculateHash() override
{
@@ -154,25 +135,19 @@ private:
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();
}
};
@@ -0,0 +1,28 @@
#ifndef RenderQueueFactory_h__
#define RenderQueueFactory_h__
#include "../Core/World.h"
#include "RenderQueue.h"
#include "../Core/ResourceManager.h"
#include "Model.h"
#include "../GLM.h"
class RenderQueueFactory
{
public:
RenderQueueFactory();
void Update(World* world);
RenderQueueCollection RenderQueues() const { return m_RenderQueues; }
private:
RenderQueueCollection m_RenderQueues;
void FillModels(World* world, RenderQueue* renderQueue);
void FillLights(World* world, RenderQueue* renderQueue);
glm::mat4 ModelMatrix(World* world, EntityID entity);
glm::vec3 GetAbsolutePosition(World* world, ComponentWrapper transformComponent);
};
#endif
+8 -13
View File
@@ -8,6 +8,8 @@
//TODO: Temp resourceManager
#include "../Core/ResourceManager.h"
#include "Util/UnorderedMapVec2.h"
#include "FrameBuffer.h"
#include "../Core/World.h"
class Renderer : public IRenderer
{
@@ -18,11 +20,10 @@ public:
private:
//----------------------Variables----------------------//
RenderQueueCollection m_TempRQ;
Texture* m_ErrorTexture;
Texture* m_WhiteTexture;
float m_CameraMoveSpeed;
GLuint m_PickingBuffer;
FrameBuffer m_PickingBuffer;
GLuint m_PickingTexture;
GLuint m_DepthBuffer;
@@ -30,29 +31,23 @@ private:
Model* m_UnitQuad;
Model* m_UnitSphere;
//Temporary
Model* m;
Model* m2;
Model* m3;
Model* MapModel;
std::unordered_map<glm::vec2, const Model*> m_PickingColorsToModels;
std::unordered_map<glm::vec2, EntityID> m_PickingColorsToEntity;
//----------------------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);
//TODO: Renderer: Get InputUpdate out of renderer
void InputUpdate(double dt);
void PickingPass();
void PickingPass(RenderQueueCollection& rq);
void DrawScreenQuad(GLuint textureToDraw);
void DrawScene(RenderQueueCollection& rq);
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
//--------------------ShaderPrograms-------------------//
ShaderProgram m_BasicForwardProgram;
ShaderProgram m_PickingProgram;
+3 -2
View File
@@ -5,6 +5,7 @@
#include "../../OpenGL.h"
#include "../../GLM.h"
#include "../../Core/Util/Rectangle.h"
#include "../FrameBuffer.h"
class ScreenCoords
{
@@ -17,8 +18,8 @@ public:
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);
static glm::vec3 ToPixelData(glm::vec2 screenCoord, FrameBuffer* PickDataBuffer, GLuint DepthBuffer);
static glm::vec3 ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer);
//Return EntityID of the clicked coordinate in given screenspace coordinates.
//EntityID ScreenCoordsToEntityID(glm::vec2 screenCoord, float depth);