Merge remote branch 'origin/master'
[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
45 #define LP_SETUP_NEW_FS 0x01
46 #define LP_SETUP_NEW_CONSTANTS 0x02
47 #define LP_SETUP_NEW_BLEND_COLOR 0x04
48 #define LP_SETUP_NEW_SCISSOR 0x08
49
50
51 struct lp_scene_queue;
52
53
54 /** Max number of scenes */
55 #define MAX_SCENES 2
56
57
58
59 /**
60 * Point/line/triangle setup context.
61 * Note: "stored" below indicates data which is stored in the bins,
62 * not arbitrary malloc'd memory.
63 *
64 *
65 * Subclass of vbuf_render, plugged directly into the draw module as
66 * the rendering backend.
67 */
68 struct setup_context
69 {
70 struct vbuf_render base;
71
72 struct vertex_info *vertex_info;
73 uint prim;
74 uint vertex_size;
75 uint nr_vertices;
76 uint vertex_buffer_size;
77 void *vertex_buffer;
78
79 /* Final pipeline stage for draw module. Draw module should
80 * create/install this itself now.
81 */
82 struct draw_stage *vbuf;
83 struct lp_rasterizer *rast;
84 struct lp_scene *scenes[MAX_SCENES]; /**< all the scenes */
85 struct lp_scene *scene; /**< current scene being built */
86 struct lp_scene_queue *empty_scenes; /**< queue of empty scenes */
87
88 boolean flatshade_first;
89 boolean ccw_is_frontface;
90 boolean scissor_test;
91 unsigned cullmode;
92
93 struct pipe_framebuffer_state fb;
94
95 struct {
96 unsigned flags;
97 union lp_rast_cmd_arg color; /**< lp_rast_clear_color() cmd */
98 union lp_rast_cmd_arg zstencil; /**< lp_rast_clear_zstencil() cmd */
99 } clear;
100
101 enum {
102 SETUP_FLUSHED,
103 SETUP_CLEARED,
104 SETUP_ACTIVE
105 } state;
106
107 struct {
108 struct lp_shader_input input[PIPE_MAX_ATTRIBS];
109 unsigned nr_inputs;
110
111 const struct lp_rast_state *stored; /**< what's in the scene */
112 struct lp_rast_state current; /**< currently set state */
113 } fs;
114
115 /** fragment shader constants */
116 struct {
117 struct pipe_buffer *current;
118 unsigned stored_size;
119 const void *stored_data;
120 } constants;
121
122 struct {
123 struct pipe_blend_color current;
124 uint8_t *stored;
125 } blend_color;
126
127 struct {
128 struct pipe_scissor_state current;
129 const void *stored;
130 } scissor;
131
132 unsigned dirty; /**< bitmask of LP_SETUP_NEW_x bits */
133
134 void (*point)( struct setup_context *,
135 const float (*v0)[4]);
136
137 void (*line)( struct setup_context *,
138 const float (*v0)[4],
139 const float (*v1)[4]);
140
141 void (*triangle)( struct setup_context *,
142 const float (*v0)[4],
143 const float (*v1)[4],
144 const float (*v2)[4]);
145 };
146
147 void lp_setup_choose_triangle( struct setup_context *setup );
148 void lp_setup_choose_line( struct setup_context *setup );
149 void lp_setup_choose_point( struct setup_context *setup );
150
151 struct lp_scene *lp_setup_get_current_scene(struct setup_context *setup);
152
153 void lp_setup_init_vbuf(struct setup_context *setup);
154
155 void lp_setup_update_state( struct setup_context *setup );
156
157 void lp_setup_destroy( struct setup_context *setup );
158
159 #endif