filament icon indicating copy to clipboard operation
filament copied to clipboard

GLError when using RenderTarget to render at an external GL texture

Open simonsland opened this issue 2 years ago • 6 comments

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.

simonsland avatar Oct 31 '22 12:10 simonsland

That error is not render target related. @bejado, any idea?

romainguy avatar Oct 31 '22 17:10 romainguy

@starccode What version of Filament are you using? I think we removed OpenGL::updateBuffer in favor of OpenGL::updateBufferObject some time ago.

It'd also be helpful if you copied that CHECK_GL_ERROR(utils::slog.e) statement after each of the nearby gl* function calls to see exactly which one is causing the error (glBufferSubData, glBufferData, etc).

bejado avatar Oct 31 '22 19:10 bejado

I'm using an old version 1.21.2. And It seems raise error since glBindBuffer() glerror

simonsland avatar Nov 01 '22 02:11 simonsland

And I run the code at version 1.25.0 of filament gltf-viewer sample. The GLError disappear, but receive a warning: warning And besides, the memory increase constantly. memory I analyze it through Profile, and it turns: profile allocation allocation_1

simonsland avatar Nov 01 '22 06:11 simonsland

I've just run the sample project "gltf-Viewer" without any extra code, and I found that the memory also increase at openGL backend as shown above. But it works right at metal backend.

To Reproduce run the sample project "gltf-Viewer"

filament Version 1.28.3

simonsland avatar Nov 02 '22 03:11 simonsland

Thanks for helping investigate. It's possible we have a memory leak with the OpenGL backend on iOS. Are you able to switch to the Metal backend? We're in the process of phasing out the OpenGL/iOS backend so this won't be high priority for us.

bejado avatar Nov 02 '22 15:11 bejado