mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-19 16:59:17 +02:00
Replace clamp with std::clamp
This commit is contained in:
@@ -821,7 +821,7 @@ bool opengl_renderer::Render_lowpoly( TDynamicObject *Dynamic, float const Squar
|
||||
Dynamic->fShade :
|
||||
1.0 ) ) ) ) };
|
||||
m_sunlight.apply_intensity(
|
||||
clamp( (
|
||||
std::clamp( (
|
||||
Dynamic->fShade > 0.f ?
|
||||
Dynamic->fShade :
|
||||
1.f )
|
||||
@@ -923,7 +923,7 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
|
||||
switch( Mode ) {
|
||||
case rendermode::color: { Config.draw_range = Global.BaseDrawRange * Global.fDistanceFactor; break; }
|
||||
case rendermode::shadows: { Config.draw_range = Global.shadowtune.range; break; }
|
||||
case rendermode::cabshadows: { Config.draw_range = ( Global.RenderCabShadowsRange > 0 ? clamp( Global.RenderCabShadowsRange, 5, 100 ) : simulation::Train->Occupied()->Dim.L ); break; }
|
||||
case rendermode::cabshadows: { Config.draw_range = ( Global.RenderCabShadowsRange > 0 ? std::clamp( Global.RenderCabShadowsRange, 5, 100 ) : simulation::Train->Occupied()->Dim.L ); break; }
|
||||
case rendermode::reflections: { Config.draw_range = Global.BaseDrawRange; break; }
|
||||
case rendermode::pickcontrols: { Config.draw_range = 50.f; break; }
|
||||
case rendermode::pickscenery: { Config.draw_range = Global.BaseDrawRange * 0.5f; break; }
|
||||
@@ -1510,7 +1510,7 @@ opengl_renderer::Render( world_environment *Environment ) {
|
||||
m_shadowcolor = interpolate(
|
||||
glm::vec4{ colors::shadow },
|
||||
glm::vec4{ colors::white },
|
||||
clamp( -Environment->m_sun.getAngle(), 0.f, 6.f ) / 6.f );
|
||||
std::clamp( -Environment->m_sun.getAngle(), 0.f, 6.f ) / 6.f );
|
||||
if( ( Environment->m_sun.getAngle() < -18.f )
|
||||
&& ( Environment->m_moon.getAngle() > 0.f ) ) {
|
||||
// turn on moon shadows after nautical twilight, if the moon is actually up
|
||||
@@ -1568,8 +1568,8 @@ opengl_renderer::Render( world_environment *Environment ) {
|
||||
|
||||
auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW );
|
||||
|
||||
auto const fogfactor { clamp( Global.fFogEnd / 2000.f, 0.f, 1.f ) }; // closer/denser fog reduces opacity of the celestial bodies
|
||||
float const duskfactor = 1.0f - clamp( std::abs( Environment->m_sun.getAngle() ), 0.0f, 12.0f ) / 12.0f;
|
||||
auto const fogfactor { std::clamp( Global.fFogEnd / 2000.f, 0.f, 1.f ) }; // closer/denser fog reduces opacity of the celestial bodies
|
||||
float const duskfactor = 1.0f - std::clamp( std::abs( Environment->m_sun.getAngle() ), 0.0f, 12.0f ) / 12.0f;
|
||||
glm::vec3 suncolor = interpolate(
|
||||
glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ),
|
||||
glm::vec3( 235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f ),
|
||||
@@ -1578,7 +1578,7 @@ opengl_renderer::Render( world_environment *Environment ) {
|
||||
if (!m_isATI)
|
||||
{
|
||||
Bind_Texture( m_suntexture );
|
||||
::glColor4f( suncolor.x, suncolor.y, suncolor.z, clamp( 1.5f - Global.Overcast, 0.f, 1.f ) * fogfactor );
|
||||
::glColor4f( suncolor.x, suncolor.y, suncolor.z, std::clamp( 1.5f - Global.Overcast, 0.f, 1.f ) * fogfactor );
|
||||
auto const sunvector = Environment->m_sun.getDirection();
|
||||
auto const sunposition = modelview * glm::vec4( sunvector.x, sunvector.y, sunvector.z, 1.0f );
|
||||
|
||||
@@ -1589,7 +1589,7 @@ opengl_renderer::Render( world_environment *Environment ) {
|
||||
float const size = interpolate( // TODO: expose distance/scale factor from the moon object
|
||||
0.0325f,
|
||||
0.0275f,
|
||||
clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f );
|
||||
std::clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f );
|
||||
::glBegin( GL_TRIANGLE_STRIP );
|
||||
::glMultiTexCoord2f( m_diffusetextureunit, 1.f, 1.f ); ::glVertex3f( -size, size, 0.f );
|
||||
::glMultiTexCoord2f( m_diffusetextureunit, 1.f, 0.f ); ::glVertex3f( -size, -size, 0.f );
|
||||
@@ -1622,7 +1622,7 @@ opengl_renderer::Render( world_environment *Environment ) {
|
||||
float const size = interpolate( // TODO: expose distance/scale factor from the moon object
|
||||
0.0160f,
|
||||
0.0135f,
|
||||
clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f );
|
||||
std::clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f );
|
||||
// choose the moon appearance variant, based on current moon phase
|
||||
// NOTE: implementation specific, 8 variants are laid out in 3x3 arrangement
|
||||
// from new moon onwards, top left to right bottom (last spot is left for future use, if any)
|
||||
@@ -2609,7 +2609,7 @@ opengl_renderer::Render_cab( TDynamicObject const *Dynamic, float const Lightlev
|
||||
GL_LIGHT_MODEL_AMBIENT,
|
||||
glm::value_ptr(
|
||||
glm::vec3( m_baseambient )
|
||||
+ ( Dynamic->InteriorLight * Lightlevel ) * static_cast<float>( clamp( 1.25 - luminance, 0.0, 1.0 ) ) ) );
|
||||
+ ( Dynamic->InteriorLight * Lightlevel ) * static_cast<float>( std::clamp( 1.25 - luminance, 0.0, 1.0 ) ) ) );
|
||||
}
|
||||
// render
|
||||
if( true == Alpha ) {
|
||||
@@ -2765,7 +2765,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
// textures...
|
||||
Bind_Material( material );
|
||||
// ...colors and opacity...
|
||||
auto const opacity { clamp( Material( material )->get_or_guess_opacity(), 0.f, 1.f ) };
|
||||
auto const opacity { std::clamp( Material( material )->get_or_guess_opacity(), 0.f, 1.f ) };
|
||||
if( Submodel->fVisible < 1.f ) {
|
||||
// setup
|
||||
::glAlphaFunc( GL_GREATER, 0.f );
|
||||
@@ -2921,7 +2921,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
// kąt większy niż maksymalny stożek swiatła
|
||||
float lightlevel = 1.f; // TODO, TBD: parameter to control light strength
|
||||
// view angle attenuation
|
||||
float const anglefactor = clamp(
|
||||
float const anglefactor = std::clamp(
|
||||
( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle ),
|
||||
0.f, 1.f );
|
||||
lightlevel *= anglefactor;
|
||||
@@ -2934,7 +2934,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
if( Global.Overcast > 0.75f ) {
|
||||
float const precipitationfactor{
|
||||
interpolate(
|
||||
interpolate( 1.f, 0.25f, clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ),
|
||||
interpolate( 1.f, 0.25f, std::clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ),
|
||||
1.f,
|
||||
distancefactor ) };
|
||||
lightlevel *= precipitationfactor;
|
||||
@@ -2970,7 +2970,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
|
||||
float const fogfactor {
|
||||
interpolate(
|
||||
2.f, 1.f,
|
||||
clamp( Global.fFogEnd / 2000, 0.f, 1.f ) )
|
||||
std::clamp( Global.fFogEnd / 2000, 0.f, 1.f ) )
|
||||
* std::max( 1.f, Global.Overcast ) };
|
||||
|
||||
::glPointSize( pointsize * fogfactor );
|
||||
@@ -3346,7 +3346,7 @@ opengl_renderer::Render_precipitation() {
|
||||
interpolate(
|
||||
0.5f * ( Global.DayLight.diffuse + Global.DayLight.ambient ),
|
||||
colors::white,
|
||||
0.5f * clamp<float>( Global.fLuminance, 0.f, 1.f ) ) ) );
|
||||
0.5f * std::clamp( (float)Global.fLuminance, 0.f, 1.f ) ) ) );
|
||||
::glPushMatrix();
|
||||
// tilt the precipitation cone against the camera movement vector for crude motion blur
|
||||
// include current wind vector while at it
|
||||
@@ -3587,14 +3587,14 @@ opengl_renderer::Render_Alpha( TTraction *Traction ) {
|
||||
0.5f * Traction->radius() + 1.f,
|
||||
distance - ( 0.5f * Traction->radius() ) ) };
|
||||
::glLineWidth(
|
||||
clamp(
|
||||
std::clamp(
|
||||
0.5f * linealpha + Traction->WireThickness * Traction->radius() / 1000.f,
|
||||
1.f, 1.75f ) );
|
||||
// McZapkie-261102: kolor zalezy od materialu i zasniedzenia
|
||||
::glColor4fv(
|
||||
glm::value_ptr(
|
||||
glm::vec4{
|
||||
Traction->wire_color() /* * ( DebugModeFlag ? 1.f : clamp( m_sunandviewangle, 0.25f, 1.f ) ) */,
|
||||
Traction->wire_color() /* * ( DebugModeFlag ? 1.f : std::clamp( m_sunandviewangle, 0.25f, 1.f ) ) */,
|
||||
linealpha } ) );
|
||||
// render
|
||||
m_geometry.draw( Traction->m_geometry );
|
||||
@@ -3637,7 +3637,7 @@ opengl_renderer::Render_Alpha( scene::lines_node const &Lines ) {
|
||||
distance - ( 0.5f * data.area.radius ) ) :
|
||||
1.f ); // negative width means the lines are always opague
|
||||
::glLineWidth(
|
||||
clamp(
|
||||
std::clamp(
|
||||
0.5f * linealpha + data.line_width * data.area.radius / 1000.f,
|
||||
1.f, 8.f ) );
|
||||
::glColor4fv(
|
||||
@@ -3839,7 +3839,7 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
|
||||
// textures...
|
||||
Bind_Material( material );
|
||||
// ...colors and opacity...
|
||||
auto const opacity { clamp( Material( material )->get_or_guess_opacity(), 0.f, 1.f ) };
|
||||
auto const opacity { std::clamp( Material( material )->get_or_guess_opacity(), 0.f, 1.f ) };
|
||||
if( Submodel->fVisible < 1.f ) {
|
||||
::glColor4f(
|
||||
Submodel->f4Diffuse.r,
|
||||
@@ -3944,13 +3944,13 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
|
||||
if( Submodel->fCosViewAngle > Submodel->fCosFalloffAngle ) {
|
||||
// only bother if the viewer is inside the visibility cone
|
||||
// luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
|
||||
auto glarelevel { clamp(
|
||||
auto glarelevel { std::clamp(
|
||||
std::max<float>(
|
||||
0.6f - Global.fLuminance, // reduce the glare in bright daylight
|
||||
Global.Overcast - 1.f ), // ensure some glare in rainy/foggy conditions
|
||||
0.f, 1.f ) };
|
||||
// view angle attenuation
|
||||
float const anglefactor { clamp(
|
||||
float const anglefactor { std::clamp(
|
||||
( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle ),
|
||||
0.f, 1.f ) };
|
||||
glarelevel *= anglefactor;
|
||||
@@ -4146,8 +4146,8 @@ glm::dvec3
|
||||
opengl_renderer::Update_Mouse_Position() {
|
||||
|
||||
glm::ivec2 mousepos = Global.cursor_pos * Global.fb_size / Global.window_size;
|
||||
mousepos.x = clamp<int>( mousepos.x, 0, Global.fb_size.x - 1 );
|
||||
mousepos.y = clamp<int>( Global.fb_size.y - mousepos.y, 0, Global.fb_size.y - 1 ) ;
|
||||
mousepos.x = std::clamp( mousepos.x, 0, Global.fb_size.x - 1 );
|
||||
mousepos.y = std::clamp(Global.fb_size.y - mousepos.y, 0, Global.fb_size.y - 1);
|
||||
GLfloat pointdepth;
|
||||
::glReadPixels( mousepos.x, mousepos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pointdepth );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user