- Changes for new software rasterizer modules
[mesa.git] / src / mesa / main / depth.c
1 /* $Id: depth.c,v 1.23 2000/11/05 18:40:57 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "context.h"
33 #include "enums.h"
34 #include "depth.h"
35 #include "macros.h"
36 #include "mem.h"
37 #include "types.h"
38 #endif
39
40
41
42 /**********************************************************************/
43 /***** API Functions *****/
44 /**********************************************************************/
45
46
47
48 void
49 _mesa_ClearDepth( GLclampd depth )
50 {
51 GET_CURRENT_CONTEXT(ctx);
52 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glClearDepth");
53 ctx->Depth.Clear = (GLfloat) CLAMP( depth, 0.0, 1.0 );
54 if (ctx->Driver.ClearDepth)
55 (*ctx->Driver.ClearDepth)( ctx, ctx->Depth.Clear );
56 ctx->NewState |= _NEW_DEPTH;
57 }
58
59
60
61 void
62 _mesa_DepthFunc( GLenum func )
63 {
64 GET_CURRENT_CONTEXT(ctx);
65 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDepthFunc");
66
67 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
68 fprintf(stderr, "glDepthFunc %s\n", gl_lookup_enum_by_nr(func));
69
70 switch (func) {
71 case GL_LESS: /* (default) pass if incoming z < stored z */
72 case GL_GEQUAL:
73 case GL_LEQUAL:
74 case GL_GREATER:
75 case GL_NOTEQUAL:
76 case GL_EQUAL:
77 case GL_ALWAYS:
78 if (ctx->Depth.Func != func) {
79 ctx->Depth.Func = func;
80 ctx->NewState |= _NEW_DEPTH;
81 ctx->_TriangleCaps &= ~DD_Z_NEVER;
82 if (ctx->Driver.DepthFunc) {
83 (*ctx->Driver.DepthFunc)( ctx, func );
84 }
85 }
86 break;
87 case GL_NEVER:
88 if (ctx->Depth.Func != func) {
89 ctx->Depth.Func = func;
90 ctx->NewState |= _NEW_DEPTH;
91 ctx->_TriangleCaps |= DD_Z_NEVER;
92 if (ctx->Driver.DepthFunc) {
93 (*ctx->Driver.DepthFunc)( ctx, func );
94 }
95 }
96 break;
97 default:
98 gl_error( ctx, GL_INVALID_ENUM, "glDepth.Func" );
99 }
100 }
101
102
103
104 void
105 _mesa_DepthMask( GLboolean flag )
106 {
107 GET_CURRENT_CONTEXT(ctx);
108 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDepthMask");
109
110 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
111 fprintf(stderr, "glDepthMask %d\n", flag);
112
113 /*
114 * GL_TRUE indicates depth buffer writing is enabled (default)
115 * GL_FALSE indicates depth buffer writing is disabled
116 */
117 if (ctx->Depth.Mask != flag) {
118 ctx->Depth.Mask = flag;
119 ctx->NewState |= _NEW_DEPTH;
120 if (ctx->Driver.DepthMask) {
121 (*ctx->Driver.DepthMask)( ctx, flag );
122 }
123 }
124 }
125
126