Giter VIP home page Giter VIP logo

Comments (6)

mosra avatar mosra commented on May 18, 2024

Hi, thanks for the detailed report!

Hmm. Actually I think I know what's happening here -- Framebuffer::clearColor() is not equivalent to glClearColor() but rather glClearBuffer(), a slightly different (and newer) API. So then, what the code in the first listing is doing is basically this:

  1. calling the clearColor() clears the framebuffer with a red color (instead of setting the clear color to red, as you assumed)
  2. then, calling the clear() clears the framebuffer again, but with the globally set clear color (so it basically clears back to black and so it looks like nothing was changed)

Setting the clear color (without clearing anything) is done using GL::Renderer::setClearColor() instead, so to fix the above either:

  • remove the second clear(), and call just clearColor(), or
  • call GL::Renderer::setClearColor(Color4::red()) instead of qtDefaultFramebuffer.clearColor()

What might be helpful for you -- the documentation has a table mapping from GL APIs to Magnum APIs, so if you know what you want to do in raw GL, you can use the table to see the equivalent Magnum APIs. It's also possible to use the search to search for e.g. glClearColor and it'll show what function it corresponds to. Every function documentation also lists GL APIs used underneath.

Hope this helps! :)


Originally I thought you're hitting a driver bug because very recently I was pushing some workarounds for Intel drivers on Windows where using clearColor() didn't do anything but clear() did. But since you're using master, you should be using the workaround already (if on an Intel GPU) and it should be listed in the engine startup log.

from magnum-bootstrap.

Gerard097 avatar Gerard097 commented on May 18, 2024

Thanks a lot for the fast and detailed explanation. I was confused because I misinterpreted the documentation of GL::Renderer::setClearColor but now it is "clear" to me.

Now, I just tried both approaches:

void MyApplication::initializeGL() {
    _context.create();
  
    GL::Renderer::setClearColor(Color4::red());
    /* TODO: Add your initialization code here */
}

void MyApplication::paintGL() {
    /* Reset state to avoid Qt affecting Magnum */
    GL::Context::current().resetState(GL::Context::State::ExitExternal);

    /* Using framebuffer provided by Qt as default framebuffer */
    auto qtDefaultFramebuffer = GL::Framebuffer::wrap(defaultFramebufferObject(), {{}, {width(), height()}});
    qtDefaultFramebuffer.clear(GL::FramebufferClear::Color);
    /* TODO: Add your drawing code here */

    /* Clean up Magnum state and back to Qt */
    GL::Context::current().resetState(GL::Context::State::EnterExternal);
}

This one worked as spected cleaning the buffer with red color.

void MyApplication::initializeGL() {
    _context.create();
    /* TODO: Add your initialization code here */
}

void MyApplication::paintGL() {
    /* Reset state to avoid Qt affecting Magnum */
    GL::Context::current().resetState(GL::Context::State::ExitExternal);

    /* Using framebuffer provided by Qt as default framebuffer */
    auto qtDefaultFramebuffer = GL::Framebuffer::wrap(defaultFramebufferObject(), {{}, {width(), height()}});
    qtDefaultFramebuffer.clearColor(GL_COLOR_ATTACHMENT0, Color4::green());
    /* TODO: Add your drawing code here */

    /* Clean up Magnum state and back to Qt */
    GL::Context::current().resetState(GL::Context::State::EnterExternal);
}

Unfortunately this one didn't work, leaving the frame buffer with a gray-black color instead of green. Is GL_COLOR_ATTACHMENT0 the right attachment to clear?

This is the startup info:

Renderer: GeForce GTX 1050/PCIe/SSE2 by NVIDIA Corporation
OpenGL version: 4.6.0 NVIDIA 399.07
Using optional features:
GL_ARB_ES2_compatibility
GL_ARB_ES3_1_compatibility
GL_ARB_direct_state_access
GL_ARB_get_texture_sub_image
GL_ARB_invalidate_subdata
GL_ARB_multi_bind
GL_ARB_robustness
GL_ARB_separate_shader_objects
GL_ARB_texture_filter_anisotropic
GL_ARB_texture_storage
GL_ARB_texture_storage_multisample
GL_ARB_vertex_array_object
GL_KHR_debug
Using driver workarounds:
no-layout-qualifiers-on-old-glsl
nv-zero-context-profile-mask
nv-implementation-color-read-format-dsa-broken
nv-windows-dangling-transform-feedback-varying-names
nv-cubemap-inconsistent-compressed-image-size
nv-cubemap-broken-full-compressed-image-query
nv-compressed-block-size-in-bits

from magnum-bootstrap.

mosra avatar mosra commented on May 18, 2024

Haha, right, the GL_COLOR_ATTACHMENT0 looked suspicious to me. Now I know why :) The index passed to clearColor() is interpreted as GL_COLOR_ATTACHMENT0 + index, so in this case you're clearing atttachment number 36064 ;)

Try this instead:

qtDefaultFramebuffer.clearColor(0, Color4::green());

Also, the code you have above should throw some GL error. You can either check GL errors manually (which is tedious), or you can run the app with --magnum-gpu-validation on passed on the command line (or, equivalently, setting the MAGNUM_GPU_VALIDATION=ON environment variable since I'm not sure how Qt propagates the command-line arguments). With this enabled, the driver should print a detailed info about every GL error that happens, NVidia drivers are exceptionally good at showing what's wrong. A bit of caution though -- it might happen that Qt itself would be spamming the output with its own GL errors in which case it would be hard to know what's your error and what Qt's. I'm being optimistic and trust Qt to not cause any GL error, but I never verified that myself so I can't be sure :)

In general, none of the Magnum APIs expect raw GL enums, it's always either a numeric value or a C++11 scoped enum wrapping the raw GL values in a more typesafe way.

from magnum-bootstrap.

Gerard097 avatar Gerard097 commented on May 18, 2024

Alright that was it :). I added the command in the build configuration and the console was displaying some clear errors.

Thanks for the tips, I'll take them in consideration.

from magnum-bootstrap.

mosra avatar mosra commented on May 18, 2024

Great :)

Anything else or can this be closed as resolved? :) For general questions you can join the Gitter channel (simply log in with your GitHub account), usually there's always someone around who's happy to help.

from magnum-bootstrap.

Gerard097 avatar Gerard097 commented on May 18, 2024

Yes, that's all.

from magnum-bootstrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.