From fa9c8e061b52a0c3ae84e9db28674c12d1518a7d Mon Sep 17 00:00:00 2001 From: fabio Date: Mon, 30 Nov 2015 10:51:02 +0000 Subject: [PATCH] Enable GLSL by default on OpenGL 3+. This doesn't override any user setting, it just changes the default when no preferglsl setting is specified. Fixes #3641. Refs #145. This was SVN commit r17338. --- binaries/data/mods/mod/hwdetect/hwdetect.js | 11 ++++++++++- source/ps/GameSetup/Config.cpp | 2 ++ source/ps/GameSetup/Config.h | 5 ++++- source/ps/GameSetup/GameSetup.cpp | 1 + source/ps/GameSetup/HWDetect.cpp | 7 +++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/binaries/data/mods/mod/hwdetect/hwdetect.js b/binaries/data/mods/mod/hwdetect/hwdetect.js index 9ac22bf6bb..00a27a7980 100644 --- a/binaries/data/mods/mod/hwdetect/hwdetect.js +++ b/binaries/data/mods/mod/hwdetect/hwdetect.js @@ -1,4 +1,4 @@ -/* Copyright (c) 2013 Wildfire Games +/* Copyright (c) 2015 Wildfire Games * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -180,6 +180,7 @@ function RunDetection(settings) var disable_shadowpcf = undefined; var disable_allwater = undefined; var disable_fancywater = undefined; + var enable_glsl = undefined; var override_renderpath = undefined; // TODO: add some mechanism for setting config values @@ -209,6 +210,10 @@ function RunDetection(settings) var GL_VERSION = settings.GL_VERSION; var GL_EXTENSIONS = settings.GL_EXTENSIONS.split(" "); + // enable GLSL on OpenGL 3+, which should be able to properly manage + // GLSL shaders, needed for effects like windy tree + if (GL_VERSION.match(/^[3-9]/)) + enable_glsl = true; // NVIDIA 260.19.* UNIX drivers cause random crashes soon after startup. // http://www.wildfiregames.com/forum/index.php?showtopic=13668 @@ -293,6 +298,7 @@ function RunDetection(settings) "disable_shadowpcf": disable_shadowpcf, "disable_allwater": disable_allwater, "disable_fancywater": disable_fancywater, + "enable_glsl": enable_glsl, "override_renderpath": override_renderpath, }; } @@ -332,6 +338,9 @@ global.RunHardwareDetection = function(settings) if (output.disable_fancywater !== undefined) Engine.SetDisableFancyWater(output.disable_fancywater); + if (output.enable_glsl !== undefined) + Engine.SetEnableGLSL(output.enable_glsl); + if (output.override_renderpath !== undefined) Engine.SetRenderPath(output.override_renderpath); }; diff --git a/source/ps/GameSetup/Config.cpp b/source/ps/GameSetup/Config.cpp index 238a292f68..273bae8e45 100644 --- a/source/ps/GameSetup/Config.cpp +++ b/source/ps/GameSetup/Config.cpp @@ -51,6 +51,8 @@ bool g_Particles = false; bool g_Silhouettes = false; bool g_ShowSky = false; +bool g_PreferGLSL = false; + float g_Gamma = 1.0f; CStr g_RenderPath = "default"; diff --git a/source/ps/GameSetup/Config.h b/source/ps/GameSetup/Config.h index 7acb1bf08a..b8f21d4664 100644 --- a/source/ps/GameSetup/Config.h +++ b/source/ps/GameSetup/Config.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2015 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -72,6 +72,9 @@ extern bool g_Silhouettes; // flag to switch on sky rendering extern bool g_ShowSky; +// Prefer GLSL shaders over ARB shaders +extern bool g_PreferGLSL; + extern float g_Gamma; // name of configured render path (depending on OpenGL extensions, this may not be // the render path that is actually in use right now) diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 121bf9ac3e..cda95b45e5 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -617,6 +617,7 @@ static void InitRenderer() g_Renderer.SetOptionBool(CRenderer::OPT_PARTICLES, g_Particles); g_Renderer.SetOptionBool(CRenderer::OPT_SILHOUETTES, g_Silhouettes); g_Renderer.SetOptionBool(CRenderer::OPT_SHOWSKY, g_ShowSky); + g_Renderer.SetOptionBool(CRenderer::OPT_PREFERGLSL, g_PreferGLSL); // create terrain related stuff new CTerrainTextureManager; diff --git a/source/ps/GameSetup/HWDetect.cpp b/source/ps/GameSetup/HWDetect.cpp index 205e398583..9474bed272 100644 --- a/source/ps/GameSetup/HWDetect.cpp +++ b/source/ps/GameSetup/HWDetect.cpp @@ -172,6 +172,12 @@ void SetDisableFancyWater(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool d g_WaterShadows = !disabled; } +void SetEnableGLSL(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool enabled) +{ + if (!IsOverridden("preferglsl")) + g_PreferGLSL = enabled; +} + void SetRenderPath(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string renderpath) { g_RenderPath = renderpath; @@ -191,6 +197,7 @@ void RunHardwareDetection() scriptInterface.RegisterFunction("SetDisableShadowPCF"); scriptInterface.RegisterFunction("SetDisableAllWater"); scriptInterface.RegisterFunction("SetDisableFancyWater"); + scriptInterface.RegisterFunction("SetEnableGLSL"); scriptInterface.RegisterFunction("SetRenderPath"); // Load the detection script: