From 38ea3f57376e90618fc57af8c616984b0e08b86b Mon Sep 17 00:00:00 2001 From: milek7 Date: Tue, 12 Mar 2019 23:11:31 +0100 Subject: [PATCH] python without submodel texture --- Texture.h | 2 +- Train.cpp | 45 ++++++++++++++++++++++++++++++--------------- Train.h | 2 +- texturewindow.cpp | 6 ++---- texturewindow.h | 2 +- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/Texture.h b/Texture.h index 7a8efe7a..af7c0726 100644 --- a/Texture.h +++ b/Texture.h @@ -43,6 +43,7 @@ struct opengl_texture { height() const { return data_height; } + void make_stub(); void alloc_rendertarget(GLint format, GLint components, int width, int height, int samples = 1, GLint wrap = GL_CLAMP_TO_BORDER); void set_components_hint(GLint hint); static void reset_unit_cache(); @@ -62,7 +63,6 @@ struct opengl_texture { private: // methods - void make_stub(); void make_request(); void load_BMP(); void load_PNG(); diff --git a/Train.cpp b/Train.cpp index 92b9502d..717dbb24 100644 --- a/Train.cpp +++ b/Train.cpp @@ -6102,7 +6102,7 @@ bool TTrain::Update( double const Deltatime ) && !FreeFlyModeFlag && simulation::Train == this ) { // don't bother if we're outside fScreenTimer = 0.f; for( auto const &screen : m_screens ) { - Application.request( { std::get<0>(screen), GetTrainState(), GfxRenderer.Texture( std::get<1>(screen) ).id } ); + Application.request( { std::get<0>(screen), GetTrainState(), std::get<1>(screen) } ); } } // sounds @@ -6864,30 +6864,45 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) >> submodelname >> renderername; - auto const *submodel { ( DynamicObject->mdKabina ? DynamicObject->mdKabina->GetFromName( submodelname ) : nullptr ) }; - if( submodel == nullptr ) { - WriteLog( "Python Screen: submodel " + submodelname + " not found - Ignoring screen" ); - continue; - } - auto const material { submodel->GetMaterial() }; - if( material <= 0 ) { - // sub model nie posiada tekstury lub tekstura wymienna - nie obslugiwana - WriteLog( "Python Screen: invalid texture id " + std::to_string( material ) + " - Ignoring screen" ); - continue; - } + opengl_texture *tex = nullptr; + if (submodelname != "none") { + auto const *submodel { ( DynamicObject->mdKabina ? DynamicObject->mdKabina->GetFromName( submodelname ) : nullptr ) }; + if( submodel == nullptr ) { + WriteLog( "Python Screen: submodel " + submodelname + " not found - Ignoring screen" ); + continue; + } + auto const material { submodel->GetMaterial() }; + if( material <= 0 ) { + // sub model nie posiada tekstury lub tekstura wymienna - nie obslugiwana + WriteLog( "Python Screen: invalid texture id " + std::to_string( material ) + " - Ignoring screen" ); + continue; + } - texture_handle &tex = GfxRenderer.Material( material ).textures[0]; + tex = &GfxRenderer.Texture(GfxRenderer.Material( material ).textures[0]); + } + else { + // TODO: fix leak + tex = new opengl_texture(); + tex->make_stub(); + } + + if (!tex) { + WriteLog( "Python Screen: missing texture in screen " + submodelname + " - Ignoring screen" ); + continue; + } + + tex->create(); // record renderer and material binding for future update requests m_screens.emplace_back( ( substr_path(renderername).empty() ? // supply vehicle folder as path if none is provided DynamicObject->asBaseDir + renderername : renderername ), - tex, + tex->id, std::nullopt); if (Global.python_displaywindows) - std::get<2>(m_screens.back()).emplace(tex, submodelname); + std::get<2>(m_screens.back()).emplace(tex->id, submodelname); } // btLampkaUnknown.Init("unknown",mdKabina,false); } while (token != ""); diff --git a/Train.h b/Train.h index 489bb323..eb98ea81 100644 --- a/Train.h +++ b/Train.h @@ -665,7 +665,7 @@ private: bool m_mastercontrollerinuse { false }; float m_mastercontrollerreturndelay { 0.f }; int iRadioChannel { 1 }; // numer aktualnego kana?u radiowego - std::vector>> m_screens; + std::vector>> m_screens; uint16_t vid { 0 }; public: diff --git a/texturewindow.cpp b/texturewindow.cpp index 9e572ace..4b949563 100644 --- a/texturewindow.cpp +++ b/texturewindow.cpp @@ -11,11 +11,9 @@ void texture_window_fb_resize(GLFWwindow *win, int w, int h) texwindow->notify_window_size(w, h); } -texture_window::texture_window(texture_handle src, std::string surfacename) +texture_window::texture_window(GLuint src, std::string surfacename) { - opengl_texture &tex = GfxRenderer.Texture(src); - tex.create(); - m_source = tex.id; + m_source = src; int window_w = m_win_w, window_h = m_win_h; diff --git a/texturewindow.h b/texturewindow.h index f35d3760..e55f39f4 100644 --- a/texturewindow.h +++ b/texturewindow.h @@ -16,7 +16,7 @@ class texture_window void threadfunc(); public: - texture_window(texture_handle src, std::string name); + texture_window(GLuint src, std::string name); ~texture_window(); void notify_window_size(int w, int h);