mesa: implement GL_MAX_VERTEX_ATTRIB_STRIDE
[mesa.git] / src / mesa / main / buffers.c
index 6cbce9d5da2f224be15ec32d346958200e07f848..8a0852c429c20d828a4128be344db3dabaa70783 100644 (file)
@@ -101,7 +101,7 @@ draw_buffer_enum_to_bitmask(const struct gl_context *ctx, GLenum buffer)
       case GL_FRONT:
          return BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_FRONT_RIGHT;
       case GL_BACK:
-         if (_mesa_is_gles3(ctx)) {
+         if (_mesa_is_gles(ctx)) {
             /* Page 181 (page 192 of the PDF) in section 4.2.1 of the OpenGL
              * ES 3.0.1 specification says:
              *
@@ -111,6 +111,11 @@ draw_buffer_enum_to_bitmask(const struct gl_context *ctx, GLenum buffer)
              *
              * Since there is no stereo rendering in ES 3.0, only return the
              * LEFT bits.  This also satisfies the "n must be 1" requirement.
+             *
+             * We also do this for GLES 1 and 2 because those APIs have no
+             * concept of selecting the front and back buffer anyway and it's
+             * convenient to be able to maintain the magic behaviour of
+             * GL_BACK in that case.
              */
             if (ctx->DrawBuffer->Visual.doubleBufferMode)
                return BUFFER_BIT_BACK_LEFT;
@@ -489,10 +494,11 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,
    }
 
    /*
-    * If n==1, destMask[0] may have up to four bits set.
+    * destMask[0] may have up to four bits set
+    * (ex: glDrawBuffer(GL_FRONT_AND_BACK)).
     * Otherwise, destMask[x] can only have one bit set.
     */
-   if (n == 1) {
+   if (n > 0 && _mesa_bitcount(destMask[0]) > 1) {
       GLuint count = 0, destMask0 = destMask[0];
       while (destMask0) {
          GLint bufIndex = ffs(destMask0) - 1;
@@ -561,16 +567,11 @@ _mesa_drawbuffers(struct gl_context *ctx, GLuint n, const GLenum *buffers,
 void
 _mesa_update_draw_buffers(struct gl_context *ctx)
 {
-   GLenum buffers[MAX_DRAW_BUFFERS];
-   GLuint i;
-
    /* should be a window system FBO */
    assert(_mesa_is_winsys_fbo(ctx->DrawBuffer));
 
-   for (i = 0; i < ctx->Const.MaxDrawBuffers; i++)
-      buffers[i] = ctx->Color.DrawBuffer[i];
-
-   _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers, buffers, NULL);
+   _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers,
+                     ctx->Color.DrawBuffer, NULL);
 }