Merge branch 'master' into Menu

This commit is contained in:
viktorljung
2016-01-23 18:27:48 +01:00
9 changed files with 26 additions and 11 deletions
+2
View File
@@ -24,6 +24,8 @@ public:
GLuint BloomTexture() const { return m_BloomTexture; } GLuint BloomTexture() const { return m_BloomTexture; }
//Return the texture with diffuse and lighting of the scene. //Return the texture with diffuse and lighting of the scene.
GLuint SceneTexture() const { return m_SceneTexture; } GLuint SceneTexture() const { return m_SceneTexture; }
FrameBuffer* FinalPassFrameBuffer() { return &m_FinalPassFrameBuffer; }
private: private:
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const; void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
+2 -1
View File
@@ -11,6 +11,7 @@
#include "../Core/ResourceManager.h" #include "../Core/ResourceManager.h"
#include "RenderQueue.h" #include "RenderQueue.h"
#include "TextPassState.h" #include "TextPassState.h"
#include "FrameBuffer.h"
class TextPass class TextPass
{ {
@@ -18,7 +19,7 @@ public:
TextPass(); TextPass();
void Initialize(); void Initialize();
void Update(); void Update();
void Draw(RenderScene& scene); void Draw(RenderScene& scene, FrameBuffer& frameBuffer);
private: private:
void renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix); void renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix);
+1 -1
View File
@@ -6,7 +6,7 @@
class TextPassState : public RenderState class TextPassState : public RenderState
{ {
public: public:
TextPassState(); TextPassState(GLuint frameBuffer);
~TextPassState(); ~TextPassState();
private: private:
+1 -1
View File
@@ -147,7 +147,7 @@ void main()
color_result += FillColor; color_result += FillColor;
} }
//bloomColor = vec4(0.3, 0.8, 0.6, 1.0); //bloomColor = vec4(0.3, 0.8, 0.6, 1.0);
sceneColor = vec4(color_result.xyz, 1.0); sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
//These if statements should be removed if they are slow. //These if statements should be removed if they are slow.
color_result += glowTexel; color_result += glowTexel;
+7 -2
View File
@@ -3,10 +3,15 @@ in vec2 TexCoords;
out vec4 color; out vec4 color;
uniform sampler2D text; uniform sampler2D text;
uniform vec3 textColor; uniform vec4 textColor;
out vec4 sceneColor;
out vec4 bloomColor;
void main() void main()
{ {
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r); vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
color = vec4(textColor, 1.0) * sampled; vec4 color_result = textColor * sampled;
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0) * sampled;
} }
+1
View File
@@ -101,6 +101,7 @@ void DrawFinalPass::Draw(RenderScene& scene)
} }
m_FinalPassFrameBuffer.Unbind(); m_FinalPassFrameBuffer.Unbind();
GLERROR("DrawFinalPass::Draw: END"); GLERROR("DrawFinalPass::Draw: END");
delete state;
} }
+1 -1
View File
@@ -101,7 +101,7 @@ void Renderer::Draw(RenderFrame& frame)
GLERROR("Renderer::Draw m_DrawScenePass->Draw"); GLERROR("Renderer::Draw m_DrawScenePass->Draw");
m_TextPass->Draw(*scene); m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
} }
m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture()); m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture());
+9 -3
View File
@@ -21,6 +21,8 @@ void TextPass::Initialize()
m_TextProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Text.vert.glsl"))); m_TextProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Text.vert.glsl")));
m_TextProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Text.frag.glsl"))); m_TextProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Text.frag.glsl")));
m_TextProgram->Compile(); m_TextProgram->Compile();
m_TextProgram->BindFragDataLocation(0, "sceneColor");
m_TextProgram->BindFragDataLocation(1, "bloomColor");
m_TextProgram->Link(); m_TextProgram->Link();
} }
@@ -29,8 +31,10 @@ void TextPass::Update()
} }
void TextPass::Draw(RenderScene& scene) void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
{ {
GLERROR("Derp1");
TextPassState* state = new TextPassState(frameBuffer.GetHandle());
for (auto &job : scene.TextJobs) { for (auto &job : scene.TextJobs) {
auto textJob = std::dynamic_pointer_cast<TextJob>(job); auto textJob = std::dynamic_pointer_cast<TextJob>(job);
if (textJob) { if (textJob) {
@@ -38,6 +42,8 @@ void TextPass::Draw(RenderScene& scene)
renderText(textJob->Content, textJob->Resource, textJob->Alignment, textJob->Color, textJob->Matrix, scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix()); renderText(textJob->Content, textJob->Resource, textJob->Alignment, textJob->Color, textJob->Matrix, scene.Camera->ProjectionMatrix(), scene.Camera->ViewMatrix());
} }
} }
GLERROR("Derp2");
delete state;
} }
void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix) void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
@@ -61,10 +67,10 @@ void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum a
penX = 0; penX = 0;
} }
TextPassState state;
m_TextProgram->Bind(); m_TextProgram->Bind();
glUniform3f(glGetUniformLocation(m_TextProgram->GetHandle(), "textColor"), color.x, color.y, color.z); glUniform4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "textColor"), 1, glm::value_ptr(color));
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix)); glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix));
+2 -2
View File
@@ -1,9 +1,9 @@
#include "Rendering/TextPassState.h" #include "Rendering/TextPassState.h"
TextPassState::TextPassState() TextPassState::TextPassState(GLuint frameBuffer)
{ {
BindFramebuffer(0); BindFramebuffer(frameBuffer);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);