| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2003 Tungsten Graphics, inc. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 9 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 10 | * the Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 19 | * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 22 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Keith Whitwell <keithw@tungstengraphics.com> |
| 26 | */ |
| 27 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 28 | #include "glheader.h" |
| 29 | #include "context.h" |
| 30 | #include "colormac.h" |
| 31 | |
| 32 | #include "t_context.h" |
| 33 | #include "t_vertex.h" |
| 34 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 35 | #define DBG 0 |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 36 | |
| 37 | /* Build and manage clipspace/ndc/window vertices. |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 38 | */ |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 39 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 40 | static GLboolean match_fastpath( struct tnl_clipspace *vtx, |
| 41 | const struct tnl_clipspace_fastpath *fp) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 42 | { |
| Brian Paul | fde4c53 | 2004-03-13 18:27:06 +0000 | [diff] [blame] | 43 | GLuint j; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 44 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 45 | if (vtx->attr_count != fp->attr_count) |
| 46 | return GL_FALSE; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 47 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 48 | for (j = 0; j < vtx->attr_count; j++) |
| 49 | if (vtx->attr[j].format != fp->attr[j].format) |
| 50 | return GL_FALSE; |
| Keith Whitwell | a887a44 | 2005-01-10 12:30:08 +0000 | [diff] [blame] | 51 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 52 | if (fp->match_strides) { |
| 53 | if (vtx->vertex_size != fp->vertex_size) |
| 54 | return GL_FALSE; |
| 55 | |
| 56 | for (j = 0; j < vtx->attr_count; j++) |
| 57 | if (vtx->attr[j].inputstride != fp->attr[j].stride) |
| 58 | return GL_FALSE; |
| Keith Whitwell | a887a44 | 2005-01-10 12:30:08 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 61 | return GL_TRUE; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 64 | static GLboolean search_fastpath_emit( struct tnl_clipspace *vtx ) |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 65 | { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 66 | struct tnl_clipspace_fastpath *fp = vtx->fastpath; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 67 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 68 | for ( ; fp ; fp = fp->next) { |
| 69 | if (match_fastpath(vtx, fp)) { |
| 70 | vtx->emit = fp->func; |
| 71 | return GL_TRUE; |
| 72 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 73 | } |
| Keith Whitwell | a887a44 | 2005-01-10 12:30:08 +0000 | [diff] [blame] | 74 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 75 | return GL_FALSE; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 76 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 77 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 78 | void _tnl_register_fastpath( struct tnl_clipspace *vtx, |
| 79 | GLboolean match_strides ) |
| 80 | { |
| 81 | struct tnl_clipspace_fastpath *fastpath = CALLOC_STRUCT(tnl_clipspace_fastpath); |
| 82 | GLuint i; |
| 83 | |
| 84 | fastpath->vertex_size = vtx->vertex_size; |
| 85 | fastpath->attr_count = vtx->attr_count; |
| 86 | fastpath->match_strides = match_strides; |
| 87 | fastpath->func = vtx->emit; |
| 88 | fastpath->attr = MALLOC(vtx->attr_count * sizeof(fastpath->attr[0])); |
| 89 | |
| 90 | for (i = 0; i < vtx->attr_count; i++) { |
| 91 | fastpath->attr[i].format = vtx->attr[i].format; |
| 92 | fastpath->attr[i].stride = vtx->attr[i].inputstride; |
| 93 | } |
| 94 | |
| 95 | fastpath->next = vtx->fastpath; |
| 96 | vtx->fastpath = fastpath; |
| 97 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 98 | |
| 99 | |
| 100 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 101 | /*********************************************************************** |
| 102 | * Build codegen functions or return generic ones: |
| 103 | */ |
| Keith Whitwell | 9a8a9fb | 2005-01-05 12:58:14 +0000 | [diff] [blame] | 104 | static void choose_emit_func( GLcontext *ctx, GLuint count, GLubyte *dest) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 105 | { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 106 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 107 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Keith Whitwell | 009aa3e | 2004-06-30 11:48:21 +0000 | [diff] [blame] | 108 | struct tnl_clipspace_attr *a = vtx->attr; |
| Keith Whitwell | 9a8a9fb | 2005-01-05 12:58:14 +0000 | [diff] [blame] | 109 | const GLuint attr_count = vtx->attr_count; |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 110 | GLuint j; |
| 111 | |
| 112 | for (j = 0; j < attr_count; j++) { |
| 113 | GLvector4f *vptr = VB->AttribPtr[a[j].attrib]; |
| 114 | a[j].inputstride = vptr->stride; |
| 115 | a[j].inputsize = vptr->size; |
| 116 | a[j].emit = a[j].insert[vptr->size - 1]; /* not always used */ |
| 117 | } |
| 118 | |
| Keith Whitwell | b97e478 | 2005-02-10 10:57:22 +0000 | [diff] [blame] | 119 | vtx->emit = NULL; |
| Keith Whitwell | 009aa3e | 2004-06-30 11:48:21 +0000 | [diff] [blame] | 120 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 121 | /* Does this match an existing (hardwired, codegen or known-bad) |
| 122 | * fastpath? |
| Keith Whitwell | 9a8a9fb | 2005-01-05 12:58:14 +0000 | [diff] [blame] | 123 | */ |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 124 | if (search_fastpath_emit(vtx)) { |
| 125 | /* Use this result. If it is null, then it is already known |
| 126 | * that the current state will fail for codegen and there is no |
| 127 | * point trying again. |
| 128 | */ |
| Keith Whitwell | 9a8a9fb | 2005-01-05 12:58:14 +0000 | [diff] [blame] | 129 | } |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 130 | else if (vtx->codegen_emit) { |
| 131 | vtx->codegen_emit(ctx); |
| 132 | } |
| 133 | |
| 134 | if (!vtx->emit) { |
| 135 | _tnl_generate_hardwired_emit(ctx); |
| 136 | } |
| 137 | |
| Keith Whitwell | 9a8a9fb | 2005-01-05 12:58:14 +0000 | [diff] [blame] | 138 | /* Otherwise use the generic version: |
| 139 | */ |
| Keith Whitwell | 009aa3e | 2004-06-30 11:48:21 +0000 | [diff] [blame] | 140 | if (!vtx->emit) |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 141 | vtx->emit = _tnl_generic_emit; |
| Keith Whitwell | 009aa3e | 2004-06-30 11:48:21 +0000 | [diff] [blame] | 142 | |
| Keith Whitwell | 9a8a9fb | 2005-01-05 12:58:14 +0000 | [diff] [blame] | 143 | vtx->emit( ctx, count, dest ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
| Keith Whitwell | 009aa3e | 2004-06-30 11:48:21 +0000 | [diff] [blame] | 147 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 148 | static void choose_interp_func( GLcontext *ctx, |
| 149 | GLfloat t, |
| 150 | GLuint edst, GLuint eout, GLuint ein, |
| 151 | GLboolean force_boundary ) |
| 152 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 153 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 154 | |
| 155 | if (vtx->need_extras && |
| 156 | (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 157 | vtx->interp = _tnl_generic_interp_extras; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 158 | } else { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 159 | vtx->interp = _tnl_generic_interp; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | vtx->interp( ctx, t, edst, eout, ein, force_boundary ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 166 | static void choose_copy_pv_func( GLcontext *ctx, GLuint edst, GLuint esrc ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 167 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 168 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 169 | |
| 170 | if (vtx->need_extras && |
| 171 | (ctx->_TriangleCaps & (DD_TRI_LIGHT_TWOSIDE|DD_TRI_UNFILLED))) { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 172 | vtx->copy_pv = _tnl_generic_copy_pv_extras; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 173 | } else { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 174 | vtx->copy_pv = _tnl_generic_copy_pv; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | vtx->copy_pv( ctx, edst, esrc ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | |
| 181 | /*********************************************************************** |
| 182 | * Public entrypoints, mostly dispatch to the above: |
| 183 | */ |
| 184 | |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 185 | |
| 186 | /* Interpolate between two vertices to produce a third: |
| 187 | */ |
| 188 | void _tnl_interp( GLcontext *ctx, |
| 189 | GLfloat t, |
| 190 | GLuint edst, GLuint eout, GLuint ein, |
| 191 | GLboolean force_boundary ) |
| 192 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 193 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 194 | vtx->interp( ctx, t, edst, eout, ein, force_boundary ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* Copy colors from one vertex to another: |
| 198 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 199 | void _tnl_copy_pv( GLcontext *ctx, GLuint edst, GLuint esrc ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 200 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 201 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 202 | vtx->copy_pv( ctx, edst, esrc ); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | |
| 206 | /* Extract a named attribute from a hardware vertex. Will have to |
| 207 | * reverse any viewport transformation, swizzling or other conversions |
| 208 | * which may have been applied: |
| 209 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 210 | void _tnl_get_attr( GLcontext *ctx, const void *vin, |
| 211 | GLenum attr, GLfloat *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 212 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 213 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 214 | const struct tnl_clipspace_attr *a = vtx->attr; |
| Brian Paul | fde4c53 | 2004-03-13 18:27:06 +0000 | [diff] [blame] | 215 | const GLuint attr_count = vtx->attr_count; |
| 216 | GLuint j; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 217 | |
| 218 | for (j = 0; j < attr_count; j++) { |
| Brian Paul | bdd15b5 | 2004-05-04 15:11:06 +0000 | [diff] [blame] | 219 | if (a[j].attrib == attr) { |
| Keith Whitwell | 44d4a8f | 2004-01-06 00:18:03 +0000 | [diff] [blame] | 220 | a[j].extract( &a[j], dest, (GLubyte *)vin + a[j].vertoffset ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 221 | return; |
| 222 | } |
| 223 | } |
| 224 | |
| Keith Whitwell | fa13622 | 2005-01-07 15:54:48 +0000 | [diff] [blame] | 225 | /* Else return the value from ctx->Current. |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 226 | */ |
| Brian Paul | 3663c0f | 2004-01-15 00:29:51 +0000 | [diff] [blame] | 227 | _mesa_memcpy( dest, ctx->Current.Attrib[attr], 4*sizeof(GLfloat)); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| Keith Whitwell | 4773634 | 2004-02-16 15:15:24 +0000 | [diff] [blame] | 230 | |
| 231 | /* Complementary operation to the above. |
| 232 | */ |
| 233 | void _tnl_set_attr( GLcontext *ctx, void *vout, |
| 234 | GLenum attr, const GLfloat *src ) |
| 235 | { |
| 236 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 237 | const struct tnl_clipspace_attr *a = vtx->attr; |
| Brian Paul | fde4c53 | 2004-03-13 18:27:06 +0000 | [diff] [blame] | 238 | const GLuint attr_count = vtx->attr_count; |
| 239 | GLuint j; |
| Keith Whitwell | 4773634 | 2004-02-16 15:15:24 +0000 | [diff] [blame] | 240 | |
| 241 | for (j = 0; j < attr_count; j++) { |
| Brian Paul | bdd15b5 | 2004-05-04 15:11:06 +0000 | [diff] [blame] | 242 | if (a[j].attrib == attr) { |
| Keith Whitwell | 4773634 | 2004-02-16 15:15:24 +0000 | [diff] [blame] | 243 | a[j].insert[4-1]( &a[j], (GLubyte *)vout + a[j].vertoffset, src ); |
| 244 | return; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 250 | void *_tnl_get_vertex( GLcontext *ctx, GLuint nr ) |
| 251 | { |
| 252 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 253 | |
| 254 | return vtx->vertex_buf + nr * vtx->vertex_size; |
| 255 | } |
| 256 | |
| 257 | void _tnl_invalidate_vertex_state( GLcontext *ctx, GLuint new_state ) |
| 258 | { |
| 259 | if (new_state & (_DD_NEW_TRI_LIGHT_TWOSIDE|_DD_NEW_TRI_UNFILLED) ) { |
| 260 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 261 | vtx->new_inputs = ~0; |
| 262 | vtx->interp = choose_interp_func; |
| 263 | vtx->copy_pv = choose_copy_pv_func; |
| 264 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 267 | static void invalidate_funcs( struct tnl_clipspace *vtx ) |
| 268 | { |
| 269 | vtx->emit = choose_emit_func; |
| 270 | vtx->interp = choose_interp_func; |
| 271 | vtx->copy_pv = choose_copy_pv_func; |
| 272 | vtx->new_inputs = ~0; |
| 273 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 274 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 275 | GLuint _tnl_install_attrs( GLcontext *ctx, const struct tnl_attr_map *map, |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 276 | GLuint nr, const GLfloat *vp, |
| 277 | GLuint unpacked_size ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 278 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 279 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Brian Paul | fde4c53 | 2004-03-13 18:27:06 +0000 | [diff] [blame] | 280 | GLuint offset = 0; |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 281 | GLuint i, j; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 282 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 283 | assert(nr < _TNL_ATTRIB_MAX); |
| 284 | assert(nr == 0 || map[0].attrib == VERT_ATTRIB_POS); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 285 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 286 | vtx->new_inputs = ~0; |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 287 | vtx->need_viewport = GL_FALSE; |
| 288 | |
| 289 | if (vp) { |
| 290 | vtx->need_viewport = GL_TRUE; |
| 291 | vtx->vp_scale[0] = vp[MAT_SX]; |
| 292 | vtx->vp_scale[1] = vp[MAT_SY]; |
| 293 | vtx->vp_scale[2] = vp[MAT_SZ]; |
| 294 | vtx->vp_scale[3] = 1.0; |
| 295 | vtx->vp_xlate[0] = vp[MAT_TX]; |
| 296 | vtx->vp_xlate[1] = vp[MAT_TY]; |
| 297 | vtx->vp_xlate[2] = vp[MAT_TZ]; |
| 298 | vtx->vp_xlate[3] = 0.0; |
| 299 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 300 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 301 | for (j = 0, i = 0; i < nr; i++) { |
| Brian Paul | fde4c53 | 2004-03-13 18:27:06 +0000 | [diff] [blame] | 302 | const GLuint format = map[i].format; |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 303 | if (format == EMIT_PAD) { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 304 | if (DBG) |
| 305 | _mesa_printf("%d: pad %d, offset %d\n", i, |
| 306 | map[i].offset, offset); |
| 307 | |
| Keith Whitwell | 009aa3e | 2004-06-30 11:48:21 +0000 | [diff] [blame] | 308 | offset += map[i].offset; |
| Keith Whitwell | 16f5421 | 2004-01-05 15:55:01 +0000 | [diff] [blame] | 309 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 310 | } |
| 311 | else { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 312 | GLuint tmpoffset; |
| Keith Whitwell | 44d4a8f | 2004-01-06 00:18:03 +0000 | [diff] [blame] | 313 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 314 | if (unpacked_size) |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 315 | tmpoffset = map[i].offset; |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 316 | else |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 317 | tmpoffset = offset; |
| 318 | |
| 319 | if (vtx->attr_count != j || |
| 320 | vtx->attr[j].attrib != map[i].attrib || |
| 321 | vtx->attr[j].format != format || |
| 322 | vtx->attr[j].vertoffset != tmpoffset) { |
| 323 | invalidate_funcs(vtx); |
| 324 | |
| 325 | vtx->attr[j].attrib = map[i].attrib; |
| 326 | vtx->attr[j].format = format; |
| 327 | vtx->attr[j].vp = vp; |
| 328 | vtx->attr[j].insert = _tnl_format_info[format].insert; |
| 329 | vtx->attr[j].extract = _tnl_format_info[format].extract; |
| 330 | vtx->attr[j].vertattrsize = _tnl_format_info[format].attrsize; |
| 331 | vtx->attr[j].vertoffset = tmpoffset; |
| 332 | } |
| 333 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 334 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 335 | if (DBG) |
| 336 | _mesa_printf("%d: %s, vp %p, offset %d\n", i, |
| 337 | _tnl_format_info[format].name, (void *)vp, |
| 338 | vtx->attr[j].vertoffset); |
| 339 | |
| 340 | offset += _tnl_format_info[format].attrsize; |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 341 | j++; |
| 342 | } |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 343 | } |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 344 | |
| Keith Whitwell | 4d36f33 | 2004-01-21 15:31:46 +0000 | [diff] [blame] | 345 | vtx->attr_count = j; |
| 346 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 347 | if (unpacked_size) |
| 348 | vtx->vertex_size = unpacked_size; |
| 349 | else |
| 350 | vtx->vertex_size = offset; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 351 | |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 352 | assert(vtx->vertex_size <= vtx->max_vertex_size); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 353 | return vtx->vertex_size; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | |
| 357 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 358 | void _tnl_invalidate_vertices( GLcontext *ctx, GLuint newinputs ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 359 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 360 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 361 | vtx->new_inputs |= newinputs; |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 365 | /* This event has broader use beyond this file - will move elsewhere |
| 366 | * and probably invoke a driver callback. |
| 367 | */ |
| 368 | void _tnl_notify_pipeline_output_change( GLcontext *ctx ) |
| 369 | { |
| 370 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 371 | invalidate_funcs(vtx); |
| 372 | } |
| 373 | |
| 374 | static void update_input_ptrs( GLcontext *ctx, GLuint start ) |
| 375 | { |
| 376 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 377 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 378 | struct tnl_clipspace_attr *a = vtx->attr; |
| 379 | const GLuint count = vtx->attr_count; |
| 380 | GLuint j; |
| 381 | |
| 382 | for (j = 0; j < count; j++) { |
| 383 | GLvector4f *vptr = VB->AttribPtr[a[j].attrib]; |
| 384 | |
| 385 | if (vtx->emit != choose_emit_func) { |
| 386 | assert(a[j].inputstride == vptr->stride); |
| 387 | assert(a[j].inputsize == vptr->size); |
| 388 | } |
| 389 | |
| 390 | a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 395 | void _tnl_build_vertices( GLcontext *ctx, |
| Keith Whitwell | 8d97ad1 | 2004-01-19 23:29:40 +0000 | [diff] [blame] | 396 | GLuint start, |
| 397 | GLuint end, |
| 398 | GLuint newinputs ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 399 | { |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 400 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 401 | update_input_ptrs( ctx, start ); |
| 402 | vtx->emit( ctx, end - start, |
| 403 | (GLubyte *)(vtx->vertex_buf + |
| 404 | start * vtx->vertex_size)); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| Keith Whitwell | fa13622 | 2005-01-07 15:54:48 +0000 | [diff] [blame] | 407 | /* Emit VB vertices start..end to dest. Note that VB vertex at |
| 408 | * postion start will be emitted to dest at position zero. |
| 409 | */ |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 410 | void *_tnl_emit_vertices_to_buffer( GLcontext *ctx, |
| Keith Whitwell | 8d97ad1 | 2004-01-19 23:29:40 +0000 | [diff] [blame] | 411 | GLuint start, |
| 412 | GLuint end, |
| 413 | void *dest ) |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 414 | { |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 415 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Keith Whitwell | 9a8a9fb | 2005-01-05 12:58:14 +0000 | [diff] [blame] | 416 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 417 | update_input_ptrs(ctx, start); |
| Keith Whitwell | 9a8a9fb | 2005-01-05 12:58:14 +0000 | [diff] [blame] | 418 | |
| 419 | /* Note: dest should not be adjusted for non-zero 'start' values: |
| 420 | */ |
| 421 | vtx->emit( ctx, end - start, dest ); |
| Keith Whitwell | 8d97ad1 | 2004-01-19 23:29:40 +0000 | [diff] [blame] | 422 | return (void *)((GLubyte *)dest + vtx->vertex_size * (end - start)); |
| Keith Whitwell | fabb973 | 2003-12-21 17:54:31 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 425 | |
| 426 | void _tnl_init_vertices( GLcontext *ctx, |
| 427 | GLuint vb_size, |
| 428 | GLuint max_vertex_size ) |
| 429 | { |
| 430 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| 431 | |
| Keith Whitwell | b97e478 | 2005-02-10 10:57:22 +0000 | [diff] [blame] | 432 | _tnl_install_attrs( ctx, NULL, 0, NULL, 0 ); |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 433 | |
| 434 | vtx->need_extras = GL_TRUE; |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 435 | if (max_vertex_size > vtx->max_vertex_size) { |
| 436 | _tnl_free_vertices( ctx ); |
| 437 | vtx->max_vertex_size = max_vertex_size; |
| Brian Paul | cb7c689 | 2004-01-26 16:16:16 +0000 | [diff] [blame] | 438 | vtx->vertex_buf = (GLubyte *)ALIGN_CALLOC(vb_size * max_vertex_size, 32 ); |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 439 | invalidate_funcs(vtx); |
| Keith Whitwell | 5882257 | 2004-01-05 15:24:53 +0000 | [diff] [blame] | 440 | } |
| Keith Whitwell | 009aa3e | 2004-06-30 11:48:21 +0000 | [diff] [blame] | 441 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 442 | switch(CHAN_TYPE) { |
| 443 | case GL_UNSIGNED_BYTE: |
| 444 | vtx->chan_scale[0] = 255.0; |
| 445 | vtx->chan_scale[1] = 255.0; |
| 446 | vtx->chan_scale[2] = 255.0; |
| 447 | vtx->chan_scale[3] = 255.0; |
| 448 | break; |
| 449 | case GL_UNSIGNED_SHORT: |
| 450 | vtx->chan_scale[0] = 65535.0; |
| 451 | vtx->chan_scale[1] = 65535.0; |
| 452 | vtx->chan_scale[2] = 65535.0; |
| 453 | vtx->chan_scale[3] = 65535.0; |
| 454 | break; |
| 455 | default: |
| 456 | vtx->chan_scale[0] = 1.0; |
| 457 | vtx->chan_scale[1] = 1.0; |
| 458 | vtx->chan_scale[2] = 1.0; |
| 459 | vtx->chan_scale[3] = 1.0; |
| 460 | break; |
| 461 | } |
| 462 | |
| 463 | vtx->identity[0] = 0.0; |
| 464 | vtx->identity[1] = 0.0; |
| 465 | vtx->identity[2] = 0.0; |
| 466 | vtx->identity[3] = 1.0; |
| 467 | |
| 468 | vtx->codegen_emit = NULL; |
| 469 | |
| 470 | #ifdef __i386__ |
| 471 | if (getenv("MESA_EXPERIMENTAL")) |
| 472 | vtx->codegen_emit = _tnl_generate_sse_emit; |
| 473 | #endif |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | |
| 477 | void _tnl_free_vertices( GLcontext *ctx ) |
| 478 | { |
| 479 | struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 480 | struct tnl_clipspace_fastpath *fp, *tmp; |
| 481 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 482 | if (vtx->vertex_buf) { |
| 483 | ALIGN_FREE(vtx->vertex_buf); |
| Keith Whitwell | b97e478 | 2005-02-10 10:57:22 +0000 | [diff] [blame] | 484 | vtx->vertex_buf = NULL; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 485 | } |
| Keith Whitwell | 0aca086 | 2005-01-12 19:38:41 +0000 | [diff] [blame] | 486 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame^] | 487 | for (fp = vtx->fastpath ; fp ; fp = tmp) { |
| 488 | tmp = fp->next; |
| 489 | FREE(fp->attr); |
| 490 | FREE((void *)fp->func); |
| 491 | FREE(fp); |
| 492 | } |
| 493 | |
| 494 | vtx->fastpath = NULL; |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 495 | } |