Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2007 VMware, Inc. |
||
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 VMWARE 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 | /** |
||
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. |
||
33 | * |
||
34 | * Authors: |
||
35 | * Brian Paul |
||
36 | */ |
||
37 | |||
38 | |||
39 | #include "main/imports.h" |
||
40 | #include "main/macros.h" |
||
41 | #include "main/feedback.h" |
||
42 | |||
43 | #include "st_context.h" |
||
44 | #include "st_atom.h" |
||
45 | #include "st_draw.h" |
||
46 | #include "st_cb_rasterpos.h" |
||
47 | #include "draw/draw_context.h" |
||
48 | #include "draw/draw_pipe.h" |
||
49 | #include "vbo/vbo.h" |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Our special drawing pipeline stage (replaces rasterization). |
||
54 | */ |
||
55 | struct rastpos_stage |
||
56 | { |
||
57 | struct draw_stage stage; /**< Base class */ |
||
58 | struct gl_context *ctx; /**< Rendering context */ |
||
59 | |||
60 | /* vertex attrib info we can setup once and re-use */ |
||
61 | struct gl_client_array array[VERT_ATTRIB_MAX]; |
||
62 | const struct gl_client_array *arrays[VERT_ATTRIB_MAX]; |
||
63 | struct _mesa_prim prim; |
||
64 | }; |
||
65 | |||
66 | |||
67 | static inline struct rastpos_stage * |
||
68 | rastpos_stage( struct draw_stage *stage ) |
||
69 | { |
||
70 | return (struct rastpos_stage *) stage; |
||
71 | } |
||
72 | |||
73 | static void |
||
74 | rastpos_flush( struct draw_stage *stage, unsigned flags ) |
||
75 | { |
||
76 | /* no-op */ |
||
77 | } |
||
78 | |||
79 | static void |
||
80 | rastpos_reset_stipple_counter( struct draw_stage *stage ) |
||
81 | { |
||
82 | /* no-op */ |
||
83 | } |
||
84 | |||
85 | static void |
||
86 | rastpos_tri( struct draw_stage *stage, struct prim_header *prim ) |
||
87 | { |
||
88 | /* should never get here */ |
||
89 | assert(0); |
||
90 | } |
||
91 | |||
92 | static void |
||
93 | rastpos_line( struct draw_stage *stage, struct prim_header *prim ) |
||
94 | { |
||
95 | /* should never get here */ |
||
96 | assert(0); |
||
97 | } |
||
98 | |||
99 | static void |
||
100 | rastpos_destroy(struct draw_stage *stage) |
||
101 | { |
||
102 | free(stage); |
||
103 | } |
||
104 | |||
105 | |||
106 | /** |
||
107 | * Update a raster pos attribute from the vertex result if it's present, |
||
108 | * else copy the current attrib. |
||
109 | */ |
||
110 | static void |
||
111 | update_attrib(struct gl_context *ctx, const GLuint *outputMapping, |
||
112 | const struct vertex_header *vert, |
||
113 | GLfloat *dest, |
||
114 | GLuint result, GLuint defaultAttrib) |
||
115 | { |
||
116 | const GLfloat *src; |
||
117 | const GLuint k = outputMapping[result]; |
||
118 | if (k != ~0U) |
||
119 | src = vert->data[k]; |
||
120 | else |
||
121 | src = ctx->Current.Attrib[defaultAttrib]; |
||
122 | COPY_4V(dest, src); |
||
123 | } |
||
124 | |||
125 | |||
126 | /** |
||
127 | * Normally, this function would render a GL_POINT. |
||
128 | */ |
||
129 | static void |
||
130 | rastpos_point(struct draw_stage *stage, struct prim_header *prim) |
||
131 | { |
||
132 | struct rastpos_stage *rs = rastpos_stage(stage); |
||
133 | struct gl_context *ctx = rs->ctx; |
||
134 | struct st_context *st = st_context(ctx); |
||
135 | const GLfloat height = (GLfloat) ctx->DrawBuffer->Height; |
||
136 | const GLuint *outputMapping = st->vertex_result_to_slot; |
||
137 | const GLfloat *pos; |
||
138 | GLuint i; |
||
139 | |||
140 | /* if we get here, we didn't get clipped */ |
||
141 | ctx->Current.RasterPosValid = GL_TRUE; |
||
142 | |||
143 | /* update raster pos */ |
||
144 | pos = prim->v[0]->data[0]; |
||
145 | ctx->Current.RasterPos[0] = pos[0]; |
||
146 | if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) |
||
147 | ctx->Current.RasterPos[1] = height - pos[1]; /* invert Y */ |
||
148 | else |
||
149 | ctx->Current.RasterPos[1] = pos[1]; |
||
150 | ctx->Current.RasterPos[2] = pos[2]; |
||
151 | ctx->Current.RasterPos[3] = pos[3]; |
||
152 | |||
153 | /* update other raster attribs */ |
||
154 | update_attrib(ctx, outputMapping, prim->v[0], |
||
155 | ctx->Current.RasterColor, |
||
156 | VARYING_SLOT_COL0, VERT_ATTRIB_COLOR0); |
||
157 | |||
158 | update_attrib(ctx, outputMapping, prim->v[0], |
||
159 | ctx->Current.RasterSecondaryColor, |
||
160 | VARYING_SLOT_COL1, VERT_ATTRIB_COLOR1); |
||
161 | |||
162 | for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { |
||
163 | update_attrib(ctx, outputMapping, prim->v[0], |
||
164 | ctx->Current.RasterTexCoords[i], |
||
165 | VARYING_SLOT_TEX0 + i, VERT_ATTRIB_TEX0 + i); |
||
166 | } |
||
167 | |||
168 | if (ctx->RenderMode == GL_SELECT) { |
||
169 | _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] ); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | |||
174 | /** |
||
175 | * Create rasterpos "drawing" stage. |
||
176 | */ |
||
177 | static struct rastpos_stage * |
||
178 | new_draw_rastpos_stage(struct gl_context *ctx, struct draw_context *draw) |
||
179 | { |
||
180 | struct rastpos_stage *rs = ST_CALLOC_STRUCT(rastpos_stage); |
||
181 | GLuint i; |
||
182 | |||
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; |
||
192 | rs->ctx = ctx; |
||
193 | |||
194 | for (i = 0; i < ARRAY_SIZE(rs->array); i++) { |
||
195 | rs->array[i].Size = 4; |
||
196 | rs->array[i].Type = GL_FLOAT; |
||
197 | rs->array[i].Format = GL_RGBA; |
||
198 | rs->array[i].Stride = 0; |
||
199 | rs->array[i].StrideB = 0; |
||
200 | rs->array[i].Ptr = (GLubyte *) ctx->Current.Attrib[i]; |
||
201 | rs->array[i].Enabled = GL_TRUE; |
||
202 | rs->array[i].Normalized = GL_TRUE; |
||
203 | rs->array[i].BufferObj = NULL; |
||
204 | rs->arrays[i] = &rs->array[i]; |
||
205 | } |
||
206 | |||
207 | rs->prim.mode = GL_POINTS; |
||
208 | rs->prim.indexed = 0; |
||
209 | rs->prim.begin = 1; |
||
210 | rs->prim.end = 1; |
||
211 | rs->prim.weak = 0; |
||
212 | rs->prim.start = 0; |
||
213 | rs->prim.count = 1; |
||
214 | |||
215 | return rs; |
||
216 | } |
||
217 | |||
218 | |||
219 | static void |
||
220 | st_RasterPos(struct gl_context *ctx, const GLfloat v[4]) |
||
221 | { |
||
222 | struct st_context *st = st_context(ctx); |
||
223 | struct draw_context *draw = st->draw; |
||
224 | struct rastpos_stage *rs; |
||
225 | const struct gl_client_array **saved_arrays = ctx->Array._DrawArrays; |
||
226 | |||
227 | if (st->rastpos_stage) { |
||
228 | /* get rastpos stage info */ |
||
229 | rs = rastpos_stage(st->rastpos_stage); |
||
230 | } |
||
231 | else { |
||
232 | /* create rastpos draw stage */ |
||
233 | rs = new_draw_rastpos_stage(ctx, draw); |
||
234 | st->rastpos_stage = &rs->stage; |
||
235 | } |
||
236 | |||
237 | /* plug our rastpos stage into the draw module */ |
||
238 | draw_set_rasterize_stage(st->draw, st->rastpos_stage); |
||
239 | |||
240 | /* make sure everything's up to date */ |
||
241 | st_validate_state(st); |
||
242 | |||
243 | /* This will get set only if rastpos_point(), above, gets called */ |
||
244 | ctx->Current.RasterPosValid = GL_FALSE; |
||
245 | |||
246 | /* All vertex attribs but position were previously initialized above. |
||
247 | * Just plug in position pointer now. |
||
248 | */ |
||
249 | rs->array[0].Ptr = (GLubyte *) v; |
||
250 | |||
251 | /* Draw the point. |
||
252 | * |
||
253 | * Don't set DriverFlags.NewArray. |
||
254 | * st_feedback_draw_vbo doesn't check for that flag. */ |
||
255 | ctx->Array._DrawArrays = rs->arrays; |
||
256 | st_feedback_draw_vbo(ctx, &rs->prim, 1, NULL, GL_TRUE, 0, 1, |
||
257 | NULL, NULL); |
||
258 | ctx->Array._DrawArrays = saved_arrays; |
||
259 | |||
260 | /* restore draw's rasterization stage depending on rendermode */ |
||
261 | if (ctx->RenderMode == GL_FEEDBACK) { |
||
262 | draw_set_rasterize_stage(draw, st->feedback_stage); |
||
263 | } |
||
264 | else if (ctx->RenderMode == GL_SELECT) { |
||
265 | draw_set_rasterize_stage(draw, st->selection_stage); |
||
266 | } |
||
267 | } |
||
268 | |||
269 | |||
270 | |||
271 | void st_init_rasterpos_functions(struct dd_function_table *functions) |
||
272 | { |
||
273 | functions->RasterPos = st_RasterPos; |
||
274 | }>>>> |