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 * glRasterPos implementation. Basically render a GL_POINT with our
30 * private draw module. Plug in a special "rasterpos" stage at the end
31 * of the 'draw' pipeline to capture the results and update the current
32 * raster pos attributes.
39 #include "main/imports.h"
40 #include "main/macros.h"
41 #include "main/feedback.h"
43 #include "st_context.h"
46 #include "st_cb_rasterpos.h"
47 #include "draw/draw_context.h"
48 #include "draw/draw_pipe.h"
55 * Our special drawing pipeline stage (replaces rasterization).
59 struct draw_stage stage
; /**< Base class */
60 GLcontext
*ctx
; /**< Rendering context */
62 /* vertex attrib info we can setup once and re-use */
63 struct gl_client_array array
[VERT_ATTRIB_MAX
];
64 const struct gl_client_array
*arrays
[VERT_ATTRIB_MAX
];
65 struct _mesa_prim prim
;
69 static INLINE
struct rastpos_stage
*
70 rastpos_stage( struct draw_stage
*stage
)
72 return (struct rastpos_stage
*) stage
;
76 rastpos_flush( struct draw_stage
*stage
, unsigned flags
)
82 rastpos_reset_stipple_counter( struct draw_stage
*stage
)
88 rastpos_tri( struct draw_stage
*stage
, struct prim_header
*prim
)
90 /* should never get here */
95 rastpos_line( struct draw_stage
*stage
, struct prim_header
*prim
)
97 /* should never get here */
102 rastpos_destroy(struct draw_stage
*stage
)
109 * Update a raster pos attribute from the vertex result if it's present,
110 * else copy the current attrib.
113 update_attrib(GLcontext
*ctx
, const GLuint
*outputMapping
,
114 const struct vertex_header
*vert
,
116 GLuint result
, GLuint defaultAttrib
)
119 const GLuint k
= outputMapping
[result
];
123 src
= ctx
->Current
.Attrib
[defaultAttrib
];
129 * Normally, this function would render a GL_POINT.
132 rastpos_point(struct draw_stage
*stage
, struct prim_header
*prim
)
134 struct rastpos_stage
*rs
= rastpos_stage(stage
);
135 GLcontext
*ctx
= rs
->ctx
;
136 struct st_context
*st
= st_context(ctx
);
137 const GLfloat height
= (GLfloat
) ctx
->DrawBuffer
->Height
;
138 const GLuint
*outputMapping
= st
->vertex_result_to_slot
;
142 /* if we get here, we didn't get clipped */
143 ctx
->Current
.RasterPosValid
= GL_TRUE
;
145 /* update raster pos */
146 pos
= prim
->v
[0]->data
[0];
147 ctx
->Current
.RasterPos
[0] = pos
[0];
148 if (st_fb_orientation(ctx
->DrawBuffer
) == Y_0_TOP
)
149 ctx
->Current
.RasterPos
[1] = height
- pos
[1]; /* invert Y */
151 ctx
->Current
.RasterPos
[1] = pos
[1];
152 ctx
->Current
.RasterPos
[2] = pos
[2];
153 ctx
->Current
.RasterPos
[3] = pos
[3];
155 /* update other raster attribs */
156 update_attrib(ctx
, outputMapping
, prim
->v
[0],
157 ctx
->Current
.RasterColor
,
158 VERT_RESULT_COL0
, VERT_ATTRIB_COLOR0
);
160 update_attrib(ctx
, outputMapping
, prim
->v
[0],
161 ctx
->Current
.RasterSecondaryColor
,
162 VERT_RESULT_COL1
, VERT_ATTRIB_COLOR1
);
164 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++) {
165 update_attrib(ctx
, outputMapping
, prim
->v
[0],
166 ctx
->Current
.RasterTexCoords
[i
],
167 VERT_RESULT_TEX0
+ i
, VERT_ATTRIB_TEX0
+ i
);
170 if (ctx
->RenderMode
== GL_SELECT
) {
171 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
177 * Create rasterpos "drawing" stage.
179 static struct rastpos_stage
*
180 new_draw_rastpos_stage(GLcontext
*ctx
, struct draw_context
*draw
)
182 struct rastpos_stage
*rs
= ST_CALLOC_STRUCT(rastpos_stage
);
185 rs
->stage
.draw
= draw
;
186 rs
->stage
.next
= NULL
;
187 rs
->stage
.point
= rastpos_point
;
188 rs
->stage
.line
= rastpos_line
;
189 rs
->stage
.tri
= rastpos_tri
;
190 rs
->stage
.flush
= rastpos_flush
;
191 rs
->stage
.destroy
= rastpos_destroy
;
192 rs
->stage
.reset_stipple_counter
= rastpos_reset_stipple_counter
;
193 rs
->stage
.destroy
= rastpos_destroy
;
196 for (i
= 0; i
< Elements(rs
->array
); i
++) {
197 rs
->array
[i
].Size
= 4;
198 rs
->array
[i
].Type
= GL_FLOAT
;
199 rs
->array
[i
].Format
= GL_RGBA
;
200 rs
->array
[i
].Stride
= 0;
201 rs
->array
[i
].StrideB
= 0;
202 rs
->array
[i
].Ptr
= (GLubyte
*) ctx
->Current
.Attrib
[i
];
203 rs
->array
[i
].Enabled
= GL_TRUE
;
204 rs
->array
[i
].Normalized
= GL_TRUE
;
205 rs
->array
[i
].BufferObj
= NULL
;
206 rs
->arrays
[i
] = &rs
->array
[i
];
209 rs
->prim
.mode
= GL_POINTS
;
210 rs
->prim
.indexed
= 0;
222 st_RasterPos(GLcontext
*ctx
, const GLfloat v
[4])
224 struct st_context
*st
= st_context(ctx
);
225 struct draw_context
*draw
= st
->draw
;
226 struct rastpos_stage
*rs
;
228 if (st
->rastpos_stage
) {
229 /* get rastpos stage info */
230 rs
= rastpos_stage(st
->rastpos_stage
);
233 /* create rastpos draw stage */
234 rs
= new_draw_rastpos_stage(ctx
, draw
);
235 st
->rastpos_stage
= &rs
->stage
;
238 /* plug our rastpos stage into the draw module */
239 draw_set_rasterize_stage(st
->draw
, st
->rastpos_stage
);
241 /* make sure everything's up to date */
242 st_validate_state(st
);
244 /* This will get set only if rastpos_point(), above, gets called */
245 ctx
->Current
.RasterPosValid
= GL_FALSE
;
247 /* All vertex attribs but position were previously initialized above.
248 * Just plug in position pointer now.
250 rs
->array
[0].Ptr
= (GLubyte
*) v
;
253 st_feedback_draw_vbo(ctx
, rs
->arrays
, &rs
->prim
, 1, NULL
, GL_TRUE
, 0, 1);
255 /* restore draw's rasterization stage depending on rendermode */
256 if (ctx
->RenderMode
== GL_FEEDBACK
) {
257 draw_set_rasterize_stage(draw
, st
->feedback_stage
);
259 else if (ctx
->RenderMode
== GL_SELECT
) {
260 draw_set_rasterize_stage(draw
, st
->selection_stage
);
266 void st_init_rasterpos_functions(struct dd_function_table
*functions
)
268 functions
->RasterPos
= st_RasterPos
;
271 #endif /* FEATURE_rastpos */