PNG is now a resource.
You can now load textures threaded. PNG will now throw exceptions when errors happend SpriteComponent is now working without billboarding.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "Frame.h"
|
#include "Frame.h"
|
||||||
#include "../Rendering/Texture.h"
|
#include "../Rendering/Texture.h"
|
||||||
|
#include "../Rendering/Util/CommonFunctions.h"
|
||||||
|
|
||||||
namespace GUI
|
namespace GUI
|
||||||
{
|
{
|
||||||
@@ -55,10 +56,10 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Texture = ResourceManager::Load<Texture>(resourceName);
|
m_Texture = CommonFunctions::LoadTexture(resourceName, false);
|
||||||
m_TextureName = resourceName;
|
m_TextureName = resourceName;
|
||||||
if (m_Texture == nullptr) {
|
if (m_Texture == nullptr) {
|
||||||
m_Texture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
m_Texture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
SizeToTexture();
|
SizeToTexture();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "FrameBuffer.h"
|
#include "FrameBuffer.h"
|
||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
#include "Util/UnorderedMapVec2.h"
|
#include "Util/UnorderedMapVec2.h"
|
||||||
|
#include "Util/CommonFunctions.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
class DrawFinalPass
|
class DrawFinalPass
|
||||||
@@ -43,6 +44,7 @@ private:
|
|||||||
Texture* m_BlackTexture;
|
Texture* m_BlackTexture;
|
||||||
Texture* m_NeutralNormalTexture;
|
Texture* m_NeutralNormalTexture;
|
||||||
Texture* m_GreyTexture;
|
Texture* m_GreyTexture;
|
||||||
|
Texture* m_ErrorTexture;
|
||||||
|
|
||||||
FrameBuffer m_FinalPassFrameBuffer;
|
FrameBuffer m_FinalPassFrameBuffer;
|
||||||
GLuint m_BloomTexture;
|
GLuint m_BloomTexture;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define Model_h__
|
#define Model_h__
|
||||||
|
|
||||||
#include "Rendering/RawModelCustom.h"
|
#include "Rendering/RawModelCustom.h"
|
||||||
|
#include "Util/CommonFunctions.h"
|
||||||
//#include "Rendering/RawModelAssimp.h"
|
//#include "Rendering/RawModelAssimp.h"
|
||||||
#include "../OpenGL.h"
|
#include "../OpenGL.h"
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,10 @@
|
|||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
#include "../Common.h"
|
#include "../Common.h"
|
||||||
|
#include "../Core/ResourceManager.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
|
||||||
class PNG : public Image
|
class PNG : public Image, public Resource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PNG(std::string path);
|
PNG(std::string path);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "../Core/Transform.h"
|
#include "../Core/Transform.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "TextPass.h"
|
#include "TextPass.h"
|
||||||
|
#include "Util/CommonFunctions.h"
|
||||||
|
|
||||||
class Renderer : public IRenderer
|
class Renderer : public IRenderer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,23 +24,17 @@ struct SpriteJob : RenderJob
|
|||||||
::RawModel::MaterialGroup matGroup = Model->MaterialGroups().front();
|
::RawModel::MaterialGroup matGroup = Model->MaterialGroups().front();
|
||||||
TextureID = (matGroup.Texture) ? matGroup.Texture->ResourceID : 0;
|
TextureID = (matGroup.Texture) ? matGroup.Texture->ResourceID : 0;
|
||||||
|
|
||||||
if (cSprite["DiffuseTexture"]) {
|
DiffuseTexture = CommonFunctions::LoadTexture(cSprite["DiffuseTexture"], true);
|
||||||
DiffuseTexture = ResourceManager::Load<Texture>(cSprite["DiffuseTexture"]);
|
|
||||||
} else {
|
IncandescenceTexture = CommonFunctions::LoadTexture(cSprite["GlowMap"], true);
|
||||||
DiffuseTexture = nullptr;
|
|
||||||
}
|
|
||||||
if (cSprite["GlowMap"]) {
|
|
||||||
IncandescenceTexture = ResourceManager::Load<Texture>(cSprite["GlowMap"]);
|
|
||||||
} else {
|
|
||||||
IncandescenceTexture = nullptr;
|
|
||||||
}
|
|
||||||
StartIndex = matGroup.StartIndex;
|
StartIndex = matGroup.StartIndex;
|
||||||
EndIndex = matGroup.EndIndex;
|
EndIndex = matGroup.EndIndex;
|
||||||
Matrix = matrix;
|
Matrix = matrix;
|
||||||
Color = cSprite["Color"];
|
Color = cSprite["Color"];
|
||||||
Entity = cSprite.EntityID;
|
Entity = cSprite.EntityID;
|
||||||
glm::vec3 abspos = Transform::AbsolutePosition(world, cSprite.EntityID);
|
Position = Transform::AbsolutePosition(world, cSprite.EntityID);
|
||||||
glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
|
glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(Position, 1));
|
||||||
Depth = viewpos.z;
|
Depth = viewpos.z;
|
||||||
World = world;
|
World = world;
|
||||||
|
|
||||||
@@ -58,6 +52,7 @@ struct SpriteJob : RenderJob
|
|||||||
const Texture* IncandescenceTexture;
|
const Texture* IncandescenceTexture;
|
||||||
float Shininess = 0.f;
|
float Shininess = 0.f;
|
||||||
glm::vec4 Color;
|
glm::vec4 Color;
|
||||||
|
glm::vec3 Position;
|
||||||
const ::Model* Model = nullptr;
|
const ::Model* Model = nullptr;
|
||||||
unsigned int StartIndex = 0;
|
unsigned int StartIndex = 0;
|
||||||
unsigned int EndIndex = 0;
|
unsigned int EndIndex = 0;
|
||||||
|
|||||||
@@ -4,14 +4,11 @@
|
|||||||
#include "../../Common.h"
|
#include "../../Common.h"
|
||||||
#include "../../OpenGL.h"
|
#include "../../OpenGL.h"
|
||||||
#include "../../GLM.h"
|
#include "../../GLM.h"
|
||||||
|
#include "../Texture.h"
|
||||||
|
|
||||||
class CommonFuntions
|
namespace CommonFunctions
|
||||||
{
|
{
|
||||||
public:
|
Texture* LoadTexture(std::string path, bool threaded);
|
||||||
CommonFuntions() = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="7364.7876" Z="0"/>
|
<Orientation X="0" Y="7364.78906" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -188,7 +188,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="2019.28503" Z="0"/>
|
<Orientation X="0" Y="2019.2854" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -683,7 +683,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="316.504456" Z="0"/>
|
<Orientation X="0" Y="316.504944" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -730,7 +730,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="316.504456" Z="0"/>
|
<Orientation X="0" Y="316.504944" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -790,7 +790,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="316.504456" Z="0"/>
|
<Orientation X="0" Y="316.504944" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -837,7 +837,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="316.504456" Z="0"/>
|
<Orientation X="0" Y="316.504944" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -883,7 +883,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="316.504456" Z="0"/>
|
<Orientation X="0" Y="316.504944" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -930,7 +930,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="316.504456" Z="0"/>
|
<Orientation X="0" Y="316.504944" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -977,7 +977,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="316.504456" Z="0"/>
|
<Orientation X="0" Y="316.504944" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -1374,7 +1374,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="850.206848" Z="0"/>
|
<Orientation X="0" Y="850.207336" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -1383,7 +1383,7 @@
|
|||||||
<c:ExplosionEffect>
|
<c:ExplosionEffect>
|
||||||
<ColorByDistance>true</ColorByDistance>
|
<ColorByDistance>true</ColorByDistance>
|
||||||
<Velocity X="0.800000012" Y="0.0379999988" Z="0"/>
|
<Velocity X="0.800000012" Y="0.0379999988" Z="0"/>
|
||||||
<TimeSinceDeath>0.75008034908941568</TimeSinceDeath>
|
<TimeSinceDeath>0.75102457088592522</TimeSinceDeath>
|
||||||
<ExplosionDuration>3.7999999523162842</ExplosionDuration>
|
<ExplosionDuration>3.7999999523162842</ExplosionDuration>
|
||||||
<EndColor A="0" B="23.5294113" G="11.7647057" R="0"/>
|
<EndColor A="0" B="23.5294113" G="11.7647057" R="0"/>
|
||||||
<Randomness>true</Randomness>
|
<Randomness>true</Randomness>
|
||||||
@@ -1430,7 +1430,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="850.206848" Z="0"/>
|
<Orientation X="0" Y="850.207336" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -1439,7 +1439,7 @@
|
|||||||
<c:ExplosionEffect>
|
<c:ExplosionEffect>
|
||||||
<Velocity X="0.5" Y="1" Z="0"/>
|
<Velocity X="0.5" Y="1" Z="0"/>
|
||||||
<ExplosionOrigin X="0" Y="0.900000036" Z="0"/>
|
<ExplosionOrigin X="0" Y="0.900000036" Z="0"/>
|
||||||
<TimeSinceDeath>1.1999860997035228</TimeSinceDeath>
|
<TimeSinceDeath>1.2009303215000324</TimeSinceDeath>
|
||||||
</c:ExplosionEffect>
|
</c:ExplosionEffect>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>Models/Assault.mesh</Resource>
|
<Resource>Models/Assault.mesh</Resource>
|
||||||
@@ -1482,7 +1482,7 @@
|
|||||||
<Axis X="0" Y="1" Z="0"/>
|
<Axis X="0" Y="1" Z="0"/>
|
||||||
</c:RaptorCopter>
|
</c:RaptorCopter>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
<Orientation X="0" Y="850.206848" Z="0"/>
|
<Orientation X="0" Y="850.207336" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -1497,7 +1497,7 @@
|
|||||||
<ColorByDistance>true</ColorByDistance>
|
<ColorByDistance>true</ColorByDistance>
|
||||||
<Velocity X="0.300000012" Y="2" Z="0"/>
|
<Velocity X="0.300000012" Y="2" Z="0"/>
|
||||||
<ExplosionOrigin X="0" Y="1.30000007" Z="-0.200000003"/>
|
<ExplosionOrigin X="0" Y="1.30000007" Z="-0.200000003"/>
|
||||||
<TimeSinceDeath>0.68343188336345406</TimeSinceDeath>
|
<TimeSinceDeath>0.68437610515996361</TimeSinceDeath>
|
||||||
<EndColor A="0" B="0.333333343" G="0.933333337" R="3.92156863"/>
|
<EndColor A="0" B="0.333333343" G="0.933333337" R="3.92156863"/>
|
||||||
<Randomness>true</Randomness>
|
<Randomness>true</Randomness>
|
||||||
</c:ExplosionEffect>
|
</c:ExplosionEffect>
|
||||||
@@ -1553,6 +1553,50 @@
|
|||||||
</Entity>
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
</Entity>
|
</Entity>
|
||||||
|
<Entity name="SpriteOrigin">
|
||||||
|
<Components>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-22.5368404" Y="1.10000002" Z="0"/>
|
||||||
|
<Orientation X="0" Y="1.45400012" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="Sprite1">
|
||||||
|
<Components>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/FoliageDiff.png</DiffuseTexture>
|
||||||
|
<GlowMap>Textures/DefenderGunBlueIncd.png</GlowMap>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="Spite2">
|
||||||
|
<Components>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/FoliageDiff.png</DiffuseTexture>
|
||||||
|
<GlowMap>Textures/AssaultWeaponBlueGlowMap.png</GlowMap>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0.106963724" Y="0" Z="-1.35893154"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="Sprite3">
|
||||||
|
<Components>
|
||||||
|
<c:Sprite>
|
||||||
|
<DiffuseTexture>Textures/FoliageDiff.png</DiffuseTexture>
|
||||||
|
<GlowMap>Textures/GlowTest.png</GlowMap>
|
||||||
|
</c:Sprite>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-0.505262792" Y="0" Z="-2.34881783"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
|
|
||||||
</Entity>
|
</Entity>
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ out VertexData{
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = P * M * vec4(Position, 1.0);
|
|
||||||
|
gl_Position = P * V * M * vec4(Position, 1.0);
|
||||||
|
|
||||||
Output.Position = Position;
|
Output.Position = Position;
|
||||||
Output.TextureCoordinate = TextureCoords;
|
Output.TextureCoordinate = TextureCoords;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer)
|
|||||||
|
|
||||||
void DrawBloomPass::InitializeTextures()
|
void DrawBloomPass::InitializeTextures()
|
||||||
{
|
{
|
||||||
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
|
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawBloomPass::InitializeShaderPrograms()
|
void DrawBloomPass::InitializeShaderPrograms()
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
|
|||||||
|
|
||||||
void DrawFinalPass::InitializeTextures()
|
void DrawFinalPass::InitializeTextures()
|
||||||
{
|
{
|
||||||
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
|
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
|
||||||
m_BlackTexture = ResourceManager::Load<Texture>("Textures/Core/Black.png");
|
m_BlackTexture = CommonFunctions::LoadTexture("Textures/Core/Black.png", false);
|
||||||
m_NeutralNormalTexture = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
|
m_NeutralNormalTexture = CommonFunctions::LoadTexture("Textures/Core/NeutralNormalMap.png", false);
|
||||||
m_GreyTexture = ResourceManager::Load<Texture>("Textures/Core/Grey.png");
|
m_GreyTexture = CommonFunctions::LoadTexture("Textures/Core/Grey.png", false);
|
||||||
|
m_ErrorTexture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawFinalPass::InitializeFrameBuffers()
|
void DrawFinalPass::InitializeFrameBuffers()
|
||||||
@@ -56,7 +57,7 @@ void DrawFinalPass::InitializeShaderPrograms()
|
|||||||
m_ExplosionEffectProgram->Link();
|
m_ExplosionEffectProgram->Link();
|
||||||
GLERROR("Creating explosion program");
|
GLERROR("Creating explosion program");
|
||||||
|
|
||||||
m_SpriteProgram = ResourceManager::Load<ShaderProgram>("#m_SpriteProgram");
|
m_SpriteProgram = ResourceManager::Load<ShaderProgram>("#SpriteProgram");
|
||||||
m_SpriteProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Sprite.vert.glsl")));
|
m_SpriteProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Sprite.vert.glsl")));
|
||||||
m_SpriteProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Sprite.frag.glsl")));
|
m_SpriteProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Sprite.frag.glsl")));
|
||||||
m_SpriteProgram->Compile();
|
m_SpriteProgram->Compile();
|
||||||
@@ -222,10 +223,12 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
|
|||||||
for(auto& job : jobs) {
|
for(auto& job : jobs) {
|
||||||
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
|
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
|
||||||
|
|
||||||
if(spriteJob) {
|
if (spriteJob) {
|
||||||
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||||
|
glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position()));
|
||||||
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
|
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
|
||||||
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(spriteJob->FillColor));
|
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(spriteJob->FillColor));
|
||||||
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), spriteJob->FillPercentage);
|
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), spriteJob->FillPercentage);
|
||||||
@@ -234,7 +237,7 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
|
|||||||
if (spriteJob->DiffuseTexture != nullptr) {
|
if (spriteJob->DiffuseTexture != nullptr) {
|
||||||
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture);
|
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture);
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ Model::Model(std::string fileName)
|
|||||||
|
|
||||||
for (auto& group : m_RawModel->MaterialGroups) {
|
for (auto& group : m_RawModel->MaterialGroups) {
|
||||||
if (!group.TexturePath.empty()) {
|
if (!group.TexturePath.empty()) {
|
||||||
group.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.TexturePath));
|
group.Texture = std::shared_ptr<Texture>(CommonFunctions::LoadTexture(group.TexturePath, false));
|
||||||
}
|
}
|
||||||
if (!group.NormalMapPath.empty()) {
|
if (!group.NormalMapPath.empty()) {
|
||||||
group.NormalMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.NormalMapPath));
|
group.NormalMap = std::shared_ptr<Texture>(CommonFunctions::LoadTexture(group.NormalMapPath, false));
|
||||||
}
|
}
|
||||||
if (!group.SpecularMapPath.empty()) {
|
if (!group.SpecularMapPath.empty()) {
|
||||||
group.SpecularMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.SpecularMapPath));
|
group.SpecularMap = std::shared_ptr<Texture>(CommonFunctions::LoadTexture(group.SpecularMapPath, false));
|
||||||
}
|
}
|
||||||
if (!group.IncandescenceMapPath.empty()) {
|
if (!group.IncandescenceMapPath.empty()) {
|
||||||
group.IncandescenceMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.IncandescenceMapPath));
|
group.IncandescenceMap = std::shared_ptr<Texture>(CommonFunctions::LoadTexture(group.IncandescenceMapPath, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,40 +4,35 @@ PNG::PNG(std::string path)
|
|||||||
{
|
{
|
||||||
FILE* file = fopen(path.c_str(), "rb");
|
FILE* file = fopen(path.c_str(), "rb");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
LOG_ERROR("Failed to open texture file \"%s\": %s", path.c_str(), const_cast<const char*>(strerror(errno)));
|
throw Resource::FailedLoadingException("Failed to open texture file.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
png_byte header[8];
|
png_byte header[8];
|
||||||
fread(header, 1, 8, file);
|
fread(header, 1, 8, file);
|
||||||
bool isPNG = !png_sig_cmp(header, 0, 8);
|
bool isPNG = !png_sig_cmp(header, 0, 8);
|
||||||
if (!isPNG) {
|
if (!isPNG) {
|
||||||
LOG_ERROR("Failed to load texture file \"%s\": File isn't PNG", path.c_str());
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
throw Resource::FailedLoadingException("File is not PNG.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize libpng
|
// Initialize libpng
|
||||||
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, (png_error_ptr)&PNG::pngErrorFunction, (png_error_ptr)&PNG::pngErrorFunction);
|
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, (png_error_ptr)&PNG::pngErrorFunction, (png_error_ptr)&PNG::pngErrorFunction);
|
||||||
if (!png_ptr) {
|
if (!png_ptr) {
|
||||||
LOG_ERROR("libpng: Failed to initialze png_struct");
|
|
||||||
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
|
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
throw Resource::FailedLoadingException("Failed to initialze png_struct.");
|
||||||
}
|
}
|
||||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (!info_ptr) {
|
if (!info_ptr) {
|
||||||
LOG_ERROR("libpng: Failed to initialze png_info");
|
|
||||||
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
|
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
throw Resource::FailedLoadingException("Failed to initialze png_info.");
|
||||||
}
|
}
|
||||||
png_infop info_end_ptr = png_create_info_struct(png_ptr);
|
png_infop info_end_ptr = png_create_info_struct(png_ptr);
|
||||||
if (!info_end_ptr) {
|
if (!info_end_ptr) {
|
||||||
LOG_ERROR("libpng: Failed to initialze second png_info");
|
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
|
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
throw Resource::FailedLoadingException("Failed to initialze second png_info.");
|
||||||
}
|
}
|
||||||
png_init_io(png_ptr, file);
|
png_init_io(png_ptr, file);
|
||||||
|
|
||||||
@@ -51,8 +46,8 @@ PNG::PNG(std::string path)
|
|||||||
unsigned int width, height;
|
unsigned int width, height;
|
||||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);
|
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);
|
||||||
if (bit_depth != 8) {
|
if (bit_depth != 8) {
|
||||||
LOG_ERROR("libpng: Unsupported bit depth \"%i\" of image \"%s\", must be 8", bit_depth, path.c_str());
|
throw Resource::FailedLoadingException("Unsupported bit depth. Must be 8");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
switch (color_type) {
|
switch (color_type) {
|
||||||
case PNG_COLOR_TYPE_RGB:
|
case PNG_COLOR_TYPE_RGB:
|
||||||
@@ -60,8 +55,7 @@ PNG::PNG(std::string path)
|
|||||||
Format = Image::ImageFormat::RGBA;
|
Format = Image::ImageFormat::RGBA;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_ERROR("libpng: Unsupported color format \"%i\" of image \"%s\"", color_type, path.c_str());
|
throw Resource::FailedLoadingException("Unsupported color format.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert RGB to RGBA, since DirectX rather treat them all the same way
|
// Convert RGB to RGBA, since DirectX rather treat them all the same way
|
||||||
|
|||||||
@@ -106,16 +106,21 @@ void Renderer::Draw(RenderFrame& frame)
|
|||||||
for (auto scene : frame.RenderScenes){
|
for (auto scene : frame.RenderScenes){
|
||||||
|
|
||||||
SortRenderJobsByDepth(*scene);
|
SortRenderJobsByDepth(*scene);
|
||||||
|
GLERROR("SortByDepth");
|
||||||
m_PickingPass->Draw(*scene);
|
m_PickingPass->Draw(*scene);
|
||||||
|
GLERROR("Drawing pickingpass");
|
||||||
m_LightCullingPass->GenerateNewFrustum(*scene);
|
m_LightCullingPass->GenerateNewFrustum(*scene);
|
||||||
|
GLERROR("Generate frustums");
|
||||||
m_LightCullingPass->FillLightList(*scene);
|
m_LightCullingPass->FillLightList(*scene);
|
||||||
|
GLERROR("Filling light list");
|
||||||
m_LightCullingPass->CullLights(*scene);
|
m_LightCullingPass->CullLights(*scene);
|
||||||
|
GLERROR("LightCulling");
|
||||||
m_DrawFinalPass->Draw(*scene);
|
m_DrawFinalPass->Draw(*scene);
|
||||||
|
GLERROR("Draw Geometry+Light");
|
||||||
//m_DrawScenePass->Draw(*scene);
|
//m_DrawScenePass->Draw(*scene);
|
||||||
|
|
||||||
GLERROR("Renderer::Draw m_DrawScenePass->Draw");
|
|
||||||
|
|
||||||
m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
|
m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
|
||||||
|
GLERROR("Draw Text");
|
||||||
|
|
||||||
}
|
}
|
||||||
m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture());
|
m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture());
|
||||||
@@ -136,7 +141,8 @@ void Renderer::Draw(RenderFrame& frame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_ImGuiRenderPass->Draw();
|
m_ImGuiRenderPass->Draw();
|
||||||
glfwSwapBuffers(m_Window);
|
GLERROR("Imgui draw");
|
||||||
|
glfwSwapBuffers(m_Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
PickData Renderer::Pick(glm::vec2 screenCoord)
|
PickData Renderer::Pick(glm::vec2 screenCoord)
|
||||||
@@ -146,8 +152,8 @@ PickData Renderer::Pick(glm::vec2 screenCoord)
|
|||||||
|
|
||||||
void Renderer::InitializeTextures()
|
void Renderer::InitializeTextures()
|
||||||
{
|
{
|
||||||
m_ErrorTexture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
m_ErrorTexture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false);
|
||||||
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
|
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -155,6 +161,7 @@ void Renderer::SortRenderJobsByDepth(RenderScene &scene)
|
|||||||
{
|
{
|
||||||
//Sort all forward jobs so transparency is good.
|
//Sort all forward jobs so transparency is good.
|
||||||
scene.TransparentObjects.sort(Renderer::DepthSort);
|
scene.TransparentObjects.sort(Renderer::DepthSort);
|
||||||
|
scene.SpriteJobs.sort(Renderer::DepthSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
|
||||||
|
|||||||
@@ -2,24 +2,25 @@
|
|||||||
|
|
||||||
Texture::Texture(std::string path)
|
Texture::Texture(std::string path)
|
||||||
{
|
{
|
||||||
|
PNG* img = ResourceManager::Load<PNG, true>(path); //TODO: Make this threaded. Catch exeptions in all other load places.
|
||||||
|
|
||||||
PNG image(path);
|
//PNG image(path);
|
||||||
|
|
||||||
if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) {
|
//if (img->Width == 0 && img->Height == 0 || img->Format == Image::ImageFormat::Unknown) {
|
||||||
//image = PNG("Textures/Core/ErrorTexture.png");
|
// //image = PNG("Textures/Core/ErrorTexture.png");
|
||||||
return; // Temporary fix to remove crash
|
// //return; // Temporary fix to remove crash
|
||||||
/*
|
|
||||||
if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) {
|
|
||||||
LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
this->Width = image.Width;
|
// if (img->Width == 0 && img->Height == 0 || img->Format == Image::ImageFormat::Unknown) {
|
||||||
this->Height = image.Height;
|
// LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
this->Width = img->Width;
|
||||||
|
this->Height = img->Height;
|
||||||
|
|
||||||
GLint format;
|
GLint format;
|
||||||
switch (image.Format) {
|
switch (img->Format) {
|
||||||
case Image::ImageFormat::RGB:
|
case Image::ImageFormat::RGB:
|
||||||
format = GL_RGB;
|
format = GL_RGB;
|
||||||
break;
|
break;
|
||||||
@@ -32,7 +33,7 @@ Texture::Texture(std::string path)
|
|||||||
glGenTextures(1, &m_Texture);
|
glGenTextures(1, &m_Texture);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_Texture);
|
glBindTexture(GL_TEXTURE_2D, m_Texture);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, format, image.Width, image.Height, 0, format, GL_UNSIGNED_BYTE, image.Data);
|
glTexImage2D(GL_TEXTURE_2D, 0, format, img->Width, img->Height, 0, format, GL_UNSIGNED_BYTE, img->Data);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|||||||
@@ -1,2 +1,19 @@
|
|||||||
#include "Rendering/Util/CommonFunctions.h"
|
#include "Rendering/Util/CommonFunctions.h"
|
||||||
|
|
||||||
|
Texture* CommonFunctions::LoadTexture(std::string path, bool threaded)
|
||||||
|
{
|
||||||
|
Texture* img;
|
||||||
|
try {
|
||||||
|
if(threaded) {
|
||||||
|
img = ResourceManager::Load<Texture, true>(path);
|
||||||
|
} else {
|
||||||
|
img = ResourceManager::Load<Texture, false>(path);
|
||||||
|
}
|
||||||
|
} catch (const Resource::StillLoadingException&) {
|
||||||
|
img = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
||||||
|
} catch (const std::exception&) {
|
||||||
|
img = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ Game::Game(int argc, char* argv[])
|
|||||||
ResourceManager::RegisterType<Model>("Model");
|
ResourceManager::RegisterType<Model>("Model");
|
||||||
ResourceManager::RegisterType<RawModel>("RawModel");
|
ResourceManager::RegisterType<RawModel>("RawModel");
|
||||||
ResourceManager::RegisterType<Texture>("Texture");
|
ResourceManager::RegisterType<Texture>("Texture");
|
||||||
|
ResourceManager::RegisterType<PNG>("Png");
|
||||||
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
|
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
|
||||||
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
||||||
ResourceManager::RegisterType<Font>("FontFile");
|
ResourceManager::RegisterType<Font>("FontFile");
|
||||||
|
|||||||
Reference in New Issue
Block a user