g3dvl: Get rid of state tracker unit tests, stale and not useful atm.
[mesa.git] / src / gallium / state_trackers / g3dvl / vl_context.c
1 #define VL_INTERNAL
2 #include "vl_context.h"
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <pipe/p_context.h>
6 #include <pipe/p_state.h>
7 #include "vl_render.h"
8 #include "vl_r16snorm_mc.h"
9 #include "vl_r16snorm_mc_buf.h"
10 #include "vl_csc.h"
11 #include "vl_basic_csc.h"
12
13 static int vlInitCommon(struct vlContext *context)
14 {
15 struct pipe_context *pipe;
16 struct pipe_rasterizer_state rast;
17 struct pipe_blend_state blend;
18 struct pipe_depth_stencil_alpha_state dsa;
19 unsigned int i;
20
21 assert(context);
22
23 pipe = context->pipe;
24
25 rast.flatshade = 1;
26 rast.flatshade_first = 0;
27 rast.light_twoside = 0;
28 rast.front_winding = PIPE_WINDING_CCW;
29 rast.cull_mode = PIPE_WINDING_CW;
30 rast.fill_cw = PIPE_POLYGON_MODE_FILL;
31 rast.fill_ccw = PIPE_POLYGON_MODE_FILL;
32 rast.offset_cw = 0;
33 rast.offset_ccw = 0;
34 rast.scissor = 0;
35 rast.poly_smooth = 0;
36 rast.poly_stipple_enable = 0;
37 rast.point_sprite = 0;
38 rast.point_size_per_vertex = 0;
39 rast.multisample = 0;
40 rast.line_smooth = 0;
41 rast.line_stipple_enable = 0;
42 rast.line_stipple_factor = 0;
43 rast.line_stipple_pattern = 0;
44 rast.line_last_pixel = 0;
45 /* Don't need clipping, but viewport mapping done here */
46 rast.bypass_clipping = 0;
47 rast.bypass_vs = 0;
48 rast.origin_lower_left = 0;
49 rast.line_width = 1;
50 rast.point_smooth = 0;
51 rast.point_size = 1;
52 rast.offset_units = 1;
53 rast.offset_scale = 1;
54 /*rast.sprite_coord_mode[i] = ;*/
55 context->raster = pipe->create_rasterizer_state(pipe, &rast);
56 pipe->bind_rasterizer_state(pipe, context->raster);
57
58 blend.blend_enable = 0;
59 blend.rgb_func = PIPE_BLEND_ADD;
60 blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
61 blend.rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
62 blend.alpha_func = PIPE_BLEND_ADD;
63 blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
64 blend.alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
65 blend.logicop_enable = 0;
66 blend.logicop_func = PIPE_LOGICOP_CLEAR;
67 /* Needed to allow color writes to FB, even if blending disabled */
68 blend.colormask = PIPE_MASK_RGBA;
69 blend.dither = 0;
70 context->blend = pipe->create_blend_state(pipe, &blend);
71 pipe->bind_blend_state(pipe, context->blend);
72
73 dsa.depth.enabled = 0;
74 dsa.depth.writemask = 0;
75 dsa.depth.func = PIPE_FUNC_ALWAYS;
76 dsa.depth.occlusion_count = 0;
77 for (i = 0; i < 2; ++i)
78 {
79 dsa.stencil[i].enabled = 0;
80 dsa.stencil[i].func = PIPE_FUNC_ALWAYS;
81 dsa.stencil[i].fail_op = PIPE_STENCIL_OP_KEEP;
82 dsa.stencil[i].zpass_op = PIPE_STENCIL_OP_KEEP;
83 dsa.stencil[i].zfail_op = PIPE_STENCIL_OP_KEEP;
84 dsa.stencil[i].ref_value = 0;
85 dsa.stencil[i].value_mask = 0;
86 dsa.stencil[i].write_mask = 0;
87 }
88 dsa.alpha.enabled = 0;
89 dsa.alpha.func = PIPE_FUNC_ALWAYS;
90 dsa.alpha.ref = 0;
91 context->dsa = pipe->create_depth_stencil_alpha_state(pipe, &dsa);
92 pipe->bind_depth_stencil_alpha_state(pipe, context->dsa);
93
94 return 0;
95 }
96
97 int vlCreateContext
98 (
99 struct vlScreen *screen,
100 struct pipe_context *pipe,
101 unsigned int picture_width,
102 unsigned int picture_height,
103 enum vlFormat picture_format,
104 enum vlProfile profile,
105 enum vlEntryPoint entry_point,
106 struct vlContext **context
107 )
108 {
109 struct vlContext *ctx;
110
111 assert(screen);
112 assert(context);
113 assert(pipe);
114
115 ctx = calloc(1, sizeof(struct vlContext));
116
117 if (!ctx)
118 return 1;
119
120 ctx->screen = screen;
121 ctx->pipe = pipe;
122 ctx->picture_width = picture_width;
123 ctx->picture_height = picture_height;
124 ctx->picture_format = picture_format;
125 ctx->profile = profile;
126 ctx->entry_point = entry_point;
127
128 vlInitCommon(ctx);
129
130 /*vlCreateR16SNormMC(pipe, picture_width, picture_height, picture_format, &ctx->render);*/
131 vlCreateR16SNormBufferedMC(pipe, picture_width, picture_height, picture_format, &ctx->render);
132 vlCreateBasicCSC(pipe, &ctx->csc);
133
134 *context = ctx;
135
136 return 0;
137 }
138
139 int vlDestroyContext
140 (
141 struct vlContext *context
142 )
143 {
144 assert(context);
145
146 /* XXX: Must unbind shaders before we can delete them for some reason */
147 context->pipe->bind_vs_state(context->pipe, NULL);
148 context->pipe->bind_fs_state(context->pipe, NULL);
149
150 context->render->vlDestroy(context->render);
151 context->csc->vlDestroy(context->csc);
152
153 context->pipe->delete_blend_state(context->pipe, context->blend);
154 context->pipe->delete_rasterizer_state(context->pipe, context->raster);
155 context->pipe->delete_depth_stencil_alpha_state(context->pipe, context->dsa);
156
157 free(context);
158
159 return 0;
160 }
161
162 struct vlScreen* vlContextGetScreen
163 (
164 struct vlContext *context
165 )
166 {
167 assert(context);
168
169 return context->screen;
170 }
171
172 struct pipe_context* vlGetPipeContext
173 (
174 struct vlContext *context
175 )
176 {
177 assert(context);
178
179 return context->pipe;
180 }
181
182 unsigned int vlGetPictureWidth
183 (
184 struct vlContext *context
185 )
186 {
187 assert(context);
188
189 return context->picture_width;
190 }
191
192 unsigned int vlGetPictureHeight
193 (
194 struct vlContext *context
195 )
196 {
197 assert(context);
198
199 return context->picture_height;
200 }
201
202 enum vlFormat vlGetPictureFormat
203 (
204 struct vlContext *context
205 )
206 {
207 assert(context);
208
209 return context->picture_format;
210 }