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.
35 /**********************************************************************/
36 /***** API Functions *****/
37 /**********************************************************************/
42 _mesa_ClearDepth( GLclampd depth
)
44 GET_CURRENT_CONTEXT(ctx
);
46 if (MESA_VERBOSE
& VERBOSE_API
)
47 _mesa_debug(ctx
, "glClearDepth(%f)\n", depth
);
49 ctx
->Depth
.Clear
= CLAMP( depth
, 0.0, 1.0 );
54 _mesa_ClearDepthf( GLclampf depth
)
56 _mesa_ClearDepth(depth
);
61 _mesa_DepthFunc( GLenum func
)
63 GET_CURRENT_CONTEXT(ctx
);
65 if (MESA_VERBOSE
& VERBOSE_API
)
66 _mesa_debug(ctx
, "glDepthFunc %s\n", _mesa_enum_to_string(func
));
68 if (ctx
->Depth
.Func
== func
)
72 case GL_LESS
: /* (default) pass if incoming z < stored z */
82 _mesa_error( ctx
, GL_INVALID_ENUM
, "glDepth.Func" );
86 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
87 ctx
->Depth
.Func
= func
;
89 if (ctx
->Driver
.DepthFunc
)
90 ctx
->Driver
.DepthFunc( ctx
, func
);
96 _mesa_DepthMask( GLboolean flag
)
98 GET_CURRENT_CONTEXT(ctx
);
100 if (MESA_VERBOSE
& VERBOSE_API
)
101 _mesa_debug(ctx
, "glDepthMask %d\n", flag
);
104 * GL_TRUE indicates depth buffer writing is enabled (default)
105 * GL_FALSE indicates depth buffer writing is disabled
107 if (ctx
->Depth
.Mask
== flag
)
110 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
111 ctx
->Depth
.Mask
= flag
;
113 if (ctx
->Driver
.DepthMask
)
114 ctx
->Driver
.DepthMask( ctx
, flag
);
120 * Specified by the GL_EXT_depth_bounds_test extension.
123 _mesa_DepthBoundsEXT( GLclampd zmin
, GLclampd zmax
)
125 GET_CURRENT_CONTEXT(ctx
);
127 if (MESA_VERBOSE
& VERBOSE_API
)
128 _mesa_debug(ctx
, "glDepthBounds(%f, %f)\n", zmin
, zmax
);
131 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDepthBoundsEXT(zmin > zmax)");
135 zmin
= CLAMP(zmin
, 0.0, 1.0);
136 zmax
= CLAMP(zmax
, 0.0, 1.0);
138 if (ctx
->Depth
.BoundsMin
== zmin
&& ctx
->Depth
.BoundsMax
== zmax
)
141 FLUSH_VERTICES(ctx
, _NEW_DEPTH
);
142 ctx
->Depth
.BoundsMin
= (GLfloat
) zmin
;
143 ctx
->Depth
.BoundsMax
= (GLfloat
) zmax
;
147 /**********************************************************************/
148 /***** Initialization *****/
149 /**********************************************************************/
153 * Initialize the depth buffer attribute group in the given context.
156 _mesa_init_depth(struct gl_context
*ctx
)
158 ctx
->Depth
.Test
= GL_FALSE
;
159 ctx
->Depth
.Clear
= 1.0;
160 ctx
->Depth
.Func
= GL_LESS
;
161 ctx
->Depth
.Mask
= GL_TRUE
;