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 "lp_context.h"
33bf215546Sopenharmony_ci#include "lp_state.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include "draw/draw_context.h"
36bf215546Sopenharmony_ci#include "util/u_helpers.h"
37bf215546Sopenharmony_ci#include "util/u_inlines.h"
38bf215546Sopenharmony_ci#include "util/u_transfer.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_cistatic void *
42bf215546Sopenharmony_cillvmpipe_create_vertex_elements_state(struct pipe_context *pipe,
43bf215546Sopenharmony_ci                                      unsigned count,
44bf215546Sopenharmony_ci                                      const struct pipe_vertex_element *attribs)
45bf215546Sopenharmony_ci{
46bf215546Sopenharmony_ci   struct lp_velems_state *velems;
47bf215546Sopenharmony_ci   assert(count <= PIPE_MAX_ATTRIBS);
48bf215546Sopenharmony_ci   velems = (struct lp_velems_state *) MALLOC(sizeof(struct lp_velems_state));
49bf215546Sopenharmony_ci   if (velems) {
50bf215546Sopenharmony_ci      velems->count = count;
51bf215546Sopenharmony_ci      memcpy(velems->velem, attribs, sizeof(*attribs) * count);
52bf215546Sopenharmony_ci   }
53bf215546Sopenharmony_ci   return velems;
54bf215546Sopenharmony_ci}
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_cistatic void
57bf215546Sopenharmony_cillvmpipe_bind_vertex_elements_state(struct pipe_context *pipe,
58bf215546Sopenharmony_ci                                    void *velems)
59bf215546Sopenharmony_ci{
60bf215546Sopenharmony_ci   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
61bf215546Sopenharmony_ci   struct lp_velems_state *lp_velems = (struct lp_velems_state *) velems;
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci   llvmpipe->velems = lp_velems;
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci   llvmpipe->dirty |= LP_NEW_VERTEX;
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci   if (velems)
68bf215546Sopenharmony_ci      draw_set_vertex_elements(llvmpipe->draw, lp_velems->count, lp_velems->velem);
69bf215546Sopenharmony_ci}
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_cistatic void
72bf215546Sopenharmony_cillvmpipe_delete_vertex_elements_state(struct pipe_context *pipe, void *velems)
73bf215546Sopenharmony_ci{
74bf215546Sopenharmony_ci   FREE( velems );
75bf215546Sopenharmony_ci}
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_cistatic void
78bf215546Sopenharmony_cillvmpipe_set_vertex_buffers(struct pipe_context *pipe,
79bf215546Sopenharmony_ci                            unsigned start_slot, unsigned count,
80bf215546Sopenharmony_ci                            unsigned unbind_num_trailing_slots,
81bf215546Sopenharmony_ci                            bool take_ownership,
82bf215546Sopenharmony_ci                            const struct pipe_vertex_buffer *buffers)
83bf215546Sopenharmony_ci{
84bf215546Sopenharmony_ci   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   assert(count <= PIPE_MAX_ATTRIBS);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   util_set_vertex_buffers_count(llvmpipe->vertex_buffer,
89bf215546Sopenharmony_ci                                 &llvmpipe->num_vertex_buffers,
90bf215546Sopenharmony_ci                                 buffers, start_slot, count,
91bf215546Sopenharmony_ci                                 unbind_num_trailing_slots,
92bf215546Sopenharmony_ci                                 take_ownership);
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci   llvmpipe->dirty |= LP_NEW_VERTEX;
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci   draw_set_vertex_buffers(llvmpipe->draw, start_slot, count,
97bf215546Sopenharmony_ci                           unbind_num_trailing_slots, buffers);
98bf215546Sopenharmony_ci}
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_civoid
102bf215546Sopenharmony_cillvmpipe_init_vertex_funcs(struct llvmpipe_context *llvmpipe)
103bf215546Sopenharmony_ci{
104bf215546Sopenharmony_ci   llvmpipe->pipe.create_vertex_elements_state = llvmpipe_create_vertex_elements_state;
105bf215546Sopenharmony_ci   llvmpipe->pipe.bind_vertex_elements_state = llvmpipe_bind_vertex_elements_state;
106bf215546Sopenharmony_ci   llvmpipe->pipe.delete_vertex_elements_state = llvmpipe_delete_vertex_elements_state;
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci   llvmpipe->pipe.set_vertex_buffers = llvmpipe_set_vertex_buffers;
109bf215546Sopenharmony_ci}
110