google / google/filament

GLError when using RenderTarget to render at an external GL texture

Open
#6,248 6 comments 0 reactions 1 assignee Claimed by @bejado View on GitHub
Dominant language
C++
Stars
20.5k
Forks
2.3k
Avg merge
2d 14h
Merged PRs (30d)
83

Description

### Discussed in https://github.com/google/filament/discussions/6223

Originally posted by **starccode** October 26, 2022
Hi,
I'm trying to render the engine's output into an external openGL texture that created outside of filament. Besides all of the work is at iOS platform and openGL backend, here is my solution:

First, create engine with shareGLContext, and a headless swapChain instead of CAEGLayer surface:
`_engine = Engine::create(Engine::Backend::OPENGL, nullptr, sharedGLContext)`
`_swapChain = _engine->createSwapChain(width, height);`

Then, create renderTarget with a import texture and config the view:
```
_color = Texture::Builder()
.width(width).height(height).levels(1)
.import(textureId)
.usage(Texture::Usage::COLOR_ATTACHMENT | Texture::Usage::SAMPLEABLE |
Texture::Usage::STENCIL_ATTACHMENT)
.format(Texture::InternalFormat::RGBA8).build(*_engine);

_renderTarget = RenderTarget::Builder()
.texture(RenderTarget::AttachmentPoint::COLOR, _color)
.build(*_engine);

_view = _engine->createView();
_view->setScene(_scene);
_view->setCamera(_camera);
_view->setRenderTarget(_renderTarget);
_view->
```

Finally, render the result to the view:
```
if (_renderer->beginFrame(_swapChain)) {
_renderer->render(_view);
_renderer->endFrame();
}
```

But the problem I met is that when I run the code with debug mode, I receive "GLError 1282" message as following:
log

and when I run it with release mode, it can render the result to the import texture as following:
render result
but the fps is lower than render to a CAEGLayer.

**If there anyone can explain the "GLError 1282" error, and how to solve this problem?** Besides, the problem can reproduce at gltf-view sample workspace.

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.