st_device.h File Reference

Include dependency graph for st_device.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  st_buffer
struct  st_context
struct  st_device

Functions

struct st_bufferst_buffer_create (struct st_device *st_dev, unsigned alignment, unsigned usage, unsigned size)
void st_buffer_destroy (struct st_buffer *st_buf)
struct st_contextst_context_create (struct st_device *st_dev)
void st_context_destroy (struct st_context *st_ctx)
struct st_devicest_device_create (boolean hardware)
void st_device_destroy (struct st_device *st_dev)


Function Documentation

struct st_buffer* st_buffer_create ( struct st_device st_dev,
unsigned  alignment,
unsigned  usage,
unsigned  size 
) [read]

Definition at line 303 of file st_device.c.

References st_buffer::buffer, CALLOC_STRUCT, pipe_buffer_create(), st_device::screen, st_buffer_destroy(), and st_buffer::st_dev.

00305 {
00306    struct pipe_screen *screen = st_dev->screen;
00307    struct st_buffer *st_buf;
00308    
00309    st_buf = CALLOC_STRUCT(st_buffer);
00310    if(!st_buf)
00311       return NULL;
00312 
00313    st_buf->st_dev = st_dev;
00314    
00315    st_buf->buffer = pipe_buffer_create(screen, alignment, usage, size);
00316    if(!st_buf->buffer) {
00317       st_buffer_destroy(st_buf);
00318       return NULL;
00319    }
00320    
00321    return st_buf;
00322 }

void st_buffer_destroy ( struct st_buffer st_buf  ) 

Definition at line 292 of file st_device.c.

References st_buffer::buffer, FREE, pipe_buffer_reference(), st_device::screen, and st_buffer::st_dev.

00293 {
00294    if(st_buf) {
00295       struct pipe_screen *screen = st_buf->st_dev->screen;
00296       pipe_buffer_reference(screen, &st_buf->buffer, NULL);
00297       FREE(st_buf);
00298    }
00299 }

struct st_context* st_context_create ( struct st_device st_dev  )  [read]

Definition at line 134 of file st_device.c.

References pipe_blend_state::alpha_dst_factor, pipe_blend_state::alpha_src_factor, pipe_texture::block, pipe_rasterizer_state::bypass_clipping, CALLOC_STRUCT, pipe_blend_state::colormask, st_winsys::context_create, st_context::cso, cso_create_context(), cso_set_blend(), cso_set_depth_stencil_alpha(), cso_set_fragment_shader_handle(), cso_set_rasterizer(), cso_set_sampler_textures(), cso_set_vertex_shader_handle(), cso_set_viewport(), cso_single_sampler(), cso_single_sampler_done(), pipe_rasterizer_state::cull_mode, st_context::default_texture, pipe_texture::depth, pipe_texture::format, pipe_rasterizer_state::front_winding, st_context::fs, pipe_screen::get_tex_surface, pipe_texture::height, pipe_format_block::height, pipe_texture::last_level, pipe_sampler_state::mag_img_filter, pipe_sampler_state::min_img_filter, pipe_sampler_state::min_mip_filter, pipe_sampler_state::normalized_coords, st_context::pipe, PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_ZERO, PIPE_BUFFER_USAGE_CPU_WRITE, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_MASK_RGBA, PIPE_MAX_SAMPLERS, pipe_surface_map(), pipe_surface_reference(), pipe_surface_unmap(), PIPE_TEX_MIPFILTER_NEAREST, PIPE_TEX_WRAP_CLAMP_TO_EDGE, PIPE_TEXTURE_2D, pipe_texture_reference(), PIPE_WINDING_CW, PIPE_WINDING_NONE, st_context::real_pipe, st_device::real_screen, st_device::refcount, pipe_blend_state::rgb_dst_factor, pipe_blend_state::rgb_src_factor, st_context::sampler_textures, pipe_viewport_state::scale, st_device::screen, semantic_names, pipe_format_block::size, st_context_destroy(), st_context::st_dev, st_device::st_ws, pipe_texture::target, pipe_screen::texture_create, TGSI_SEMANTIC_GENERIC, TGSI_SEMANTIC_POSITION, trace_context_create(), pipe_viewport_state::translate, util_make_fragment_passthrough_shader(), util_make_vertex_passthrough_shader(), st_context::vs, pipe_texture::width, pipe_format_block::width, pipe_sampler_state::wrap_r, pipe_sampler_state::wrap_s, and pipe_sampler_state::wrap_t.

00135 {
00136    struct st_context *st_ctx;
00137    
00138    st_ctx = CALLOC_STRUCT(st_context);
00139    if(!st_ctx)
00140       return NULL;
00141    
00142    st_ctx->st_dev = st_dev;
00143    ++st_dev->refcount;
00144    
00145    st_ctx->real_pipe = st_dev->st_ws->context_create(st_dev->real_screen);
00146    if(!st_ctx->real_pipe) {
00147       st_context_destroy(st_ctx);
00148       return NULL;
00149    }
00150    
00151    st_ctx->pipe = trace_context_create(st_dev->screen, st_ctx->real_pipe);
00152    if(!st_ctx->pipe) {
00153       st_context_destroy(st_ctx);
00154       return NULL;
00155    }
00156 
00157    st_ctx->cso = cso_create_context(st_ctx->pipe);
00158    if(!st_ctx->cso) {
00159       st_context_destroy(st_ctx);
00160       return NULL;
00161    }
00162    
00163    /* disabled blending/masking */
00164    {
00165       struct pipe_blend_state blend;
00166       memset(&blend, 0, sizeof(blend));
00167       blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
00168       blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
00169       blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
00170       blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
00171       blend.colormask = PIPE_MASK_RGBA;
00172       cso_set_blend(st_ctx->cso, &blend);
00173    }
00174 
00175    /* no-op depth/stencil/alpha */
00176    {
00177       struct pipe_depth_stencil_alpha_state depthstencil;
00178       memset(&depthstencil, 0, sizeof(depthstencil));
00179       cso_set_depth_stencil_alpha(st_ctx->cso, &depthstencil);
00180    }
00181 
00182    /* rasterizer */
00183    {
00184       struct pipe_rasterizer_state rasterizer;
00185       memset(&rasterizer, 0, sizeof(rasterizer));
00186       rasterizer.front_winding = PIPE_WINDING_CW;
00187       rasterizer.cull_mode = PIPE_WINDING_NONE;
00188       rasterizer.bypass_clipping = 1;
00189       /*rasterizer.bypass_vs = 1;*/
00190       cso_set_rasterizer(st_ctx->cso, &rasterizer);
00191    }
00192 
00193    /* identity viewport */
00194    {
00195       struct pipe_viewport_state viewport;
00196       viewport.scale[0] = 1.0;
00197       viewport.scale[1] = 1.0;
00198       viewport.scale[2] = 1.0;
00199       viewport.scale[3] = 1.0;
00200       viewport.translate[0] = 0.0;
00201       viewport.translate[1] = 0.0;
00202       viewport.translate[2] = 0.0;
00203       viewport.translate[3] = 0.0;
00204       cso_set_viewport(st_ctx->cso, &viewport);
00205    }
00206 
00207    /* samplers */
00208    {
00209       struct pipe_sampler_state sampler;
00210       unsigned i;
00211       memset(&sampler, 0, sizeof(sampler));
00212       sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
00213       sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
00214       sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
00215       sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
00216       sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
00217       sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
00218       sampler.normalized_coords = 1;
00219       for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
00220          cso_single_sampler(st_ctx->cso, i, &sampler);
00221       cso_single_sampler_done(st_ctx->cso);
00222    }
00223 
00224    /* default textures */
00225    {
00226       struct pipe_screen *screen = st_dev->screen;
00227       struct pipe_texture templat;
00228       struct pipe_surface *surface;
00229       unsigned i;
00230 
00231       memset( &templat, 0, sizeof( templat ) );
00232       templat.target = PIPE_TEXTURE_2D;
00233       templat.format = PIPE_FORMAT_A8R8G8B8_UNORM;
00234       templat.block.size = 4;
00235       templat.block.width = 1;
00236       templat.block.height = 1;
00237       templat.width[0] = 1;
00238       templat.height[0] = 1;
00239       templat.depth[0] = 1;
00240       templat.last_level = 0;
00241    
00242       st_ctx->default_texture = screen->texture_create( screen, &templat );
00243       if(st_ctx->default_texture) {
00244          surface = screen->get_tex_surface( screen, 
00245                                             st_ctx->default_texture, 0, 0, 0,
00246                                             PIPE_BUFFER_USAGE_CPU_WRITE );
00247          if(surface) {
00248             uint32_t *map;
00249             map = (uint32_t *) pipe_surface_map(surface, PIPE_BUFFER_USAGE_CPU_WRITE );
00250             if(map) {
00251                *map = 0x00000000;
00252                pipe_surface_unmap( surface );
00253             }
00254             pipe_surface_reference(&surface, NULL);
00255          }
00256       }
00257    
00258       for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
00259          pipe_texture_reference(&st_ctx->sampler_textures[i], st_ctx->default_texture);
00260       
00261       cso_set_sampler_textures(st_ctx->cso, PIPE_MAX_SAMPLERS, st_ctx->sampler_textures);
00262    }
00263    
00264    /* vertex shader */
00265    {
00266       struct pipe_shader_state vert_shader;
00267 
00268       const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
00269                                       TGSI_SEMANTIC_GENERIC };
00270       const uint semantic_indexes[] = { 0, 0 };
00271       st_ctx->vs = util_make_vertex_passthrough_shader(st_ctx->pipe, 
00272                                                        2, 
00273                                                        semantic_names,
00274                                                        semantic_indexes,
00275                                                        &vert_shader);
00276       cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs);
00277    }
00278 
00279    /* fragment shader */
00280    {
00281       struct pipe_shader_state frag_shader;
00282       st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe, 
00283                                                          &frag_shader);
00284       cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs);
00285    }
00286 
00287    return st_ctx;
00288 }

void st_context_destroy ( struct st_context st_ctx  ) 

Definition at line 104 of file st_device.c.

References st_context::cso, cso_delete_fragment_shader(), cso_delete_vertex_shader(), cso_destroy_context(), st_context::default_texture, pipe_context::destroy, FREE, st_context::fs, st_context::pipe, PIPE_MAX_SAMPLERS, pipe_texture_reference(), st_device::refcount, st_context::sampler_textures, st_context::st_dev, st_device_really_destroy(), and st_context::vs.

00105 {
00106    unsigned i;
00107    
00108    if(st_ctx) {
00109       struct st_device *st_dev = st_ctx->st_dev;
00110       
00111       if(st_ctx->cso) {
00112          cso_delete_vertex_shader(st_ctx->cso, st_ctx->vs);
00113          cso_delete_fragment_shader(st_ctx->cso, st_ctx->fs);
00114          
00115          cso_destroy_context(st_ctx->cso);
00116       }
00117       
00118       if(st_ctx->pipe)
00119          st_ctx->pipe->destroy(st_ctx->pipe);
00120       
00121       for(i = 0; i < PIPE_MAX_SAMPLERS; ++i)
00122          pipe_texture_reference(&st_ctx->sampler_textures[i], NULL);
00123       pipe_texture_reference(&st_ctx->default_texture, NULL);
00124 
00125       FREE(st_ctx);
00126       
00127       if(!--st_dev->refcount)
00128          st_device_really_destroy(st_dev);
00129    }
00130 }

struct st_device* st_device_create ( boolean  hardware  )  [read]

Definition at line 95 of file st_device.c.

References st_device_create_from_st_winsys(), st_hardpipe_winsys, and st_softpipe_winsys.

00095                                    {
00096    if(hardware)
00097       return st_device_create_from_st_winsys(&st_hardpipe_winsys);
00098    else
00099       return st_device_create_from_st_winsys(&st_softpipe_winsys);
00100 }

void st_device_destroy ( struct st_device st_dev  ) 

Definition at line 55 of file st_device.c.

References st_device::refcount, and st_device_really_destroy().

00056 {
00057    if(!--st_dev->refcount)
00058       st_device_really_destroy(st_dev);
00059 }


Generated on Tue Sep 29 06:25:44 2009 for Gallium3D by  doxygen 1.5.4