fix void pointer arithmetic warnings
[mesa.git] / src / mesa / state_tracker / st_atom_alphatest.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 * Brian Paul
32 */
33
34
35 #include "st_context.h"
36 #include "st_cache.h"
37 #include "st_atom.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_defines.h"
40
41
42 /**
43 * Convert GLenum stencil func tokens to pipe tokens.
44 */
45 static GLuint
46 gl_alpha_func_to_sp(GLenum func)
47 {
48 /* Same values, just biased */
49 assert(PIPE_FUNC_NEVER == GL_NEVER - GL_NEVER);
50 assert(PIPE_FUNC_LESS == GL_LESS - GL_NEVER);
51 assert(PIPE_FUNC_EQUAL == GL_EQUAL - GL_NEVER);
52 assert(PIPE_FUNC_LEQUAL == GL_LEQUAL - GL_NEVER);
53 assert(PIPE_FUNC_GREATER == GL_GREATER - GL_NEVER);
54 assert(PIPE_FUNC_NOTEQUAL == GL_NOTEQUAL - GL_NEVER);
55 assert(PIPE_FUNC_GEQUAL == GL_GEQUAL - GL_NEVER);
56 assert(PIPE_FUNC_ALWAYS == GL_ALWAYS - GL_NEVER);
57 assert(func >= GL_NEVER);
58 assert(func <= GL_ALWAYS);
59 return func - GL_NEVER;
60 }
61
62
63 static void
64 update_alpha_test( struct st_context *st )
65 {
66 struct pipe_alpha_test_state alpha;
67 const struct cso_alpha_test *cso;
68
69 memset(&alpha, 0, sizeof(alpha));
70
71 if (st->ctx->Color.AlphaEnabled) {
72 alpha.enabled = 1;
73 alpha.func = gl_alpha_func_to_sp(st->ctx->Color.AlphaFunc);
74 alpha.ref = st->ctx->Color.AlphaRef;
75 }
76 cso = st_cached_alpha_test_state(st, &alpha);
77 if (st->state.alpha_test != cso) {
78 /* state has changed */
79 st->state.alpha_test = cso;
80 st->pipe->bind_alpha_test_state(st->pipe, cso->data); /* bind new state */
81 }
82 }
83
84
85 const struct st_tracked_state st_update_alpha_test = {
86 .name = "st_update_alpha_test",
87 .dirty = {
88 .mesa = (_NEW_COLOR),
89 .st = 0,
90 },
91 .update = update_alpha_test
92 };