Build libsoftpipe.a
[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 "pipe/p_defines.h"
36 #include "sp_context.h"
37 #include "sp_clear.h"
38 #include "sp_region.h"
39 #include "sp_state.h"
40 #include "sp_surface.h"
41 #include "sp_prim_setup.h"
42
43
44 static void map_surfaces(struct softpipe_context *sp)
45 {
46 struct pipe_context *pipe = &sp->pipe;
47 GLuint i;
48
49 for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
50 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.cbufs[i]); pipe->region_map(pipe, sps->surface.region);
51 }
52
53 if (sp->framebuffer.zbuf) {
54 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.zbuf);
55 pipe->region_map(pipe, sps->surface.region);
56 }
57
58 /* XXX depth & stencil bufs */
59 }
60
61
62 static void unmap_surfaces(struct softpipe_context *sp)
63 {
64 struct pipe_context *pipe = &sp->pipe;
65 GLuint i;
66
67 for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
68 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.cbufs[i]);
69 pipe->region_unmap(pipe, sps->surface.region);
70 }
71
72 if (sp->framebuffer.zbuf) {
73 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.zbuf);
74 pipe->region_unmap(pipe, sps->surface.region);
75 }
76 /* XXX depth & stencil bufs */
77 }
78
79
80 static void softpipe_destroy( struct pipe_context *pipe )
81 {
82 struct softpipe_context *softpipe = softpipe_context( pipe );
83
84 draw_destroy( softpipe->draw );
85
86 free( softpipe );
87 }
88
89
90 static void softpipe_draw_vb( struct pipe_context *pipe,
91 struct vertex_buffer *VB )
92 {
93 struct softpipe_context *softpipe = softpipe_context( pipe );
94
95 if (softpipe->dirty)
96 softpipe_update_derived( softpipe );
97
98 /* XXX move mapping/unmapping to higher/coarser level? */
99 map_surfaces(softpipe);
100 draw_vb( softpipe->draw, VB );
101 unmap_surfaces(softpipe);
102 }
103
104
105 static void softpipe_reset_occlusion_counter(struct pipe_context *pipe)
106 {
107 struct softpipe_context *softpipe = softpipe_context( pipe );
108 softpipe->occlusion_counter = 0;
109 }
110
111 /* XXX pipe param should be const */
112 static GLuint softpipe_get_occlusion_counter(struct pipe_context *pipe)
113 {
114 struct softpipe_context *softpipe = softpipe_context( pipe );
115 return softpipe->occlusion_counter;
116 }
117
118
119 struct pipe_context *softpipe_create( void )
120 {
121 struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
122
123 softpipe->pipe.destroy = softpipe_destroy;
124 softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state;
125 softpipe->pipe.set_blend_color = softpipe_set_blend_color;
126 softpipe->pipe.set_blend_state = softpipe_set_blend_state;
127 softpipe->pipe.set_clip_state = softpipe_set_clip_state;
128 softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state;
129 softpipe->pipe.set_depth_state = softpipe_set_depth_test_state;
130 softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;
131 softpipe->pipe.set_fs_state = softpipe_set_fs_state;
132 softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
133 softpipe->pipe.set_sampler_state = softpipe_set_sampler_state;
134 softpipe->pipe.set_scissor_state = softpipe_set_scissor_state;
135 softpipe->pipe.set_setup_state = softpipe_set_setup_state;
136 softpipe->pipe.set_stencil_state = softpipe_set_stencil_state;
137 softpipe->pipe.set_texture_state = softpipe_set_texture_state;
138 softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;
139 softpipe->pipe.draw_vb = softpipe_draw_vb;
140 softpipe->pipe.clear = softpipe_clear;
141 softpipe->pipe.reset_occlusion_counter = softpipe_reset_occlusion_counter;
142 softpipe->pipe.get_occlusion_counter = softpipe_get_occlusion_counter;
143
144 softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe);
145 softpipe->quad.shade = sp_quad_shade_stage(softpipe);
146 softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe);
147 softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe);
148 softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe);
149 softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe);
150 softpipe->quad.coverage = sp_quad_coverage_stage(softpipe);
151 softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe);
152 softpipe->quad.blend = sp_quad_blend_stage(softpipe);
153 softpipe->quad.colormask = sp_quad_colormask_stage(softpipe);
154 softpipe->quad.output = sp_quad_output_stage(softpipe);
155
156 /*
157 * Create drawing context and plug our rendering stage into it.
158 */
159 softpipe->draw = draw_create();
160 assert(softpipe->draw);
161 draw_set_setup_stage(softpipe->draw, sp_draw_render_stage(softpipe));
162
163 sp_init_region_functions(softpipe);
164 sp_init_surface_functions(softpipe);
165
166 /*
167 * XXX we could plug GL selection/feedback into the drawing pipeline
168 * by specifying a different setup/render stage.
169 */
170
171 return &softpipe->pipe;
172 }