2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 /**********************************************************************/
37 /***** API Functions *****/
38 /**********************************************************************/
43 _mesa_ClearDepth( GLclampd depth
)
45 GET_CURRENT_CONTEXT(ctx
);
46 ASSERT_OUTSIDE_BEGIN_END(ctx
);
48 depth
= CLAMP( depth
, 0.0, 1.0 );
50 if (ctx
->Depth
.Clear
== depth
)
53 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
54 ctx
->Depth
.Clear
= depth
;
55 if (ctx
->Driver
.ClearDepth
)
56 (*ctx
->Driver
.ClearDepth
)( ctx
, ctx
->Depth
.Clear
);
62 _mesa_DepthFunc( GLenum func
)
64 GET_CURRENT_CONTEXT(ctx
);
65 ASSERT_OUTSIDE_BEGIN_END(ctx
);
67 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
68 _mesa_debug(ctx
, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func
));
71 case GL_LESS
: /* (default) pass if incoming z < stored z */
81 _mesa_error( ctx
, GL_INVALID_ENUM
, "glDepth.Func" );
85 if (ctx
->Depth
.Func
== func
)
88 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
89 ctx
->Depth
.Func
= func
;
91 if (ctx
->Driver
.DepthFunc
)
92 ctx
->Driver
.DepthFunc( ctx
, func
);
98 _mesa_DepthMask( GLboolean flag
)
100 GET_CURRENT_CONTEXT(ctx
);
101 ASSERT_OUTSIDE_BEGIN_END(ctx
);
103 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
104 _mesa_debug(ctx
, "glDepthMask %d\n", flag
);
107 * GL_TRUE indicates depth buffer writing is enabled (default)
108 * GL_FALSE indicates depth buffer writing is disabled
110 if (ctx
->Depth
.Mask
== flag
)
113 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
114 ctx
->Depth
.Mask
= flag
;
116 if (ctx
->Driver
.DepthMask
)
117 ctx
->Driver
.DepthMask( ctx
, flag
);
122 /* GL_EXT_depth_bounds_test */
124 _mesa_DepthBoundsEXT( GLclampd zmin
, GLclampd zmax
)
126 GET_CURRENT_CONTEXT(ctx
);
127 ASSERT_OUTSIDE_BEGIN_END(ctx
);
130 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDepthBoundsEXT(zmin > zmax)");
134 zmin
= CLAMP(zmin
, 0.0, 1.0);
135 zmax
= CLAMP(zmax
, 0.0, 1.0);
137 if (ctx
->Depth
.BoundsMin
== zmin
&& ctx
->Depth
.BoundsMax
== zmax
)
140 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
141 ctx
->Depth
.BoundsMin
= (GLfloat
) zmin
;
142 ctx
->Depth
.BoundsMax
= (GLfloat
) zmax
;
146 /**********************************************************************/
147 /***** Initialization *****/
148 /**********************************************************************/
150 void _mesa_init_depth( GLcontext
* ctx
)
152 /* Depth buffer group */
153 ctx
->Depth
.Test
= GL_FALSE
;
154 ctx
->Depth
.Clear
= 1.0;
155 ctx
->Depth
.Func
= GL_LESS
;
156 ctx
->Depth
.Mask
= GL_TRUE
;
157 ctx
->Depth
.OcclusionTest
= GL_FALSE
;
160 if (ctx
->Visual
.depthBits
== 0) {
161 /* Special case. Even if we don't have a depth buffer we need
162 * good values for DepthMax for Z vertex transformation purposes
163 * and for per-fragment fog computation.
165 ctx
->DepthMax
= 1 << 16;
166 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
168 else if (ctx
->Visual
.depthBits
< 32) {
169 ctx
->DepthMax
= (1 << ctx
->Visual
.depthBits
) - 1;
170 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
173 /* Special case since shift values greater than or equal to the
174 * number of bits in the left hand expression's type are undefined.
176 ctx
->DepthMax
= 0xffffffff;
177 ctx
->DepthMaxF
= (GLfloat
) ctx
->DepthMax
;
179 ctx
->MRD
= 1.0; /* Minimum resolvable depth value, for polygon offset */