mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01: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()) {
|
||||
gpu::doInBatch("splashFrame", _gpuContext, [&](gpu::Batch& batch) {
|
||||
batch.enableStereo(false);
|
||||
batch.setFramebuffer(finalFramebuffer);
|
||||
batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, { 0, 0, 0, 1 });
|
||||
batch.enableSkybox(true);
|
||||
batch.enableStereo(isStereo);
|
||||
batch.setViewportTransform({ 0, 0, finalFramebuffer->getSize() });
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
#include <gpu/Texture.h>
|
||||
#include <shaders/Shaders.h>
|
||||
#include <gpu/gl/GLShader.h>
|
||||
#include <gpu/gl/GLShared.h>
|
||||
#include <gpu/gl/GLBackend.h>
|
||||
#include <GeometryCache.h>
|
||||
|
@ -634,18 +633,26 @@ void OpenGLDisplayPlugin::internalPresent() {
|
|||
_presentRate.increment();
|
||||
}
|
||||
|
||||
std::atomic<bool> OpenGLDisplayPlugin::_allProgramsLoaded { false };
|
||||
unsigned int OpenGLDisplayPlugin::_currentLoadingProgramIndex { 0 };
|
||||
|
||||
bool OpenGLDisplayPlugin::areAllProgramsLoaded() const {
|
||||
return OpenGLDisplayPlugin::_allProgramsLoaded.load();
|
||||
}
|
||||
|
||||
void OpenGLDisplayPlugin::present() {
|
||||
auto frameId = (uint64_t)presentCount();
|
||||
PROFILE_RANGE_EX(render, __FUNCTION__, 0xffffff00, frameId)
|
||||
uint64_t startPresent = usecTimestampNow();
|
||||
|
||||
if (!_allProgramsLoaded) {
|
||||
if (!OpenGLDisplayPlugin::_allProgramsLoaded.load()) {
|
||||
const auto& programIDs = shader::allPrograms();
|
||||
if (_currentLoadingProgramIndex < programIDs.size()) {
|
||||
auto shader = gpu::Shader::createProgram(programIDs.at(_currentLoadingProgramIndex++));
|
||||
gpu::gl::GLShader::sync(*getGLBackend(), *shader);
|
||||
if (OpenGLDisplayPlugin::_currentLoadingProgramIndex < programIDs.size()) {
|
||||
gpu::doInBatch("createAndSyncProgram", _gpuContext, [&programIDs](gpu::Batch& batch) {
|
||||
batch.createAndSyncProgram(programIDs.at(OpenGLDisplayPlugin::_currentLoadingProgramIndex++));
|
||||
});
|
||||
} else {
|
||||
_allProgramsLoaded = true;
|
||||
OpenGLDisplayPlugin::_allProgramsLoaded.store(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -841,10 +848,6 @@ void OpenGLDisplayPlugin::render(std::function<void(gpu::Batch& batch)> f) {
|
|||
_gpuContext->executeBatch(batch);
|
||||
}
|
||||
|
||||
OpenGLDisplayPlugin::OpenGLDisplayPlugin() : DisplayPlugin() {
|
||||
_allProgramsLoaded = false;
|
||||
}
|
||||
|
||||
OpenGLDisplayPlugin::~OpenGLDisplayPlugin() {
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ protected:
|
|||
using Lock = std::unique_lock<Mutex>;
|
||||
using Condition = std::condition_variable;
|
||||
public:
|
||||
OpenGLDisplayPlugin();
|
||||
~OpenGLDisplayPlugin();
|
||||
// These must be final to ensure proper ordering of operations
|
||||
// between the main thread and the presentation thread
|
||||
|
@ -84,6 +83,8 @@ public:
|
|||
|
||||
void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync) override;
|
||||
|
||||
bool areAllProgramsLoaded() const override;
|
||||
|
||||
protected:
|
||||
friend class PresentThread;
|
||||
|
||||
|
@ -182,6 +183,7 @@ protected:
|
|||
mutable Mutex _presentMutex;
|
||||
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_popProfileRange),
|
||||
|
||||
(&::gpu::gl::GLBackend::do_createAndSyncProgram),
|
||||
};
|
||||
|
||||
#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 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 {
|
||||
Lock lock(_trashMutex);
|
||||
_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_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 getTextureID(const TexturePointer& texture) final;
|
||||
virtual GLuint getBufferID(const Buffer& buffer) = 0;
|
||||
|
|
|
@ -760,3 +760,9 @@ void Batch::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 createAndSyncProgram(unsigned int programID);
|
||||
|
||||
// Maybe useful but shoudln't be public. Please convince me otherwise
|
||||
// Well porting to gles i need it...
|
||||
void runLambda(std::function<void()> f);
|
||||
|
@ -368,6 +370,8 @@ public:
|
|||
COMMAND_pushProfileRange,
|
||||
COMMAND_popProfileRange,
|
||||
|
||||
COMMAND_createAndSyncProgram,
|
||||
|
||||
NUM_COMMANDS,
|
||||
};
|
||||
typedef std::vector<Command> Commands;
|
||||
|
|
|
@ -217,7 +217,7 @@ public:
|
|||
|
||||
static const QString& MENU_PATH();
|
||||
|
||||
bool areAllProgramsLoaded() { return _allProgramsLoaded; }
|
||||
virtual bool areAllProgramsLoaded() const { return true; }
|
||||
|
||||
signals:
|
||||
void recommendedFramebufferSizeChanged(const QSize& size);
|
||||
|
@ -235,8 +235,6 @@ protected:
|
|||
|
||||
float _renderResolutionScale { 1.0f };
|
||||
|
||||
std::atomic<bool> _allProgramsLoaded { true };
|
||||
|
||||
private:
|
||||
QMutex _presentMutex;
|
||||
QWaitCondition _presentCondition;
|
||||
|
|
Loading…
Reference in a new issue