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 **************************************************************************/
29 * Private data structures, etc for the draw module.
35 * Keith Whitwell <keith@tungstengraphics.com>
40 #ifndef DRAW_PRIVATE_H
41 #define DRAW_PRIVATE_H
44 #include "main/glheader.h"
45 #include "pipe/p_state.h"
46 #include "pipe/p_defines.h"
52 * Carry some useful information around with the vertices in the prim pipe.
54 struct vertex_header
{
61 GLfloat data
[][4]; /* Note variable size */
64 #define MAX_VERTEX_SIZE ((2 + FRAG_ATTRIB_MAX) * 4 * sizeof(GLfloat))
69 * Basic info for a point/line/triangle primitive.
72 GLfloat det
; /**< front/back face determinant */
73 GLuint reset_line_stipple
:1;
76 struct vertex_header
*v
[3]; /**< 1 to 3 vertex pointers */
84 * Base class for all primitive drawing stages.
88 struct draw_context
*draw
; /**< parent context */
90 struct draw_stage
*next
; /**< next stage in pipeline */
92 struct vertex_header
**tmp
;
95 void (*begin
)( struct draw_stage
* );
97 void (*point
)( struct draw_stage
*,
98 struct prim_header
* );
100 void (*line
)( struct draw_stage
*,
101 struct prim_header
* );
103 void (*tri
)( struct draw_stage
*,
104 struct prim_header
* );
106 void (*end
)( struct draw_stage
* );
108 void (*reset_stipple_counter
)( struct draw_stage
* );
112 #define PRIM_QUEUE_LENGTH 16
113 #define VCACHE_SIZE 32
114 #define VCACHE_OVERFLOW 4
115 #define VS_QUEUE_LENGTH (VCACHE_SIZE + VCACHE_OVERFLOW + 1) /* can never fill up */
119 * Private context for the drawing module.
124 struct draw_stage
*first
; /**< one of the following */
126 /* stages (in logical order) */
127 struct draw_stage
*flatshade
;
128 struct draw_stage
*clip
;
129 struct draw_stage
*cull
;
130 struct draw_stage
*twoside
;
131 struct draw_stage
*offset
;
132 struct draw_stage
*unfilled
;
133 struct draw_stage
*setup
; /* aka render/rasterize */
136 /* pipe state that we need: */
137 struct pipe_setup_state setup
;
138 struct pipe_viewport_state viewport
;
140 /* Clip derived state:
142 GLfloat plane
[12][4];
145 GLuint vf_attr_to_slot
[PIPE_ATTRIB_MAX
];
147 struct vf_attr_map attrs
[VF_ATTRIB_MAX
];
149 GLuint vertex_size
; /**< in bytes */
150 struct vertex_fetch
*vf
;
158 struct vertex_header
*(*get_vertex
)( struct draw_context
*draw
,
161 /* Post-tnl vertex cache:
165 GLuint idx
[VCACHE_SIZE
+ VCACHE_OVERFLOW
];
166 struct vertex_header
*vertex
[VCACHE_SIZE
+ VCACHE_OVERFLOW
];
170 /* Vertex shader queue:
175 struct vertex_header
*dest
;
176 } queue
[VS_QUEUE_LENGTH
];
180 /* Prim pipeline queue:
184 /* Need to queue up primitives until their vertices have been
185 * transformed by a vs queue flush.
187 struct prim_header queue
[PRIM_QUEUE_LENGTH
];
193 GLenum prim
; /**< GL_POINTS, GL_LINE_STRIP, GL_QUADS, etc */
194 unsigned reduced_prim
;
203 extern struct draw_stage
*draw_unfilled_stage( struct draw_context
*context
);
204 extern struct draw_stage
*draw_twoside_stage( struct draw_context
*context
);
205 extern struct draw_stage
*draw_offset_stage( struct draw_context
*context
);
206 extern struct draw_stage
*draw_clip_stage( struct draw_context
*context
);
207 extern struct draw_stage
*draw_flatshade_stage( struct draw_context
*context
);
208 extern struct draw_stage
*draw_cull_stage( struct draw_context
*context
);
211 extern void draw_free_tmps( struct draw_stage
*stage
);
212 extern void draw_alloc_tmps( struct draw_stage
*stage
, GLuint nr
);
217 * Get a writeable copy of a vertex.
218 * \param stage drawing stage info
219 * \param vert the vertex to copy (source)
220 * \param idx index into stage's tmp[] array to put the copy (dest)
221 * \return pointer to the copied vertex
223 static INLINE
struct vertex_header
*
224 dup_vert( struct draw_stage
*stage
,
225 const struct vertex_header
*vert
,
228 struct vertex_header
*tmp
= stage
->tmp
[idx
];
229 memcpy(tmp
, vert
, stage
->draw
->vertex_size
);
234 #endif /* DRAW_PRIVATE_H */