{
fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
GLuint i;
- GLint bottom=fxMesa->y_delta-1;
+ GLint bottom=fxMesa->height+fxMesa->y_offset-1;
if (MESA_VERBOSE&VERBOSE_DRIVER) {
fprintf(stderr,"fxmesa: fxDDReadRGBAPixels(...)\n");
GLuint n, GLint x, GLint y, const GLdepth depth[],
const GLubyte mask[])
{
- fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
- GLint bottom=fxMesa->height+fxMesa->y_offset-1;
+ fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
+ GLint bottom = fxMesa->height + fxMesa->y_offset - 1;
- if (MESA_VERBOSE&VERBOSE_DRIVER) {
- fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n");
+ if (MESA_VERBOSE & VERBOSE_DRIVER) {
+ fprintf(stderr, "fxmesa: fxDDWriteDepthSpan(...)\n");
}
x += fxMesa->x_offset;
GLint i;
for (i = 0; i < n; i++) {
if (mask[i]) {
- writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom-y,
- GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &depth[i]);
+ GLshort d = depth[i];
+ writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom - y,
+ GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d);
}
}
}
else {
- writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom-y,
- GR_LFB_SRC_FMT_ZA16, n, 1, 0, (void *) depth);
+ GLushort depth16[MAX_WIDTH];
+ GLint i;
+ for (i = 0; i < n; i++) {
+ depth16[i] = depth[i];
+ }
+ writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom - y,
+ GR_LFB_SRC_FMT_ZA16, n, 1, 0, (void *) depth16);
}
}
void fxDDReadDepthSpan(GLcontext *ctx,
GLuint n, GLint x, GLint y, GLdepth depth[])
{
- fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
- GLint bottom=fxMesa->height+fxMesa->y_offset-1;
+ fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
+ GLint bottom = fxMesa->height + fxMesa->y_offset - 1;
+ GLushort depth16[MAX_WIDTH];
+ GLuint i;
- if (MESA_VERBOSE&VERBOSE_DRIVER) {
- fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n");
+ if (MESA_VERBOSE & VERBOSE_DRIVER) {
+ fprintf(stderr, "fxmesa: fxDDReadDepthSpan(...)\n");
}
- x+=fxMesa->x_offset;
- FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,depth);
+ x += fxMesa->x_offset;
+ FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, x, bottom - y, n, 1, 0, depth16);
+ for (i = 0; i < n; i++) {
+ depth[i] = depth16[i];
+ }
}
GLuint n, const GLint x[], const GLint y[],
const GLdepth depth[], const GLubyte mask[])
{
- fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
- GLint bottom=fxMesa->height+fxMesa->y_offset-1;
+ fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
+ GLint bottom = fxMesa->height + fxMesa->y_offset - 1;
GLuint i;
- if (MESA_VERBOSE&VERBOSE_DRIVER) {
- fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n");
+ if (MESA_VERBOSE & VERBOSE_DRIVER) {
+ fprintf(stderr, "fxmesa: fxDDWriteDepthPixels(...)\n");
}
for (i = 0; i < n; i++) {
if (mask[i]) {
int xpos = x[i] + fxMesa->x_offset;
int ypos = bottom - y[i];
+ GLushort d = depth[i];
writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, xpos, ypos,
- GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &depth[i]);
+ GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d);
}
}
}
void fxDDReadDepthPixels(GLcontext *ctx, GLuint n,
const GLint x[], const GLint y[], GLdepth depth[])
{
- fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
- GLint bottom=fxMesa->height+fxMesa->y_offset-1;
+ fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
+ GLint bottom = fxMesa->height + fxMesa->y_offset - 1;
GLuint i;
- if (MESA_VERBOSE&VERBOSE_DRIVER) {
- fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n");
+ if (MESA_VERBOSE & VERBOSE_DRIVER) {
+ fprintf(stderr, "fxmesa: fxDDReadDepthPixels(...)\n");
}
-
for (i = 0; i < n; i++) {
int xpos = x[i] + fxMesa->x_offset;
int ypos = bottom - y[i];
- FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,xpos,ypos,1,1,0,&depth[i]);
+ GLushort d;
+ FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, xpos, ypos, 1, 1, 0, &d);
+ depth[i] = d;
}
}
-/* $Id: osmesa.c,v 1.9 2000/01/15 06:13:26 rjfrank Exp $ */
+/* $Id: osmesa.c,v 1.10 2000/03/03 17:50:09 brianp Exp $ */
/*
* Mesa 3-D graphics library
swalpha, /* software alpha */
GL_FALSE, /* double buffer */
GL_FALSE, /* stereo */
- DEPTH_BITS,
+ DEFAULT_SOFTWARE_DEPTH_BITS,
STENCIL_BITS,
rgbmode ? ACCUM_BITS : 0,
indexBits,
-
OSMesaContext GLAPIENTRY OSMesaGetCurrentContext( void )
{
GLcontext *ctx = gl_get_current_context();
#define INTERP_XY 1
#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define CLIP_HACK 1
#define PLOT(X,Y) \
if (Z < *zPtr) { \
#endif
}
+
/*
* Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
*/
#define INTERP_XY 1
#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define CLIP_HACK 1
-#define PLOT(X,Y) \
- if (Z < *zPtr) { \
- { GLuint *ptr4 = PIXELADDR4(X,Y); \
- GLuint pixel = 0; \
- pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\
- pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\
- pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\
- *ptr4 = pixel; \
- } \
+#define PLOT(X,Y) \
+ if (Z < *zPtr) { \
+ GLuint *ptr4 = PIXELADDR4(X,Y); \
+ GLuint pixel = 0; \
+ pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
+ pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
+ pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
+ *ptr4 = pixel; \
}
#ifdef WIN32
#endif
}
+
/*
* Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
*/
#define INTERP_XY 1
#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define CLIP_HACK 1
-#define PLOT(X,Y) \
- if (Z < *zPtr) { \
- { GLuint *ptr4 = PIXELADDR4(X,Y); \
- GLuint pixel = 0; \
- pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\
- pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\
- pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\
- *ptr4 = pixel; \
- } \
- *zPtr = Z; \
+#define PLOT(X,Y) \
+ if (Z < *zPtr) { \
+ GLuint *ptr4 = PIXELADDR4(X,Y); \
+ GLuint pixel = 0; \
+ pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \
+ pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \
+ pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \
+ *ptr4 = pixel; \
+ *zPtr = Z; \
}
#ifdef WIN32
if (ctx->RasterMask==DEPTH_BIT
&& ctx->Depth.Func==GL_LESS
- && ctx->Depth.Mask==GL_TRUE) {
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {
switch(osmesa->format) {
case OSMESA_RGBA:
case OSMESA_BGRA:
if (ctx->RasterMask==(DEPTH_BIT|BLEND_BIT)
&& ctx->Depth.Func==GL_LESS
&& ctx->Depth.Mask==GL_TRUE
+ && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
&& ctx->Color.BlendSrcRGB==GL_SRC_ALPHA
&& ctx->Color.BlendDstRGB==GL_ONE_MINUS_SRC_ALPHA
&& ctx->Color.BlendSrcA==GL_SRC_ALPHA
if (ctx->RasterMask==(DEPTH_BIT|BLEND_BIT)
&& ctx->Depth.Func==GL_LESS
&& ctx->Depth.Mask==GL_FALSE
+ && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
&& ctx->Color.BlendSrcRGB==GL_SRC_ALPHA
&& ctx->Color.BlendDstRGB==GL_ONE_MINUS_SRC_ALPHA
&& ctx->Color.BlendSrcA==GL_SRC_ALPHA
(void) pv;
osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */
#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define INTERP_RGB 1
#define INTERP_ALPHA 1
#define INNER_LOOP( LEFT, RIGHT, Y ) \
{
OSMesaContext osmesa = (OSMesaContext) ctx;
#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define SETUP_CODE \
GLubyte r = VB->ColorPtr->data[pv][0]; \
GLubyte g = VB->ColorPtr->data[pv][1]; \
if (ctx->RasterMask==DEPTH_BIT
&& ctx->Depth.Func==GL_LESS
&& ctx->Depth.Mask==GL_TRUE
+ && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
&& osmesa->format!=OSMESA_COLOR_INDEX) {
if (ctx->Light.ShadeModel==GL_SMOOTH) {
return smooth_rgba_z_triangle;
return NULL;
}
+
+
/**********************************************************************/
/***** Occlusion rendering routines *****/
/**********************************************************************/
} \
return;
-/***** Color Index *****/
+/**
+*** Color Index
+**/
+
static void write_index32_span_occ( const GLcontext *ctx,
- GLuint n, GLint x, GLint y,
- const GLuint index[], const GLubyte mask[] )
+ GLuint n, GLint x, GLint y,
+ const GLuint index[], const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
+
+
static void write_index8_span_occ( const GLcontext *ctx,
- GLuint n, GLint x, GLint y,
- const GLubyte index[], const GLubyte mask[] )
+ GLuint n, GLint x, GLint y,
+ const GLubyte index[], const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
+
+
static void write_monoindex_span_occ( const GLcontext *ctx,
- GLuint n, GLint x, GLint y,
- const GLubyte mask[] )
+ GLuint n, GLint x, GLint y,
+ const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
+
+
static void write_index_pixels_occ( const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- const GLuint index[], const GLubyte mask[] )
+ GLuint n, const GLint x[], const GLint y[],
+ const GLuint index[], const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
+
+
static void write_monoindex_pixels_occ( const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- const GLubyte mask[] )
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
-/***** RGB/RGBA *****/
+/**
+*** RGB/RGBA
+**/
static void write_rgba_span_occ( const GLcontext *ctx,
- GLuint n, GLint x, GLint y,
- CONST GLubyte rgba[][4], const GLubyte mask[] )
+ GLuint n, GLint x, GLint y,
+ CONST GLubyte rgba[][4], const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
+
+
static void write_rgb_span_occ( const GLcontext *ctx,
- GLuint n, GLint x, GLint y,
- CONST GLubyte rgb[][3],
- const GLubyte mask[] )
+ GLuint n, GLint x, GLint y,
+ CONST GLubyte rgb[][3],
+ const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
+
+
static void write_rgba_pixels_occ( const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- CONST GLubyte rgba[][4], const GLubyte mask[] )
+ GLuint n, const GLint x[], const GLint y[],
+ CONST GLubyte rgba[][4], const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
+
+
static void write_monocolor_span_occ( const GLcontext *ctx,
- GLuint n, GLint x, GLint y,
- const GLubyte mask[] )
+ GLuint n, GLint x, GLint y,
+ const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
+
+
static void write_monocolor_pixels_occ( const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- const GLubyte mask[] )
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte mask[] )
{
- OCC_STD_MASK_TEST
+ OCC_STD_MASK_TEST
}
-/***** Line Drawing *****/
+
+/**
+*** Line Drawing
+**/
static void line_occ( GLcontext *ctx,
- GLuint vert0, GLuint vert1, GLuint pvert )
+ GLuint vert0, GLuint vert1, GLuint pvert )
{
OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
osmesa->bVisible = GL_TRUE;
}
+
static void line_z_occ( GLcontext *ctx,
- GLuint vert0, GLuint vert1, GLuint pvert )
+ GLuint vert0, GLuint vert1, GLuint pvert )
{
OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
if (osmesa->bVisible) return;
#define INTERP_XY 1
#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define CLIP_HACK 1
#define PLOT(X,Y) \
if (Z < *zPtr) { \
#endif
}
-/***** Triangle Drawing *****/
+
+/**
+*** Triangle Drawing
+**/
static void triangle_occ( GLcontext *ctx, GLuint v0, GLuint v1,
- GLuint v2, GLuint pv )
+ GLuint v2, GLuint pv )
{
OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
osmesa->bVisible = GL_TRUE;
}
+
+
static void triangle_z_occ( GLcontext *ctx, GLuint v0, GLuint v1,
- GLuint v2, GLuint pv )
+ GLuint v2, GLuint pv )
{
OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx;
if (osmesa->bVisible) return;
#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
#define INNER_LOOP( LEFT, RIGHT, Y ) \
{ \
GLint i, len = RIGHT-LEFT; \
#endif
}
+
static const GLubyte *get_string( GLcontext *ctx, GLenum name )
{
(void) ctx;
-/* $Id: fakeglx.c,v 1.24 2000/02/27 18:26:54 brianp Exp $ */
+/* $Id: fakeglx.c,v 1.25 2000/03/03 17:50:09 brianp Exp $ */
/*
* Mesa 3-D graphics library
/*
* Create a GLX visual from a regular XVisualInfo.
+ * This is called when Fake GLX is given an XVisualInfo which wasn't
+ * returned by glXChooseVisual. Since this is the first time we're
+ * considering this visual we'll take a guess at reasonable values
+ * for depth buffer size, stencil size, accum size, etc.
+ * This is the best we can do with a client-side emulation of GLX.
*/
static XMesaVisual
create_glx_visual( Display *dpy, XVisualInfo *visinfo )
GL_FALSE, /* alpha */
GL_TRUE, /* double */
GL_FALSE, /* stereo */
- 8*sizeof(GLdepth),
- 8*sizeof(GLstencil),
- 8*sizeof(GLaccum),
+ DEFAULT_SOFTWARE_DEPTH_BITS,
+ 8 * sizeof(GLstencil),
+ 8 * sizeof(GLaccum),
0 /* level */
);
}
}
if (vis) {
+ /* Note: we're not exactly obeying the glXChooseVisual rules here.
+ * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
+ * largest depth buffer size, which is 32bits/value. However, we
+ * return 16 to maintain performance with earlier versions of Mesa.
+ */
+ if (depth_size == 1)
+ depth_size = DEFAULT_SOFTWARE_DEPTH_BITS;
+ else if (depth_size > 24)
+ depth_size = 31;
+ else if (depth_size > 16)
+ depth_size = 24;
+ /* we only support one size of stencil and accum buffers. */
+ if (stencil_size > 0)
+ stencil_size = STENCIL_BITS;
+ if (accum_size > 0)
+ accum_size = ACCUM_BITS;
if (!save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
stereo_flag,
depth_size, stencil_size, accum_size, level ))
-/* $Id: config.h,v 1.6 2000/02/21 14:46:28 brianp Exp $ */
+/* $Id: config.h,v 1.7 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
/*
- * Bits per depth buffer value: 16 or 32
+ * Bits per depth buffer value: 16 or 32 (GLushort or GLuint)
+ * gl_create_visual() can select any depth in [0, 32].
*/
-#ifdef MESAD3D
- /* Mesa / Direct3D driver only */
- extern float g_DepthScale, g_MaxDepth;
-# define DEPTH_BITS 32
-# define DEPTH_SCALE g_DepthScale
-# define MAX_DEPTH g_MaxDepth
-#else
-# define DEPTH_BITS 16
-# if DEPTH_BITS==16
-# define MAX_DEPTH 0xffff
-# define DEPTH_SCALE 65535.0F
-# elif DEPTH_BITS==32
-# define MAX_DEPTH 0x3fffffff
-# define DEPTH_SCALE ((GLfloat) MAX_DEPTH)
-# else
-# error "illegal number of depth bits"
-# endif
-#endif
+#define DEFAULT_SOFTWARE_DEPTH_BITS 16
+#define DEFAULT_SOFTWARE_DEPTH_TYPE GLushort
+
/*
-/* $Id: context.c,v 1.43 2000/02/12 17:26:15 brianp Exp $ */
+/* $Id: context.c,v 1.44 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
* alphaFlag - alloc software alpha buffers?
* dbFlag - double buffering?
* stereoFlag - stereo buffer?
- * depthFits - requested minimum bits per depth buffer value
- * stencilFits - requested minimum bits per stencil buffer value
- * accumFits - requested minimum bits per accum buffer component
- * indexFits - number of bits per pixel if rgbFlag==GL_FALSE
- * red/green/blue/alphaFits - number of bits per color component
- * in frame buffer for RGB(A) mode.
+ * depthBits - requested bits per depth buffer value
+ * Any value in [0, 32] is acceptable but the actual
+ * depth type will be GLushort or GLuint as needed.
+ * stencilBits - requested minimum bits per stencil buffer value
+ * accumBits - requested minimum bits per accum buffer component
+ * indexBits - number of bits per pixel if rgbFlag==GL_FALSE
+ * red/green/blue/alphaBits - number of bits per color component
+ * in frame buffer for RGB(A) mode.
+ * We always use 8 in core Mesa though.
* Return: pointer to new GLvisual or NULL if requested parameters can't
* be met.
*/
{
GLvisual *vis;
- if (depthBits > (GLint) (8*sizeof(GLdepth))) {
- /* can't meet depth buffer requirements */
+ /* This is to catch bad values from device drivers not updated for
+ * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
+ * bad value now (a 1-bit depth buffer!?!).
+ */
+ assert(depthBits == 0 || depthBits > 1);
+
+ if (depthBits < 0 || depthBits > 32) {
return NULL;
}
- if (stencilBits > (GLint) (8*sizeof(GLstencil))) {
- /* can't meet stencil buffer requirements */
+ if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
return NULL;
}
- if (accumBits > (GLint) (8*sizeof(GLaccum))) {
- /* can't meet accum buffer requirements */
+ if (accumBits < 0 || accumBits > (GLint) (8 * sizeof(GLaccum))) {
return NULL;
}
vis->RedBits = redBits;
vis->GreenBits = greenBits;
vis->BlueBits = blueBits;
- vis->AlphaBits = alphaFlag ? 8*sizeof(GLubyte) : alphaBits;
+ vis->AlphaBits = alphaFlag ? (8 * sizeof(GLubyte)) : alphaBits;
vis->IndexBits = indexBits;
- vis->DepthBits = (depthBits>0) ? 8*sizeof(GLdepth) : 0;
- vis->AccumBits = (accumBits>0) ? 8*sizeof(GLaccum) : 0;
- vis->StencilBits = (stencilBits>0) ? 8*sizeof(GLstencil) : 0;
+ vis->DepthBits = depthBits;
+ vis->AccumBits = (accumBits > 0) ? (8 * sizeof(GLaccum)) : 0;
+ vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
vis->SoftwareAlpha = alphaFlag;
+ if (depthBits == 0) {
+ /* Special case. Even if we don't have a depth buffer we need
+ * good values for DepthMax for Z vertex transformation purposes.
+ */
+ vis->DepthMax = 1;
+ vis->DepthMaxF = 1.0F;
+ }
+ else {
+ vis->DepthMax = (1 << depthBits) - 1;
+ vis->DepthMaxF = (GLfloat) vis->DepthMax;
+ }
+
return vis;
}
#define Sz 10
#define Tz 14
- ctx->Viewport.WindowMap.m[Sz] = 0.5 * DEPTH_SCALE;
- ctx->Viewport.WindowMap.m[Tz] = 0.5 * DEPTH_SCALE;
+ ctx->Viewport.WindowMap.m[Sz] = 0.5 * ctx->Visual->DepthMaxF;
+ ctx->Viewport.WindowMap.m[Tz] = 0.5 * ctx->Visual->DepthMaxF;
#undef Sz
#undef Tz
-/* $Id: dd.h,v 1.13 2000/03/03 15:38:57 brianp Exp $ */
+/* $Id: dd.h,v 1.14 2000/03/03 17:54:56 brianp Exp $ */
/*
* Mesa 3-D graphics library
/***
*** For supporting hardware Z buffers:
*** Either ALL or NONE of these functions must be implemented!
+ *** NOTE that Each depth value is a 32-bit GLuint. If the depth
+ *** buffer is less than 32 bits deep then the extra upperbits are zero.
***/
void (*WriteDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y,
-/* $Id: depth.c,v 1.12 2000/02/02 22:16:04 brianp Exp $ */
+/* $Id: depth.c,v 1.13 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.3
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
/**********************************************************************/
+/***** Misc *****/
+/**********************************************************************/
+
+/*
+ * Return address of depth buffer value for given window coord.
+ */
+GLvoid *
+_mesa_zbuffer_address(GLcontext *ctx, GLint x, GLint y)
+{
+ if (ctx->Visual->DepthBits <= 16)
+ return (GLushort *) ctx->DrawBuffer->DepthBuffer + ctx->DrawBuffer->Width * y + x;
+ else
+ return (GLuint *) ctx->DrawBuffer->DepthBuffer + ctx->DrawBuffer->Width * y + x;
+}
+
+
+#define Z_ADDRESS16( CTX, X, Y ) \
+ ( ((GLushort *) (CTX)->DrawBuffer->DepthBuffer) \
+ + (CTX)->DrawBuffer->Width * (Y) + (X) )
+
+#define Z_ADDRESS32( CTX, X, Y ) \
+ ( ((GLuint *) (CTX)->DrawBuffer->DepthBuffer) \
+ + (CTX)->DrawBuffer->Width * (Y) + (X) )
+
+
+
+/**********************************************************************/
/***** Depth Testing Functions *****/
/**********************************************************************/
* Return: number of fragments which pass the test.
*/
static GLuint
-depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
- GLdepth zbuffer[], const GLdepth z[], GLubyte mask[] )
+depth_test_span16( GLcontext *ctx, GLuint n, GLint x, GLint y,
+ GLushort zbuffer[], const GLdepth z[], GLubyte mask[] )
{
GLuint passed = 0;
MEMSET(mask, 0, n * sizeof(GLubyte));
break;
default:
- gl_problem(ctx, "Bad depth func in depth_test_span");
+ gl_problem(ctx, "Bad depth func in depth_test_span16");
+ }
+
+ return passed;
+}
+
+
+static GLuint
+depth_test_span32( GLcontext *ctx, GLuint n, GLint x, GLint y,
+ GLuint zbuffer[], const GLdepth z[], GLubyte mask[] )
+{
+ GLuint passed = 0;
+
+ /* switch cases ordered from most frequent to less frequent */
+ switch (ctx->Depth.Func) {
+ case GL_LESS:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ if (z[i] < zbuffer[i]) {
+ /* pass */
+ zbuffer[i] = z[i];
+ passed++;
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ if (z[i] < zbuffer[i]) {
+ /* pass */
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_LEQUAL:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] <= zbuffer[i]) {
+ zbuffer[i] = z[i];
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] <= zbuffer[i]) {
+ /* pass */
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_GEQUAL:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] >= zbuffer[i]) {
+ zbuffer[i] = z[i];
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] >= zbuffer[i]) {
+ /* pass */
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_GREATER:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] > zbuffer[i]) {
+ zbuffer[i] = z[i];
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] > zbuffer[i]) {
+ /* pass */
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_NOTEQUAL:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] != zbuffer[i]) {
+ zbuffer[i] = z[i];
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] != zbuffer[i]) {
+ /* pass */
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_EQUAL:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] == zbuffer[i]) {
+ zbuffer[i] = z[i];
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ if (z[i] == zbuffer[i]) {
+ /* pass */
+ passed++;
+ }
+ else {
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_ALWAYS:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0;i<n;i++) {
+ if (mask[i]) {
+ zbuffer[i] = z[i];
+ passed++;
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer or mask */
+ passed = n;
+ }
+ break;
+ case GL_NEVER:
+ MEMSET(mask, 0, n * sizeof(GLubyte));
+ break;
+ default:
+ gl_problem(ctx, "Bad depth func in depth_test_span32");
}
return passed;
_mesa_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
const GLdepth z[], GLubyte mask[] )
{
- GLdepth zbuffer[MAX_WIDTH];
- GLdepth *zptr;
- GLuint passed;
-
if (ctx->Driver.ReadDepthSpan) {
- /* read depth values out of hardware Z buffer */
+ /* hardware-based depth buffer */
+ GLdepth zbuffer[MAX_WIDTH];
+ GLuint passed;
(*ctx->Driver.ReadDepthSpan)(ctx, n, x, y, zbuffer);
- zptr = zbuffer;
+ passed = depth_test_span32(ctx, n, x, y, zbuffer, z, mask);
+ assert(ctx->Driver.WriteDepthSpan);
+ (*ctx->Driver.WriteDepthSpan)(ctx, n, x, y, zbuffer, mask);
+ return passed;
}
else {
- /* test against software depth buffer values */
- zptr = Z_ADDRESS( ctx, x, y );
+ /* software depth buffer */
+ if (ctx->Visual->DepthBits <= 16) {
+ GLushort *zptr = (GLushort *) Z_ADDRESS16(ctx, x, y);
+ GLuint passed = depth_test_span16(ctx, n, x, y, zptr, z, mask);
+ return passed;
+ }
+ else {
+ GLuint *zptr = (GLuint *) Z_ADDRESS32(ctx, x, y);
+ GLuint passed = depth_test_span32(ctx, n, x, y, zptr, z, mask);
+ return passed;
+ }
}
+}
- passed = depth_test_span( ctx, n, x, y, zptr, z, mask );
- if (ctx->Driver.WriteDepthSpan) {
- /* write updated depth values into hardware Z buffer */
- assert(zptr == zbuffer);
- (*ctx->Driver.WriteDepthSpan)(ctx, n, x, y, zbuffer, mask);
- }
- return passed;
-}
+/*
+ * Do depth testing for an array of fragments using software Z buffer.
+ */
+static void
+software_depth_test_pixels16( GLcontext *ctx, GLuint n,
+ const GLint x[], const GLint y[],
+ const GLdepth z[], GLubyte mask[] )
+{
+ /* switch cases ordered from most frequent to less frequent */
+ switch (ctx->Depth.Func) {
+ case GL_LESS:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] < *zptr) {
+ /* pass */
+ *zptr = z[i];
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] < *zptr) {
+ /* pass */
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_LEQUAL:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] <= *zptr) {
+ /* pass */
+ *zptr = z[i];
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] <= *zptr) {
+ /* pass */
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_GEQUAL:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] >= *zptr) {
+ /* pass */
+ *zptr = z[i];
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] >= *zptr) {
+ /* pass */
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_GREATER:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] > *zptr) {
+ /* pass */
+ *zptr = z[i];
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] > *zptr) {
+ /* pass */
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_NOTEQUAL:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] != *zptr) {
+ /* pass */
+ *zptr = z[i];
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] != *zptr) {
+ /* pass */
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_EQUAL:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] == *zptr) {
+ /* pass */
+ *zptr = z[i];
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ if (z[i] == *zptr) {
+ /* pass */
+ }
+ else {
+ /* fail */
+ mask[i] = 0;
+ }
+ }
+ }
+ }
+ break;
+ case GL_ALWAYS:
+ if (ctx->Depth.Mask) {
+ /* Update Z buffer */
+ GLuint i;
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ GLushort *zptr = Z_ADDRESS16(ctx,x[i],y[i]);
+ *zptr = z[i];
+ }
+ }
+ }
+ else {
+ /* Don't update Z buffer or mask */
+ }
+ break;
+ case GL_NEVER:
+ /* depth test never passes */
+ MEMSET(mask, 0, n * sizeof(GLubyte));
+ break;
+ default:
+ gl_problem(ctx, "Bad depth func in software_depth_test_pixels");
+ }
+}
* Do depth testing for an array of fragments using software Z buffer.
*/
static void
-software_depth_test_pixels( GLcontext *ctx, GLuint n,
- const GLint x[], const GLint y[],
- const GLdepth z[], GLubyte mask[] )
+software_depth_test_pixels32( GLcontext *ctx, GLuint n,
+ const GLint x[], const GLint y[],
+ const GLdepth z[], GLubyte mask[] )
{
/* switch cases ordered from most frequent to less frequent */
switch (ctx->Depth.Func) {
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] < *zptr) {
/* pass */
*zptr = z[i];
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] < *zptr) {
/* pass */
}
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] <= *zptr) {
/* pass */
*zptr = z[i];
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] <= *zptr) {
/* pass */
}
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] >= *zptr) {
/* pass */
*zptr = z[i];
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] >= *zptr) {
/* pass */
}
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] > *zptr) {
/* pass */
*zptr = z[i];
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] > *zptr) {
/* pass */
}
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] != *zptr) {
/* pass */
*zptr = z[i];
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] != *zptr) {
/* pass */
}
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] == *zptr) {
/* pass */
*zptr = z[i];
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
if (z[i] == *zptr) {
/* pass */
}
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
- GLdepth *zptr = Z_ADDRESS(ctx,x[i],y[i]);
+ GLuint *zptr = Z_ADDRESS32(ctx,x[i],y[i]);
*zptr = z[i];
}
}
/* update hardware Z buffer with new values */
assert(ctx->Driver.WriteDepthPixels);
- (*ctx->Driver.WriteDepthPixels)(ctx, n, x, y, z, mask );
+ (*ctx->Driver.WriteDepthPixels)(ctx, n, x, y, zbuffer, mask );
}
else {
/* software depth testing */
- software_depth_test_pixels(ctx, n, x, y, z, mask);
+ if (ctx->Visual->DepthBits <= 16)
+ software_depth_test_pixels16(ctx, n, x, y, z, mask);
+ else
+ software_depth_test_pixels32(ctx, n, x, y, z, mask);
}
}
_mesa_read_depth_span_float( GLcontext* ctx,
GLuint n, GLint x, GLint y, GLfloat depth[] )
{
- const GLfloat scale = 1.0F / DEPTH_SCALE;
+ const GLfloat scale = 1.0F / ctx->Visual->DepthMaxF;
- if (ctx->DrawBuffer->Depth) {
+ if (ctx->DrawBuffer->DepthBuffer) {
/* read from software depth buffer */
- const GLdepth *zptr = Z_ADDRESS( ctx, x, y );
- GLuint i;
- for (i = 0; i < n; i++) {
- depth[i] = (GLfloat) zptr[i] * scale;
+ if (ctx->Visual->DepthBits <= 16) {
+ const GLushort *zptr = Z_ADDRESS16( ctx, x, y );
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ depth[i] = (GLfloat) zptr[i] * scale;
+ }
+ }
+ else {
+ const GLuint *zptr = Z_ADDRESS32( ctx, x, y );
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ depth[i] = (GLfloat) zptr[i] * scale;
+ }
}
}
else if (ctx->Driver.ReadDepthSpan) {
* This function is only called through Driver.alloc_depth_buffer.
*/
void
-_mesa_alloc_depth_buffer( GLcontext* ctx )
+_mesa_alloc_depth_buffer( GLcontext *ctx )
{
/* deallocate current depth buffer if present */
if (ctx->DrawBuffer->UseSoftwareDepthBuffer) {
+ GLint bytesPerValue;
+
if (ctx->DrawBuffer->Depth) {
FREE(ctx->DrawBuffer->Depth);
+ ctx->DrawBuffer->DepthBuffer = NULL;
ctx->DrawBuffer->Depth = NULL;
}
/* allocate new depth buffer, but don't initialize it */
- ctx->DrawBuffer->Depth = (GLdepth *) MALLOC( ctx->DrawBuffer->Width
- * ctx->DrawBuffer->Height
- * sizeof(GLdepth) );
+ if (ctx->Visual->DepthBits <= 16)
+ bytesPerValue = sizeof(GLushort);
+ else
+ bytesPerValue = sizeof(GLuint);
+
+ ctx->DrawBuffer->DepthBuffer = MALLOC( ctx->DrawBuffer->Width
+ * ctx->DrawBuffer->Height
+ * bytesPerValue );
+ ctx->DrawBuffer->Depth = (GLdepth *) ctx->DrawBuffer->DepthBuffer;
+
if (!ctx->DrawBuffer->Depth) {
/* out of memory */
ctx->Depth.Test = GL_FALSE;
* This function is only called through Driver.clear_depth_buffer.
*/
void
-_mesa_clear_depth_buffer( GLcontext* ctx )
+_mesa_clear_depth_buffer( GLcontext *ctx )
{
- GLdepth clear_value = (GLdepth) (ctx->Depth.Clear * DEPTH_SCALE);
-
- if (ctx->Visual->DepthBits==0 || !ctx->DrawBuffer->Depth || !ctx->Depth.Mask) {
+ if (ctx->Visual->DepthBits == 0
+ || !ctx->DrawBuffer->DepthBuffer
+ || !ctx->Depth.Mask) {
/* no depth buffer, or writing to it is disabled */
return;
}
if (ctx->Scissor.Enabled) {
/* only clear scissor region */
- GLint y;
- for (y=ctx->DrawBuffer->Ymin; y<=ctx->DrawBuffer->Ymax; y++) {
- GLdepth *d = Z_ADDRESS( ctx, ctx->DrawBuffer->Xmin, y );
- GLint n = ctx->DrawBuffer->Xmax - ctx->DrawBuffer->Xmin + 1;
- do {
- *d++ = clear_value;
- n--;
- } while (n);
+ if (ctx->Visual->DepthBits <= 16) {
+ const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->Visual->DepthMax);
+ const GLint rows = ctx->DrawBuffer->Ymax - ctx->DrawBuffer->Ymin + 1;
+ const GLint width = ctx->DrawBuffer->Width;
+ GLushort *dRow = (GLushort *) ctx->DrawBuffer->DepthBuffer
+ + ctx->DrawBuffer->Ymin * width + ctx->DrawBuffer->Xmin;
+ GLint i, j;
+ for (i = 0; i < rows; i++) {
+ for (j = 0; j < width; j++) {
+ dRow[j] = clearValue;
+ }
+ dRow += width;
+ }
+ }
+ else {
+ const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->Visual->DepthMax);
+ const GLint rows = ctx->DrawBuffer->Ymax - ctx->DrawBuffer->Ymin + 1;
+ const GLint width = ctx->DrawBuffer->Width;
+ GLuint *dRow = (GLuint *) ctx->DrawBuffer->DepthBuffer
+ + ctx->DrawBuffer->Ymin * width + ctx->DrawBuffer->Xmin;
+ GLint i, j;
+ for (i = 0; i < rows; i++) {
+ for (j = 0; j < width; j++) {
+ dRow[j] = clearValue;
+ }
+ dRow += width;
+ }
}
}
else {
/* clear whole buffer */
- if (sizeof(GLdepth)==2 && (clear_value&0xff)==(clear_value>>8)) {
- /* lower and upper bytes of clear_value are same, use MEMSET */
- MEMSET( ctx->DrawBuffer->Depth, clear_value & 0xff,
- 2*ctx->DrawBuffer->Width * ctx->DrawBuffer->Height);
+ if (ctx->Visual->DepthBits <= 16) {
+ const GLushort clearValue = (GLushort) (ctx->Depth.Clear * ctx->Visual->DepthMax);
+ if ((clearValue & 0xff) == (clearValue >> 8)) {
+ /* lower and upper bytes of clear_value are same, use MEMSET */
+ MEMSET( ctx->DrawBuffer->DepthBuffer, clearValue & 0xff,
+ 2 * ctx->DrawBuffer->Width * ctx->DrawBuffer->Height);
+ }
+ else {
+ GLushort *d = ctx->DrawBuffer->DepthBuffer;
+ GLint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height;
+ while (n >= 16) {
+ d[0] = clearValue; d[1] = clearValue;
+ d[2] = clearValue; d[3] = clearValue;
+ d[4] = clearValue; d[5] = clearValue;
+ d[6] = clearValue; d[7] = clearValue;
+ d[8] = clearValue; d[9] = clearValue;
+ d[10] = clearValue; d[11] = clearValue;
+ d[12] = clearValue; d[13] = clearValue;
+ d[14] = clearValue; d[15] = clearValue;
+ d += 16;
+ n -= 16;
+ }
+ while (n > 0) {
+ *d++ = clearValue;
+ n--;
+ }
+ }
}
else {
- GLdepth *d = ctx->DrawBuffer->Depth;
+ /* >16 bit depth buffer */
+ GLuint *d = (GLuint *) ctx->DrawBuffer->DepthBuffer;
+ const GLuint clearValue = (GLuint) (ctx->Depth.Clear * ctx->Visual->DepthMax);
GLint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height;
- while (n>=16) {
- d[0] = clear_value; d[1] = clear_value;
- d[2] = clear_value; d[3] = clear_value;
- d[4] = clear_value; d[5] = clear_value;
- d[6] = clear_value; d[7] = clear_value;
- d[8] = clear_value; d[9] = clear_value;
- d[10] = clear_value; d[11] = clear_value;
- d[12] = clear_value; d[13] = clear_value;
- d[14] = clear_value; d[15] = clear_value;
+ while (n >= 16) {
+ d[0] = clearValue; d[1] = clearValue;
+ d[2] = clearValue; d[3] = clearValue;
+ d[4] = clearValue; d[5] = clearValue;
+ d[6] = clearValue; d[7] = clearValue;
+ d[8] = clearValue; d[9] = clearValue;
+ d[10] = clearValue; d[11] = clearValue;
+ d[12] = clearValue; d[13] = clearValue;
+ d[14] = clearValue; d[15] = clearValue;
d += 16;
n -= 16;
}
- while (n>0) {
- *d++ = clear_value;
+ while (n > 0) {
+ *d++ = clearValue;
n--;
}
}
-/* $Id: depth.h,v 1.6 2000/02/02 22:16:04 brianp Exp $ */
+/* $Id: depth.h,v 1.7 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.3
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
-
/*
- * Return the address of the Z-buffer value for window coordinate (x,y):
+ * Internal functions
*/
-#define Z_ADDRESS( CTX, X, Y ) \
- ((CTX)->DrawBuffer->Depth + (CTX)->DrawBuffer->Width * (Y) + (X))
-
+extern GLvoid *
+_mesa_zbuffer_address(GLcontext *ctx, GLint x, GLint y);
extern GLuint
-/* $Id: dlist.c,v 1.33 2000/03/03 17:45:21 brianp Exp $ */
+/* $Id: dlist.c,v 1.34 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
static void save_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
{
- save_PolygonOffset(factor, DEPTH_SCALE * bias);
+ GET_CURRENT_CONTEXT(ctx);
+ save_PolygonOffset(factor, ctx->Visual->DepthMaxF * bias);
}
-/* $Id: drawpix.c,v 1.13 2000/03/03 15:39:13 brianp Exp $ */
+/* $Id: drawpix.c,v 1.14 2000/03/03 17:54:56 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "feedback.h"
#include "image.h"
#include "macros.h"
+#include "mem.h"
#include "mmath.h"
#include "pixel.h"
#include "span.h"
}
else {
/* setup array of fragment Z value to pass to zoom function */
- GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * DEPTH_SCALE);
+ GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMaxF);
GLint i;
assert(drawWidth < MAX_WIDTH);
for (i=0; i<drawWidth; i++)
/* Fragment depth values */
if (ctx->Depth.Test || ctx->Fog.Enabled) {
- GLdepth zval = (GLdepth) (ctx->Current.RasterPos[2] * DEPTH_SCALE);
+ GLdepth zval = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMaxF);
GLint i;
for (i = 0; i < drawWidth; i++) {
zspan[i] = zval;
/* Special case: directly write 16-bit depth values */
GLint row;
for (row = 0; row < height; row++, y++) {
- const GLdepth *zptr = gl_pixel_addr_in_image(&ctx->Unpack,
+ GLdepth zspan[MAX_WIDTH];
+ const GLushort *zptr = gl_pixel_addr_in_image(&ctx->Unpack,
pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0);
- gl_write_rgba_span( ctx, width, x, y, zptr, rgba, GL_BITMAP );
+ GLint i;
+ for (i = 0; i < width; i++)
+ zspan[i] = zptr[i];
+ gl_write_rgba_span( ctx, width, x, y, zspan, rgba, GL_BITMAP );
}
}
- else if (type==GL_UNSIGNED_INT && sizeof(GLdepth)==sizeof(GLuint)
+ else if (type==GL_UNSIGNED_INT && ctx->Visual->DepthBits == 32
&& !bias_or_scale && !zoom && ctx->Visual->RGBAflag) {
/* Special case: directly write 32-bit depth values */
- GLint i, row;
- /* Compute shift value to scale 32-bit uints down to depth values. */
- GLuint shift = 0;
- GLuint max = MAX_DEPTH;
- while ((max & 0x80000000) == 0) {
- max = max << 1;
- shift++;
- }
+ GLint row;
for (row = 0; row < height; row++, y++) {
- GLdepth zspan[MAX_WIDTH];
- const GLdepth *zptr = gl_pixel_addr_in_image(&ctx->Unpack,
+ const GLuint *zptr = gl_pixel_addr_in_image(&ctx->Unpack,
pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0);
- for (i=0;i<width;i++) {
- zspan[i] = zptr[i] >> shift;
- }
- gl_write_rgba_span( ctx, width, x, y, zspan, rgba, GL_BITMAP );
+ gl_write_rgba_span( ctx, width, x, y, zptr, rgba, GL_BITMAP );
}
}
else {
/* Fragment depth values */
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
- GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * DEPTH_SCALE);
+ GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual->DepthMaxF);
GLint i;
for (i=0;i<width;i++) {
zspan[i] = z;
-/* $Id: feedback.c,v 1.8 2000/01/25 16:49:20 brianp Exp $ */
+/* $Id: feedback.c,v 1.9 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
FEEDBACK_TOKEN( ctx, win[0] );
FEEDBACK_TOKEN( ctx, win[1] );
if (ctx->Feedback.Mask & FB_3D) {
+ printf("FB %g\n", win[2]);
FEEDBACK_TOKEN( ctx, win[2] );
}
if (ctx->Feedback.Mask & FB_4D) {
win[0] = VB->Win.data[v][0];
win[1] = VB->Win.data[v][1];
- win[2] = VB->Win.data[v][2] / DEPTH_SCALE;
+ win[2] = VB->Win.data[v][2] / ctx->Visual->DepthMaxF;
win[3] = 1.0 / VB->Win.data[v][3];
if (ctx->Light.ShadeModel == GL_SMOOTH)
void gl_select_triangle( GLcontext *ctx,
GLuint v0, GLuint v1, GLuint v2, GLuint pv )
{
- struct vertex_buffer *VB = ctx->VB;
+ const struct vertex_buffer *VB = ctx->VB;
if (gl_cull_triangle( ctx, v0, v1, v2, 0 )) {
- gl_update_hitflag( ctx, VB->Win.data[v0][2] / DEPTH_SCALE );
- gl_update_hitflag( ctx, VB->Win.data[v1][2] / DEPTH_SCALE );
- gl_update_hitflag( ctx, VB->Win.data[v2][2] / DEPTH_SCALE );
+ const GLfloat zs = 1.0F / ctx->Visual->DepthMaxF;
+ gl_update_hitflag( ctx, VB->Win.data[v0][2] * zs );
+ gl_update_hitflag( ctx, VB->Win.data[v1][2] * zs );
+ gl_update_hitflag( ctx, VB->Win.data[v2][2] * zs );
}
}
void gl_select_line( GLcontext *ctx,
GLuint v0, GLuint v1, GLuint pv )
{
- struct vertex_buffer *VB = ctx->VB;
-
- gl_update_hitflag( ctx, VB->Win.data[v0][2] / DEPTH_SCALE );
- gl_update_hitflag( ctx, VB->Win.data[v1][2] / DEPTH_SCALE );
+ const struct vertex_buffer *VB = ctx->VB;
+ const GLfloat zs = 1.0F / ctx->Visual->DepthMaxF;
+ gl_update_hitflag( ctx, VB->Win.data[v0][2] * zs );
+ gl_update_hitflag( ctx, VB->Win.data[v1][2] * zs );
}
void gl_select_points( GLcontext *ctx, GLuint first, GLuint last )
{
struct vertex_buffer *VB = ctx->VB;
+ const GLfloat zs = 1.0F / ctx->Visual->DepthMaxF;
GLuint i;
for (i=first;i<=last;i++) {
if (VB->ClipMask[i]==0) {
- gl_update_hitflag( ctx, VB->Win.data[i][2] / DEPTH_SCALE);
+ gl_update_hitflag( ctx, VB->Win.data[i][2] * zs );
}
}
}
-/* $Id: image.c,v 1.17 2000/02/21 16:33:20 brianp Exp $ */
+/* $Id: image.c,v 1.18 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
/* clamp depth values to [0,1] and convert from floats to integers */
{
+ const GLfloat zs = ctx->Visual->DepthMaxF;
GLuint i;
for (i = 0; i < n; i++) {
- dest[i] = (GLdepth) (CLAMP(depth[i], 0.0F, 1.0F) * DEPTH_SCALE);
+ dest[i] = (GLdepth) (CLAMP(depth[i], 0.0F, 1.0F) * zs);
}
}
-/* $Id: matrix.c,v 1.15 2000/02/21 23:00:51 brianp Exp $ */
+/* $Id: matrix.c,v 1.16 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
ctx->Viewport.WindowMap.m[MAT_TX] = ctx->Viewport.WindowMap.m[MAT_SX] + x;
ctx->Viewport.WindowMap.m[MAT_SY] = (GLfloat) height / 2.0F;
ctx->Viewport.WindowMap.m[MAT_TY] = ctx->Viewport.WindowMap.m[MAT_SY] + y;
- ctx->Viewport.WindowMap.m[MAT_SZ] = 0.5 * DEPTH_SCALE;
- ctx->Viewport.WindowMap.m[MAT_TZ] = 0.5 * DEPTH_SCALE;
+ ctx->Viewport.WindowMap.m[MAT_SZ] = 0.5 * ctx->Visual->DepthMaxF;
+ ctx->Viewport.WindowMap.m[MAT_TZ] = 0.5 * ctx->Visual->DepthMaxF;
ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;
ctx->Viewport.Near = n;
ctx->Viewport.Far = f;
- ctx->Viewport.WindowMap.m[MAT_SZ] = DEPTH_SCALE * ((f - n) / 2.0);
- ctx->Viewport.WindowMap.m[MAT_TZ] = DEPTH_SCALE * ((f - n) / 2.0 + n);
+ ctx->Viewport.WindowMap.m[MAT_SZ] = ctx->Visual->DepthMaxF * ((f - n) / 2.0);
+ ctx->Viewport.WindowMap.m[MAT_TZ] = ctx->Visual->DepthMaxF * ((f - n) / 2.0 + n);
ctx->ModelProjectWinMatrixUptodate = GL_FALSE;
-/* $Id: polygon.c,v 1.8 2000/02/27 20:38:15 keithw Exp $ */
+/* $Id: polygon.c,v 1.9 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
void
_mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
{
- _mesa_PolygonOffset(factor, bias * DEPTH_SCALE );
+ GET_CURRENT_CONTEXT(ctx);
+ ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffsetEXT");
+ _mesa_PolygonOffset(factor, bias * ctx->Visual->DepthMaxF );
}
-/* $Id: rastpos.c,v 1.5 2000/02/02 19:17:57 brianp Exp $ */
+/* $Id: rastpos.c,v 1.6 2000/03/03 17:47:39 brianp Exp $ */
/*
* Mesa 3-D graphics library
* Version: 3.3
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
ctx->Current.RasterPos[1] = (ndc[1] * ctx->Viewport.WindowMap.m[MAT_SY] +
ctx->Viewport.WindowMap.m[MAT_TY]);
ctx->Current.RasterPos[2] = (ndc[2] * ctx->Viewport.WindowMap.m[MAT_SZ] +
- ctx->Viewport.WindowMap.m[MAT_TZ]) / DEPTH_SCALE;
+ ctx->Viewport.WindowMap.m[MAT_TZ]) / ctx->Visual->DepthMaxF;
ctx->Current.RasterPos[3] = clip[3];
ctx->Current.RasterPosValid = GL_TRUE;