Merge, now you can see sprites.

Merge remote-tracking branch 'origin/deffered_rendering' into particles

Conflicts:
	src/GameWorld.cpp
This commit is contained in:
Stiffly
2014-05-31 00:00:00 +02:00
7 changed files with 92 additions and 69 deletions
+2 -3
View File
@@ -4,16 +4,15 @@
#include <string>
#include "Component.h"
#include "Color.h"
namespace Components
{
struct Model : Component
{
Model() : Visible(true), ShadowCaster(true), Transparent(false) { }
Model() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)), Visible(true), ShadowCaster(true), Transparent(false) { }
std::string ModelFile;
Color Color;
glm::vec4 Color;
bool Visible;
bool ShadowCaster;
bool Transparent;
+3 -2
View File
@@ -4,15 +4,16 @@
#include <string>
#include "Component.h"
#include "Color.h"
namespace Components
{
struct Sprite : Component
{
Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { }
std::string SpriteFile;
Color Color;
glm::vec4 Color;
virtual Sprite* Clone() const override { return new Sprite(*this); }
};
+2 -2
View File
@@ -25,13 +25,13 @@ public:
vp1->X = 0;
vp1->Width = 640;
vp1->Height = 720 / 2;
new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
//new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2->X = vp1->Right();
vp2->Width = 640;
vp2->Height = 720 / 2;
new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
//new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
auto vpc = new Viewport(worldFrame, "ViewportFreeCam", m_World);
vpc->Y = 720 / 2;
+16 -7
View File
@@ -44,6 +44,10 @@ public:
{
EntityID entity = pair.first;
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if (templateComponent)
continue;
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform)
continue;
@@ -78,12 +82,11 @@ public:
float textureRepeat = blendmapComponent->TextureRepeats;
EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix);
EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix, modelComponent->Color);
}
else
{
float transparent = modelComponent->Transparent;
EnqueueModel(modelAsset, modelMatrix, transparent);
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color);
}
}
@@ -100,7 +103,7 @@ public:
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(textureAsset, modelMatrix);
EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color);
}
}
@@ -120,6 +123,8 @@ public:
);
}
}
RenderQueue.Sort();
}
protected:
@@ -152,7 +157,7 @@ private:
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent)
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color)
{
for (auto texGroup : model->TextureGroups)
{
@@ -166,6 +171,8 @@ private:
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
job.Transparent = transparent;
job.Color = color;
if(job.Transparent)
{
RenderQueue.Forward.Add(job);
@@ -177,7 +184,7 @@ private:
}
}
void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix)
void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix, glm::vec4 color)
{
for (auto texGroup : model->TextureGroups)
{
@@ -200,17 +207,19 @@ private:
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
job.Color = color;
RenderQueue.Deferred.Add(job);
}
}
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix)
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color)
{
SpriteJob job;
job.TextureID = texture->ResourceID;
job.Texture = *texture;
job.ModelMatrix = modelMatrix;
job.Color = color;
RenderQueue.Forward.Add(job);
}
+50 -46
View File
@@ -745,29 +745,31 @@ EntityID GameWorld::CreateTank(int playerID)
}
CommitEntity(wheel);
// auto entity = CreateEntity(tank);
// auto transformComponent = AddComponent<Components::Transform>(entity);
// transformComponent->Position = glm::vec3(2, -1.7, 2.0);
// transformComponent->Scale = glm::vec3(3, 3, 3);
// transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
// auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
// emitterComponent->SpawnCount = 2;
// emitterComponent->SpawnFrequency = 0.005;
// emitterComponent->SpreadAngle = glm::pi<float>();
// emitterComponent->UseGoalVelocity = false;
// emitterComponent->LifeTime = 0.5;
// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
// CommitEntity(entity);
//
// auto particleEntity = CreateEntity(entity);
// auto TEMP = AddComponent<Components::Transform>(particleEntity);
// TEMP->Scale = glm::vec3(0);
// auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
// emitterComponent->ParticleTemplate = particleEntity;
//
// CommitEntity(particleEntity);
auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(2, -1.7, 2.0);
transformComponent->Scale = glm::vec3(3, 3, 3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
{
auto particleEntity = CreateEntity(entity);
auto templateComponent = AddComponent<Components::Template>(particleEntity);
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
CommitEntity(particleEntity);
emitterComponent->ParticleTemplate = particleEntity;
}
}
{
@@ -830,29 +832,31 @@ EntityID GameWorld::CreateTank(int playerID)
CommitEntity(wheel);
#pragma endregion
// auto entity = CreateEntity(tank);
// auto transformComponent = AddComponent<Components::Transform>(entity);
// transformComponent->Position = glm::vec3(-2, -1.7, 2.0);
// transformComponent->Scale = glm::vec3(3, 3, 3);
// transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
// auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
// emitterComponent->SpawnCount = 2;
// emitterComponent->SpawnFrequency = 0.005;
// emitterComponent->SpreadAngle = glm::pi<float>();
// emitterComponent->UseGoalVelocity = false;
// emitterComponent->LifeTime = 0.5;
// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
// CommitEntity(entity);
//
// auto particleEntity = CreateEntity(entity);
// auto TEMP = AddComponent<Components::Transform>(particleEntity);
// TEMP->Scale = glm::vec3(0);
// auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
// emitterComponent->ParticleTemplate = particleEntity;
//
// CommitEntity(particleEntity);
auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(-2, -1.7, 2.0);
transformComponent->Scale = glm::vec3(3, 3, 3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
{
auto particleEntity = CreateEntity(entity);
auto templateComponent = AddComponent<Components::Template>(particleEntity);
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
CommitEntity(particleEntity);
emitterComponent->ParticleTemplate = particleEntity;
}
}
CommitEntity(tank);
+10
View File
@@ -83,6 +83,10 @@ public:
{
job.CalculateHash();
m_Jobs.push_front(std::shared_ptr<T>(new T(job)));
}
void Sort()
{
m_Jobs.sort();
}
@@ -115,6 +119,12 @@ struct RenderQueuePair
Deferred.Clear();
Forward.Clear();
}
void Sort()
{
Deferred.Sort();
Forward.Sort();
}
};
#endif // RenderQueue_h__
+9 -9
View File
@@ -490,7 +490,7 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(modelJob->Color));
glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glBindVertexArray(modelJob->VAO);
@@ -514,11 +514,14 @@ void Renderer::ForwardRendering(RenderQueue &rq)
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(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()));
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color));
glm::mat4 modelMatrix = spriteJob->ModelMatrix;
MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4(MVP)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4(modelMatrix)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4(m_Camera->ViewMatrix())));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4(cameraProjection)));
glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
@@ -557,8 +560,6 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
//for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender
//{
// Model* model;
@@ -589,7 +590,6 @@ void Renderer::Swap()
glfwSwapBuffers(m_Window);
}
void Renderer::DrawSkybox()
{
//glBindFramebuffer(GL_FRAMEBUFFER, 0);