1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
34 /* This code is a prototype of what a passhthrough vertex shader might
37 * Probably the best approach for us is to do:
40 * - cliptest / viewport transform
42 * in one step, then examine the clipOrMask & choose between two paths:
45 * - build primitive headers
46 * - clip and the primitive path
47 * - build clipped vertex buffers,
48 * - vertex-emit to vbuf buffers
51 * - vertex-emit directly to vbuf buffers
53 * But when bypass clipping is enabled, we just take the latter
54 * choice. If (some new) passthrough-vertex-shader flag is also set,
55 * the pipeline degenerates to:
58 * - vertex emit to vbuf buffers
60 * Which is what is prototyped here.
62 #include "pipe/p_util.h"
63 #include "draw/draw_context.h"
64 #include "draw/draw_private.h"
65 #include "draw/draw_vbuf.h"
66 #include "draw/draw_vertex.h"
70 /* Example of a fetch/emit passthrough shader which could be
71 * generated when bypass_clipping is enabled on a passthrough vertex
74 static void fetch_xyz_rgb_st( struct draw_context
*draw
,
79 const unsigned *pitch
= draw
->vertex_fetch
.pitch
;
80 const ubyte
**src
= draw
->vertex_fetch
.src_ptr
;
83 const ubyte
*xyzw
= src
[0] + start
* pitch
[0];
84 const ubyte
*rgba
= src
[1] + start
* pitch
[1];
85 const ubyte
*st
= src
[2] + start
* pitch
[2];
87 /* loop over vertex attributes (vertex shader inputs)
89 for (i
= 0; i
< count
; i
++) {
91 const float *in
= (const float *)xyzw
; xyzw
+= pitch
[0];
92 /* decode input, encode output. Assume both are float[4] */
100 const float *in
= (const float *)rgba
; rgba
+= pitch
[1];
101 /* decode input, encode output. Assume both are float[4] */
109 const float *in
= (const float *)st
; st
+= pitch
[2];
110 /* decode input, encode output. Assume both are float[2] */
120 static boolean
update_shader( struct draw_context
*draw
)
122 const struct vertex_info
*vinfo
= draw
->render
->get_vertex_info(draw
->render
);
124 unsigned nr_attrs
= vinfo
->num_attribs
;
127 for (i
= 0; i
< nr_attrs
; i
++) {
128 unsigned buf
= draw
->vertex_element
[i
].vertex_buffer_index
;
130 draw
->vertex_fetch
.src_ptr
[i
] = (const ubyte
*) draw
->user
.vbuffer
[buf
] +
131 draw
->vertex_buffer
[buf
].buffer_offset
+
132 draw
->vertex_element
[i
].src_offset
;
134 draw
->vertex_fetch
.pitch
[i
] = draw
->vertex_buffer
[buf
].pitch
;
135 draw
->vertex_fetch
.fetch
[i
] = NULL
;
138 draw
->vertex_fetch
.nr_attrs
= nr_attrs
;
139 draw
->vertex_fetch
.fetch_func
= NULL
;
140 draw
->vertex_fetch
.pt_fetch
= NULL
;
142 draw
->pt
.hw_vertex_size
= vinfo
->size
* 4;
144 /* Just trying to figure out how this would work:
147 0 /* some other tests */)
149 draw
->vertex_fetch
.pt_fetch
= fetch_xyz_rgb_st
;
150 assert(vinfo
->size
== 10);
159 static boolean
set_prim( struct draw_context
*draw
,
162 assert(!draw
->user
.elts
);
164 draw
->pt
.prim
= prim
;
167 case PIPE_PRIM_LINE_LOOP
:
168 case PIPE_PRIM_QUADS
:
169 case PIPE_PRIM_QUAD_STRIP
:
172 draw
->render
->set_primitive( draw
->render
, prim
);
180 draw_passthrough_arrays(struct draw_context
*draw
,
187 if (!set_prim(draw
, prim
))
190 if (!update_shader( draw
))
193 hw_verts
= draw
->render
->allocate_vertices( draw
->render
,
194 draw
->pt
.hw_vertex_size
,
200 /* Single routine to fetch vertices, run shader and emit HW verts.
201 * Clipping and viewport transformation are done on hardware.
203 draw
->vertex_fetch
.pt_fetch( draw
,
207 /* Draw arrays path to avoid re-emitting index list again and
210 draw
->render
->draw_arrays( draw
->render
,
215 draw
->render
->release_vertices( draw
->render
,
217 draw
->pt
.hw_vertex_size
,