google / google/filament

RenderTarget with imported texture results in flickering

Open
#7,115 5 comments 0 reactions 1 assignee Claimed by @pixelflinger View on GitHub
opengl
Dominant language
C++
Stars
20.5k
Forks
2.3k
Avg merge
2d 16h
Merged PRs (30d)
74

Description

**Describe the bug**

Amazing to see how much work has been done the last couple of years, really awesome! After working on some other projects I'm again looking into using Filament for rendering by using a shared context. In the past I've used my own fork with some features that worked for me. Now, I want to use the `import()` feature of a `Texture` and use Filament to render a 3D scene into a texture.

In my GLFW based app I create a window and OpenGL context. I create a Filament instance and share my OpenGL context. Next I create a texture using my GL context and use the [import()][funcimport] call. I setup a `View` and render it into a `RenderTarget` similarly as shown in the [rendertarget][rtt] example.

However I'm seeing flickering when rendering. I'm pretty sure that this is caused because we're having two contexts and the Filament threads/context maybe clears the shared image while I'm rendering it. Therefore I'm calling [Engine::flushAndWait()][fw] which fixes the issue.

I've got some concerns regarding peformance when using `flushAndWait()` and the `glfwSwapBuffers()` so I measured the time my render loop takes when it calls `flushAndWait()` and I noticed no performance impact. The total time of my render loop is about 16ms but as I'm just testing and not yet rendering anything else besides the *FlightHelmet* scene I'm not sure if I'll run into a performance issue in the future that I can't solve due to the approach I'm using.

My question is, when I'm using an imported texture as render target of a view what is the correct way to prevent flickering?

[funcimport]: https://github.com/google/filament/blob/main/filament/include/filament/Texture.h#L241
[rtt]: https://github.com/google/filament/blob/main/samples/rendertarget.cpp
[fw]: https://github.com/google/filament/blob/702ceda82ab21a8644218a096929d9be25a15c31/filament/include/filament/Engine.h#L716

**To Reproduce**

Currently I've no code example that I can share to reproduce this. I'm not sure this is a bug or if I'm using the API incorrectly. If required I'll create a standalone app that demonstrates the issue.

**Expected behavior**

When I render the texture that I created with the OpenGL context I would expect it not to flicker when I render it.

**Screenshots**

https://github.com/google/filament/assets/358809/23c3d27b-d63a-4c92-a580-c1e97565bb5f

**Desktop:**

- OS: `Linux 6.4.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 24 Jul 2023 20:19:38 +0000 x86_64 GNU/Linux`
- GPU: `NVIDIA GTX 2080i`
- Backend: `OpenGL`

**Additional context**

Some related issues:

- https://github.com/google/filament/issues/2261
- https://github.com/google/filament/issues/1921

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.