mesa: replace GLenum with GLenum16 in common structures (v4)
[mesa.git] / src / mesa / main / buffers.c
index 5c37f0f5376fae13cd634703bc87b7f0b45863d9..5492227de0860d7319511b4ae737de2d8a60f916 100644 (file)
@@ -170,7 +170,7 @@ draw_buffer_enum_to_bitmask(const struct gl_context *ctx, GLenum buffer)
  * Helper routine used by glReadBuffer.
  * Given a GLenum naming a color buffer, return the index of the corresponding
  * renderbuffer (a BUFFER_* value).
- * return -1 for an invalid buffer.
+ * return BUFFER_NONE for an invalid buffer.
  */
 static gl_buffer_index
 read_buffer_enum_to_index(const struct gl_context *ctx, GLenum buffer)
@@ -299,7 +299,8 @@ draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb,
    }
 
    /* if we get here, there's no error so set new state */
-   _mesa_drawbuffers(ctx, fb, 1, &buffer, &destMask);
+   const GLenum16 buffer16 = buffer;
+   _mesa_drawbuffers(ctx, fb, 1, &buffer16, &destMask);
 
    /* Call device driver function only if fb is the bound draw buffer */
    if (fb == ctx->DrawBuffer) {
@@ -573,7 +574,11 @@ draw_buffers(struct gl_context *ctx, struct gl_framebuffer *fb, GLsizei n,
    }
 
    /* OK, if we get here, there were no errors so set the new state */
-   _mesa_drawbuffers(ctx, fb, n, buffers, destMask);
+   GLenum16 buffers16[MAX_DRAW_BUFFERS];
+   for (int i = 0; i < n; i++)
+      buffers16[i] = buffers[i];
+
+   _mesa_drawbuffers(ctx, fb, n, buffers16, destMask);
 
    /*
     * Call device driver function if fb is the bound draw buffer.
@@ -694,7 +699,8 @@ updated_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb)
  */
 void
 _mesa_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
-                  GLuint n, const GLenum *buffers, const GLbitfield *destMask)
+                  GLuint n, const GLenum16 *buffers,
+                  const GLbitfield *destMask)
 {
    GLbitfield mask[MAX_DRAW_BUFFERS];
    GLuint buf;
@@ -719,7 +725,7 @@ _mesa_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
    if (n > 0 && _mesa_bitcount(destMask[0]) > 1) {
       GLuint count = 0, destMask0 = destMask[0];
       while (destMask0) {
-         const int bufIndex = u_bit_scan(&destMask0);
+         const gl_buffer_index bufIndex = u_bit_scan(&destMask0);
          if (fb->_ColorDrawBufferIndexes[count] != bufIndex) {
             updated_drawbuffers(ctx, fb);
             fb->_ColorDrawBufferIndexes[count] = bufIndex;
@@ -733,7 +739,7 @@ _mesa_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
       GLuint count = 0;
       for (buf = 0; buf < n; buf++ ) {
          if (destMask[buf]) {
-            GLint bufIndex = ffs(destMask[buf]) - 1;
+            gl_buffer_index bufIndex = ffs(destMask[buf]) - 1;
             /* only one bit should be set in the destMask[buf] field */
             assert(_mesa_bitcount(destMask[buf]) == 1);
             if (fb->_ColorDrawBufferIndexes[buf] != bufIndex) {
@@ -743,9 +749,9 @@ _mesa_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
             count = buf + 1;
          }
          else {
-            if (fb->_ColorDrawBufferIndexes[buf] != -1) {
+            if (fb->_ColorDrawBufferIndexes[buf] != BUFFER_NONE) {
               updated_drawbuffers(ctx, fb);
-               fb->_ColorDrawBufferIndexes[buf] = -1;
+               fb->_ColorDrawBufferIndexes[buf] = BUFFER_NONE;
             }
          }
          fb->ColorDrawBuffer[buf] = buffers[buf];
@@ -753,11 +759,11 @@ _mesa_drawbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
       fb->_NumColorDrawBuffers = count;
    }
 
-   /* set remaining outputs to -1 (GL_NONE) */
+   /* set remaining outputs to BUFFER_NONE */
    for (buf = fb->_NumColorDrawBuffers; buf < ctx->Const.MaxDrawBuffers; buf++) {
-      if (fb->_ColorDrawBufferIndexes[buf] != -1) {
+      if (fb->_ColorDrawBufferIndexes[buf] != BUFFER_NONE) {
          updated_drawbuffers(ctx, fb);
-         fb->_ColorDrawBufferIndexes[buf] = -1;
+         fb->_ColorDrawBufferIndexes[buf] = BUFFER_NONE;
       }
    }
    for (buf = n; buf < ctx->Const.MaxDrawBuffers; buf++) {