diff --git a/src/noggit/TextureManager.cpp b/src/noggit/TextureManager.cpp index 569ed4b1..a66a0940 100644 --- a/src/noggit/TextureManager.cpp +++ b/src/noggit/TextureManager.cpp @@ -260,13 +260,19 @@ void blp_texture::finishLoading() namespace noggit { - QPixmap render_blp_to_pixmap ( std::string const& blp_filename + QPixmap* render_blp_to_pixmap ( std::string const& blp_filename , int width , int height ) { - opengl::context::save_current_context const context_save (::gl); + static std::map, QPixmap> cache{}; + std::tuple const curEntry{blp_filename, width, height}; + auto it{cache.find(curEntry)}; + if(it != cache.end()) + return &it->second; + + opengl::context::save_current_context const context_save (::gl); QOpenGLContext context; context.create(); @@ -388,17 +394,17 @@ out_color = vec4(texture(tex, f_tex_coord/2.f + vec2(0.5)).rgb, 1.); gl.drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr); - QPixmap pixmap (QPixmap::fromImage (pixel_buffer.toImage())); - + QPixmap result{}; + result = std::move(QPixmap::fromImage(pixel_buffer.toImage())); pixel_buffer.release(); - if (pixmap.isNull()) + if (result.isNull()) { throw std::runtime_error ("failed rendering " + blp_filename + " to pixmap"); } - return pixmap; + return &(cache[curEntry] = std::move(result)); } } diff --git a/src/noggit/TextureManager.h b/src/noggit/TextureManager.h index d1f365a6..085eaf7c 100644 --- a/src/noggit/TextureManager.h +++ b/src/noggit/TextureManager.h @@ -81,7 +81,7 @@ private: namespace noggit { - QPixmap render_blp_to_pixmap ( std::string const& blp_filename + QPixmap* render_blp_to_pixmap ( std::string const& blp_filename , int width = -1 , int height = -1 ); diff --git a/src/noggit/ui/About.cpp b/src/noggit/ui/About.cpp index 5c16a58c..33c70124 100644 --- a/src/noggit/ui/About.cpp +++ b/src/noggit/ui/About.cpp @@ -23,7 +23,7 @@ namespace noggit new QVBoxLayout (this); auto icon (new QLabel (this)); - icon->setPixmap (render_blp_to_pixmap ("interface/icons/inv_potion_83.blp")); + icon->setPixmap (*render_blp_to_pixmap ("interface/icons/inv_potion_83.blp")); layout()->addWidget (icon); //! \todo was Skurri32 layout()->addWidget (new QLabel ("Noggit Studio", this)); diff --git a/src/noggit/ui/CurrentTexture.cpp b/src/noggit/ui/CurrentTexture.cpp index 96b136d3..f43a9a15 100644 --- a/src/noggit/ui/CurrentTexture.cpp +++ b/src/noggit/ui/CurrentTexture.cpp @@ -56,7 +56,7 @@ namespace noggit _need_update = false; show(); - setPixmap (render_blp_to_pixmap (_filename, width(), height())); + setPixmap (*render_blp_to_pixmap (_filename, width(), height())); setToolTip(QString::fromStdString(_filename)); } diff --git a/src/noggit/ui/HelperModels.cpp b/src/noggit/ui/HelperModels.cpp index 68e00558..53f38464 100644 --- a/src/noggit/ui/HelperModels.cpp +++ b/src/noggit/ui/HelperModels.cpp @@ -27,7 +27,7 @@ namespace noggit layout->addLayout (bottom_layout); auto icon (new QLabel (this)); - icon->setPixmap (render_blp_to_pixmap ("interface/icons/inv_misc_enggizmos_swissarmy.blp")); + icon->setPixmap (*render_blp_to_pixmap ("interface/icons/inv_misc_enggizmos_swissarmy.blp")); top_layout->addWidget (icon); top_layout->addWidget (new QLabel ("Select a model to add.\nYou should select a chunk first.", this)); diff --git a/src/noggit/ui/SettingsPanel.cpp b/src/noggit/ui/SettingsPanel.cpp index 636fa6ef..af78a030 100644 --- a/src/noggit/ui/SettingsPanel.cpp +++ b/src/noggit/ui/SettingsPanel.cpp @@ -175,7 +175,7 @@ namespace noggit new QHBoxLayout (warning); auto icon (new QLabel (warning)); icon->setPixmap - (render_blp_to_pixmap ("interface/gossipframe/availablequesticon.blp")); + (*render_blp_to_pixmap ("interface/gossipframe/availablequesticon.blp")); warning->layout()->addWidget (icon); warning->layout()->addWidget (new QLabel ("Changes may not take effect until next launch.", warning)); diff --git a/src/noggit/ui/TexturingGUI.cpp b/src/noggit/ui/TexturingGUI.cpp index 6142bd2f..1771d99b 100644 --- a/src/noggit/ui/TexturingGUI.cpp +++ b/src/noggit/ui/TexturingGUI.cpp @@ -47,7 +47,7 @@ namespace noggit //! \note The one time Qt is const correct and we don't want that. auto that (const_cast (this)); that->_rendered = true; - that->_pixmap = render_blp_to_pixmap (data (Qt::DisplayRole).toString().prepend ("tileset/").toStdString(), 256, 256); + that->_pixmap = *render_blp_to_pixmap (data (Qt::DisplayRole).toString().prepend ("tileset/").toStdString(), 256, 256); } return QIcon(_pixmap); } diff --git a/src/noggit/ui/texture_palette_small.cpp b/src/noggit/ui/texture_palette_small.cpp index 308d1169..6a1ebd04 100644 --- a/src/noggit/ui/texture_palette_small.cpp +++ b/src/noggit/ui/texture_palette_small.cpp @@ -147,7 +147,7 @@ namespace noggit _texture_paths.emplace(display_name.toStdString()); QListWidgetItem* list_item = new QListWidgetItem(_texture_list); - list_item->setIcon(render_blp_to_pixmap(filename, _texture_list->iconSize().width(), _texture_list->iconSize().height())); + list_item->setIcon(*render_blp_to_pixmap(filename, _texture_list->iconSize().width(), _texture_list->iconSize().height())); list_item->setToolTip(display_name); list_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled); diff --git a/src/opengl/primitives.cpp b/src/opengl/primitives.cpp index 93151d12..4007d9d8 100644 --- a/src/opengl/primitives.cpp +++ b/src/opengl/primitives.cpp @@ -51,8 +51,6 @@ namespace opengl , R"code( #version 330 core - in vec4 position; - uniform vec3 pointPositions[8]; uniform mat4 model_view; uniform mat4 projection; @@ -60,7 +58,6 @@ namespace opengl void main() { - vec4 pos = position; // hack to get rid of compiler optimizations, else Noggit crashes gl_Position = projection * model_view * transform * vec4(pointPositions[gl_VertexID], 1.0); } )code"} @@ -85,27 +82,9 @@ namespace opengl //std::vector positions (math::box_points (min_point, max_point)); - std::vector positions = { - {-0.5f, -0.5f, -0.5f}, - {0.5f, -0.5f, -0.5f}, - {0.5f, 0.5f, -0.5f}, - {-0.5f, 0.5f, -0.5f}, - {-0.5f, -0.5f, 0.5f}, - {0.5f, -0.5f, 0.5f}, - {0.5f, 0.5f, 0.5f}, - {-0.5f, 0.5f, 0.5f}, - }; - static std::array const indices {{5, 7, 3, 2, 0, 1, 3, 1, 5, 4, 0, 4, 6, 2, 6, 7}}; - scoped::buffer_binder const pos_buffer (_positions); - gl.bufferData ( GL_ARRAY_BUFFER - , positions.size() * sizeof (*positions.data()) - , positions.data() - , GL_STATIC_DRAW - ); - scoped::buffer_binder const index_buffer (_indices); gl.bufferData ( GL_ELEMENT_ARRAY_BUFFER , indices.size() * sizeof (*indices.data()) @@ -117,8 +96,6 @@ namespace opengl opengl::scoped::vao_binder const _ (_vao[0]); - shader.attrib("position", 3, GL_FLOAT, GL_FALSE, 0, 0); - _buffers_are_setup = true; } diff --git a/src/opengl/primitives.hpp b/src/opengl/primitives.hpp index 9d51af98..5f5de2d5 100644 --- a/src/opengl/primitives.hpp +++ b/src/opengl/primitives.hpp @@ -44,9 +44,8 @@ namespace opengl void setup_buffers(); scoped::deferred_upload_vertex_arrays<1> _vao; - scoped::deferred_upload_buffers<2> _buffers; - GLuint const& _positions = _buffers[0]; - GLuint const& _indices = _buffers[1]; + scoped::deferred_upload_buffers<1> _buffers; + GLuint const& _indices = _buffers[0]; std::unique_ptr _program; };