mesa: create read_buffer_err() and always inline read_buffer()
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 26 Jun 2017 15:06:14 +0000 (17:06 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 28 Jun 2017 08:25:13 +0000 (10:25 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/main/buffers.c

index d85974afe60d24eab710a7fbd3df325839c25a75..18e46adf84e69549bb312853d7c770f66211cc45 100644 (file)
@@ -738,11 +738,10 @@ _mesa_readbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
  * renderbuffer for reading pixels.
  * \param mode color buffer such as GL_FRONT, GL_BACK, etc.
  */
-static void
+static ALWAYS_INLINE void
 read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
-            GLenum buffer, const char *caller)
+            GLenum buffer, const char *caller, bool no_error)
 {
-   GLbitfield supportedMask;
    gl_buffer_index srcBuffer;
 
    FLUSH_VERTICES(ctx, 0);
@@ -756,23 +755,29 @@ read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
    }
    else {
       /* general case / window-system framebuffer */
-      if (_mesa_is_gles3(ctx) && !is_legal_es3_readbuffer_enum(buffer))
+      if (!no_error &&_mesa_is_gles3(ctx) &&
+          !is_legal_es3_readbuffer_enum(buffer))
          srcBuffer = BUFFER_NONE;
       else
          srcBuffer = read_buffer_enum_to_index(ctx, buffer);
 
-      if (srcBuffer == BUFFER_NONE) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "%s(invalid buffer %s)", caller,
-                     _mesa_enum_to_string(buffer));
-         return;
-      }
-      supportedMask = supported_buffer_bitmask(ctx, fb);
-      if (((1 << srcBuffer) & supportedMask) == 0) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "%s(invalid buffer %s)", caller,
-                     _mesa_enum_to_string(buffer));
-         return;
+      if (!no_error) {
+         GLbitfield supportedMask;
+
+         if (srcBuffer == BUFFER_NONE) {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "%s(invalid buffer %s)", caller,
+                        _mesa_enum_to_string(buffer));
+            return;
+         }
+
+         supportedMask = supported_buffer_bitmask(ctx, fb);
+         if (((1 << srcBuffer) & supportedMask) == 0) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "%s(invalid buffer %s)", caller,
+                        _mesa_enum_to_string(buffer));
+            return;
+         }
       }
    }
 
@@ -788,11 +793,19 @@ read_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
 }
 
 
+static void
+read_buffer_err(struct gl_context *ctx, struct gl_framebuffer *fb,
+                GLenum buffer, const char *caller)
+{
+   read_buffer(ctx, fb, buffer, caller, false);
+}
+
+
 void GLAPIENTRY
 _mesa_ReadBuffer(GLenum buffer)
 {
    GET_CURRENT_CONTEXT(ctx);
-   read_buffer(ctx, ctx->ReadBuffer, buffer, "glReadBuffer");
+   read_buffer_err(ctx, ctx->ReadBuffer, buffer, "glReadBuffer");
 }
 
 
@@ -811,5 +824,5 @@ _mesa_NamedFramebufferReadBuffer(GLuint framebuffer, GLenum src)
    else
       fb = ctx->WinSysReadBuffer;
 
-   read_buffer(ctx, fb, src, "glNamedFramebufferReadBuffer");
+   read_buffer_err(ctx, fb, src, "glNamedFramebufferReadBuffer");
 }