Question

According to the OpenGL documentation I should be able to set the source for pixel reading to any of GL_COLOR_ATTACHMENTi. However, when I try this, glGetError gives me a GL_INVALID_ENUM error. A subsequent glReadPixels simply reads the back buffer.

The version reported by glGetString(GL_VERSION) is 4.2.11627 Core Profile Forward-Compatible Context. I am running on linux and have the fglrx ati drivers installed (version 8.96.7-120312a-135598C-ATI).

I checked that my FBO is bound and complete. I also verified the glGetError was not set by a previous call.

It fails already on this (I would expect an error here, but rather INVALID_OPERATION than INVALID_ENUM):

#include <iostream>
#include "Window.h" // My own class based on sfml, but I am sure context creation works fine
#include <glload/gll.hpp>
#include <glload/gl_core.hpp>

int main()
{
    const unsigned int screenW = 1280, screenH = 720;
    Window w(screenW, screenH, 32, false);
    if (glload::LoadFunctions() == glload::LS_LOAD_FAILED)
    {
        std::cerr << "glload failed to load" << std::endl;
        return -1;
    }
    gl::ReadBuffer(gl::GL_COLOR_ATTACHMENT0);
    if( gl::GetError() == gl::GL_INVALID_ENUM)
    {
        std::cerr << "Invalid enum error" << std::endl;
        return -1;
    }
    return 0;
}

Is there another reason this call could trigger INVALID_ENUM or is it more likely that the OpenGL implementation I am using is bugged?

Was it helpful?

Solution

However, when I try this, glGetError gives me a GL_INVALID_ENUM error. A subsequent glReadPixels simply reads the back buffer.

If you're reading from the back buffer, then that means the default framebuffer is still bound. And glReadBuffer sets the reading buffer for the current framebuffer.

The default framebuffer doesn't have GL_COLOR_ATTACHMENTs. Therefore, setting one of these images to be the read buffer is an error. You have to bind the FBO first, then set the read buffer. Note that glReadBuffer sets the binding for the framebuffer bound to GL_READ_FRAMEBUFFER, not GL_DRAW_FRAMEBUFFER. So make sure it's bound to the right place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top