gpt4 book ai didi

c++ - headless QT4 OpenGL 应用程序

转载 作者:搜寻专家 更新时间:2023-10-31 01:51:01 25 4
gpt4 key购买 nike

我正致力于在 QT4 中创建一个 headless 控制台应用程序,该应用程序执行一些 OpenGL 渲染,然后通过网络套接字将结果发送到网络。我已经运行了所有的渲染和网络代码(假设我有一个 GUI),但是我在转换到 headless 应用程序时遇到了一些麻烦。是否可以在没有窗口的情况下创建 QGLContext?

在网络上阅读的内容并不多,但根据我收集到的信息,您可以创建一个 QGLPixelBuffer,它是一个有效的 QPaintDevice。它似乎创建了自己的私有(private) QGLContext 用于硬件加速绘图。我在这条路线上遇到的问题是我需要访问它的底层 QGLContext 以便我可以与另一个线程共享它(用于快速 DMA 纹理传输出渲染场景的网络线程)。下面包括一个小原型(prototype)。有什么想法吗?

应用程序.h

/**
@file
@author Nikolaus Karpinsky
*/

#ifndef _APPLICATION_H_
#define _APPLICATION_H_

#include <QCoreApplication>
#include <QTimer>

#include "MainController.h"

#endif // _APPLICATION_H_

应用程序.cpp

#include "Application.h"

int main(int argc, char **argv)
{
// Setup our console application with an event loop
QCoreApplication app(argc, argv);

// Create and initialize our controller
MainController controller;
controller.Init();
QObject::connect(&controller, SIGNAL( Finished() ), &app, SLOT( quit() ), Qt::QueuedConnection);

// This will put start on top of the event loop
QTimer::singleShot(0, &controller, SLOT( Start() ));

// Finally start up the event loop
return app.exec();
}

主 Controller .h

/**
@file
@author Nikolaus Karpinsky
*/

#ifndef _MAIN_CONTROLLER_H_
#define _MAIN_CONTROLLER_H_

#include <QObject>
#include <QGLWidget>
#include <QGLPixelBuffer>
#include <QGLFramebufferObject>
#include <memory>

using namespace std;

class MainController : public QObject
{
Q_OBJECT

private:
unqiue_ptr<QGLPixelBuffer> m_mainBuffer;
//unique_ptr<QGLContext> m_mainContext;

public:
MainController();
void Init(void);

public slots:
void Start(void);
void Close(void);

signals:
void Finished(void);
};

#endif // _MAIN_CONTROLLER_H_

主 Controller .cpp

#include "MainController.h"

MainController::MainController() : QObject()
{ }

void MainController::Init(void)
{
m_mainBuffer = unique_ptr<QGLPixelBuffer>(new QGLPixelBuffer(800, 600));
bool has = buffer->hasOpenGLPbuffers();
bool current = buffer->makeCurrent();
bool valid = buffer->isValid();

// Now I need to get access to the context to share it with additional threads
// m_mainContext = unique_ptr<QGLContext>(new QGLContext(buffer.getContext()));
}

void MainController::Start(void)
{
}

void MainController::Close(void)
{
// This will tell the event loop that we are done and close the app
emit( Finished() );
}

最佳答案

Is it possible to create a QGLContext without having a window?

是的,但是有一个问题……

Reading on the web hasn't turned up much, but from what I have gathered you can create a QGLPixelBuffer which is a valid QPaintDevice.

是的,但是 PBuffer 仍然需要与 GPU 通信。在 Linux 中,与 GPU 通信的通常方式是通过 X 服务器。因此,您实际上需要一个使用 GPU 驱动程序的 X 服务器来启动事件 VT,以便 PBuffer 可以在 GPU 上工作。

希望 GPU 很快就会有一个新的 ABI/API,它允许您在 GPU 上创建屏幕外渲染上下文,而无需周围有 X 服务器。

The problem that I am having with this route is that I need access to it's underlying QGLContext so that I can share it with another thread (network thread for fast DMA texture transfers out of the rendered scene).

不幸的是,Qt 开发人员似乎对 OpenGL 的了解有限。 OpenGL 可以完美实现并明确指定的一些事情在 Qt 中是不可能的,原因不明。例如,您可以使用单个可绘制对象拥有任意数量的上下文。但是您也可以通过重新绑定(bind)在任意数量的(兼容的)可绘制对象上使用单个上下文。 Qt 和明显的设计缺陷都不支持它们。我自己现在也在为此苦苦挣扎。

关于c++ - headless QT4 OpenGL 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14347286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com