Merge branch 'origin' into softpipe_0_1_branch
[mesa.git] / src / mesa / pipe / softpipe / sp_context.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 /* Author:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 #include "main/imports.h"
33 #include "main/macros.h"
34 #include "pipe/draw/draw_context.h"
35 #include "sp_context.h"
36 #include "sp_clear.h"
37 #include "sp_state.h"
38 #include "sp_prim_setup.h"
39
40
41 static void softpipe_destroy( struct pipe_context *pipe )
42 {
43 struct softpipe_context *softpipe = softpipe_context( pipe );
44
45 draw_destroy( softpipe->draw );
46
47 free( softpipe );
48 }
49
50
51 static void softpipe_draw_vb( struct pipe_context *pipe,
52 struct vertex_buffer *VB )
53 {
54 struct softpipe_context *softpipe = softpipe_context( pipe );
55
56 if (softpipe->dirty)
57 softpipe_update_derived( softpipe );
58
59 draw_vb( softpipe->draw, VB );
60 }
61
62
63 static void softpipe_reset_occlusion_counter(struct pipe_context *pipe)
64 {
65 struct softpipe_context *softpipe = softpipe_context( pipe );
66 softpipe->occlusion_counter = 0;
67 }
68
69 /* XXX pipe param should be const */
70 static GLuint softpipe_get_occlusion_counter(struct pipe_context *pipe)
71 {
72 struct softpipe_context *softpipe = softpipe_context( pipe );
73 return softpipe->occlusion_counter;
74 }
75
76
77 struct pipe_context *softpipe_create( void )
78 {
79 struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
80
81 softpipe->pipe.destroy = softpipe_destroy;
82 softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state;
83 softpipe->pipe.set_blend_color = softpipe_set_blend_color;
84 softpipe->pipe.set_blend_state = softpipe_set_blend_state;
85 softpipe->pipe.set_clip_state = softpipe_set_clip_state;
86 softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state;
87 softpipe->pipe.set_depth_state = softpipe_set_depth_test_state;
88 softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;
89 softpipe->pipe.set_fs_state = softpipe_set_fs_state;
90 softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
91 softpipe->pipe.set_sampler_state = softpipe_set_sampler_state;
92 softpipe->pipe.set_scissor_state = softpipe_set_scissor_state;
93 softpipe->pipe.set_setup_state = softpipe_set_setup_state;
94 softpipe->pipe.set_stencil_state = softpipe_set_stencil_state;
95 softpipe->pipe.set_texture_state = softpipe_set_texture_state;
96 softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;
97 softpipe->pipe.draw_vb = softpipe_draw_vb;
98 softpipe->pipe.clear = softpipe_clear;
99 softpipe->pipe.reset_occlusion_counter = softpipe_reset_occlusion_counter;
100 softpipe->pipe.get_occlusion_counter = softpipe_get_occlusion_counter;
101
102 softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe);
103 softpipe->quad.shade = sp_quad_shade_stage(softpipe);
104 softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe);
105 softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe);
106 softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe);
107 softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe);
108 softpipe->quad.coverage = sp_quad_coverage_stage(softpipe);
109 softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe);
110 softpipe->quad.blend = sp_quad_blend_stage(softpipe);
111 softpipe->quad.colormask = sp_quad_colormask_stage(softpipe);
112 softpipe->quad.output = sp_quad_output_stage(softpipe);
113
114 /*
115 * Create drawing context and plug our rendering stage into it.
116 */
117 softpipe->draw = draw_create();
118 draw_set_setup_stage(softpipe->draw, sp_draw_render_stage(softpipe));
119
120 /*
121 * XXX we could plug GL selection/feedback into the drawing pipeline
122 * by specifying a different setup/render stage.
123 */
124
125 return &softpipe->pipe;
126 }