mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 05:03:41 +02:00
Display plugins now use gpu::Context API
This commit is contained in:
parent
6d7edd38cc
commit
cac529a1b1
5 changed files with 36 additions and 30 deletions
|
@ -5385,7 +5385,7 @@ void Application::updateDisplayMode() {
|
|||
DisplayPluginList advanced;
|
||||
DisplayPluginList developer;
|
||||
foreach(auto displayPlugin, displayPlugins) {
|
||||
displayPlugin->setBackend(_gpuContext->getBackend());
|
||||
displayPlugin->setContext(_gpuContext);
|
||||
auto grouping = displayPlugin->getGrouping();
|
||||
switch (grouping) {
|
||||
case Plugin::ADVANCED:
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <ui-plugins/PluginContainer.h>
|
||||
#include <FramebufferCache.h>
|
||||
#include <gpu/Frame.h>
|
||||
#include <gpu/Context.h>
|
||||
|
||||
const QString NullDisplayPlugin::NAME("NullDisplayPlugin");
|
||||
|
||||
|
@ -24,9 +25,9 @@ bool NullDisplayPlugin::hasFocus() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
void NullDisplayPlugin::submitFrame(const gpu::FramePointer& resultFramebuffer) {
|
||||
if (resultFramebuffer) {
|
||||
resultFramebuffer->preRender();
|
||||
void NullDisplayPlugin::submitFrame(const gpu::FramePointer& frame) {
|
||||
if (frame) {
|
||||
_gpuContext->consumeFrameUpdates(frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -425,8 +425,7 @@ void OpenGLDisplayPlugin::uncustomizeContext() {
|
|||
withPresentThreadLock([&] {
|
||||
_currentFrame.reset();
|
||||
while (!_newFrameQueue.empty()) {
|
||||
_currentFrame = _newFrameQueue.front();
|
||||
_currentFrame->preRender();
|
||||
_gpuContext->consumeFrameUpdates(_newFrameQueue.front());
|
||||
_newFrameQueue.pop();
|
||||
}
|
||||
});
|
||||
|
@ -491,12 +490,12 @@ void OpenGLDisplayPlugin::updateFrameData() {
|
|||
uint32_t skippedCount = 0;
|
||||
if (!_newFrameQueue.empty()) {
|
||||
// We're changing frames, so we can cleanup any GL resources that might have been used by the old frame
|
||||
getGLBackend()->cleanupTrash();
|
||||
_gpuContext->recycle();
|
||||
}
|
||||
while (!_newFrameQueue.empty()) {
|
||||
_currentFrame = _newFrameQueue.front();
|
||||
_currentFrame->preRender();
|
||||
_newFrameQueue.pop();
|
||||
_gpuContext->consumeFrameUpdates(_currentFrame);
|
||||
if (_currentFrame && oldFrame) {
|
||||
skippedCount += (_currentFrame->frameIndex - oldFrame->frameIndex) - 1;
|
||||
}
|
||||
|
@ -604,17 +603,18 @@ void OpenGLDisplayPlugin::internalPresent() {
|
|||
void OpenGLDisplayPlugin::present() {
|
||||
PROFILE_RANGE_EX(__FUNCTION__, 0xffffff00, (uint64_t)presentCount())
|
||||
updateFrameData();
|
||||
|
||||
incrementPresentCount();
|
||||
|
||||
{
|
||||
PROFILE_RANGE_EX("recycle", 0xff00ff00, (uint64_t)presentCount())
|
||||
_gpuContext->recycle();
|
||||
}
|
||||
|
||||
if (_currentFrame) {
|
||||
_backend->cleanupTrash();
|
||||
_backend->setStereoState(_currentFrame->stereoState);
|
||||
{
|
||||
PROFILE_RANGE_EX("execute", 0xff00ff00, (uint64_t)presentCount())
|
||||
// Execute the frame rendering commands
|
||||
for (auto& batch : _currentFrame->batches) {
|
||||
_backend->render(batch);
|
||||
}
|
||||
PROFILE_RANGE_EX("execute", 0xff00ff00, (uint64_t)presentCount())
|
||||
_gpuContext->executeFrame(_currentFrame);
|
||||
}
|
||||
|
||||
// Write all layers to a local framebuffer
|
||||
|
@ -718,17 +718,22 @@ ivec4 OpenGLDisplayPlugin::eyeViewport(Eye eye) const {
|
|||
}
|
||||
|
||||
gpu::gl::GLBackend* OpenGLDisplayPlugin::getGLBackend() {
|
||||
if (!_backend) {
|
||||
if (!_gpuContext || !_gpuContext->getBackend()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto backend = _backend.get();
|
||||
auto backend = _gpuContext->getBackend().get();
|
||||
#if Q_OS_MAC
|
||||
// Should be dynamic_cast, but that doesn't work in plugins on OSX
|
||||
auto glbackend = static_cast<gpu::gl::GLBackend*>(backend);
|
||||
#else
|
||||
auto glbackend = dynamic_cast<gpu::gl::GLBackend*>(backend);
|
||||
#endif
|
||||
|
||||
return glbackend;
|
||||
}
|
||||
|
||||
void OpenGLDisplayPlugin::render(std::function<void(gpu::Batch& batch)> f) {
|
||||
gpu::Batch batch;
|
||||
f(batch);
|
||||
batch.flush();
|
||||
_backend->render(batch);
|
||||
_gpuContext->executeBatch(batch);
|
||||
}
|
||||
|
|
|
@ -69,14 +69,14 @@ glm::uvec2 InterleavedStereoDisplayPlugin::getRecommendedRenderSize() const {
|
|||
}
|
||||
|
||||
void InterleavedStereoDisplayPlugin::internalPresent() {
|
||||
gpu::Batch presentBatch;
|
||||
presentBatch.enableStereo(false);
|
||||
presentBatch.resetViewTransform();
|
||||
presentBatch.setFramebuffer(gpu::FramebufferPointer());
|
||||
presentBatch.setViewportTransform(ivec4(uvec2(0), getSurfacePixels()));
|
||||
presentBatch.setResourceTexture(0, _currentFrame->framebuffer->getRenderBuffer(0));
|
||||
presentBatch.setPipeline(_interleavedPresentPipeline);
|
||||
presentBatch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
_backend->render(presentBatch);
|
||||
render([&](gpu::Batch& batch) {
|
||||
batch.enableStereo(false);
|
||||
batch.resetViewTransform();
|
||||
batch.setFramebuffer(gpu::FramebufferPointer());
|
||||
batch.setViewportTransform(ivec4(uvec2(0), getSurfacePixels()));
|
||||
batch.setResourceTexture(0, _currentFrame->framebuffer->getRenderBuffer(0));
|
||||
batch.setPipeline(_interleavedPresentPipeline);
|
||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||
});
|
||||
swapBuffers();
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ public:
|
|||
virtual QString getPreferredAudioOutDevice() const { return QString(); }
|
||||
|
||||
// Rendering support
|
||||
virtual void setBackend(const gpu::BackendPointer& backend) final { _backend = backend; }
|
||||
virtual void setContext(const gpu::ContextPointer& context) final { _gpuContext = context; }
|
||||
virtual void submitFrame(const gpu::FramePointer& newFrame) = 0;
|
||||
|
||||
// Does the rendering surface have current focus?
|
||||
|
@ -200,7 +200,7 @@ signals:
|
|||
protected:
|
||||
void incrementPresentCount();
|
||||
|
||||
gpu::BackendPointer _backend;
|
||||
gpu::ContextPointer _gpuContext;
|
||||
|
||||
private:
|
||||
std::atomic<uint32_t> _presentedFrameIndex;
|
||||
|
|
Loading…
Reference in a new issue