mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
Use the sq function to force constexpr expressions for numeric literals and enhance readability
This commit is contained in:
@@ -26,8 +26,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
//#define EU07_DEBUG_OPENGL
|
||||
|
||||
int const EU07_PICKBUFFERSIZE{ 1024 }; // size of (square) textures bound with the pick framebuffer
|
||||
int const EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
|
||||
int constexpr EU07_PICKBUFFERSIZE{ 1024 }; // size of (square) textures bound with the pick framebuffer
|
||||
int constexpr EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
|
||||
|
||||
void GLAPIENTRY
|
||||
ErrorCallback( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam ) {
|
||||
@@ -1293,7 +1293,7 @@ bool opengl33_renderer::Render_reflections(viewport_config &vp)
|
||||
|
||||
auto const timestamp{ Timer::GetRenderTime() };
|
||||
if( ( timestamp - m_environmentupdatetime < Global.reflectiontune.update_interval )
|
||||
&& ( glm::length2( m_renderpass.pass_camera.position() - m_environmentupdatelocation ) < 1000.0 * 1000.0 ) ) // length2 is better than length for comparing because it does not require sqrt function
|
||||
&& ( glm::length2( m_renderpass.pass_camera.position() - m_environmentupdatelocation ) < sq(1000.0)) ) // length2 is better than length for comparing because it does not require sqrt function
|
||||
{
|
||||
// run update every 5+ mins of simulation time, or at least 1km from the last location
|
||||
return false;
|
||||
@@ -2690,7 +2690,7 @@ void opengl33_renderer::Render(scene::shape_node const &Shape, bool const Ignore
|
||||
// reflection mode draws simplified version of the shapes, by artificially increasing view range
|
||||
distancesquared =
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET )
|
||||
sq(EU07_REFLECTIONFIDELITYOFFSET)
|
||||
+ glm::length2( ( data.area.center - m_renderpass.pass_camera.position() ) );
|
||||
/*
|
||||
// TBD: take into account distance multipliers?
|
||||
@@ -2764,7 +2764,7 @@ void opengl33_renderer::Render(TAnimModel *Instance)
|
||||
return;
|
||||
}
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
distancesquared += ( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET );
|
||||
distancesquared += sq(EU07_REFLECTIONFIDELITYOFFSET);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2779,7 +2779,7 @@ void opengl33_renderer::Render(TAnimModel *Instance)
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( distancesquared > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( distancesquared > sq(drawdistancethreshold) ) {
|
||||
return;
|
||||
}
|
||||
// second stage visibility cull, reject modelstoo far away to be noticeable
|
||||
@@ -2857,7 +2857,7 @@ bool opengl33_renderer::Render(TDynamicObject *Dynamic)
|
||||
}
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
// NOTE: combined 'squared' distance doesn't equal actual squared (distance + offset) but, eh
|
||||
squaredistance += ( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET );
|
||||
squaredistance += sq(EU07_REFLECTIONFIDELITYOFFSET);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2869,7 +2869,7 @@ bool opengl33_renderer::Render(TDynamicObject *Dynamic)
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow and reflection passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( squaredistance > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( squaredistance > sq(drawdistancethreshold) ) {
|
||||
return false;
|
||||
}
|
||||
// second stage visibility cull, reject vehicles too far away to be noticeable
|
||||
@@ -3779,7 +3779,7 @@ void opengl33_renderer::Render_Alpha(TAnimModel *Instance)
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( distancesquared > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( distancesquared > sq(drawdistancethreshold) ) {
|
||||
return;
|
||||
}
|
||||
// second stage visibility cull, reject modelstoo far away to be noticeable
|
||||
@@ -4619,7 +4619,7 @@ void opengl33_renderer::Update_Lights(light_array &Lights)
|
||||
break;
|
||||
}
|
||||
auto const lightoffset = glm::vec3{scenelight.position - camera};
|
||||
if (glm::length2(lightoffset) > 1000.f * 1000.f) {
|
||||
if (glm::length2(lightoffset) > sq(1000.f)) {
|
||||
// we don't care about lights past arbitrary limit of 1 km.
|
||||
// but there could still be weaker lights which are closer, so keep looking
|
||||
continue;
|
||||
|
||||
@@ -28,9 +28,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "rendering/screenshot.h"
|
||||
#include <imgui/imgui_impl_opengl2.h>
|
||||
|
||||
int const EU07_PICKBUFFERSIZE { 1024 }; // size of (square) textures bound with the pick framebuffer
|
||||
int const EU07_ENVIRONMENTBUFFERSIZE { 256 }; // size of (square) environmental cube map texture
|
||||
int const EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
|
||||
int constexpr EU07_PICKBUFFERSIZE { 1024 }; // size of (square) textures bound with the pick framebuffer
|
||||
int constexpr EU07_ENVIRONMENTBUFFERSIZE { 256 }; // size of (square) environmental cube map texture
|
||||
int constexpr EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
|
||||
|
||||
float const EU07_OPACITYDEFAULT { 0.5f };
|
||||
|
||||
@@ -892,7 +892,7 @@ opengl_renderer::Render_reflections() {
|
||||
|
||||
auto const timestamp { Timer::GetRenderTime() };
|
||||
if( ( timestamp - m_environmentupdatetime < Global.reflectiontune.update_interval )
|
||||
&& ( glm::length2( m_renderpass.camera.position() - m_environmentupdatelocation ) < 1000.0 * 1000.0 ) ) {
|
||||
&& ( glm::length2( m_renderpass.camera.position() - m_environmentupdatelocation ) < sq(1000.0)) ) {
|
||||
// run update every 5+ mins of simulation time, or at least 1km from the last location
|
||||
return false;
|
||||
}
|
||||
@@ -2284,7 +2284,7 @@ opengl_renderer::Render( scene::shape_node const &Shape, bool const Ignorerange
|
||||
// reflection mode draws simplified version of the shapes, by artificially increasing view range
|
||||
distancesquared =
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET )
|
||||
sq(EU07_REFLECTIONFIDELITYOFFSET)
|
||||
// TBD: take into account distance multipliers?
|
||||
+ glm::length2( ( data.area.center - m_renderpass.camera.position() ) ) /* / Global.fDistanceFactor */;
|
||||
break;
|
||||
@@ -2360,7 +2360,7 @@ opengl_renderer::Render( TAnimModel *Instance ) {
|
||||
return;
|
||||
}
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
distancesquared += ( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET );
|
||||
distancesquared += sq(EU07_REFLECTIONFIDELITYOFFSET);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -2374,7 +2374,7 @@ opengl_renderer::Render( TAnimModel *Instance ) {
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( distancesquared > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( distancesquared > sq(drawdistancethreshold) ) {
|
||||
return;
|
||||
}
|
||||
// second stage visibility cull, reject modelstoo far away to be noticeable
|
||||
@@ -2426,14 +2426,14 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCamera.Pos } } / Global.ZoomFactor );
|
||||
if( false == FreeFlyModeFlag ) {
|
||||
// filter out small details if we're in vehicle cab
|
||||
squaredistance = std::max( 100.f * 100.f, squaredistance );
|
||||
squaredistance = std::max( sq(100.f), squaredistance );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case rendermode::cabshadows: {
|
||||
squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCamera.Pos } } / Global.ZoomFactor );
|
||||
// filter out small details
|
||||
squaredistance = std::max( 100.f * 100.f, squaredistance );
|
||||
squaredistance = std::max( sq(100.f), squaredistance );
|
||||
break;
|
||||
}
|
||||
case rendermode::reflections: {
|
||||
@@ -2441,7 +2441,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
// it also ignores zoom settings and distance multipliers
|
||||
squaredistance =
|
||||
std::max(
|
||||
100.f * 100.f,
|
||||
sq(100.f),
|
||||
// TBD: take into account distance multipliers?
|
||||
glm::length2( glm::vec3{ originoffset } ) /* / Global.fDistanceFactor */ );
|
||||
// NOTE: arbitrary draw range limit
|
||||
@@ -2450,7 +2450,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
}
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
// NOTE: combined 'squared' distance doesn't equal actual squared (distance + offset) but, eh
|
||||
squaredistance += ( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET );
|
||||
squaredistance += sq(EU07_REFLECTIONFIDELITYOFFSET);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -2461,7 +2461,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow and reflection passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( squaredistance > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( squaredistance > sq(drawdistancethreshold) ) {
|
||||
return false;
|
||||
}
|
||||
// second stage visibility cull, reject vehicles too far away to be noticeable
|
||||
@@ -3519,7 +3519,7 @@ opengl_renderer::Render_Alpha( TAnimModel *Instance ) {
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( distancesquared > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( distancesquared > sq(drawdistancethreshold) ) {
|
||||
return;
|
||||
}
|
||||
// second stage visibility cull, reject modelstoo far away to be noticeable
|
||||
@@ -4342,7 +4342,7 @@ opengl_renderer::Update_Lights( light_array &Lights ) {
|
||||
}
|
||||
auto const lightoffset = glm::vec3{ scenelight.position - camera };
|
||||
// length2 is better than length for comparing because it does not require sqrt function
|
||||
if( glm::length2( lightoffset ) > 1000.f * 1000.f ) {
|
||||
if( glm::length2( lightoffset ) > sq(1000.f)) {
|
||||
// we don't care about lights past arbitrary limit of 1 km.
|
||||
// but there could still be weaker lights which are closer, so keep looking
|
||||
continue;
|
||||
|
||||
@@ -71,7 +71,7 @@ basic_precipitation::update() {
|
||||
}
|
||||
// ... from camera jump to another location
|
||||
// length2 is better than length for comparing because it does not require sqrt function
|
||||
if( glm::length2( cameramove ) > 100.0 * 100.0 )
|
||||
if( glm::length2( cameramove ) > sq(100.0) )
|
||||
{
|
||||
cameramove = glm::dvec3{ 0.0 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user