Skip to content

Commit 6d5a986

Browse files
committed
Merge branch 'master' into for-0.56.0/sync
2 parents bb81c8f + af2ba5a commit 6d5a986

File tree

7 files changed

+111
-26
lines changed

7 files changed

+111
-26
lines changed

src.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ endif()
9090
set(COMMONTESTLIST
9191
${LIB_DIR}/tinyformat/TinyformatTest.cpp
9292
${COMMON_DIR}/ColorTest.cpp
93+
${COMMON_DIR}/CvarTest.cpp
9394
${COMMON_DIR}/FileSystemTest.cpp
9495
${COMMON_DIR}/StringTest.cpp
9596
${COMMON_DIR}/cm/unittest.cpp

src/common/CvarTest.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
===========================================================================
3+
Daemon BSD Source Code
4+
Copyright (c) 2024, Daemon Developers
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Daemon developers nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
===========================================================================
29+
*/
30+
31+
#include <gtest/gtest.h>
32+
33+
#include "common/Common.h"
34+
#include "engine/framework/CvarSystem.h"
35+
36+
namespace Cvar {
37+
namespace {
38+
39+
TEST(ModifiedCvarTest, Normal)
40+
{
41+
Modified<Cvar<int>> cv("test_modified", "desc", NONE, 3);
42+
Util::optional<int> modified = cv.GetModifiedValue();
43+
ASSERT_TRUE(modified); // modified flag is true on birth
44+
ASSERT_EQ(modified.value(), 3);
45+
46+
// now cleared
47+
ASSERT_FALSE(cv.GetModifiedValue());
48+
ASSERT_FALSE(cv.GetModifiedValue());
49+
50+
// test setting via the cvar object
51+
cv.Set(9);
52+
modified = cv.GetModifiedValue();
53+
ASSERT_TRUE(modified);
54+
ASSERT_EQ(modified.value(), 9);
55+
56+
ASSERT_FALSE(cv.GetModifiedValue());
57+
58+
// test setting externally
59+
SetValue("test_modified", "1");
60+
modified = cv.GetModifiedValue();
61+
ASSERT_TRUE(modified);
62+
ASSERT_EQ(modified.value(), 1);
63+
64+
ASSERT_FALSE(cv.GetModifiedValue());
65+
66+
// test that invalid set is ignored
67+
SetValue("test_modified", "a");
68+
ASSERT_FALSE(cv.GetModifiedValue());
69+
}
70+
71+
TEST(ModifiedCvarTest, Latch)
72+
{
73+
Modified<Cvar<float>> cv("test_modifiedLatched", "desc", NONE, 1.5f);
74+
Latch(cv);
75+
ASSERT_TRUE(cv.GetModifiedValue());
76+
ASSERT_FALSE(cv.GetModifiedValue());
77+
78+
cv.Set(-5.0f);
79+
ASSERT_EQ(cv.Get(), 1.5f);
80+
81+
// Clear latch flag. It's probably true now because the implementation of latched cvars
82+
// sets them to the new value and back to the current value, but let's not make this
83+
// part of the contract.
84+
cv.GetModifiedValue();
85+
86+
// Make sure modified flag is set upon unlatching
87+
Latch(cv);
88+
Util::optional<float> modified = cv.GetModifiedValue();
89+
ASSERT_TRUE(modified);
90+
ASSERT_EQ(modified.value(), -5.0f);
91+
}
92+
93+
} // namespace Cvar
94+
} // namespace

src/engine/renderer/glsl_source/heatHaze_fp.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2929
uniform sampler2D u_CurrentMap;
3030
uniform float u_AlphaThreshold;
3131

32-
#if defined(MATERIAL_SYSTEM)
32+
#if defined(USE_MATERIAL_SYSTEM)
3333
uniform float u_DeformEnable;
3434
#endif
3535

@@ -56,7 +56,7 @@ void main()
5656

5757
// offset by the scaled normal and clamp it to 0.0 - 1.0
5858

59-
#if defined(MATERIAL_SYSTEM)
59+
#if defined(USE_MATERIAL_SYSTEM)
6060
// Use a global uniform for heatHaze with material system to avoid duplicating all of the shader stage data
6161
st += normal.xy * var_Deform * u_DeformEnable;
6262
#else

src/engine/renderer/tr_cmds.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,10 @@ void RE_BeginFrame()
834834
}
835835

836836
// texturemode stuff
837-
if ( r_textureMode->modified )
837+
if ( Util::optional<std::string> textureMode = r_textureMode.GetModifiedValue() )
838838
{
839839
R_SyncRenderThread();
840-
GL_TextureMode( r_textureMode->string );
841-
r_textureMode->modified = false;
840+
GL_TextureMode( textureMode->c_str() );
842841
}
843842

844843
// check for errors

src/engine/renderer/tr_image.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ void GL_TextureMode( const char *string )
111111
gl_filter_min = modes[ i ].minimize;
112112
gl_filter_max = modes[ i ].maximize;
113113

114+
if ( glConfig2.usingBindlessTextures && !tr.images.empty() )
115+
{
116+
Log::Notice( "Changing filter type of existing bindless textures requires a restart" );
117+
return;
118+
}
119+
114120
// change all the existing mipmap texture objects
115121
for ( image_t *image : tr.images )
116122
{
@@ -127,11 +133,6 @@ void GL_TextureMode( const char *string )
127133
{
128134
glTexParameterf( image->type, GL_TEXTURE_MAX_ANISOTROPY_EXT, glConfig2.textureAnisotropy );
129135
}
130-
131-
// Getting bindless handle makes the texture immutable, so generate it again because we used glTexParameter*
132-
if ( glConfig2.usingBindlessTextures ) {
133-
image->texture->GenBindlessHandle();
134-
}
135136
}
136137
}
137138
}

src/engine/renderer/tr_init.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
158158
cvar_t *r_replaceMaterialMinDimensionIfPresentWithMaxDimension;
159159
Cvar::Range<Cvar::Cvar<int>> r_imageFitScreen("r_imageFitScreen", "downscale “fitscreen” images to fit the screen size: 0: disable, 1: downscale as much as possible without being smaller than screen size (default), 2: downscale to never be larger then screen size", Cvar::NONE, 1, 0, 2);
160160
cvar_t *r_finish;
161-
cvar_t *r_textureMode;
161+
Cvar::Modified<Cvar::Cvar<std::string>> r_textureMode(
162+
"r_textureMode", "default texture filter mode", Cvar::NONE, "GL_LINEAR_MIPMAP_LINEAR");
162163
cvar_t *r_offsetFactor;
163164
cvar_t *r_offsetUnits;
164165

@@ -830,18 +831,8 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
830831

831832
tr.currenttextures.resize( glConfig2.maxTextureUnits );
832833

833-
// initialize downstream texture units if we're running
834-
// in a multitexture environment
835-
if ( glConfig.driverType == glDriverType_t::GLDRV_OPENGL3 )
836-
{
837-
for ( int i = 0; i < glConfig2.maxTextureUnits; i++ )
838-
{
839-
GL_SelectTexture( i );
840-
GL_TextureMode( r_textureMode->string );
841-
}
842-
}
843-
844-
GL_CheckErrors();
834+
GL_TextureMode( r_textureMode.Get().c_str() );
835+
r_textureMode.GetModifiedValue();
845836

846837
GL_DepthFunc( GL_LEQUAL );
847838

@@ -1077,7 +1068,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
10771068
Log::Notice("Forcing glFinish." );
10781069
}
10791070

1080-
Log::Debug("texturemode: %s", r_textureMode->string );
1071+
Log::Debug("texturemode: %s", r_textureMode.Get() );
10811072
Log::Debug("picmip: %d", r_picMip->integer );
10821073
Log::Debug("imageMaxDimension: %d", r_imageMaxDimension->integer );
10831074
Log::Debug("ignoreMaterialMinDimension: %d", r_ignoreMaterialMinDimension->integer );
@@ -1179,7 +1170,6 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
11791170
r_zfar = Cvar_Get( "r_zfar", "0", CVAR_CHEAT );
11801171
r_checkGLErrors = Cvar_Get( "r_checkGLErrors", "-1", 0 );
11811172
r_finish = Cvar_Get( "r_finish", "0", CVAR_CHEAT );
1182-
r_textureMode = Cvar_Get( "r_textureMode", "GL_LINEAR_MIPMAP_LINEAR", CVAR_ARCHIVE );
11831173
r_gamma = Cvar_Get( "r_gamma", "1.0", CVAR_ARCHIVE );
11841174
r_facePlaneCull = Cvar_Get( "r_facePlaneCull", "1", 0 );
11851175

src/engine/renderer/tr_local.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2944,7 +2944,7 @@ enum class shaderProfilerRenderSubGroupsMode {
29442944
extern Cvar::Range<Cvar::Cvar<int>> r_imageFitScreen;
29452945
extern cvar_t *r_finish;
29462946
extern cvar_t *r_drawBuffer;
2947-
extern cvar_t *r_textureMode;
2947+
extern Cvar::Modified<Cvar::Cvar<std::string>> r_textureMode;
29482948
extern cvar_t *r_offsetFactor;
29492949
extern cvar_t *r_offsetUnits;
29502950

0 commit comments

Comments
 (0)