python windows improvements

This commit is contained in:
milek7
2019-03-18 20:11:59 +01:00
parent e7a58cc1ba
commit f4c53f2579
6 changed files with 80 additions and 49 deletions

View File

@@ -76,6 +76,8 @@ void python_screen_viewer::threadfunc()
while (!m_exit)
{
auto start_time = std::chrono::high_resolution_clock::now();
for (auto &window : m_windows) {
glfwMakeContextCurrent(window->window);
gl::program::unbind();
@@ -88,16 +90,38 @@ void python_screen_viewer::threadfunc()
window->ubo->update(m_ubs);
if (!Global.python_sharectx) {
std::lock_guard<std::mutex> guard(m_rt->mutex);
unsigned char *image;
int format, components, width, height;
if (!m_rt->image)
continue;
{
std::lock_guard<std::mutex> guard(m_rt->mutex);
if (window->timestamp == m_rt->timestamp)
continue;
if (!m_rt->image)
continue;
format = m_rt->format;
components = m_rt->components;
width = m_rt->width;
height = m_rt->height;
size_t size = width * height * (components == GL_RGB ? 3 : 4);
image = new unsigned char[size];
memcpy(image, m_rt->image, size);
window->timestamp = m_rt->timestamp;
}
glTexImage2D(
GL_TEXTURE_2D, 0,
m_rt->format,
m_rt->width, m_rt->height, 0,
m_rt->components, GL_UNSIGNED_BYTE, m_rt->image);
format,
width, height, 0,
components, GL_UNSIGNED_BYTE, image);
delete[] image;
if (Global.python_mipmaps) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
@@ -115,6 +139,11 @@ void python_screen_viewer::threadfunc()
glfwSwapBuffers(window->window);
}
auto frametime = std::chrono::high_resolution_clock::now() - start_time;
if ((Global.python_minframetime - frametime).count() > 0.0f)
std::this_thread::sleep_for(Global.minframetime - frametime);
}
}