0

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.

  • Do you have a different device you can try it on? How old is the OS build on the device? Just from what you posted here, I don't see anything wrong. I found that earlier ES 3.0 drivers were very buggy. – Reto Koradi Apr 26 '15 at 23:02
  • This is my only device with Opengl ES 3.0 for the time being. Great suggestion about upgrading the OS build. It turns out I had Lollipop 5.0.1 update waiting for me. Unfortunately after upgrading the problem still persists. – user4833370 Apr 28 '15 at 10:37

1 Answers1

1

if you call:

glReadBuffer(COLOR_ATTACHMENT_1);
glReadPixels(*); 

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

Gal Kamar
  • 173
  • 1
  • 8