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 "pipe/draw/draw_context.h"
33 #include "pipe/p_defines.h"
34 #include "pipe/p_util.h"
36 #include "sp_context.h"
38 #include "sp_prim_setup.h"
39 #include "sp_region.h"
41 #include "sp_surface.h"
42 #include "sp_tex_layout.h"
43 #include "sp_winsys.h"
48 * Return list of supported surface/texture formats.
49 * If we find texture and drawable support differs, add a selector
50 * parameter or another function.
52 static const unsigned *
53 softpipe_supported_formats(struct pipe_context *pipe, unsigned *numFormats)
56 static const unsigned supported[] = {
57 PIPE_FORMAT_U_R8_G8_B8_A8,
58 PIPE_FORMAT_U_A8_R8_G8_B8,
59 PIPE_FORMAT_U_R5_G6_B5,
64 PIPE_FORMAT_S_R16_G16_B16_A16,
66 PIPE_FORMAT_YCBCR_REV,
74 *numFormats = sizeof(supported)/sizeof(supported[0]);
77 struct softpipe_context *softpipe = softpipe_context( pipe );
78 return softpipe->winsys->supported_formats( softpipe->winsys, numFormats );
83 /** XXX remove these? */
84 #define MAX_TEXTURE_LEVELS 11
85 #define MAX_TEXTURE_RECT_SIZE 2048
86 #define MAX_3D_TEXTURE_LEVELS 8
89 softpipe_max_texture_size(struct pipe_context *pipe, unsigned textureType,
90 unsigned *maxWidth, unsigned *maxHeight,
93 switch (textureType) {
95 *maxWidth = 1 << (MAX_TEXTURE_LEVELS - 1);
99 *maxHeight = 1 << (MAX_TEXTURE_LEVELS - 1);
101 case PIPE_TEXTURE_3D:
104 *maxDepth = 1 << (MAX_3D_TEXTURE_LEVELS - 1);
106 case PIPE_TEXTURE_CUBE:
108 *maxHeight = MAX_TEXTURE_RECT_SIZE;
117 softpipe_map_surfaces(struct softpipe_context *sp)
119 struct pipe_context *pipe = &sp->pipe;
122 for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
123 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.cbufs[i]);
124 if (sps->surface.region)
125 pipe->region_map(pipe, sps->surface.region);
128 if (sp->framebuffer.zbuf) {
129 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.zbuf);
130 if (sps->surface.region)
131 pipe->region_map(pipe, sps->surface.region);
134 if (sp->framebuffer.sbuf) {
135 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.sbuf);
136 if (sps->surface.region)
137 pipe->region_map(pipe, sps->surface.region);
141 for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
142 struct pipe_mipmap_tree *mt = sp->texture[i];
144 pipe->region_map(pipe, mt->region);
148 /* XXX depth & stencil bufs */
153 softpipe_unmap_surfaces(struct softpipe_context *sp)
155 struct pipe_context *pipe = &sp->pipe;
158 for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
159 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.cbufs[i]);
160 if (sps->surface.region)
161 pipe->region_unmap(pipe, sps->surface.region);
164 if (sp->framebuffer.zbuf) {
165 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.zbuf);
166 if (sps->surface.region)
167 pipe->region_unmap(pipe, sps->surface.region);
170 if (sp->framebuffer.sbuf) {
171 struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.sbuf);
172 if (sps->surface.region)
173 pipe->region_unmap(pipe, sps->surface.region);
177 for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
178 struct pipe_mipmap_tree *mt = sp->texture[i];
180 pipe->region_unmap(pipe, mt->region);
184 /* XXX depth & stencil bufs */
188 static void softpipe_destroy( struct pipe_context *pipe )
190 struct softpipe_context *softpipe = softpipe_context( pipe );
192 draw_destroy( softpipe->draw );
198 static void softpipe_draw_vb( struct pipe_context *pipe,
199 struct vertex_buffer *VB )
201 struct softpipe_context *softpipe = softpipe_context( pipe );
204 softpipe_update_derived( softpipe );
206 /* XXX move mapping/unmapping to higher/coarser level? */
207 softpipe_map_surfaces(softpipe);
208 draw_vb( softpipe->draw, VB );
209 softpipe_unmap_surfaces(softpipe);
214 softpipe_draw_vertices(struct pipe_context *pipe,
216 unsigned numVertex, const float *verts,
217 unsigned numAttribs, const unsigned attribs[])
219 struct softpipe_context *softpipe = softpipe_context( pipe );
222 softpipe_update_derived( softpipe );
224 /* XXX move mapping/unmapping to higher/coarser level? */
225 softpipe_map_surfaces(softpipe);
226 draw_vertices(softpipe->draw, mode, numVertex, verts, numAttribs, attribs);
227 softpipe_unmap_surfaces(softpipe);
232 static void softpipe_reset_occlusion_counter(struct pipe_context *pipe)
234 struct softpipe_context *softpipe = softpipe_context( pipe );
235 softpipe->occlusion_counter = 0;
238 /* XXX pipe param should be const */
239 static unsigned softpipe_get_occlusion_counter(struct pipe_context *pipe)
241 struct softpipe_context *softpipe = softpipe_context( pipe );
242 return softpipe->occlusion_counter;
245 static const char *softpipe_get_name( struct pipe_context *pipe )
250 static const char *softpipe_get_vendor( struct pipe_context *pipe )
252 return "Tungsten Graphics, Inc.";
256 struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
257 struct softpipe_winsys *softpipe_winsys )
259 struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
261 softpipe->pipe.winsys = pipe_winsys;
262 softpipe->pipe.destroy = softpipe_destroy;
265 softpipe->pipe.supported_formats = softpipe_supported_formats;
266 softpipe->pipe.max_texture_size = softpipe_max_texture_size;
269 softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state;
270 softpipe->pipe.set_blend_color = softpipe_set_blend_color;
271 softpipe->pipe.set_blend_state = softpipe_set_blend_state;
272 softpipe->pipe.set_clip_state = softpipe_set_clip_state;
273 softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state;
274 softpipe->pipe.set_depth_state = softpipe_set_depth_test_state;
275 softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;
276 softpipe->pipe.set_fs_state = softpipe_set_fs_state;
277 softpipe->pipe.set_vs_state = softpipe_set_vs_state;
278 softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
279 softpipe->pipe.set_sampler_state = softpipe_set_sampler_state;
280 softpipe->pipe.set_scissor_state = softpipe_set_scissor_state;
281 softpipe->pipe.set_setup_state = softpipe_set_setup_state;
282 softpipe->pipe.set_stencil_state = softpipe_set_stencil_state;
283 softpipe->pipe.set_texture_state = softpipe_set_texture_state;
284 softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;
285 softpipe->pipe.set_vertex_buffer = softpipe_set_vertex_buffer;
286 softpipe->pipe.set_vertex_element = softpipe_set_vertex_element;
288 softpipe->pipe.draw_vb = softpipe_draw_vb;
289 softpipe->pipe.draw_vertices = softpipe_draw_vertices;
290 softpipe->pipe.draw_arrays = softpipe_draw_arrays;
292 softpipe->pipe.clear = softpipe_clear;
293 softpipe->pipe.flush = softpipe_flush;
294 softpipe->pipe.reset_occlusion_counter = softpipe_reset_occlusion_counter;
295 softpipe->pipe.get_occlusion_counter = softpipe_get_occlusion_counter;
296 softpipe->pipe.get_name = softpipe_get_name;
297 softpipe->pipe.get_vendor = softpipe_get_vendor;
300 softpipe->pipe.mipmap_tree_layout = softpipe_mipmap_tree_layout;
301 softpipe->pipe.get_tex_surface = softpipe_get_tex_surface;
303 /* setup quad rendering stages */
304 softpipe->quad.polygon_stipple = sp_quad_polygon_stipple_stage(softpipe);
305 softpipe->quad.shade = sp_quad_shade_stage(softpipe);
306 softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe);
307 softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe);
308 softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe);
309 softpipe->quad.occlusion = sp_quad_occlusion_stage(softpipe);
310 softpipe->quad.coverage = sp_quad_coverage_stage(softpipe);
311 softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe);
312 softpipe->quad.blend = sp_quad_blend_stage(softpipe);
313 softpipe->quad.colormask = sp_quad_colormask_stage(softpipe);
314 softpipe->quad.output = sp_quad_output_stage(softpipe);
316 softpipe->winsys = softpipe_winsys;
319 * Create drawing context and plug our rendering stage into it.
321 softpipe->draw = draw_create();
322 assert(softpipe->draw);
323 draw_set_setup_stage(softpipe->draw, sp_draw_render_stage(softpipe));
325 draw_set_vertex_array_info(softpipe->draw,
326 softpipe->vertex_buffer,
327 softpipe->vertex_element);
329 sp_init_region_functions(softpipe);
330 sp_init_surface_functions(softpipe);
333 * XXX we could plug GL selection/feedback into the drawing pipeline
334 * by specifying a different setup/render stage.
337 return &softpipe->pipe;