merge manul

This commit is contained in:
WLs50
2025-03-09 15:36:11 +01:00
parent a687f551a2
commit a5f6397eca
1211 changed files with 483542 additions and 58643 deletions

View File

@@ -48,7 +48,6 @@ void render_task::run() {
PyDict_SetItemString(input, datapair.first.c_str(), list);
Py_DECREF(list);
}
delete m_input;
m_input = nullptr;
// call the renderer
@@ -69,32 +68,30 @@ void render_task::run() {
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 (false && !Global.gfx_usegles)
{
int size = width * height * 3;
format = GL_SRGB8;
components = GL_RGB;
m_target->image = new unsigned char[size];
memcpy(m_target->image, image, size);
m_target->image.resize(size);
memcpy(m_target->image.data(), image, size);
}
else
{
format = GL_SRGB8_ALPHA8;
components = GL_RGBA;
m_target->image = new unsigned char[width * height * 4];
m_target->image.resize(width * height * 4);
int w = width;
int h = height;
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++)
{
m_target->image[(y * w + x) * 4 + 0] = image[(y * w + x) * 3 + 0];
m_target->image[(y * w + x) * 4 + 1] = image[(y * w + x) * 3 + 1];
m_target->image[(y * w + x) * 4 + 2] = image[(y * w + x) * 3 + 2];
m_target->image[(y * w + x) * 4 + 3] = 0xFF;
m_target->image[(y * w + x) * 4 + 0] = image[(y * w + x) * 4 + 0];
m_target->image[(y * w + x) * 4 + 1] = image[(y * w + x) * 4 + 1];
m_target->image[(y * w + x) * 4 + 2] = image[(y * w + x) * 4 + 2];
m_target->image[(y * w + x) * 4 + 3] = image[(y * w + x) * 4 + 3];
}
}
@@ -112,36 +109,33 @@ void render_task::run() {
void render_task::upload()
{
if (Global.python_uploadmain && m_target->image)
if (Global.python_uploadmain && m_target && m_target->shared_tex)
{
glBindTexture(GL_TEXTURE_2D, m_target->shared_tex);
glTexImage2D(
GL_TEXTURE_2D, 0,
m_target->format,
m_target->width, m_target->height, 0,
m_target->components, GL_UNSIGNED_BYTE, m_target->image);
if (Global.python_mipmaps)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
if (Global.python_threadedupload)
glFlush();
m_target->shared_tex->update_from_memory(m_target->width, m_target->height, reinterpret_cast<const uint8_t*>(m_target->image.data()));
//glBindTexture(GL_TEXTURE_2D, m_target->shared_tex->get_id());
//glTexImage2D(
// GL_TEXTURE_2D, 0,
// m_target->format,
// m_target->width, m_target->height, 0,
// m_target->components, GL_UNSIGNED_BYTE, m_target->image);
//
//if (Global.python_mipmaps)
//{
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// glGenerateMipmap(GL_TEXTURE_2D);
//}
//else
//{
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//}
//
//if (Global.python_threadedupload)
// glFlush();
}
delete this;
}
void render_task::cancel() {
delete m_input;
delete this;
}
// initializes the module. returns true on success
@@ -239,7 +233,7 @@ void python_taskqueue::exit() {
}
// get rid of the leftover tasks
// with the workers dead we don't have to worry about concurrent access anymore
for( auto *task : m_tasks.data ) {
for( auto task : m_tasks.data ) {
task->cancel();
}
// take a bow
@@ -259,7 +253,7 @@ auto python_taskqueue::insert( task_request const &Task ) -> bool {
auto *renderer { fetch_renderer( Task.renderer ) };
if( renderer == nullptr ) { return false; }
auto *newtask { new render_task( renderer, Task.input, Task.target ) };
auto newtask = std::make_shared<render_task>( renderer, Task.input, Task.target );
bool newtaskinserted { false };
// acquire a lock on the task queue and add the new task
{
@@ -341,13 +335,15 @@ auto python_taskqueue::fetch_renderer( std::string const Renderer ) ->PyObject *
ErrorLog( "Python Renderer: class \"" + file + "\" not defined" );
goto cache_and_return;
}
rendererarguments = Py_BuildValue( "(s)", path.c_str() );
rendererarguments = Py_BuildValue("(s)", path.c_str());
if( rendererarguments == nullptr ) {
ErrorLog( "Python Renderer: failed to create initialization arguments" );
goto cache_and_return;
}
renderer = PyObject_CallObject( renderername, rendererarguments );
PyObject_CallMethod(renderer, "manul_set_format", "(s)", "RGBA");
if( PyErr_Occurred() != nullptr ) {
error();
renderer = nullptr;
@@ -375,7 +371,7 @@ void python_taskqueue::run( GLFWwindow *Context, rendertask_sequence &Tasks, upl
auto *threadstate { PyThreadState_New( m_mainthread->interp ) };
PyEval_ReleaseLock();
render_task *task { nullptr };
std::shared_ptr<render_task> task { nullptr };
while( false == Exit.load() ) {
// regardless of the reason we woke up prime the spurious wakeup flag for the next time