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"
48 #include "draw/draw_context.h"
49 #include "draw/draw_private.h"
50 #include "shader/prog_instruction.h"
56 * Our special drawing pipeline stage (replaces rasterization).
60 struct draw_stage stage
; /**< Base class */
61 GLcontext
*ctx
; /**< Rendering context */
63 /* vertex attrib info we can setup once and re-use */
64 struct gl_client_array array
[VERT_ATTRIB_MAX
];
65 const struct gl_client_array
*arrays
[VERT_ATTRIB_MAX
];
66 struct _mesa_prim prim
;
70 static INLINE
struct rastpos_stage
*
71 rastpos_stage( struct draw_stage
*stage
)
73 return (struct rastpos_stage
*) stage
;
77 rastpos_flush( struct draw_stage
*stage
, unsigned flags
)
83 rastpos_reset_stipple_counter( struct draw_stage
*stage
)
89 rastpos_tri( struct draw_stage
*stage
, struct prim_header
*prim
)
91 /* should never get here */
96 rastpos_line( struct draw_stage
*stage
, struct prim_header
*prim
)
98 /* should never get here */
103 rastpos_destroy(struct draw_stage
*stage
)
110 * Update a raster pos attribute from the vertex result if it's present,
111 * else copy the current attrib.
114 update_attrib(GLcontext
*ctx
, const GLuint
*outputMapping
,
115 const struct vertex_header
*vert
,
117 GLuint result
, GLuint defaultAttrib
)
120 const GLuint k
= outputMapping
[result
];
124 src
= ctx
->Current
.Attrib
[defaultAttrib
];
130 * Normally, this function would render a GL_POINT.
133 rastpos_point(struct draw_stage
*stage
, struct prim_header
*prim
)
135 struct rastpos_stage
*rs
= rastpos_stage(stage
);
136 GLcontext
*ctx
= rs
->ctx
;
137 struct st_context
*st
= ctx
->st
;
138 const GLfloat height
= ctx
->DrawBuffer
->Height
;
139 const GLuint
*outputMapping
= st
->vertex_result_to_slot
;
143 /* if we get here, we didn't get clipped */
144 ctx
->Current
.RasterPosValid
= GL_TRUE
;
146 /* update raster pos */
147 pos
= prim
->v
[0]->data
[0];
148 ctx
->Current
.RasterPos
[0] = pos
[0];
149 ctx
->Current
.RasterPos
[1] = height
- pos
[1]; /* invert Y */
150 ctx
->Current
.RasterPos
[2] = pos
[2];
151 ctx
->Current
.RasterPos
[3] = pos
[3];
153 /* update other raster attribs */
154 update_attrib(ctx
, outputMapping
, prim
->v
[0],
155 ctx
->Current
.RasterColor
,
156 VERT_RESULT_COL0
, VERT_ATTRIB_COLOR0
);
158 update_attrib(ctx
, outputMapping
, prim
->v
[0],
159 ctx
->Current
.RasterSecondaryColor
,
160 VERT_RESULT_COL1
, VERT_ATTRIB_COLOR1
);
162 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++) {
163 update_attrib(ctx
, outputMapping
, prim
->v
[0],
164 ctx
->Current
.RasterTexCoords
[i
],
165 VERT_RESULT_TEX0
+ i
, VERT_ATTRIB_TEX0
+ i
);
168 if (ctx
->RenderMode
== GL_SELECT
) {
169 _mesa_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );
175 * Create rasterpos "drawing" stage.
177 static struct rastpos_stage
*
178 new_draw_rastpos_stage(GLcontext
*ctx
, struct draw_context
*draw
)
180 struct rastpos_stage
*rs
= CALLOC_STRUCT(rastpos_stage
);
183 rs
->stage
.draw
= draw
;
184 rs
->stage
.next
= NULL
;
185 rs
->stage
.point
= rastpos_point
;
186 rs
->stage
.line
= rastpos_line
;
187 rs
->stage
.tri
= rastpos_tri
;
188 rs
->stage
.flush
= rastpos_flush
;
189 rs
->stage
.destroy
= rastpos_destroy
;
190 rs
->stage
.reset_stipple_counter
= rastpos_reset_stipple_counter
;
191 rs
->stage
.destroy
= rastpos_destroy
;
194 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
195 rs
->array
[i
].Size
= 4;
196 rs
->array
[i
].Type
= GL_FLOAT
;
197 rs
->array
[i
].Stride
= 0;
198 rs
->array
[i
].StrideB
= 0;
199 rs
->array
[i
].Ptr
= (GLubyte
*) ctx
->Current
.Attrib
[i
];
200 rs
->array
[i
].Enabled
= GL_TRUE
;
201 rs
->array
[i
].Normalized
= GL_TRUE
;
202 rs
->array
[i
].BufferObj
= NULL
;
203 rs
->arrays
[i
] = &rs
->array
[i
];
206 rs
->prim
.mode
= GL_POINTS
;
207 rs
->prim
.indexed
= 0;
219 st_RasterPos(GLcontext
*ctx
, const GLfloat v
[4])
221 struct st_context
*st
= ctx
->st
;
222 struct draw_context
*draw
= st
->draw
;
223 struct rastpos_stage
*rs
;
225 if (st
->rastpos_stage
) {
226 /* get rastpos stage info */
227 rs
= rastpos_stage(st
->rastpos_stage
);
230 /* create rastpos draw stage */
231 rs
= new_draw_rastpos_stage(ctx
, draw
);
232 st
->rastpos_stage
= &rs
->stage
;
235 /* plug our rastpos stage into the draw module */
236 draw_set_rasterize_stage(st
->draw
, st
->rastpos_stage
);
238 /* make sure everything's up to date */
239 st_validate_state(ctx
->st
);
241 /* This will get set only if rastpos_point(), above, gets called */
242 ctx
->Current
.RasterPosValid
= GL_FALSE
;
244 /* All vertex attribs but position were previously initialized above.
245 * Just plug in position pointer now.
247 rs
->array
[0].Ptr
= (GLubyte
*) v
;
250 st_feedback_draw_vbo(ctx
, rs
->arrays
, &rs
->prim
, 1, NULL
, 0, 1);
255 void st_init_rasterpos_functions(struct dd_function_table
*functions
)
257 functions
->RasterPos
= st_RasterPos
;