Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / gallium / drivers / llvmpipe / lp_setup_context.h
1 /**************************************************************************
2 *
3 * Copyright 2007-2009 VMware, Inc.
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 VMWARE 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 /**
30 * The setup code is concerned with point/line/triangle setup and
31 * putting commands/data into the bins.
32 */
33
34
35 #ifndef LP_SETUP_CONTEXT_H
36 #define LP_SETUP_CONTEXT_H
37
38 #include "lp_setup.h"
39 #include "lp_rast.h"
40 #include "lp_tile_soa.h" /* for TILE_SIZE */
41 #include "lp_scene.h"
42
43 #include "draw/draw_vbuf.h"
44 #include "util/u_rect.h"
45
46 #define LP_SETUP_NEW_FS 0x01
47 #define LP_SETUP_NEW_CONSTANTS 0x02
48 #define LP_SETUP_NEW_BLEND_COLOR 0x04
49 #define LP_SETUP_NEW_SCISSOR 0x08
50
51
52 struct lp_scene_queue;
53
54
55 /** Max number of scenes */
56 #define MAX_SCENES 2
57
58
59
60 /**
61 * Point/line/triangle setup context.
62 * Note: "stored" below indicates data which is stored in the bins,
63 * not arbitrary malloc'd memory.
64 *
65 *
66 * Subclass of vbuf_render, plugged directly into the draw module as
67 * the rendering backend.
68 */
69 struct lp_setup_context
70 {
71 struct vbuf_render base;
72
73 struct vertex_info *vertex_info;
74 uint prim;
75 uint vertex_size;
76 uint nr_vertices;
77 uint sprite;
78 uint vertex_buffer_size;
79 void *vertex_buffer;
80
81 /* Final pipeline stage for draw module. Draw module should
82 * create/install this itself now.
83 */
84 struct draw_stage *vbuf;
85 unsigned num_threads;
86 struct lp_scene *scenes[MAX_SCENES]; /**< all the scenes */
87 struct lp_scene *scene; /**< current scene being built */
88 struct lp_scene_queue *empty_scenes; /**< queue of empty scenes */
89
90 boolean flatshade_first;
91 boolean ccw_is_frontface;
92 boolean scissor_test;
93 boolean point_size_per_vertex;
94 unsigned cullmode;
95 float pixel_offset;
96 float line_width;
97 float point_size;
98 float psize;
99
100 struct pipe_framebuffer_state fb;
101 struct u_rect framebuffer;
102 struct u_rect scissor;
103 struct u_rect draw_region; /* intersection of fb & scissor */
104
105 struct {
106 unsigned flags;
107 union lp_rast_cmd_arg color; /**< lp_rast_clear_color() cmd */
108 struct lp_rast_clearzs clearzs; /**< lp_rast_clear_zstencil() cmd */
109 } clear;
110
111 enum setup_state {
112 SETUP_FLUSHED, /**< scene is null */
113 SETUP_EMPTY, /**< scene exists but has only state changes */
114 SETUP_CLEARED, /**< scene exists but has only clears */
115 SETUP_ACTIVE /**< scene exists and has at least one draw/query */
116 } state;
117
118 struct {
119 struct lp_shader_input input[PIPE_MAX_ATTRIBS];
120 unsigned nr_inputs;
121
122 const struct lp_rast_state *stored; /**< what's in the scene */
123 struct lp_rast_state current; /**< currently set state */
124 struct pipe_resource *current_tex[PIPE_MAX_SAMPLERS];
125 } fs;
126
127 /** fragment shader constants */
128 struct {
129 struct pipe_resource *current;
130 unsigned stored_size;
131 const void *stored_data;
132 } constants;
133
134 struct {
135 struct pipe_blend_color current;
136 uint8_t *stored;
137 } blend_color;
138
139
140 unsigned dirty; /**< bitmask of LP_SETUP_NEW_x bits */
141
142 void (*point)( struct lp_setup_context *,
143 const float (*v0)[4]);
144
145 void (*line)( struct lp_setup_context *,
146 const float (*v0)[4],
147 const float (*v1)[4]);
148
149 void (*triangle)( struct lp_setup_context *,
150 const float (*v0)[4],
151 const float (*v1)[4],
152 const float (*v2)[4]);
153 };
154
155 void lp_setup_choose_triangle( struct lp_setup_context *setup );
156 void lp_setup_choose_line( struct lp_setup_context *setup );
157 void lp_setup_choose_point( struct lp_setup_context *setup );
158
159 struct lp_scene *lp_setup_get_current_scene(struct lp_setup_context *setup);
160
161 void lp_setup_init_vbuf(struct lp_setup_context *setup);
162
163 void lp_setup_update_state( struct lp_setup_context *setup );
164
165 void lp_setup_destroy( struct lp_setup_context *setup );
166
167 void
168 lp_setup_print_triangle(struct lp_setup_context *setup,
169 const float (*v0)[4],
170 const float (*v1)[4],
171 const float (*v2)[4]);
172
173 void
174 lp_setup_print_vertex(struct lp_setup_context *setup,
175 const char *name,
176 const float (*v)[4]);
177
178
179 struct lp_rast_triangle *
180 lp_setup_alloc_triangle(struct lp_scene *scene,
181 unsigned nr_inputs,
182 unsigned nr_planes,
183 unsigned *tri_size);
184
185 void
186 lp_setup_bin_triangle( struct lp_setup_context *setup,
187 struct lp_rast_triangle *tri,
188 const struct u_rect *bbox,
189 int nr_planes );
190
191 #endif
192