Merge branch 'master' into DashEffect
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include "Core/PerformanceTimer.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
cpu_timer PerformanceTimer::m_Timer;
|
||||
std::map<std::string, cpu_timer> PerformanceTimer::timers;
|
||||
std::string PerformanceTimer::currentTimerRunning = "";
|
||||
@@ -74,3 +77,15 @@ void PerformanceTimer::CreateExcelData()
|
||||
}
|
||||
someFileStream.close();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void PerformanceTimer::StartTimer(std::string nameOfTimer) {};
|
||||
void PerformanceTimer::StartTimerAndStopPrevious(std::string nameOfTimer) {};
|
||||
void PerformanceTimer::StopTimer(std::string nameOfTimer) {};
|
||||
void PerformanceTimer::SetFrameNumber(int frameNumber) {};
|
||||
|
||||
void PerformanceTimer::ResetAllTimers() {};
|
||||
void PerformanceTimer::CreateExcelData() {};
|
||||
|
||||
#endif //DEBUG
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
#include "Core/TransformSystem.h"
|
||||
|
||||
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::PositionCache;
|
||||
std::unordered_map<EntityWrapper, glm::quat> TransformSystem::OrientationCache;
|
||||
std::unordered_map<EntityWrapper, glm::vec3> TransformSystem::ScaleCache;
|
||||
std::unordered_map<EntityWrapper, glm::mat4> TransformSystem::MatrixCache;
|
||||
|
||||
int TransformSystem::RecalculatedPositions = 0;
|
||||
int TransformSystem::RecalculatedOrientations = 0;
|
||||
int TransformSystem::RecalculatedScales = 0;
|
||||
|
||||
TransformSystem::TransformSystem(SystemParams params)
|
||||
: System(params)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &TransformSystem::OnEntityDeleted);
|
||||
}
|
||||
|
||||
bool TransformSystem::OnEntityDeleted(const Events::EntityDeleted& e)
|
||||
{
|
||||
// Clean up deleted entity
|
||||
PositionCache.erase(e.DeletedEntity);
|
||||
OrientationCache.erase(e.DeletedEntity);
|
||||
ScaleCache.erase(e.DeletedEntity);
|
||||
MatrixCache.erase(e.DeletedEntity);
|
||||
return true;
|
||||
}
|
||||
|
||||
//glm::mat4 Transform::AbsoluteTransformation(EntityWrapper entity)
|
||||
//{
|
||||
// glm::mat4 t = glm::mat4(1.f);
|
||||
//
|
||||
// while (entity.Valid()) {
|
||||
// t = glm::translate((const glm::vec3&)entity["Transform"]["Position"]) * glm::toMat4(glm::quat((const glm::vec3&)entity["Transform"]["Orientation"])) * glm::scale((const glm::vec3&)entity["Transform"]["Scale"]) * t;
|
||||
// entity = entity.Parent();
|
||||
// }
|
||||
//
|
||||
// return t;
|
||||
//}
|
||||
|
||||
glm::vec3 TransformSystem::AbsolutePosition(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsolutePosition(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsolutePosition(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::vec3();
|
||||
}
|
||||
|
||||
auto cacheIt = PositionCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformPosition = cTransform["Position"];
|
||||
if (cacheIt != PositionCache.end() && !cTransformPosition.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate position
|
||||
glm::vec3 position = AbsolutePosition(parent) + TransformSystem::AbsoluteOrientation(parent) * (TransformSystem::AbsoluteScale(parent) * (const glm::vec3&)cTransformPosition);
|
||||
// Cache it
|
||||
PositionCache[entity] = position;
|
||||
RecalculatedPositions++;
|
||||
// Unset dirty flag
|
||||
cTransformPosition.SetDirty(DirtySetType::Transform, false);
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteOrientationEuler(EntityWrapper entity)
|
||||
{
|
||||
glm::vec3 orientation;
|
||||
|
||||
while (entity.Valid()) {
|
||||
ComponentWrapper transform = entity["Transform"];
|
||||
orientation += (Field<glm::vec3>)transform["Orientation"];
|
||||
entity = entity.Parent();
|
||||
}
|
||||
|
||||
return orientation;
|
||||
}
|
||||
|
||||
glm::quat TransformSystem::AbsoluteOrientation(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsoluteOrientation(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::quat TransformSystem::AbsoluteOrientation(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::quat();
|
||||
}
|
||||
|
||||
auto cacheIt = OrientationCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformOrientation = cTransform["Orientation"];
|
||||
if (cacheIt != OrientationCache.end() && !cTransformOrientation.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate orientation
|
||||
glm::quat orientation = AbsoluteOrientation(parent) * glm::quat((const glm::vec3&)cTransformOrientation);
|
||||
// Cache it
|
||||
OrientationCache[entity] = orientation;
|
||||
RecalculatedOrientations++;
|
||||
// Unset dirty flag
|
||||
cTransformOrientation.SetDirty(DirtySetType::Transform, false);
|
||||
return orientation;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteScale(World* world, EntityID entity)
|
||||
{
|
||||
return TransformSystem::AbsoluteScale(EntityWrapper(world, entity));
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::AbsoluteScale(EntityWrapper entity)
|
||||
{
|
||||
if (!entity.Valid()) {
|
||||
return glm::vec3(1.f);
|
||||
}
|
||||
|
||||
auto cacheIt = ScaleCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
ComponentWrapper::SubscriptProxy cTransformScale = cTransform["Scale"];
|
||||
if (cacheIt != ScaleCache.end() && !cTransformScale.Dirty(DirtySetType::Transform)) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
EntityWrapper parent = entity.Parent();
|
||||
// Calculate scale
|
||||
glm::vec3 scale = AbsoluteScale(parent) * (const glm::vec3&)cTransformScale;
|
||||
// Cache it
|
||||
ScaleCache[entity] = scale;
|
||||
RecalculatedPositions++;
|
||||
// Unset dirty flag
|
||||
cTransformScale.SetDirty(DirtySetType::Transform, false);
|
||||
return scale;
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 TransformSystem::ModelMatrix(EntityID entityID, World* world)
|
||||
{
|
||||
return ModelMatrix(EntityWrapper(world, entityID));
|
||||
}
|
||||
|
||||
glm::mat4 TransformSystem::ModelMatrix(EntityWrapper entity)
|
||||
{
|
||||
auto cacheIt = MatrixCache.find(entity);
|
||||
ComponentWrapper cTransform = entity["Transform"];
|
||||
bool isDirty = cTransform["Position"].Dirty(DirtySetType::Transform) || cTransform["Orientation"].Dirty(DirtySetType::Transform) || cTransform["Scale"].Dirty(DirtySetType::Transform);
|
||||
if (cacheIt != MatrixCache.end() && !isDirty) {
|
||||
return cacheIt->second;
|
||||
} else {
|
||||
glm::mat4 matrix = glm::translate(AbsolutePosition(entity)) * glm::toMat4(AbsoluteOrientation(entity)) * glm::scale(AbsoluteScale(entity));
|
||||
MatrixCache[entity] = matrix;
|
||||
return matrix;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 TransformSystem::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
|
||||
{
|
||||
return glm::vec3(matrix * glm::vec4(point.x, point.y, point.z, 1));
|
||||
}
|
||||
@@ -108,7 +108,15 @@ void Client::Update(double dt)
|
||||
|
||||
hasServerTimedOut();
|
||||
}
|
||||
//Network::Update();
|
||||
|
||||
if (ImGui::BeginPopupModal("Disconnected", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::Text("You have been disconnected from server.\n\n");
|
||||
ImGui::SetCursorPosX(ImGui::GetContentRegionAvailWidth() - 120);
|
||||
if (ImGui::Button("OK", ImVec2(120, 0))) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void Client::parseMessageType(Packet& packet)
|
||||
@@ -199,7 +207,7 @@ void Client::parseTCPConnect(Packet& packet)
|
||||
packet.WritePrimitive(m_PlayerID);
|
||||
m_Unreliable.Send(packet);
|
||||
|
||||
// LOG_INFO("Sent UDP Connect Server");
|
||||
// LOG_INFO("Sent UDP Connect Server");
|
||||
}
|
||||
|
||||
void Client::parsePlayerConnected(Packet & packet)
|
||||
@@ -695,6 +703,7 @@ void Client::hasServerTimedOut()
|
||||
if (timeSincePing > m_TimeoutMs) {
|
||||
// Clear everything and go to menu.
|
||||
LOG_INFO("Server has timed out, returning to menu, Beep Boop.");
|
||||
ImGui::OpenPopup("Disconnected");
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ void BlurHUD::InitializeBuffers()
|
||||
}
|
||||
m_GaussianFrameBuffer_horiz.Generate();
|
||||
|
||||
CommonFunctions::GenerateTexture(&m_DepthStencil_vert, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||
res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
|
||||
//CommonFunctions::GenerateTexture(&m_DepthStencil_vert, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||
// res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
|
||||
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_NEAREST,
|
||||
res2, GL_RGBA16F, GL_RGBA, GL_FLOAT);
|
||||
|
||||
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
|
||||
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_vert, GL_DEPTH_STENCIL_ATTACHMENT)));
|
||||
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_horiz, GL_DEPTH_STENCIL_ATTACHMENT)));
|
||||
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_GaussianFrameBuffer_vert.Generate();
|
||||
@@ -260,22 +260,22 @@ void BlurHUD::FillStencil(RenderScene& scene)
|
||||
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
|
||||
}
|
||||
|
||||
state.BindFramebuffer(m_GaussianFrameBuffer_vert.GetHandle());
|
||||
for (auto& job : scene.Jobs.SpriteJob) {
|
||||
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
|
||||
if (!spriteJob) {
|
||||
continue;
|
||||
}
|
||||
if(!spriteJob->BlurBackground) {
|
||||
continue;
|
||||
}
|
||||
glm::mat4 MVP = VP * spriteJob->Matrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
//state.BindFramebuffer(m_GaussianFrameBuffer_vert.GetHandle());
|
||||
//for (auto& job : scene.Jobs.SpriteJob) {
|
||||
// auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
|
||||
// if (!spriteJob) {
|
||||
// continue;
|
||||
// }
|
||||
// if(!spriteJob->BlurBackground) {
|
||||
// continue;
|
||||
// }
|
||||
// glm::mat4 MVP = VP * spriteJob->Matrix;
|
||||
// glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
|
||||
glBindVertexArray(spriteJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
|
||||
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
|
||||
}
|
||||
// glBindVertexArray(spriteJob->Model->VAO);
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
|
||||
// glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
|
||||
//}
|
||||
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,12 +76,12 @@ void DrawBloomPass::InitializeShaderPrograms()
|
||||
void DrawBloomPass::InitializeBuffers()
|
||||
{
|
||||
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);
|
||||
&m_GaussianTexture_horiz, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height),
|
||||
GL_RGB16F, GL_RGB, GL_FLOAT, m_BloomLod, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST);
|
||||
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);
|
||||
&m_GaussianTexture_vert, GL_CLAMP_TO_BORDER, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height),
|
||||
GL_RGB16F, GL_RGB, GL_FLOAT, m_BloomLod, GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST);
|
||||
CommonFunctions::GenerateTexture(&m_FinalGaussianTexture, GL_CLAMP_TO_BORDER, GL_NEAREST, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
|
||||
if (m_GaussianCombineBuffer.GetHandle() == 0) {
|
||||
m_GaussianCombineBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_FinalGaussianTexture, GL_COLOR_ATTACHMENT0)));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Rendering/DrawFinalPass.h"
|
||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass)
|
||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, ShadowPass* shadowPass, ConfigFile* config)
|
||||
: m_Renderer(renderer)
|
||||
, m_LightCullingPass(lightCullingPass)
|
||||
, m_CubeMapPass(cubeMapPass)
|
||||
@@ -8,6 +8,11 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
|
||||
{
|
||||
//TODO: Make sure that uniforms are not sent into shader if not needed.
|
||||
m_ShieldPixelRate = 8;
|
||||
m_FinalPassFrameBuffer = new FrameBuffer();
|
||||
m_ShieldDepthFrameBuffer = new FrameBuffer();
|
||||
|
||||
setMSAA(config->Get<int>("MSAA.Level", 0));
|
||||
|
||||
InitializeTextures();
|
||||
InitializeShaderPrograms();
|
||||
InitializeFrameBuffers();
|
||||
@@ -19,6 +24,9 @@ DrawFinalPass::~DrawFinalPass(){
|
||||
CommonFunctions::DeleteTexture(&m_DepthBuffer);
|
||||
CommonFunctions::DeleteTexture(&m_ShieldBuffer);
|
||||
CommonFunctions::DeleteTexture(&m_CubeMapTexture);
|
||||
|
||||
delete m_FinalPassFrameBuffer;
|
||||
delete m_ShieldDepthFrameBuffer;
|
||||
}
|
||||
|
||||
void DrawFinalPass::InitializeTextures()
|
||||
@@ -32,26 +40,88 @@ void DrawFinalPass::InitializeTextures()
|
||||
|
||||
void DrawFinalPass::InitializeFrameBuffers()
|
||||
{
|
||||
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_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);
|
||||
if (m_MSAA) {
|
||||
CommonFunctions::GenerateTexture(&m_AntiAliasedTexture, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
|
||||
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);
|
||||
if (m_AntiAliasedFrameBuffer == nullptr) {
|
||||
m_AntiAliasedFrameBuffer = new FrameBuffer();
|
||||
m_AntiAliasedFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_AntiAliasedTexture, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_AntiAliasedFrameBuffer->Generate();
|
||||
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT)));
|
||||
//m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_StencilTexture, GL_STENCIL_ATTACHMENT)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
m_FinalPassFrameBuffer.Generate();
|
||||
GLERROR("FBO generation");
|
||||
if (m_SceneTexture != 0) {
|
||||
glDeleteRenderbuffers(1, &m_SceneTexture);
|
||||
}
|
||||
glGenRenderbuffers(1, &m_SceneTexture);
|
||||
GLERROR("FBO 1");
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_SceneTexture);
|
||||
GLERROR("FBO 11");
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
GLERROR("FBO 111");
|
||||
|
||||
if (m_BloomTexture != 0) {
|
||||
glDeleteRenderbuffers(1, &m_BloomTexture);
|
||||
}
|
||||
glGenRenderbuffers(1, &m_BloomTexture);
|
||||
GLERROR("FBO 2");
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_BloomTexture);
|
||||
GLERROR("FBO 22");
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
GLERROR("FBO 222");
|
||||
|
||||
if (m_DepthBuffer != 0) {
|
||||
glDeleteRenderbuffers(1, &m_DepthBuffer);
|
||||
}
|
||||
glGenRenderbuffers(1, &m_DepthBuffer);
|
||||
GLERROR("FBO 3");
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||
GLERROR("FBO 33");
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_DEPTH24_STENCIL8, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
GLERROR("FBO 333");
|
||||
|
||||
//CommonFunctions::GenerateMultiSampleTexture(&m_SceneTexture, m_MSAA, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F);
|
||||
//CommonFunctions::GenerateMultiSampleTexture(&m_BloomTexture, m_MSAA, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F);
|
||||
|
||||
//CommonFunctions::GenerateMultiSampleTexture(&m_DepthBuffer, m_MSAA,
|
||||
//glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8);
|
||||
|
||||
//CommonFunctions::GenerateMultiSampleTexture(&m_ShieldBuffer, m_MSAA,
|
||||
//glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32F);
|
||||
} else {
|
||||
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_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);
|
||||
|
||||
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_ShieldBuffer, 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);
|
||||
m_ShieldDepthFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_ShieldBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
m_ShieldDepthFrameBuffer.Generate();
|
||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT);
|
||||
|
||||
if (m_FinalPassFrameBuffer->GetHandle() == 0) {
|
||||
if (m_MSAA) {
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT)));
|
||||
//m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_StencilTexture, GL_STENCIL_ATTACHMENT)));
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
} else {
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT)));
|
||||
//m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_StencilTexture, GL_STENCIL_ATTACHMENT)));
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
}
|
||||
}
|
||||
m_FinalPassFrameBuffer->Generate();
|
||||
GLERROR("FBO generation");
|
||||
|
||||
if (m_ShieldDepthFrameBuffer->GetHandle() == 0) {
|
||||
m_ShieldDepthFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_ShieldBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
}
|
||||
m_ShieldDepthFrameBuffer->Generate();
|
||||
}
|
||||
|
||||
void DrawFinalPass::InitializeShaderPrograms()
|
||||
@@ -245,14 +315,14 @@ void DrawFinalPass::InitializeShaderPrograms()
|
||||
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
||||
{
|
||||
GLERROR("Pre");
|
||||
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
|
||||
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer->GetHandle());
|
||||
//Draw shields to stencil
|
||||
DrawToDepthStencilBuffer(scene.Jobs.ShieldObjects, scene);
|
||||
GLERROR("StencilPass");
|
||||
delete stateDethp;
|
||||
|
||||
|
||||
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
||||
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
|
||||
if (scene.ClearDepth) {
|
||||
//glClear(GL_DEPTH_BUFFER_BIT);
|
||||
state->Disable(GL_DEPTH_TEST);
|
||||
@@ -293,17 +363,22 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
||||
delete state;
|
||||
if (scene.ShouldBlur) {
|
||||
//This needs to be drawn only when the full scene is being renderd, and then let be, otherwise sprite and other shit will show on it.
|
||||
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
|
||||
GLuint sceneTexture = SceneTexture();
|
||||
m_FullBlurredTexture = blurHUDPass->Draw(sceneTexture, scene);
|
||||
}
|
||||
|
||||
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
||||
DrawFinalPassState* stateSprite;
|
||||
if(scene.ShouldBlur) {
|
||||
//Combine nonblur and blur texture
|
||||
stateSprite->Disable(GL_DEPTH_TEST);
|
||||
stateSprite->Disable(GL_STENCIL_TEST);
|
||||
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
|
||||
GLuint sceneTexture = SceneTexture();
|
||||
stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
|
||||
stateSprite->Disable(GL_DEPTH_TEST);
|
||||
stateSprite->Disable(GL_STENCIL_TEST);
|
||||
m_CombinedTexture = blurHUDPass->CombineTextures(sceneTexture, m_FullBlurredTexture);
|
||||
|
||||
}
|
||||
} else {
|
||||
stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
|
||||
}
|
||||
//Draw Transparen objects
|
||||
//state->BlendFunc(GL_ONE, GL_ONE);
|
||||
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
|
||||
@@ -325,33 +400,67 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
||||
void DrawFinalPass::ClearBuffer()
|
||||
{
|
||||
GLERROR("PRE");
|
||||
m_ShieldDepthFrameBuffer.Bind();
|
||||
m_ShieldDepthFrameBuffer->Bind();
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
m_ShieldDepthFrameBuffer.Unbind();
|
||||
m_FinalPassFrameBuffer.Bind();
|
||||
m_ShieldDepthFrameBuffer->Unbind();
|
||||
m_FinalPassFrameBuffer->Bind();
|
||||
GLERROR("Bind HighRes");
|
||||
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
GLERROR("ViewPort,Scissor LowRes");
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_FinalPassFrameBuffer.Unbind();
|
||||
m_FinalPassFrameBuffer->Unbind();
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
|
||||
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_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();
|
||||
if (m_FinalPassFrameBuffer->MultiSampling() != (bool)m_MSAA) {
|
||||
delete m_FinalPassFrameBuffer;
|
||||
delete m_ShieldDepthFrameBuffer;
|
||||
m_FinalPassFrameBuffer = new FrameBuffer();
|
||||
m_ShieldDepthFrameBuffer = new FrameBuffer();
|
||||
}
|
||||
|
||||
if (m_MSAA) {
|
||||
if (m_AntiAliasedFrameBuffer != nullptr) {
|
||||
delete m_AntiAliasedFrameBuffer;
|
||||
m_AntiAliasedFrameBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
InitializeFrameBuffers();
|
||||
GLERROR("Error changing texture resolutions");
|
||||
}
|
||||
|
||||
void DrawFinalPass::setMSAA(unsigned int numberOfSamples) {
|
||||
if (m_MSAA == numberOfSamples) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(bool)numberOfSamples) {
|
||||
if (m_AntiAliasedFrameBuffer != nullptr) {
|
||||
delete m_AntiAliasedFrameBuffer;
|
||||
m_AntiAliasedFrameBuffer = nullptr;
|
||||
}
|
||||
delete m_FinalPassFrameBuffer;
|
||||
m_FinalPassFrameBuffer = new FrameBuffer();
|
||||
}
|
||||
|
||||
if ((bool)numberOfSamples && !(bool)m_MSAA) {
|
||||
delete m_FinalPassFrameBuffer;
|
||||
m_FinalPassFrameBuffer = new FrameBuffer();
|
||||
}
|
||||
|
||||
m_MSAA = numberOfSamples;
|
||||
|
||||
InitializeFrameBuffers();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene)
|
||||
{
|
||||
GLuint forwardHandle = m_ForwardPlusProgram->GetHandle();
|
||||
@@ -1215,11 +1324,6 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
|
||||
if (lastShader != m_FillDepthStencilBufferSkinnedProgram->GetHandle()) {
|
||||
m_FillDepthStencilBufferSkinnedProgram->Bind();
|
||||
lastShader = m_FillDepthStencilBufferSkinnedProgram->GetHandle();
|
||||
glUniform1i(glGetUniformLocation(shaderSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2f(glGetUniformLocation(shaderSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
glUniform4fv(glGetUniformLocation(shaderSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
|
||||
GLERROR("Bind Uniforms 1");
|
||||
}
|
||||
|
||||
@@ -1238,11 +1342,6 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
|
||||
if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) {
|
||||
m_FillDepthStencilBufferProgram->Bind();
|
||||
lastShader = m_FillDepthStencilBufferProgram->GetHandle();
|
||||
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
|
||||
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()));
|
||||
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
|
||||
GLERROR("Bind Uniforms 2");
|
||||
}
|
||||
|
||||
@@ -1298,7 +1397,14 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
if (spriteJob->ClampToBorder) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
}
|
||||
else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
#include "Rendering/FrameBuffer.h"
|
||||
|
||||
|
||||
BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod)
|
||||
BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod, bool multiSampling)
|
||||
{
|
||||
m_ResourceHandle = resourceHandle;
|
||||
m_ResourceType = resourceType;
|
||||
m_Attachment = attachment;
|
||||
m_MipMapLod = mipMapLod;
|
||||
m_MultiSampling = multiSampling;
|
||||
}
|
||||
|
||||
Texture2D::~Texture2D()
|
||||
@@ -15,14 +16,23 @@ Texture2D::~Texture2D()
|
||||
if (m_ResourceHandle != 0) {
|
||||
glDeleteTextures(1, m_ResourceHandle);
|
||||
}
|
||||
*m_ResourceHandle = 0;
|
||||
}
|
||||
|
||||
Texture2DMultiSample::~Texture2DMultiSample()
|
||||
{
|
||||
if (m_ResourceHandle != 0) {
|
||||
glDeleteTextures(1, m_ResourceHandle);
|
||||
}
|
||||
*m_ResourceHandle = 0;
|
||||
}
|
||||
|
||||
RenderBuffer::~RenderBuffer()
|
||||
{
|
||||
if (m_ResourceHandle != 0) {
|
||||
glDeleteRenderbuffers(1, m_ResourceHandle);
|
||||
}
|
||||
*m_ResourceHandle = 0;
|
||||
}
|
||||
|
||||
Texture2DArray::~Texture2DArray()
|
||||
@@ -30,6 +40,7 @@ Texture2DArray::~Texture2DArray()
|
||||
if (m_ResourceHandle != 0) {
|
||||
glDeleteTextures(1, m_ResourceHandle);
|
||||
}
|
||||
*m_ResourceHandle = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +53,14 @@ FrameBuffer::~FrameBuffer()
|
||||
|
||||
void FrameBuffer::AddResource(std::shared_ptr<BufferResource> resource)
|
||||
{
|
||||
//m_MultiSampling is true when initialized
|
||||
if (m_MultiSampling != resource->m_MultiSampling) {
|
||||
if (m_MultiSampling == false) {
|
||||
GLERROR("All renderbuffers is/is not using multisampling");
|
||||
} else {
|
||||
m_MultiSampling = false;
|
||||
}
|
||||
}
|
||||
m_Resources.push_back(resource);
|
||||
}
|
||||
|
||||
@@ -55,20 +74,23 @@ void FrameBuffer::Generate()
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_BufferHandle);
|
||||
GLERROR("1");
|
||||
|
||||
for (auto it = m_Resources.begin(); it != m_Resources.end(); it++) {
|
||||
switch ((*it)->m_ResourceType) {
|
||||
case GL_TEXTURE_2D_MULTISAMPLE:
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, GL_TEXTURE_2D_MULTISAMPLE, 0, 0);
|
||||
GLERROR("FrameBuffer generate: GL_TEXTURE_2D_MULTISAMPLE");
|
||||
break;
|
||||
case GL_TEXTURE_2D:
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, (*it)->m_MipMapLod);
|
||||
GLERROR("FrameBuffer generate: glFramebufferTexture2D");
|
||||
GLERROR("FrameBuffer generate: GL_TEXTURE_2D");
|
||||
break;
|
||||
case GL_RENDERBUFFER:
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle);
|
||||
GLERROR("FrameBuffer generate: glFramebufferRenderbuffer");
|
||||
GLERROR("FrameBuffer generate: GL_RENDERBUFFER");
|
||||
break;
|
||||
case GL_TEXTURE_2D_ARRAY:
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0);
|
||||
GLERROR("FrameBuffer generate: glFramebufferTexture2DArray");
|
||||
GLERROR("FrameBuffer generate: GL_TEXTURE_2D_ARRAY");
|
||||
break;
|
||||
}
|
||||
GLERROR("2");
|
||||
@@ -77,8 +99,8 @@ void FrameBuffer::Generate()
|
||||
attachments.push_back((*it)->m_Attachment);
|
||||
}
|
||||
GLERROR("Attachment");
|
||||
|
||||
}
|
||||
|
||||
GLERROR("3");
|
||||
|
||||
GLenum* bufferTextures = attachments.data();
|
||||
@@ -89,7 +111,7 @@ void FrameBuffer::Generate()
|
||||
|
||||
if (GLenum frameBufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
GLERROR("Framebuffer incomplete");
|
||||
//LOG_ERROR("FrameBuffer incomplete: 0x%x\n", frameBufferStatus);
|
||||
LOG_ERROR("FrameBuffer incomplete: 0x%x\n", glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
GLERROR("END");
|
||||
@@ -110,3 +132,11 @@ GLuint FrameBuffer::GetHandle()
|
||||
{
|
||||
return m_BufferHandle;
|
||||
}
|
||||
|
||||
void FrameBuffer::Read() {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_BufferHandle);
|
||||
}
|
||||
|
||||
void FrameBuffer::Draw() {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_BufferHandle);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,11 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
|
||||
if (modelJob) {
|
||||
if(modelJob->NotPickable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
int pickColor[2] = { m_ColorCounter[0], m_ColorCounter[1] };
|
||||
|
||||
PickingInfo pickInfo;
|
||||
|
||||
@@ -362,6 +362,11 @@ void RenderSystem::fillPointLights(std::list<std::shared_ptr<RenderJob>>& jobs,
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityWrapper entity(world, pointlightC.EntityID);
|
||||
if (!isEntityVisible(entity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::shared_ptr<PointLightJob> pointLightJob = std::shared_ptr<PointLightJob>(new PointLightJob(transformC, pointlightC, m_World));
|
||||
jobs.push_back(pointLightJob);
|
||||
}
|
||||
|
||||
@@ -67,10 +67,19 @@ void Renderer::InitializeWindow()
|
||||
// Create a window
|
||||
GLFWmonitor* monitor = nullptr;
|
||||
if (m_Fullscreen) {
|
||||
monitor = glfwGetPrimaryMonitor();
|
||||
//monitor = glfwGetPrimaryMonitor();
|
||||
//const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||
|
||||
//glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
||||
//glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
||||
//glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
||||
//glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
|
||||
glfwWindowHint(GLFW_DECORATED, false);
|
||||
glfwWindowHint(GLFW_AUTO_ICONIFY, false);
|
||||
}
|
||||
//glfwWindowHint(GLFW_SAMPLES, 8);
|
||||
m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height, "daydream", monitor, nullptr);
|
||||
|
||||
//glfwWindowHint(GLFW_SAMPLES, 8);
|
||||
m_Window = glfwCreateWindow(m_Resolution.Width, m_Resolution.Height + 1, "daydream", monitor, nullptr);
|
||||
if (!m_Window) {
|
||||
LOG_ERROR("GLFW: Failed to create window");
|
||||
exit(EXIT_FAILURE);
|
||||
@@ -168,8 +177,10 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
|
||||
ImGui::SliderInt("SSAO Quality", &m_SSAO_Quality, 0, 3);
|
||||
ImGui::SliderInt("Glow Quality", &m_GLOW_Quality, 0, 3);
|
||||
ImGui::SliderInt("MSAA Level", (int*)&m_MSAA_Level, 0, 16);
|
||||
m_SSAOPass->ChangeQuality(m_SSAO_Quality);
|
||||
m_DrawBloomPass->ChangeQuality(m_GLOW_Quality);
|
||||
m_DrawFinalPass->setMSAA(m_MSAA_Level);
|
||||
GLERROR("SSAO Settings");
|
||||
//clear buffer 0
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
@@ -228,7 +239,8 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
|
||||
if (m_DebugTextureToDraw == 0) {
|
||||
PerformanceTimer::StartTimer("Renderer-Color Correction Pass");
|
||||
m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture(), frame.Gamma, frame.Exposure);
|
||||
GLuint test = m_DrawFinalPass->SceneTexture();
|
||||
m_DrawColorCorrectionPass->Draw(test, m_DrawBloomPass->GaussianTexture(), frame.Gamma, frame.Exposure);
|
||||
PerformanceTimer::StopTimer("Renderer-Color Correction Pass");
|
||||
}
|
||||
|
||||
@@ -307,7 +319,7 @@ void Renderer::InitializeRenderPasses()
|
||||
m_SSAOPass = new SSAOPass(this, m_Config);
|
||||
m_ShadowPass = new ShadowPass(this);
|
||||
m_BlurHUDPass = new BlurHUD(this);
|
||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_ShadowPass);
|
||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_ShadowPass, m_Config);
|
||||
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
|
||||
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
|
||||
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
|
||||
|
||||
@@ -226,8 +226,8 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_DepthMap, 0, i);
|
||||
|
||||
|
||||
GLuint shaderHandle;
|
||||
|
||||
GLuint shaderHandle = 0;
|
||||
GLuint lastModel = 0;
|
||||
for (auto &job : scene.Jobs.DirectionalLight) {
|
||||
|
||||
auto directionalLightJob = std::dynamic_pointer_cast<DirectionalLightJob>(job);
|
||||
@@ -240,19 +240,6 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
//RadiusToLightspace(m_shadowFrusta[i]);
|
||||
m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]);
|
||||
|
||||
|
||||
m_ShadowProgram->Bind();
|
||||
shaderHandle = m_ShadowProgram->GetHandle();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i]));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i]));
|
||||
|
||||
m_ShadowProgramSkinned->Bind();
|
||||
shaderHandle = m_ShadowProgramSkinned->GetHandle();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i]));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_LightView[i]));
|
||||
|
||||
|
||||
|
||||
GLERROR("ShadowLight ERROR");
|
||||
|
||||
for (auto &objectJob : scene.Jobs.OpaqueObjects) {
|
||||
@@ -264,8 +251,10 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
}
|
||||
|
||||
if(modelJob->Model->IsSkinned()) {
|
||||
m_ShadowProgramSkinned->Bind();
|
||||
shaderHandle = m_ShadowProgramSkinned->GetHandle();
|
||||
if (shaderHandle != m_ShadowProgramSkinned->GetHandle()) {
|
||||
m_ShadowProgramSkinned->Bind();
|
||||
shaderHandle = m_ShadowProgramSkinned->GetHandle();
|
||||
}
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
@@ -276,15 +265,19 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
} else {
|
||||
m_ShadowProgram->Bind();
|
||||
shaderHandle = m_ShadowProgram->GetHandle();
|
||||
if (shaderHandle != m_ShadowProgram->GetHandle()) {
|
||||
m_ShadowProgram->Bind();
|
||||
shaderHandle = m_ShadowProgram->GetHandle();
|
||||
}
|
||||
}
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i] * m_LightView[i] * modelJob->Matrix));
|
||||
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), 1.f);
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
if (lastModel != modelJob->ModelID) {
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
}
|
||||
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
|
||||
|
||||
GLERROR("Shadow Draw ERROR");
|
||||
@@ -301,8 +294,10 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
}
|
||||
|
||||
if (modelJob->Model->IsSkinned()) {
|
||||
m_ShadowProgramSkinned->Bind();
|
||||
shaderHandle = m_ShadowProgramSkinned->GetHandle();
|
||||
if (shaderHandle != m_ShadowProgramSkinned->GetHandle()) {
|
||||
m_ShadowProgramSkinned->Bind();
|
||||
shaderHandle = m_ShadowProgramSkinned->GetHandle();
|
||||
}
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
@@ -313,11 +308,13 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
} else {
|
||||
m_ShadowProgram->Bind();
|
||||
shaderHandle = m_ShadowProgram->GetHandle();
|
||||
if (shaderHandle != m_ShadowProgram->GetHandle()) {
|
||||
m_ShadowProgram->Bind();
|
||||
shaderHandle = m_ShadowProgram->GetHandle();
|
||||
}
|
||||
}
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i] * m_LightView[i] * modelJob->Matrix));
|
||||
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a);
|
||||
|
||||
if (m_TexturedShadows) {
|
||||
@@ -345,9 +342,10 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
if (lastModel != modelJob->ModelID) {
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
}
|
||||
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
|
||||
|
||||
GLERROR("Shadow Draw ERROR");
|
||||
|
||||
@@ -33,33 +33,33 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim
|
||||
PoseData poseData;
|
||||
|
||||
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
|
||||
std::vector<Animation::Keyframe> boneKeyFrames = animation->JointAnimations.at(bone->ID);
|
||||
const std::vector<Animation::Keyframe>& boneKeyFrames = animation->JointAnimations.at(bone->ID);
|
||||
|
||||
Animation::Keyframe currentFrame;
|
||||
Animation::Keyframe nextFrame;
|
||||
const Animation::Keyframe* currentFrame;
|
||||
const Animation::Keyframe* nextFrame;
|
||||
|
||||
if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone
|
||||
for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame
|
||||
if (time >= boneKeyFrames.at(index).Time) {
|
||||
currentFrame = boneKeyFrames.at(index);
|
||||
nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size());
|
||||
currentFrame = &boneKeyFrames.at(index);
|
||||
nextFrame = &boneKeyFrames.at((index + 1) % boneKeyFrames.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float progress;
|
||||
|
||||
if (nextFrame.Index == 0) {
|
||||
if (nextFrame->Index == 0) {
|
||||
nextFrame = currentFrame;
|
||||
progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time);
|
||||
progress = (time - currentFrame->Time) / (animation->Duration - currentFrame->Time);
|
||||
} else {
|
||||
progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
|
||||
progress = (time - currentFrame->Time) / (nextFrame->Time - currentFrame->Time);
|
||||
|
||||
}
|
||||
|
||||
progress = glm::clamp(progress, 0.0f, 1.0f);
|
||||
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
|
||||
Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties;
|
||||
const Animation::Keyframe::BoneProperty& currentBoneProperty = currentFrame->BoneProperties;
|
||||
const Animation::Keyframe::BoneProperty& nextBoneProperty = nextFrame->BoneProperties;
|
||||
|
||||
glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress;
|
||||
glm::quat rotation = glm::normalize(glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress));
|
||||
@@ -77,10 +77,10 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim
|
||||
boneMatrices[bone->ID] = poseData;
|
||||
|
||||
} else { // 1 keyframes for the current bone
|
||||
currentFrame = boneKeyFrames.at(0);
|
||||
poseData.Translation = currentFrame.BoneProperties.Position;
|
||||
poseData.Orientation = currentFrame.BoneProperties.Rotation;
|
||||
poseData.Scale = currentFrame.BoneProperties.Scale;
|
||||
currentFrame = &boneKeyFrames.at(0);
|
||||
poseData.Translation = currentFrame->BoneProperties.Position;
|
||||
poseData.Orientation = currentFrame->BoneProperties.Rotation;
|
||||
poseData.Scale = currentFrame->BoneProperties.Scale;
|
||||
boneMatrices[bone->ID] = poseData;
|
||||
}
|
||||
}
|
||||
@@ -117,33 +117,33 @@ Skeleton::PoseData Skeleton::GetAdditiveBonePose(const Bone* bone, const Animati
|
||||
glm::vec3 scale = glm::vec3(1);
|
||||
|
||||
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
|
||||
std::vector<Animation::Keyframe> boneKeyFrames = animation->JointAnimations.at(bone->ID);
|
||||
const std::vector<Animation::Keyframe>& boneKeyFrames = animation->JointAnimations.at(bone->ID);
|
||||
|
||||
Animation::Keyframe currentFrame;
|
||||
Animation::Keyframe nextFrame;
|
||||
const Animation::Keyframe* currentFrame;
|
||||
const Animation::Keyframe* nextFrame;
|
||||
|
||||
if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone
|
||||
for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame
|
||||
if (time >= boneKeyFrames.at(index).Time) {
|
||||
currentFrame = boneKeyFrames.at(index);
|
||||
nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size());
|
||||
currentFrame = &boneKeyFrames.at(index);
|
||||
nextFrame = &boneKeyFrames.at((index + 1) % boneKeyFrames.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float progress;
|
||||
|
||||
if (nextFrame.Index == 0) {
|
||||
if (nextFrame->Index == 0) {
|
||||
nextFrame = currentFrame;
|
||||
progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time);
|
||||
progress = (time - currentFrame->Time) / (animation->Duration - currentFrame->Time);
|
||||
} else {
|
||||
progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
|
||||
progress = (time - currentFrame->Time) / (nextFrame->Time - currentFrame->Time);
|
||||
}
|
||||
|
||||
progress = glm::clamp(progress, 0.0f, 1.0f);
|
||||
|
||||
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
|
||||
Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties;
|
||||
const Animation::Keyframe::BoneProperty& currentBoneProperty = currentFrame->BoneProperties;
|
||||
const Animation::Keyframe::BoneProperty& nextBoneProperty = nextFrame->BoneProperties;
|
||||
|
||||
position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress;
|
||||
rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress);
|
||||
@@ -151,10 +151,10 @@ Skeleton::PoseData Skeleton::GetAdditiveBonePose(const Bone* bone, const Animati
|
||||
|
||||
|
||||
} else { // 1 keyframes for the current bone
|
||||
currentFrame = boneKeyFrames.at(0);
|
||||
position = currentFrame.BoneProperties.Position;
|
||||
rotation = currentFrame.BoneProperties.Rotation;
|
||||
scale = currentFrame.BoneProperties.Scale;
|
||||
currentFrame = &boneKeyFrames.at(0);
|
||||
position = currentFrame->BoneProperties.Position;
|
||||
rotation = currentFrame->BoneProperties.Rotation;
|
||||
scale = currentFrame->BoneProperties.Scale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,10 +270,10 @@ void Skeleton::AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, std::
|
||||
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
|
||||
} else {
|
||||
if (bone->Parent) {
|
||||
boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix);
|
||||
boneMatrix = parentMatrix * bone->BindTransformMatrix * bone->Parent->OffsetMatrix;
|
||||
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
|
||||
} else {
|
||||
boneMatrix = glm::inverse(bone->OffsetMatrix);
|
||||
boneMatrix = bone->BindTransformMatrix;
|
||||
boneMatrices[bone->ID] = parentMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,25 +17,26 @@ void CommonFunctions::GenerateMultiSampleTexture(GLuint* texture, int numSamples
|
||||
{
|
||||
glDeleteTextures(1, texture);
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, *texture);
|
||||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, internalFormat, dimensions.x, dimensions.y, false);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
GLERROR("Texture initialization failed 1");
|
||||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, internalFormat, dimensions.x, dimensions.y, GL_FALSE);
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
|
||||
void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps)
|
||||
void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type, GLint numMipMaps, GLint MAGFilter, GLint MINFilter)
|
||||
{
|
||||
glDeleteTextures(1, texture);
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexStorage2D(GL_TEXTURE_2D, numMipMaps, GL_RGBA8, dimensions.x, dimensions.y);
|
||||
glTexStorage2D(GL_TEXTURE_2D, numMipMaps, internalFormat, dimensions.x, dimensions.y);
|
||||
//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);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, MAGFilter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MINFilter);
|
||||
GLERROR("MipMap Texture initialization failed");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
|
||||
|
||||
Events::ChangeBGM e;
|
||||
e.FilePath = "Audio/bgm/MenuMusic.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &SoundManager::OnSetCamera);
|
||||
}
|
||||
|
||||
SoundManager::~SoundManager()
|
||||
@@ -67,8 +64,7 @@ void SoundManager::Update(double dt)
|
||||
deleteInactiveEmitters();
|
||||
updateEmitters(dt);
|
||||
updateListener(dt);
|
||||
if (m_DrumLoopHasBeenStarted)
|
||||
matchBGMLoop();
|
||||
matchBGMLoop();
|
||||
}
|
||||
|
||||
void SoundManager::deleteInactiveEmitters()
|
||||
@@ -363,15 +359,6 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e)
|
||||
{
|
||||
if (e.PlayerID == -1) { // Local player
|
||||
m_LocalPlayer = e.Player;
|
||||
if (m_DrumLoopHasBeenStarted) {
|
||||
return true;
|
||||
}
|
||||
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
|
||||
m_CurrentBGMCombo->Type = SoundType::BGM;
|
||||
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
|
||||
setGain(m_CurrentBGMCombo, 0);
|
||||
playSound(m_CurrentBGMCombo);
|
||||
m_DrumLoopHasBeenStarted = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -394,7 +381,9 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
|
||||
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
|
||||
{
|
||||
if (m_CurrentBGM != nullptr) {
|
||||
stopSound(m_CurrentBGM);
|
||||
if (getSourceState(m_CurrentBGM->ALsource) == AL_PLAYING) {
|
||||
stopSound(m_CurrentBGM);
|
||||
}
|
||||
}
|
||||
m_CurrentBGM = createSource(e.FilePath);
|
||||
m_CurrentBGM->Type = SoundType::BGM;
|
||||
@@ -403,6 +392,34 @@ bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoundManager::OnSetCamera(const Events::SetCamera& e)
|
||||
{
|
||||
if (e.CameraEntity.Name() == "Overview_Camera_Start_Menu") {
|
||||
if (m_CurrentBGMCombo != nullptr) {
|
||||
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
|
||||
stopSound(m_CurrentBGMCombo);
|
||||
}
|
||||
}
|
||||
Events::ChangeBGM changeBGM;
|
||||
changeBGM.FilePath = "Audio/BGM/MenuMusic.wav";
|
||||
m_EventBroker->Publish(changeBGM);
|
||||
} else if (e.CameraEntity.Name() == "PickTeamCamera") {
|
||||
Events::ChangeBGM changeBGM;
|
||||
changeBGM.FilePath = "Audio/BGM/Layer1.wav";
|
||||
m_EventBroker->Publish(changeBGM);
|
||||
if (m_CurrentBGMCombo != nullptr) {
|
||||
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
|
||||
stopSound(m_CurrentBGMCombo);
|
||||
}
|
||||
}
|
||||
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
|
||||
m_CurrentBGMCombo->Type = SoundType::BGM;
|
||||
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
|
||||
setGain(m_CurrentBGMCombo, 0);
|
||||
playSound(m_CurrentBGMCombo);
|
||||
}
|
||||
}
|
||||
|
||||
ALenum SoundManager::getSourceState(ALuint source)
|
||||
{
|
||||
ALenum state;
|
||||
@@ -419,14 +436,14 @@ void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundCom
|
||||
{
|
||||
float gain;
|
||||
switch (source->Type) {
|
||||
case SoundType::SFX:
|
||||
gain = m_SFXVolumeChannel;
|
||||
case SoundType::SFX:
|
||||
gain = m_SFXVolumeChannel;
|
||||
break;
|
||||
case SoundType::BGM:
|
||||
case SoundType::BGM:
|
||||
gain = m_BGMVolumeChannel;
|
||||
break;
|
||||
case SoundType::Announcer:
|
||||
gain = m_AnnouncerVolumeChannel;
|
||||
case SoundType::Announcer:
|
||||
gain = m_AnnouncerVolumeChannel;
|
||||
break;
|
||||
default:
|
||||
gain = 1.f;
|
||||
|
||||
@@ -23,7 +23,7 @@ void HealthHUDSystem::Update(double dt)
|
||||
|
||||
if (entity.HasComponent("Text")) {
|
||||
double health = (const double&)entityIDParent["Health"]["Health"];
|
||||
double maxHealth = (const double&)entityIDParent["Health"]["Health"];
|
||||
double maxHealth = (const double&)entityIDParent["Health"]["MaxHealth"];
|
||||
std::string s = "";
|
||||
s = s + std::to_string((int)health);
|
||||
s = s + "/";
|
||||
@@ -35,7 +35,7 @@ void HealthHUDSystem::Update(double dt)
|
||||
|
||||
if(entity.HasComponent("Fill")) {
|
||||
double health = (const double&)entityIDParent["Health"]["Health"];
|
||||
double maxHealth = (const double&)entityIDParent["Health"]["Health"];
|
||||
double maxHealth = (const double&)entityIDParent["Health"]["MaxHealth"];
|
||||
float healthPercentage = health/maxHealth;
|
||||
entity["Fill"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Fill"]["Color"]).a);
|
||||
entity["Fill"]["Percentage"] = (double)healthPercentage;
|
||||
|
||||
@@ -83,15 +83,24 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
if (it->Team == cSpawnerTeam["Team"].Enum("Spectator")) {
|
||||
++playersSpectating;
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Choose a different spawner depending on class picked?
|
||||
std::string playerEntityFile;
|
||||
if (it->Class == PlayerClass::Assault) {
|
||||
playerEntityFile = (const std::string&)cPlayerSpawn["AssaultFile"];
|
||||
} else if (it->Class == PlayerClass::Defender) {
|
||||
playerEntityFile = (const std::string&)cPlayerSpawn["DefenderFile"];
|
||||
} else if (it->Class == PlayerClass::Sniper) {
|
||||
playerEntityFile = (const std::string&)cPlayerSpawn["SniperFile"];
|
||||
}
|
||||
|
||||
// Spawn the player!
|
||||
EntityWrapper player = SpawnerSystem::Spawn(spawner, EntityWrapper::Invalid, "Player");
|
||||
EntityWrapper player = SpawnerSystem::SpawnEntityFile(playerEntityFile, spawner, EntityWrapper::Invalid, "Player");
|
||||
// Set the player team affiliation
|
||||
player["Team"]["Team"] = it->Team;
|
||||
|
||||
|
||||
@@ -30,11 +30,6 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
|
||||
Events::PlayAnonuncerVoice go;
|
||||
go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav";
|
||||
m_EventBroker->Publish(go);
|
||||
{
|
||||
Events::ChangeBGM ev;
|
||||
ev.FilePath = "Audio/BGM/Layer1.wav";
|
||||
m_EventBroker->Publish(ev);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,17 @@ SpawnerSystem::SpawnerSystem(SystemParams params)
|
||||
}
|
||||
|
||||
EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /*= EntityWrapper::Invalid*/, const std::string& dontCollideComponent)
|
||||
{
|
||||
// Load the entity file and parse it
|
||||
const std::string& entityFilePath = spawner["Spawner"]["EntityFile"];
|
||||
if (!entityFilePath.empty()) {
|
||||
return SpawnEntityFile(entityFilePath, spawner, parent, dontCollideComponent);
|
||||
} else {
|
||||
return EntityWrapper::Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
EntityWrapper SpawnerSystem::SpawnEntityFile(const std::string& entityFilePath, EntityWrapper spawner, EntityWrapper parent /*= EntityWrapper::Invalid*/, const std::string& dontCollideComponent /*= ""*/)
|
||||
{
|
||||
// Spawn the entity in the parent's world if it exists, otherwise in the spawner's world
|
||||
World* world = parent.World;
|
||||
@@ -15,8 +26,6 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /
|
||||
world = spawner.World;
|
||||
}
|
||||
|
||||
// Load the entity file and parse it
|
||||
const std::string& entityFilePath = spawner["Spawner"]["EntityFile"];
|
||||
EntityWrapper spawnedEntity;
|
||||
try {
|
||||
auto entityFile = ResourceManager::Load<EntityFile>(entityFilePath);
|
||||
@@ -39,7 +48,7 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /
|
||||
|
||||
// Find any SpawnPoints existing as children of spawner
|
||||
auto children = spawner.World->GetDirectChildren(spawner.ID);
|
||||
std::vector<EntityWrapper> spawnPoints;
|
||||
std::list<EntityWrapper> spawnPoints;
|
||||
for (auto kv = children.first; kv != children.second; ++kv) {
|
||||
const EntityID& child = kv->second;
|
||||
if (spawner.World->HasComponent(child, "SpawnPoint")) {
|
||||
|
||||
@@ -61,7 +61,11 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
|
||||
// TODO: 1 Signifies spectator, should probably have real enum here later.
|
||||
// Spectators should never end up at the class select, instead put them at the SpectatorCamera.
|
||||
if (swapToClass && m_PickedTeam != 1) {
|
||||
camName = "PickClassCamera";
|
||||
if (m_PickedTeam == 2) {
|
||||
camName = "PickClassCameraRed";
|
||||
} else if (m_PickedTeam == 3) {
|
||||
camName = "PickClassCameraBlue";
|
||||
}
|
||||
} else if (e.Command == "SwapToTeamPick") {
|
||||
camName = "PickTeamCamera";
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user