From 4322a5d8dae2c9d1f9377d304f167cfb3d2353b8 Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 10 Mar 2016 15:21:11 +0100 Subject: [PATCH] Some fixes for sprites --- include/Engine/Rendering/SpriteJob.h | 14 +- resources/Schema/Components/Sprite.xml | 2 + resources/Schema/Components/Sprite.xsd | 12 +- resources/Schema/Entities/OverwatchCamera.xml | 167 ++++++++++-------- src/Engine/Rendering/DrawFinalPass.cpp | 8 +- src/Engine/Rendering/TextureSprite.cpp | 2 +- 6 files changed, 124 insertions(+), 81 deletions(-) diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h index 6b52144f..6ba2e63f 100644 --- a/include/Engine/Rendering/SpriteJob.h +++ b/include/Engine/Rendering/SpriteJob.h @@ -21,14 +21,23 @@ 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"]); + if ((bool)cSprite["Linear"]) { + glBindTexture(GL_TEXTURE_2D, DiffuseTexture->m_Texture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + glBindTexture(GL_TEXTURE_2D, DiffuseTexture->m_Texture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + StartIndex = matProp.material->StartIndex; EndIndex = matProp.material->EndIndex; Matrix = matrix; @@ -89,6 +98,7 @@ struct SpriteJob : RenderJob 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/resources/Schema/Components/Sprite.xml b/resources/Schema/Components/Sprite.xml index 2c0465e9..a1963ff8 100644 --- a/resources/Schema/Components/Sprite.xml +++ b/resources/Schema/Components/Sprite.xml @@ -1,5 +1,6 @@ + Models/Core/UnitQuad.mesh @@ -8,5 +9,6 @@ false false false + false false diff --git a/resources/Schema/Components/Sprite.xsd b/resources/Schema/Components/Sprite.xsd index eab74bfc..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 @@ -33,6 +36,9 @@ 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/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index a18bd411..a685a6d3 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1271,14 +1271,15 @@ 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)); @@ -1294,6 +1295,8 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture); } + + glActiveTexture(GL_TEXTURE2); if (spriteJob->IncandescenceTexture != nullptr) { glBindTexture(GL_TEXTURE_2D, spriteJob->IncandescenceTexture->m_Texture); @@ -1307,6 +1310,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/TextureSprite.cpp b/src/Engine/Rendering/TextureSprite.cpp index 2a43e455..70d086cd 100644 --- a/src/Engine/Rendering/TextureSprite.cpp +++ b/src/Engine/Rendering/TextureSprite.cpp @@ -6,6 +6,6 @@ TextureSprite::TextureSprite(std::string path) 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