Lines Matching refs:p

89 static void init_prog(struct program *p)  in init_prog()  argument
95 ret = pipe_loader_probe(&p->dev, 1); in init_prog()
99 p->screen = pipe_loader_create_screen(p->dev, PIPE_SEARCH_DIR); in init_prog()
100 assert(p->screen); in init_prog()
103 p->pipe = p->screen->context_create(p->screen, NULL); in init_prog()
104 p->cso = cso_create_context(p->pipe); in init_prog()
107 p->clear_color.f[0] = 0.3; in init_prog()
108 p->clear_color.f[1] = 0.1; in init_prog()
109 p->clear_color.f[2] = 0.3; in init_prog()
110 p->clear_color.f[3] = 1.0; in init_prog()
133 p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER, in init_prog()
135 pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices); in init_prog()
151 p->target = p->screen->resource_create(p->screen, &tmplt); in init_prog()
172 p->tex = p->screen->resource_create(p->screen, &t_tmplt); in init_prog()
178 t = p->pipe->get_transfer(p->pipe, p->tex, 0, PIPE_TRANSFER_WRITE, &box); in init_prog()
180 ptr = p->pipe->transfer_map(p->pipe, t); in init_prog()
185 p->pipe->transfer_unmap(p->pipe, t); in init_prog()
187 p->pipe->transfer_destroy(p->pipe, t); in init_prog()
189 u_sampler_view_default_template(&v_tmplt, p->tex, p->tex->format); in init_prog()
191 p->view = p->pipe->create_sampler_view(p->pipe, p->tex, &v_tmplt); in init_prog()
195 memset(&p->blend, 0, sizeof(p->blend)); in init_prog()
196 p->blend.rt[0].colormask = PIPE_MASK_RGBA; in init_prog()
199 memset(&p->depthstencil, 0, sizeof(p->depthstencil)); in init_prog()
202 memset(&p->rasterizer, 0, sizeof(p->rasterizer)); in init_prog()
203 p->rasterizer.cull_face = PIPE_FACE_NONE; in init_prog()
204 p->rasterizer.gl_rasterization_rules = 1; in init_prog()
205 p->rasterizer.depth_clip = 1; in init_prog()
208 memset(&p->sampler, 0, sizeof(p->sampler)); in init_prog()
209 p->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; in init_prog()
210 p->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; in init_prog()
211 p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; in init_prog()
212 p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; in init_prog()
213 p->sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR; in init_prog()
214 p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR; in init_prog()
215 p->sampler.normalized_coords = 1; in init_prog()
223 memset(&p->framebuffer, 0, sizeof(p->framebuffer)); in init_prog()
224 p->framebuffer.width = WIDTH; in init_prog()
225 p->framebuffer.height = HEIGHT; in init_prog()
226 p->framebuffer.nr_cbufs = 1; in init_prog()
227 p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl); in init_prog()
247 p->viewport.scale[0] = half_width; in init_prog()
248 p->viewport.scale[1] = half_height * scale; in init_prog()
249 p->viewport.scale[2] = half_depth; in init_prog()
250 p->viewport.scale[3] = 1.0f; in init_prog()
252 p->viewport.translate[0] = half_width + x; in init_prog()
253 p->viewport.translate[1] = (half_height + y) * scale + bias; in init_prog()
254 p->viewport.translate[2] = half_depth + z; in init_prog()
255 p->viewport.translate[3] = 0.0f; in init_prog()
259 memset(p->velem, 0, sizeof(p->velem)); in init_prog()
260 p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */ in init_prog()
261 p->velem[0].instance_divisor = 0; in init_prog()
262 p->velem[0].vertex_buffer_index = 0; in init_prog()
263 p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; in init_prog()
265 p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */ in init_prog()
266 p->velem[1].instance_divisor = 0; in init_prog()
267 p->velem[1].vertex_buffer_index = 0; in init_prog()
268 p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; in init_prog()
275 p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes); in init_prog()
279 p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D, TGSI_INTERPOLATE_LINEAR); in init_prog()
282 static void close_prog(struct program *p) in close_prog() argument
285 cso_set_sampler_views(p->cso, PIPE_SHADER_FRAGMENT, 0, NULL); in close_prog()
288 cso_release_all(p->cso); in close_prog()
290 p->pipe->delete_vs_state(p->pipe, p->vs); in close_prog()
291 p->pipe->delete_fs_state(p->pipe, p->fs); in close_prog()
293 pipe_surface_reference(&p->framebuffer.cbufs[0], NULL); in close_prog()
294 pipe_sampler_view_reference(&p->view, NULL); in close_prog()
295 pipe_resource_reference(&p->target, NULL); in close_prog()
296 pipe_resource_reference(&p->tex, NULL); in close_prog()
297 pipe_resource_reference(&p->vbuf, NULL); in close_prog()
299 cso_destroy_context(p->cso); in close_prog()
300 p->pipe->destroy(p->pipe); in close_prog()
301 p->screen->destroy(p->screen); in close_prog()
302 pipe_loader_release(&p->dev, 1); in close_prog()
304 FREE(p); in close_prog()
307 static void draw(struct program *p) in draw() argument
310 cso_set_framebuffer(p->cso, &p->framebuffer); in draw()
313 p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, &p->clear_color, 0, 0); in draw()
316 cso_set_blend(p->cso, &p->blend); in draw()
317 cso_set_depth_stencil_alpha(p->cso, &p->depthstencil); in draw()
318 cso_set_rasterizer(p->cso, &p->rasterizer); in draw()
319 cso_set_viewport(p->cso, &p->viewport); in draw()
322 cso_single_sampler(p->cso, 0, &p->sampler); in draw()
323 cso_single_sampler_done(p->cso); in draw()
326 cso_set_sampler_views(p->cso, PIPE_SHADER_FRAGMENT, 1, &p->view); in draw()
329 cso_set_fragment_shader_handle(p->cso, p->fs); in draw()
330 cso_set_vertex_shader_handle(p->cso, p->vs); in draw()
333 cso_set_vertex_elements(p->cso, 2, p->velem); in draw()
335 util_draw_vertex_buffer(p->pipe, p->cso, in draw()
336 p->vbuf, 0, in draw()
341 p->pipe->flush(p->pipe, NULL); in draw()
343 debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]); in draw()
348 struct program *p = CALLOC_STRUCT(program); in main() local
350 init_prog(p); in main()
351 draw(p); in main()
352 close_prog(p); in main()