1 /* $Id: stencil.c,v 1.27 2001/05/09 16:34:09 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
45 _mesa_ClearStencil( GLint s
)
47 GET_CURRENT_CONTEXT(ctx
);
48 ASSERT_OUTSIDE_BEGIN_END(ctx
);
50 if (ctx
->Stencil
.Clear
== (GLstencil
) s
)
53 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
54 ctx
->Stencil
.Clear
= (GLstencil
) s
;
56 if (ctx
->Driver
.ClearStencil
) {
57 (*ctx
->Driver
.ClearStencil
)( ctx
, s
);
64 _mesa_StencilFunc( GLenum func
, GLint ref
, GLuint mask
)
66 GET_CURRENT_CONTEXT(ctx
);
68 ASSERT_OUTSIDE_BEGIN_END(ctx
);
81 _mesa_error( ctx
, GL_INVALID_ENUM
, "glStencilFunc" );
85 maxref
= (1 << STENCIL_BITS
) - 1;
86 ref
= (GLstencil
) CLAMP( ref
, 0, maxref
);
88 if (ctx
->Stencil
.Function
== func
&&
89 ctx
->Stencil
.ValueMask
== (GLstencil
) mask
&&
90 ctx
->Stencil
.Ref
== ref
)
93 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
94 ctx
->Stencil
.Function
= func
;
95 ctx
->Stencil
.Ref
= ref
;
96 ctx
->Stencil
.ValueMask
= (GLstencil
) mask
;
98 if (ctx
->Driver
.StencilFunc
) {
99 (*ctx
->Driver
.StencilFunc
)( ctx
, func
, ctx
->Stencil
.Ref
, mask
);
106 _mesa_StencilMask( GLuint mask
)
108 GET_CURRENT_CONTEXT(ctx
);
109 ASSERT_OUTSIDE_BEGIN_END(ctx
);
111 if (ctx
->Stencil
.WriteMask
== (GLstencil
) mask
)
114 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
115 ctx
->Stencil
.WriteMask
= (GLstencil
) mask
;
117 if (ctx
->Driver
.StencilMask
) {
118 (*ctx
->Driver
.StencilMask
)( ctx
, mask
);
125 _mesa_StencilOp(GLenum fail
, GLenum zfail
, GLenum zpass
)
127 GET_CURRENT_CONTEXT(ctx
);
128 ASSERT_OUTSIDE_BEGIN_END(ctx
);
138 case GL_INCR_WRAP_EXT
:
139 case GL_DECR_WRAP_EXT
:
140 if (!ctx
->Extensions
.EXT_stencil_wrap
) {
145 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
156 case GL_INCR_WRAP_EXT
:
157 case GL_DECR_WRAP_EXT
:
158 if (ctx
->Extensions
.EXT_stencil_wrap
) {
163 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
174 case GL_INCR_WRAP_EXT
:
175 case GL_DECR_WRAP_EXT
:
176 if (ctx
->Extensions
.EXT_stencil_wrap
) {
181 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
185 if (ctx
->Stencil
.ZFailFunc
== zfail
&&
186 ctx
->Stencil
.ZPassFunc
== zpass
&&
187 ctx
->Stencil
.FailFunc
== fail
)
190 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
191 ctx
->Stencil
.ZFailFunc
= zfail
;
192 ctx
->Stencil
.ZPassFunc
= zpass
;
193 ctx
->Stencil
.FailFunc
= fail
;
195 if (ctx
->Driver
.StencilOp
) {
196 (*ctx
->Driver
.StencilOp
)(ctx
, fail
, zfail
, zpass
);