i965: Move FS instruction scheduling to a non-FS-specific file.
[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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #include "glheader.h"
28 #include "imports.h"
29 #include "context.h"
30 #include "depth.h"
31 #include "enums.h"
32 #include "macros.h"
33 #include "mtypes.h"
34
35
36 /**********************************************************************/
37 /***** API Functions *****/
38 /**********************************************************************/
39
40
41
42 void GLAPIENTRY
43 _mesa_ClearDepth( GLclampd depth )
44 {
45 GET_CURRENT_CONTEXT(ctx);
46
47 if (MESA_VERBOSE & VERBOSE_API)
48 _mesa_debug(ctx, "glClearDepth(%f)\n", depth);
49
50 ctx->Depth.Clear = CLAMP( depth, 0.0, 1.0 );
51 }
52
53
54 void GLAPIENTRY
55 _mesa_ClearDepthf( GLclampf depth )
56 {
57 _mesa_ClearDepth(depth);
58 }
59
60
61 void GLAPIENTRY
62 _mesa_DepthFunc( GLenum func )
63 {
64 GET_CURRENT_CONTEXT(ctx);
65
66 if (MESA_VERBOSE & VERBOSE_API)
67 _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_lookup_enum_by_nr(func));
68
69 switch (func) {
70 case GL_LESS: /* (default) pass if incoming z < stored z */
71 case GL_GEQUAL:
72 case GL_LEQUAL:
73 case GL_GREATER:
74 case GL_NOTEQUAL:
75 case GL_EQUAL:
76 case GL_ALWAYS:
77 case GL_NEVER:
78 break;
79 default:
80 _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" );
81 return;
82 }
83
84 if (ctx->Depth.Func == func)
85 return;
86
87 FLUSH_VERTICES(ctx, _NEW_DEPTH);
88 ctx->Depth.Func = func;
89
90 if (ctx->Driver.DepthFunc)
91 ctx->Driver.DepthFunc( ctx, func );
92 }
93
94
95
96 void GLAPIENTRY
97 _mesa_DepthMask( GLboolean flag )
98 {
99 GET_CURRENT_CONTEXT(ctx);
100
101 if (MESA_VERBOSE & VERBOSE_API)
102 _mesa_debug(ctx, "glDepthMask %d\n", flag);
103
104 /*
105 * GL_TRUE indicates depth buffer writing is enabled (default)
106 * GL_FALSE indicates depth buffer writing is disabled
107 */
108 if (ctx->Depth.Mask == flag)
109 return;
110
111 FLUSH_VERTICES(ctx, _NEW_DEPTH);
112 ctx->Depth.Mask = flag;
113
114 if (ctx->Driver.DepthMask)
115 ctx->Driver.DepthMask( ctx, flag );
116 }
117
118
119
120 /**
121 * Specified by the GL_EXT_depth_bounds_test extension.
122 */
123 void GLAPIENTRY
124 _mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
125 {
126 GET_CURRENT_CONTEXT(ctx);
127
128 if (MESA_VERBOSE & VERBOSE_API)
129 _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
130
131 if (zmin > zmax) {
132 _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
133 return;
134 }
135
136 zmin = CLAMP(zmin, 0.0, 1.0);
137 zmax = CLAMP(zmax, 0.0, 1.0);
138
139 if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
140 return;
141
142 FLUSH_VERTICES(ctx, _NEW_DEPTH);
143 ctx->Depth.BoundsMin = (GLfloat) zmin;
144 ctx->Depth.BoundsMax = (GLfloat) zmax;
145 }
146
147
148 /**********************************************************************/
149 /***** Initialization *****/
150 /**********************************************************************/
151
152
153 /**
154 * Initialize the depth buffer attribute group in the given context.
155 */
156 void
157 _mesa_init_depth(struct gl_context *ctx)
158 {
159 ctx->Depth.Test = GL_FALSE;
160 ctx->Depth.Clear = 1.0;
161 ctx->Depth.Func = GL_LESS;
162 ctx->Depth.Mask = GL_TRUE;
163 }