cell_clear.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00033 #include <stdio.h>
00034 #include <assert.h>
00035 #include <stdint.h>
00036 #include "pipe/p_inlines.h"
00037 #include "util/u_memory.h"
00038 #include "util/u_pack_color.h"
00039 #include "cell/common.h"
00040 #include "cell_clear.h"
00041 #include "cell_context.h"
00042 #include "cell_batch.h"
00043 #include "cell_flush.h"
00044 #include "cell_spu.h"
00045 #include "cell_state.h"
00046 
00047 
00051 static unsigned
00052 convert_color(enum pipe_format srcFormat, unsigned srcColor,
00053               enum pipe_format dstFormat)
00054 {
00055    ubyte r, g, b, a;
00056    unsigned dstColor;
00057 
00058    util_unpack_color_ub(srcFormat, &srcColor, &r, &g, &b, &a);
00059    util_pack_color_ub(r, g, b, a, dstFormat, &dstColor);
00060 
00061    return dstColor;
00062 }
00063 
00064 
00065 
00069 void
00070 cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps,
00071                    unsigned clearValue)
00072 {
00073    struct pipe_screen *screen = pipe->screen;
00074    struct cell_context *cell = cell_context(pipe);
00075    uint surfIndex;
00076 
00077    if (cell->dirty)
00078       cell_update_derived(cell);
00079 
00080 
00081    if (!cell->cbuf_map[0])
00082       cell->cbuf_map[0] = screen->surface_map(screen, ps,
00083                                               PIPE_BUFFER_USAGE_GPU_WRITE);
00084 
00085    if (ps == cell->framebuffer.zsbuf) {
00086       /* clear z/stencil buffer */
00087       surfIndex = 1;
00088    }
00089    else {
00090       /* clear color buffer */
00091       surfIndex = 0;
00092 
00093       if (ps->format != PIPE_FORMAT_A8R8G8B8_UNORM) {
00094          clearValue = convert_color(PIPE_FORMAT_A8R8G8B8_UNORM, clearValue,
00095                                     ps->format);
00096       }
00097    }
00098 
00099 
00100    /* Build a CLEAR command and place it in the current batch buffer */
00101    {
00102       struct cell_command_clear_surface *clr
00103          = (struct cell_command_clear_surface *)
00104          cell_batch_alloc(cell, sizeof(*clr));
00105       clr->opcode = CELL_CMD_CLEAR_SURFACE;
00106       clr->surface = surfIndex;
00107       clr->value = clearValue;
00108    }
00109 }

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