mesa: don't flag _NEW_DEPTH for st/mesa
[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 #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_enum_to_string(func));
67
68 if (ctx->Depth.Func == func)
69 return;
70
71 switch (func) {
72 case GL_LESS: /* (default) pass if incoming z < stored z */
73 case GL_GEQUAL:
74 case GL_LEQUAL:
75 case GL_GREATER:
76 case GL_NOTEQUAL:
77 case GL_EQUAL:
78 case GL_ALWAYS:
79 case GL_NEVER:
80 break;
81 default:
82 _mesa_error( ctx, GL_INVALID_ENUM, "glDepth.Func" );
83 return;
84 }
85
86 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
87 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
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, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
112 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
113 ctx->Depth.Mask = flag;
114
115 if (ctx->Driver.DepthMask)
116 ctx->Driver.DepthMask( ctx, flag );
117 }
118
119
120
121 /**
122 * Specified by the GL_EXT_depth_bounds_test extension.
123 */
124 void GLAPIENTRY
125 _mesa_DepthBoundsEXT( GLclampd zmin, GLclampd zmax )
126 {
127 GET_CURRENT_CONTEXT(ctx);
128
129 if (MESA_VERBOSE & VERBOSE_API)
130 _mesa_debug(ctx, "glDepthBounds(%f, %f)\n", zmin, zmax);
131
132 if (zmin > zmax) {
133 _mesa_error(ctx, GL_INVALID_VALUE, "glDepthBoundsEXT(zmin > zmax)");
134 return;
135 }
136
137 zmin = CLAMP(zmin, 0.0, 1.0);
138 zmax = CLAMP(zmax, 0.0, 1.0);
139
140 if (ctx->Depth.BoundsMin == zmin && ctx->Depth.BoundsMax == zmax)
141 return;
142
143 FLUSH_VERTICES(ctx, ctx->DriverFlags.NewDepth ? 0 : _NEW_DEPTH);
144 ctx->NewDriverState |= ctx->DriverFlags.NewDepth;
145 ctx->Depth.BoundsMin = (GLfloat) zmin;
146 ctx->Depth.BoundsMax = (GLfloat) zmax;
147 }
148
149
150 /**********************************************************************/
151 /***** Initialization *****/
152 /**********************************************************************/
153
154
155 /**
156 * Initialize the depth buffer attribute group in the given context.
157 */
158 void
159 _mesa_init_depth(struct gl_context *ctx)
160 {
161 ctx->Depth.Test = GL_FALSE;
162 ctx->Depth.Clear = 1.0;
163 ctx->Depth.Func = GL_LESS;
164 ctx->Depth.Mask = GL_TRUE;
165 }