mesa: add LOCATION_COMPONENT support to GetProgramResourceiv
[mesa.git] / src / mesa / main / buffers.c
index 2c4a1386776ae747b899091d1ab6a529470d8f08..a28c5831576575589869fc09ee9363d4caf1b783 100644 (file)
@@ -58,10 +58,7 @@ supported_buffer_bitmask(const struct gl_context *ctx,
 
    if (_mesa_is_user_fbo(fb)) {
       /* A user-created renderbuffer */
-      GLuint i;
-      for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
-         mask |= (BUFFER_BIT_COLOR0 << i);
-      }
+      mask = ((1 << ctx->Const.MaxColorAttachments) - 1) << BUFFER_COLOR0;
    }
    else {
       /* A window system framebuffer */
@@ -225,9 +222,15 @@ read_buffer_enum_to_index(GLenum buffer)
    }
 }
 
+static bool
+is_legal_es3_readbuffer_enum(GLenum buf)
+{
+   return buf == GL_BACK || buf == GL_NONE ||
+          (buf >= GL_COLOR_ATTACHMENT0 && buf <= GL_COLOR_ATTACHMENT31);
+}
 
 /**
- * Called by glDrawBuffer().
+ * Called by glDrawBuffer() and glNamedFramebufferDrawBuffer().
  * Specify which renderbuffer(s) to draw into for the first color output.
  * <buffer> can name zero, one, two or four renderbuffers!
  * \sa _mesa_DrawBuffers
@@ -248,9 +251,9 @@ read_buffer_enum_to_index(GLenum buffer)
  *
  * See the GL_EXT_framebuffer_object spec for more info.
  */
-void
-_mesa_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
-                  GLenum buffer, const char *caller)
+static void
+draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
+            GLenum buffer, const char *caller)
 {
    GLbitfield destMask;
 
@@ -299,7 +302,7 @@ void GLAPIENTRY
 _mesa_DrawBuffer(GLenum buffer)
 {
    GET_CURRENT_CONTEXT(ctx);
-   _mesa_draw_buffer(ctx, ctx->DrawBuffer, buffer, "glDrawBuffer");
+   draw_buffer(ctx, ctx->DrawBuffer, buffer, "glDrawBuffer");
 }
 
 
@@ -318,22 +321,22 @@ _mesa_NamedFramebufferDrawBuffer(GLuint framebuffer, GLenum buf)
    else
       fb = ctx->WinSysDrawBuffer;
 
-   _mesa_draw_buffer(ctx, fb, buf, "glNamedFramebufferDrawBuffer");
+   draw_buffer(ctx, fb, buf, "glNamedFramebufferDrawBuffer");
 }
 
 
 /**
- * Called by glDrawBuffersARB; specifies the destination color renderbuffers
- * for N fragment program color outputs.
+ * Called by glDrawBuffersARB() and glNamedFramebufferDrawBuffers() to specify
+ * the destination color renderbuffers for N fragment program color outputs.
  * \sa _mesa_DrawBuffer
  * \param n  number of outputs
  * \param buffers  array [n] of renderbuffer names.  Unlike glDrawBuffer, the
  *                 names cannot specify more than one buffer.  For example,
  *                 GL_FRONT_AND_BACK is illegal.
  */
-void
-_mesa_draw_buffers(struct gl_context *ctx, struct gl_framebuffer *fb,
-                   GLsizei n, const GLenum *buffers, const char *caller)
+static void
+draw_buffers(struct gl_context *ctx, struct gl_framebuffer *fb,
+             GLsizei n, const GLenum *buffers, const char *caller)
 {
    GLuint output;
    GLbitfield usedBufferMask, supportedMask;
@@ -508,7 +511,7 @@ void GLAPIENTRY
 _mesa_DrawBuffers(GLsizei n, const GLenum *buffers)
 {
    GET_CURRENT_CONTEXT(ctx);
-   _mesa_draw_buffers(ctx, ctx->DrawBuffer, n, buffers, "glDrawBuffers");
+   draw_buffers(ctx, ctx->DrawBuffer, n, buffers, "glDrawBuffers");
 }
 
 
@@ -528,7 +531,7 @@ _mesa_NamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n,
    else
       fb = ctx->WinSysDrawBuffer;
 
-   _mesa_draw_buffers(ctx, fb, n, bufs, "glNamedFramebufferDrawBuffers");
+   draw_buffers(ctx, fb, n, bufs, "glNamedFramebufferDrawBuffers");
 }
 
 
@@ -551,8 +554,8 @@ updated_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb)
 
 
 /**
- * Helper function to set the GL_DRAW_BUFFER state in the context and
- * current FBO.  Called via glDrawBuffer(), glDrawBuffersARB()
+ * Helper function to set the GL_DRAW_BUFFER state for the given context and
+ * FBO.  Called via glDrawBuffer(), glDrawBuffersARB()
  *
  * All error checking will have been done prior to calling this function
  * so nothing should go wrong at this point.
@@ -668,8 +671,11 @@ _mesa_update_draw_buffers(struct gl_context *ctx)
 
 /**
  * Like \sa _mesa_drawbuffers(), this is a helper function for setting
- * GL_READ_BUFFER state in the context and current FBO.
+ * GL_READ_BUFFER state for the given context and FBO.
+ * Note that all error checking should have been done before calling
+ * this function.
  * \param ctx  the rendering context
+ * \param fb  the framebuffer object to update
  * \param buffer  GL_FRONT, GL_BACK, GL_COLOR_ATTACHMENT0, etc.
  * \param bufferIndex  the numerical index corresponding to 'buffer'
  */
@@ -693,12 +699,13 @@ _mesa_readbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
 
 
 /**
- * Called by glReadBuffer to set the source renderbuffer for reading pixels.
+ * Called by glReadBuffer and glNamedFramebufferReadBuffer to set the source
+ * renderbuffer for reading pixels.
  * \param mode color buffer such as GL_FRONT, GL_BACK, etc.
  */
-void
-_mesa_read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
-                  GLenum buffer, const char *caller)
+static void
+read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
+            GLenum buffer, const char *caller)
 {
    GLbitfield supportedMask;
    gl_buffer_index srcBuffer;
@@ -714,7 +721,11 @@ _mesa_read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
    }
    else {
       /* general case / window-system framebuffer */
-      srcBuffer = read_buffer_enum_to_index(buffer);
+      if (_mesa_is_gles3(ctx) && !is_legal_es3_readbuffer_enum(buffer))
+         srcBuffer = -1;
+      else
+         srcBuffer = read_buffer_enum_to_index(buffer);
+
       if (srcBuffer == -1) {
          _mesa_error(ctx, GL_INVALID_ENUM,
                      "%s(invalid buffer %s)", caller,
@@ -746,7 +757,7 @@ void GLAPIENTRY
 _mesa_ReadBuffer(GLenum buffer)
 {
    GET_CURRENT_CONTEXT(ctx);
-   _mesa_read_buffer(ctx, ctx->ReadBuffer, buffer, "glReadBuffer");
+   read_buffer(ctx, ctx->ReadBuffer, buffer, "glReadBuffer");
 }
 
 
@@ -765,5 +776,5 @@ _mesa_NamedFramebufferReadBuffer(GLuint framebuffer, GLenum src)
    else
       fb = ctx->WinSysReadBuffer;
 
-   _mesa_read_buffer(ctx, fb, src, "glNamedFramebufferReadBuffer");
+   read_buffer(ctx, fb, src, "glNamedFramebufferReadBuffer");
 }