mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-21 07:24:57 +01:00
With python.threadedupload (the default) the worker wrote the image into the texture the drawing thread draws from, with glTexImage2D and glGenerateMipmap from its own context, and only a glFlush after. Nothing ordered the two contexts: the drawing one could sample the texture while its storage was being made anew, its level 0 half written or its mipmaps not made yet, and on a change of size the worker deleted the texture and wrote a new name into `id` with no synchronisation. The worker now uploads each image into a new texture, sets a fence after it and flushes. The drawing thread, once per frame in python_taskqueue::update(), waits for that fence on the gpu (glWaitSync, the cpu goes on), deletes the old texture and puts the new one in place. The worker no longer touches the texture drawn from, nor `id`. An image the drawing thread didn't take yet is dropped by the next one. Without sync objects the worker waits for the upload with glFinish. The windows of python.displaywindows with python.sharectx bound the texture once; they now bind the name of the last image put in place, which python_rt keeps for them. Uploads on the drawing thread (python.threadedupload no, the Lua and WebAssembly screens, the editor) are as they were.
49 lines
1.5 KiB
C++
49 lines
1.5 KiB
C++
#include "rendering/renderer.h"
|
|
#include "scripting/PyInt.h"
|
|
#include <GLFW/glfw3.h>
|
|
|
|
class python_screen_viewer
|
|
{
|
|
struct window_state {
|
|
GLFWwindow *window = nullptr;
|
|
|
|
glm::ivec2 window_size;
|
|
glm::ivec2 fb_size;
|
|
glm::ivec2 cursor_pos;
|
|
|
|
glm::vec2 offset;
|
|
glm::vec2 scale;
|
|
|
|
std::unique_ptr<gl::ubo> ubo;
|
|
std::unique_ptr<gl::program> shader;
|
|
|
|
std::chrono::high_resolution_clock::time_point timestamp;
|
|
size_t shared_texture{0}; // with python.sharectx, the texture of the screen bound in this window's context
|
|
|
|
window_state() = default;
|
|
~window_state();
|
|
};
|
|
|
|
std::vector<std::unique_ptr<window_state>> m_windows;
|
|
|
|
std::shared_ptr<python_rt> m_rt;
|
|
std::shared_ptr<std::vector<glm::vec2>> m_touchlist;
|
|
std::shared_ptr<std::thread> m_renderthread;
|
|
gl::scene_ubs m_ubs;
|
|
|
|
std::atomic_bool m_exit = false;
|
|
|
|
void threadfunc();
|
|
// with python.sharectx, binds the texture with the last image of the screen, in the context of the window made current
|
|
void bind_shared_texture(window_state &Window) const;
|
|
|
|
public:
|
|
python_screen_viewer(std::shared_ptr<python_rt> rt, std::shared_ptr<std::vector<glm::vec2>> touchlist, std::string const &name);
|
|
~python_screen_viewer();
|
|
|
|
void notify_window_size(GLFWwindow const *window, int w, int h) const;
|
|
void notify_window_fb_size(GLFWwindow const *window, int w, int h) const;
|
|
void notify_cursor_pos(GLFWwindow const *window, double x, double y) const;
|
|
void notify_click(GLFWwindow const *window, int button, int action) const;
|
|
};
|