attempt to fix fps drops in various setups
This commit is contained in:
@@ -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<std::tuple<std::string, int, int>, QPixmap> cache{};
|
||||
std::tuple<std::string, int, int> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace noggit
|
||||
//! \note The one time Qt is const correct and we don't want that.
|
||||
auto that (const_cast<model_item*> (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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<math::vector_3d> positions (math::box_points (min_point, max_point));
|
||||
|
||||
std::vector<math::vector_3d> 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<std::uint8_t, 16> const indices
|
||||
{{5, 7, 3, 2, 0, 1, 3, 1, 5, 4, 0, 4, 6, 2, 6, 7}};
|
||||
|
||||
scoped::buffer_binder<GL_ARRAY_BUFFER> const pos_buffer (_positions);
|
||||
gl.bufferData ( GL_ARRAY_BUFFER
|
||||
, positions.size() * sizeof (*positions.data())
|
||||
, positions.data()
|
||||
, GL_STATIC_DRAW
|
||||
);
|
||||
|
||||
scoped::buffer_binder<GL_ELEMENT_ARRAY_BUFFER> 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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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<opengl::program> _program;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user