Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_draw_quad.c
4561 views
/**************************************************************************1*2* Copyright 2008 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**************************************************************************/262728#include "pipe/p_context.h"29#include "pipe/p_defines.h"30#include "util/u_inlines.h"31#include "util/u_draw_quad.h"32#include "util/u_memory.h"33#include "cso_cache/cso_context.h"343536/**37* Draw a simple vertex buffer / primitive.38* Limited to float[4] vertex attribs, tightly packed.39*/40void41util_draw_vertex_buffer(struct pipe_context *pipe,42struct cso_context *cso,43struct pipe_resource *vbuf,44uint vbuf_slot,45uint offset,46uint prim_type,47uint num_verts,48uint num_attribs)49{50struct pipe_vertex_buffer vbuffer;5152assert(num_attribs <= PIPE_MAX_ATTRIBS);5354/* tell pipe about the vertex buffer */55memset(&vbuffer, 0, sizeof(vbuffer));56vbuffer.buffer.resource = vbuf;57vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */58vbuffer.buffer_offset = offset;5960/* note: vertex elements already set by caller */6162if (cso) {63cso_set_vertex_buffers(cso, vbuf_slot, 1, &vbuffer);64cso_draw_arrays(cso, prim_type, 0, num_verts);65} else {66pipe->set_vertex_buffers(pipe, vbuf_slot, 1, 0, false, &vbuffer);67util_draw_arrays(pipe, prim_type, 0, num_verts);68}69}707172/**73* Draw a simple vertex buffer / primitive.74* Limited to float[4] vertex attribs, tightly packed.75*/76void77util_draw_user_vertex_buffer(struct cso_context *cso, void *buffer,78uint prim_type, uint num_verts, uint num_attribs)79{80struct pipe_vertex_buffer vbuffer = {0};8182assert(num_attribs <= PIPE_MAX_ATTRIBS);8384vbuffer.is_user_buffer = true;85vbuffer.buffer.user = buffer;86vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */8788/* note: vertex elements already set by caller */8990cso_set_vertex_buffers(cso, 0, 1, &vbuffer);91cso_draw_arrays(cso, prim_type, 0, num_verts);92}939495