diff --git a/assets b/assets index 3af64d8b..007b54bd 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 3af64d8b1f8cdf3e20198b079dfc02f6d64fdc88 +Subproject commit 007b54bd678d0e80af878bed457e33e73bc0834a diff --git a/include/Engine/Rendering/DrawBloomPass.h b/include/Engine/Rendering/DrawBloomPass.h index e6a87c11..eaf17570 100644 --- a/include/Engine/Rendering/DrawBloomPass.h +++ b/include/Engine/Rendering/DrawBloomPass.h @@ -33,12 +33,14 @@ public: if (m_Quality == 0) { return m_BlackTexture->m_Texture; } else { - return m_GaussianTexture_vert; + return m_FinalGaussianTexture; } } private: + void GaussianLodPass(GLuint mipMap, GLuint texture); + void CombineGaussianBlur(); Texture* m_BlackTexture; Model* m_ScreenQuad; @@ -47,15 +49,19 @@ private: //const LightCullingPass* m_LightCullingPass int m_Iterations; int m_Quality = 0; + int m_BloomLod = 5; GLuint m_GaussianTexture_horiz = 0; GLuint m_GaussianTexture_vert = 0; + GLuint m_FinalGaussianTexture = 0; - FrameBuffer m_GaussianFrameBuffer_horiz; - FrameBuffer m_GaussianFrameBuffer_vert; + FrameBuffer* m_GaussianFrameBuffer_horiz = nullptr; + FrameBuffer* m_GaussianFrameBuffer_vert = nullptr; + FrameBuffer m_GaussianCombineBuffer; ShaderProgram* m_GaussianProgram_horiz; ShaderProgram* m_GaussianProgram_vert; + ShaderProgram* m_GaussianCombineProgram; }; diff --git a/include/Engine/Rendering/FrameBuffer.h b/include/Engine/Rendering/FrameBuffer.h index e9171894..1b4f6012 100644 --- a/include/Engine/Rendering/FrameBuffer.h +++ b/include/Engine/Rendering/FrameBuffer.h @@ -7,11 +7,12 @@ class BufferResource { public: - BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment); + BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod); GLuint* m_ResourceHandle; GLenum m_ResourceType; GLenum m_Attachment; + GLuint m_MipMapLod = 0; private: }; @@ -20,15 +21,15 @@ template class ResourceType : public BufferResource { public: - ResourceType(GLuint* resourceHandle, GLenum attachment) - : BufferResource(resourceHandle, RESOURCETYPE, attachment) { } + ResourceType(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod) + : BufferResource(resourceHandle, RESOURCETYPE, attachment, mipMapLod) { } }; class Texture2D : public ResourceType { public: - Texture2D(GLuint* resourceHandle, GLenum attachment) - : ResourceType(resourceHandle, attachment) { }; + Texture2D(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod = 0) + : ResourceType(resourceHandle, attachment, mipMapLod) { }; ~Texture2D(); }; @@ -37,7 +38,7 @@ class RenderBuffer : public ResourceType { public: RenderBuffer(GLuint* resourceHandle, GLenum attachment) - : ResourceType(resourceHandle, attachment) + : ResourceType(resourceHandle, attachment, 0) { }; ~RenderBuffer(); @@ -47,7 +48,7 @@ class Texture2DArray : public ResourceType { public: Texture2DArray(GLuint* resourceHandle, GLenum attachment) - : ResourceType(resourceHandle, attachment) + : ResourceType(resourceHandle, attachment, 0) { }; ~Texture2DArray(); diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h index c323fa06..3d55e721 100644 --- a/include/Engine/Rendering/SpriteJob.h +++ b/include/Engine/Rendering/SpriteJob.h @@ -21,14 +21,15 @@ struct SpriteJob : RenderJob SpriteJob(ComponentWrapper cSprite, Camera* camera, glm::mat4 matrix, World* world, glm::vec4 fillColor, float fillPercentage, bool depthSorted, bool isIndicator) : RenderJob() { - Model = ResourceManager::Load<::Model>("Models/Core/UnitQuad.mesh"); + Model = ResourceManager::Load<::Model>((std::string)cSprite["Model"]); ::RawModel::MaterialProperties matProp = Model->MaterialGroups().front(); TextureID = 0; DiffuseTexture = CommonFunctions::TryLoadResource(cSprite["DiffuseTexture"]); - IncandescenceTexture = CommonFunctions::TryLoadResource(cSprite["GlowMap"]); + Linear = (bool)cSprite["Linear"]; + StartIndex = matProp.material->StartIndex; EndIndex = matProp.material->EndIndex; Matrix = matrix; @@ -48,6 +49,26 @@ struct SpriteJob : RenderJob FillColor = fillColor; FillPercentage = fillPercentage; + + glm::vec3 scale = Transform::AbsoluteScale(world, cSprite.EntityID); + + if((bool)cSprite["KeepRatio"] == true) { + if(scale.y >= scale.x) { + ScaleY = (scale.x)/(scale.y); + ScaleX = 1.f; + } else { + ScaleY = 1.f; + ScaleX = (scale.x)/(scale.y); + } + } else { + if ((bool)cSprite["KeepRatioX"] == true) { + ScaleX = scale.x; + } + if ((bool)cSprite["KeepRatioY"] == true) { + ScaleY = scale.y; + } + } + }; unsigned int TextureID; @@ -69,6 +90,9 @@ struct SpriteJob : RenderJob bool Pickable; bool IsIndicator = false; bool BlurBackground = false; + float ScaleX = 1; + float ScaleY = 1; + bool Linear = false; glm::vec4 FillColor = glm::vec4(0); float FillPercentage = 0.0; diff --git a/include/Engine/Rendering/Util/GLError.h b/include/Engine/Rendering/Util/GLError.h index 8efe45f3..740a5a3c 100644 --- a/include/Engine/Rendering/Util/GLError.h +++ b/include/Engine/Rendering/Util/GLError.h @@ -16,7 +16,7 @@ inline bool _GLERROR(const char* info, const char* file, const char* func, unsig return false; } -#ifndef DEBUG +#ifdef DEBUG #define GLERROR(function) \ _GLERROR(function, __BASE_FILE__, __func__, __LINE__) #else diff --git a/include/Game/Systems/CapturePointSystem.h b/include/Game/Systems/CapturePointSystem.h index 3cf72e15..6211ad49 100644 --- a/include/Game/Systems/CapturePointSystem.h +++ b/include/Game/Systems/CapturePointSystem.h @@ -30,6 +30,7 @@ private: bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); EventRelay m_ECaptured; bool CapturePointSystem::OnCaptured(const Events::Captured& e); + void ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner); bool m_WinnerWasFound = false; //need to track these variables for the captureSystem to work as per design! diff --git a/resources/Schema/Components/Model.xml b/resources/Schema/Components/Model.xml index 35b05b69..99190e1f 100644 --- a/resources/Schema/Components/Model.xml +++ b/resources/Schema/Components/Model.xml @@ -9,5 +9,5 @@ true true true - 3.0 + 1.0 \ No newline at end of file diff --git a/resources/Schema/Components/Sprite.xml b/resources/Schema/Components/Sprite.xml index e577ac96..a1963ff8 100644 --- a/resources/Schema/Components/Sprite.xml +++ b/resources/Schema/Components/Sprite.xml @@ -1,9 +1,14 @@ + Models/Core/UnitQuad.mesh true true + false + false + false + false false diff --git a/resources/Schema/Components/Sprite.xsd b/resources/Schema/Components/Sprite.xsd index e26d71c9..af4860c8 100644 --- a/resources/Schema/Components/Sprite.xsd +++ b/resources/Schema/Components/Sprite.xsd @@ -9,14 +9,17 @@ + + The model the sprite will use. + - Diffuse Texture file + Diffuse Texture file. - GlowMap file + GlowMap file. - Color tint + Color tint. Whether the model is visible or not @@ -24,6 +27,18 @@ Whether the sprite should be sorted with depth or not. Only use false for textures that are on HUD + + Wether the sprite should repeat in x instead of stretch when scaled. + + + Wether the sprite should repeat in y instead of stretch when scaled. + + + Keep a 1:1 ratio between X and Y. + + + If it should use Linear or Nearest sampling method. + Wether the background should be blurred begind this sprite. diff --git a/resources/Schema/Entities/OverwatchCamera.xml b/resources/Schema/Entities/OverwatchCamera.xml index 6c93f033..92540e5b 100644 --- a/resources/Schema/Entities/OverwatchCamera.xml +++ b/resources/Schema/Entities/OverwatchCamera.xml @@ -8,7 +8,7 @@ - + @@ -34,13 +34,49 @@ + + + + + false + Models/Core/UnitQuad.mesh + + Textures/Icons/Classes/Assault-01.png + + + PickClass + 1 + + + + + + + + + + + Assault + Fonts/DroidSans.ttf,64 + + + + + + + + + + + - Textures/Icons/Classes/Defender-01.png - false + Models/Core/UnitQuad.mesh + + Textures/Icons/Classes/Defender-01.png PickClass @@ -72,9 +108,10 @@ - Textures/Icons/Classes/Sniper-01.png - false + Models/Core/UnitQuad.mesh + + Textures/Icons/Classes/Sniper-01.png PickClass @@ -102,40 +139,6 @@ - - - - - Textures/Icons/Classes/Assault-01.png - - false - - - PickClass - 1 - - - - - - - - - - - Assault - Fonts/DroidSans.ttf,64 - - - - - - - - - - - @@ -154,9 +157,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -232,9 +236,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -266,10 +271,11 @@ - Textures/Core/UnitHexagon.png + Models/Core/UnitQuad.mesh - false + Textures/Core/UnitHexagon.png + true PickTeam @@ -300,10 +306,12 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png + true PickTeam @@ -334,9 +342,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png false @@ -422,9 +431,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -441,9 +451,10 @@ 3 - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -458,9 +469,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -477,9 +489,10 @@ 4 - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -494,9 +507,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -513,9 +527,10 @@ 2 - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -530,9 +545,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -550,9 +566,10 @@ 1 - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -567,9 +584,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -584,9 +602,10 @@ - Textures/Core/UnitHexagon_Rotated.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon_Rotated.png @@ -604,9 +623,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png @@ -651,9 +671,10 @@ - Textures/Core/UnitHexagon.png - false + Models/Core/UnitQuad.mesh + + Textures/Core/UnitHexagon.png diff --git a/resources/Schema/Entities/aim_rays_with_capturep.xml b/resources/Schema/Entities/aim_rays_with_capturep.xml index 6aa3246a..3cf5a26a 100644 --- a/resources/Schema/Entities/aim_rays_with_capturep.xml +++ b/resources/Schema/Entities/aim_rays_with_capturep.xml @@ -99,7 +99,7 @@ - Schema/Entities/Player.xml + Schema/Entities/PlayerRed.xml @@ -225,6 +225,11 @@ + + + + false + @@ -239,7 +244,17 @@ - + + + + + + + + + + + diff --git a/resources/Shaders/CombineGaussianTexture.frag.glsl b/resources/Shaders/CombineGaussianTexture.frag.glsl new file mode 100644 index 00000000..93c36fb8 --- /dev/null +++ b/resources/Shaders/CombineGaussianTexture.frag.glsl @@ -0,0 +1,21 @@ +#version 430 + +layout (binding = 0) uniform sampler2D Texture; +uniform int MaxMipMap; + + +in VertexData{ + vec2 TextureCoordinate; +}Input; + +out vec4 fragmentColor; + +void main() +{ + vec4 result = vec4(0.0, 0.0, 0.0, 0.0); + + for(int i = 0; i < MaxMipMap; i++) { + result += textureLod(Texture, Input.TextureCoordinate, i); + } + fragmentColor = result; +} diff --git a/resources/Shaders/CombineGaussianTexture.vert.glsl b/resources/Shaders/CombineGaussianTexture.vert.glsl new file mode 100644 index 00000000..346bc141 --- /dev/null +++ b/resources/Shaders/CombineGaussianTexture.vert.glsl @@ -0,0 +1,13 @@ +#version 430 + +layout (location = 0) in vec3 Position; + +out VertexData{ + vec2 TextureCoordinate; +}Output; + +void main() +{ + gl_Position = vec4(Position, 1.0); + Output.TextureCoordinate = (vec2(Position) + 1) / 2; +} \ No newline at end of file diff --git a/resources/Shaders/Gaussian_horiz.frag.glsl b/resources/Shaders/Gaussian_horiz.frag.glsl index 8a306ec2..06426ed3 100644 --- a/resources/Shaders/Gaussian_horiz.frag.glsl +++ b/resources/Shaders/Gaussian_horiz.frag.glsl @@ -2,6 +2,7 @@ #extension GL_EXT_gpu_shader4 : enable layout (binding = 0) uniform sampler2D Texture; +uniform int Lod; in VertexData{ vec2 TextureCoordinate; @@ -10,12 +11,14 @@ in VertexData{ out vec4 fragmentColor; uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216); +//uniform float weight[3] = float[](0.265495, 0.226535, 0.140718); void main() { - vec2 tex_offset = 1.0 / textureSize2D(Texture, 0); + vec2 tex_offset = 1.0 / textureSize(Texture, Lod); vec3 center = texture(Texture, Input.TextureCoordinate).rgb; vec3 result = center * weight[0]; + for(int i = 1; i < 5; ++i) { vec4 eastFragments = texture(Texture, Input.TextureCoordinate + vec2(tex_offset.x * i, 0.0)); vec4 westFragments = texture(Texture, Input.TextureCoordinate - vec2(tex_offset.x * i, 0.0)); diff --git a/resources/Shaders/Gaussian_vert.frag.glsl b/resources/Shaders/Gaussian_vert.frag.glsl index 921ba55a..3924450a 100644 --- a/resources/Shaders/Gaussian_vert.frag.glsl +++ b/resources/Shaders/Gaussian_vert.frag.glsl @@ -2,6 +2,7 @@ #extension GL_EXT_gpu_shader4 : enable layout (binding = 0) uniform sampler2D Texture; +uniform int Lod; in VertexData{ vec2 TextureCoordinate; @@ -10,12 +11,14 @@ in VertexData{ out vec4 fragmentColor; uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216); +//uniform float weight[3] = float[](0.265495, 0.226535, 0.140718); void main() { - vec2 tex_offset = 1.0 / textureSize2D(Texture, 0); + vec2 tex_offset = 1.0 / textureSize(Texture, Lod); vec3 center = texture(Texture, Input.TextureCoordinate).rgb; vec3 result = center * weight[0]; + for(int i = 1; i < 5; ++i) { vec4 northFragments = texture(Texture, Input.TextureCoordinate + vec2(0.0, tex_offset.y * i)); vec4 southFragments = texture(Texture, Input.TextureCoordinate - vec2(0.0, tex_offset.y * i)); diff --git a/resources/Shaders/Sprite.frag.glsl b/resources/Shaders/Sprite.frag.glsl index abad7df1..5b6567eb 100644 --- a/resources/Shaders/Sprite.frag.glsl +++ b/resources/Shaders/Sprite.frag.glsl @@ -3,6 +3,8 @@ uniform vec4 Color; uniform vec4 FillColor; uniform float FillPercentage; +uniform float ScaleX; +uniform float ScaleY; uniform mat4 P; layout (binding = 1) uniform sampler2D DiffuseTexture; @@ -21,15 +23,16 @@ out vec4 bloomColor; void main() { - vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); - vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate); + vec4 diffuseTexel = texture2D(DiffuseTexture, vec2(Input.TextureCoordinate.x*ScaleX, Input.TextureCoordinate.y*ScaleY)); + vec4 glowTexel = texture2D(GlowMapTexture, vec2(Input.TextureCoordinate.x*ScaleX, Input.TextureCoordinate.y*ScaleY)); vec4 color_result = Color * diffuseTexel; float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; - if(pos <= FillPercentage) { - color_result = FillColor*diffuseTexel.a; - } + float fillResult = floor(pos*FillPercentage); + + color_result = FillColor*diffuseTexel.a*fillResult + color_result*(1-fillResult); + sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); //bloomColor = vec4(clamp((glowTexel.xyz*3) - 1.0, 0, 100), 1.0); diff --git a/src/Engine/Rendering/BlurHUD.cpp b/src/Engine/Rendering/BlurHUD.cpp index 8fdb7f1a..d9af3085 100644 --- a/src/Engine/Rendering/BlurHUD.cpp +++ b/src/Engine/Rendering/BlurHUD.cpp @@ -97,14 +97,14 @@ void BlurHUD::ClearBuffer() glClearStencil(0x00); glStencilMask(~0); glDisable(GL_SCISSOR_TEST); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_GaussianFrameBuffer_horiz.Unbind(); m_GaussianFrameBuffer_vert.Bind(); glClearColor(0.f, 0.f, 0.f, 0.f); glClearStencil(0x00); glStencilMask(~0); glDisable(GL_SCISSOR_TEST); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_GaussianFrameBuffer_vert.Unbind(); m_CombinedTextureBuffer.Bind(); @@ -211,12 +211,16 @@ void BlurHUD::FillStencil(RenderScene& scene) RenderState state; state.BindFramebuffer(m_GaussianFrameBuffer_horiz.GetHandle()); - state.Disable(GL_DEPTH_TEST); + state.Enable(GL_DEPTH_TEST); state.Enable(GL_CULL_FACE); state.Enable(GL_STENCIL_TEST); state.StencilFunc(GL_ALWAYS, 1, 0xFF); state.StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); state.StencilMask(0xFF); + + state.AlphaFunc(GL_GEQUAL, 0.95f); + state.Enable(GL_ALPHA_TEST); + glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality); m_FillDepthStencilProgram->Bind(); diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index 4172118c..f70f25c1 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -12,6 +12,7 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer, ConfigFile* config) DrawBloomPass::~DrawBloomPass() { CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz); CommonFunctions::DeleteTexture(&m_GaussianTexture_vert); + CommonFunctions::DeleteTexture(&m_FinalGaussianTexture); } void DrawBloomPass::InitializeTextures() @@ -30,9 +31,8 @@ void DrawBloomPass::ChangeQuality(int quality) if (m_Quality == 0) { CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz); - CommonFunctions::DeleteTexture(&m_GaussianTexture_vert); - m_GaussianTexture_horiz = 0; - m_GaussianTexture_vert = 0; + CommonFunctions::DeleteTexture(&m_GaussianTexture_vert); + CommonFunctions::DeleteTexture(&m_FinalGaussianTexture); return; } InitializeTextures(); @@ -62,22 +62,50 @@ void DrawBloomPass::InitializeShaderPrograms() m_GaussianProgram_vert->BindFragDataLocation(0, "fragmentColor"); m_GaussianProgram_vert->Link(); } + + m_GaussianCombineProgram = ResourceManager::Load("#GaussianCombineProgram"); + if (m_GaussianCombineProgram->GetHandle() == 0) { + m_GaussianCombineProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/CombineGaussianTexture.vert.glsl"))); + m_GaussianCombineProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/CombineGaussianTexture.frag.glsl"))); + m_GaussianCombineProgram->Compile(); + m_GaussianCombineProgram->BindFragDataLocation(0, "fragmentColor"); + m_GaussianCombineProgram->Link(); + } } void DrawBloomPass::InitializeBuffers() { - CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + CommonFunctions::GenerateMipMapTexture( + &m_GaussianTexture_horiz, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + , GL_RGB, GL_FLOAT, m_BloomLod); + CommonFunctions::GenerateMipMapTexture( + &m_GaussianTexture_vert, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + , GL_RGB, GL_FLOAT, m_BloomLod); + CommonFunctions::GenerateTexture(&m_FinalGaussianTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) { - m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0))); - } - m_GaussianFrameBuffer_horiz.Generate(); + if (m_GaussianCombineBuffer.GetHandle() == 0) { + m_GaussianCombineBuffer.AddResource(std::shared_ptr(new Texture2D(&m_FinalGaussianTexture, GL_COLOR_ATTACHMENT0))); + } + m_GaussianCombineBuffer.Generate(); - CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - if (m_GaussianFrameBuffer_vert.GetHandle() == 0) { - m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0))); - } - m_GaussianFrameBuffer_vert.Generate(); + if(m_GaussianFrameBuffer_horiz == nullptr) { + m_GaussianFrameBuffer_horiz = new FrameBuffer[m_BloomLod]; + } + if (m_GaussianFrameBuffer_vert == nullptr) { + m_GaussianFrameBuffer_vert = new FrameBuffer[m_BloomLod]; + } + + for (int i = 0; i < m_BloomLod; i++) { + if(m_GaussianFrameBuffer_horiz[i].GetHandle() == 0) { + m_GaussianFrameBuffer_horiz[i].AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0, i))); + } + m_GaussianFrameBuffer_horiz[i].Generate(); + + if (m_GaussianFrameBuffer_vert[i].GetHandle() == 0) { + m_GaussianFrameBuffer_vert[i].AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0, i))); + } + m_GaussianFrameBuffer_vert[i].Generate(); + } } @@ -87,33 +115,75 @@ void DrawBloomPass::ClearBuffer() return; } GLERROR("PRE"); - m_GaussianFrameBuffer_horiz.Bind(); + for (int i = 0; i < m_BloomLod; i++) { + m_GaussianFrameBuffer_horiz[i].Bind(); + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + m_GaussianFrameBuffer_horiz[i].Unbind(); + m_GaussianFrameBuffer_vert[i].Bind(); + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + m_GaussianFrameBuffer_vert[i].Unbind(); + + } + m_GaussianCombineBuffer.Bind(); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT); - m_GaussianFrameBuffer_horiz.Unbind(); - m_GaussianFrameBuffer_vert.Bind(); - glClearColor(0.f, 0.f, 0.f, 0.f); - glClear(GL_COLOR_BUFFER_BIT); - m_GaussianFrameBuffer_vert.Unbind(); + m_GaussianCombineBuffer.Unbind(); GLERROR("END"); } void DrawBloomPass::Draw(GLuint texture) +{ + if (m_Quality == 0) { + return; + } + + for (int i = 0; i < m_BloomLod; i++) { + GaussianLodPass(i, texture); + } + CombineGaussianBlur(); +} + + +void DrawBloomPass::OnWindowResize() { if (m_Quality == 0) { return; } - GLERROR("DrawBloomPass::Draw: Pre"); + CommonFunctions::GenerateMipMapTexture( + &m_GaussianTexture_vert, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + , GL_RGB, GL_FLOAT, m_BloomLod); + CommonFunctions::GenerateMipMapTexture( + &m_GaussianTexture_horiz, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height) + , GL_RGB, GL_FLOAT, m_BloomLod); + for (int i = 0; i < m_BloomLod; i++) { + m_GaussianFrameBuffer_vert[i].Generate(); + m_GaussianFrameBuffer_horiz[i].Generate(); + } + +} + +void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture) +{ + GLERROR("DrawBloomPass::Draw: Pre"); + glViewport(0, 0, m_Renderer->GetViewportSize().Width/(glm::pow(2, mipMap)), m_Renderer->GetViewportSize().Height/(glm::pow(2, mipMap))); DrawBloomPassState state; GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle(); GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle(); + m_GaussianProgram_vert->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_vert, "Lod"), mipMap); + m_GaussianProgram_horiz->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), mipMap); + //Horizontal pass, first use the given texture then save it to the horizontal framebuffer. - m_GaussianFrameBuffer_horiz.Bind(); - m_GaussianProgram_horiz->Bind(); + m_GaussianFrameBuffer_horiz[mipMap].Bind(); + + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glBindVertexArray(m_ScreenQuad->VAO); @@ -123,55 +193,56 @@ void DrawBloomPass::Draw(GLuint texture) //Iterate some times to make it more gaussian. for (int i = 1; i < m_Iterations; i++) { //Vertical pass - m_GaussianFrameBuffer_vert.Bind(); + m_GaussianFrameBuffer_vert[mipMap].Bind(); m_GaussianProgram_vert->Bind(); - glActiveTexture(GL_TEXTURE0); + + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); //horizontal pass - m_GaussianFrameBuffer_vert.Unbind(); + m_GaussianFrameBuffer_vert[mipMap].Unbind(); - m_GaussianFrameBuffer_horiz.Bind(); + m_GaussianFrameBuffer_horiz[mipMap].Bind(); m_GaussianProgram_horiz->Bind(); - glActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); - m_GaussianFrameBuffer_horiz.Unbind(); + m_GaussianFrameBuffer_horiz[mipMap].Unbind(); } //final vertical gaussian after the iterations are done - m_GaussianFrameBuffer_vert.Bind(); + m_GaussianFrameBuffer_vert[mipMap].Bind(); m_GaussianProgram_vert->Bind(); - glActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); GLERROR("DrawBloomPass::Draw: END"); + glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); + m_GaussianFrameBuffer_vert[mipMap].Unbind(); + } - -void DrawBloomPass::OnWindowResize() +void DrawBloomPass::CombineGaussianBlur() { - if (m_Quality == 0) { - return; - } - CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - m_GaussianFrameBuffer_vert.Generate(); - CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - m_GaussianFrameBuffer_horiz.Generate(); + m_GaussianCombineBuffer.Bind(); + m_GaussianCombineProgram->Bind(); + glUniform1i(glGetUniformLocation(m_GaussianCombineProgram->GetHandle(), "MaxMipMap"), m_BloomLod); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert); + glBindVertexArray(m_ScreenQuad->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1 + , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); } diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 67a67351..d03b0c2b 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -32,9 +32,9 @@ void DrawFinalPass::InitializeTextures() void DrawFinalPass::InitializeFrameBuffers() { - CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); //GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); //GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4); //GenerateTexture(&m_StencilTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_STENCIL, GL_STENCIL_INDEX8, GL_INT); @@ -311,6 +311,8 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass) GLERROR("TransparentObjects"); //state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); stateSprite->Enable(GL_DEPTH_TEST); + //stateSprite->AlphaFunc(GL_GEQUAL, 0.05f); + //stateSprite->Enable(GL_ALPHA_TEST); DrawSprites(scene.Jobs.SpriteJob, scene); GLERROR("SpriteJobs"); @@ -343,8 +345,8 @@ void DrawFinalPass::OnWindowResize() //InitializeFrameBuffers(); CommonFunctions::GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); - CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); m_FinalPassFrameBuffer.Generate(); GLERROR("Error changing texture resolutions"); @@ -1269,23 +1271,34 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position())); + RenderState* jobState = new RenderState(); + for(auto& job : jobs) { auto spriteJob = std::dynamic_pointer_cast(job); - RenderState jobState; if (spriteJob) { if(spriteJob->Depth == 0) { - jobState.Disable(GL_DEPTH_TEST); + jobState->Disable(GL_DEPTH_TEST); } glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * spriteJob->Matrix)); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(spriteJob->FillColor)); glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), spriteJob->FillPercentage); + glUniform1f(glGetUniformLocation(shaderHandle, "ScaleX"), spriteJob->ScaleX); + glUniform1f(glGetUniformLocation(shaderHandle, "ScaleY"), spriteJob->ScaleY); glActiveTexture(GL_TEXTURE1); if (spriteJob->DiffuseTexture != nullptr) { glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture); + if (spriteJob->Linear) { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + } else { glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture); } @@ -1303,6 +1316,7 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int))); } } + delete jobState; // m_SpriteProgram->Unbind(); } diff --git a/src/Engine/Rendering/FrameBuffer.cpp b/src/Engine/Rendering/FrameBuffer.cpp index c94423ba..dfabb8a3 100644 --- a/src/Engine/Rendering/FrameBuffer.cpp +++ b/src/Engine/Rendering/FrameBuffer.cpp @@ -2,11 +2,12 @@ #include "Rendering/FrameBuffer.h" -BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment) +BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod) { m_ResourceHandle = resourceHandle; m_ResourceType = resourceType; m_Attachment = attachment; + m_MipMapLod = mipMapLod; } Texture2D::~Texture2D() @@ -58,7 +59,7 @@ void FrameBuffer::Generate() for (auto it = m_Resources.begin(); it != m_Resources.end(); it++) { switch ((*it)->m_ResourceType) { case GL_TEXTURE_2D: - glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle, 0); + glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, (*it)->m_MipMapLod); GLERROR("FrameBuffer generate: glFramebufferTexture2D"); break; case GL_RENDERBUFFER: diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index 93783e19..820c184e 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -24,7 +24,7 @@ void PickingPass::InitializeTextures() glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE); CommonFunctions::GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST, - glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); + glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); } void PickingPass::InitializeFrameBuffers() diff --git a/src/Engine/Rendering/SSAOPass.cpp b/src/Engine/Rendering/SSAOPass.cpp index f3c7f74c..166bf924 100644 --- a/src/Engine/Rendering/SSAOPass.cpp +++ b/src/Engine/Rendering/SSAOPass.cpp @@ -233,6 +233,11 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera) GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle(); GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle(); + m_GaussianProgram_vert->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_vert, "Lod"), 0); + m_GaussianProgram_horiz->Bind(); + glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), 0); + m_GaussianFrameBuffer_horiz.Bind(); m_GaussianProgram_horiz->Bind(); @@ -252,8 +257,6 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_Gaussian_horiz); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); //horizontal pass @@ -265,8 +268,6 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_Gaussian_vert); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); m_GaussianFrameBuffer_horiz.Unbind(); @@ -279,8 +280,7 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_Gaussian_horiz); - glBindVertexArray(m_ScreenQuad->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex + 1 , GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex); diff --git a/src/Engine/Rendering/TextureSprite.cpp b/src/Engine/Rendering/TextureSprite.cpp index 178aebf0..70d086cd 100644 --- a/src/Engine/Rendering/TextureSprite.cpp +++ b/src/Engine/Rendering/TextureSprite.cpp @@ -3,9 +3,9 @@ TextureSprite::TextureSprite(std::string path) :Texture(path) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); GLERROR("Texture load"); } \ No newline at end of file diff --git a/src/Engine/Rendering/Util/CommonFunctions.cpp b/src/Engine/Rendering/Util/CommonFunctions.cpp index e1344928..c185cd5c 100644 --- a/src/Engine/Rendering/Util/CommonFunctions.cpp +++ b/src/Engine/Rendering/Util/CommonFunctions.cpp @@ -25,10 +25,12 @@ void CommonFunctions::GenerateMultiSampleTexture(GLuint* texture, int numSamples void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) { + glDeleteTextures(1, texture); glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, *texture); glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, texture); + //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dimensions.x, dimensions.y, format, type, NULL); + GLERROR("MipMap Texture glTexSubImage2D failed"); glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping); diff --git a/src/Engine/Rendering/Util/ScreenCoords.cpp b/src/Engine/Rendering/Util/ScreenCoords.cpp index a858524d..a8d8a662 100644 --- a/src/Engine/Rendering/Util/ScreenCoords.cpp +++ b/src/Engine/Rendering/Util/ScreenCoords.cpp @@ -36,10 +36,6 @@ ScreenCoords::PixelData ScreenCoords::ToPixelData(float x, float y, FrameBuffer* unsigned char pdata[3]; glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pdata); GLERROR("glReadPixels(pdata) Error"); - PickDataBuffer->Unbind(); - GLERROR("Unbind Error"); - glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer); - GLERROR("glBindFramebuffer(DepthBuffer) Error"); float depthData; glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depthData); GLERROR("glReadPixels(depthData) Error"); diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index 4647d1b7..13ac59f3 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -108,10 +108,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp //change what model is displaying (change all in case 2 capturepoints has been captured on the same frame) for (int i = 0; i < m_NumberOfCapturePoints; i++) { auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"]; - if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) { - (bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false; - (bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false; - (bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false; + if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").Valid()) { + ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Red"), owner == redTeam); + ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue"), owner == blueTeam); + ChangeCapturePointModelsVisibility(m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator"), owner == spectatorTeam); } } //save the next cap points and publish the captured event @@ -232,6 +232,14 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } +void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) { + (bool&)capturePointModels["Model"]["Visible"] = isOwner; + for (auto& capModel : capturePointModels.ChildrenWithComponent("Model")) + { + (bool&)capModel["Model"]["Visible"] = isOwner; + } +} + bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e) { //personEntered = e.Entity, thingEntered = e.Trigger