Hello
I have a problem with glClear color
when scissor is enabled.
Below pseudo code give a blue rendering
whilst a green is expected.
glViewport (0,0,width,height);
glScissor (0,0,width,height);
glClearColor (0.,1.,0.,0.);
glEnable (GL_SCISSOR_TEST);
glClear (GL_COLOR_BUFFER_BIT);
/* Drawn in blue !!!! Should be green !!!!.*/
It happens with Mesa-3.0, Mesa-3.1b3.
An investigation shows that in
X/xmesa2.c/clear_32bit_ximage
the "all" flag is false and then we pass in the code :
register int i, j;
register GLuint pixel = (GLuint) xmesa->clearpixel;
for (j=0;j<height;j++) {
register GLuint *ptr4 = PIXELADDR4( x, y+j );
for (i=0;i<width;i++) {
*ptr4++ = pixel;
}
}
that does not do a pixel byte swapping
which is correctly done in the 'all==true' part
of the code where we pass if scissor is disabled
(giving the correct color in :
glViewport (0,0,width,height);
glScissor (0,0,width,height);
glClearColor (0.,1.,0.,0.);
glClear (GL_COLOR_BUFFER_BIT); ).
Then clearly this part of the code should be :
register int i, j;
register GLuint pixel = (GLuint) xmesa->clearpixel;
if (xmesa->swapbytes) {
pixel = ((pixel >> 24) & 0x000000ff)
| ((pixel >> 8) & 0x0000ff00)
| ((pixel << 8) & 0x00ff0000)
| ((pixel << 24) & 0xff000000);
}
for (j=0;j<height;j++) {
register GLuint *ptr4 = PIXELADDR4( x, y+j );
for (i=0;i<width;i++) {
*ptr4++ = pixel;
}
}
I assume it should be the case also for other-like
routines in xmesa2.c !!!
I join my xdpyinfo and a full test program.
Regards.
Guy Barrand
-------------------------------------------------------------
Guy Barrand e-mail: [EMAIL PROTECTED]
LAL Tel: +33 (1) 64 46 84 17
Universite de Paris-Sud Fax: +33 (1) 69 07 94 04
B.P 34
91898 ORSAY CEDEX France
CERN Tel: 41 22 76 76990 (B02-R005)
-------------------------------------------------------------
/* +---------------------- Copyright notice -------------------------------+ */
/* | Copyright (C) 1995, Guy Barrand, LAL Orsay, ([EMAIL PROTECTED]) | */
/* | Permission to use, copy, modify, and distribute this software | */
/* | and its documentation for any purpose and without fee is hereby | */
/* | granted, provided that the above copyright notice appear in all | */
/* | copies and that both that copyright notice and this permission | */
/* | notice appear in supporting documentation. This software is | */
/* | provided "as is" without express or implied warranty. | */
/* +---------------------- Copyright notice -------------------------------+ */
#define HAS_GL
#define HAS_X
#include <stdio.h>
#if defined(HAS_GL) && defined(HAS_X)
#include <math.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#ifdef HAS_CO
#include <CCharacter.h>
#include <CMemory.h>
#include <CPrinter.h>
#else
#define CWarn printf
#define CInfo printf
#define CInfoF printf
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#ifdef __cplusplus
extern "C"{
#endif
static void Initialize ();
static Window CreateWindow (char*,int,int,unsigned int,unsigned int);
static void GetWindowSize (Display*,Window,int*,int*);
static Bool WaitForNotify (Display*,XEvent*,char*);
#ifdef __cplusplus
}
#endif
static struct
{
Display* display;
Colormap colormap;
XVisualInfo* vinfo;
GLXContext ctx;
int privateColormap;
} Class = {NULL,0L,NULL,NULL,1};
/***************************************************************************/
int main (
int a_argn
,char* a_args[]
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
Window win1,win2,win3;
int width,height;
GLint viewport[4];
double aspect;
GLuint list;
/*.........................................................................*/
if(a_argn==2)
{
Class.privateColormap = 0;
}
Initialize ();
/*Set window 1.*/
win1 = CreateWindow("win 1",0 , 0,400,200);
if(glXMakeCurrent(Class.display,win1,Class.ctx)==False)
{
CWarn("glXMakeCurrent failed.\n");
}
GetWindowSize (Class.display,win1,&width,&height);
glViewport (0,0,width,height);
glEnable (GL_SCISSOR_TEST);
glClearColor (0.,1.,0.,0.);
glClear (GL_COLOR_BUFFER_BIT);
glFinish ();
glXSwapBuffers (Class.display,win1);
glXWaitX ();
{GLenum error = glGetError();
if(error!=GL_NO_ERROR)
printf("Some OpenGL error occured : %s\n",gluErrorString(error));}
while(1)
{ XEvent xevent;
if(XPending(Class.display)!=0)
{
}
}
}
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
static void Initialize (
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
static int attributeList[] = { GLX_RGBA,
GLX_RED_SIZE, 2,
GLX_GREEN_SIZE, 2,
GLX_BLUE_SIZE, 2,
GLX_DOUBLEBUFFER,
GLX_DEPTH_SIZE, 1,
None };
/*.........................................................................*/
Class.display = XOpenDisplay(NULL);
if(Class.display==NULL)
{
CWarn("Can't open display.\n");
exit(EXIT_SUCCESS);
}
Class.vinfo =
glXChooseVisual(Class.display,DefaultScreen(Class.display),attributeList);
if(Class.vinfo==NULL)
{
CWarn("Can't choose a visual.\n");
exit(EXIT_SUCCESS);
}
Class.ctx = glXCreateContext(Class.display,Class.vinfo,NULL,GL_FALSE);
if(Class.ctx==NULL)
{
CWarn("Can't create a GLX context.\n");
exit(EXIT_SUCCESS);
}
if(Class.privateColormap==1)
{
/* It is better to create a colormap adapted to the visual.*/
Class.colormap = XCreateColormap
(Class.display,XDefaultRootWindow(Class.display),Class.vinfo->visual, AllocNone);
}
else
{
/* Default colormap does not work on an SGI with SGI libGL.*/
Class.colormap = XDefaultColormap
(Class.display,DefaultScreen(Class.display));
}
if(Class.colormap==0L)
{
CWarn("Can't create X colormap.\n");
exit(EXIT_SUCCESS);
}
}
/***************************************************************************/
static Window CreateWindow (
char* title
,int a_x
,int a_y
,unsigned int a_width
,unsigned int a_height
)
/***************************************************************************/
/* From:
UNIX> man glXIntro
*/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
Window This;
XSetWindowAttributes swa;
XSizeHints sh;
XTextProperty tp;
/*.........................................................................*/
if(Class.display==NULL) return 0L;
if(Class.vinfo==NULL) return 0L;
swa.colormap = Class.colormap;
swa.border_pixel = 0L;
swa.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask;
This = XCreateWindow (Class.display,
XDefaultRootWindow(Class.display),
a_x,a_y,a_width,a_height,
0,
Class.vinfo->depth,
InputOutput,
Class.vinfo->visual,
CWBorderPixel|CWColormap|CWEventMask,&swa);
if(This==0L)
{
CWarn ("Can't create an X window.\n");
exit (EXIT_SUCCESS);
}
XStringListToTextProperty (&title, 1, &tp);
sh.flags = USPosition | USSize;
XSetWMProperties (Class.display, This, &tp, &tp, 0, 0, &sh, 0, 0);
XFree (tp.value);
XMapWindow (Class.display, This);
XRaiseWindow (Class.display, This);
{XEvent event;
XIfEvent (Class.display, &event, WaitForNotify, (char*)This);}
return This;
}
/***************************************************************************/
static void GetWindowSize (
Display* a_display
,Window a_window
,int* a_width
,int* a_height
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
XWindowAttributes watbs;
/*.........................................................................*/
if(a_width) *a_width = 0;
if(a_height) *a_height = 0;
if(!a_display) return;
if(!a_window) return;
XGetWindowAttributes (a_display,a_window,&watbs);
if(a_width) *a_width = watbs.width;
if(a_height) *a_height = watbs.height;
}
/***************************************************************************/
static Bool WaitForNotify (
Display* d
,XEvent* e
,char* arg
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
/*.........................................................................*/
d = NULL;
return (e->type == MapNotify) && (e->xmap.window == (Window)arg);
}
#else
#define CWarn printf
int main() {CWarn ("C macro HAS_GL or HAS_X not defined.\n");return 0;}
#endif
name of display: 134.158.90.210:0.0
version number: 11.0
vendor string: Hummingbird Communications Ltd.
vendor release number: 6010
maximum request size: 4194300 bytes
motion buffer size: 1
bitmap unit, bit order, padding: 8, MSBFirst, 32
image byte order: MSBFirst
number of supported pixmap formats: 2
supported pixmap formats:
depth 1, bits_per_pixel 1, scanline_pad 32
depth 24, bits_per_pixel 32, scanline_pad 32
keycode range: minimum 8, maximum 254
focus: window 0x1c0000d, revert to PointerRoot
number of extensions: 11
BIG-REQUESTS
DOUBLE-BUFFER
HCL-DOS-Access
HCLMISC
HCLxperf
LBX
SECURITY
SHAPE
XC-APPGROUP
XC-MISC
XInputExtension
default screen number: 0
number of screens: 1
screen #0:
dimensions: 1152x864 pixels (320x240 millimeters)
resolution: 91x91 dots per inch
depths (2): 1, 24
root window id: 0x29
depth of root window: 24 planes
number of colormaps: minimum 1, maximum 1
default colormap: 0x20
default number of colormap cells: 256
preallocated pixels: black 0, white 16777215
options: backing-store WHEN MAPPED, save-unders NO
largest cursor: 32x32
current input event mask: 0x780000
SubstructureNotifyMask SubstructureRedirectMask FocusChangeMask
PropertyChangeMask
number of visuals: 1
default visual id: 0x21
visual:
visual id: 0x21
class: TrueColor
depth: 24 planes
available colormap entries: 256 per subfield
red, green, blue masks: 0xff, 0xff00, 0xff0000
significant bits in color specification: 8 bits