diff --git a/assets b/assets index 6cc3858..72b93d5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 6cc38589ed77dbb3b9c34c1168d52e0f86e1de46 +Subproject commit 72b93d5750283864f244241e65a38436d05c5f96 diff --git a/src/Engine.h b/src/Engine.h index 2dd5866..a0f09ac 100755 --- a/src/Engine.h +++ b/src/Engine.h @@ -2,6 +2,9 @@ #include #include "ResourceManager.h" +#include "OBJ.h" +#include "Model.h" +#include "Texture.h" #include "EventBroker.h" #include "RenderQueue.h" #include "Renderer.h" @@ -15,7 +18,12 @@ public: Engine(int argc, char* argv[]) { m_EventBroker = std::make_shared(); + m_ResourceManager = std::make_shared(); + m_ResourceManager->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); }); + auto rm = m_ResourceManager; + m_ResourceManager->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load("OBJ", resourceName)); }); + m_ResourceManager->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); }); m_Renderer = std::make_shared(); m_Renderer->Initialize(); @@ -23,6 +31,8 @@ public: m_InputManager = std::make_shared(m_Renderer->GetWindow(), m_EventBroker); m_FrameStack = new GUI::Frame(m_EventBroker, m_ResourceManager); + m_FrameStack->Width = 1280; + m_FrameStack->Height = 720; new GUI::GameFrame(m_FrameStack, "GameFrame"); //m_World = std::make_shared(m_EventBroker, m_ResourceManager); @@ -36,12 +46,21 @@ public: void Tick() { double currentTime = glfwGetTime(); - double dt = currentTime - m_LastTime; + double dt = currentTime - m_LastTime; m_LastTime = currentTime; + // Update input m_InputManager->Update(dt); + + // Update frame stack + m_EventBroker->Process(); + m_FrameStack->UpdateLayered(dt); + + // Render scene m_FrameStack->DrawLayered(m_Renderer); + m_Renderer->Swap(); + // Swap event queues m_EventBroker->Clear(); glfwPollEvents(); diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index 2681d2a..8ebb30c 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -41,7 +41,6 @@ public: , m_Layer(0) { SetParent(std::shared_ptr(parent)); } - ::RenderQueue RenderQueue; std::shared_ptr Parent() const { return m_Parent; } @@ -84,10 +83,7 @@ public: } int Right() const override { - if (m_Parent) - return m_Parent->Right() + X + Width; - else - return X + Width; + return Left() + Width; } int Top() const override { @@ -98,24 +94,31 @@ public: } int Bottom() const override { - if (m_Parent) - return m_Parent->Bottom() + Y + Height; - else - return Y + Height; + return Top() + Height; } Rectangle AbsoluteRectangle() { - return Rectangle(Left(), Right(), Width, Height); + return Rectangle(Left(), Top(), Width, Height); } - virtual void Update(double dt) + void UpdateLayered(double dt) { - for (auto &pair : m_Children[m_Layer + 1]) + // Update ourselves + this->Update(dt); + + // Update children + for (auto &pairLayer : m_Children) { - pair.second->Update(dt); + auto children = pairLayer.second; + for (auto &pairChild : children) + { + auto child = pairChild.second; + child->Update(dt); + } } } + virtual void Update(double dt) { } void DrawLayered(std::shared_ptr renderer) { @@ -130,7 +133,8 @@ public: for (auto &pairChild : children) { auto child = pairChild.second; - renderer->SetViewport(child->AbsoluteRectangle()); + Rectangle rect = child->AbsoluteRectangle(); + renderer->SetViewport(rect); child->Draw(renderer); } } diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 09eb2ba..52b9003 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -4,6 +4,7 @@ #include "GUI/Frame.h" #include "GUI/WorldFrame.h" #include "GUI/Viewport.h" +#include "GUI/TextureFrame.h" #include "GameWorld.h" @@ -17,27 +18,25 @@ public: : Frame(parent, name) { m_World = std::make_shared(EventBroker, ResourceManager); - m_World->Initialize(); - auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World); { - new Viewport(worldFrame, "Viewport1", m_World); - new Viewport(worldFrame, "Viewport2", m_World); + vp1 = new Viewport(worldFrame, "Viewport1", m_World); + vp1->X = 0; + vp1->Width = 640; + vp2 = new Viewport(worldFrame, "Viewport2", m_World); + vp2->X = vp1->Right(); + vp2->Width = 640; + + auto tex = new TextureFrame(vp1, "TextureFrameThingy"); + tex->SetTexture("Textures/GUI/hurt.png"); } - } - - void Update(double dt) override - { - - } - - void Draw(std::shared_ptr renderer) override - { - + m_World->Initialize(); } private: std::shared_ptr m_World; + Viewport* vp1; + Viewport* vp2; }; } diff --git a/src/GUI/TextureFrame.h b/src/GUI/TextureFrame.h index 0b85fb9..447510c 100644 --- a/src/GUI/TextureFrame.h +++ b/src/GUI/TextureFrame.h @@ -10,7 +10,7 @@ namespace GUI class TextureFrame : public Frame { public: - TextureFrame(std::shared_ptr parent, std::string name) + TextureFrame(Frame* parent, std::string name) : Frame(parent, name) { } void Draw(std::shared_ptr renderer) override @@ -25,7 +25,7 @@ public: RenderQueue.Add(job); renderer->SetCamera(nullptr); - renderer->Draw(RenderQueue); + renderer->DrawFrame(RenderQueue); } std::shared_ptr<::Texture> Texture() const { return m_Texture; } diff --git a/src/GUI/Viewport.h b/src/GUI/Viewport.h index c2faf57..88af865 100644 --- a/src/GUI/Viewport.h +++ b/src/GUI/Viewport.h @@ -20,9 +20,7 @@ public: Viewport(Frame* parent, std::string name, std::shared_ptr world) : Frame(parent, name) , m_World(world) - { - m_TransformSystem = m_World->GetSystem(); - } + { } EntityID CameraEntity() const { return m_CameraEntity; } void SetCameraEntity(EntityID cameraEntity) @@ -41,6 +39,9 @@ public: void Update(double dt) override { + if (!m_TransformSystem) + m_TransformSystem = m_World->GetSystem(); + auto transformComponent = m_World->GetComponent(m_CameraEntity); if (!transformComponent) return; @@ -60,8 +61,11 @@ public: void Draw(std::shared_ptr renderer) override { + if (!m_Camera) + return; + renderer->SetCamera(m_Camera); - renderer->Draw(m_Parent->RenderQueue); + renderer->DrawWorld(m_Parent->RenderQueue); } private: diff --git a/src/GUI/WorldFrame.h b/src/GUI/WorldFrame.h index e303b55..995b133 100644 --- a/src/GUI/WorldFrame.h +++ b/src/GUI/WorldFrame.h @@ -23,17 +23,20 @@ public: , m_World(world) { EVENT_SUBSCRIBE_MEMBER(m_ESetViewportCamera, &WorldFrame::OnSetViewportCamera); - m_TransformSystem = m_World->GetSystem(); } void Update(double dt) override { + if (!m_TransformSystem) + m_TransformSystem = m_World->GetSystem(); + m_World->Update(dt); } void Draw(std::shared_ptr renderer) override { RenderQueue.Clear(); + renderer->ClearPointLights(); for (auto &pair : *m_World->GetEntities()) { @@ -75,8 +78,17 @@ public: auto pointLightComponent = m_World->GetComponent(entity); if (pointLightComponent) { - // TODO: Push lights to renderer - // renderer->PushLight(...); + glm::vec3 position = m_TransformSystem->AbsolutePosition(entity); + renderer->AddPointLightToDraw( + position, + pointLightComponent->Specular, + pointLightComponent->Diffuse, + pointLightComponent->specularExponent, + pointLightComponent->ConstantAttenuation, + pointLightComponent->LinearAttenuation, + pointLightComponent->QuadraticAttenuation, + pointLightComponent->Radius + ); } } } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 324b6eb..5545075 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -45,32 +45,17 @@ void GameWorld::Initialize() RegisterComponents(); - auto camera = CreateEntity(); - { - auto transform = AddComponent(camera); - transform->Position.z = 20.f; - transform->Position.y = 20.f; - //transform->Orientation = glm::quat(glm::vec3(glm::pi() / 8.f, 0.f, 0.f)); - auto cameraComp = AddComponent(camera); - cameraComp->FarClip = 2000.f; - auto freeSteering = AddComponent(camera); - } - CommitEntity(camera); - - auto viewport1 = CreateEntity(); - { - auto viewport = AddComponent(viewport1); - viewport->Right = 0.5f; - viewport->Camera = camera; - } - CommitEntity(viewport1); - - auto viewport2 = CreateEntity(); - { - auto viewport = AddComponent(viewport2); - viewport->Left = 0.5f; - } - CommitEntity(viewport2); + //auto camera = CreateEntity(); + //{ + // auto transform = AddComponent(camera); + // transform->Position.z = 20.f; + // transform->Position.y = 20.f; + // //transform->Orientation = glm::quat(glm::vec3(glm::pi() / 8.f, 0.f, 0.f)); + // auto cameraComp = AddComponent(camera); + // cameraComp->FarClip = 2000.f; + // auto freeSteering = AddComponent(camera); + //} + auto player1 = CreateEntity(); { @@ -343,7 +328,12 @@ void GameWorld::Initialize() //auto freeSteering = AddComponent(cameraTower); } CommitEntity(cameraTower); - GetComponent(viewport1)->Camera = cameraTower; + { + Events::SetViewportCamera e; + e.CameraEntity = cameraTower; + e.ViewportFrame = "Viewport1"; + EventBroker->Publish(e); + } } { @@ -761,7 +751,12 @@ void GameWorld::Initialize() //auto freeSteering = AddComponent(cameraTower); } CommitEntity(cameraTower); - GetComponent(viewport2)->Camera = cameraTower; + { + Events::SetViewportCamera e; + e.CameraEntity = cameraTower; + e.ViewportFrame = "Viewport2"; + EventBroker->Publish(e); + } } { @@ -1103,7 +1098,7 @@ void GameWorld::Initialize() CommitEntity(entity); }*/ - for(int i = 0; i < 1; i++) + /*for(int i = 0; i < 1; i++) { for (int y = 0; y < 15; y++) { @@ -1133,7 +1128,7 @@ void GameWorld::Initialize() CommitEntity(brick); } } - } + }*/ /*for (int x = 0; x < 5; x++) for (int y = 0; y < 5; y++) diff --git a/src/RenderQueue.h b/src/RenderQueue.h index e9b76d7..be2d18e 100644 --- a/src/RenderQueue.h +++ b/src/RenderQueue.h @@ -27,7 +27,10 @@ protected: struct ModelJob : RenderJob { + unsigned int ShaderID; unsigned int TextureID; + + GLuint ShaderProgram; GLuint DiffuseTexture; GLuint NormalTexture; GLuint SpecularTexture; @@ -44,7 +47,10 @@ struct ModelJob : RenderJob struct SpriteJob : RenderJob { + unsigned int ShaderID; unsigned int TextureID; + + GLuint ShaderProgram; GLuint Texture; glm::mat4 ModelMatrix; @@ -70,6 +76,16 @@ public: m_Jobs.clear(); } + std::forward_list>::const_iterator begin() + { + return m_Jobs.begin(); + } + + std::forward_list>::const_iterator end() + { + return m_Jobs.end(); + } + private: std::forward_list> m_Jobs; }; diff --git a/src/Renderer.cpp b/src/Renderer.cpp index e06795c..2aff840 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -17,12 +17,12 @@ Renderer::Renderer() CAtt = 1.0f; LAtt = 0.0f; QAtt = 3.0f; - m_ShadowMapRes = 2048*8; + m_ShadowMapRes = 2048*2; m_SunPosition = glm::vec3(0.f, 1.0f, 0.5f); m_SunTarget = glm::vec3(0, 0, 0); m_SunProjection_height = glm::vec2(-40.f, 40.f); m_SunProjection_width = glm::vec2(-40.f, 40.f); - m_SunProjection_length = glm::vec2(-50.f, 50.f); + m_SunProjection_length = glm::vec2(500.f, -500.f); m_SunProjection = glm::ortho(m_SunProjection_width.x, m_SunProjection_width.y, m_SunProjection_height.x, m_SunProjection_height.y, m_SunProjection_length.x, m_SunProjection_length.y); /* Lights = 0;*/ } @@ -76,6 +76,7 @@ void Renderer::Initialize() glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); LoadContent(); } @@ -246,9 +247,181 @@ void Renderer::Draw(double dt) glfwSwapBuffers(m_Window); } -void Renderer::Draw(RenderQueue &rq) +void Renderer::DrawFrame(RenderQueue &rq) { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glViewport(m_Viewport.X, -m_Viewport.Y, m_Viewport.Width, m_Viewport.Height); + glScissor(m_Viewport.X, -m_Viewport.Y, m_Viewport.Width, m_Viewport.Height); + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + //glClearColor(0.0f, 0.5f, 0.0f, 1.0f); + + glDisable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + //glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * m_Camera->ViewMatrix(); + //glm::mat4 MVP; + + m_ForwardRendering.Bind(); + + //for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender + //{ + // Model* model; + // glm::mat4 modelMatrix; + // bool visible; + // std::tie(model, modelMatrix, visible, std::ignore) = tuple; + // if (!visible) + // continue; + + // MVP = cameraMatrix * modelMatrix; + // glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + // glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + // glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + // glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height))); + + // glBindVertexArray(model->VAO); + // for (auto texGroup : model->TextureGroups) + // { + // glActiveTexture(GL_TEXTURE0); + // glBindTexture(GL_TEXTURE_2D, *texGroup.Texture); + // glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); + // } + //} + + for (auto &job : rq) + { + //auto modelJob = std::dynamic_pointer_cast(job); + //if (modelJob) + //{ + // glm::mat4 modelMatrix = modelJob->ModelMatrix; + + // MVP = cameraMatrix * modelMatrix; + // depthMVP = depthCameraMatrix * modelMatrix; + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); + // //glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview)); + + // glBindVertexArray(modelJob->VAO); + // glActiveTexture(GL_TEXTURE0); + // glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); + // if (modelJob->NormalTexture != 0) + // { + // glActiveTexture(GL_TEXTURE2); + // glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); + // } + // if (modelJob->SpecularTexture) + // { + // glActiveTexture(GL_TEXTURE3); + // glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); + // } + // glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); + + // continue; + //} + + auto spriteJob = std::dynamic_pointer_cast(job); + if (spriteJob) + { + glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, spriteJob->Texture); + glBindVertexArray(m_ScreenQuad); + glDrawArrays(GL_TRIANGLES, 0, 6); + + continue; + } + } +} + +void Renderer::DrawWorld(RenderQueue &rq) +{ + glDisable(GL_BLEND); + + DrawShadowMap(rq); + + /* + Base pass + */ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); + glViewport(m_Viewport.X, -m_Viewport.Y, m_Viewport.Width, m_Viewport.Height); + glScissor(m_Viewport.X, -m_Viewport.Y, m_Viewport.Width, m_Viewport.Height); + //glViewport(0, 0, m_Width, m_Height); + + // Clear G-buffer + GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + glDrawBuffers(4, windowBuffClear); + glClearColor(0.0f, 0.7f, 0.3f, 0.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // Execute the first render stage which will fill out the internal buffers with data(??) + m_FirstPassProgram.Bind(); + GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + glDrawBuffers(4, windowBuffOpaque); + + glCullFace(GL_BACK); + glEnable(GL_DEPTH_TEST); + DrawFBOScene(rq); + + /* + Lighting pass + */ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass); + GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 }; + glDrawBuffers(1, lightingPassAttachments); + + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + + m_SecondPassProgram.Bind(); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_fPositionTexture); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture); + + glCullFace(GL_FRONT); + DrawLightScene(rq); + + /* + Final pass + */ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + //glViewport(m_Viewport.X, m_Viewport.Y, m_Viewport.Width, m_Viewport.Height); + glViewport(0, 0, m_Width, m_Height); + glScissor(0, 0, m_Width, m_Height); + glClear(GL_DEPTH_BUFFER_BIT); + + m_FinalPassProgram.Bind(); + + // Ambient light + glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f))); + glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, m_fLightingTexture); + + glCullFace(GL_BACK); + glBindVertexArray(m_ScreenQuad); + glEnableVertexAttribArray(0); + glDrawArrays(GL_TRIANGLES, 0, 6); +} + +void Renderer::Swap() +{ + glfwSwapBuffers(m_Window); } #pragma region TempRegion @@ -293,7 +466,7 @@ void Renderer::CreateShadowMap(int resolution) } } -void Renderer::DrawShadowMap() +void Renderer::DrawShadowMap(RenderQueue &rq) { glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object @@ -307,7 +480,8 @@ void Renderer::DrawShadowMap() //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Creates the "camera" for the shadowmap from the direction of the sun. - glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate((-m_Camera->Position() + (glm::vec3(40.0) * -m_Camera->Forward())) * glm::vec3(1,0,1)); + glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 1, 1)); + //glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate((-m_Camera->Position() + (glm::vec3(40.0) * -m_Camera->Forward())) * glm::vec3(1, 1, 1)); glm::mat4 depthCamera = m_SunProjection * depthViewMatrix; glm::mat4 MVP; @@ -315,6 +489,23 @@ void Renderer::DrawShadowMap() glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons //For each model, render them to the shadowmap + for (auto &job : rq) + { + auto modelJob = std::dynamic_pointer_cast(job); + if (modelJob) + { + glm::mat4 modelMatrix = modelJob->ModelMatrix; + + MVP = depthCamera * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + //glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview)); + + glBindVertexArray(modelJob->VAO); + glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); + + continue; + } + } for (auto tuple : ModelsToRender) { Model* model; @@ -675,84 +866,84 @@ void Renderer::FrameBufferTextures() void Renderer::DrawFBO() { - DrawShadowMap(); + //DrawShadowMap(); - for (auto &pair : m_Viewports) - { - Viewport &viewport = pair.second; - if (!viewport.Camera) - continue; + //for (auto &pair : m_Viewports) + //{ + // Viewport &viewport = pair.second; + // if (!viewport.Camera) + // continue; - int x = viewport.Left * m_Width; - int y = viewport.Top * m_Height; - int width = (viewport.Right - viewport.Left) * m_Width; - int height = (viewport.Bottom - viewport.Top) * m_Height; - - /* - Base pass - */ - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); - glViewport(0, 0, m_Width, m_Height); + // int x = viewport.Left * m_Width; + // int y = viewport.Top * m_Height; + // int width = (viewport.Right - viewport.Left) * m_Width; + // int height = (viewport.Bottom - viewport.Top) * m_Height; + // + // /* + // Base pass + // */ + // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); + // glViewport(0, 0, m_Width, m_Height); - // Clear G-buffer - GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; - glDrawBuffers(4, windowBuffClear); - glClearColor(0.0f, 0.3f, 0.7f, 0.f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + // // Clear G-buffer + // GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + // glDrawBuffers(4, windowBuffClear); + // glClearColor(0.0f, 0.3f, 0.7f, 0.f); + // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // Execute the first render stage which will fill out the internal buffers with data(??) - m_FirstPassProgram.Bind(); - GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; - glDrawBuffers(4, windowBuffOpaque); + // // Execute the first render stage which will fill out the internal buffers with data(??) + // m_FirstPassProgram.Bind(); + // GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + // glDrawBuffers(4, windowBuffOpaque); - glCullFace(GL_BACK); - - DrawFBOScene(viewport); + // glCullFace(GL_BACK); + // + // DrawFBOScene(viewport); - /* - Lighting pass - */ - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass); - GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 }; - glDrawBuffers(1, lightingPassAttachments); + // /* + // Lighting pass + // */ + // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass); + // GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 }; + // glDrawBuffers(1, lightingPassAttachments); - glClearColor(0.f, 0.f, 0.f, 0.f); - glClear(GL_COLOR_BUFFER_BIT); + // glClearColor(0.f, 0.f, 0.f, 0.f); + // glClear(GL_COLOR_BUFFER_BIT); - m_SecondPassProgram.Bind(); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_fPositionTexture); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture); - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture); + // m_SecondPassProgram.Bind(); + // glActiveTexture(GL_TEXTURE0); + // glBindTexture(GL_TEXTURE_2D, m_fPositionTexture); + // glActiveTexture(GL_TEXTURE1); + // glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture); + // glActiveTexture(GL_TEXTURE2); + // glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture); - glCullFace(GL_FRONT); - DrawLightScene(viewport); + // glCullFace(GL_FRONT); + // DrawLightScene(viewport); - /* - Final pass - */ - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glViewport(x, y, width, height); - glClear(GL_DEPTH_BUFFER_BIT); + // /* + // Final pass + // */ + // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + // glViewport(x, y, width, height); + // glClear(GL_DEPTH_BUFFER_BIT); - m_FinalPassProgram.Bind(); + // m_FinalPassProgram.Bind(); - // Ambient light - glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f))); - glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma); + // // Ambient light + // glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f))); + // glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, m_fLightingTexture); + // glActiveTexture(GL_TEXTURE0); + // glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); + // glActiveTexture(GL_TEXTURE1); + // glBindTexture(GL_TEXTURE_2D, m_fLightingTexture); - glCullFace(GL_BACK); - glBindVertexArray(m_ScreenQuad); - glEnableVertexAttribArray(0); - glDrawArrays(GL_TRIANGLES, 0, 6); - } + // glCullFace(GL_BACK); + // glBindVertexArray(m_ScreenQuad); + // glEnableVertexAttribArray(0); + // glDrawArrays(GL_TRIANGLES, 0, 6); + //} } void Renderer::DrawFBO2() @@ -760,14 +951,15 @@ void Renderer::DrawFBO2() ForwardRendering(); } -void Renderer::DrawFBOScene(Viewport &viewport) +void Renderer::DrawFBOScene(RenderQueue &rq) { // glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly // glEnable(GL_CULL_FACE); //removes triangles on the wrong side of the object // glCullFace(GL_BACK); //Make it so that only the back faces are rendered glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Draws filled polygons - glm::mat4 cameraMatrix = viewport.Camera->ProjectionMatrix((float)m_Width / m_Height) * viewport.Camera->ViewMatrix(); + glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); + glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); glm::mat4 MVP; glm::mat4 biasMatrix( 0.5, 0.0, 0.0, 0.0, @@ -776,81 +968,83 @@ void Renderer::DrawFBOScene(Viewport &viewport) 0.5, 0.5, 0.5, 1.0 ); - glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate((-m_Camera->Position() + (glm::vec3(40.0) * -m_Camera->Forward())) * glm::vec3(1,0,1)); + //glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate((-m_Camera->Position() + (glm::vec3(40.0) * -m_Camera->Forward())) * glm::vec3(1, 1, 1)); + glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 1, 1)); glm::mat4 depthCamera = m_SunProjection * depthViewMatrix; glm::mat4 depthCameraMatrix = biasMatrix * depthCamera; glm::mat4 depthMVP; glm::vec3 sunDirection = m_SunTarget - m_SunPosition; - glm::vec3 sunDirection_cameraview = glm::vec3(m_Camera->ProjectionMatrix((float)m_Width / m_Height) * m_Camera->ViewMatrix() * glm::vec4(sunDirection, 1.0)); + glm::vec3 sunDirection_cameraview = glm::vec3(cameraProjection * m_Camera->ViewMatrix() * glm::vec4(sunDirection, 1.0)); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture); - for (auto tuple : ModelsToRender) + for (auto &job : rq) { - Model* model; - glm::mat4 modelMatrix; - bool visible; - std::tie(model, modelMatrix, visible, std::ignore) = tuple; - if (!visible) - continue; - - MVP = cameraMatrix * modelMatrix; - depthMVP = depthCameraMatrix * modelMatrix; - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix())); - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix((float)m_Width / m_Height))); - glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview)); - - glBindVertexArray(model->VAO); - for (auto texGroup : model->TextureGroups) + auto modelJob = std::dynamic_pointer_cast(job); + if (modelJob) { + glm::mat4 modelMatrix = modelJob->ModelMatrix; + + MVP = cameraMatrix * modelMatrix; + depthMVP = depthCameraMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); + glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); + //glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview)); + + glBindVertexArray(modelJob->VAO); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, *texGroup.Texture); - if (texGroup.NormalMap) + glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); + if (modelJob->NormalTexture != 0) { glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, *texGroup.NormalMap); + glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); } - if (texGroup.SpecularMap) + if (modelJob->SpecularTexture) { glActiveTexture(GL_TEXTURE3); - glBindTexture(GL_TEXTURE_2D, *texGroup.SpecularMap); + glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); } - glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); - } - } - - for (auto tuple : TexturesToRender) - { - Texture* texture; - glm::mat4 modelMatrix; - glm::mat4 billboardMatrix; - std::tie(texture, modelMatrix, billboardMatrix) = tuple; - - //MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix ); - MVP = cameraMatrix * modelMatrix * billboardMatrix; + glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); - depthMVP = depthCameraMatrix * modelMatrix; - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix())); - glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix((float)m_Width / m_Height))); + continue; + } - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, *texture); - glBindVertexArray(m_ScreenQuad); - glDrawArrays(GL_TRIANGLES, 0, 6); + //auto spriteJob = std::dynamic_pointer_cast(job); + //if (spriteJob) + //{ + // Texture* texture; + // glm::mat4 modelMatrix; + // glm::mat4 billboardMatrix; + // std::tie(texture, modelMatrix, billboardMatrix) = tuple; + + // //MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix ); + // MVP = cameraMatrix * modelMatrix * billboardMatrix; + + // depthMVP = depthCameraMatrix * modelMatrix; + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + // glUniformMatrix4fv(glGetUniformLocation(m_FirstPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height))); + + // glActiveTexture(GL_TEXTURE0); + // glBindTexture(GL_TEXTURE_2D, *texture); + // glBindVertexArray(m_ScreenQuad); + // glDrawArrays(GL_TRIANGLES, 0, 6); + + // continue; + //} } } -void Renderer::DrawLightScene(Viewport &viewport) +void Renderer::DrawLightScene(RenderQueue &rq) { glEnable(GL_BLEND); glBlendEquation (GL_FUNC_ADD); @@ -860,7 +1054,8 @@ void Renderer::DrawLightScene(Viewport &viewport) glDepthMask (GL_FALSE); glBindVertexArray(m_sphereModel->VAO); - glm::mat4 cameraMatrix = viewport.Camera->ProjectionMatrix((float)m_Width / m_Height) * viewport.Camera->ViewMatrix(); + glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); + glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); glm::mat4 MVP; for (auto &light : Lights) @@ -869,13 +1064,13 @@ void Renderer::DrawLightScene(Viewport &viewport) glUniform2fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ViewportSize"), 1,glm::value_ptr(glm::vec2(m_Width, m_Height))); glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); - glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ViewMatrix())); - glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(viewport.Camera->ProjectionMatrix((float)m_Width / m_Height))); + glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); glUniformMatrix4fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(light.SphereModelMatrix)); glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ls"), 1, glm::value_ptr(light.Specular)); glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ld"), 1, glm::value_ptr(light.Diffuse)); glUniform3fv(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "lp"), 1, glm::value_ptr(light.Position)); - glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "CameraPosition"), viewport.Camera->Position().x, viewport.Camera->Position().y, viewport.Camera->Position().z); + glUniform3f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "CameraPosition"), m_Camera->Position().x, m_Camera->Position().y, m_Camera->Position().z); glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "specularExponent"), light.SpecularExponent); // glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "ConstantAttenuation"), light.ConstantAttenuation); // glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), light.LinearAttenuation); @@ -1002,4 +1197,9 @@ void Renderer::UpdateCamera(int cameraIdentifier, glm::vec3 position, glm::quat m_Cameras[cameraIdentifier]->FOV(FOV); m_Cameras[cameraIdentifier]->NearClip(nearClip); m_Cameras[cameraIdentifier]->FarClip(farClip);*/ -} \ No newline at end of file +} + +void Renderer::ClearPointLights() +{ + Lights.clear(); +} diff --git a/src/Renderer.h b/src/Renderer.h index 5f2d013..8a10359 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -53,7 +53,9 @@ public: m_Camera = camera; } - void Draw(RenderQueue &rq); + void DrawFrame(RenderQueue &rq); + void DrawWorld(RenderQueue &rq); + void Swap(); #pragma endregion @@ -70,6 +72,8 @@ public: float _QuadraticAttenuation, float _radius ); + void ClearPointLights(); + void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding); void LoadContent(); @@ -178,13 +182,13 @@ private: void ClearStuff(); void DrawScene(); void DrawModels(ShaderProgram &shader); - void DrawShadowMap(); + void DrawShadowMap(RenderQueue &rq); void CreateShadowMap(int resolution); void FrameBufferTextures(); void DrawFBO(); void DrawFBO2(); - void DrawFBOScene(Viewport &viewport); - void DrawLightScene(Viewport &viewport); + void DrawFBOScene(RenderQueue &rq); + void DrawLightScene(RenderQueue &rq); void BindFragDataLocation(); glm::mat4 CreateLightMatrix(Light &_light); void UpdateSunProjection(); diff --git a/src/ShaderProgram.cpp b/src/ShaderProgram.cpp index bd67e90..6357149 100755 --- a/src/ShaderProgram.cpp +++ b/src/ShaderProgram.cpp @@ -155,4 +155,41 @@ void ShaderProgram::Bind() void ShaderProgram::Unbind() { glActiveShaderProgram(0, 0); -} \ No newline at end of file +} + +void ShaderProgram::LoadFromFolder(std::string folderPath) +{ + auto path = boost::filesystem::path(folderPath); + + if (!boost::filesystem::is_directory(path)) + { + LOG_ERROR("Failed to load shader program: \"%s\" is not a directory", folderPath.c_str()); + return; + } + + for (auto it = boost::filesystem::directory_iterator(path); it != boost::filesystem::directory_iterator(); it++) + { + std::string filename = it->path().filename().string(); + if (filename == "Vertex.glsl") + { + AddShader(std::shared_ptr(new VertexShader(filename))); + } + else if (filename == "Fragment.glsl") + { + AddShader(std::shared_ptr(new FragmentShader(filename))); + + } + else if (filename == "Geometry.glsl") + { + AddShader(std::shared_ptr(new GeometryShader(filename))); + } + } +} + +void ShaderProgram::BindFragDataLocation(int colorNumber, std::string name) +{ + if (m_ShaderProgramHandle == 0) + return; + + glBindFragDataLocation(m_ShaderProgramHandle, colorNumber, name.c_str()); +} diff --git a/src/ShaderProgram.h b/src/ShaderProgram.h index a27300c..f071d7f 100755 --- a/src/ShaderProgram.h +++ b/src/ShaderProgram.h @@ -6,6 +6,11 @@ #include #include +#include +#include + +#include "ResourceManager.h" + class Shader { public: @@ -57,23 +62,32 @@ public: : ShaderType(fileName) { } }; -class ShaderProgram +class ShaderProgram : public Resource { public: ShaderProgram() - : m_ShaderProgramHandle(0) { } + : m_ShaderProgramHandle(0) + { } + ShaderProgram(std::string folderPath) + : m_ShaderProgramHandle(0) + { } + ~ShaderProgram(); void AddShader(std::shared_ptr shader); + void BindFragDataLocation(int colorNumber, std::string name); void Compile(); GLuint Link(); GLuint GetHandle(); + operator GLuint() const { return m_ShaderProgramHandle; } void Bind(); void Unbind(); private: GLuint m_ShaderProgramHandle; std::vector> m_Shaders; + + void LoadFromFolder(std::string folderPath); }; #endif // ShaderProgram_h__ \ No newline at end of file diff --git a/src/Systems/RenderSystem.cpp b/src/Systems/RenderSystem.cpp index 5b84627..e101f30 100755 --- a/src/Systems/RenderSystem.cpp +++ b/src/Systems/RenderSystem.cpp @@ -4,9 +4,7 @@ void Systems::RenderSystem::RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) { - rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load("OBJ", resourceName)); }); - rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); }); - rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); }); + rm->RegisterType("Shader", [](std::string resourceName) { return new ShaderProgram(resourceName); }); } void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf) diff --git a/src/Systems/RenderSystem.h b/src/Systems/RenderSystem.h index f259f4c..e6350db 100755 --- a/src/Systems/RenderSystem.h +++ b/src/Systems/RenderSystem.h @@ -5,6 +5,7 @@ #include "System.h" #include "Systems/TransformSystem.h" +#include "ShaderProgram.h" #include "Model.h" #include "Texture.h" #include "Components/Transform.h" @@ -14,11 +15,11 @@ #include "Components/PointLight.h" #include "Components/DirectionalLight.h" #include "Components/Viewport.h" - #include "Components/Template.h" #include "Components/Transform.h" #include "Renderer.h" #include "RenderQueue.h" +#include "Events/SetViewportCamera.h" namespace Systems {