diff options
-rw-r--r-- | gfx/gl/shaders/lightingShader.vs | 7 | ||||
-rw-r--r-- | ui/sceneRenderer.cpp | 66 | ||||
-rw-r--r-- | ui/sceneRenderer.h | 2 |
3 files changed, 24 insertions, 51 deletions
diff --git a/gfx/gl/shaders/lightingShader.vs b/gfx/gl/shaders/lightingShader.vs index 933a46a..2271d2e 100644 --- a/gfx/gl/shaders/lightingShader.vs +++ b/gfx/gl/shaders/lightingShader.vs @@ -1,13 +1,12 @@ #version 330 core -in vec3 aPos; -in vec2 aTexCoords; +in vec4 position; out vec2 TexCoords; void main() { - TexCoords = aTexCoords; - gl_Position = vec4(aPos, 1.0); + gl_Position = vec4(position.xy, 0.0, 1.0); + TexCoords = position.zw; } diff --git a/ui/sceneRenderer.cpp b/ui/sceneRenderer.cpp index 5cd5097..5e03704 100644 --- a/ui/sceneRenderer.cpp +++ b/ui/sceneRenderer.cpp @@ -1,9 +1,24 @@ #include "sceneRenderer.h" #include <gfx/gl/shaders/fs-lightingShader.h> #include <gfx/gl/shaders/vs-lightingShader.h> +#include <glm/gtc/type_ptr.hpp> +static constexpr std::array<glm::vec4, 4> displayVAOdata {{ + // positions(x,y) texture coords(z,w) + {-1.0f, 1.0f, 0.0f, 1.0f}, + {-1.0f, -1.0f, 0.0f, 0.0f}, + {1.0f, 1.0f, 1.0f, 1.0f}, + {1.0f, -1.0f, 1.0f, 0.0f}, +}}; SceneRenderer::SceneRenderer(glm::ivec2 size) : lighting {lightingShader_vs.compile(), lightingShader_fs.compile()} { + glBindVertexArray(displayVAO); + glBindBuffer(GL_ARRAY_BUFFER, displayVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(displayVAOdata), nullptr, GL_STATIC_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(displayVAOdata), glm::value_ptr(displayVAOdata.front())); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(glm::vec4), nullptr); + glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); const auto configuregdata = [size](const GLuint data, const GLint format, const GLenum type, const GLenum attachment) { @@ -31,57 +46,12 @@ SceneRenderer::SceneRenderer(glm::ivec2 size) : lighting {lightingShader_vs.comp glBindFramebuffer(GL_FRAMEBUFFER, 0); } -unsigned int quadVAO = 0; -unsigned int quadVBO; -void -renderQuad() -{ - if (quadVAO == 0) { - float quadVertices[] = { - // positions // texture Coords - -1.0f, - 1.0f, - 0.0f, - 0.0f, - 1.0f, - -1.0f, - -1.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - 1.0f, - 0.0f, - 1.0f, - 1.0f, - 1.0f, - -1.0f, - 0.0f, - 1.0f, - 0.0f, - }; - // setup plane VAO - glGenVertexArrays(1, &quadVAO); - glGenBuffers(1, &quadVBO); - glBindVertexArray(quadVAO); - glBindBuffer(GL_ARRAY_BUFFER, quadVBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), nullptr); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), reinterpret_cast<void *>(3 * sizeof(float))); - } - glBindVertexArray(quadVAO); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); -} - void SceneRenderer::render(std::function<void()> content) const { + // Geometry pass glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); - // Geometry pass glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); content(); @@ -98,5 +68,7 @@ SceneRenderer::render(std::function<void()> content) const glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, gAlbedoSpec); // TODO Configure lights - renderQuad(); + glBindVertexArray(displayVAO); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); } diff --git a/ui/sceneRenderer.h b/ui/sceneRenderer.h index 2e1c372..1c01069 100644 --- a/ui/sceneRenderer.h +++ b/ui/sceneRenderer.h @@ -15,4 +15,6 @@ private: glTexture gPosition, gNormal, gAlbedoSpec; glRenderBuffer depth; ProgramHandleBase lighting; + glVertexArray displayVAO; + glBuffer displayVBO; }; |