softpipe: fix texture view crashes
[mesa.git] / src / gallium / drivers / softpipe / sp_state_blend.c
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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 /* Authors: Keith Whitwell <keithw@vmware.com>
29 */
30
31 #include "util/u_math.h"
32 #include "util/u_memory.h"
33 #include "draw/draw_context.h"
34 #include "sp_context.h"
35 #include "sp_state.h"
36
37
38 static void *
39 softpipe_create_blend_state(struct pipe_context *pipe,
40 const struct pipe_blend_state *blend)
41 {
42 return mem_dup(blend, sizeof(*blend));
43 }
44
45
46 static void
47 softpipe_bind_blend_state(struct pipe_context *pipe,
48 void *blend)
49 {
50 struct softpipe_context *softpipe = softpipe_context(pipe);
51
52 draw_flush(softpipe->draw);
53
54 softpipe->blend = (struct pipe_blend_state *)blend;
55
56 softpipe->dirty |= SP_NEW_BLEND;
57 }
58
59
60 static void
61 softpipe_delete_blend_state(struct pipe_context *pipe,
62 void *blend)
63 {
64 FREE( blend );
65 }
66
67
68 static void
69 softpipe_set_blend_color(struct pipe_context *pipe,
70 const struct pipe_blend_color *blend_color)
71 {
72 struct softpipe_context *softpipe = softpipe_context(pipe);
73 unsigned i;
74
75 draw_flush(softpipe->draw);
76
77 softpipe->blend_color = *blend_color;
78
79 /* save clamped color too */
80 for (i = 0; i < 4; i++)
81 softpipe->blend_color_clamped.color[i] =
82 CLAMP(blend_color->color[i], 0.0f, 1.0f);
83
84 softpipe->dirty |= SP_NEW_BLEND;
85 }
86
87
88 static void *
89 softpipe_create_depth_stencil_state(struct pipe_context *pipe,
90 const struct pipe_depth_stencil_alpha_state *depth_stencil)
91 {
92 return mem_dup(depth_stencil, sizeof(*depth_stencil));
93 }
94
95
96 static void
97 softpipe_bind_depth_stencil_state(struct pipe_context *pipe,
98 void *depth_stencil)
99 {
100 struct softpipe_context *softpipe = softpipe_context(pipe);
101
102 softpipe->depth_stencil = (struct pipe_depth_stencil_alpha_state *)depth_stencil;
103
104 softpipe->dirty |= SP_NEW_DEPTH_STENCIL_ALPHA;
105 }
106
107
108 static void
109 softpipe_delete_depth_stencil_state(struct pipe_context *pipe, void *depth)
110 {
111 FREE( depth );
112 }
113
114
115 static void
116 softpipe_set_stencil_ref(struct pipe_context *pipe,
117 const struct pipe_stencil_ref *stencil_ref)
118 {
119 struct softpipe_context *softpipe = softpipe_context(pipe);
120
121 softpipe->stencil_ref = *stencil_ref;
122
123 softpipe->dirty |= SP_NEW_DEPTH_STENCIL_ALPHA;
124 }
125
126
127 static void
128 softpipe_set_sample_mask(struct pipe_context *pipe,
129 unsigned sample_mask)
130 {
131 }
132
133
134 void
135 softpipe_init_blend_funcs(struct pipe_context *pipe)
136 {
137 pipe->create_blend_state = softpipe_create_blend_state;
138 pipe->bind_blend_state = softpipe_bind_blend_state;
139 pipe->delete_blend_state = softpipe_delete_blend_state;
140
141 pipe->set_blend_color = softpipe_set_blend_color;
142
143 pipe->create_depth_stencil_alpha_state = softpipe_create_depth_stencil_state;
144 pipe->bind_depth_stencil_alpha_state = softpipe_bind_depth_stencil_state;
145 pipe->delete_depth_stencil_alpha_state = softpipe_delete_depth_stencil_state;
146
147 pipe->set_stencil_ref = softpipe_set_stencil_ref;
148
149 pipe->set_sample_mask = softpipe_set_sample_mask;
150 }