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 00028 /* 00029 * Authors: 00030 * Keith Whitwell <keith@tungstengraphics.com> 00031 */ 00032 00033 #include "util/u_memory.h" 00034 #include "draw/draw_private.h" 00035 #include "draw/draw_pipe.h" 00036 00037 00038 00039 void 00040 draw_pipe_passthrough_point(struct draw_stage *stage, struct prim_header *header) 00041 { 00042 stage->next->point(stage->next, header); 00043 } 00044 00045 void 00046 draw_pipe_passthrough_line(struct draw_stage *stage, struct prim_header *header) 00047 { 00048 stage->next->line(stage->next, header); 00049 } 00050 00051 void 00052 draw_pipe_passthrough_tri(struct draw_stage *stage, struct prim_header *header) 00053 { 00054 stage->next->tri(stage->next, header); 00055 } 00056 00057 00058 00059 00060 00061 /* This is only used for temporary verts. 00062 */ 00063 #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float)) 00064 00065 00069 boolean draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr ) 00070 { 00071 assert(!stage->tmp); 00072 00073 stage->tmp = NULL; 00074 stage->nr_tmps = nr; 00075 00076 if (nr != 0) 00077 { 00078 unsigned i; 00079 ubyte *store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr ); 00080 00081 if (store == NULL) 00082 return FALSE; 00083 00084 stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr ); 00085 if (stage->tmp == NULL) { 00086 FREE(store); 00087 return FALSE; 00088 } 00089 00090 for (i = 0; i < nr; i++) 00091 stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE); 00092 } 00093 00094 return TRUE; 00095 } 00096 00097 00098 void draw_free_temp_verts( struct draw_stage *stage ) 00099 { 00100 if (stage->tmp) { 00101 FREE( stage->tmp[0] ); 00102 FREE( stage->tmp ); 00103 stage->tmp = NULL; 00104 } 00105 } 00106 00107 00108 /* Reset vertex ids. This is basically a type of flush. 00109 * 00110 * Called only from draw_pipe_vbuf.c 00111 */ 00112 void draw_reset_vertex_ids(struct draw_context *draw) 00113 { 00114 struct draw_stage *stage = draw->pipeline.first; 00115 00116 while (stage) { 00117 unsigned i; 00118 00119 for (i = 0; i < stage->nr_tmps; i++) 00120 stage->tmp[i]->vertex_id = UNDEFINED_VERTEX_ID; 00121 00122 stage = stage->next; 00123 } 00124 00125 if (draw->pipeline.verts) 00126 { 00127 unsigned i; 00128 char *verts = draw->pipeline.verts; 00129 unsigned stride = draw->pipeline.vertex_stride; 00130 00131 for (i = 0; i < draw->pipeline.vertex_count; i++) { 00132 ((struct vertex_header *)verts)->vertex_id = UNDEFINED_VERTEX_ID; 00133 verts += stride; 00134 } 00135 } 00136 } 00137