1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci/* Authors: Keith Whitwell <keithw@vmware.com> 29bf215546Sopenharmony_ci */ 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "sp_context.h" 33bf215546Sopenharmony_ci#include "sp_state.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci#include "util/u_memory.h" 36bf215546Sopenharmony_ci#include "util/u_helpers.h" 37bf215546Sopenharmony_ci#include "util/u_inlines.h" 38bf215546Sopenharmony_ci#include "util/u_transfer.h" 39bf215546Sopenharmony_ci#include "draw/draw_context.h" 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_cistatic void * 43bf215546Sopenharmony_cisoftpipe_create_vertex_elements_state(struct pipe_context *pipe, 44bf215546Sopenharmony_ci unsigned count, 45bf215546Sopenharmony_ci const struct pipe_vertex_element *attribs) 46bf215546Sopenharmony_ci{ 47bf215546Sopenharmony_ci struct sp_velems_state *velems; 48bf215546Sopenharmony_ci assert(count <= PIPE_MAX_ATTRIBS); 49bf215546Sopenharmony_ci velems = (struct sp_velems_state *) MALLOC(sizeof(struct sp_velems_state)); 50bf215546Sopenharmony_ci if (velems) { 51bf215546Sopenharmony_ci velems->count = count; 52bf215546Sopenharmony_ci memcpy(velems->velem, attribs, sizeof(*attribs) * count); 53bf215546Sopenharmony_ci } 54bf215546Sopenharmony_ci return velems; 55bf215546Sopenharmony_ci} 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_cistatic void 59bf215546Sopenharmony_cisoftpipe_bind_vertex_elements_state(struct pipe_context *pipe, 60bf215546Sopenharmony_ci void *velems) 61bf215546Sopenharmony_ci{ 62bf215546Sopenharmony_ci struct softpipe_context *softpipe = softpipe_context(pipe); 63bf215546Sopenharmony_ci struct sp_velems_state *sp_velems = (struct sp_velems_state *) velems; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci softpipe->velems = sp_velems; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci softpipe->dirty |= SP_NEW_VERTEX; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci if (sp_velems) 70bf215546Sopenharmony_ci draw_set_vertex_elements(softpipe->draw, sp_velems->count, sp_velems->velem); 71bf215546Sopenharmony_ci} 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_cistatic void 75bf215546Sopenharmony_cisoftpipe_delete_vertex_elements_state(struct pipe_context *pipe, void *velems) 76bf215546Sopenharmony_ci{ 77bf215546Sopenharmony_ci FREE( velems ); 78bf215546Sopenharmony_ci} 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_cistatic void 82bf215546Sopenharmony_cisoftpipe_set_vertex_buffers(struct pipe_context *pipe, 83bf215546Sopenharmony_ci unsigned start_slot, unsigned count, 84bf215546Sopenharmony_ci unsigned unbind_num_trailing_slots, 85bf215546Sopenharmony_ci bool take_ownership, 86bf215546Sopenharmony_ci const struct pipe_vertex_buffer *buffers) 87bf215546Sopenharmony_ci{ 88bf215546Sopenharmony_ci struct softpipe_context *softpipe = softpipe_context(pipe); 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci assert(count <= PIPE_MAX_ATTRIBS); 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci util_set_vertex_buffers_count(softpipe->vertex_buffer, 93bf215546Sopenharmony_ci &softpipe->num_vertex_buffers, 94bf215546Sopenharmony_ci buffers, start_slot, count, 95bf215546Sopenharmony_ci unbind_num_trailing_slots, 96bf215546Sopenharmony_ci take_ownership); 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci softpipe->dirty |= SP_NEW_VERTEX; 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ci draw_set_vertex_buffers(softpipe->draw, start_slot, count, 101bf215546Sopenharmony_ci unbind_num_trailing_slots, buffers); 102bf215546Sopenharmony_ci} 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_civoid 106bf215546Sopenharmony_cisoftpipe_init_vertex_funcs(struct pipe_context *pipe) 107bf215546Sopenharmony_ci{ 108bf215546Sopenharmony_ci pipe->create_vertex_elements_state = softpipe_create_vertex_elements_state; 109bf215546Sopenharmony_ci pipe->bind_vertex_elements_state = softpipe_bind_vertex_elements_state; 110bf215546Sopenharmony_ci pipe->delete_vertex_elements_state = softpipe_delete_vertex_elements_state; 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci pipe->set_vertex_buffers = softpipe_set_vertex_buffers; 113bf215546Sopenharmony_ci} 114