Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/ShadowMap.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
historic_bruno: 2019 | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 22 Lines | |||||
#include "graphics/ShaderManager.h" | #include "graphics/ShaderManager.h" | ||||
#include "maths/BoundingBoxAligned.h" | #include "maths/BoundingBoxAligned.h" | ||||
#include "maths/Brush.h" | #include "maths/Brush.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "maths/Matrix3D.h" | #include "maths/Matrix3D.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/RenderingOptions.h" | |||||
#include "renderer/ShadowMap.h" | #include "renderer/ShadowMap.h" | ||||
/////////////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// ShadowMap implementation | // ShadowMap implementation | ||||
/** | /** | ||||
* Struct ShadowMapInternals: Internal data for the ShadowMap implementation | * Struct ShadowMapInternals: Internal data for the ShadowMap implementation | ||||
▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | void ShadowMapInternals::CreateTexture() | ||||
case 32: formatname = "DEPTH_COMPONENT32"; break; | case 32: formatname = "DEPTH_COMPONENT32"; break; | ||||
default: formatname = "DEPTH_COMPONENT"; break; | default: formatname = "DEPTH_COMPONENT"; break; | ||||
} | } | ||||
LOGMESSAGE("Creating shadow texture (size %dx%d) (format = %s)", | LOGMESSAGE("Creating shadow texture (size %dx%d) (format = %s)", | ||||
Width, Height, formatname); | Width, Height, formatname); | ||||
if (g_Renderer.m_Options.m_ShadowAlphaFix) | if (g_RenderingOptions.GetShadowAlphaFix()) | ||||
{ | { | ||||
glGenTextures(1, &DummyTexture); | glGenTextures(1, &DummyTexture); | ||||
g_Renderer.BindTexture(0, DummyTexture); | g_Renderer.BindTexture(0, DummyTexture); | ||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | #endif | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
// bind to framebuffer object | // bind to framebuffer object | ||||
glBindTexture(GL_TEXTURE_2D, 0); | glBindTexture(GL_TEXTURE_2D, 0); | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Framebuffer); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Framebuffer); | ||||
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, Texture, 0); | pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, Texture, 0); | ||||
if (g_Renderer.m_Options.m_ShadowAlphaFix) | if (g_RenderingOptions.GetShadowAlphaFix()) | ||||
{ | { | ||||
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, DummyTexture, 0); | pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, DummyTexture, 0); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
#if CONFIG2_GLES | #if CONFIG2_GLES | ||||
#warning TODO: figure out whether the glDrawBuffer/glReadBuffer stuff is needed, since it is not supported by GLES | #warning TODO: figure out whether the glDrawBuffer/glReadBuffer stuff is needed, since it is not supported by GLES | ||||
#else | #else | ||||
Show All 11 Lines | #endif | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, SavedViewFBO); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, SavedViewFBO); | ||||
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) | if (status != GL_FRAMEBUFFER_COMPLETE_EXT) | ||||
{ | { | ||||
LOGWARNING("Framebuffer object incomplete: 0x%04X", status); | LOGWARNING("Framebuffer object incomplete: 0x%04X", status); | ||||
// Disable shadow rendering (but let the user try again if they want) | // Disable shadow rendering (but let the user try again if they want) | ||||
g_Renderer.m_Options.m_Shadows = false; | g_RenderingOptions.SetShadows(false); | ||||
} | } | ||||
} | } | ||||
/////////////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
// Set up to render into shadow map texture | // Set up to render into shadow map texture | ||||
void ShadowMap::BeginRender() | void ShadowMap::BeginRender() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
2019