Bug 13978

Summary: [Mesa core] glGetIntegerv(GL_DRAW_BUFFER0) returns wrong buffer enum
Product: Mesa Reporter: Shuang He <shuang.he>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: christophe.prigent, haihao.xiang
Version: unspecified   
Hardware: Other   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: test case
Simple Demonstration

Description Shuang He 2008-01-08 17:36:59 UTC
System Environment:
--------------------------
--Platform: FC6
--Xf86_video_intel:f089942689df622b1af00569eade4883a84eb7a3
--Mesa:3369cd9a6f943365242d7832e69788d4aede9a8f 
--DRM:cd19dcef4f7cc454f68618a0a1e903f159db21ad
--Kernel:2.6.22

Bug detailed description:
--------------------------
this issue happens in both software rendering and DRI mode
specified GL_FRONT_LEFT and GL_BACK_LEFT as draw buffers, but what glGetIntegerv(GL_DRAW_BUFFER0) returns are wrong.

Reproduce steps:
----------------
start X
compile and run the attached test case


Current result:
----------------
glGetIntegerv(GL_DRAW_BUFFER0) returns wrong buffer enum


Expected result:
----------------
glGetIntegerv(GL_DRAW_BUFFER0) should return correct buffer enum
Comment 1 Shuang He 2008-01-08 17:41:05 UTC
Created attachment 13602 [details]
test case
Comment 2 Shuang He 2008-01-08 18:22:33 UTC
seems this can fix this issue:

--- a/src/mesa/main/buffers.c   2008-01-09 09:54:06.000000000 +0800
+++ b/src/mesa/main/buffers.c   2008-01-09 09:56:15.000000000 +0800
@@ -540,10 +540,12 @@
       for (buf = 0; buf < n; buf++ ) {
          if (destMask[buf]) {
             fb->_ColorDrawBufferIndexes[buf] = _mesa_ffs(destMask[buf]) - 1;
+            fb->ColorDrawBuffer[buf] = buffers[buf];
             count = buf + 1;
          }
          else {
             fb->_ColorDrawBufferIndexes[buf] = -1;
+            fb->ColorDrawBuffer[buf] = GL_NONE;
          }
       }
       /* set remaining outputs to -1 (GL_NONE) */


Comment 3 Brian Paul 2008-01-09 13:19:12 UTC
Your patch is the correct fix.  I'm committing it to git.
Comment 4 Shuang He 2008-10-12 19:11:34 UTC
verified 
Comment 5 Benjamin Botwin 2014-01-04 14:54:24 UTC
Created attachment 91486 [details]
Simple Demonstration
Comment 6 Benjamin Botwin 2014-01-04 14:56:12 UTC
GL_DRAW_BUFFER0 returns 1029 instead of GL_BACK_LEFT
Comment 7 Samuel Iglesias Gonsálvez 2015-07-23 10:17:10 UTC
(In reply to Benjamin Botwin from comment #6)
> GL_DRAW_BUFFER0 returns 1029 instead of GL_BACK_LEFT

I test it and I have not found anything wrong in Mesa. The initial value for double-buffered contexts is GL_BACK.
   * See: https://www.opengl.org/sdk/docs/man4/html/glDrawBuffer.xhtml
   * Also see: https://www.opengl.org/sdk/docs/man2/xhtml/glGet.xml Search for GL_DRAW_BUFFER.

Furthermore, glClearBuffer() doc says the following:
  "If buffer is GL_COLOR, a particular draw buffer GL_DRAW_BUFFERi
   is specified by passing i as drawBuffer."

As a second parameter of glClearbuffer(), you are passing the value got from glGetIntegeriv() which is wrong. For GL_DRAW_BUFFER0, you should pass a 0. If you do that, the window is cleared with red color once we swap buffers.
   * See https://www.opengl.org/sdk/docs/man3/xhtml/glClearBuffer.xml
Comment 8 Tapani Pälli 2015-07-28 10:07:42 UTC
I tested as well, GL_BACK is returned as specified, therefore resolving as fixed

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.