New 'draw' module for primitive drawing (clipping, culling, etc).
[mesa.git] / src / mesa / pipe / softpipe / sp_context.h
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 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
29 */
30
31 #ifndef SP_CONTEXT_H
32 #define SP_CONTEXT_H
33
34 #include "glheader.h"
35
36 #include "pipe/p_state.h"
37 #include "pipe/p_context.h"
38
39 #include "sp_quad.h"
40
41
42 struct softpipe_surface;
43 struct draw_context;
44 struct prim_stage;
45
46
47 enum interp_mode {
48 INTERP_CONSTANT,
49 INTERP_LINEAR,
50 INTERP_PERSPECTIVE
51 };
52
53
54 #define G_NEW_VIEWPORT 0x1
55 #define G_NEW_SETUP 0x2
56 #define G_NEW_FS 0x4
57 #define G_NEW_BLEND 0x8
58 #define G_NEW_CLIP 0x20
59 #define G_NEW_SCISSOR 0x40
60 #define G_NEW_STIPPLE 0x80
61 #define G_NEW_FRAMEBUFFER 0x100
62 #define G_NEW_ALPHA_TEST 0x200
63 #define G_NEW_DEPTH_TEST 0x400
64 #define G_NEW_SAMPLER 0x800
65 #define G_NEW_TEXTURE 0x1000
66
67
68 struct softpipe_context {
69 struct pipe_context pipe;
70
71 /* The most recent drawing state as set by the driver:
72 */
73 struct pipe_alpha_test_state alpha_test;
74 struct pipe_blend_state blend;
75 struct pipe_blend_color blend_color;
76 struct pipe_clear_color_state clear_color;
77 struct pipe_clip_state clip;
78 struct pipe_depth_state depth_test;
79 struct pipe_framebuffer_state framebuffer;
80 struct pipe_fs_state fs;
81 struct pipe_poly_stipple poly_stipple;
82 struct pipe_scissor_state scissor;
83 struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS];
84 struct pipe_setup_state setup;
85 struct pipe_texture_object *texture[PIPE_MAX_SAMPLERS];
86 struct pipe_viewport_state viewport;
87 GLuint dirty;
88
89 /* Setup derived state. TODO: this should be passed in the program
90 * tokens as parameters to DECL instructions.
91 *
92 * For now we just set colors to CONST on flatshade, textures to
93 * perspective always and everything else to linear.
94 */
95 enum interp_mode interp[PIPE_ATTRIB_MAX];
96
97
98 /* FS + setup derived state:
99 */
100 GLuint fp_attr_to_slot[PIPE_ATTRIB_MAX];
101 GLuint vf_attr_to_slot[PIPE_ATTRIB_MAX];
102 GLuint nr_attrs;
103 GLuint nr_frag_attrs;
104 GLuint attr_mask;
105
106 GLboolean need_z;
107 GLboolean need_w;
108
109 /* Stipple derived state:
110 */
111 GLubyte stipple_masks[16][16];
112
113 /*
114 * Software quad rendering pipeline
115 */
116 struct {
117 struct quad_stage *shade;
118 struct quad_stage *alpha_test;
119 struct quad_stage *depth_test;
120 struct quad_stage *blend;
121 struct quad_stage *output;
122
123 struct quad_stage *first; /**< points to one of the above stages */
124 } quad;
125
126 /* Temp kludge:
127 */
128 struct draw_context *draw;
129 };
130
131
132
133
134 static INLINE struct softpipe_context *
135 softpipe_context( struct pipe_context *pipe )
136 {
137 return (struct softpipe_context *)pipe;
138 }
139
140
141 #endif /* SP_CONTEXT_H */