1 /* $Id: stencil.c,v 1.23 2000/11/22 07:32:17 joukj Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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_AND_FLUSH(ctx
, "glClearStencil");
49 ctx
->Stencil
.Clear
= (GLstencil
) s
;
50 ctx
->NewState
|= _NEW_STENCIL
;
52 if (ctx
->Driver
.ClearStencil
) {
53 (*ctx
->Driver
.ClearStencil
)( ctx
, s
);
60 _mesa_StencilFunc( GLenum func
, GLint ref
, GLuint mask
)
62 GET_CURRENT_CONTEXT(ctx
);
65 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glStencilFunc");
76 ctx
->Stencil
.Function
= func
;
79 gl_error( ctx
, GL_INVALID_ENUM
, "glStencilFunc" );
83 maxref
= (1 << STENCIL_BITS
) - 1;
84 ctx
->Stencil
.Ref
= (GLstencil
) CLAMP( ref
, 0, maxref
);
85 ctx
->Stencil
.ValueMask
= (GLstencil
) mask
;
86 ctx
->NewState
|= _NEW_STENCIL
;
88 if (ctx
->Driver
.StencilFunc
) {
89 (*ctx
->Driver
.StencilFunc
)( ctx
, func
, ctx
->Stencil
.Ref
, mask
);
96 _mesa_StencilMask( GLuint mask
)
98 GET_CURRENT_CONTEXT(ctx
);
99 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glStencilMask");
100 ctx
->Stencil
.WriteMask
= (GLstencil
) mask
;
101 ctx
->NewState
|= _NEW_STENCIL
;
103 if (ctx
->Driver
.StencilMask
) {
104 (*ctx
->Driver
.StencilMask
)( ctx
, mask
);
111 _mesa_StencilOp(GLenum fail
, GLenum zfail
, GLenum zpass
)
113 GET_CURRENT_CONTEXT(ctx
);
114 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glStencilOp");
122 ctx
->Stencil
.FailFunc
= fail
;
124 case GL_INCR_WRAP_EXT
:
125 case GL_DECR_WRAP_EXT
:
126 if (ctx
->Extensions
.EXT_stencil_wrap
) {
127 ctx
->Stencil
.FailFunc
= fail
;
132 gl_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
142 ctx
->Stencil
.ZFailFunc
= zfail
;
144 case GL_INCR_WRAP_EXT
:
145 case GL_DECR_WRAP_EXT
:
146 if (ctx
->Extensions
.EXT_stencil_wrap
) {
147 ctx
->Stencil
.ZFailFunc
= zfail
;
152 gl_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
162 ctx
->Stencil
.ZPassFunc
= zpass
;
164 case GL_INCR_WRAP_EXT
:
165 case GL_DECR_WRAP_EXT
:
166 if (ctx
->Extensions
.EXT_stencil_wrap
) {
167 ctx
->Stencil
.ZPassFunc
= zpass
;
172 gl_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
176 ctx
->NewState
|= _NEW_STENCIL
;
178 if (ctx
->Driver
.StencilOp
) {
179 (*ctx
->Driver
.StencilOp
)(ctx
, fail
, zfail
, zpass
);