diff --git a/drivermode.cpp b/drivermode.cpp index 7c4cfab2..574bcb8f 100644 --- a/drivermode.cpp +++ b/drivermode.cpp @@ -437,7 +437,7 @@ driver_mode::update_camera( double const Deltatime ) { if( d ) pDynamicNearest = d; // zmiana na nowy, jeśli coś znaleziony niepusty if( pDynamicNearest ) - Camera.LookAt = pDynamicNearest->GetPosition(); + Camera.LookAt = pDynamicNearest->GetPosition() + 0.5 * pDynamicNearest->VectorUp() * pDynamicNearest->MoverParameters->Dim.H; } Camera.RaLook(); // jednorazowe przestawienie kamery } diff --git a/gamepadinput.cpp b/gamepadinput.cpp index ecbbd031..0ee7e6cf 100644 --- a/gamepadinput.cpp +++ b/gamepadinput.cpp @@ -464,9 +464,22 @@ gamepad_input::process_axes() { if( inputtype == input_type::value_invert ) { param *= -1.0; } - // special case, viewturn receives some param scaling - if( boundcommand1 == user_command::viewturn ) { + } + // scale passed value according to command type + switch( boundcommand1 ) { + case user_command::viewturn: { param *= 10.0 * ( Timer::GetDeltaRenderTime() * 60.0 ); + break; + } + case user_command::movehorizontal: + case user_command::movehorizontalfast: { + // these expect value in -1:1 range + break; + } + default: { + // commands generally expect their parameter to be in 0:1 range + param = param * 0.5 + 0.5; + break; } } break; diff --git a/gl/framebuffer.cpp b/gl/framebuffer.cpp index 1caa89c8..7c6439b6 100644 --- a/gl/framebuffer.cpp +++ b/gl/framebuffer.cpp @@ -56,7 +56,7 @@ bool gl::framebuffer::is_complete() auto const iscomplete { status == GL_FRAMEBUFFER_COMPLETE }; if( false == iscomplete ) { - ErrorLog( "framebuffer status error: " + to_hex_str( status ) ); + ErrorLog( "framebuffer status: error " + to_hex_str( status ) ); } return iscomplete; diff --git a/material.cpp b/material.cpp index 69a0cc38..0b6eb8f2 100644 --- a/material.cpp +++ b/material.cpp @@ -43,7 +43,8 @@ void opengl_material::log_error(const std::string &str) std::map texture_bindings { { "diffuse", 0 }, - { "normal", 1 } + { "normals", 1 }, + { "normalmap", 1 } }; void opengl_material::finalize(bool Loadnow) diff --git a/opengl33renderer.cpp b/opengl33renderer.cpp index 4ca6e647..368da47b 100644 --- a/opengl33renderer.cpp +++ b/opengl33renderer.cpp @@ -48,8 +48,6 @@ bool opengl33_renderer::Init(GLFWwindow *Window) if (!Init_caps()) return false; - WriteLog("preparing renderer..."); - OpenGLMatrices.upload() = false; // set matrix stack in virtual mode m_window = Window; @@ -80,12 +78,10 @@ bool opengl33_renderer::Init(GLFWwindow *Window) m_lights.emplace_back(light); } // preload some common textures - WriteLog("Loading common gfx data..."); m_glaretexture = Fetch_Texture("fx/lightglare"); m_suntexture = Fetch_Texture("fx/sun"); m_moontexture = Fetch_Texture("fx/moon"); m_smoketexture = Fetch_Texture("fx/smoke"); - WriteLog("...gfx data pre-loading done"); // prepare basic geometry chunks float const size = 2.5f / 2.0f; @@ -168,6 +164,7 @@ bool opengl33_renderer::Init(GLFWwindow *Window) m_shadow_tex = std::make_unique(); m_shadow_tex->alloc_rendertarget(Global.gfx_format_depth, GL_DEPTH_COMPONENT, m_shadowbuffersize, m_shadowbuffersize, m_shadowpass.size()); m_shadow_fb->attach(*m_shadow_tex, GL_DEPTH_ATTACHMENT, 0); + m_shadow_fb->setup_drawing(0); if( !m_shadow_fb->is_complete() ) { ErrorLog( "shadow framebuffer setup failed" ); @@ -277,7 +274,7 @@ bool opengl33_renderer::Init(GLFWwindow *Window) WriteLog("picking objects created"); - WriteLog("gfx renderer setup complete"); + WriteLog("Gfx Renderer: setup complete"); return true; } @@ -303,7 +300,7 @@ bool opengl33_renderer::init_viewport(viewport_config &vp) { glfwMakeContextCurrent(vp.window); - WriteLog("init viewport: " + std::to_string(vp.width) + ", " + std::to_string(vp.height)); + WriteLog("init viewport: " + std::to_string(vp.width) + " x " + std::to_string(vp.height)); glfwSwapInterval( Global.VSync ? 1 : 0 ); @@ -331,8 +328,11 @@ bool opengl33_renderer::init_viewport(viewport_config &vp) else if (GLAD_GL_EXT_clip_control) glClipControlEXT(GL_LOWER_LEFT_EXT, GL_ZERO_TO_ONE_EXT); - if (!Global.gfx_usegles) - glEnable(GL_PROGRAM_POINT_SIZE); + if( !Global.gfx_usegles ) { + glEnable( GL_PROGRAM_POINT_SIZE ); + // not present in core, but if we get compatibility profile instead we won't get gl_pointcoord without it + glEnable( GL_POINT_SPRITE ); + } if (!gl::vao::use_vao) { @@ -4035,10 +4035,9 @@ bool opengl33_renderer::Init_caps() { WriteLog( "Gfx Renderer: " + std::string( (char *)glGetString(GL_RENDERER)) - + "\nVendor: " + std::string( (char *)glGetString(GL_VENDOR)) - + "\nOpenGL Version: " + std::string((char *)glGetString(GL_VERSION)) ); + + " Vendor: " + std::string( (char *)glGetString(GL_VENDOR)) + + " OpenGL Version: " + std::string((char *)glGetString(GL_VERSION)) ); - WriteLog("--------"); { GLint extCount = 0; glGetIntegerv( GL_NUM_EXTENSIONS, &extCount ); @@ -4052,7 +4051,6 @@ bool opengl33_renderer::Init_caps() } WriteLog( extensions ); } - WriteLog("--------"); if (!Global.gfx_usegles) { @@ -4100,15 +4098,15 @@ bool opengl33_renderer::Init_caps() glGetError(); glLineWidth(2.0f); - if (!glGetError()) - { + if (!glGetError()) { WriteLog("wide lines supported"); m_widelines_supported = true; } - else - WriteLog("warning: wide lines not supported"); + else { + WriteLog( "warning: wide lines not supported" ); + } - WriteLog("--------"); + WriteLog( "render path: Shaders, VBO" ); // ograniczenie maksymalnego rozmiaru tekstur - parametr dla skalowania tekstur { @@ -4134,7 +4132,7 @@ bool opengl33_renderer::Init_caps() if (Global.gfx_framebuffer_height == -1) Global.gfx_framebuffer_height = Global.iWindowHeight; - WriteLog("main window size: " + std::to_string(Global.gfx_framebuffer_width) + "x" + std::to_string(Global.gfx_framebuffer_height)); + WriteLog("main window size: " + std::to_string(Global.gfx_framebuffer_width) + " x " + std::to_string(Global.gfx_framebuffer_height)); return true; } diff --git a/openglparticles.cpp b/openglparticles.cpp index b12d6c48..4b4e0163 100644 --- a/openglparticles.cpp +++ b/openglparticles.cpp @@ -129,7 +129,7 @@ opengl_particles::update( opengl_camera const &Camera ) { } std::size_t -opengl_particles::render( int const Textureunit ) { +opengl_particles::render( GLint const Textureunit ) { if( false == Global.Smoke ) { return 0; } if( m_buffercapacity == 0 ) { return 0; } @@ -143,7 +143,7 @@ opengl_particles::render( int const Textureunit ) { ::glEnableClientState( GL_VERTEX_ARRAY ); ::glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( particle_vertex ), reinterpret_cast( sizeof( float ) * 3 ) ); ::glEnableClientState( GL_COLOR_ARRAY ); - ::glClientActiveTexture( Textureunit ); + ::glClientActiveTexture( GL_TEXTURE0 + Textureunit ); ::glTexCoordPointer( 2, GL_FLOAT, sizeof( particle_vertex ), reinterpret_cast( sizeof( float ) * 3 + sizeof( std::uint8_t ) * 4 ) ); ::glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // ...draw... diff --git a/openglparticles.h b/openglparticles.h index afb18a29..aca20af5 100644 --- a/openglparticles.h +++ b/openglparticles.h @@ -24,7 +24,7 @@ public: void update( opengl_camera const &Camera ); std::size_t - render( int const Textureunit ); + render( GLint const Textureunit ); private: // types struct particle_vertex { diff --git a/openglprecipitation.cpp b/openglprecipitation.cpp index 1e28de38..c5ac8821 100644 --- a/openglprecipitation.cpp +++ b/openglprecipitation.cpp @@ -139,7 +139,7 @@ opengl_precipitation::update() { } void -opengl_precipitation::render() { +opengl_precipitation::render( GLint const Textureunit ) { if( m_texture == null_handle ) { return; } @@ -154,7 +154,7 @@ opengl_precipitation::render() { ::glEnableClientState( GL_VERTEX_ARRAY ); // uvs ::glBindBuffer( GL_ARRAY_BUFFER, m_uvbuffer ); - ::glClientActiveTexture( m_textureunit ); + ::glClientActiveTexture( GL_TEXTURE0 + Textureunit ); ::glTexCoordPointer( 2, GL_FLOAT, sizeof( glm::vec2 ), reinterpret_cast( 0 ) ); ::glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // uv transformation matrix diff --git a/openglprecipitation.h b/openglprecipitation.h index 3b49e7f1..ced4fddf 100644 --- a/openglprecipitation.h +++ b/openglprecipitation.h @@ -19,14 +19,10 @@ public: // destructor ~opengl_precipitation(); // methods - inline - void - set_unit( GLint const Textureunit ) { - m_textureunit = Textureunit; } void update(); void - render(); + render( GLint const Textureunit ); private: // methods @@ -38,7 +34,6 @@ private: GLuint m_vertexbuffer { (GLuint)-1 }; GLuint m_uvbuffer { (GLuint)-1 }; GLuint m_indexbuffer { (GLuint)-1 }; - GLint m_textureunit { 0 }; texture_handle m_texture { null_handle }; float m_overcast { -1.f }; // cached overcast level, difference from current state triggers texture update }; diff --git a/openglrenderer.cpp b/openglrenderer.cpp index 9f97bddf..5e585989 100644 --- a/openglrenderer.cpp +++ b/openglrenderer.cpp @@ -52,7 +52,6 @@ opengl_renderer::Init( GLFWwindow *Window ) { std::vector{ m_diffusetextureunit } : std::vector{ m_normaltextureunit, m_diffusetextureunit } ); ui_layer::set_unit( m_diffusetextureunit ); - m_precipitationrenderer.set_unit( m_diffusetextureunit ); select_unit( m_diffusetextureunit ); ::glDepthFunc( GL_LEQUAL ); @@ -109,7 +108,6 @@ opengl_renderer::Init( GLFWwindow *Window ) { m_lights.emplace_back( light ); } // preload some common textures - WriteLog( "Loading common gfx data..." ); m_glaretexture = Fetch_Texture( "fx/lightglare" ); m_suntexture = Fetch_Texture( "fx/sun" ); m_moontexture = Fetch_Texture( "fx/moon" ); @@ -117,7 +115,6 @@ opengl_renderer::Init( GLFWwindow *Window ) { m_reflectiontexture = Fetch_Texture( "fx/reflections" ); } m_smoketexture = Fetch_Texture( "fx/smoke" ); - WriteLog( "...gfx data pre-loading done" ); #ifdef EU07_USE_PICKING_FRAMEBUFFER // pick buffer resources @@ -312,6 +309,8 @@ opengl_renderer::Init( GLFWwindow *Window ) { m_quadric = ::gluNewQuadric(); ::gluQuadricNormals( m_quadric, GLU_FLAT ); + WriteLog( "Gfx Renderer: setup complete" ); + return true; } @@ -338,7 +337,7 @@ opengl_renderer::Render() { // add user interface setup_units( true, false, false ); ::glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); - ::glClientActiveTexture( m_diffusetextureunit ); + ::glClientActiveTexture( GL_TEXTURE0 + m_diffusetextureunit ); ::glBindBuffer( GL_ARRAY_BUFFER, 0 ); Application.render_ui(); ::glPopClientAttrib(); @@ -3151,7 +3150,7 @@ opengl_renderer::Render_precipitation() { // momentarily disable depth write, to allow vehicle cab drawn afterwards to mask it instead of leaving it 'inside' ::glDepthMask( GL_FALSE ); - m_precipitationrenderer.render(); + m_precipitationrenderer.render( m_diffusetextureunit ); if( Global.bUseVBO ) { gfx::opengl_vbogeometrybank::reset(); } @@ -4161,15 +4160,16 @@ opengl_renderer::Init_caps() { } #endif - WriteLog( "Supported extensions: " + std::string((char *)glGetString( GL_EXTENSIONS )) ); + WriteLog( "Supported extensions: \n" + + 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( GL_EXT_framebuffer_object ) { m_framebuffersupport = true; - WriteLog( "Framebuffer objects enabled" ); + WriteLog( "framebuffer objects enabled" ); } else { - WriteLog( "Framebuffer objects not supported, resorting to back buffer rendering where possible" ); + WriteLog( "framebuffer objects not supported, resorting to back buffer rendering where possible" ); } // ograniczenie maksymalnego rozmiaru tekstur - parametr dla skalowania tekstur { @@ -4181,18 +4181,18 @@ opengl_renderer::Init_caps() { Global.CurrentMaxTextureSize = Global.iMaxTextureSize; m_shadowbuffersize = Global.shadowtune.map_size; m_shadowbuffersize = std::min( m_shadowbuffersize, texturesize ); - WriteLog( "Shadows map size capped at " + std::to_string( m_shadowbuffersize ) + "p" ); + WriteLog( "shadows map size capped at " + std::to_string( m_shadowbuffersize ) + "p" ); } // cap the number of supported lights based on hardware { 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)" ); + 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 ) { - WriteLog( "Basic renderer selected, shadow and reflection mapping will be disabled" ); + WriteLog( "basic renderer selected, shadow and reflection mapping will be disabled" ); Global.RenderShadows = false; m_diffusetextureunit = 0; m_helpertextureunit = -1; @@ -4203,7 +4203,7 @@ opengl_renderer::Init_caps() { GLint maxtextureunits; ::glGetIntegerv( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtextureunits ); if( maxtextureunits < 4 ) { - WriteLog( "Less than 4 texture units, shadow and reflection mapping will be disabled" ); + WriteLog( "less than 4 texture units, shadow and reflection mapping will be disabled" ); Global.BasicRenderer = true; Global.RenderShadows = false; m_diffusetextureunit = 0; @@ -4214,9 +4214,11 @@ opengl_renderer::Init_caps() { } if( Global.iMultisampling ) { - WriteLog( "Using multisampling x" + std::to_string( 1 << Global.iMultisampling ) ); + WriteLog( "using multisampling x" + std::to_string( 1 << Global.iMultisampling ) ); } + WriteLog( "main window size: " + std::to_string( Global.gfx_framebuffer_width ) + "x" + std::to_string( Global.gfx_framebuffer_height ) ); + return true; }