compiler/glsl: explicitly store NumUniformBlocks
[mesa.git] / src / mesa / main / depth.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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.
23 */
24
25
26 #include "glheader.h"
27
28 #include "context.h"
29 #include "depth.h"
30 #include "enums.h"
31 #include "macros.h"
32 #include "mtypes.h"
33 #include "state.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 static ALWAYS_INLINE void
62 depth_func(struct gl_context *ctx, GLenum func, bool no_error)
63 {
64 if (ctx->Depth.Func == func)
65 return;
66
67 if (!no_error) {
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
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);
88
89 if (ctx->Driver.DepthFunc)
90 ctx->Driver.DepthFunc(ctx, func);
91 }
92
93
94 void GLAPIENTRY
95 _mesa_DepthFunc_no_error(GLenum func)
96 {
97 GET_CURRENT_CONTEXT(ctx);
98 depth_func(ctx, func, true);
99 }
100
101
102 void GLAPIENTRY
103 _mesa_DepthFunc(GLenum func)
104 {
105 GET_CURRENT_CONTEXT(ctx);
106
107 if (MESA_VERBOSE & VERBOSE_API)
108 _mesa_debug(ctx, "glDepthFunc %s\n", _mesa_enum_to_string(func));
109
110 depth_func(ctx, func, false);
111 }
112
113
114
115 void GLAPIENTRY
116 _mesa_DepthMask( GLboolean flag )
117 {
118 GET_CURRENT_CONTEXT(ctx);
119
120 if (MESA_VERBOSE & VERBOSE_API)
121 _mesa_debug(ctx, "glDepthMask %d\n", flag);
122
123 /*
124 * GL_TRUE indicates depth buffer writing is enabled (default)
125 * GL_FALSE indicates depth buffer writing is disabled
126 */
127 if (ctx->Depth.Mask == flag)
128 return;
129
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);
134
135 if (ctx->Driver.DepthMask)
136 ctx->Driver.DepthMask( ctx, flag );
137 }
138
139
140
141 /**
142 * Specified by the GL_EXT_depth_bounds_test extension.
143 */
144 void GLAPIENTRY
145 _mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
146 {
147 GET_CURRENT_CONTEXT(ctx);
148
149 if (MESA_VERBOSE & VERBOSE_API)
150 _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
151
152 if (zmin > zmax) {
153 _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
154 return;
155 }
156
157 zmin = CLAMP(zmin, 0.0, 1.0);
158 zmax = CLAMP(zmax, 0.0, 1.0);
159
160 if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
161 return;
162
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;
167 }
168
169
170 /**********************************************************************/
171 /***** Initialization *****/
172 /**********************************************************************/
173
174
175 /**
176 * Initialize the depth buffer attribute group in the given context.
177 */
178 void
179 _mesa_init_depth(struct gl_context *ctx)
180 {
181 ctx->Depth.Test = GL_FALSE;
182 ctx->Depth.Clear = 1.0;
183 ctx->Depth.Func = GL_LESS;
184 ctx->Depth.Mask = GL_TRUE;
185 }