mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 11:39:19 +02:00
python windows improvements
This commit is contained in:
@@ -801,6 +801,13 @@ global_settings::ConfigParse(cParser &Parser) {
|
|||||||
Parser.getTokens(1);
|
Parser.getTokens(1);
|
||||||
Parser >> python_sharectx;
|
Parser >> python_sharectx;
|
||||||
}
|
}
|
||||||
|
else if (token == "python.fpslimit")
|
||||||
|
{
|
||||||
|
Parser.getTokens(1);
|
||||||
|
float fpslimit;
|
||||||
|
Parser >> fpslimit;
|
||||||
|
python_minframetime = std::chrono::duration<float>(1.0f / fpslimit);
|
||||||
|
}
|
||||||
else if (token == "python.vsync")
|
else if (token == "python.vsync")
|
||||||
{
|
{
|
||||||
Parser.getTokens(1);
|
Parser.getTokens(1);
|
||||||
|
|||||||
@@ -188,7 +188,8 @@ struct global_settings {
|
|||||||
bool python_displaywindows = false;
|
bool python_displaywindows = false;
|
||||||
bool python_threadedupload = true;
|
bool python_threadedupload = true;
|
||||||
bool python_vsync = true;
|
bool python_vsync = true;
|
||||||
bool python_sharectx = false;
|
bool python_sharectx = true;
|
||||||
|
std::chrono::duration<float> python_minframetime {0.01f};
|
||||||
|
|
||||||
int gfx_framebuffer_width = -1;
|
int gfx_framebuffer_width = -1;
|
||||||
int gfx_framebuffer_height = -1;
|
int gfx_framebuffer_height = -1;
|
||||||
|
|||||||
70
PyInt.cpp
70
PyInt.cpp
@@ -46,35 +46,47 @@ void render_task::run() {
|
|||||||
if( ( outputwidth != nullptr )
|
if( ( outputwidth != nullptr )
|
||||||
&& ( outputheight != nullptr )
|
&& ( outputheight != nullptr )
|
||||||
&& m_target) {
|
&& m_target) {
|
||||||
m_width = PyInt_AsLong( outputwidth );
|
int width = PyInt_AsLong( outputwidth );
|
||||||
m_height = PyInt_AsLong( outputheight );
|
int height = PyInt_AsLong( outputheight );
|
||||||
|
int components, format;
|
||||||
|
|
||||||
const unsigned char *image = reinterpret_cast<const unsigned char *>( PyString_AsString( output ) );
|
const unsigned char *image = reinterpret_cast<const unsigned char *>( PyString_AsString( output ) );
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> guard(m_target->mutex);
|
||||||
|
if (m_target->image)
|
||||||
|
delete[] m_target->image;
|
||||||
|
|
||||||
if (!Global.gfx_usegles)
|
if (!Global.gfx_usegles)
|
||||||
{
|
{
|
||||||
int size = m_width * m_height * 3;
|
int size = width * height * 3;
|
||||||
m_format = GL_SRGB8;
|
format = GL_SRGB8;
|
||||||
m_components = GL_RGB;
|
components = GL_RGB;
|
||||||
m_image = new unsigned char[size];
|
m_target->image = new unsigned char[size];
|
||||||
memcpy(m_image, image, size);
|
memcpy(m_target->image, image, size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_format = GL_SRGB8_ALPHA8;
|
format = GL_SRGB8_ALPHA8;
|
||||||
m_components = GL_RGBA;
|
components = GL_RGBA;
|
||||||
m_image = new unsigned char[m_width * m_height * 4];
|
m_target->image = new unsigned char[width * height * 4];
|
||||||
|
|
||||||
int w = m_width;
|
int w = width;
|
||||||
int h = m_height;
|
int h = height;
|
||||||
for (int y = 0; y < h; y++)
|
for (int y = 0; y < h; y++)
|
||||||
for (int x = 0; x < w; x++)
|
for (int x = 0; x < w; x++)
|
||||||
{
|
{
|
||||||
m_image[(y * w + x) * 4 + 0] = image[(y * w + x) * 3 + 0];
|
m_target->image[(y * w + x) * 4 + 0] = image[(y * w + x) * 3 + 0];
|
||||||
m_image[(y * w + x) * 4 + 1] = image[(y * w + x) * 3 + 1];
|
m_target->image[(y * w + x) * 4 + 1] = image[(y * w + x) * 3 + 1];
|
||||||
m_image[(y * w + x) * 4 + 2] = image[(y * w + x) * 3 + 2];
|
m_target->image[(y * w + x) * 4 + 2] = image[(y * w + x) * 3 + 2];
|
||||||
m_image[(y * w + x) * 4 + 3] = 0xFF;
|
m_target->image[(y * w + x) * 4 + 3] = 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_target->width = width;
|
||||||
|
m_target->height = height;
|
||||||
|
m_target->components = components;
|
||||||
|
m_target->format = format;
|
||||||
|
m_target->timestamp = std::chrono::high_resolution_clock::now();
|
||||||
}
|
}
|
||||||
if( outputheight != nullptr ) { Py_DECREF( outputheight ); }
|
if( outputheight != nullptr ) { Py_DECREF( outputheight ); }
|
||||||
if( outputwidth != nullptr ) { Py_DECREF( outputwidth ); }
|
if( outputwidth != nullptr ) { Py_DECREF( outputwidth ); }
|
||||||
@@ -84,32 +96,14 @@ void render_task::run() {
|
|||||||
|
|
||||||
void render_task::upload()
|
void render_task::upload()
|
||||||
{
|
{
|
||||||
if (m_image)
|
if (m_target->image)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, m_target->shared_tex);
|
glBindTexture(GL_TEXTURE_2D, m_target->shared_tex);
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
GL_TEXTURE_2D, 0,
|
GL_TEXTURE_2D, 0,
|
||||||
m_format,
|
m_target->format,
|
||||||
m_width, m_height, 0,
|
m_target->width, m_target->height, 0,
|
||||||
m_components, GL_UNSIGNED_BYTE, m_image);
|
m_target->components, GL_UNSIGNED_BYTE, m_target->image);
|
||||||
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> guard(m_target->mutex);
|
|
||||||
if (m_target->image)
|
|
||||||
delete[] m_target->image;
|
|
||||||
|
|
||||||
size_t size = m_width * m_height * (m_components == GL_RGB ? 3 : 4);
|
|
||||||
m_target->image = new unsigned char[size];
|
|
||||||
|
|
||||||
memcpy(m_target->image, m_image, size);
|
|
||||||
|
|
||||||
m_target->width = m_width;
|
|
||||||
m_target->height = m_height;
|
|
||||||
m_target->components = m_components;
|
|
||||||
m_target->format = m_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] m_image;
|
|
||||||
|
|
||||||
if (Global.python_mipmaps)
|
if (Global.python_mipmaps)
|
||||||
{
|
{
|
||||||
|
|||||||
6
PyInt.h
6
PyInt.h
@@ -80,6 +80,8 @@ struct python_rt {
|
|||||||
int height;
|
int height;
|
||||||
unsigned char *image = nullptr;
|
unsigned char *image = nullptr;
|
||||||
|
|
||||||
|
std::chrono::high_resolution_clock::time_point timestamp;
|
||||||
|
|
||||||
~python_rt() {
|
~python_rt() {
|
||||||
if (image)
|
if (image)
|
||||||
delete[] image;
|
delete[] image;
|
||||||
@@ -105,10 +107,6 @@ private:
|
|||||||
PyObject *m_renderer {nullptr};
|
PyObject *m_renderer {nullptr};
|
||||||
dictionary_source *m_input { nullptr };
|
dictionary_source *m_input { nullptr };
|
||||||
std::shared_ptr<python_rt> m_target { nullptr };
|
std::shared_ptr<python_rt> m_target { nullptr };
|
||||||
|
|
||||||
unsigned char *m_image = nullptr;
|
|
||||||
int m_width, m_height;
|
|
||||||
GLenum m_components, m_format;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class python_taskqueue {
|
class python_taskqueue {
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ void python_screen_viewer::threadfunc()
|
|||||||
|
|
||||||
while (!m_exit)
|
while (!m_exit)
|
||||||
{
|
{
|
||||||
|
auto start_time = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
for (auto &window : m_windows) {
|
for (auto &window : m_windows) {
|
||||||
glfwMakeContextCurrent(window->window);
|
glfwMakeContextCurrent(window->window);
|
||||||
gl::program::unbind();
|
gl::program::unbind();
|
||||||
@@ -88,16 +90,38 @@ void python_screen_viewer::threadfunc()
|
|||||||
window->ubo->update(m_ubs);
|
window->ubo->update(m_ubs);
|
||||||
|
|
||||||
if (!Global.python_sharectx) {
|
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(
|
glTexImage2D(
|
||||||
GL_TEXTURE_2D, 0,
|
GL_TEXTURE_2D, 0,
|
||||||
m_rt->format,
|
format,
|
||||||
m_rt->width, m_rt->height, 0,
|
width, height, 0,
|
||||||
m_rt->components, GL_UNSIGNED_BYTE, m_rt->image);
|
components, GL_UNSIGNED_BYTE, image);
|
||||||
|
|
||||||
|
delete[] image;
|
||||||
|
|
||||||
if (Global.python_mipmaps) {
|
if (Global.python_mipmaps) {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
@@ -115,6 +139,11 @@ void python_screen_viewer::threadfunc()
|
|||||||
|
|
||||||
glfwSwapBuffers(window->window);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class python_screen_viewer
|
|||||||
std::unique_ptr<gl::ubo> ubo;
|
std::unique_ptr<gl::ubo> ubo;
|
||||||
std::unique_ptr<gl::program> shader;
|
std::unique_ptr<gl::program> shader;
|
||||||
|
|
||||||
|
std::chrono::high_resolution_clock::time_point timestamp;
|
||||||
|
|
||||||
window_state() = default;
|
window_state() = default;
|
||||||
~window_state();
|
~window_state();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user