16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 07:39:19 +02:00

maintenance: settings item refactoring, include dependencies fixes

This commit is contained in:
tmj-fstate
2018-01-26 16:44:47 +01:00
parent 9d008d2a3e
commit 0124032d3b
92 changed files with 2226 additions and 2233 deletions

View File

@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "renderer.h"
#include "color.h"
#include "globals.h"
#include "timer.h"
#include "simulation.h"
@@ -20,7 +21,7 @@ http://mozilla.org/MPL/2.0/.
#include "traction.h"
#include "uilayer.h"
#include "logs.h"
#include "usefull.h"
#include "utilities.h"
opengl_renderer GfxRenderer;
extern TWorld World;
@@ -28,12 +29,33 @@ extern TWorld World;
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
namespace colors {
void
opengl_light::apply_intensity( float const Factor ) {
glm::vec4 const none { 0.f, 0.f, 0.f, 1.f };
glm::vec4 const white{ 1.f, 1.f, 1.f, 1.f };
if( Factor == 1.0 ) {
::glLightfv( id, GL_AMBIENT, glm::value_ptr( ambient ) );
::glLightfv( id, GL_DIFFUSE, glm::value_ptr( diffuse ) );
::glLightfv( id, GL_SPECULAR, glm::value_ptr( specular ) );
}
else {
// temporary light scaling mechanics (ultimately this work will be left to the shaders
glm::vec4 scaledambient( ambient.r * Factor, ambient.g * Factor, ambient.b * Factor, ambient.a );
glm::vec4 scaleddiffuse( diffuse.r * Factor, diffuse.g * Factor, diffuse.b * Factor, diffuse.a );
glm::vec4 scaledspecular( specular.r * Factor, specular.g * Factor, specular.b * Factor, specular.a );
glLightfv( id, GL_AMBIENT, glm::value_ptr( scaledambient ) );
glLightfv( id, GL_DIFFUSE, glm::value_ptr( scaleddiffuse ) );
glLightfv( id, GL_SPECULAR, glm::value_ptr( scaledspecular ) );
}
}
void
opengl_light::apply_angle() {
::glLightfv( id, GL_POSITION, glm::value_ptr( position ) );
::glLightfv( id, GL_SPOT_DIRECTION, glm::value_ptr( glm::vec4{ direction, ( is_omnidirectional ? 1.f : 0.f ) } ) );
}
} // namespace colors
void
opengl_camera::update_frustum( glm::mat4 const &Projection, glm::mat4 const &Modelview ) {
@@ -100,7 +122,7 @@ opengl_renderer::Init( GLFWwindow *Window ) {
glShadeModel( GL_SMOOTH ); // Enable Smooth Shading
m_geometry.units().texture = (
Global::BasicRenderer ?
Global.BasicRenderer ?
std::vector<GLint>{ m_diffusetextureunit } :
std::vector<GLint>{ m_normaltextureunit, m_diffusetextureunit } );
m_textures.assign_units( m_helpertextureunit, m_shadowtextureunit, m_normaltextureunit, m_diffusetextureunit ); // TODO: add reflections unit
@@ -124,7 +146,7 @@ opengl_renderer::Init( GLFWwindow *Window ) {
::glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR );
::glMaterialf( GL_FRONT, GL_SHININESS, 15.0f );
if( true == Global::ScaleSpecularValues ) {
if( true == Global.ScaleSpecularValues ) {
m_specularopaquescalefactor = 0.25f;
m_speculartranslucentscalefactor = 1.5f;
}
@@ -136,23 +158,21 @@ opengl_renderer::Init( GLFWwindow *Window ) {
::glEnable( GL_LIGHTING );
::glEnable( GL_LIGHT0 );
Global::DayLight.id = opengl_renderer::sunlight;
// directional light
// TODO, TBD: test omni-directional variant
Global::DayLight.position[ 3 ] = 1.0f;
::glLightf( opengl_renderer::sunlight, GL_SPOT_CUTOFF, 90.0f );
m_sunlight.id = opengl_renderer::sunlight;
// ::glLightf( opengl_renderer::sunlight, GL_SPOT_CUTOFF, 90.0f );
Global.DayLight.is_omnidirectional = true;
// rgb value for 5780 kelvin
Global::DayLight.diffuse[ 0 ] = 255.0f / 255.0f;
Global::DayLight.diffuse[ 1 ] = 242.0f / 255.0f;
Global::DayLight.diffuse[ 2 ] = 231.0f / 255.0f;
Global.DayLight.diffuse[ 0 ] = 255.0f / 255.0f;
Global.DayLight.diffuse[ 1 ] = 242.0f / 255.0f;
Global.DayLight.diffuse[ 2 ] = 231.0f / 255.0f;
// create dynamic light pool
for( int idx = 0; idx < Global::DynamicLightCount; ++idx ) {
for( int idx = 0; idx < Global.DynamicLightCount; ++idx ) {
opengl_light light;
light.id = GL_LIGHT1 + idx;
light.position[ 3 ] = 1.0f;
light.is_omnidirectional = true;
::glLightf( light.id, GL_SPOT_CUTOFF, 7.5f );
::glLightf( light.id, GL_SPOT_EXPONENT, 7.5f );
::glLightf( light.id, GL_CONSTANT_ATTENUATION, 0.0f );
@@ -204,7 +224,7 @@ opengl_renderer::Init( GLFWwindow *Window ) {
}
#endif
// shadowmap resources
if( ( true == Global::RenderShadows )
if( ( true == Global.RenderShadows )
&& ( true == m_framebuffersupport ) ) {
// primary shadow map
{
@@ -252,7 +272,7 @@ opengl_renderer::Init( GLFWwindow *Window ) {
}
else {
ErrorLog( "Shadows framebuffer setup failed" );
Global::RenderShadows = false;
Global.RenderShadows = false;
}
// switch back to primary render target for now
::glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
@@ -305,14 +325,14 @@ opengl_renderer::Init( GLFWwindow *Window ) {
}
else {
ErrorLog( "Cab shadows framebuffer setup failed" );
Global::RenderShadows = false;
Global.RenderShadows = false;
}
}
// switch back to primary render target for now
::glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
}
// environment cube map resources
if( ( false == Global::BasicRenderer )
if( ( false == Global.BasicRenderer )
&& ( true == m_framebuffersupport ) ) {
// texture:
::glGenTextures( 1, &m_environmentcubetexture );
@@ -417,8 +437,8 @@ opengl_renderer::Render_pass( rendermode const Mode ) {
case rendermode::color: {
if( ( true == Global::RenderShadows )
&& ( false == Global::bWireFrame )
if( ( true == Global.RenderShadows )
&& ( false == Global.bWireFrame )
&& ( true == World.InitPerformed() )
&& ( m_shadowcolor != colors::white ) ) {
@@ -465,7 +485,7 @@ opengl_renderer::Render_pass( rendermode const Mode ) {
}
}
::glViewport( 0, 0, Global::iWindowWidth, Global::iWindowHeight );
::glViewport( 0, 0, Global.iWindowWidth, Global.iWindowHeight );
if( World.InitPerformed() ) {
auto const skydomecolour = World.Environment.m_skydome.GetAverageColor();
@@ -493,7 +513,7 @@ opengl_renderer::Render_pass( rendermode const Mode ) {
::glColor4f( 1.f, 0.9f, 0.8f, 1.f );
::glDisable( GL_LIGHTING );
::glDisable( GL_TEXTURE_2D );
if( ( true == Global::RenderShadows ) && ( false == Global::bWireFrame ) ) {
if( ( true == Global.RenderShadows ) && ( false == Global.bWireFrame ) ) {
m_shadowpass.camera.draw( m_renderpass.camera.position() - m_shadowpass.camera.position() );
}
if( DebugCameraFlag ) {
@@ -758,12 +778,12 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
if( false == World.InitPerformed() ) { return; }
// setup draw range
switch( Mode ) {
case rendermode::color: { Config.draw_range = Global::BaseDrawRange; break; }
case rendermode::shadows: { Config.draw_range = Global::BaseDrawRange * 0.5f; break; }
case rendermode::cabshadows: { Config.draw_range = ( Global::pWorld->train()->Dynamic()->MoverParameters->ActiveCab != 0 ? 10.f : 20.f ); break; }
case rendermode::reflections: { Config.draw_range = Global::BaseDrawRange; break; }
case rendermode::color: { Config.draw_range = Global.BaseDrawRange; break; }
case rendermode::shadows: { Config.draw_range = Global.BaseDrawRange * 0.5f; break; }
case rendermode::cabshadows: { Config.draw_range = ( Global.pWorld->train()->Dynamic()->MoverParameters->ActiveCab != 0 ? 10.f : 20.f ); 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; }
case rendermode::pickscenery: { Config.draw_range = Global.BaseDrawRange * 0.5f; break; }
default: { Config.draw_range = 0.f; break; }
}
// setup camera
@@ -776,23 +796,23 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
case rendermode::color: {
// modelview
if( ( false == DebugCameraFlag ) || ( true == Ignoredebug ) ) {
camera.position() = Global::pCameraPosition;
camera.position() = Global.pCameraPosition;
World.Camera.SetMatrix( viewmatrix );
}
else {
camera.position() = Global::DebugCameraPosition;
camera.position() = Global.DebugCameraPosition;
World.DebugCamera.SetMatrix( viewmatrix );
}
// projection
auto const zfar = Config.draw_range * Global::fDistanceFactor * Zfar;
auto const zfar = Config.draw_range * Global.fDistanceFactor * Zfar;
auto const znear = (
Znear > 0.f ?
Znear * zfar :
0.1f * Global::ZoomFactor );
0.1f * Global.ZoomFactor );
camera.projection() *=
glm::perspective(
glm::radians( Global::FieldOfView / Global::ZoomFactor ),
std::max( 1.f, (float)Global::iWindowWidth ) / std::max( 1.f, (float)Global::iWindowHeight ),
glm::radians( Global.FieldOfView / Global.ZoomFactor ),
std::max( 1.f, (float)Global.iWindowWidth ) / std::max( 1.f, (float)Global.iWindowHeight ),
znear,
zfar );
break;
@@ -800,7 +820,7 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
case rendermode::shadows: {
// calculate lightview boundaries based on relevant area of the world camera frustum:
// ...setup chunk of frustum we're interested in...
auto const zfar = std::min( 1.f, Global::shadowtune.depth / ( Global::BaseDrawRange * Global::fDistanceFactor ) * std::max( 1.f, Global::ZoomFactor * 0.5f ) );
auto const zfar = std::min( 1.f, Global.shadowtune.depth / ( Global.BaseDrawRange * Global.fDistanceFactor ) * std::max( 1.f, Global.ZoomFactor * 0.5f ) );
renderpass_config worldview;
setup_pass( worldview, rendermode::color, 0.f, zfar, true );
auto &frustumchunkshapepoints = worldview.camera.frustum_points();
@@ -811,9 +831,9 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
// ...cap the vertical angle to keep shadows from getting too long...
auto const lightvector =
glm::normalize( glm::vec3{
Global::DayLight.direction.x,
std::min( Global::DayLight.direction.y, -0.2f ),
Global::DayLight.direction.z } );
Global.DayLight.direction.x,
std::min( Global.DayLight.direction.y, -0.2f ),
Global.DayLight.direction.z } );
// ...place the light source at the calculated centre and setup world space light view matrix...
camera.position() = worldview.camera.position() + glm::dvec3{ frustumchunkcentre };
viewmatrix *= glm::lookAt(
@@ -830,7 +850,7 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
}
bounding_box( frustumchunkmin, frustumchunkmax, std::begin( frustumchunkshapepoints ), std::end( frustumchunkshapepoints ) );
// quantize the frustum points and add some padding, to reduce shadow shimmer on scale changes
auto const quantizationstep{ std::min( Global::shadowtune.depth, 50.f ) };
auto const quantizationstep{ std::min( Global.shadowtune.depth, 50.f ) };
frustumchunkmin = quantizationstep * glm::floor( frustumchunkmin * ( 1.f / quantizationstep ) );
frustumchunkmax = quantizationstep * glm::ceil( frustumchunkmax * ( 1.f / quantizationstep ) );
// ...use the dimensions to set up light projection boundaries...
@@ -844,16 +864,16 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
// fixed ortho projection from old build, for quick quality comparisons
camera.projection() *=
glm::ortho(
-Global::shadowtune.width, Global::shadowtune.width,
-Global::shadowtune.width, Global::shadowtune.width,
-Global::shadowtune.depth, Global::shadowtune.depth );
camera.position() = Global::pCameraPosition - glm::dvec3{ Global::DayLight.direction };
if( camera.position().y - Global::pCameraPosition.y < 0.1 ) {
camera.position().y = Global::pCameraPosition.y + 0.1;
-Global.shadowtune.width, Global.shadowtune.width,
-Global.shadowtune.width, Global.shadowtune.width,
-Global.shadowtune.depth, Global.shadowtune.depth );
camera.position() = Global.pCameraPosition - glm::dvec3{ Global.DayLight.direction };
if( camera.position().y - Global.pCameraPosition.y < 0.1 ) {
camera.position().y = Global.pCameraPosition.y + 0.1;
}
viewmatrix *= glm::lookAt(
camera.position(),
glm::dvec3{ Global::pCameraPosition },
glm::dvec3{ Global.pCameraPosition },
glm::dvec3{ 0.f, 1.f, 0.f } );
*/
// ... and adjust the projection to sample complete shadow map texels:
@@ -874,13 +894,13 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
// modelview
auto const lightvector =
glm::normalize( glm::vec3{
Global::DayLight.direction.x,
std::min( Global::DayLight.direction.y, -0.2f ),
Global::DayLight.direction.z } );
camera.position() = Global::pCameraPosition - glm::dvec3 { lightvector };
Global.DayLight.direction.x,
std::min( Global.DayLight.direction.y, -0.2f ),
Global.DayLight.direction.z } );
camera.position() = Global.pCameraPosition - glm::dvec3 { lightvector };
viewmatrix *= glm::lookAt(
camera.position(),
glm::dvec3 { Global::pCameraPosition },
glm::dvec3 { Global.pCameraPosition },
glm::dvec3 { 0.f, 1.f, 0.f } );
// projection
auto const maphalfsize { Config.draw_range * 0.5f };
@@ -902,8 +922,8 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
// modelview
camera.position() = (
( ( true == DebugCameraFlag ) && ( false == Ignoredebug ) ) ?
Global::DebugCameraPosition :
Global::pCameraPosition );
Global.DebugCameraPosition :
Global.pCameraPosition );
glm::dvec3 const cubefacetargetvectors[ 6 ] = { { 1.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { 0.0, 0.0, -1.0 } };
glm::dvec3 const cubefaceupvectors[ 6 ] = { { 0.0, -1.0, 0.0 }, { 0.0, -1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { 0.0, 0.0, -1.0 }, { 0.0, -1.0, 0.0 }, { 0.0, -1.0, 0.0 } };
auto const cubefaceindex = m_environmentcubetextureface - GL_TEXTURE_CUBE_MAP_POSITIVE_X;
@@ -917,8 +937,8 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
glm::perspective(
glm::radians( 90.f ),
1.f,
0.1f * Global::ZoomFactor,
Config.draw_range * Global::fDistanceFactor );
0.1f * Global.ZoomFactor,
Config.draw_range * Global.fDistanceFactor );
break;
}
@@ -926,15 +946,15 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
case rendermode::pickscenery: {
// TODO: scissor test for pick modes
// modelview
camera.position() = Global::pCameraPosition;
camera.position() = Global.pCameraPosition;
World.Camera.SetMatrix( viewmatrix );
// projection
camera.projection() *=
glm::perspective(
glm::radians( Global::FieldOfView / Global::ZoomFactor ),
std::max( 1.f, (float)Global::iWindowWidth ) / std::max( 1.f, (float)Global::iWindowHeight ),
0.1f * Global::ZoomFactor,
Config.draw_range * Global::fDistanceFactor );
glm::radians( Global.FieldOfView / Global.ZoomFactor ),
std::max( 1.f, (float)Global.iWindowWidth ) / std::max( 1.f, (float)Global.iWindowHeight ),
0.1f * Global.ZoomFactor,
Config.draw_range * Global.fDistanceFactor );
break;
}
default: {
@@ -984,14 +1004,14 @@ opengl_renderer::setup_drawing( bool const Alpha ) {
case rendermode::reflections: {
::glEnable( GL_LIGHTING );
::glShadeModel( GL_SMOOTH );
if( Global::iMultisampling ) {
if( Global.iMultisampling ) {
::glEnable( GL_MULTISAMPLE );
}
// setup fog
if( Global::fFogEnd > 0 ) {
if( Global.fFogEnd > 0 ) {
// fog setup
::glFogfv( GL_FOG_COLOR, Global::FogColor );
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / Global::fFogEnd ) );
::glFogfv( GL_FOG_COLOR, Global.FogColor );
::glFogf( GL_FOG_DENSITY, static_cast<GLfloat>( 1.0 / Global.fFogEnd ) );
::glEnable( GL_FOG );
}
else { ::glDisable( GL_FOG ); }
@@ -1005,7 +1025,7 @@ opengl_renderer::setup_drawing( bool const Alpha ) {
::glColor4fv( glm::value_ptr( colors::white ) );
::glDisable( GL_LIGHTING );
::glShadeModel( GL_FLAT );
if( Global::iMultisampling ) {
if( Global.iMultisampling ) {
::glDisable( GL_MULTISAMPLE );
}
::glDisable( GL_FOG );
@@ -1028,7 +1048,7 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
select_unit( m_helpertextureunit );
if( ( true == Reflections )
|| ( ( true == Global::RenderShadows ) && ( true == Shadows ) && ( false == Global::bWireFrame ) ) ) {
|| ( ( true == Global.RenderShadows ) && ( true == Shadows ) && ( false == Global.bWireFrame ) ) ) {
// we need to have texture on the helper for either the reflection and shadow generation (or both)
if( true == m_environmentcubetexturesupport ) {
// bind dynamic environment cube if it's enabled...
@@ -1051,7 +1071,7 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
}
}
if( ( true == Global::RenderShadows ) && ( true == Shadows ) && ( false == Global::bWireFrame ) ) {
if( ( true == Global.RenderShadows ) && ( true == Shadows ) && ( false == Global.bWireFrame ) ) {
::glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
::glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, glm::value_ptr( m_shadowcolor ) );
@@ -1107,9 +1127,9 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
// shadow texture unit.
// interpolates between primary colour and the previous unit, which should hold darkened variant of the primary colour
if( m_shadowtextureunit >= 0 ) {
if( ( true == Global::RenderShadows )
if( ( true == Global.RenderShadows )
&& ( true == Shadows )
&& ( false == Global::bWireFrame )
&& ( false == Global.bWireFrame )
&& ( m_shadowcolor != colors::white ) ) {
select_unit( m_shadowtextureunit );
@@ -1211,8 +1231,8 @@ void
opengl_renderer::setup_shadow_map( GLuint const Texture, glm::mat4 const &Transformation ) {
if( ( m_shadowtextureunit == -1 )
|| ( false == Global::RenderShadows )
|| ( true == Global::bWireFrame )
|| ( false == Global.RenderShadows )
|| ( true == Global.bWireFrame )
|| ( m_shadowcolor == colors::white ) ) {
// shadows are off
return;
@@ -1241,9 +1261,9 @@ opengl_renderer::switch_units( bool const Diffuse, bool const Shadows, bool cons
select_unit( m_helpertextureunit );
if( ( true == Reflections )
|| ( ( true == Global::RenderShadows )
|| ( ( true == Global.RenderShadows )
&& ( true == Shadows )
&& ( false == Global::bWireFrame )
&& ( false == Global.bWireFrame )
&& ( m_shadowcolor != colors::white ) ) ) {
if( true == m_environmentcubetexturesupport ) {
::glEnable( GL_TEXTURE_CUBE_MAP );
@@ -1263,7 +1283,7 @@ opengl_renderer::switch_units( bool const Diffuse, bool const Shadows, bool cons
}
// shadow texture unit.
if( m_shadowtextureunit >= 0 ) {
if( ( true == Global::RenderShadows ) && ( true == Shadows ) && ( false == Global::bWireFrame ) ) {
if( ( true == Global.RenderShadows ) && ( true == Shadows ) && ( false == Global.bWireFrame ) ) {
select_unit( m_shadowtextureunit );
::glEnable( GL_TEXTURE_2D );
@@ -1312,6 +1332,33 @@ opengl_renderer::setup_shadow_color( glm::vec4 const &Shadowcolor ) {
select_unit( m_diffusetextureunit );
}
void
opengl_renderer::setup_environment_light( TEnvironmentType const Environment ) {
if( m_environment == Environment ) { return; }
switch( Environment ) {
case e_flat: {
m_sunlight.apply_intensity();
m_environment = e_flat;
break;
}
case e_canyon: {
m_sunlight.apply_intensity( 0.4f );
m_environment = Environment;
break;
}
case e_tunnel: {
m_sunlight.apply_intensity( 0.2f );
m_environment = Environment;
break;
}
default: {
break;
}
}
}
bool
opengl_renderer::Render( world_environment *Environment ) {
@@ -1328,9 +1375,9 @@ opengl_renderer::Render( world_environment *Environment ) {
// soften shadows depending on sky overcast factor
m_shadowcolor = glm::min(
colors::white,
m_shadowcolor + glm::vec4{ glm::vec3{ 0.5f * Global::Overcast }, 1.f } );
m_shadowcolor + glm::vec4{ glm::vec3{ 0.5f * Global.Overcast }, 1.f } );
if( Global::bWireFrame ) {
if( Global.bWireFrame ) {
// bez nieba w trybie rysowania linii
return false;
}
@@ -1343,7 +1390,7 @@ opengl_renderer::Render( world_environment *Environment ) {
// skydome
Environment->m_skydome.Render();
if( true == Global::bUseVBO ) {
if( true == Global.bUseVBO ) {
// skydome uses a custom vbo which could potentially confuse the main geometry system. hardly elegant but, eh
gfx::opengl_vbogeometrybank::reset();
}
@@ -1352,7 +1399,7 @@ opengl_renderer::Render( world_environment *Environment ) {
// setup
::glPushMatrix();
::glRotatef( Environment->m_stars.m_latitude, 1.f, 0.f, 0.f ); // ustawienie osi OY na północ
::glRotatef( -std::fmod( (float)Global::fTimeAngleDeg, 360.f ), 0.f, 1.f, 0.f ); // obrót dobowy osi OX
::glRotatef( -std::fmod( (float)Global.fTimeAngleDeg, 360.f ), 0.f, 1.f, 0.f ); // obrót dobowy osi OX
::glPointSize( 2.f );
// render
GfxRenderer.Render( Environment->m_stars.m_stars, nullptr, 1.0 );
@@ -1407,7 +1454,7 @@ opengl_renderer::Render( world_environment *Environment ) {
{
Bind_Texture( m_moontexture );
glm::vec3 mooncolor( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f );
::glColor4f( mooncolor.x, mooncolor.y, mooncolor.z, static_cast<GLfloat>( 1.0 - Global::fLuminance * 0.5 ) );
::glColor4f( mooncolor.x, mooncolor.y, mooncolor.z, static_cast<GLfloat>( 1.0 - Global.fLuminance * 0.5 ) );
auto const moonposition = modelview * glm::vec4( Environment->m_moon.getDirection(), 1.0f );
::glPushMatrix();
@@ -1453,7 +1500,7 @@ opengl_renderer::Render( world_environment *Environment ) {
GL_LIGHT_MODEL_AMBIENT,
glm::value_ptr(
interpolate( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f )
* interpolate( 1.f, 0.35f, Global::Overcast / 2.f ) // overcast darkens the clouds
* interpolate( 1.f, 0.35f, Global.Overcast / 2.f ) // overcast darkens the clouds
* 2.5f // arbitrary adjustment factor
) );
// render
@@ -1465,8 +1512,8 @@ opengl_renderer::Render( world_environment *Environment ) {
::glDisable( GL_LIGHTING );
}
Global::DayLight.apply_angle();
Global::DayLight.apply_intensity();
m_sunlight.apply_angle();
m_sunlight.apply_intensity();
::glPopMatrix();
::glDepthMask( GL_TRUE );
@@ -1523,7 +1570,7 @@ void
opengl_renderer::Bind_Material( material_handle const Material ) {
auto const &material = m_materials.material( Material );
if( false == Global::BasicRenderer ) {
if( false == Global.BasicRenderer ) {
m_textures.bind( textureunit::normals, material.texture2 );
}
m_textures.bind( textureunit::diffuse, material.texture1 );
@@ -1569,7 +1616,7 @@ opengl_renderer::Render( scene::basic_region *Region ) {
glm::vec3 const cameraposition { m_renderpass.camera.position() };
auto const camerax = static_cast<int>( std::floor( cameraposition.x / scene::EU07_SECTIONSIZE + scene::EU07_REGIONSIDESECTIONCOUNT / 2 ) );
auto const cameraz = static_cast<int>( std::floor( cameraposition.z / scene::EU07_SECTIONSIZE + scene::EU07_REGIONSIDESECTIONCOUNT / 2 ) );
int const segmentcount = 2 * static_cast<int>( std::ceil( m_renderpass.draw_range * Global::fDistanceFactor / scene::EU07_SECTIONSIZE ) );
int const segmentcount = 2 * static_cast<int>( std::ceil( m_renderpass.draw_range * Global.fDistanceFactor / scene::EU07_SECTIONSIZE ) );
int const originx = camerax - segmentcount / 2;
int const originz = cameraz - segmentcount / 2;
@@ -1590,6 +1637,7 @@ opengl_renderer::Render( scene::basic_region *Region ) {
switch( m_renderpass.draw_mode ) {
case rendermode::color: {
m_sunlight = Global.DayLight;
Update_Lights( simulation::Lights );
Render( std::begin( m_sectionqueue ), std::end( m_sectionqueue ) );
@@ -1851,11 +1899,11 @@ opengl_renderer::Render( scene::shape_node const &Shape, bool const Ignorerange
switch( m_renderpass.draw_mode ) {
case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
distancesquared = SquareMagnitude( ( data.area.center - Global::pCameraPosition ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
default: {
distancesquared = SquareMagnitude( ( data.area.center - m_renderpass.camera.position() ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = glm::length2( ( data.area.center - m_renderpass.camera.position() ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
}
@@ -1875,7 +1923,7 @@ opengl_renderer::Render( scene::shape_node const &Shape, bool const Ignorerange
// NOTE: ambient component is set by diffuse component
// NOTE: for the time being non-instanced shapes are rendered without specular component due to wrong/arbitrary values set in legacy scenarios
// TBD, TODO: find a way to resolve this with the least amount of tears?
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( data.lighting.specular * Global::DayLight.specular.a * m_specularopaquescalefactor ) );
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( data.lighting.specular * Global.DayLight.specular.a * m_specularopaquescalefactor ) );
*/
break;
}
@@ -1905,11 +1953,11 @@ opengl_renderer::Render( TAnimModel *Instance ) {
switch( m_renderpass.draw_mode ) {
case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
distancesquared = SquareMagnitude( ( Instance->location() - Global::pCameraPosition ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
default: {
distancesquared = SquareMagnitude( ( Instance->location() - m_renderpass.camera.position() ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = Math3D::SquareMagnitude( ( Instance->location() - m_renderpass.camera.position() ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
}
@@ -1959,11 +2007,11 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
float squaredistance;
switch( m_renderpass.draw_mode ) {
case rendermode::shadows: {
squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global::pCameraPosition } } / Global::ZoomFactor ) / Global::fDistanceFactor;
squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCameraPosition } } / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
default: {
squaredistance = glm::length2( glm::vec3{ originoffset } / Global::ZoomFactor ) / Global::fDistanceFactor;
squaredistance = glm::length2( glm::vec3{ originoffset } / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
}
@@ -1978,7 +2026,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
case rendermode::color: {
if( Dynamic->fShade > 0.0f ) {
// change light level based on light level of the occupied track
Global::DayLight.apply_intensity( Dynamic->fShade );
m_sunlight.apply_intensity( Dynamic->fShade );
}
m_renderspecular = true; // vehicles are rendered with specular component. static models without, at least for the time being
// render
@@ -2011,7 +2059,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
m_renderspecular = false;
if( Dynamic->fShade > 0.0f ) {
// restore regular light level
Global::DayLight.apply_intensity();
m_sunlight.apply_intensity();
}
break;
}
@@ -2077,7 +2125,7 @@ opengl_renderer::Render_cab( TDynamicObject const *Dynamic, bool const Alpha ) {
// render path specific setup:
if( Dynamic->fShade > 0.0f ) {
// change light level based on light level of the occupied track
Global::DayLight.apply_intensity( Dynamic->fShade );
m_sunlight.apply_intensity( Dynamic->fShade );
}
if( Dynamic->InteriorLightLevel > 0.f ) {
// crude way to light the cabin, until we have something more complete in place
@@ -2095,7 +2143,7 @@ opengl_renderer::Render_cab( TDynamicObject const *Dynamic, bool const Alpha ) {
// post-render restore
if( Dynamic->fShade > 0.0f ) {
// change light level based on light level of the occupied track
Global::DayLight.apply_intensity();
m_sunlight.apply_intensity();
}
if( Dynamic->InteriorLightLevel > 0.0f ) {
// reset the overall ambient
@@ -2242,14 +2290,14 @@ opengl_renderer::Render( TSubModel *Submodel ) {
}
// ...colors...
::glColor3fv( glm::value_ptr( Submodel->f4Diffuse ) ); // McZapkie-240702: zamiast ub
if( ( true == m_renderspecular ) && ( Global::DayLight.specular.a > 0.01f ) ) {
if( ( true == m_renderspecular ) && ( Global.DayLight.specular.a > 0.01f ) ) {
// specular strength in legacy models is set uniformly to 150, 150, 150 so we scale it down for opaque elements
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( Submodel->f4Specular * Global::DayLight.specular.a * m_specularopaquescalefactor ) );
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( Submodel->f4Specular * Global.DayLight.specular.a * m_specularopaquescalefactor ) );
::glEnable( GL_RESCALE_NORMAL );
}
// ...luminance
auto const unitstate = m_unitstate;
if( Global::fLuminance < Submodel->fLight ) {
if( Global.fLuminance < Submodel->fLight ) {
// zeby swiecilo na kolorowo
::glMaterialfv( GL_FRONT, GL_EMISSION, glm::value_ptr( Submodel->f4Diffuse * Submodel->f4Emision.a ) );
// disable shadows so they don't obstruct self-lit items
@@ -2263,10 +2311,10 @@ opengl_renderer::Render( TSubModel *Submodel ) {
m_geometry.draw( Submodel->m_geometry );
// post-draw reset
if( ( true == m_renderspecular ) && ( Global::DayLight.specular.a > 0.01f ) ) {
if( ( true == m_renderspecular ) && ( Global.DayLight.specular.a > 0.01f ) ) {
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( colors::none ) );
}
if( Global::fLuminance < Submodel->fLight ) {
if( Global.fLuminance < Submodel->fLight ) {
// restore default (lack of) brightness
::glMaterialfv( GL_FRONT, GL_EMISSION, glm::value_ptr( colors::none ) );
/*
@@ -2402,7 +2450,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
// colour points are only rendered in colour mode(s)
case rendermode::color:
case rendermode::reflections: {
if( Global::fLuminance < Submodel->fLight ) {
if( Global.fLuminance < Submodel->fLight ) {
// material configuration:
::glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT );
@@ -2456,7 +2504,7 @@ opengl_renderer::Render( TTrack *Track ) {
switch( m_renderpass.draw_mode ) {
case rendermode::color:
case rendermode::reflections: {
Track->EnvironmentSet();
setup_environment_light( Track->eEnvironment );
if( Track->m_material1 != 0 ) {
Bind_Material( Track->m_material1 );
m_geometry.draw( std::begin( Track->Geometry1 ), std::end( Track->Geometry1 ) );
@@ -2465,7 +2513,7 @@ opengl_renderer::Render( TTrack *Track ) {
Bind_Material( Track->m_material2 );
m_geometry.draw( std::begin( Track->Geometry2 ), std::end( Track->Geometry2 ) );
}
Track->EnvironmentReset();
setup_environment_light();
break;
}
case rendermode::shadows: {
@@ -2529,10 +2577,10 @@ opengl_renderer::Render( scene::basic_cell::path_sequence::const_iterator First,
switch( m_renderpass.draw_mode ) {
case rendermode::color:
case rendermode::reflections: {
track->EnvironmentSet();
setup_environment_light( track->eEnvironment );
Bind_Material( track->m_material1 );
m_geometry.draw( std::begin( track->Geometry1 ), std::end( track->Geometry1 ) );
track->EnvironmentReset();
setup_environment_light();
break;
}
case rendermode::shadows: {
@@ -2567,10 +2615,10 @@ opengl_renderer::Render( scene::basic_cell::path_sequence::const_iterator First,
switch( m_renderpass.draw_mode ) {
case rendermode::color:
case rendermode::reflections: {
track->EnvironmentSet();
setup_environment_light( track->eEnvironment );
Bind_Material( track->m_material2 );
m_geometry.draw( std::begin( track->Geometry2 ), std::end( track->Geometry2 ) );
track->EnvironmentReset();
setup_environment_light();
break;
}
case rendermode::shadows: {
@@ -2712,7 +2760,7 @@ opengl_renderer::Render_Alpha( cell_sequence::reverse_iterator First, cell_seque
::glPushMatrix();
auto const originoffset { cell->m_area.center - m_renderpass.camera.position() };
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
if( !Global::bSmoothTraction ) {
if( !Global.bSmoothTraction ) {
// na liniach kiepsko wygląda - robi gradient
::glDisable( GL_LINE_SMOOTH );
}
@@ -2722,7 +2770,7 @@ opengl_renderer::Render_Alpha( cell_sequence::reverse_iterator First, cell_seque
for( auto &lines : cell->m_lines ) { Render_Alpha( lines ); }
// post-render cleanup
::glLineWidth( 1.0 );
if( !Global::bSmoothTraction ) {
if( !Global.bSmoothTraction ) {
::glEnable( GL_LINE_SMOOTH );
}
::glPopMatrix();
@@ -2746,11 +2794,11 @@ opengl_renderer::Render_Alpha( TAnimModel *Instance ) {
switch( m_renderpass.draw_mode ) {
case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
distancesquared = SquareMagnitude( ( Instance->location() - Global::pCameraPosition ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
default: {
distancesquared = SquareMagnitude( ( Instance->location() - m_renderpass.camera.position() ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = glm::length2( ( Instance->location() - m_renderpass.camera.position() ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
}
@@ -2778,11 +2826,11 @@ opengl_renderer::Render_Alpha( TTraction *Traction ) {
switch( m_renderpass.draw_mode ) {
case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
distancesquared = SquareMagnitude( ( Traction->location() - Global::pCameraPosition ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = Math3D::SquareMagnitude( ( Traction->location() - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
default: {
distancesquared = SquareMagnitude( ( Traction->location() - m_renderpass.camera.position() ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = glm::length2( ( Traction->location() - m_renderpass.camera.position() ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
}
@@ -2839,11 +2887,11 @@ opengl_renderer::Render_Alpha( scene::lines_node const &Lines ) {
switch( m_renderpass.draw_mode ) {
case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
distancesquared = SquareMagnitude( ( data.area.center - Global::pCameraPosition ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCameraPosition ) / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
default: {
distancesquared = SquareMagnitude( ( data.area.center - m_renderpass.camera.position() ) / Global::ZoomFactor ) / Global::fDistanceFactor;
distancesquared = glm::length2( ( data.area.center - m_renderpass.camera.position() ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
}
@@ -2867,7 +2915,7 @@ opengl_renderer::Render_Alpha( scene::lines_node const &Lines ) {
::glColor4fv(
glm::value_ptr(
glm::vec4{
glm::vec3{ data.lighting.diffuse * Global::DayLight.ambient }, // w zaleznosci od koloru swiatla
glm::vec3{ data.lighting.diffuse * Global.DayLight.ambient }, // w zaleznosci od koloru swiatla
std::min( 1.f, linealpha ) } ) );
// render
m_geometry.draw( data.geometry );
@@ -2887,11 +2935,11 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) {
float squaredistance;
switch( m_renderpass.draw_mode ) {
case rendermode::shadows: {
squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global::pCameraPosition } } / Global::ZoomFactor ) / Global::fDistanceFactor;
squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCameraPosition } } / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
default: {
squaredistance = glm::length2( glm::vec3{ originoffset } / Global::ZoomFactor ) / Global::fDistanceFactor;
squaredistance = glm::length2( glm::vec3{ originoffset } / Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
}
@@ -2903,7 +2951,7 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) {
if( Dynamic->fShade > 0.0f ) {
// change light level based on light level of the occupied track
Global::DayLight.apply_intensity( Dynamic->fShade );
m_sunlight.apply_intensity( Dynamic->fShade );
}
m_renderspecular = true;
@@ -2937,7 +2985,7 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) {
m_renderspecular = false;
if( Dynamic->fShade > 0.0f ) {
// restore regular light level
Global::DayLight.apply_intensity();
m_sunlight.apply_intensity();
}
::glPopMatrix();
@@ -3052,12 +3100,12 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
}
// ...colors...
::glColor3fv( glm::value_ptr( Submodel->f4Diffuse ) ); // McZapkie-240702: zamiast ub
if( ( true == m_renderspecular ) && ( Global::DayLight.specular.a > 0.01f ) ) {
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( Submodel->f4Specular * Global::DayLight.specular.a * m_speculartranslucentscalefactor ) );
if( ( true == m_renderspecular ) && ( Global.DayLight.specular.a > 0.01f ) ) {
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( Submodel->f4Specular * Global.DayLight.specular.a * m_speculartranslucentscalefactor ) );
}
// ...luminance
auto const unitstate = m_unitstate;
if( Global::fLuminance < Submodel->fLight ) {
if( Global.fLuminance < Submodel->fLight ) {
// zeby swiecilo na kolorowo
::glMaterialfv( GL_FRONT, GL_EMISSION, glm::value_ptr( Submodel->f4Diffuse * Submodel->f4Emision.a ) );
// disable shadows so they don't obstruct self-lit items
@@ -3071,10 +3119,10 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
m_geometry.draw( Submodel->m_geometry );
// post-draw reset
if( ( true == m_renderspecular ) && ( Global::DayLight.specular.a > 0.01f ) ) {
if( ( true == m_renderspecular ) && ( Global.DayLight.specular.a > 0.01f ) ) {
::glMaterialfv( GL_FRONT, GL_SPECULAR, glm::value_ptr( colors::none ) );
}
if( Global::fLuminance < Submodel->fLight ) {
if( Global.fLuminance < Submodel->fLight ) {
// restore default (lack of) brightness
::glMaterialfv( GL_FRONT, GL_EMISSION, glm::value_ptr( colors::none ) );
/*
@@ -3122,7 +3170,7 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
}
else if( Submodel->eType == TP_FREESPOTLIGHT ) {
if( Global::fLuminance < Submodel->fLight ) {
if( Global.fLuminance < Submodel->fLight ) {
// NOTE: we're forced here to redo view angle calculations etc, because this data isn't instanced but stored along with the single mesh
// TODO: separate instance data from reusable geometry
auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW );
@@ -3137,14 +3185,14 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
float glarelevel = 0.6f; // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
if( Submodel->fCosViewAngle > Submodel->fCosFalloffAngle ) {
// only bother if the viewer is inside the visibility cone
if( Global::Overcast > 1.0 ) {
if( Global.Overcast > 1.0 ) {
// increase the glare in rainy/foggy conditions
glarelevel += std::max( 0.f, 0.5f * ( Global::Overcast - 1.f ) );
glarelevel += std::max( 0.f, 0.5f * ( Global.Overcast - 1.f ) );
}
// scale it down based on view angle
glarelevel *= ( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( 1.0f - Submodel->fCosFalloffAngle );
// reduce the glare in bright daylight
glarelevel = clamp( glarelevel - static_cast<float>(Global::fLuminance), 0.f, 1.f );
glarelevel = clamp( glarelevel - static_cast<float>(Global.fLuminance), 0.f, 1.f );
if( glarelevel > 0.0f ) {
// setup
@@ -3243,15 +3291,15 @@ opengl_renderer::Update_Pick_Control() {
// determine point to examine
glm::dvec2 mousepos;
glfwGetCursorPos( m_window, &mousepos.x, &mousepos.y );
mousepos.y = Global::iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl
#ifdef EU07_USE_PICKING_FRAMEBUFFER
glm::ivec2 pickbufferpos;
if( true == m_framebuffersupport ) {
// ::glReadBuffer( GL_COLOR_ATTACHMENT0_EXT );
pickbufferpos = glm::ivec2{
mousepos.x * EU07_PICKBUFFERSIZE / std::max( 1, Global::iWindowWidth ),
mousepos.y * EU07_PICKBUFFERSIZE / std::max( 1, Global::iWindowHeight ) };
mousepos.x * EU07_PICKBUFFERSIZE / std::max( 1, Global.iWindowWidth ),
mousepos.y * EU07_PICKBUFFERSIZE / std::max( 1, Global.iWindowHeight ) };
}
else {
// ::glReadBuffer( GL_BACK );
@@ -3290,15 +3338,15 @@ opengl_renderer::Update_Pick_Node() {
// determine point to examine
glm::dvec2 mousepos;
glfwGetCursorPos( m_window, &mousepos.x, &mousepos.y );
mousepos.y = Global::iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl
mousepos.y = Global.iWindowHeight - mousepos.y; // cursor coordinates are flipped compared to opengl
#ifdef EU07_USE_PICKING_FRAMEBUFFER
glm::ivec2 pickbufferpos;
if( true == m_framebuffersupport ) {
// ::glReadBuffer( GL_COLOR_ATTACHMENT0_EXT );
pickbufferpos = glm::ivec2{
mousepos.x * EU07_PICKBUFFERSIZE / Global::iWindowWidth,
mousepos.y * EU07_PICKBUFFERSIZE / Global::iWindowHeight
mousepos.x * EU07_PICKBUFFERSIZE / Global.iWindowWidth,
mousepos.y * EU07_PICKBUFFERSIZE / Global.iWindowHeight
};
}
else {
@@ -3347,31 +3395,31 @@ opengl_renderer::Update( double const Deltatime ) {
if( framerate > 90.0 ) { targetfactor = 3.0f; }
else if( framerate > 60.0 ) { targetfactor = 1.5f; }
else if( framerate > 30.0 ) { targetfactor = 1.25; }
else { targetfactor = std::max( Global::iWindowHeight / 768.f, 1.f ); }
else { targetfactor = std::max( Global.iWindowHeight / 768.f, 1.f ); }
if( targetfactor > Global::fDistanceFactor ) {
if( targetfactor > Global.fDistanceFactor ) {
Global::fDistanceFactor = std::min( targetfactor, Global::fDistanceFactor + 0.05f );
Global.fDistanceFactor = std::min( targetfactor, Global.fDistanceFactor + 0.05f );
}
else if( targetfactor < Global::fDistanceFactor ) {
else if( targetfactor < Global.fDistanceFactor ) {
Global::fDistanceFactor = std::max( targetfactor, Global::fDistanceFactor - 0.05f );
Global.fDistanceFactor = std::max( targetfactor, Global.fDistanceFactor - 0.05f );
}
if( ( framerate < 15.0 ) && ( Global::iSlowMotion < 7 ) ) {
Global::iSlowMotion = ( Global::iSlowMotion << 1 ) + 1; // zapalenie kolejnego bitu
if( Global::iSlowMotionMask & 1 )
if( Global::iMultisampling ) // a multisampling jest włączony
if( ( framerate < 15.0 ) && ( Global.iSlowMotion < 7 ) ) {
Global.iSlowMotion = ( Global.iSlowMotion << 1 ) + 1; // zapalenie kolejnego bitu
if( Global.iSlowMotionMask & 1 )
if( Global.iMultisampling ) // a multisampling jest włączony
::glDisable( GL_MULTISAMPLE ); // wyłączenie multisamplingu powinno poprawić FPS
}
else if( ( framerate > 20.0 ) && Global::iSlowMotion ) { // FPS się zwiększył, można włączyć bajery
Global::iSlowMotion = ( Global::iSlowMotion >> 1 ); // zgaszenie bitu
if( Global::iSlowMotion == 0 ) // jeśli jest pełna prędkość
if( Global::iMultisampling ) // a multisampling jest włączony
else if( ( framerate > 20.0 ) && Global.iSlowMotion ) { // FPS się zwiększył, można włączyć bajery
Global.iSlowMotion = ( Global.iSlowMotion >> 1 ); // zgaszenie bitu
if( Global.iSlowMotion == 0 ) // jeśli jest pełna prędkość
if( Global.iMultisampling ) // a multisampling jest włączony
::glEnable( GL_MULTISAMPLE );
}
if( ( true == Global::ResourceSweep )
if( ( true == Global.ResourceSweep )
&& ( true == World.InitPerformed() ) ) {
// garbage collection
m_geometry.update();
@@ -3382,7 +3430,7 @@ opengl_renderer::Update( double const Deltatime ) {
m_debugtimestext += m_textures.info();
}
if( ( true == Global::ControlPicking )
if( ( true == Global.ControlPicking )
&& ( false == FreeFlyModeFlag ) ) {
Update_Pick_Control();
}
@@ -3390,7 +3438,7 @@ opengl_renderer::Update( double const Deltatime ) {
m_pickcontrolitem = nullptr;
}
// temporary conditions for testing. eventually will be coupled with editor mode
if( ( true == Global::ControlPicking )
if( ( true == Global.ControlPicking )
&& ( true == DebugModeFlag )
&& ( true == FreeFlyModeFlag ) ) {
Update_Pick_Node();
@@ -3403,7 +3451,7 @@ opengl_renderer::Update( double const Deltatime ) {
if( glerror != GL_NO_ERROR ) {
std::string glerrorstring( ( char * )::gluErrorString( glerror ) );
win1250_to_ascii( glerrorstring );
Global::LastGLError = std::to_string( glerror ) + " (" + glerrorstring + ")";
Global.LastGLError = std::to_string( glerror ) + " (" + glerrorstring + ")";
}
}
@@ -3456,10 +3504,10 @@ opengl_renderer::Update_Lights( light_array &Lights ) {
continue;
}
// if the light passed tests so far, it's good enough
renderlight->set_position( lightoffset );
renderlight->position = lightoffset;
renderlight->direction = scenelight.direction;
auto luminance = static_cast<float>( Global::fLuminance );
auto luminance = static_cast<float>( Global.fLuminance );
// adjust luminance level based on vehicle's location, e.g. tunnels
auto const environment = scenelight.owner->fShade;
if( environment > 0.f ) {
@@ -3516,7 +3564,7 @@ opengl_renderer::Init_caps() {
WriteLog( "Supported extensions: " + std::string((char *)glGetString( GL_EXTENSIONS )) );
WriteLog( std::string("Render path: ") + ( Global::bUseVBO ? "VBO" : "Display lists" ) );
WriteLog( std::string("Render path: ") + ( Global.bUseVBO ? "VBO" : "Display lists" ) );
if( GLEW_EXT_framebuffer_object ) {
m_framebuffersupport = true;
WriteLog( "Framebuffer objects enabled" );
@@ -3528,9 +3576,9 @@ opengl_renderer::Init_caps() {
{
GLint texturesize;
::glGetIntegerv( GL_MAX_TEXTURE_SIZE, &texturesize );
Global::iMaxTextureSize = std::min( Global::iMaxTextureSize, texturesize );
WriteLog( "Texture sizes capped at " + std::to_string( Global::iMaxTextureSize ) + " pixels" );
m_shadowbuffersize = Global::shadowtune.map_size;
Global.iMaxTextureSize = std::min( Global.iMaxTextureSize, texturesize );
WriteLog( "Texture sizes capped at " + std::to_string( Global.iMaxTextureSize ) + " pixels" );
m_shadowbuffersize = Global.shadowtune.map_size;
m_shadowbuffersize = std::min( m_shadowbuffersize, texturesize );
WriteLog( "Shadows map size capped at " + std::to_string( m_shadowbuffersize ) + " pixels" );
}
@@ -3538,13 +3586,13 @@ opengl_renderer::Init_caps() {
{
GLint maxlights;
::glGetIntegerv( GL_MAX_LIGHTS, &maxlights );
Global::DynamicLightCount = std::min( Global::DynamicLightCount, maxlights - 1 );
WriteLog( "Dynamic light amount capped at " + std::to_string( Global::DynamicLightCount ) + " (" + std::to_string(maxlights) + " lights total supported by the gfx card)" );
Global.DynamicLightCount = std::min( Global.DynamicLightCount, maxlights - 1 );
WriteLog( "Dynamic light amount capped at " + std::to_string( Global.DynamicLightCount ) + " (" + std::to_string(maxlights) + " lights total supported by the gfx card)" );
}
// select renderer mode
if( true == Global::BasicRenderer ) {
if( true == Global.BasicRenderer ) {
WriteLog( "Basic renderer selected, shadow and reflection mapping will be disabled" );
Global::RenderShadows = false;
Global.RenderShadows = false;
m_diffusetextureunit = GL_TEXTURE0;
m_helpertextureunit = -1;
m_shadowtextureunit = -1;
@@ -3555,8 +3603,8 @@ opengl_renderer::Init_caps() {
::glGetIntegerv( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtextureunits );
if( maxtextureunits < 4 ) {
WriteLog( "Less than 4 texture units, shadow and reflection mapping will be disabled" );
Global::BasicRenderer = true;
Global::RenderShadows = false;
Global.BasicRenderer = true;
Global.RenderShadows = false;
m_diffusetextureunit = GL_TEXTURE0;
m_helpertextureunit = -1;
m_shadowtextureunit = -1;
@@ -3564,8 +3612,8 @@ opengl_renderer::Init_caps() {
}
}
if( Global::iMultisampling ) {
WriteLog( "Using multisampling x" + std::to_string( 1 << Global::iMultisampling ) );
if( Global.iMultisampling ) {
WriteLog( "Using multisampling x" + std::to_string( 1 << Global.iMultisampling ) );
}
return true;