llvmpipe: import experimental softpipe rasterizer code, wip binning code
[mesa.git] / src / gallium / drivers / llvmpipe / lp_setup.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /**
29 * \brief Primitive rasterization/rendering (points, lines)
30 *
31 * \author Keith Whitwell <keith@tungstengraphics.com>
32 * \author Brian Paul
33 */
34
35 #include "lp_context.h"
36 #include "lp_quad.h"
37 #include "lp_quad_pipe.h"
38 #include "lp_setup.h"
39 #include "lp_state.h"
40 #include "draw/draw_context.h"
41 #include "draw/draw_private.h"
42 #include "draw/draw_vertex.h"
43 #include "pipe/p_shader_tokens.h"
44 #include "pipe/p_thread.h"
45 #include "util/u_math.h"
46 #include "util/u_memory.h"
47
48
49 #define DEBUG_VERTS 0
50
51 /* Stubs for lines & points for now:
52 */
53 void
54 llvmpipe_setup_point(struct setup_context *setup,
55 const float (*v0)[4])
56 {
57 }
58
59 void
60 llvmpipe_setup_line(struct setup_context *setup,
61 const float (*v0)[4],
62 const float (*v1)[4])
63 {
64 }
65
66
67 /* Called after statechange, before emitting primitives. If binning
68 * is active, this function should store relevant state in the binning
69 * context.
70 *
71 * That includes:
72 * - current fragment shader function
73 * - bound constant buffer contents
74 * - bound textures
75 * - blend color
76 * - etc.
77 *
78 * Basically everything needed at some point in the future to
79 * rasterize triangles for the current state.
80 *
81 * Additionally this will set up the state needed for the rasterizer
82 * to process and bin incoming triangles. That would include such
83 * things as:
84 * - cull mode
85 * - ???
86 * - etc.
87 *
88 */
89 void setup_prepare( struct setup_context *setup )
90 {
91 struct llvmpipe_context *lp = setup->llvmpipe;
92
93 if (lp->dirty) {
94 llvmpipe_update_derived(lp);
95 }
96
97 lp->quad.first->begin( lp->quad.first );
98
99 if (lp->reduced_api_prim == PIPE_PRIM_TRIANGLES &&
100 lp->rasterizer->fill_cw == PIPE_POLYGON_MODE_FILL &&
101 lp->rasterizer->fill_ccw == PIPE_POLYGON_MODE_FILL) {
102 /* we'll do culling */
103 setup->winding = lp->rasterizer->cull_mode;
104 }
105 else {
106 /* 'draw' will do culling */
107 setup->winding = PIPE_WINDING_NONE;
108 }
109
110 setup_prepare_tri( setup->llvmpipe );
111 }
112
113
114
115 void setup_destroy_context( struct setup_context *setup )
116 {
117 FREE( setup );
118 }
119
120
121 /**
122 * Create a new primitive setup/render stage.
123 */
124 struct setup_context *setup_create_context( struct llvmpipe_context *llvmpipe )
125 {
126 struct setup_context *setup = CALLOC_STRUCT(setup_context);
127 unsigned i;
128
129 setup->llvmpipe = llvmpipe;
130
131 return setup;
132 }
133