看来如果我足够快地拖动调整大小,窗口本身就是通过子类化qwindow并在其上创建一个openGLcontext来创建的.
码:
#include <QGuiApplication>
#include <QOpenGLContext>
#include <QWindow>
#include <QOpenGLFunctions_3_3_Core>
#include <stdio.h>
class OpenGLWindow : public QWindow, protected QOpenGLFunctions_3_3_Core{
public:
explicit OpenGLWindow();
~OpenGLWindow();
virtual void render();
bool isWindowInitialized;
void exposeEvent(QExposeEvent *event);
bool event(QEvent *event);
private:
QOpenGLContext* ctx;
QSurfaceFormat* fmt;
bool isGLInitialized;
GLuint VertexArrayID;
GLuint buffer1;
GLuint ProgramID;
};
bool OpenGLWindow::event(QEvent *event)
{
switch (event->type()) {
case QEvent::UpdateRequest:
render();
return true;
case QEvent::Close:
glDisableVertexAttribArray(0);
glDeleteBuffers(1, &buffer1);
glDeleteVertexArrays(1, &VertexArrayID);
glDeleteProgram(ProgramID);
return QWindow::event(event);
case QEvent::Resize:
if(isWindowInitialized && isGLInitialized)glViewport(0,0,width(),height());
return QWindow::event(event);
default:
return QWindow::event(event); …Run Code Online (Sandbox Code Playgroud) 作为 webGL 开发人员,这些图表让我心碎。如果垃圾收集器在主线程中运行阻塞超过半秒动画的工作流程,那么流畅的动画就不可能不间断地播放
我已经尝试了所有,缓存,对象池,声明全局变量并使我的返回函数像状态机一样工作,直到我最终发现即使对 RequestAnimationFrame 本身的空调用也可能每秒产生高达 1mb 的垃圾
对 RAF 的乒乓调用也不会改变我系统上的垃圾创建率
假设在 GC 启动时不可能有一个完全响应的 webgl 页面,我想知道是否有任何替代我们通常在 webgl 项目中看到的常用代码结构。起初我想使用 webWorker 并将主线程自由地留给 GC 而不中断动画渲染,但代价是深入研究 OffscreenCanvas 接口,但似乎它只在 Firefox atm 中受支持
使用 setTimeout 仍然会产生抖动并且被认为是不好的做法,所以我想知道是否真的有避免 GC 中断的解决方法