[colobot] 361/390: Implemented graceful degradation of shadow quality when not enough texture units are available
Didier Raboud
odyx at moszumanska.debian.org
Fri Jun 12 14:22:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch upstream/latest
in repository colobot.
commit d210dcf70edca4907fc5e957f95ea7c6df26f5e2
Author: Tomasz Kapuściński <tomaszkax86 at gmail.com>
Date: Fri May 15 10:12:35 2015 +0200
Implemented graceful degradation of shadow quality when not enough texture units are available
---
src/graphics/engine/engine.cpp | 177 ++++++++++++++++++++++-----------------
src/graphics/opengl/gldevice.cpp | 1 +
2 files changed, 100 insertions(+), 78 deletions(-)
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 4b571aa..38196b1 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -3192,11 +3192,13 @@ void CEngine::Render()
// Begin the scene
m_device->BeginScene();
- if (m_shadowMapping)
- RenderShadowMap();
-
if (m_drawWorld)
+ {
+ if (m_shadowMapping)
+ RenderShadowMap();
+
Draw3DScene();
+ }
m_app->StartPerformanceCounter(PCNT_RENDER_INTERFACE);
DrawInterface();
@@ -3242,85 +3244,94 @@ void CEngine::Draw3DScene()
{
if (m_qualityShadows)
{
- // Texture Unit 2
- m_device->SetTextureEnabled(2, true);
- m_device->SetTexture(2, m_shadowMap);
- m_device->SetTextureMatrix(2, m_shadowTextureMat);
-
- Math::Matrix identity;
- identity.LoadIdentity();
- m_device->SetTransform(TRANSFORM_WORLD, identity);
-
- float shadowBias = 0.6f;
- float shadowUnbias = 1.0f - shadowBias;
-
- TextureStageParams params;
- params.colorOperation = TEX_MIX_OPER_MODULATE;
- params.colorArg1 = TEX_MIX_ARG_TEXTURE;
- params.colorArg2 = TEX_MIX_ARG_FACTOR;
- params.colorOperation = TEX_MIX_OPER_DEFAULT;
- params.factor = Color(shadowBias, shadowBias, shadowBias, 1.0f);
- params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
- params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
-
- m_device->SetTextureStageParams(2, params);
-
- TextureGenerationParams genParams;
-
- for (int i = 0; i < 4; i++)
+ if (m_device->GetMaxTextureStageCount() < 6)
{
- genParams.coords[i].mode = TEX_GEN_EYE_LINEAR;
-
- for (int j = 0; j < 4; j++)
- {
- genParams.coords[i].plane[j] = (i == j ? 1.0f : 0.0f);
- }
+ m_qualityShadows = false;
+ GetLogger()->Error("Cannot use quality shadow maps, not enough texture units\n");
+ GetLogger()->Error("Attempting to use lower quality shadow maps\n");
}
+ else
+ {
+ // Texture Unit 2
+ m_device->SetTextureEnabled(2, true);
+ m_device->SetTexture(2, m_shadowMap);
+ m_device->SetTextureMatrix(2, m_shadowTextureMat);
- m_device->SetTextureCoordGeneration(2, genParams);
-
- // Texture Unit 3
- m_device->SetTextureEnabled(3, true);
- m_device->SetTexture(3, m_shadowMap);
-
- params.LoadDefault();
- params.colorOperation = TEX_MIX_OPER_ADD;
- params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
- params.colorArg2 = TEX_MIX_ARG_FACTOR;
- params.alphaOperation = TEX_MIX_OPER_DEFAULT;
- params.factor = Color(shadowUnbias, shadowUnbias, shadowUnbias, 0.0f);
- params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
- params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
+ Math::Matrix identity;
+ identity.LoadIdentity();
+ m_device->SetTransform(TRANSFORM_WORLD, identity);
- m_device->SetTextureStageParams(3, params);
+ float shadowBias = 0.6f;
+ float shadowUnbias = 1.0f - shadowBias;
- // Texture Unit 4
- m_device->SetTextureEnabled(4, true);
- m_device->SetTexture(4, m_shadowMap);
+ TextureStageParams params;
+ params.colorOperation = TEX_MIX_OPER_MODULATE;
+ params.colorArg1 = TEX_MIX_ARG_TEXTURE;
+ params.colorArg2 = TEX_MIX_ARG_FACTOR;
+ params.colorOperation = TEX_MIX_OPER_DEFAULT;
+ params.factor = Color(shadowBias, shadowBias, shadowBias, 1.0f);
+ params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
+ params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
- params.LoadDefault();
- params.colorOperation = TEX_MIX_OPER_MODULATE;
- params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
- params.colorArg2 = TEX_MIX_ARG_SRC_COLOR;
- params.alphaOperation = TEX_MIX_OPER_DEFAULT;
- params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
- params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
+ m_device->SetTextureStageParams(2, params);
- m_device->SetTextureStageParams(4, params);
+ TextureGenerationParams genParams;
- // Texture Unit 5
- m_device->SetTextureEnabled(5, true);
- m_device->SetTexture(5, m_shadowMap);
+ for (int i = 0; i < 4; i++)
+ {
+ genParams.coords[i].mode = TEX_GEN_EYE_LINEAR;
- params.LoadDefault();
- params.colorOperation = TEX_MIX_OPER_MODULATE;
- params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
- params.colorArg2 = TEX_MIX_ARG_TEXTURE_0;
- params.alphaOperation = TEX_MIX_OPER_DEFAULT;
- params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
- params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
+ for (int j = 0; j < 4; j++)
+ {
+ genParams.coords[i].plane[j] = (i == j ? 1.0f : 0.0f);
+ }
+ }
- m_device->SetTextureStageParams(5, params);
+ m_device->SetTextureCoordGeneration(2, genParams);
+
+ // Texture Unit 3
+ m_device->SetTextureEnabled(3, true);
+ m_device->SetTexture(3, m_shadowMap);
+
+ params.LoadDefault();
+ params.colorOperation = TEX_MIX_OPER_ADD;
+ params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
+ params.colorArg2 = TEX_MIX_ARG_FACTOR;
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
+ params.factor = Color(shadowUnbias, shadowUnbias, shadowUnbias, 0.0f);
+ params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
+ params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
+
+ m_device->SetTextureStageParams(3, params);
+
+ // Texture Unit 4
+ m_device->SetTextureEnabled(4, true);
+ m_device->SetTexture(4, m_shadowMap);
+
+ params.LoadDefault();
+ params.colorOperation = TEX_MIX_OPER_MODULATE;
+ params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
+ params.colorArg2 = TEX_MIX_ARG_SRC_COLOR;
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
+ params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
+ params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
+
+ m_device->SetTextureStageParams(4, params);
+
+ // Texture Unit 5
+ m_device->SetTextureEnabled(5, true);
+ m_device->SetTexture(5, m_shadowMap);
+
+ params.LoadDefault();
+ params.colorOperation = TEX_MIX_OPER_MODULATE;
+ params.colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
+ params.colorArg2 = TEX_MIX_ARG_TEXTURE_0;
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
+ params.wrapS = TEX_WRAP_CLAMP_TO_BORDER;
+ params.wrapT = TEX_WRAP_CLAMP_TO_BORDER;
+
+ m_device->SetTextureStageParams(5, params);
+ }
}
else // Simpler shadows
{
@@ -3425,14 +3436,17 @@ void CEngine::Draw3DScene()
m_device->SetTextureCoordGeneration(2, params);
- m_device->SetTexture(3, 0);
- m_device->SetTextureEnabled(3, false);
+ if (m_qualityShadows)
+ {
+ m_device->SetTexture(3, 0);
+ m_device->SetTextureEnabled(3, false);
- m_device->SetTexture(4, 0);
- m_device->SetTextureEnabled(4, false);
+ m_device->SetTexture(4, 0);
+ m_device->SetTextureEnabled(4, false);
- m_device->SetTexture(5, 0);
- m_device->SetTextureEnabled(5, false);
+ m_device->SetTexture(5, 0);
+ m_device->SetTextureEnabled(5, false);
+ }
}
// Draws the shadows , if shadows enabled
@@ -3610,6 +3624,13 @@ void CEngine::RenderShadowMap()
{
if (!m_shadowMapping) return;
+ if (m_device->GetMaxTextureStageCount() < 3)
+ {
+ m_shadowMapping = false;
+ GetLogger()->Error("Cannot use shadow maps, not enough texture units\n");
+ GetLogger()->Error("Disabling shadow mapping\n");
+ }
+
m_app->StartPerformanceCounter(PCNT_RENDER_SHADOW_MAP);
// If no shadow map texture exists, create it
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index 99dafa1..7ba9142 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -331,6 +331,7 @@ bool CGLDevice::Create()
int maxTextures = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextures);
+ GetLogger()->Info("Maximum texture units: %d\n", maxTextures);
m_currentTextures = std::vector<Texture> (maxTextures, Texture());
m_texturesEnabled = std::vector<bool> (maxTextures, false);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list