Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

# This will setup all of FAST's dependencies
add_definitions(-DQT_DISABLE_DEPRECATED_UP_TO=0x050F00) # Make FAST ready for Qt 6
include(cmake/Depdendencies.cmake)

if(FAST_BUILD_DOCS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void SurfaceExtraction::execute() {
} else {
// Transfer OpenCL buffer data to CPU
#ifdef FAST_MODULE_VISUALIZATION
QGLFunctions *fun = Window::getMainGLContext()->functions();
QOpenGLFunctions *fun = Window::getMainGLContext()->functions();
auto data = make_uninitialized_unique<float[]>(9*totalSum);
queue.enqueueReadBuffer(
coordinatesBuffer,
Expand Down
14 changes: 7 additions & 7 deletions source/FAST/Data/BoundingBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ BoundingBoxSetAccess::pointer BoundingBoxSet::getAccess(accessType type) {
if(!QApplication::instance()) {
Window::initializeQtApp();
}
if(QGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent();
if(QOpenGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent(Window::getQSurface());

QOpenGLFunctions_3_3_Core *fun = new QOpenGLFunctions_3_3_Core;
fun->initializeOpenGLFunctions();
Expand Down Expand Up @@ -203,9 +203,9 @@ BoundingBoxSetOpenGLAccess::pointer BoundingBoxSet::getOpenGLAccess(
if(!QApplication::instance()) {
Window::initializeQtApp();
}
if(QGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent();
QGLFunctions *fun = Window::getMainGLContext()->functions();
if(QOpenGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent(Window::getQSurface());
QOpenGLFunctions *fun = Window::getMainGLContext()->functions();
fun->glDeleteBuffers(1, &mCoordinateVBO);
fun->glGenBuffers(1, &mCoordinateVBO);
fun->glDeleteBuffers(1, &mLineEBO);
Expand Down Expand Up @@ -250,7 +250,7 @@ BoundingBoxSetOpenGLAccess::pointer BoundingBoxSet::getOpenGLAccess(
} else {
if(!mVBODataIsUpToDate) {
#ifdef FAST_MODULE_VISUALIZATION
QGLFunctions *fun = Window::getMainGLContext()->functions();
QOpenGLFunctions *fun = Window::getMainGLContext()->functions();
// Update VBO/EBO data from host
// Coordinates
fun->glBindBuffer(GL_ARRAY_BUFFER, mCoordinateVBO);
Expand Down Expand Up @@ -296,7 +296,7 @@ void BoundingBoxSet::freeAll() {
// Need mutual exclusive write lock to delete data
//VertexBufferObjectAccess::pointer access = getVertexBufferObjectAccess(ACCESS_READ_WRITE);
//Window::getMainGLContext()->makeCurrent(); // Need an active context to delete the mesh VBO
QGLFunctions *fun = Window::getMainGLContext()->functions();
QOpenGLFunctions *fun = Window::getMainGLContext()->functions();
// glDeleteBuffer is not used due to multi-threading issues..
//fun->glDeleteBuffers(1, &mVBOID);

Expand Down
2 changes: 1 addition & 1 deletion source/FAST/Data/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ void Image::freeAll() {
}
if(m_GLtextureID > 0) {
// We have to have current GL context to delete it
if(QGLContext::currentContext() == nullptr) {
if(QOpenGLContext::currentContext() == nullptr) {
reportWarning() << "Unable to delete texture because no OpenGL context was current" << reportEnd();
} else {
glDeleteTextures(1, &m_GLtextureID);
Expand Down
12 changes: 6 additions & 6 deletions source/FAST/Data/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ VertexBufferObjectAccess::pointer Mesh::getVertexBufferObjectAccess(
if(!QApplication::instance()) {
Window::initializeQtApp();
}
if(QGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent();
QGLFunctions *fun = Window::getMainGLContext()->functions();
if(QOpenGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent(Window::getQSurface());
QOpenGLFunctions *fun = Window::getMainGLContext()->functions();
fun->glDeleteBuffers(1, &mCoordinateVBO);
fun->glGenBuffers(1, &mCoordinateVBO);
if(mHostHasData) {
Expand Down Expand Up @@ -275,8 +275,8 @@ MeshAccess::pointer Mesh::getMeshAccess(accessType type) {
if(!QApplication::instance()) {
Window::initializeQtApp();
}
if(QGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent();
if(QOpenGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent(Window::getQSurface());

QOpenGLFunctions_3_3_Core *fun = new QOpenGLFunctions_3_3_Core;
fun->initializeOpenGLFunctions();
Expand Down Expand Up @@ -467,7 +467,7 @@ void Mesh::freeAll() {
// Need mutual exclusive write lock to delete data
//VertexBufferObjectAccess::pointer access = getVertexBufferObjectAccess(ACCESS_READ_WRITE);
//Window::getMainGLContext()->makeCurrent(); // Need an active context to delete the mesh VBO
QGLFunctions *fun = Window::getMainGLContext()->functions();
QOpenGLFunctions *fun = Window::getMainGLContext()->functions();
// glDeleteBuffer is not used due to multi-threading issues..
//fun->glDeleteBuffers(1, &mVBOID);

Expand Down
8 changes: 4 additions & 4 deletions source/FAST/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ std::vector<OpenCLDevice::pointer> DeviceManager::getDevices(DeviceCriteria crit
if(enableVisualization) {
#ifdef FAST_MODULE_VISUALIZATION
fast::Window::getMainGLContext(); // Still have to create GL context
Window::getMainGLContext()->makeCurrent();
Window::getMainGLContext()->makeCurrent(nullptr); // If not nullptr here, we get NV-GLX missing on display error
#endif
#if defined(__APPLE__) || defined(__MACOSX)
CGLContextObj appleContext = CGLGetCurrentContext();
Expand Down Expand Up @@ -242,8 +242,8 @@ bool DeviceManager::deviceSatisfiesCriteria(OpenCLDevice::pointer device,
bool DeviceManager::deviceHasOpenGLInteropCapability(const cl::Device &device, const cl::Platform &platform) {
#ifndef _WIN32
if(platform.getInfo<CL_PLATFORM_VENDOR>().find("NVIDIA") != std::string::npos) {
reportInfo() << "NVIDIA platform was detected on linux, disabling OpenGL interop due to error Xlib extension NV-GLX missing" << reportEnd();
return false;
//reportInfo() << "NVIDIA platform was detected on linux, disabling OpenGL interop due to error Xlib extension NV-GLX missing" << reportEnd();
//return false;
}
#endif
// Get the cl_device_id of the device
Expand All @@ -253,7 +253,7 @@ bool DeviceManager::deviceHasOpenGLInteropCapability(const cl::Device &device, c
// Get all devices that are capable of OpenGL interop with this platform
// Create properties for CL-GL context
#ifdef FAST_MODULE_VISUALIZATION
Window::getMainGLContext()->makeCurrent();
Window::getMainGLContext()->makeCurrent(Window::getQSurface());
#endif
unsigned long* glContext;
#if defined(__APPLE__) || defined(__MACOSX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import PySide2.QtSvg # Must import this before fast due to conflicting symbols
import fast # Must import FAST before rest of pyside2
from PySide2.QtWidgets import *
from PySide2.QtOpenGL import QGLWidget
from PySide2.QtCore import Slot
from shiboken2 import wrapInstance

Expand All @@ -31,12 +30,12 @@ def __init__(self):

# Create FAST view
self.view = fast.View()
self.installEventFilter(wrapInstance(int(self.view.asQGLWidget()), QGLWidget))
self.installEventFilter(wrapInstance(int(self.view.asQGLWidget()), QOpenGLWidget))
self.view.set2DMode()

# Create layout and add widgets
layout = QVBoxLayout()
layout.addWidget(wrapInstance(int(self.view.asQGLWidget()), QGLWidget))
layout.addWidget(wrapInstance(int(self.view.asQGLWidget()), QOpenGLWidget))
layout.addWidget(self.button)
self.setLayout(layout)

Expand Down
7 changes: 3 additions & 4 deletions source/FAST/Tools/OpenIGTLinkServer/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,14 @@ static igtl::ImageMessage::Pointer createIGTLImageMessage(Image::pointer image)
void GUI::streamData() {
// Hack to make this work on windows (get issues with switching GL context to thread):
// 1. Create a new GL context in this thread
QGLWidget* widget = new QGLWidget;
QGLContext* mainGLContext = new QGLContext(QGLFormat::defaultFormat(), widget); // by including widget here the context becomes valid
auto mainGLContext = new QOpenGLContext();
mainGLContext->create();
if (!mainGLContext->isValid()) {
if(!mainGLContext->isValid()) {
throw Exception("Qt GL context is invalid!");
}
// 2. Substitute the GL context in the window with this one
setMainGLContext(mainGLContext);
mainGLContext->makeCurrent();
mainGLContext->makeCurrent(nullptr);

reportInfo() << "Listening for new connections on port " << mPort << reportEnd();
try {
Expand Down
7 changes: 3 additions & 4 deletions source/FAST/Visualization/ComputationThread.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "ComputationThread.hpp"
#include "SimpleWindow.hpp"
#include "View.hpp"
#include <QGLContext>
#include <QApplication>
#include <QMessageBox>

Expand Down Expand Up @@ -30,8 +29,8 @@ void ComputationThread::run() {
mIsRunning = true;
mStop = false;
}
QGLContext* mainGLContext = Window::getMainGLContext();
mainGLContext->makeCurrent();
auto mainGLContext = Window::getMainGLContext();
mainGLContext->makeCurrent(Window::getQSurface());

m_signalFinished = true;

Expand Down Expand Up @@ -216,7 +215,7 @@ QThread* ComputationThread::start() {
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));

std::weak_ptr<Window> ptr = std::static_pointer_cast<Window>(mPtr.lock());
QGLContext* mainGLContext = Window::getMainGLContext();
auto mainGLContext = Window::getMainGLContext();
if(!mainGLContext->isValid()) {
throw Exception("QGL context is invalid!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "FAST/Utility.hpp"
#include "FAST/SceneGraph.hpp"
#include <FAST/Data/ImagePyramid.hpp>
#include <QGLContext>
#include <FAST/Visualization/Window.hpp>
#include <FAST/Visualization/View.hpp>
#include <FAST/Algorithms/ImageSharpening/ImageSharpening.hpp>
Expand Down Expand Up @@ -87,28 +86,29 @@ ImagePyramidRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, f
if(!m_bufferThread) {
// Create thread to load patches
// Create a GL context for the thread which is sharing with the context of the view
auto context = new QGLContext(View::getGLFormat(), m_view);
context->create(m_view->context());
auto context = new QOpenGLContext(m_view);
context->setShareContext(m_view->context());
context->create();

if(!context->isValid())
throw Exception("The custom Qt GL context is invalid!");

if(!context->isSharing())
if(!context->areSharing(context, m_view->context()))
throw Exception("The custom Qt GL context is not sharing!");

context->makeCurrent();
context->makeCurrent(Window::getQSurface());
#ifdef WIN32
auto nativeContextHandle = wglGetCurrentContext();
context->doneCurrent();
m_view->context()->makeCurrent();
m_view->context()->makeCurrent(Window::getQSurface());
auto dc = wglGetCurrentDC();

m_bufferThread = std::make_unique<std::thread>([this, dc, nativeContextHandle]() {
wglMakeCurrent(dc, nativeContextHandle);
#elif defined(__APPLE__)
auto nativeContextHandle = CGLGetCurrentContext();
context->doneCurrent();
m_view->context()->makeCurrent();
m_view->context()->makeCurrent(Window::getQSurface());

m_bufferThread = std::make_unique<std::thread>([this, nativeContextHandle]() {
CGLSetCurrentContext(nativeContextHandle);
Expand All @@ -117,7 +117,7 @@ ImagePyramidRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, f
auto drawable = glXGetCurrentDrawable();
auto display = glXGetCurrentDisplay();
context->doneCurrent();
m_view->context()->makeCurrent();
m_view->context()->makeCurrent(Window::getQSurface());

m_bufferThread = std::make_unique<std::thread>([this, display, drawable, nativeContextHandle]() {
glXMakeCurrent(display, drawable, nativeContextHandle);
Expand Down
20 changes: 11 additions & 9 deletions source/FAST/Visualization/RenderToImage/RenderToImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <FAST/Visualization/VolumeRenderer/VolumeRenderer.hpp>
#include <FAST/Visualization/Window.hpp>
#include <FAST/Data/Image.hpp>
#include <QGLContext>
#include <QOpenGLContext>
#include <FAST/Algorithms/ImageFlipper/ImageFlipper.hpp>

namespace fast {
Expand All @@ -23,22 +23,24 @@ RenderToImage::RenderToImage(Color bgcolor, int width, int height) {

if(QThread::currentThread() == QApplication::instance()->thread()) { // Is main thread?
// Main thread..
QGLContext *context = new QGLContext(View::getGLFormat(), fast::Window::getSecondaryGLContext()->device());
context->create(fast::Window::getSecondaryGLContext());
if(!context->isValid() || !context->isSharing()) {
auto context = new QOpenGLContext();
context->setShareContext(fast::Window::getSecondaryGLContext());
context->create();
if(!context->isValid() || !context->areSharing(context, fast::Window::getSecondaryGLContext())) {
throw Exception("The custom Qt GL context in fast::View is invalid!");
}
m_context = context;
} else {
// Computation thread
QGLContext *context = new QGLContext(View::getGLFormat(), fast::Window::getMainGLContext()->device());
context->create(fast::Window::getMainGLContext());
if(!context->isValid() || !context->isSharing()) {
auto context = new QOpenGLContext();
context->setShareContext(fast::Window::getMainGLContext());
context->create();
if(!context->isValid() || !context->areSharing(context, fast::Window::getMainGLContext())) {
throw Exception("The custom Qt GL context in fast::View is invalid!");
}
m_context = context;
}
m_context->makeCurrent();
m_context->makeCurrent(Window::getQSurface());
initializeOpenGLFunctions();
}

Expand Down Expand Up @@ -81,7 +83,7 @@ std::vector<Renderer::pointer> RenderToImage::getRenderers() {
}

void RenderToImage::execute() {
m_context->makeCurrent();
m_context->makeCurrent(Window::getQSurface());
bool doContinue = true;
for(auto renderer : getRenderers()) {
renderer->update(m_executeToken);
Expand Down
4 changes: 2 additions & 2 deletions source/FAST/Visualization/RenderToImage/RenderToImage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <FAST/Visualization/Renderer.hpp>
#include <FAST/Data/Color.hpp>

class QGLContext;
class QOpenGLContext;

namespace fast {

Expand Down Expand Up @@ -77,7 +77,7 @@ class FAST_EXPORT RenderToImage : public ProcessObject, protected QOpenGLFunctio

float mLeft, mRight, mBottom, mTop; // Used for ortho projection

QGLContext* m_context;
QOpenGLContext* m_context;
protected:
void recalculateCamera();
void getMinMaxFromBoundingBoxes(bool transform, Vector3f& min, Vector3f& max);
Expand Down
5 changes: 3 additions & 2 deletions source/FAST/Visualization/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ DataBoundingBox Renderer::getBoundingBox(bool transform) {
void Renderer::createShaderProgram(std::vector<std::string> shaderFilenames, std::string programName) {
// We need an active GL context to do this, and we also need to initialize the OpenGLFunctions
// First check if an there is an active GL context
if(QGLContext::currentContext() == nullptr)
Window::getMainGLContext()->makeCurrent();
if(QOpenGLContext::currentContext() == nullptr) {
Window::getMainGLContext()->makeCurrent(Window::getQSurface());
}
initializeOpenGLFunctions();

uint programID = glCreateProgram();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifdef FAST_MODULE_WSI
#include <FAST/Data/ImagePyramid.hpp>
#include <FAST/Visualization/Window.hpp>
#endif
#include "SegmentationRenderer.hpp"
#include <QGLContext>
#include <FAST/Visualization/View.hpp>
#ifdef WIN32
#elif defined(__APPLE__) || defined(__MACOSX)
Expand Down Expand Up @@ -136,28 +136,29 @@ void SegmentationRenderer::drawPyramid(std::shared_ptr<SpatialDataObject> dataTo
if(!m_bufferThread) {
// Create thread to load patches
// Create a GL context for the thread which is sharing with the context of the view
auto context = new QGLContext(View::getGLFormat(), m_view);
context->create(m_view->context());
auto context = new QOpenGLContext(m_view);
context->setShareContext(m_view->context());
context->create();

if(!context->isValid())
throw Exception("The custom Qt GL context is invalid!");

if(!context->isSharing())
if(!context->areSharing(context, m_view->context()))
throw Exception("The custom Qt GL context is not sharing!");

context->makeCurrent();
context->makeCurrent(Window::getQSurface());
#ifdef WIN32
auto nativeContextHandle = wglGetCurrentContext();
context->doneCurrent();
m_view->context()->makeCurrent();
m_view->context()->makeCurrent(Window::getQSurface());
auto dc = wglGetCurrentDC();

m_bufferThread = std::make_unique<std::thread>([this, dc, nativeContextHandle]() {
wglMakeCurrent(dc, nativeContextHandle);
#elif defined(__APPLE__)
auto nativeContextHandle = CGLGetCurrentContext();
context->doneCurrent();
m_view->context()->makeCurrent();
m_view->context()->makeCurrent(Window::getQSurface());

m_bufferThread = std::make_unique<std::thread>([this, nativeContextHandle]() {
CGLSetCurrentContext(nativeContextHandle);
Expand All @@ -166,7 +167,7 @@ void SegmentationRenderer::drawPyramid(std::shared_ptr<SpatialDataObject> dataTo
auto drawable = glXGetCurrentDrawable();
auto display = glXGetCurrentDisplay();
context->doneCurrent();
m_view->context()->makeCurrent();
m_view->context()->makeCurrent(Window::getQSurface());

m_bufferThread = std::make_unique<std::thread>([this, display, drawable, nativeContextHandle]() {
glXMakeCurrent(display, drawable, nativeContextHandle);
Expand Down
Loading
Loading