Path: blob/21.2-virgl/src/gallium/auxiliary/draw/draw_pipe_util.c
4565 views
/**************************************************************************1*2* Copyright 2007 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/*28* Authors:29* Keith Whitwell <[email protected]>30*/3132#include "util/u_memory.h"33#include "draw/draw_private.h"34#include "draw/draw_pipe.h"35363738void39draw_pipe_passthrough_point(struct draw_stage *stage, struct prim_header *header)40{41stage->next->point(stage->next, header);42}4344void45draw_pipe_passthrough_line(struct draw_stage *stage, struct prim_header *header)46{47stage->next->line(stage->next, header);48}4950void51draw_pipe_passthrough_tri(struct draw_stage *stage, struct prim_header *header)52{53stage->next->tri(stage->next, header);54}555657585960/* This is only used for temporary verts.61*/62#define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))636465/**66* Allocate space for temporary post-transform vertices, such as for clipping.67*/68boolean draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr )69{70assert(!stage->tmp);7172stage->tmp = NULL;73stage->nr_tmps = nr;7475if (nr != 0)76{77unsigned i;78ubyte *store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr +79DRAW_EXTRA_VERTICES_PADDING );80if (!store)81return FALSE;8283stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr );84if (stage->tmp == NULL) {85FREE(store);86return FALSE;87}8889for (i = 0; i < nr; i++)90stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);91}9293return TRUE;94}959697void draw_free_temp_verts( struct draw_stage *stage )98{99if (stage->tmp) {100FREE( stage->tmp[0] );101FREE( stage->tmp );102stage->tmp = NULL;103}104}105106107/* Reset vertex ids. This is basically a type of flush.108*109* Called only from draw_pipe_vbuf.c110*/111void draw_reset_vertex_ids(struct draw_context *draw)112{113struct draw_stage *stage = draw->pipeline.first;114115while (stage) {116unsigned i;117118for (i = 0; i < stage->nr_tmps; i++)119stage->tmp[i]->vertex_id = UNDEFINED_VERTEX_ID;120121stage = stage->next;122}123124if (draw->pipeline.verts)125{126unsigned i;127char *verts = draw->pipeline.verts;128unsigned stride = draw->pipeline.vertex_stride;129130for (i = 0; i < draw->pipeline.vertex_count; i++) {131((struct vertex_header *)verts)->vertex_id = UNDEFINED_VERTEX_ID;132verts += stride;133}134}135}136137138139