st/xorg: bind rasterizer state
[mesa.git] / src / gallium / state_trackers / python / p_texture.i
index b97d1889737dedf96237910b86c73862369e06b6..1d513abf3c75489a751cf7de42e4b6299c655c22 100644 (file)
@@ -84,7 +84,7 @@
    {
       struct st_surface *surface;
       
-      if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6 : 1))
+      if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U))
          SWIG_exception(SWIG_ValueError, "face out of bounds");
       if(level > $self->last_level)
          SWIG_exception(SWIG_ValueError, "level out of bounds");
@@ -126,17 +126,28 @@ struct st_surface
    unsigned format;
    unsigned width;
    unsigned height;
+   unsigned nblocksx;
+   unsigned nblocksy;
    
    ~st_surface() {
       pipe_texture_reference(&$self->texture, NULL);
       FREE($self);
    }
    
-   void
-   get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, char *raw, unsigned stride)
+   %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
+   void get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH)
    {
-      struct pipe_screen *screen = $self->texture->screen;
+      struct pipe_texture *texture = $self->texture;
+      struct pipe_screen *screen = texture->screen;
       struct pipe_transfer *transfer;
+      unsigned stride;
+
+      stride = pf_get_nblocksx(&texture->block, w) * texture->block.size;
+      *LENGTH = pf_get_nblocksy(&texture->block, h) * stride;
+      *STRING = (char *) malloc(*LENGTH);
+      if(!*STRING)
+         return;
+
       transfer = screen->get_tex_transfer(screen,
                                           $self->texture,
                                           $self->face,
@@ -145,16 +156,24 @@ struct st_surface
                                           PIPE_TRANSFER_READ,
                                           x, y, w, h);
       if(transfer) {
-         pipe_get_tile_raw(transfer, 0, 0, w, h, raw, stride);
+         pipe_get_tile_raw(transfer, 0, 0, w, h, *STRING, stride);
          screen->tex_transfer_destroy(transfer);
       }
    }
 
-   void
-   put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const char *raw, unsigned stride)
+   %cstring_input_binary(const char *STRING, unsigned LENGTH);
+   void put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0)
    {
-      struct pipe_screen *screen = $self->texture->screen;
+      struct pipe_texture *texture = $self->texture;
+      struct pipe_screen *screen = texture->screen;
       struct pipe_transfer *transfer;
+     
+      if(stride == 0)
+         stride = pf_get_nblocksx(&texture->block, w) * texture->block.size;
+      
+      if(LENGTH < pf_get_nblocksy(&texture->block, h) * stride)
+         SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
+         
       transfer = screen->get_tex_transfer(screen,
                                           $self->texture,
                                           $self->face,
@@ -162,10 +181,14 @@ struct st_surface
                                           $self->zslice,
                                           PIPE_TRANSFER_WRITE,
                                           x, y, w, h);
-      if(transfer) {
-         pipe_put_tile_raw(transfer, 0, 0, w, h, raw, stride);
-         screen->tex_transfer_destroy(transfer);
-      }
+      if(!transfer)
+         SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
+         
+      pipe_put_tile_raw(transfer, 0, 0, w, h, STRING, stride);
+      screen->tex_transfer_destroy(transfer);
+
+   fail:
+      return;
    }
 
    void
@@ -225,31 +248,28 @@ struct st_surface
       if(!*STRING)
          return;
       
-      rgba = malloc(w*4*sizeof(float));
+      rgba = malloc(h*w*4*sizeof(float));
       if(!rgba)
          return;
       
       rgba8 = (unsigned char *) *STRING;
 
-      for(j = 0; j < h; ++j) {
-         transfer = screen->get_tex_transfer(screen,
-                                             $self->texture,
-                                             $self->face,
-                                             $self->level,
-                                             $self->zslice,
-                                             PIPE_TRANSFER_READ,
-                                             x, y + j,
-                                             w,
-                                             1);
-         if(transfer) {
-            pipe_get_tile_rgba(transfer,
-                               0, 0, w, 1,
-                               rgba);
+      transfer = screen->get_tex_transfer(screen,
+                                          $self->texture,
+                                          $self->face,
+                                          $self->level,
+                                          $self->zslice,
+                                          PIPE_TRANSFER_READ,
+                                          x, y,
+                                          w, h);
+      if(transfer) {
+         pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba);
+         for(j = 0; j < h; ++j) {
             for(i = 0; i < w; ++i)
                for(k = 0; k <4; ++k)
-                  rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[i*4 + k]);
-            screen->tex_transfer_destroy(transfer);
+                  rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
          }
+         screen->tex_transfer_destroy(transfer);
       }
       
       free(rgba);
@@ -363,11 +383,23 @@ struct st_surface
    {
       return surface->texture->height[surface->level];
    }
+
+   static unsigned
+   st_surface_nblocksx_get(struct st_surface *surface)
+   {
+      return surface->texture->nblocksx[surface->level];
+   }
+   
+   static unsigned
+   st_surface_nblocksy_get(struct st_surface *surface)
+   {
+      return surface->texture->nblocksy[surface->level];
+   }
 %}
 
 /* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */ 
-%rename(read) pipe_buffer_read_; 
-%rename(write) pipe_buffer_write_; 
+%rename(read) read_; 
+%rename(write) write_; 
 
 %extend pipe_buffer {
    
@@ -394,7 +426,7 @@ struct st_surface
       if(!*STRING)
          return;
       
-      pipe_buffer_read(screen, $self, 0, $self->size, STRING);
+      pipe_buffer_read(screen, $self, 0, $self->size, *STRING);
    }
    
    %cstring_input_binary(const char *STRING, unsigned LENGTH);