3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 _mesa_ClearStencil( GLint s
)
40 GET_CURRENT_CONTEXT(ctx
);
41 ASSERT_OUTSIDE_BEGIN_END(ctx
);
43 if (ctx
->Stencil
.Clear
== (GLstencil
) s
)
46 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
47 ctx
->Stencil
.Clear
= (GLstencil
) s
;
49 if (ctx
->Driver
.ClearStencil
) {
50 (*ctx
->Driver
.ClearStencil
)( ctx
, s
);
57 _mesa_StencilFunc( GLenum func
, GLint ref
, GLuint mask
)
59 GET_CURRENT_CONTEXT(ctx
);
60 const GLint face
= ctx
->Stencil
.ActiveFace
;
62 ASSERT_OUTSIDE_BEGIN_END(ctx
);
75 _mesa_error( ctx
, GL_INVALID_ENUM
, "glStencilFunc" );
79 maxref
= (1 << STENCIL_BITS
) - 1;
80 ref
= (GLstencil
) CLAMP( ref
, 0, maxref
);
82 if (ctx
->Stencil
.Function
[face
] == func
&&
83 ctx
->Stencil
.ValueMask
[face
] == (GLstencil
) mask
&&
84 ctx
->Stencil
.Ref
[face
] == ref
)
87 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
88 ctx
->Stencil
.Function
[face
] = func
;
89 ctx
->Stencil
.Ref
[face
] = ref
;
90 ctx
->Stencil
.ValueMask
[face
] = (GLstencil
) mask
;
92 if (ctx
->Driver
.StencilFunc
) {
93 (*ctx
->Driver
.StencilFunc
)( ctx
, func
, ref
, mask
);
100 _mesa_StencilMask( GLuint mask
)
102 GET_CURRENT_CONTEXT(ctx
);
103 const GLint face
= ctx
->Stencil
.ActiveFace
;
104 ASSERT_OUTSIDE_BEGIN_END(ctx
);
106 if (ctx
->Stencil
.WriteMask
[face
] == (GLstencil
) mask
)
109 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
110 ctx
->Stencil
.WriteMask
[face
] = (GLstencil
) mask
;
112 if (ctx
->Driver
.StencilMask
) {
113 (*ctx
->Driver
.StencilMask
)( ctx
, mask
);
120 _mesa_StencilOp(GLenum fail
, GLenum zfail
, GLenum zpass
)
122 GET_CURRENT_CONTEXT(ctx
);
123 const GLint face
= ctx
->Stencil
.ActiveFace
;
124 ASSERT_OUTSIDE_BEGIN_END(ctx
);
134 case GL_INCR_WRAP_EXT
:
135 case GL_DECR_WRAP_EXT
:
136 if (ctx
->Extensions
.EXT_stencil_wrap
) {
141 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
152 case GL_INCR_WRAP_EXT
:
153 case GL_DECR_WRAP_EXT
:
154 if (ctx
->Extensions
.EXT_stencil_wrap
) {
159 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
170 case GL_INCR_WRAP_EXT
:
171 case GL_DECR_WRAP_EXT
:
172 if (ctx
->Extensions
.EXT_stencil_wrap
) {
177 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
181 if (ctx
->Stencil
.ZFailFunc
[face
] == zfail
&&
182 ctx
->Stencil
.ZPassFunc
[face
] == zpass
&&
183 ctx
->Stencil
.FailFunc
[face
] == fail
)
186 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
187 ctx
->Stencil
.ZFailFunc
[face
] = zfail
;
188 ctx
->Stencil
.ZPassFunc
[face
] = zpass
;
189 ctx
->Stencil
.FailFunc
[face
] = fail
;
191 if (ctx
->Driver
.StencilOp
) {
192 (*ctx
->Driver
.StencilOp
)(ctx
, fail
, zfail
, zpass
);
197 /* GL_EXT_stencil_two_side */
199 _mesa_ActiveStencilFaceEXT(GLenum face
)
201 GET_CURRENT_CONTEXT(ctx
);
202 ASSERT_OUTSIDE_BEGIN_END(ctx
);
204 if (face
== GL_FRONT
|| face
== GL_BACK
) {
205 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
206 ctx
->Stencil
.ActiveFace
= (face
== GL_FRONT
) ? 0 : 1;
209 if (ctx
->Driver
.ActiveStencilFace
) {
210 (*ctx
->Driver
.ActiveStencilFace
)( ctx
, (GLuint
) ctx
->Stencil
.ActiveFace
);