2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 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.
35 /**********************************************************************/
36 /***** API Functions *****/
37 /**********************************************************************/
42 _mesa_ClearDepth( GLclampd depth
)
44 GET_CURRENT_CONTEXT(ctx
);
45 ASSERT_OUTSIDE_BEGIN_END(ctx
);
47 if (MESA_VERBOSE
& VERBOSE_API
)
48 _mesa_debug(ctx
, "glClearDepth(%f)\n", depth
);
50 depth
= CLAMP( depth
, 0.0, 1.0 );
52 if (ctx
->Depth
.Clear
== depth
)
55 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
56 ctx
->Depth
.Clear
= depth
;
61 _mesa_ClearDepthf( GLclampf depth
)
63 _mesa_ClearDepth(depth
);
68 _mesa_DepthFunc( GLenum func
)
70 GET_CURRENT_CONTEXT(ctx
);
71 ASSERT_OUTSIDE_BEGIN_END(ctx
);
73 if (MESA_VERBOSE
& VERBOSE_API
)
74 _mesa_debug(ctx
, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func
));
77 case GL_LESS
: /* (default) pass if incoming z < stored z */
87 _mesa_error( ctx
, GL_INVALID_ENUM
, "glDepth.Func" );
91 if (ctx
->Depth
.Func
== func
)
94 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
95 ctx
->Depth
.Func
= func
;
97 if (ctx
->Driver
.DepthFunc
)
98 ctx
->Driver
.DepthFunc( ctx
, func
);
104 _mesa_DepthMask( GLboolean flag
)
106 GET_CURRENT_CONTEXT(ctx
);
107 ASSERT_OUTSIDE_BEGIN_END(ctx
);
109 if (MESA_VERBOSE
& VERBOSE_API
)
110 _mesa_debug(ctx
, "glDepthMask %d\n", flag
);
113 * GL_TRUE indicates depth buffer writing is enabled (default)
114 * GL_FALSE indicates depth buffer writing is disabled
116 if (ctx
->Depth
.Mask
== flag
)
119 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
120 ctx
->Depth
.Mask
= flag
;
122 if (ctx
->Driver
.DepthMask
)
123 ctx
->Driver
.DepthMask( ctx
, flag
);
129 * Specified by the GL_EXT_depth_bounds_test extension.
132 _mesa_DepthBoundsEXT( GLclampd zmin
, GLclampd zmax
)
134 GET_CURRENT_CONTEXT(ctx
);
135 ASSERT_OUTSIDE_BEGIN_END(ctx
);
137 if (MESA_VERBOSE
& VERBOSE_API
)
138 _mesa_debug(ctx
, "glDepthBounds(%f, %f)\n", zmin
, zmax
);
141 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDepthBoundsEXT(zmin > zmax)");
145 zmin
= CLAMP(zmin
, 0.0, 1.0);
146 zmax
= CLAMP(zmax
, 0.0, 1.0);
148 if (ctx
->Depth
.BoundsMin
== zmin
&& ctx
->Depth
.BoundsMax
== zmax
)
151 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
152 ctx
->Depth
.BoundsMin
= (GLfloat
) zmin
;
153 ctx
->Depth
.BoundsMax
= (GLfloat
) zmax
;
157 /**********************************************************************/
158 /***** Initialization *****/
159 /**********************************************************************/
163 * Initialize the depth buffer attribute group in the given context.
166 _mesa_init_depth(struct gl_context
*ctx
)
168 ctx
->Depth
.Test
= GL_FALSE
;
169 ctx
->Depth
.Clear
= 1.0;
170 ctx
->Depth
.Func
= GL_LESS
;
171 ctx
->Depth
.Mask
= GL_TRUE
;