简体   繁体   中英

Mulitple Fragment Outputs in GLSL 300 es

While writing unit tests for a simple NDK Opengl ES 3.0 demo, I encountered an issue in using multiple render targets. Consider this simple Fragment shader with two outputs, declared in a C++11 string literal.

const static std::string multipleOutputsFragment = R"(#version 300 es
    precision mediump float;
    layout(location = 0) out vec3 out_color1;
    layout(location = 1) out vec3 out_color2;
    void main()
    {
        out_color1 = vec3(1.0, 0.0, 0.0);
        out_color2 = vec3(0.0, 0.0, 1.0);
    }
)";

I have correctly setup an FBO with two color attachments (via glFramebufferTexture2D) and the glCheckFramebufferStatus comes back as GL_FRAMEBUFFER_COMPLETE. I also call glDrawBuffers(2, &attachments[0]), where attachments is a vector of GL_COLOR_ATTACHMENTi enums. Afterwards, I compile and link the shader, without any linking or compile errors (just used a simple vertex passthrough that is irrevelant to this post).

Is there any reason why I can get the fragment location for out_color1 but not for out_color2, using the following opengles function?

auto location = glGetFragDataLocation(m_programId, name.c_str());

The correct location is returned for out_color1 of 0, but when providing "out_color2" to glGetFragDataLocation, the function returns -1.

I'm testing this on a physical device, Galaxy S4, Android 4.4.4 Adreno 320, Opengl ES 3.0.

if you call:

glReadBuffer(COLOR_ATTACHMENT_1);
glReadPixels(*); 

can you see the data that you write to the fbo?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM