mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-13 14:19:38 +02:00
move to batch, try to use static
This commit is contained in:
parent
cbe5814c64
commit
0fccb4c73c
8 changed files with 37 additions and 17 deletions
|
@ -117,9 +117,7 @@ void Application::paintGL() {
|
||||||
|
|
||||||
if (!displayPlugin->areAllProgramsLoaded()) {
|
if (!displayPlugin->areAllProgramsLoaded()) {
|
||||||
gpu::doInBatch("splashFrame", _gpuContext, [&](gpu::Batch& batch) {
|
gpu::doInBatch("splashFrame", _gpuContext, [&](gpu::Batch& batch) {
|
||||||
batch.enableStereo(false);
|
|
||||||
batch.setFramebuffer(finalFramebuffer);
|
batch.setFramebuffer(finalFramebuffer);
|
||||||
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, { 0, 0, 0, 1 });
|
|
||||||
batch.enableSkybox(true);
|
batch.enableSkybox(true);
|
||||||
batch.enableStereo(isStereo);
|
batch.enableStereo(isStereo);
|
||||||
batch.setViewportTransform({ 0, 0, finalFramebuffer->getSize() });
|
batch.setViewportTransform({ 0, 0, finalFramebuffer->getSize() });
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
#include <gpu/Texture.h>
|
#include <gpu/Texture.h>
|
||||||
#include <shaders/Shaders.h>
|
#include <shaders/Shaders.h>
|
||||||
#include <gpu/gl/GLShader.h>
|
|
||||||
#include <gpu/gl/GLShared.h>
|
#include <gpu/gl/GLShared.h>
|
||||||
#include <gpu/gl/GLBackend.h>
|
#include <gpu/gl/GLBackend.h>
|
||||||
#include <GeometryCache.h>
|
#include <GeometryCache.h>
|
||||||
|
@ -634,18 +633,26 @@ void OpenGLDisplayPlugin::internalPresent() {
|
||||||
_presentRate.increment();
|
_presentRate.increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::atomic<bool> OpenGLDisplayPlugin::_allProgramsLoaded { false };
|
||||||
|
unsigned int OpenGLDisplayPlugin::_currentLoadingProgramIndex { 0 };
|
||||||
|
|
||||||
|
bool OpenGLDisplayPlugin::areAllProgramsLoaded() const {
|
||||||
|
return OpenGLDisplayPlugin::_allProgramsLoaded.load();
|
||||||
|
}
|
||||||
|
|
||||||
void OpenGLDisplayPlugin::present() {
|
void OpenGLDisplayPlugin::present() {
|
||||||
auto frameId = (uint64_t)presentCount();
|
auto frameId = (uint64_t)presentCount();
|
||||||
PROFILE_RANGE_EX(render, __FUNCTION__, 0xffffff00, frameId)
|
PROFILE_RANGE_EX(render, __FUNCTION__, 0xffffff00, frameId)
|
||||||
uint64_t startPresent = usecTimestampNow();
|
uint64_t startPresent = usecTimestampNow();
|
||||||
|
|
||||||
if (!_allProgramsLoaded) {
|
if (!OpenGLDisplayPlugin::_allProgramsLoaded.load()) {
|
||||||
const auto& programIDs = shader::allPrograms();
|
const auto& programIDs = shader::allPrograms();
|
||||||
if (_currentLoadingProgramIndex < programIDs.size()) {
|
if (OpenGLDisplayPlugin::_currentLoadingProgramIndex < programIDs.size()) {
|
||||||
auto shader = gpu::Shader::createProgram(programIDs.at(_currentLoadingProgramIndex++));
|
gpu::doInBatch("createAndSyncProgram", _gpuContext, [&programIDs](gpu::Batch& batch) {
|
||||||
gpu::gl::GLShader::sync(*getGLBackend(), *shader);
|
batch.createAndSyncProgram(programIDs.at(OpenGLDisplayPlugin::_currentLoadingProgramIndex++));
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
_allProgramsLoaded = true;
|
OpenGLDisplayPlugin::_allProgramsLoaded.store(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -841,10 +848,6 @@ void OpenGLDisplayPlugin::render(std::function<void(gpu::Batch& batch)> f) {
|
||||||
_gpuContext->executeBatch(batch);
|
_gpuContext->executeBatch(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenGLDisplayPlugin::OpenGLDisplayPlugin() : DisplayPlugin() {
|
|
||||||
_allProgramsLoaded = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
OpenGLDisplayPlugin::~OpenGLDisplayPlugin() {
|
OpenGLDisplayPlugin::~OpenGLDisplayPlugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ protected:
|
||||||
using Lock = std::unique_lock<Mutex>;
|
using Lock = std::unique_lock<Mutex>;
|
||||||
using Condition = std::condition_variable;
|
using Condition = std::condition_variable;
|
||||||
public:
|
public:
|
||||||
OpenGLDisplayPlugin();
|
|
||||||
~OpenGLDisplayPlugin();
|
~OpenGLDisplayPlugin();
|
||||||
// These must be final to ensure proper ordering of operations
|
// These must be final to ensure proper ordering of operations
|
||||||
// between the main thread and the presentation thread
|
// between the main thread and the presentation thread
|
||||||
|
@ -84,6 +83,8 @@ public:
|
||||||
|
|
||||||
void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync) override;
|
void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync) override;
|
||||||
|
|
||||||
|
bool areAllProgramsLoaded() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class PresentThread;
|
friend class PresentThread;
|
||||||
|
|
||||||
|
@ -182,6 +183,7 @@ protected:
|
||||||
mutable Mutex _presentMutex;
|
mutable Mutex _presentMutex;
|
||||||
float _hudAlpha{ 1.0f };
|
float _hudAlpha{ 1.0f };
|
||||||
|
|
||||||
size_t _currentLoadingProgramIndex { 0 };
|
static std::atomic<bool> _allProgramsLoaded;
|
||||||
|
static unsigned int _currentLoadingProgramIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,8 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
|
||||||
|
|
||||||
(&::gpu::gl::GLBackend::do_pushProfileRange),
|
(&::gpu::gl::GLBackend::do_pushProfileRange),
|
||||||
(&::gpu::gl::GLBackend::do_popProfileRange),
|
(&::gpu::gl::GLBackend::do_popProfileRange),
|
||||||
|
|
||||||
|
(&::gpu::gl::GLBackend::do_createAndSyncProgram),
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GL_GET_INTEGER(NAME) glGetIntegerv(GL_##NAME, &const_cast<GLint&>(NAME));
|
#define GL_GET_INTEGER(NAME) glGetIntegerv(GL_##NAME, &const_cast<GLint&>(NAME));
|
||||||
|
@ -706,6 +708,11 @@ void GLBackend::do_glColor4f(const Batch& batch, size_t paramOffset) {
|
||||||
(void)CHECK_GL_ERROR();
|
(void)CHECK_GL_ERROR();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLBackend::do_createAndSyncProgram(const Batch& batch, size_t paramOffset) {
|
||||||
|
auto shader = gpu::Shader::createProgram(batch._params[paramOffset + 0]._uint);
|
||||||
|
gpu::gl::GLShader::sync(*this, *shader);
|
||||||
|
}
|
||||||
|
|
||||||
void GLBackend::releaseBuffer(GLuint id, Size size) const {
|
void GLBackend::releaseBuffer(GLuint id, Size size) const {
|
||||||
Lock lock(_trashMutex);
|
Lock lock(_trashMutex);
|
||||||
_currentFrameTrash.buffersTrash.push_back({ id, size });
|
_currentFrameTrash.buffersTrash.push_back({ id, size });
|
||||||
|
|
|
@ -380,6 +380,8 @@ public:
|
||||||
virtual void do_setStateBlendFactor(const Batch& batch, size_t paramOffset) final;
|
virtual void do_setStateBlendFactor(const Batch& batch, size_t paramOffset) final;
|
||||||
virtual void do_setStateScissorRect(const Batch& batch, size_t paramOffset) final;
|
virtual void do_setStateScissorRect(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
||||||
|
virtual void do_createAndSyncProgram(const Batch& batch, size_t paramOffset) final;
|
||||||
|
|
||||||
virtual GLuint getFramebufferID(const FramebufferPointer& framebuffer) = 0;
|
virtual GLuint getFramebufferID(const FramebufferPointer& framebuffer) = 0;
|
||||||
virtual GLuint getTextureID(const TexturePointer& texture) final;
|
virtual GLuint getTextureID(const TexturePointer& texture) final;
|
||||||
virtual GLuint getBufferID(const Buffer& buffer) = 0;
|
virtual GLuint getBufferID(const Buffer& buffer) = 0;
|
||||||
|
|
|
@ -760,3 +760,9 @@ void Batch::flush() {
|
||||||
buffer->flush();
|
buffer->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Batch::createAndSyncProgram(unsigned int programID) {
|
||||||
|
ADD_COMMAND(createAndSyncProgram);
|
||||||
|
|
||||||
|
_params.emplace_back(programID);
|
||||||
|
}
|
|
@ -289,6 +289,8 @@ public:
|
||||||
|
|
||||||
void _glColor4f(float red, float green, float blue, float alpha);
|
void _glColor4f(float red, float green, float blue, float alpha);
|
||||||
|
|
||||||
|
void createAndSyncProgram(unsigned int programID);
|
||||||
|
|
||||||
// Maybe useful but shoudln't be public. Please convince me otherwise
|
// Maybe useful but shoudln't be public. Please convince me otherwise
|
||||||
// Well porting to gles i need it...
|
// Well porting to gles i need it...
|
||||||
void runLambda(std::function<void()> f);
|
void runLambda(std::function<void()> f);
|
||||||
|
@ -368,6 +370,8 @@ public:
|
||||||
COMMAND_pushProfileRange,
|
COMMAND_pushProfileRange,
|
||||||
COMMAND_popProfileRange,
|
COMMAND_popProfileRange,
|
||||||
|
|
||||||
|
COMMAND_createAndSyncProgram,
|
||||||
|
|
||||||
NUM_COMMANDS,
|
NUM_COMMANDS,
|
||||||
};
|
};
|
||||||
typedef std::vector<Command> Commands;
|
typedef std::vector<Command> Commands;
|
||||||
|
|
|
@ -217,7 +217,7 @@ public:
|
||||||
|
|
||||||
static const QString& MENU_PATH();
|
static const QString& MENU_PATH();
|
||||||
|
|
||||||
bool areAllProgramsLoaded() { return _allProgramsLoaded; }
|
virtual bool areAllProgramsLoaded() const { return true; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void recommendedFramebufferSizeChanged(const QSize& size);
|
void recommendedFramebufferSizeChanged(const QSize& size);
|
||||||
|
@ -235,8 +235,6 @@ protected:
|
||||||
|
|
||||||
float _renderResolutionScale { 1.0f };
|
float _renderResolutionScale { 1.0f };
|
||||||
|
|
||||||
std::atomic<bool> _allProgramsLoaded { true };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMutex _presentMutex;
|
QMutex _presentMutex;
|
||||||
QWaitCondition _presentCondition;
|
QWaitCondition _presentCondition;
|
||||||
|
|
Loading…
Reference in a new issue