draw_pt_emit.c revision f1401385587882bb9d18a5f5b01dcbb71ddf0a2f
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 28c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "pipe/p_util.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 48c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellvoid draw_pt_emit_prepare( struct pt_emit *emit, 490a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell unsigned prim, 500a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell unsigned *max_vertices ) 51c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 52c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct draw_context *draw = emit->draw; 53c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell const struct vertex_info *vinfo; 54c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned dst_offset; 55c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct translate_key hw_key; 56c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned i; 57c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell boolean ok; 58d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell 59aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 60aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell */ 61aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 62aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell 63c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith 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 69d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell ok = draw->render->set_primitive(draw->render, emit->prim); 70c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!ok) { 71c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell assert(0); 72c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return; 73c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 74c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 75c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell /* Must do this after set_primitive() above: 76c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 77fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell emit->vinfo = vinfo = draw->render->get_vertex_info(draw->render); 787ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell 79c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 80cb9f0a589623397c3437911aeef39f189213527aKeith Whitwell /* Translate from pipeline vertices to hw vertices. 81c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 82c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell dst_offset = 0; 83c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell for (i = 0; i < vinfo->num_attribs; i++) { 84c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned emit_sz = 0; 85c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned src_buffer = 0; 86c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned output_format; 87a773f06e969a3992451dd7fe6fd55ea96b2774faKeith Whitwell unsigned src_offset = (vinfo->src_index[i] * 4 * sizeof(float) ); 88c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 89c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 90c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 91c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell switch (vinfo->emit[i]) { 92c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell case EMIT_4F: 93c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 94c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit_sz = 4 * sizeof(float); 95c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell break; 96c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell case EMIT_3F: 97c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell output_format = PIPE_FORMAT_R32G32B32_FLOAT; 98c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit_sz = 3 * sizeof(float); 99c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell break; 100c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell case EMIT_2F: 101c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell output_format = PIPE_FORMAT_R32G32_FLOAT; 102c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit_sz = 2 * sizeof(float); 103c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell break; 104c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell case EMIT_1F: 105c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell output_format = PIPE_FORMAT_R32_FLOAT; 106c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit_sz = 1 * sizeof(float); 107c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell break; 108c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell case EMIT_1F_PSIZE: 109c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell output_format = PIPE_FORMAT_R32_FLOAT; 110c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit_sz = 1 * sizeof(float); 111c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell src_buffer = 1; 112c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell src_offset = 0; 113c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell break; 114c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell case EMIT_4UB: 115c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell output_format = PIPE_FORMAT_B8G8R8A8_UNORM; 116c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit_sz = 4 * sizeof(ubyte); 117529762d5df6d9427f9fa0927e38b9886e412a6bcKeith Whitwell break; 118c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell default: 119c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell assert(0); 120c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell output_format = PIPE_FORMAT_NONE; 121c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit_sz = 0; 122c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell break; 123c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 124c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 125c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 126c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_buffer = src_buffer; 127c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_offset = src_offset; 128c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].output_format = output_format; 129c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].output_offset = dst_offset; 130c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 131c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell dst_offset += emit_sz; 132c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 133c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 134c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.nr_elements = vinfo->num_attribs; 135c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.output_stride = vinfo->size * 4; 136c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 137c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!emit->translate || 1387ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell translate_key_compare(&emit->translate->key, &hw_key) != 0) 139c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell { 1407ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell translate_key_sanitize(&hw_key); 1415fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin emit->translate = translate_cache_find(emit->cache, &hw_key); 142c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 1430a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell 1440a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell *max_vertices = (draw->render->max_vertex_buffer_bytes / 1450a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell (vinfo->size * 4)); 146f1401385587882bb9d18a5f5b01dcbb71ddf0a2fBrian Paul 147f1401385587882bb9d18a5f5b01dcbb71ddf0a2fBrian Paul /* even number */ 148f1401385587882bb9d18a5f5b01dcbb71ddf0a2fBrian Paul *max_vertices = *max_vertices & ~1; 149c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 150c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 151c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 152c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellvoid draw_pt_emit( struct pt_emit *emit, 153a773f06e969a3992451dd7fe6fd55ea96b2774faKeith Whitwell const float (*vertex_data)[4], 154c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned vertex_count, 155a773f06e969a3992451dd7fe6fd55ea96b2774faKeith Whitwell unsigned stride, 156c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell const ushort *elts, 157c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned count ) 158c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 159c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct draw_context *draw = emit->draw; 160c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct translate *translate = emit->translate; 161c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct vbuf_render *render = draw->render; 162c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell void *hw_verts; 163c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 164c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 165c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 166c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 167c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 168d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell /* XXX: and work out some way to coordinate the render primitive 169d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell * between vbuf.c and here... 170d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell */ 171d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell if (!draw->render->set_primitive(draw->render, emit->prim)) { 172d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell assert(0); 173d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell return; 174d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell } 175d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell 176c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_verts = render->allocate_vertices(render, 177c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell (ushort)translate->key.output_stride, 1787462f0557f9cce73ff2d32e62ef110b5d8622f87Michel Dänzer (ushort)vertex_count); 179c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!hw_verts) { 180c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell assert(0); 181c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return; 182c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 183c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 184c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell translate->set_buffer(translate, 185c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 0, 186a773f06e969a3992451dd7fe6fd55ea96b2774faKeith Whitwell vertex_data, 187c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell stride ); 188c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 189c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell translate->set_buffer(translate, 190c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 1, 191c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell &draw->rasterizer->point_size, 192c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 0); 193c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 194c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell translate->run( translate, 195c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 0, 196c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell vertex_count, 197c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_verts ); 198c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 199c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell render->draw(render, 200c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell elts, 201c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell count); 202c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 203c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell render->release_vertices(render, 204c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_verts, 205c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell translate->key.output_stride, 206c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell vertex_count); 207c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 208c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 209c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 210abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusinvoid draw_pt_emit_linear(struct pt_emit *emit, 211abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin const float (*vertex_data)[4], 212abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin unsigned vertex_count, 213abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin unsigned stride, 214abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin unsigned start, 215abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin unsigned count) 216abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin{ 217abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct draw_context *draw = emit->draw; 218abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct translate *translate = emit->translate; 219abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct vbuf_render *render = draw->render; 220abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin void *hw_verts; 221abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 22266d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin#if 0 22366d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin debug_printf("Linear emit\n"); 22466d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin#endif 225abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 226abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin */ 227abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 228abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 22993bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell /* XXX: and work out some way to coordinate the render primitive 23093bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell * between vbuf.c and here... 23193bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell */ 23293bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell if (!draw->render->set_primitive(draw->render, emit->prim)) { 23393bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell assert(0); 23493bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell return; 23593bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell } 23693bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell 237abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin hw_verts = render->allocate_vertices(render, 238abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin (ushort)translate->key.output_stride, 239abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin (ushort)count); 240abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin if (!hw_verts) { 241abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin assert(0); 242abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin return; 243abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin } 244abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 245abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->set_buffer(translate, 0, 246abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin vertex_data, stride); 247abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 248abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->set_buffer(translate, 1, 249abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin &draw->rasterizer->point_size, 250abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 0); 251abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 252abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->run(translate, 253abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 0, 254abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin vertex_count, 255abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin hw_verts); 256abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 257fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell if (0) { 258fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell unsigned i; 259fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell for (i = 0; i < vertex_count; i++) { 260fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell debug_printf("\n\n%s vertex %d:\n", __FUNCTION__, i); 261fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell draw_dump_emitted_vertex( emit->vinfo, 262fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell (const uint8_t *)hw_verts + 263fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell translate->key.output_stride * i ); 264fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell } 265fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell } 266fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell 267fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell 268abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin render->draw_arrays(render, start, count); 269abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 270abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin render->release_vertices(render, 271abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin hw_verts, 272abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->key.output_stride, 273abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin vertex_count); 274abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin} 275abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 276c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellstruct pt_emit *draw_pt_emit_create( struct draw_context *draw ) 277c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 278c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct pt_emit *emit = CALLOC_STRUCT(pt_emit); 279c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!emit) 280c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return NULL; 281c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 282c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit->draw = draw; 2835fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin emit->cache = translate_cache_create(); 28495f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin if (!emit->cache) { 28595f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin FREE(emit); 28695f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin return NULL; 28795f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin } 288c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 289c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return emit; 290c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 291c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 292c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellvoid draw_pt_emit_destroy( struct pt_emit *emit ) 293c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 2947ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell if (emit->cache) 2957ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell translate_cache_destroy(emit->cache); 296c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 297c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell FREE(emit); 298c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 299