python: Set default state.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Mon, 14 Jul 2008 02:38:44 +0000 (11:38 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Mon, 14 Jul 2008 03:41:06 +0000 (12:41 +0900)
src/gallium/state_trackers/python/gallium.i
src/gallium/state_trackers/python/st_device.c
src/gallium/state_trackers/python/st_device.h

index 53d160ef6c4960199a601140465471aa9d23fb0e..6e355b79757b2774bbbfb59f881a23fe7a221b47 100644 (file)
@@ -266,6 +266,8 @@ struct st_context {
 
    void set_sampler_texture(unsigned index,
                             struct pipe_texture *texture) {
+      if(!texture)
+         texture = $self->default_texture;
       pipe_texture_reference(&$self->sampler_textures[index], texture);
       $self->pipe->set_sampler_textures($self->pipe, 
                                         PIPE_MAX_SAMPLERS,
index e9002b493de12c183faad9998a1eb0b77022c43c..25b5a4fa8c154a454c8bbdae7e6d8723dfacff16 100644 (file)
@@ -111,7 +111,8 @@ st_context_destroy(struct st_context *st_ctx)
       
       for(i = 0; i < PIPE_MAX_SAMPLERS; ++i)
          pipe_texture_reference(&st_ctx->sampler_textures[i], NULL);
-   
+      pipe_texture_reference(&st_ctx->default_texture, NULL);
+
       FREE(st_ctx);
       
       if(!--st_dev->refcount)
@@ -140,8 +141,111 @@ st_context_create(struct st_device *st_dev)
    if(!st_ctx->cso)
       st_context_destroy(st_ctx);
    
+   /* disabled blending/masking */
+   {
+      struct pipe_blend_state blend;
+      memset(&blend, 0, sizeof(blend));
+      blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
+      blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
+      blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
+      blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
+      blend.colormask = PIPE_MASK_RGBA;
+      cso_set_blend(st_ctx->cso, &blend);
+   }
+
+   /* no-op depth/stencil/alpha */
+   {
+      struct pipe_depth_stencil_alpha_state depthstencil;
+      memset(&depthstencil, 0, sizeof(depthstencil));
+      cso_set_depth_stencil_alpha(st_ctx->cso, &depthstencil);
+   }
+
+   /* rasterizer */
+   {
+      struct pipe_rasterizer_state rasterizer;
+      memset(&rasterizer, 0, sizeof(rasterizer));
+      rasterizer.front_winding = PIPE_WINDING_CW;
+      rasterizer.cull_mode = PIPE_WINDING_NONE;
+      rasterizer.bypass_clipping = 1;
+      /*rasterizer.bypass_vs = 1;*/
+      cso_set_rasterizer(st_ctx->cso, &rasterizer);
+   }
+
+   /* identity viewport */
+   {
+      struct pipe_viewport_state viewport;
+      viewport.scale[0] = 1.0;
+      viewport.scale[1] = 1.0;
+      viewport.scale[2] = 1.0;
+      viewport.scale[3] = 1.0;
+      viewport.translate[0] = 0.0;
+      viewport.translate[1] = 0.0;
+      viewport.translate[2] = 0.0;
+      viewport.translate[3] = 0.0;
+      cso_set_viewport(st_ctx->cso, &viewport);
+   }
+
+   /* samplers */
+   {
+      struct pipe_sampler_state sampler;
+      unsigned i;
+      memset(&sampler, 0, sizeof(sampler));
+      sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+      sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+      sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+      sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
+      sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
+      sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
+      sampler.normalized_coords = 1;
+      for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
+         cso_single_sampler(st_ctx->cso, i, &sampler);
+      cso_single_sampler_done(st_ctx->cso);
+   }
+
+   /* default textures */
+   {
+      struct pipe_screen *screen = st_dev->screen;
+      struct pipe_texture templat;
+      struct pipe_surface *surface;
+      unsigned i;
+
+      memset( &templat, 0, sizeof( templat ) );
+      templat.target = PIPE_TEXTURE_2D;
+      templat.format = PIPE_FORMAT_A8R8G8B8_UNORM;
+      templat.block.size = 4;
+      templat.block.width = 1;
+      templat.block.height = 1;
+      templat.width[0] = 1;
+      templat.height[0] = 1;
+      templat.depth[0] = 1;
+      templat.last_level = 0;
+   
+      st_ctx->default_texture = screen->texture_create( screen, &templat );
+      if(st_ctx->default_texture) {
+         surface = screen->get_tex_surface( screen, 
+                                            st_ctx->default_texture, 0, 0, 0,
+                                            PIPE_BUFFER_USAGE_CPU_WRITE );
+         if(surface) {
+            uint32_t *map;
+            map = (uint32_t *) pipe_surface_map(surface, PIPE_BUFFER_USAGE_CPU_WRITE );
+            if(map) {
+               *map = 0x00000000;
+               pipe_surface_unmap( surface );
+            }
+            pipe_surface_reference(&surface, NULL);
+         }
+      }
+   
+      for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
+         pipe_texture_reference(&st_ctx->sampler_textures[i], st_ctx->default_texture);
+      
+      cso_set_sampler_textures(st_ctx->cso, PIPE_MAX_SAMPLERS, st_ctx->sampler_textures);
+   }
+   
    /* vertex shader */
    {
+      struct pipe_shader_state vert_shader;
+
       const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
                                       TGSI_SEMANTIC_GENERIC };
       const uint semantic_indexes[] = { 0, 0 };
@@ -149,15 +253,17 @@ st_context_create(struct st_device *st_dev)
                                                        2, 
                                                        semantic_names,
                                                        semantic_indexes,
-                                                       &st_ctx->vert_shader);
+                                                       &vert_shader);
+      cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs);
    }
 
    /* fragment shader */
-   st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe, 
-                                                      &st_ctx->frag_shader);
-   
-   cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs);
-   cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs);
+   {
+      struct pipe_shader_state frag_shader;
+      st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe, 
+                                                         &frag_shader);
+      cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs);
+   }
 
    return st_ctx;
 }
index 46db20acd76bfe2015e560dc8349b3c1c3603395..2d95c2da73181156066df6d4676bbdca9e95efd6 100644 (file)
@@ -45,12 +45,10 @@ struct st_context {
    
    struct cso_context *cso;
    
-   struct pipe_shader_state vert_shader;
-   struct pipe_shader_state frag_shader;
-
    void *vs;
    void *fs;
 
+   struct pipe_texture *default_texture;
    struct pipe_texture *sampler_textures[PIPE_MAX_SAMPLERS];
    struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
    struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS];