WIP
This commit is contained in:
@@ -24,6 +24,8 @@ public:
|
||||
GLuint BloomTexture() const { return m_BloomTexture; }
|
||||
//Return the texture with diffuse and lighting of the scene.
|
||||
GLuint SceneTexture() const { return m_SceneTexture; }
|
||||
FrameBuffer FinalPassFrameBuffer() { return m_FinalPassFrameBuffer; }
|
||||
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "TextPassState.h"
|
||||
#include "FrameBuffer.h"
|
||||
|
||||
class TextPass
|
||||
{
|
||||
@@ -18,7 +19,7 @@ public:
|
||||
TextPass();
|
||||
void Initialize();
|
||||
void Update();
|
||||
void Draw(RenderScene& scene);
|
||||
void Draw(RenderScene& scene, FrameBuffer& frameBuffer);
|
||||
|
||||
private:
|
||||
void renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
class TextPassState : public RenderState
|
||||
{
|
||||
public:
|
||||
TextPassState();
|
||||
TextPassState(GLuint frameBuffer);
|
||||
~TextPassState();
|
||||
private:
|
||||
|
||||
|
||||
@@ -3,10 +3,15 @@ in vec2 TexCoords;
|
||||
out vec4 color;
|
||||
|
||||
uniform sampler2D text;
|
||||
uniform vec3 textColor;
|
||||
uniform vec4 textColor;
|
||||
|
||||
out vec4 sceneColor;
|
||||
out vec4 bloomColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
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);
|
||||
}
|
||||
@@ -23,8 +23,8 @@ void DrawFinalPass::InitializeFrameBuffers()
|
||||
|
||||
GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_FLOAT, 4);
|
||||
GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_FLOAT, 4);
|
||||
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
@@ -97,6 +97,7 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
||||
}
|
||||
m_FinalPassFrameBuffer.Unbind();
|
||||
GLERROR("DrawFinalPass::Draw: END");
|
||||
delete state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
|
||||
GLERROR("Renderer::Draw m_DrawScenePass->Draw");
|
||||
|
||||
m_TextPass->Draw(*scene);
|
||||
m_TextPass->Draw(*scene, m_DrawFinalPass->FinalPassFrameBuffer());
|
||||
|
||||
}
|
||||
m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture());
|
||||
|
||||
@@ -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 FragmentShader("Shaders/Text.frag.glsl")));
|
||||
m_TextProgram->Compile();
|
||||
m_TextProgram->BindFragDataLocation(0, "sceneColor");
|
||||
m_TextProgram->BindFragDataLocation(1, "bloomColor");
|
||||
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) {
|
||||
auto textJob = std::dynamic_pointer_cast<TextJob>(job);
|
||||
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());
|
||||
}
|
||||
}
|
||||
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)
|
||||
@@ -61,10 +67,10 @@ void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum a
|
||||
penX = 0;
|
||||
}
|
||||
|
||||
TextPassState state;
|
||||
|
||||
|
||||
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(), "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_TextProgram->GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix));
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "Rendering/TextPassState.h"
|
||||
|
||||
|
||||
TextPassState::TextPassState()
|
||||
TextPassState::TextPassState(GLuint frameBuffer)
|
||||
{
|
||||
BindFramebuffer(0);
|
||||
BindFramebuffer(frameBuffer);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
Reference in New Issue
Block a user