Skip to content

Commit

Permalink
Merge branch 'master' into for-0.56.0/sync
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Dec 29, 2024
2 parents bb81c8f + af2ba5a commit 6d5a986
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 26 deletions.
1 change: 1 addition & 0 deletions src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ endif()
set(COMMONTESTLIST
${LIB_DIR}/tinyformat/TinyformatTest.cpp
${COMMON_DIR}/ColorTest.cpp
${COMMON_DIR}/CvarTest.cpp
${COMMON_DIR}/FileSystemTest.cpp
${COMMON_DIR}/StringTest.cpp
${COMMON_DIR}/cm/unittest.cpp
Expand Down
94 changes: 94 additions & 0 deletions src/common/CvarTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
===========================================================================
Daemon BSD Source Code
Copyright (c) 2024, Daemon Developers
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Daemon developers nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
===========================================================================
*/

#include <gtest/gtest.h>

#include "common/Common.h"
#include "engine/framework/CvarSystem.h"

namespace Cvar {
namespace {

TEST(ModifiedCvarTest, Normal)
{
Modified<Cvar<int>> cv("test_modified", "desc", NONE, 3);
Util::optional<int> modified = cv.GetModifiedValue();
ASSERT_TRUE(modified); // modified flag is true on birth
ASSERT_EQ(modified.value(), 3);

// now cleared
ASSERT_FALSE(cv.GetModifiedValue());
ASSERT_FALSE(cv.GetModifiedValue());

// test setting via the cvar object
cv.Set(9);
modified = cv.GetModifiedValue();
ASSERT_TRUE(modified);
ASSERT_EQ(modified.value(), 9);

ASSERT_FALSE(cv.GetModifiedValue());

// test setting externally
SetValue("test_modified", "1");
modified = cv.GetModifiedValue();
ASSERT_TRUE(modified);
ASSERT_EQ(modified.value(), 1);

ASSERT_FALSE(cv.GetModifiedValue());

// test that invalid set is ignored
SetValue("test_modified", "a");
ASSERT_FALSE(cv.GetModifiedValue());
}

TEST(ModifiedCvarTest, Latch)
{
Modified<Cvar<float>> cv("test_modifiedLatched", "desc", NONE, 1.5f);
Latch(cv);
ASSERT_TRUE(cv.GetModifiedValue());
ASSERT_FALSE(cv.GetModifiedValue());

cv.Set(-5.0f);
ASSERT_EQ(cv.Get(), 1.5f);

// Clear latch flag. It's probably true now because the implementation of latched cvars
// sets them to the new value and back to the current value, but let's not make this
// part of the contract.
cv.GetModifiedValue();

// Make sure modified flag is set upon unlatching
Latch(cv);
Util::optional<float> modified = cv.GetModifiedValue();
ASSERT_TRUE(modified);
ASSERT_EQ(modified.value(), -5.0f);
}

} // namespace Cvar
} // namespace
4 changes: 2 additions & 2 deletions src/engine/renderer/glsl_source/heatHaze_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
uniform sampler2D u_CurrentMap;
uniform float u_AlphaThreshold;

#if defined(MATERIAL_SYSTEM)
#if defined(USE_MATERIAL_SYSTEM)
uniform float u_DeformEnable;
#endif

Expand All @@ -56,7 +56,7 @@ void main()

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

#if defined(MATERIAL_SYSTEM)
#if defined(USE_MATERIAL_SYSTEM)
// Use a global uniform for heatHaze with material system to avoid duplicating all of the shader stage data
st += normal.xy * var_Deform * u_DeformEnable;
#else
Expand Down
5 changes: 2 additions & 3 deletions src/engine/renderer/tr_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,10 @@ void RE_BeginFrame()
}

// texturemode stuff
if ( r_textureMode->modified )
if ( Util::optional<std::string> textureMode = r_textureMode.GetModifiedValue() )
{
R_SyncRenderThread();
GL_TextureMode( r_textureMode->string );
r_textureMode->modified = false;
GL_TextureMode( textureMode->c_str() );
}

// check for errors
Expand Down
11 changes: 6 additions & 5 deletions src/engine/renderer/tr_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ void GL_TextureMode( const char *string )
gl_filter_min = modes[ i ].minimize;
gl_filter_max = modes[ i ].maximize;

if ( glConfig2.usingBindlessTextures && !tr.images.empty() )
{
Log::Notice( "Changing filter type of existing bindless textures requires a restart" );
return;
}

// change all the existing mipmap texture objects
for ( image_t *image : tr.images )
{
Expand All @@ -127,11 +133,6 @@ void GL_TextureMode( const char *string )
{
glTexParameterf( image->type, GL_TEXTURE_MAX_ANISOTROPY_EXT, glConfig2.textureAnisotropy );
}

// Getting bindless handle makes the texture immutable, so generate it again because we used glTexParameter*
if ( glConfig2.usingBindlessTextures ) {
image->texture->GenBindlessHandle();
}
}
}
}
Expand Down
20 changes: 5 additions & 15 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *r_replaceMaterialMinDimensionIfPresentWithMaxDimension;
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);
cvar_t *r_finish;
cvar_t *r_textureMode;
Cvar::Modified<Cvar::Cvar<std::string>> r_textureMode(
"r_textureMode", "default texture filter mode", Cvar::NONE, "GL_LINEAR_MIPMAP_LINEAR");
cvar_t *r_offsetFactor;
cvar_t *r_offsetUnits;

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

tr.currenttextures.resize( glConfig2.maxTextureUnits );

// initialize downstream texture units if we're running
// in a multitexture environment
if ( glConfig.driverType == glDriverType_t::GLDRV_OPENGL3 )
{
for ( int i = 0; i < glConfig2.maxTextureUnits; i++ )
{
GL_SelectTexture( i );
GL_TextureMode( r_textureMode->string );
}
}

GL_CheckErrors();
GL_TextureMode( r_textureMode.Get().c_str() );
r_textureMode.GetModifiedValue();

GL_DepthFunc( GL_LEQUAL );

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

Log::Debug("texturemode: %s", r_textureMode->string );
Log::Debug("texturemode: %s", r_textureMode.Get() );
Log::Debug("picmip: %d", r_picMip->integer );
Log::Debug("imageMaxDimension: %d", r_imageMaxDimension->integer );
Log::Debug("ignoreMaterialMinDimension: %d", r_ignoreMaterialMinDimension->integer );
Expand Down Expand Up @@ -1179,7 +1170,6 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_zfar = Cvar_Get( "r_zfar", "0", CVAR_CHEAT );
r_checkGLErrors = Cvar_Get( "r_checkGLErrors", "-1", 0 );
r_finish = Cvar_Get( "r_finish", "0", CVAR_CHEAT );
r_textureMode = Cvar_Get( "r_textureMode", "GL_LINEAR_MIPMAP_LINEAR", CVAR_ARCHIVE );
r_gamma = Cvar_Get( "r_gamma", "1.0", CVAR_ARCHIVE );
r_facePlaneCull = Cvar_Get( "r_facePlaneCull", "1", 0 );

Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2944,7 +2944,7 @@ enum class shaderProfilerRenderSubGroupsMode {
extern Cvar::Range<Cvar::Cvar<int>> r_imageFitScreen;
extern cvar_t *r_finish;
extern cvar_t *r_drawBuffer;
extern cvar_t *r_textureMode;
extern Cvar::Modified<Cvar::Cvar<std::string>> r_textureMode;
extern cvar_t *r_offsetFactor;
extern cvar_t *r_offsetUnits;

Expand Down

0 comments on commit 6d5a986

Please sign in to comment.