rhi: Make it possible to request making the context current on GL

Needed by Qt Quick to handle cases where the application (or other Qt)
code contains OpenGL calls, and Qt Quick facilitates this by ensuring
the scenegraph's GL context is current. The expectation is that when
running with the GL backend of the rhi, all such code remains fully
functional. So add a makeCurrent type of call into the QRhi API that is
a no-op with anything other than OpenGL.

Change-Id: I6f774bf828e31802bdab0c3fef9421cdc0cebe5c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Laszlo Agocs 2019-06-17 12:17:19 +02:00
parent 39d74b5b3d
commit 4c297bdca8
13 changed files with 49 additions and 0 deletions

View File

@ -4443,6 +4443,20 @@ const QRhiNativeHandles *QRhi::nativeHandles()
return d->nativeHandles();
}
/*!
With OpenGL this makes the OpenGL context current on the current thread.
The function has no effect with other backends.
Calling this function is relevant typically in Qt framework code, when one
has to ensure external OpenGL code provided by the application can still
run like it did before with direct usage of OpenGL, as long as the QRhi is
using the OpenGL backend.
*/
void QRhi::makeThreadLocalNativeContextCurrent()
{
d->makeThreadLocalNativeContextCurrent();
}
/*!
\return the associated QRhiProfiler instance.

View File

@ -1352,6 +1352,7 @@ public:
int resourceLimit(ResourceLimit limit) const;
const QRhiNativeHandles *nativeHandles();
void makeThreadLocalNativeContextCurrent();
QRhiProfiler *profiler();

View File

@ -148,6 +148,7 @@ public:
virtual int resourceLimit(QRhi::ResourceLimit limit) const = 0;
virtual const QRhiNativeHandles *nativeHandles() = 0;
virtual void sendVMemStatsToProfiler() = 0;
virtual void makeThreadLocalNativeContextCurrent() = 0;
bool isCompressedFormat(QRhiTexture::Format format) const;
void compressedFormatInfo(QRhiTexture::Format format, const QSize &size,

View File

@ -408,6 +408,11 @@ void QRhiD3D11::sendVMemStatsToProfiler()
// nothing to do here
}
void QRhiD3D11::makeThreadLocalNativeContextCurrent()
{
// nothing to do here
}
QRhiRenderBuffer *QRhiD3D11::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
int sampleCount, QRhiRenderBuffer::Flags flags)
{

View File

@ -563,6 +563,7 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
void makeThreadLocalNativeContextCurrent() override;
void flushCommandBuffer();
void enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cbD,

View File

@ -649,6 +649,14 @@ void QRhiGles2::sendVMemStatsToProfiler()
// nothing to do here
}
void QRhiGles2::makeThreadLocalNativeContextCurrent()
{
if (inFrame && !ofr.active)
ensureContext(currentSwapChain->surface);
else
ensureContext();
}
QRhiRenderBuffer *QRhiGles2::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
int sampleCount, QRhiRenderBuffer::Flags flags)
{

View File

@ -574,6 +574,7 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
void makeThreadLocalNativeContextCurrent() override;
bool ensureContext(QSurface *surface = nullptr) const;
void executeDeferredReleases();

View File

@ -538,6 +538,11 @@ void QRhiMetal::sendVMemStatsToProfiler()
// nothing to do here
}
void QRhiMetal::makeThreadLocalNativeContextCurrent()
{
// nothing to do here
}
QRhiRenderBuffer *QRhiMetal::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
int sampleCount, QRhiRenderBuffer::Flags flags)
{

View File

@ -375,6 +375,7 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
void makeThreadLocalNativeContextCurrent() override;
void executeDeferredReleases(bool forced = false);
void finishActiveReadbacks(bool forced = false);

View File

@ -166,6 +166,11 @@ void QRhiNull::sendVMemStatsToProfiler()
// nothing to do here
}
void QRhiNull::makeThreadLocalNativeContextCurrent()
{
// nothing to do here
}
QRhiRenderBuffer *QRhiNull::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
int sampleCount, QRhiRenderBuffer::Flags flags)
{

View File

@ -268,6 +268,7 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
void makeThreadLocalNativeContextCurrent() override;
QRhiNullNativeHandles nativeHandlesStruct;
QRhiSwapChain *currentSwapChain = nullptr;

View File

@ -3457,6 +3457,11 @@ void QRhiVulkan::sendVMemStatsToProfiler()
stats.total.usedBytes, stats.total.unusedBytes));
}
void QRhiVulkan::makeThreadLocalNativeContextCurrent()
{
// nothing to do here
}
QRhiRenderBuffer *QRhiVulkan::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
int sampleCount, QRhiRenderBuffer::Flags flags)
{

View File

@ -644,6 +644,7 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
void makeThreadLocalNativeContextCurrent() override;
VkResult createDescriptorPool(VkDescriptorPool *pool);
bool allocateDescriptorSet(VkDescriptorSetAllocateInfo *allocInfo, VkDescriptorSet *result, int *resultPoolIndex);