mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 06:04:03 +00:00
gl_engine: use raw pointer to pass and hold GlRenderTask
This commit is contained in:
parent
db1f171d2a
commit
2038818e16
5 changed files with 60 additions and 33 deletions
|
@ -63,11 +63,25 @@ void GlRenderTarget::init(GLint resolveId)
|
||||||
|
|
||||||
GlRenderPass::GlRenderPass(GlRenderTarget* fbo): mFbo(fbo), mTasks() {}
|
GlRenderPass::GlRenderPass(GlRenderTarget* fbo): mFbo(fbo), mTasks() {}
|
||||||
|
|
||||||
GlRenderPass::GlRenderPass(GlRenderPass&& other): mFbo(other.mFbo), mTasks(std::move(other.mTasks)) {}
|
GlRenderPass::GlRenderPass(GlRenderPass&& other): mFbo(other.mFbo), mTasks()
|
||||||
|
|
||||||
GlRenderPass::~GlRenderPass() {}
|
|
||||||
|
|
||||||
void GlRenderPass::addRenderTask(unique_ptr<GlRenderTask> task)
|
|
||||||
{
|
{
|
||||||
mTasks.emplace_back(std::move(task));
|
mTasks.push(other.mTasks);
|
||||||
|
|
||||||
|
other.mTasks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
GlRenderPass::~GlRenderPass()
|
||||||
|
{
|
||||||
|
if (mTasks.empty()) return;
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < mTasks.count; i++) {
|
||||||
|
delete mTasks[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
mTasks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlRenderPass::addRenderTask(GlRenderTask* task)
|
||||||
|
{
|
||||||
|
mTasks.push(task);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,17 +57,17 @@ public:
|
||||||
|
|
||||||
~GlRenderPass();
|
~GlRenderPass();
|
||||||
|
|
||||||
void addRenderTask(unique_ptr<GlRenderTask> task);
|
void addRenderTask(GlRenderTask* task);
|
||||||
|
|
||||||
GLuint getFboId() { return mFbo->getFboId(); }
|
GLuint getFboId() { return mFbo->getFboId(); }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
unique_ptr<T> endRenderPass(GlProgram* program, GLuint targetFbo) {
|
T* endRenderPass(GlProgram* program, GLuint targetFbo) {
|
||||||
return make_unique<T>(program, targetFbo, mFbo->getFboId(), std::move(mTasks));
|
return new T(program, targetFbo, mFbo->getFboId(), std::move(mTasks));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
GlRenderTarget* mFbo;
|
GlRenderTarget* mFbo;
|
||||||
vector<unique_ptr<GlRenderTask>> mTasks = {};
|
Array<GlRenderTask*> mTasks = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -90,9 +90,20 @@ void GlRenderTask::setViewport(const RenderRegion &viewport)
|
||||||
mViewport = viewport;
|
mViewport = viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlComposeTask::GlComposeTask(GlProgram* program, GLuint target, GLuint selfFbo, vector<unique_ptr<GlRenderTask>> tasks)
|
GlComposeTask::GlComposeTask(GlProgram* program, GLuint target, GLuint selfFbo, Array<GlRenderTask*>&& tasks)
|
||||||
:GlRenderTask(program) ,mTargetFbo(target), mSelfFbo(selfFbo), mTasks(std::move(tasks))
|
:GlRenderTask(program) ,mTargetFbo(target), mSelfFbo(selfFbo), mTasks()
|
||||||
{
|
{
|
||||||
|
mTasks.push(tasks);
|
||||||
|
tasks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
GlComposeTask::~GlComposeTask()
|
||||||
|
{
|
||||||
|
for(uint32_t i = 0; i < mTasks.count; i++) {
|
||||||
|
delete mTasks[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
mTasks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlComposeTask::run()
|
void GlComposeTask::run()
|
||||||
|
@ -106,12 +117,12 @@ void GlComposeTask::run()
|
||||||
GL_CHECK(glDrawBuffers(1, &color_buffer));
|
GL_CHECK(glDrawBuffers(1, &color_buffer));
|
||||||
GL_CHECK(glClearBufferfv(GL_COLOR, 0, transparent));
|
GL_CHECK(glClearBufferfv(GL_COLOR, 0, transparent));
|
||||||
|
|
||||||
for(auto& task : mTasks) {
|
for(uint32_t i = 0; i < mTasks.count; i++) {
|
||||||
task->run();
|
mTasks[i]->run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlBlitTask::GlBlitTask(GlProgram* program, GLuint target, GLuint compose, vector<unique_ptr<GlRenderTask>> tasks)
|
GlBlitTask::GlBlitTask(GlProgram* program, GLuint target, GLuint compose, Array<GlRenderTask*>&& tasks)
|
||||||
: GlComposeTask(program, target, compose, std::move(tasks))
|
: GlComposeTask(program, target, compose, std::move(tasks))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -132,7 +143,7 @@ void GlBlitTask::run()
|
||||||
GL_CHECK(glBlitFramebuffer(0, 0, mWidth, mHeight, 0, 0, mWidth, mHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST));
|
GL_CHECK(glBlitFramebuffer(0, 0, mWidth, mHeight, 0, 0, mWidth, mHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST));
|
||||||
}
|
}
|
||||||
|
|
||||||
GlDrawBlitTask::GlDrawBlitTask(GlProgram* program, GLuint target, GLuint compose, vector<unique_ptr<GlRenderTask>> tasks)
|
GlDrawBlitTask::GlDrawBlitTask(GlProgram* program, GLuint target, GLuint compose, Array<GlRenderTask*>&& tasks)
|
||||||
: GlComposeTask(program, target, compose, std::move(tasks))
|
: GlComposeTask(program, target, compose, std::move(tasks))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,8 +98,8 @@ private:
|
||||||
class GlComposeTask : public GlRenderTask
|
class GlComposeTask : public GlRenderTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GlComposeTask(GlProgram* program, GLuint target, GLuint selfFbo, vector<unique_ptr<GlRenderTask>> tasks);
|
GlComposeTask(GlProgram* program, GLuint target, GLuint selfFbo, Array<GlRenderTask*>&& tasks);
|
||||||
~GlComposeTask() override = default;
|
~GlComposeTask() override;
|
||||||
|
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
|
@ -111,13 +111,13 @@ protected:
|
||||||
private:
|
private:
|
||||||
GLuint mTargetFbo;
|
GLuint mTargetFbo;
|
||||||
GLuint mSelfFbo;
|
GLuint mSelfFbo;
|
||||||
vector<unique_ptr<GlRenderTask>> mTasks;
|
Array<GlRenderTask*> mTasks;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GlBlitTask : public GlComposeTask
|
class GlBlitTask : public GlComposeTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GlBlitTask(GlProgram*, GLuint target, GLuint compose, vector<unique_ptr<GlRenderTask>> tasks);
|
GlBlitTask(GlProgram*, GLuint target, GLuint compose, Array<GlRenderTask*>&& tasks);
|
||||||
~GlBlitTask() override = default;
|
~GlBlitTask() override = default;
|
||||||
|
|
||||||
void setSize(uint32_t width, uint32_t height);
|
void setSize(uint32_t width, uint32_t height);
|
||||||
|
@ -132,7 +132,7 @@ private:
|
||||||
class GlDrawBlitTask : public GlComposeTask
|
class GlDrawBlitTask : public GlComposeTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GlDrawBlitTask(GlProgram*, GLuint target, GLuint compose, vector<unique_ptr<GlRenderTask>> tasks);
|
GlDrawBlitTask(GlProgram*, GLuint target, GLuint compose, Array<GlRenderTask*>&& tasks);
|
||||||
~GlDrawBlitTask() override = default;
|
~GlDrawBlitTask() override = default;
|
||||||
|
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
|
@ -107,6 +107,8 @@ bool GlRenderer::sync()
|
||||||
mRenderPassStack.clear();
|
mRenderPassStack.clear();
|
||||||
mPoolIndex = 0;
|
mPoolIndex = 0;
|
||||||
|
|
||||||
|
delete task;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +204,9 @@ bool GlRenderer::renderImage(void* data)
|
||||||
|
|
||||||
if ((sdata->updateFlag & RenderUpdateFlag::Image) == 0) return false;
|
if ((sdata->updateFlag & RenderUpdateFlag::Image) == 0) return false;
|
||||||
|
|
||||||
auto task = make_unique<GlRenderTask>(mPrograms[RT_Image].get());
|
auto task = new GlRenderTask(mPrograms[RT_Image].get());
|
||||||
|
|
||||||
if (!sdata->geometry->draw(task.get(), mGpuBuffer.get(), RenderUpdateFlag::Image)) return false;
|
if (!sdata->geometry->draw(task, mGpuBuffer.get(), RenderUpdateFlag::Image)) return false;
|
||||||
|
|
||||||
// matrix buffer
|
// matrix buffer
|
||||||
{
|
{
|
||||||
|
@ -238,7 +240,7 @@ bool GlRenderer::renderImage(void* data)
|
||||||
task->addBindResource(GlBindingResource{0, sdata->texId, loc});
|
task->addBindResource(GlBindingResource{0, sdata->texId, loc});
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPass()->addRenderTask(std::move(task));
|
currentPass()->addRenderTask(task);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -471,9 +473,9 @@ void GlRenderer::initShaders()
|
||||||
|
|
||||||
void GlRenderer::drawPrimitive(GlShape& sdata, uint8_t r, uint8_t g, uint8_t b, uint8_t a, RenderUpdateFlag flag)
|
void GlRenderer::drawPrimitive(GlShape& sdata, uint8_t r, uint8_t g, uint8_t b, uint8_t a, RenderUpdateFlag flag)
|
||||||
{
|
{
|
||||||
auto task = make_unique<GlRenderTask>(mPrograms[RT_Color].get());
|
auto task = new GlRenderTask(mPrograms[RT_Color].get());
|
||||||
|
|
||||||
if (!sdata.geometry->draw(task.get(), mGpuBuffer.get(), flag)) return;
|
if (!sdata.geometry->draw(task, mGpuBuffer.get(), flag)) return;
|
||||||
|
|
||||||
a = MULTIPLY(a, sdata.opacity);
|
a = MULTIPLY(a, sdata.opacity);
|
||||||
|
|
||||||
|
@ -505,7 +507,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, uint8_t r, uint8_t g, uint8_t b,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPass()->addRenderTask(std::move(task));
|
currentPass()->addRenderTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -515,17 +517,17 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFla
|
||||||
auto stopCnt = fill->colorStops(&stops);
|
auto stopCnt = fill->colorStops(&stops);
|
||||||
if (stopCnt < 2) return;
|
if (stopCnt < 2) return;
|
||||||
|
|
||||||
unique_ptr<GlRenderTask> task;
|
GlRenderTask* task = nullptr;
|
||||||
|
|
||||||
if (fill->identifier() == TVG_CLASS_ID_LINEAR) {
|
if (fill->identifier() == TVG_CLASS_ID_LINEAR) {
|
||||||
task = make_unique<GlRenderTask>(mPrograms[RT_LinGradient].get());
|
task = new GlRenderTask(mPrograms[RT_LinGradient].get());
|
||||||
} else if (fill->identifier() == TVG_CLASS_ID_RADIAL) {
|
} else if (fill->identifier() == TVG_CLASS_ID_RADIAL) {
|
||||||
task = make_unique<GlRenderTask>(mPrograms[RT_RadGradient].get());
|
task = new GlRenderTask(mPrograms[RT_RadGradient].get());
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sdata.geometry->draw(task.get(), mGpuBuffer.get(), flag)) return;
|
if (!sdata.geometry->draw(task, mGpuBuffer.get(), flag)) return;
|
||||||
|
|
||||||
// matrix buffer
|
// matrix buffer
|
||||||
{
|
{
|
||||||
|
@ -599,7 +601,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFla
|
||||||
task->addBindResource(gradientBinding);
|
task->addBindResource(gradientBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPass()->addRenderTask(std::move(task));
|
currentPass()->addRenderTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlRenderPass* GlRenderer::currentPass()
|
GlRenderPass* GlRenderer::currentPass()
|
||||||
|
@ -683,7 +685,7 @@ void GlRenderer::endRenderPass(Compositor* cmp)
|
||||||
auto task = renderPass.endRenderPass<GlDrawBlitTask>(
|
auto task = renderPass.endRenderPass<GlDrawBlitTask>(
|
||||||
mPrograms[RT_Image].get(), currentPass()->getFboId());
|
mPrograms[RT_Image].get(), currentPass()->getFboId());
|
||||||
|
|
||||||
prepareCmpTask(task.get());
|
prepareCmpTask(task);
|
||||||
|
|
||||||
// matrix buffer
|
// matrix buffer
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue