7 * Mesa 3-D graphics library
10 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 * Set the clear value for the stencil buffer.
44 * \param s clear value.
46 * \sa glClearStencil().
48 * Updates gl_stencil_attrib::Clear. On change
49 * flushes the vertices and notifies the driver via
50 * the dd_function_table::ClearStencil callback.
53 _mesa_ClearStencil( GLint s
)
55 GET_CURRENT_CONTEXT(ctx
);
56 ASSERT_OUTSIDE_BEGIN_END(ctx
);
58 if (ctx
->Stencil
.Clear
== (GLstencil
) s
)
61 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
62 ctx
->Stencil
.Clear
= (GLstencil
) s
;
64 if (ctx
->Driver
.ClearStencil
) {
65 (*ctx
->Driver
.ClearStencil
)( ctx
, s
);
71 * Set the function and reference value for stencil testing.
73 * \param func test function.
74 * \param ref reference value.
75 * \param mask bitmask.
77 * \sa glStencilFunc().
79 * Verifies the parameters and updates the respective values in
80 * __GLcontextRec::Stencil. On change flushes the vertices and notifies the
81 * driver via the dd_function_table::StencilFunc callback.
84 _mesa_StencilFunc( GLenum func
, GLint ref
, GLuint mask
)
86 GET_CURRENT_CONTEXT(ctx
);
87 const GLint face
= ctx
->Stencil
.ActiveFace
;
89 ASSERT_OUTSIDE_BEGIN_END(ctx
);
102 _mesa_error( ctx
, GL_INVALID_ENUM
, "glStencilFunc" );
106 maxref
= (1 << STENCIL_BITS
) - 1;
107 ref
= (GLstencil
) CLAMP( ref
, 0, maxref
);
109 if (ctx
->Stencil
.Function
[face
] == func
&&
110 ctx
->Stencil
.ValueMask
[face
] == (GLstencil
) mask
&&
111 ctx
->Stencil
.Ref
[face
] == ref
)
114 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
115 ctx
->Stencil
.Function
[face
] = func
;
116 ctx
->Stencil
.Ref
[face
] = ref
;
117 ctx
->Stencil
.ValueMask
[face
] = (GLstencil
) mask
;
119 if (ctx
->Driver
.StencilFunc
) {
120 (*ctx
->Driver
.StencilFunc
)( ctx
, func
, ref
, mask
);
126 * Set the stencil writing mask.
128 * \param mask bit-mask to enable/disable writing of individual bits in the
131 * \sa glStencilMask().
133 * Updates gl_stencil_attrib::WriteMask. On change flushes the vertices and
134 * notifies the driver via the dd_function_table::StencilMask callback.
137 _mesa_StencilMask( GLuint mask
)
139 GET_CURRENT_CONTEXT(ctx
);
140 const GLint face
= ctx
->Stencil
.ActiveFace
;
141 ASSERT_OUTSIDE_BEGIN_END(ctx
);
143 if (ctx
->Stencil
.WriteMask
[face
] == (GLstencil
) mask
)
146 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
147 ctx
->Stencil
.WriteMask
[face
] = (GLstencil
) mask
;
149 if (ctx
->Driver
.StencilMask
) {
150 (*ctx
->Driver
.StencilMask
)( ctx
, mask
);
156 * Set the stencil test actions.
158 * \param fail action to take when stencil test fails.
159 * \param zfail action to take when stencil test passes, but the depth test fails.
160 * \param zpass action to take when stencil test passes and the depth test
161 * passes (or depth testing is not enabled).
165 * Verifies the parameters and updates the respective fields in
166 * __GLcontextRec::Stencil. On change flushes the vertices and notifies the
167 * driver via the dd_function_table::StencilOp callback.
170 _mesa_StencilOp(GLenum fail
, GLenum zfail
, GLenum zpass
)
172 GET_CURRENT_CONTEXT(ctx
);
173 const GLint face
= ctx
->Stencil
.ActiveFace
;
174 ASSERT_OUTSIDE_BEGIN_END(ctx
);
184 case GL_INCR_WRAP_EXT
:
185 case GL_DECR_WRAP_EXT
:
186 if (ctx
->Extensions
.EXT_stencil_wrap
) {
191 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
202 case GL_INCR_WRAP_EXT
:
203 case GL_DECR_WRAP_EXT
:
204 if (ctx
->Extensions
.EXT_stencil_wrap
) {
209 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
220 case GL_INCR_WRAP_EXT
:
221 case GL_DECR_WRAP_EXT
:
222 if (ctx
->Extensions
.EXT_stencil_wrap
) {
227 _mesa_error(ctx
, GL_INVALID_ENUM
, "glStencilOp");
231 if (ctx
->Stencil
.ZFailFunc
[face
] == zfail
&&
232 ctx
->Stencil
.ZPassFunc
[face
] == zpass
&&
233 ctx
->Stencil
.FailFunc
[face
] == fail
)
236 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
237 ctx
->Stencil
.ZFailFunc
[face
] = zfail
;
238 ctx
->Stencil
.ZPassFunc
[face
] = zpass
;
239 ctx
->Stencil
.FailFunc
[face
] = fail
;
241 if (ctx
->Driver
.StencilOp
) {
242 (*ctx
->Driver
.StencilOp
)(ctx
, fail
, zfail
, zpass
);
248 /* GL_EXT_stencil_two_side */
250 _mesa_ActiveStencilFaceEXT(GLenum face
)
252 GET_CURRENT_CONTEXT(ctx
);
253 ASSERT_OUTSIDE_BEGIN_END(ctx
);
255 if (face
== GL_FRONT
|| face
== GL_BACK
) {
256 FLUSH_VERTICES(ctx
, _NEW_STENCIL
);
257 ctx
->Stencil
.ActiveFace
= (face
== GL_FRONT
) ? 0 : 1;
260 if (ctx
->Driver
.ActiveStencilFace
) {
261 (*ctx
->Driver
.ActiveStencilFace
)( ctx
, (GLuint
) ctx
->Stencil
.ActiveFace
);
268 * Initialize the context stipple state.
270 * \param ctx GL context.
272 * Initializes __GLcontextRec::Stencil attribute group.
274 void _mesa_init_stencil( GLcontext
* ctx
)
278 ctx
->Stencil
.Enabled
= GL_FALSE
;
279 ctx
->Stencil
.TestTwoSide
= GL_FALSE
;
280 ctx
->Stencil
.ActiveFace
= 0; /* 0 = GL_FRONT, 1 = GL_BACK */
281 ctx
->Stencil
.Function
[0] = GL_ALWAYS
;
282 ctx
->Stencil
.Function
[1] = GL_ALWAYS
;
283 ctx
->Stencil
.FailFunc
[0] = GL_KEEP
;
284 ctx
->Stencil
.FailFunc
[1] = GL_KEEP
;
285 ctx
->Stencil
.ZPassFunc
[0] = GL_KEEP
;
286 ctx
->Stencil
.ZPassFunc
[1] = GL_KEEP
;
287 ctx
->Stencil
.ZFailFunc
[0] = GL_KEEP
;
288 ctx
->Stencil
.ZFailFunc
[1] = GL_KEEP
;
289 ctx
->Stencil
.Ref
[0] = 0;
290 ctx
->Stencil
.Ref
[1] = 0;
291 ctx
->Stencil
.ValueMask
[0] = STENCIL_MAX
;
292 ctx
->Stencil
.ValueMask
[1] = STENCIL_MAX
;
293 ctx
->Stencil
.WriteMask
[0] = STENCIL_MAX
;
294 ctx
->Stencil
.WriteMask
[1] = STENCIL_MAX
;
295 ctx
->Stencil
.Clear
= 0;