Merge branch 'gles2-2'
[mesa.git] / src / gallium / drivers / llvmpipe / lp_state_blend.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 /**
30 * @author Jose Fonseca <jfonseca@vmware.com>
31 * @author Keith Whitwell <keith@tungstengraphics.com>
32 */
33
34 #include "util/u_memory.h"
35 #include "util/u_math.h"
36 #include "util/u_dump.h"
37 #include "draw/draw_context.h"
38 #include "lp_screen.h"
39 #include "lp_context.h"
40 #include "lp_state.h"
41
42
43 static void *
44 llvmpipe_create_blend_state(struct pipe_context *pipe,
45 const struct pipe_blend_state *blend)
46 {
47 return mem_dup(blend, sizeof(*blend));
48 }
49
50
51 static void
52 llvmpipe_bind_blend_state(struct pipe_context *pipe, void *blend)
53 {
54 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
55
56 if (llvmpipe->blend == blend)
57 return;
58
59 draw_flush(llvmpipe->draw);
60
61 llvmpipe->blend = blend;
62
63 llvmpipe->dirty |= LP_NEW_BLEND;
64 }
65
66
67 static void
68 llvmpipe_delete_blend_state(struct pipe_context *pipe, void *blend)
69 {
70 FREE( blend );
71 }
72
73
74 static void
75 llvmpipe_set_blend_color(struct pipe_context *pipe,
76 const struct pipe_blend_color *blend_color)
77 {
78 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
79
80 if(!blend_color)
81 return;
82
83 if(memcmp(&llvmpipe->blend_color, blend_color, sizeof *blend_color) == 0)
84 return;
85
86 draw_flush(llvmpipe->draw);
87
88 memcpy(&llvmpipe->blend_color, blend_color, sizeof *blend_color);
89
90 llvmpipe->dirty |= LP_NEW_BLEND_COLOR;
91 }
92
93
94 /** XXX move someday? Or consolidate all these simple state setters
95 * into one file.
96 */
97
98
99 static void *
100 llvmpipe_create_depth_stencil_state(struct pipe_context *pipe,
101 const struct pipe_depth_stencil_alpha_state *depth_stencil)
102 {
103 return mem_dup(depth_stencil, sizeof(*depth_stencil));
104 }
105
106
107 static void
108 llvmpipe_bind_depth_stencil_state(struct pipe_context *pipe,
109 void *depth_stencil)
110 {
111 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
112
113 if (llvmpipe->depth_stencil == depth_stencil)
114 return;
115
116 draw_flush(llvmpipe->draw);
117
118 llvmpipe->depth_stencil = depth_stencil;
119
120 llvmpipe->dirty |= LP_NEW_DEPTH_STENCIL_ALPHA;
121 }
122
123
124 static void
125 llvmpipe_delete_depth_stencil_state(struct pipe_context *pipe, void *depth)
126 {
127 FREE( depth );
128 }
129
130
131 static void
132 llvmpipe_set_stencil_ref(struct pipe_context *pipe,
133 const struct pipe_stencil_ref *stencil_ref)
134 {
135 struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
136
137 if(!stencil_ref)
138 return;
139
140 if(memcmp(&llvmpipe->stencil_ref, stencil_ref, sizeof *stencil_ref) == 0)
141 return;
142
143 draw_flush(llvmpipe->draw);
144
145 memcpy(&llvmpipe->stencil_ref, stencil_ref, sizeof *stencil_ref);
146
147 /* not sure. want new flag? */
148 llvmpipe->dirty |= LP_NEW_DEPTH_STENCIL_ALPHA;
149 }
150
151
152 void
153 llvmpipe_init_blend_funcs(struct llvmpipe_context *llvmpipe)
154 {
155 llvmpipe->pipe.create_blend_state = llvmpipe_create_blend_state;
156 llvmpipe->pipe.bind_blend_state = llvmpipe_bind_blend_state;
157 llvmpipe->pipe.delete_blend_state = llvmpipe_delete_blend_state;
158
159 llvmpipe->pipe.create_depth_stencil_alpha_state = llvmpipe_create_depth_stencil_state;
160 llvmpipe->pipe.bind_depth_stencil_alpha_state = llvmpipe_bind_depth_stencil_state;
161 llvmpipe->pipe.delete_depth_stencil_alpha_state = llvmpipe_delete_depth_stencil_state;
162
163 llvmpipe->pipe.set_blend_color = llvmpipe_set_blend_color;
164
165 llvmpipe->pipe.set_stencil_ref = llvmpipe_set_stencil_ref;
166 }