mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / main / depth.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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 * THE AUTHORS 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.
23 */
24
25
26 #include "glheader.h"
27 #include "imports.h"
28 #include "context.h"
29 #include "depth.h"
30 #include "enums.h"
31 #include "macros.h"
32 #include "mtypes.h"
33
34
35 /**********************************************************************/
36 /***** API Functions *****/
37 /**********************************************************************/
38
39
40
41 void GLAPIENTRY
42 _mesa_ClearDepth( GLclampd depth )
43 {
44 GET_CURRENT_CONTEXT(ctx);
45
46 if (MESA_VERBOSE & VERBOSE_API)
47 _mesa_debug(ctx, "glClearDepth(%f)\n", depth);
48
49 ctx->Depth.Clear = CLAMP( depth, 0.0, 1.0 );
50 }
51
52
53 void GLAPIENTRY
54 _mesa_ClearDepthf( GLclampf depth )
55 {
56 _mesa_ClearDepth(depth);
57 }
58
59
60 void GLAPIENTRY
61 _mesa_DepthFunc( GLenum func )
62 {
63 GET_CURRENT_CONTEXT(ctx);
64
65 if (MESA_VERBOSE & VERBOSE_API)
66 _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func));
67
68 switch (func) {
69 case GL_LESS: /* (default) pass if incoming z < stored z */
70 case GL_GEQUAL:
71 case GL_LEQUAL:
72 case GL_GREATER:
73 case GL_NOTEQUAL:
74 case GL_EQUAL:
75 case GL_ALWAYS:
76 case GL_NEVER:
77 break;
78 default:
79 _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" );
80 return;
81 }
82
83 if (ctx->Depth.Func == func)
84 return;
85
86 FLUSH_VERTICES(ctx, _NEW_DEPTH);
87 ctx->Depth.Func = func;
88
89 if (ctx->Driver.DepthFunc)
90 ctx->Driver.DepthFunc( ctx, func );
91 }
92
93
94
95 void GLAPIENTRY
96 _mesa_DepthMask( GLboolean flag )
97 {
98 GET_CURRENT_CONTEXT(ctx);
99
100 if (MESA_VERBOSE & VERBOSE_API)
101 _mesa_debug(ctx, "glDepthMask %d\n", flag);
102
103 /*
104 * GL_TRUE indicates depth buffer writing is enabled (default)
105 * GL_FALSE indicates depth buffer writing is disabled
106 */
107 if (ctx->Depth.Mask == flag)
108 return;
109
110 FLUSH_VERTICES(ctx, _NEW_DEPTH);
111 ctx->Depth.Mask = flag;
112
113 if (ctx->Driver.DepthMask)
114 ctx->Driver.DepthMask( ctx, flag );
115 }
116
117
118
119 /**
120 * Specified by the GL_EXT_depth_bounds_test extension.
121 */
122 void GLAPIENTRY
123 _mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
124 {
125 GET_CURRENT_CONTEXT(ctx);
126
127 if (MESA_VERBOSE & VERBOSE_API)
128 _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
129
130 if (zmin > zmax) {
131 _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
132 return;
133 }
134
135 zmin = CLAMP(zmin, 0.0, 1.0);
136 zmax = CLAMP(zmax, 0.0, 1.0);
137
138 if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
139 return;
140
141 FLUSH_VERTICES(ctx, _NEW_DEPTH);
142 ctx->Depth.BoundsMin = (GLfloat) zmin;
143 ctx->Depth.BoundsMax = (GLfloat) zmax;
144 }
145
146
147 /**********************************************************************/
148 /***** Initialization *****/
149 /**********************************************************************/
150
151
152 /**
153 * Initialize the depth buffer attribute group in the given context.
154 */
155 void
156 _mesa_init_depth(struct gl_context *ctx)
157 {
158 ctx->Depth.Test = GL_FALSE;
159 ctx->Depth.Clear = 1.0;
160 ctx->Depth.Func = GL_LESS;
161 ctx->Depth.Mask = GL_TRUE;
162 }