2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
36 /**********************************************************************/
37 /***** API Functions *****/
38 /**********************************************************************/
43 _mesa_ClearDepth( GLclampd depth
)
45 GET_CURRENT_CONTEXT(ctx
);
47 if (MESA_VERBOSE
& VERBOSE_API
)
48 _mesa_debug(ctx
, "glClearDepth(%f)\n", depth
);
50 ctx
->Depth
.Clear
= CLAMP( depth
, 0.0, 1.0 );
55 _mesa_ClearDepthf( GLclampf depth
)
57 _mesa_ClearDepth(depth
);
61 static ALWAYS_INLINE
void
62 depth_func(struct gl_context
*ctx
, GLenum func
, bool no_error
)
64 if (ctx
->Depth
.Func
== func
)
69 case GL_LESS
: /* (default) pass if incoming z < stored z */
79 _mesa_error(ctx
, GL_INVALID_ENUM
, "glDepth.Func");
84 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewDepth
? 0 : _NEW_DEPTH
);
85 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewDepth
;
86 ctx
->Depth
.Func
= func
;
87 _mesa_update_allow_draw_out_of_order(ctx
);
89 if (ctx
->Driver
.DepthFunc
)
90 ctx
->Driver
.DepthFunc(ctx
, func
);
95 _mesa_DepthFunc_no_error(GLenum func
)
97 GET_CURRENT_CONTEXT(ctx
);
98 depth_func(ctx
, func
, true);
103 _mesa_DepthFunc(GLenum func
)
105 GET_CURRENT_CONTEXT(ctx
);
107 if (MESA_VERBOSE
& VERBOSE_API
)
108 _mesa_debug(ctx
, "glDepthFunc %s\n", _mesa_enum_to_string(func
));
110 depth_func(ctx
, func
, false);
116 _mesa_DepthMask( GLboolean flag
)
118 GET_CURRENT_CONTEXT(ctx
);
120 if (MESA_VERBOSE
& VERBOSE_API
)
121 _mesa_debug(ctx
, "glDepthMask %d\n", flag
);
124 * GL_TRUE indicates depth buffer writing is enabled (default)
125 * GL_FALSE indicates depth buffer writing is disabled
127 if (ctx
->Depth
.Mask
== flag
)
130 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewDepth
? 0 : _NEW_DEPTH
);
131 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewDepth
;
132 ctx
->Depth
.Mask
= flag
;
133 _mesa_update_allow_draw_out_of_order(ctx
);
135 if (ctx
->Driver
.DepthMask
)
136 ctx
->Driver
.DepthMask( ctx
, flag
);
142 * Specified by the GL_EXT_depth_bounds_test extension.
145 _mesa_DepthBoundsEXT( GLclampd zmin
, GLclampd zmax
)
147 GET_CURRENT_CONTEXT(ctx
);
149 if (MESA_VERBOSE
& VERBOSE_API
)
150 _mesa_debug(ctx
, "glDepthBounds(%f, %f)\n", zmin
, zmax
);
153 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDepthBoundsEXT(zmin > zmax)");
157 zmin
= CLAMP(zmin
, 0.0, 1.0);
158 zmax
= CLAMP(zmax
, 0.0, 1.0);
160 if (ctx
->Depth
.BoundsMin
== zmin
&& ctx
->Depth
.BoundsMax
== zmax
)
163 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewDepth
? 0 : _NEW_DEPTH
);
164 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewDepth
;
165 ctx
->Depth
.BoundsMin
= (GLfloat
) zmin
;
166 ctx
->Depth
.BoundsMax
= (GLfloat
) zmax
;
170 /**********************************************************************/
171 /***** Initialization *****/
172 /**********************************************************************/
176 * Initialize the depth buffer attribute group in the given context.
179 _mesa_init_depth(struct gl_context
*ctx
)
181 ctx
->Depth
.Test
= GL_FALSE
;
182 ctx
->Depth
.Clear
= 1.0;
183 ctx
->Depth
.Func
= GL_LESS
;
184 ctx
->Depth
.Mask
= GL_TRUE
;