These are chat archives for mosra/magnum

1st
Jul 2021
hsdk123
@hsdk123
Jul 01 2021 02:10 UTC
Hi all, what could be the reason that the status of Magnum::GL::defaultFramebuffer turns into undefined? (when previously complete)
hsdk123
@hsdk123
Jul 01 2021 02:32 UTC

It seems the moment I

frame_buffer->attachRenderbuffer(
                    Magnum::GL::Framebuffer::BufferAttachment::Depth, *depth_buffer);

the defaultframebuffer turns undefined - would anyone have any hunches?

hsdk123
@hsdk123
Jul 01 2021 02:39 UTC
Sorry, it seems it's this line
frame_buffer->attachTexture(
                    Magnum::GL::Framebuffer::ColorAttachment{ 0 }, *rendertex, 0);
rendertex:
const auto rendertex = std::make_shared<Magnum::GL::Texture2D>();
            rendertex->setStorage(1, Magnum::GL::TextureFormat::RGBA8, { render_w, render_h });
            rendertex->setWrapping(Magnum::SamplerWrapping::ClampToEdge);
hsdk123
@hsdk123
Jul 01 2021 02:55 UTC

It actually seems like the moment I do this

const auto frame_buffer = std::make_shared<Magnum::GL::Framebuffer>(Magnum::Range2Di{ {}, { render_w, render_h } });

we get the undefined.

on iOS
Vladimír Vondruš
@mosra
Jul 01 2021 10:25 UTC
@hsdk123 what do you mean by "undefined"?
Vladimír Vondruš
@mosra
Jul 01 2021 11:15 UTC
amazing
cmake's try_compile doesn't work when i want to link to libraries defined in the project
so when assimp is a cmake subproject, the try_compile check that's there to check for stupidity levels of that library will break the build
Vladimír Vondruš
@mosra
Jul 01 2021 11:42 UTC
actually this kinda makes sense, after all
try_compile() is ran before any of the libraries i could link to are built, so it can't link to them anyway
is this a stockholm syndrome?
ytain
@ytain:matrix.org
[m] Jul 01 2021 11:46 UTC
it's only useful if you include a source code of yours that uses a header from the library you want to test against
to make sure that the library you're linking against has the required stuff that is exposed thru the headers
kinda similar to the autotools/configure from the days of makefile
Vladimír Vondruš
@mosra
Jul 01 2021 11:50 UTC
yeah yeah that's what i use it for
but wasn't aware of this limitation
ytain
@ytain:matrix.org
[m] Jul 01 2021 11:53 UTC
the cmake docs says it can be used for compiling the whole project but the text there in the docs is unclear
Vladimír Vondruš
@mosra
Jul 01 2021 11:54 UTC
yeah no, all i need it for is checking assimp's version
ytain
@ytain:matrix.org
[m] Jul 01 2021 11:56 UTC
aha ok
nice trick
hsdk123
@hsdk123
Jul 01 2021 12:21 UTC

@mosra

undefined

Magnum::GL::defaultFramebuffer.checkStatus for both read/draw return undefined

when it was 'complete' right before the new frame buffer creation
Vladimír Vondruš
@mosra
Jul 01 2021 12:23 UTC
:eyes:
huh
i suppose this is because iOS doesn't actually have a default framebuffer?
so at the start, what magnum thinks is a default framebuffer, is some other FB, and checking for its status will return "complete"
then when you create another FB it'll switch to the new one
and when you ask on the default framebuffer again, it'll try to bind framebuffer 0, which doesn't exist, so it'll be undefined
soo i guess the solution is to not even use the GL::defaultFramebuffer but instead query the real framebuffer ID , GL::Framebuffer::wrap() it and use that instead
hsdk123
@hsdk123
Jul 01 2021 12:27 UTC

query the real framebuffer ID

How would I do this?

Vladimír Vondruš
@mosra
Jul 01 2021 12:27 UTC
if you apply this patch, you should consistently get "undefined" both before and after ... can you try it?
diff --git a/src/Magnum/GL/Implementation/FramebufferState.cpp b/src/Magnum/GL/Implementation/FramebufferState.cpp
index 38f48883c..43dcca79c 100644
--- a/src/Magnum/GL/Implementation/FramebufferState.cpp
+++ b/src/Magnum/GL/Implementation/FramebufferState.cpp
@@ -39,7 +39,7 @@ using namespace Containers::Literals;

 constexpr const Range2Di FramebufferState::DisengagedViewport;

-FramebufferState::FramebufferState(Context& context, Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions): readBinding{0}, drawBinding{0}, renderbufferBinding{0}, maxDrawBuffers{0}, maxColorAttachments{0}, maxRenderbufferSize{0},
+FramebufferState::FramebufferState(Context& context, Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions): readBinding{State::DisengagedBinding}, drawBinding{State::DisengagedBinding}, renderbufferBinding{0}, maxDrawBuffers{0}, maxColorAttachments{0}, maxRenderbufferSize{0},
     #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
     maxSamples{0},
     #endif

How would I do this?

this seems to be the way: https://stackoverflow.com/a/9755439 (no, magnum doesn't have such getters on its own)

hsdk123
@hsdk123
Jul 01 2021 12:32 UTC

so at the start, what magnum thinks is a default framebuffer, is some other FB

Just to confirm, so what magnum thinks is a default framebuffer, is still a valid framebuffer, just not the default one?

hsdk123
@hsdk123
Jul 01 2021 13:08 UTC

GL_FRAMEBUFFER_BINDING_OES

What header do I need to include to get this?

Vladimír Vondruš
@mosra
Jul 01 2021 14:53 UTC
ah, oh ... GL_FRAMEBUFFER_BINDING, then? GL_FRAMEBUFFER_DRAW_BINDING? something along those lines?

what magnum thinks is a default framebuffer, is still a valid framebuffer, just not the default one?

exactly, and the state tracker thinks it's the default one because that's what it usually is on other platforms

hsdk123
@hsdk123
Jul 01 2021 15:33 UTC

@mosra

GL_FRAMEBUFFER_BINDING

Seems we might be moving forward. I now realise that I get
GL::Renderer::Error::InvalidOperation errors each time I run SDL2Application::swapBuffers() on ios - any hunches?

Vladimír Vondruš
@mosra
Jul 01 2021 15:34 UTC
so if you ask for error state right before swapBuffers(), it's not there, but after that it is?
hsdk123
@hsdk123
Jul 01 2021 15:35 UTC
Correct
Vladimír Vondruš
@mosra
Jul 01 2021 15:36 UTC
:eyes:
hahah i have no idea
i would need to look into what SDL does there
but ... this used to work, no? few years ago definitely
hsdk123
@hsdk123
Jul 01 2021 15:38 UTC
I think back when it used to work, I didn't create new framebuffer objects
Vladimír Vondruš
@mosra
Jul 01 2021 15:39 UTC
oh so if you don't create that new framebuffer, it doesn't emit an error?
hsdk123
@hsdk123
Jul 01 2021 15:39 UTC
Yup, if I just use the default frame buffer the whole way, it's fine
does anything from here ring a bell? are you using multisampling?
how do you query and wrap the existing framebuffer?
hsdk123
@hsdk123
Jul 01 2021 15:44 UTC
GLint defaultFBO_index;
    /*glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &defaultFBO);*/
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO_index);
    Magnum::Debug{} << "default framebuffer index: " << defaultFBO_index;

    const auto viewport = Magnum::GL::defaultFramebuffer.viewport();

    _default_frame_buffer = std::make_unique< Magnum::GL::Framebuffer>(
        Magnum::GL::Framebuffer::wrap(defaultFBO_index, viewport)
    );
not sure what multisampling is
Vladimír Vondruš
@mosra
Jul 01 2021 15:49 UTC
antialiasing
setSampleCount() in Sdl2Application configuration
hsdk123
@hsdk123
Jul 01 2021 15:50 UTC
nope, didn't know that existed
Vladimír Vondruš
@mosra
Jul 01 2021 15:50 UTC
okay
do you have a possibility of running this through the xcode opengl debugger/tracer/profiler? if it still exists there
that should (hopefully) show what GL call this fails on
hsdk123
@hsdk123
Jul 01 2021 15:53 UTC

xcode opengl debugger

Didn't know that existed either - will look it up!

if you do _default_frame_buffer.bind() before swapBuffers(), does it fix the error?
actually probably glBindFramebuffer(GL_READ_FRAMEBUFFER, _default_frame_buffer.id()); instead :sweat_smile:
hsdk123
@hsdk123
Jul 01 2021 16:01 UTC
Will try both!
hsdk123
@hsdk123
Jul 01 2021 16:58 UTC
@mosra
Seems both don't work - I've tried using the gpu capture feature in xcode, and I see
Attempted present of non-layer backed renderbuffer
on here
https://github.com/libsdl-org/SDL/blob/39302c921445e9f695a72469be17ba041f6f09db/src/video/uikit/SDL_uikitopenglview.m#L319
hsdk123
@hsdk123
Jul 01 2021 19:01 UTC
Seems what I needed was glBindRenderbuffer!