Path: blob/21.2-virgl/src/gallium/drivers/softpipe/sp_state_vertex.c
4570 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/* Authors: Keith Whitwell <[email protected]>28*/293031#include "sp_context.h"32#include "sp_state.h"3334#include "util/u_memory.h"35#include "util/u_helpers.h"36#include "util/u_inlines.h"37#include "util/u_transfer.h"38#include "draw/draw_context.h"394041static void *42softpipe_create_vertex_elements_state(struct pipe_context *pipe,43unsigned count,44const struct pipe_vertex_element *attribs)45{46struct sp_velems_state *velems;47assert(count <= PIPE_MAX_ATTRIBS);48velems = (struct sp_velems_state *) MALLOC(sizeof(struct sp_velems_state));49if (velems) {50velems->count = count;51memcpy(velems->velem, attribs, sizeof(*attribs) * count);52}53return velems;54}555657static void58softpipe_bind_vertex_elements_state(struct pipe_context *pipe,59void *velems)60{61struct softpipe_context *softpipe = softpipe_context(pipe);62struct sp_velems_state *sp_velems = (struct sp_velems_state *) velems;6364softpipe->velems = sp_velems;6566softpipe->dirty |= SP_NEW_VERTEX;6768if (sp_velems)69draw_set_vertex_elements(softpipe->draw, sp_velems->count, sp_velems->velem);70}717273static void74softpipe_delete_vertex_elements_state(struct pipe_context *pipe, void *velems)75{76FREE( velems );77}787980static void81softpipe_set_vertex_buffers(struct pipe_context *pipe,82unsigned start_slot, unsigned count,83unsigned unbind_num_trailing_slots,84bool take_ownership,85const struct pipe_vertex_buffer *buffers)86{87struct softpipe_context *softpipe = softpipe_context(pipe);8889assert(count <= PIPE_MAX_ATTRIBS);9091util_set_vertex_buffers_count(softpipe->vertex_buffer,92&softpipe->num_vertex_buffers,93buffers, start_slot, count,94unbind_num_trailing_slots,95take_ownership);9697softpipe->dirty |= SP_NEW_VERTEX;9899draw_set_vertex_buffers(softpipe->draw, start_slot, count,100unbind_num_trailing_slots, buffers);101}102103104void105softpipe_init_vertex_funcs(struct pipe_context *pipe)106{107pipe->create_vertex_elements_state = softpipe_create_vertex_elements_state;108pipe->bind_vertex_elements_state = softpipe_bind_vertex_elements_state;109pipe->delete_vertex_elements_state = softpipe_delete_vertex_elements_state;110111pipe->set_vertex_buffers = softpipe_set_vertex_buffers;112}113114115