nvfx: expose GLSL
[mesa/mesa-lb.git] / src / gallium / drivers / svga / svga_swtnl_draw.c
blobda15be155c8e7c34a17c9fbc522da20f2c1cdc46
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
24 **********************************************************/
26 #include "draw/draw_context.h"
27 #include "draw/draw_vbuf.h"
28 #include "util/u_inlines.h"
29 #include "pipe/p_state.h"
31 #include "svga_context.h"
32 #include "svga_swtnl.h"
33 #include "svga_state.h"
34 #include "svga_swtnl_private.h"
38 enum pipe_error
39 svga_swtnl_draw_range_elements(struct svga_context *svga,
40 struct pipe_buffer *indexBuffer,
41 unsigned indexSize,
42 unsigned min_index,
43 unsigned max_index,
44 unsigned prim, unsigned start, unsigned count)
46 struct draw_context *draw = svga->swtnl.draw;
47 unsigned i;
48 const void *map;
49 enum pipe_error ret;
51 assert(!svga->dirty);
52 assert(svga->state.sw.need_swtnl);
53 assert(draw);
55 ret = svga_update_state(svga, SVGA_STATE_SWTNL_DRAW);
56 if (ret) {
57 svga_context_flush(svga, NULL);
58 ret = svga_update_state(svga, SVGA_STATE_SWTNL_DRAW);
59 svga->swtnl.new_vbuf = TRUE;
60 assert(ret == PIPE_OK);
64 * Map vertex buffers
66 for (i = 0; i < svga->curr.num_vertex_buffers; i++) {
67 map = pipe_buffer_map(svga->pipe.screen,
68 svga->curr.vb[i].buffer,
69 PIPE_BUFFER_USAGE_CPU_READ);
71 draw_set_mapped_vertex_buffer(draw, i, map);
74 /* Map index buffer, if present */
75 if (indexBuffer) {
76 map = pipe_buffer_map(svga->pipe.screen, indexBuffer,
77 PIPE_BUFFER_USAGE_CPU_READ);
79 draw_set_mapped_element_buffer_range(draw,
80 indexSize,
81 min_index,
82 max_index,
83 map);
86 if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
87 map = pipe_buffer_map(svga->pipe.screen,
88 svga->curr.cb[PIPE_SHADER_VERTEX],
89 PIPE_BUFFER_USAGE_CPU_READ);
90 assert(map);
91 draw_set_mapped_constant_buffer(
92 draw, PIPE_SHADER_VERTEX, 0,
93 map,
94 svga->curr.cb[PIPE_SHADER_VERTEX]->size);
97 draw_arrays(svga->swtnl.draw, prim, start, count);
99 draw_flush(svga->swtnl.draw);
101 /* Ensure the draw module didn't touch this */
102 assert(i == svga->curr.num_vertex_buffers);
105 * unmap vertex/index buffers
107 for (i = 0; i < svga->curr.num_vertex_buffers; i++) {
108 pipe_buffer_unmap(svga->pipe.screen, svga->curr.vb[i].buffer);
109 draw_set_mapped_vertex_buffer(draw, i, NULL);
112 if (indexBuffer) {
113 pipe_buffer_unmap(svga->pipe.screen, indexBuffer);
114 draw_set_mapped_element_buffer(draw, 0, NULL);
117 if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
118 pipe_buffer_unmap(svga->pipe.screen,
119 svga->curr.cb[PIPE_SHADER_VERTEX]);
122 return ret;
128 boolean svga_init_swtnl( struct svga_context *svga )
130 svga->swtnl.backend = svga_vbuf_render_create(svga);
131 if(!svga->swtnl.backend)
132 goto fail;
135 * Create drawing context and plug our rendering stage into it.
137 svga->swtnl.draw = draw_create();
138 if (svga->swtnl.draw == NULL)
139 goto fail;
142 draw_set_rasterize_stage(svga->swtnl.draw,
143 draw_vbuf_stage( svga->swtnl.draw, svga->swtnl.backend ));
145 draw_set_render(svga->swtnl.draw, svga->swtnl.backend);
147 draw_install_aaline_stage(svga->swtnl.draw, &svga->pipe);
148 draw_install_aapoint_stage(svga->swtnl.draw, &svga->pipe);
149 draw_install_pstipple_stage(svga->swtnl.draw, &svga->pipe);
151 draw_set_driver_clipping(svga->swtnl.draw, debug_get_bool_option("SVGA_SWTNL_FSE", FALSE));
153 return TRUE;
155 fail:
156 if (svga->swtnl.backend)
157 svga->swtnl.backend->destroy( svga->swtnl.backend );
159 if (svga->swtnl.draw)
160 draw_destroy( svga->swtnl.draw );
162 return FALSE;
166 void svga_destroy_swtnl( struct svga_context *svga )
168 draw_destroy( svga->swtnl.draw );