1c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell/************************************************************************** 2c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 3c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 4c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * All Rights Reserved. 5c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 6c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 7c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * copy of this software and associated documentation files (the 8c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * "Software"), to deal in the Software without restriction, including 9c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 10c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 11c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * permit persons to whom the Software is furnished to do so, subject to 12c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * the following conditions: 13c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 14c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * The above copyright notice and this permission notice (including the 15c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * next paragraph) shall be included in all copies or substantial portions 16c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * of the Software. 17c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 18c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 26c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell **************************************************************************/ 27c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 284f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h" 29c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_context.h" 30c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_private.h" 31c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_vbuf.h" 32c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_vertex.h" 33c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_pt.h" 34c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "translate/translate.h" 355fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin#include "translate/translate_cache.h" 36c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 37c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellstruct pt_emit { 38c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct draw_context *draw; 39c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 40c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct translate *translate; 41f088b53769aacbee20135d912c33d688b6002011Zack Rusin 425fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin struct translate_cache *cache; 43d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell unsigned prim; 44fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell 45fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell const struct vertex_info *vinfo; 46c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell}; 47c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 48994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul 49994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paulvoid 50994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Pauldraw_pt_emit_prepare(struct pt_emit *emit, 51994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul unsigned prim, 52994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul unsigned *max_vertices) 53c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 54c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct draw_context *draw = emit->draw; 55c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell const struct vertex_info *vinfo; 56c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned dst_offset; 57c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct translate_key hw_key; 58c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned i; 59994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul 60994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 61aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell */ 62aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 63aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell 64d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell /* XXX: may need to defensively reset this later on as clipping can 65d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell * clobber this state in the render backend. 66d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell */ 67d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell emit->prim = prim; 68d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell 69488dd2c1912132fe7ee5e81b05fb64ba62a46098Brian Paul draw->render->set_primitive(draw->render, emit->prim); 70c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 71c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell /* Must do this after set_primitive() above: 72c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 73fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell emit->vinfo = vinfo = draw->render->get_vertex_info(draw->render); 747ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell 75cb9f0a589623397c3437911aeef39f189213527aKeith Whitwell /* Translate from pipeline vertices to hw vertices. 76c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 77c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell dst_offset = 0; 78c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell for (i = 0; i < vinfo->num_attribs; i++) { 79c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned emit_sz = 0; 80c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned src_buffer = 0; 81c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned output_format; 8253d4706c6c0922160f310834daaec5718ff1c511Keith Whitwell unsigned src_offset = (vinfo->attrib[i].src_index * 4 * sizeof(float) ); 83c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 8484a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit); 8584a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); 86c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 8784a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz /* doesn't handle EMIT_OMIT */ 8884a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz assert(emit_sz != 0); 8984a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz 9084a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) { 91c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell src_buffer = 1; 92c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell src_offset = 0; 93c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 94543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol 95543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL; 96c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 97c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_buffer = src_buffer; 98c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_offset = src_offset; 997ca0ce38340144794267609646048b3820d594abMichal Krol hw_key.element[i].instance_divisor = 0; 100c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].output_format = output_format; 101c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].output_offset = dst_offset; 102c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 103c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell dst_offset += emit_sz; 104c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 105c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 106c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.nr_elements = vinfo->num_attribs; 107c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.output_stride = vinfo->size * 4; 108c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 109c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!emit->translate || 110994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul translate_key_compare(&emit->translate->key, &hw_key) != 0) { 111994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul translate_key_sanitize(&hw_key); 112994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul emit->translate = translate_cache_find(emit->cache, &hw_key); 113994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul } 1140a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell 115994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul *max_vertices = (draw->render->max_vertex_buffer_bytes / 1160a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell (vinfo->size * 4)); 117c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 118c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 119c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 120994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paulvoid 121994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Pauldraw_pt_emit(struct pt_emit *emit, 122994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul const struct draw_vertex_info *vert_info, 123994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul const struct draw_prim_info *prim_info) 124c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 125b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const float (*vertex_data)[4] = (const float (*)[4])vert_info->verts->data; 126b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned vertex_count = vert_info->count; 127b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned stride = vert_info->stride; 128b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const ushort *elts = prim_info->elts; 129c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct draw_context *draw = emit->draw; 130c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct translate *translate = emit->translate; 131c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct vbuf_render *render = draw->render; 132b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned start, i; 133c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell void *hw_verts; 134c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 135994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 136c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 137c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 138c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 1391c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell if (vertex_count == 0) 1401c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell return; 1411c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell 142d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell /* XXX: and work out some way to coordinate the render primitive 143d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell * between vbuf.c and here... 144d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell */ 145488dd2c1912132fe7ee5e81b05fb64ba62a46098Brian Paul draw->render->set_primitive(draw->render, emit->prim); 146d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell 147befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell render->allocate_vertices(render, 148befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell (ushort)translate->key.output_stride, 149befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell (ushort)vertex_count); 150befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 151befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell hw_verts = render->map_vertices( render ); 152c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!hw_verts) { 153f0f623a9075107461438468e1aea6bca3a3234f3Brian Paul debug_warn_once("map of vertex buffer failed (out of memory?)"); 154c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return; 155c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 156c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 157994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul translate->set_buffer(translate, 158994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul 0, 159a773f06e969a3992451dd7fe6fd55ea96b2774faKeith Whitwell vertex_data, 1602a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca stride, 1612a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca ~0); 162c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 163994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul translate->set_buffer(translate, 164994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul 1, 165c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell &draw->rasterizer->point_size, 1662a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca 0, 1672a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca ~0); 168c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 1698c3cc83432bbbc190b0f71f87e3e9583ae11f0b2Brian Paul /* fetch/translate vertex attribs to fill hw_verts[] */ 170994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul translate->run(translate, 171994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul 0, 172994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul vertex_count, 173994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul draw->instance_id, 174994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul hw_verts ); 175c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 176994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul render->unmap_vertices(render, 0, vertex_count - 1); 177befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 178b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell for (start = i = 0; 179b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell i < prim_info->primitive_count; 180b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell start += prim_info->primitive_lengths[i], i++) 181b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell { 182b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell render->draw_elements(render, 183b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell elts + start, 184b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell prim_info->primitive_lengths[i]); 185b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell } 186c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 187befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell render->release_vertices(render); 188c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 189c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 190c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 191994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paulvoid 192994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Pauldraw_pt_emit_linear(struct pt_emit *emit, 193994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul const struct draw_vertex_info *vert_info, 194994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul const struct draw_prim_info *prim_info) 195abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin{ 196b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const float (*vertex_data)[4] = (const float (*)[4])vert_info->verts->data; 197b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned stride = vert_info->stride; 198b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned count = vert_info->count; 199abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct draw_context *draw = emit->draw; 200abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct translate *translate = emit->translate; 201abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct vbuf_render *render = draw->render; 202abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin void *hw_verts; 203b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned start, i; 204abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 20566d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin#if 0 20666d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin debug_printf("Linear emit\n"); 20766d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin#endif 208994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 209abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin */ 210abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 211abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 21293bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell /* XXX: and work out some way to coordinate the render primitive 21393bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell * between vbuf.c and here... 21493bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell */ 215488dd2c1912132fe7ee5e81b05fb64ba62a46098Brian Paul draw->render->set_primitive(draw->render, emit->prim); 21693bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell 217befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell if (!render->allocate_vertices(render, 218befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell (ushort)translate->key.output_stride, 219befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell (ushort)count)) 220befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell goto fail; 221befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 222befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell hw_verts = render->map_vertices( render ); 223befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell if (!hw_verts) 224befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell goto fail; 225abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 226abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->set_buffer(translate, 0, 2272a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca vertex_data, stride, count - 1); 228abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 229abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->set_buffer(translate, 1, 230abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin &draw->rasterizer->point_size, 2312a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca 0, ~0); 232abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 233abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->run(translate, 234abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 0, 235befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell count, 2367ca0ce38340144794267609646048b3820d594abMichal Krol draw->instance_id, 237abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin hw_verts); 238abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 239fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell if (0) { 240fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell unsigned i; 241befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell for (i = 0; i < count; i++) { 242fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell debug_printf("\n\n%s vertex %d:\n", __FUNCTION__, i); 243994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul draw_dump_emitted_vertex( emit->vinfo, 244994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul (const uint8_t *)hw_verts + 245fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell translate->key.output_stride * i ); 246fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell } 247fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell } 248fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell 2491c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell render->unmap_vertices( render, 0, count - 1 ); 250befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 251b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell for (start = i = 0; 252b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell i < prim_info->primitive_count; 253b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell start += prim_info->primitive_lengths[i], i++) 254b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell { 255b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell render->draw_arrays(render, 256b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell start, 257b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell prim_info->primitive_lengths[i]); 258b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell } 259befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 260befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell render->release_vertices(render); 261fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell 262befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell return; 263abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 264befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwellfail: 265f0f623a9075107461438468e1aea6bca3a3234f3Brian Paul debug_warn_once("allocate or map of vertex buffer failed (out of memory?)"); 266befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell return; 267abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin} 268abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 269994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul 270994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paulstruct pt_emit * 271994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Pauldraw_pt_emit_create(struct draw_context *draw) 272c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 273c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct pt_emit *emit = CALLOC_STRUCT(pt_emit); 274c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!emit) 275c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return NULL; 276c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 277c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit->draw = draw; 2785fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin emit->cache = translate_cache_create(); 27995f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin if (!emit->cache) { 28095f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin FREE(emit); 28195f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin return NULL; 28295f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin } 283c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 284c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return emit; 285c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 286c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 287994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paul 288994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Paulvoid 289994c33db875c6af2f5b535a7a173ff3bfa24fc32Brian Pauldraw_pt_emit_destroy(struct pt_emit *emit) 290c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 2917ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell if (emit->cache) 2927ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell translate_cache_destroy(emit->cache); 293c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 294c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell FREE(emit); 295c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 296