QT4で、OpenGLレンダリングを実行し、その結果をWebSocketを介してネットワーク経由で送信するヘッドレスコンソールアプリケーションの作成に取り組んでいます。すべてのレンダリングとネットワークコードを実行していますが(GUIがあると仮定)、ヘッドレスアプリケーションへの移行に問題があります。ウィンドウなしでQGLContextを作成することは可能ですか?
Webでの読み取りはそれほど多くはありませんが、私が収集したものから、有効なQPaintDeviceであるQGLPixelBufferを作成できます。ハードウェアアクセラレーションによる描画に使用する独自のプライベートQGLContextを作成しているようです。このルートで発生している問題は、別のスレッド(レンダリングされたシーンからの高速DMAテクスチャ転送用のネットワークスレッド)と共有できるように、基になるQGLContextにアクセスする必要があることです。以下に含まれているのは小さなプロトタイプです。何か案は?
Application.h
/**
@file
@author Nikolaus Karpinsky
*/
#ifndef _APPLICATION_H_
#define _APPLICATION_H_
#include <QCoreApplication>
#include <QTimer>
#include "MainController.h"
#endif // _APPLICATION_H_
Application.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();
}
MainController.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_
MainController.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() );
}