1 /**************************************************************************
3 * Copyright 2003 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 **************************************************************************/
28 #include "main/glheader.h"
29 #include "main/macros.h"
30 #include "main/enums.h"
33 #include "pipe/draw/draw_context.h"
34 #include "i915_context.h"
35 #include "i915_state.h"
38 #define EMIT_ATTR( VF_ATTR, FRAG_ATTR, INTERP ) \
40 slot_to_vf_attr[nr_attrs] = VF_ATTR; \
42 attr_mask |= (1 << (VF_ATTR)); \
46 static const GLuint frag_to_vf
[FRAG_ATTRIB_MAX
] =
72 * Determine which post-transform / pre-rasterization vertex attributes
74 * Derived from: fs, setup states.
76 static void calculate_vertex_layout( struct i915_context
*i915
)
78 // const GLbitfield inputsRead = i915->fs.inputs_read;
79 const GLbitfield inputsRead
= (FRAG_BIT_WPOS
| FRAG_BIT_COL0
);
80 GLuint slot_to_vf_attr
[VF_ATTRIB_MAX
];
81 GLbitfield attr_mask
= 0x0;
85 memset(slot_to_vf_attr
, 0, sizeof(slot_to_vf_attr
));
88 /* TODO - Figure out if we need to do perspective divide, etc.
90 EMIT_ATTR(VF_ATTRIB_POS
, FRAG_ATTRIB_WPOS
, INTERP_LINEAR
);
92 /* Pull in the rest of the attributes. They are all in float4
93 * format. Future optimizations could be to keep some attributes
94 * as fixed point or ubyte format.
96 for (i
= 1; i
< FRAG_ATTRIB_TEX0
; i
++) {
97 if (inputsRead
& (1 << i
)) {
98 assert(i
< sizeof(frag_to_vf
) / sizeof(frag_to_vf
[0]));
99 if (i915
->setup
.flatshade
100 && (i
== FRAG_ATTRIB_COL0
|| i
== FRAG_ATTRIB_COL1
))
101 EMIT_ATTR(frag_to_vf
[i
], i
, INTERP_CONSTANT
);
103 EMIT_ATTR(frag_to_vf
[i
], i
, INTERP_LINEAR
);
107 for (i
= FRAG_ATTRIB_TEX0
; i
< FRAG_ATTRIB_MAX
; i
++) {
108 if (inputsRead
& (1 << i
)) {
109 assert(i
< sizeof(frag_to_vf
) / sizeof(frag_to_vf
[0]));
110 EMIT_ATTR(frag_to_vf
[i
], i
, INTERP_PERSPECTIVE
);
114 /* Additional attributes required for setup: Just twosided
115 * lighting. Edgeflag is dealt with specially by setting bits in
118 if (i915
->setup
.light_twoside
) {
119 if (inputsRead
& FRAG_BIT_COL0
) {
120 EMIT_ATTR(VF_ATTRIB_BFC0
, FRAG_ATTRIB_MAX
, 0); /* XXX: mark as discarded after setup */
123 if (inputsRead
& FRAG_BIT_COL1
) {
124 EMIT_ATTR(VF_ATTRIB_BFC1
, FRAG_ATTRIB_MAX
, 0); /* XXX: discard after setup */
128 /* If the attributes have changed, tell the draw module (which in turn
129 * tells the vf module) about the new vertex layout.
131 draw_set_vertex_attributes( i915
->draw
,
138 * Recompute cliprect from scissor bounds, scissor enable and surface size.
141 compute_cliprect(struct i915_context
*sp
)
143 GLint surfWidth
, surfHeight
;
145 if (sp
->framebuffer
.num_cbufs
> 0) {
146 surfWidth
= sp
->framebuffer
.cbufs
[0]->width
;
147 surfHeight
= sp
->framebuffer
.cbufs
[0]->height
;
151 surfWidth
= sp
->scissor
.maxx
;
152 surfHeight
= sp
->scissor
.maxy
;
155 if (sp
->setup
.scissor
) {
156 /* clip to scissor rect */
157 sp
->cliprect
.minx
= MAX2(sp
->scissor
.minx
, 0);
158 sp
->cliprect
.miny
= MAX2(sp
->scissor
.miny
, 0);
159 sp
->cliprect
.maxx
= MIN2(sp
->scissor
.maxx
, surfWidth
);
160 sp
->cliprect
.maxy
= MIN2(sp
->scissor
.maxy
, surfHeight
);
163 /* clip to surface bounds */
164 sp
->cliprect
.minx
= 0;
165 sp
->cliprect
.miny
= 0;
166 sp
->cliprect
.maxx
= surfWidth
;
167 sp
->cliprect
.maxy
= surfHeight
;
172 /* Hopefully this will remain quite simple, otherwise need to pull in
173 * something like the state tracker mechanism.
175 void i915_update_derived( struct i915_context
*i915
)
177 if (i915
->dirty
& (I915_NEW_SETUP
| I915_NEW_FS
))
178 calculate_vertex_layout( i915
);
180 if (i915
->dirty
& (I915_NEW_SCISSOR
|
182 I915_NEW_FRAMEBUFFER
))
183 compute_cliprect(i915
);