1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
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_buffer.h"
38 #include "sp_context.h"
40 #include "sp_prim_setup.h"
41 #include "sp_region.h"
43 #include "sp_surface.h"
44 #include "sp_tex_layout.h"
45 #include "sp_winsys.h"
50 * Return list of supported surface/texture formats.
51 * If we find texture and drawable support differs, add a selector
52 * parameter or another function.
55 softpipe_supported_formats(struct pipe_context
*pipe
, GLuint
*numFormats
)
57 static const GLuint supported
[] = {
58 PIPE_FORMAT_U_R8_G8_B8_A8
,
59 PIPE_FORMAT_U_A8_R8_G8_B8
,
60 PIPE_FORMAT_U_R5_G6_B5
,
65 PIPE_FORMAT_S_R16_G16_B16_A16
,
67 PIPE_FORMAT_YCBCR_REV
,
75 *numFormats
= sizeof(supported
)/sizeof(supported
[0]);
81 static void map_surfaces(struct softpipe_context
*sp
)
83 struct pipe_context
*pipe
= &sp
->pipe
;
86 for (i
= 0; i
< sp
->framebuffer
.num_cbufs
; i
++) {
87 struct softpipe_surface
*sps
= softpipe_surface(sp
->framebuffer
.cbufs
[i
]); pipe
->region_map(pipe
, sps
->surface
.region
);
90 if (sp
->framebuffer
.zbuf
) {
91 struct softpipe_surface
*sps
= softpipe_surface(sp
->framebuffer
.zbuf
);
92 pipe
->region_map(pipe
, sps
->surface
.region
);
96 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
97 struct pipe_mipmap_tree
*mt
= sp
->texture
[i
];
99 pipe
->region_map(pipe
, mt
->region
);
103 /* XXX depth & stencil bufs */
107 static void unmap_surfaces(struct softpipe_context
*sp
)
109 struct pipe_context
*pipe
= &sp
->pipe
;
112 for (i
= 0; i
< sp
->framebuffer
.num_cbufs
; i
++) {
113 struct softpipe_surface
*sps
= softpipe_surface(sp
->framebuffer
.cbufs
[i
]);
114 pipe
->region_unmap(pipe
, sps
->surface
.region
);
117 if (sp
->framebuffer
.zbuf
) {
118 struct softpipe_surface
*sps
= softpipe_surface(sp
->framebuffer
.zbuf
);
119 pipe
->region_unmap(pipe
, sps
->surface
.region
);
123 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
124 struct pipe_mipmap_tree
*mt
= sp
->texture
[i
];
126 pipe
->region_unmap(pipe
, mt
->region
);
130 /* XXX depth & stencil bufs */
134 static void softpipe_destroy( struct pipe_context
*pipe
)
136 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
138 draw_destroy( softpipe
->draw
);
144 static void softpipe_draw_vb( struct pipe_context
*pipe
,
145 struct vertex_buffer
*VB
)
147 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
150 softpipe_update_derived( softpipe
);
152 /* XXX move mapping/unmapping to higher/coarser level? */
153 map_surfaces(softpipe
);
154 draw_vb( softpipe
->draw
, VB
);
155 unmap_surfaces(softpipe
);
160 softpipe_draw_vertices(struct pipe_context
*pipe
,
162 GLuint numVertex
, const GLfloat
*verts
,
163 GLuint numAttribs
, const GLuint attribs
[])
165 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
168 softpipe_update_derived( softpipe
);
170 /* XXX move mapping/unmapping to higher/coarser level? */
171 map_surfaces(softpipe
);
172 draw_vertices(softpipe
->draw
, mode
, numVertex
, verts
, numAttribs
, attribs
);
173 unmap_surfaces(softpipe
);
178 static void softpipe_reset_occlusion_counter(struct pipe_context
*pipe
)
180 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
181 softpipe
->occlusion_counter
= 0;
184 /* XXX pipe param should be const */
185 static GLuint
softpipe_get_occlusion_counter(struct pipe_context
*pipe
)
187 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
188 return softpipe
->occlusion_counter
;
192 struct pipe_context
*softpipe_create( struct softpipe_winsys
*sws
)
194 struct softpipe_context
*softpipe
= CALLOC_STRUCT(softpipe_context
);
196 softpipe
->pipe
.destroy
= softpipe_destroy
;
198 softpipe
->pipe
.supported_formats
= softpipe_supported_formats
;
200 softpipe
->pipe
.set_alpha_test_state
= softpipe_set_alpha_test_state
;
201 softpipe
->pipe
.set_blend_color
= softpipe_set_blend_color
;
202 softpipe
->pipe
.set_blend_state
= softpipe_set_blend_state
;
203 softpipe
->pipe
.set_clip_state
= softpipe_set_clip_state
;
204 softpipe
->pipe
.set_clear_color_state
= softpipe_set_clear_color_state
;
205 softpipe
->pipe
.set_depth_state
= softpipe_set_depth_test_state
;
206 softpipe
->pipe
.set_framebuffer_state
= softpipe_set_framebuffer_state
;
207 softpipe
->pipe
.set_fs_state
= softpipe_set_fs_state
;
208 softpipe
->pipe
.set_polygon_stipple
= softpipe_set_polygon_stipple
;
209 softpipe
->pipe
.set_sampler_state
= softpipe_set_sampler_state
;
210 softpipe
->pipe
.set_scissor_state
= softpipe_set_scissor_state
;
211 softpipe
->pipe
.set_setup_state
= softpipe_set_setup_state
;
212 softpipe
->pipe
.set_stencil_state
= softpipe_set_stencil_state
;
213 softpipe
->pipe
.set_texture_state
= softpipe_set_texture_state
;
214 softpipe
->pipe
.set_viewport_state
= softpipe_set_viewport_state
;
215 softpipe
->pipe
.draw_vb
= softpipe_draw_vb
;
216 softpipe
->pipe
.draw_vertices
= softpipe_draw_vertices
;
217 softpipe
->pipe
.clear
= softpipe_clear
;
218 softpipe
->pipe
.flush
= softpipe_flush
;
219 softpipe
->pipe
.finish
= softpipe_finish
;
220 softpipe
->pipe
.reset_occlusion_counter
= softpipe_reset_occlusion_counter
;
221 softpipe
->pipe
.get_occlusion_counter
= softpipe_get_occlusion_counter
;
223 softpipe
->pipe
.mipmap_tree_layout
= softpipe_mipmap_tree_layout
;
224 softpipe
->pipe
.get_tex_surface
= softpipe_get_tex_surface
;
226 softpipe
->quad
.polygon_stipple
= sp_quad_polygon_stipple_stage(softpipe
);
227 softpipe
->quad
.shade
= sp_quad_shade_stage(softpipe
);
228 softpipe
->quad
.alpha_test
= sp_quad_alpha_test_stage(softpipe
);
229 softpipe
->quad
.depth_test
= sp_quad_depth_test_stage(softpipe
);
230 softpipe
->quad
.stencil_test
= sp_quad_stencil_test_stage(softpipe
);
231 softpipe
->quad
.occlusion
= sp_quad_occlusion_stage(softpipe
);
232 softpipe
->quad
.coverage
= sp_quad_coverage_stage(softpipe
);
233 softpipe
->quad
.bufloop
= sp_quad_bufloop_stage(softpipe
);
234 softpipe
->quad
.blend
= sp_quad_blend_stage(softpipe
);
235 softpipe
->quad
.colormask
= sp_quad_colormask_stage(softpipe
);
236 softpipe
->quad
.output
= sp_quad_output_stage(softpipe
);
238 softpipe
->winsys
= sws
;
241 * Create drawing context and plug our rendering stage into it.
243 softpipe
->draw
= draw_create();
244 assert(softpipe
->draw
);
245 draw_set_setup_stage(softpipe
->draw
, sp_draw_render_stage(softpipe
));
247 sp_init_buffer_functions(softpipe
);
248 sp_init_region_functions(softpipe
);
249 sp_init_surface_functions(softpipe
);
252 * XXX we could plug GL selection/feedback into the drawing pipeline
253 * by specifying a different setup/render stage.
256 return &softpipe
->pipe
;