Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1 | #include "glheader.h" |
| 2 | #include "api_noop.h" |
| 3 | #include "context.h" |
| 4 | #include "colormac.h" |
| 5 | #include "light.h" |
| 6 | #include "macros.h" |
| 7 | #include "mmath.h" |
| 8 | #include "mtypes.h" |
| 9 | |
| 10 | |
| 11 | typedef struct { |
| 12 | GLint unit; |
| 13 | struct gl_client_array *array; |
| 14 | void *func; |
| 15 | } AAtexarray; |
| 16 | |
| 17 | |
| 18 | typedef struct { |
| 19 | struct gl_client_array *array; |
| 20 | void *func; |
| 21 | } AAarray; |
| 22 | |
| 23 | typedef struct { |
| 24 | AAtexarray texarrays[MAX_TEXTURE_UNITS+1]; |
| 25 | AAarray arrays[10]; |
| 26 | GLuint NewState; |
| 27 | } AAcontext; |
| 28 | |
| 29 | |
| 30 | static void *colorfuncs[2][7] = { |
| 31 | { glColor3bv, |
| 32 | glColor3ub, |
| 33 | glColor3sv, |
| 34 | glColor3usv, |
| 35 | glColor3iv, |
| 36 | glColor3fv, |
| 37 | glColor3dv }, |
| 38 | |
| 39 | { glColor4bv, |
| 40 | glColor4ub, |
| 41 | glColor4sv, |
| 42 | glColor4usv, |
| 43 | glColor4iv, |
| 44 | glColor4fv, |
| 45 | glColor4dv } |
| 46 | }; |
| 47 | |
| 48 | static void *vertexfuncs[3][7] = { |
| 49 | { glVertex3bv, |
| 50 | glVertex3ub, |
| 51 | glVertex3sv, |
| 52 | glVertex3usv, |
| 53 | glVertex3iv, |
| 54 | glVertex3fv, |
| 55 | glVertex3dv }, |
| 56 | |
| 57 | { glVertex3bv, |
| 58 | glVertex3ub, |
| 59 | glVertex3sv, |
| 60 | glVertex3usv, |
| 61 | glVertex3iv, |
| 62 | glVertex3fv, |
| 63 | glVertex3dv }, |
| 64 | |
| 65 | { glVertex4bv, |
| 66 | glVertex4ub, |
| 67 | glVertex4sv, |
| 68 | glVertex4usv, |
| 69 | glVertex4iv, |
| 70 | glVertex4fv, |
| 71 | glVertex4dv } |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | static void *multitexfuncs[4][7] = { |
| 76 | { glMultiTexCoord1bv, |
| 77 | glMultiTexCoord1ub, |
| 78 | glMultiTexCoord1sv, |
| 79 | glMultiTexCoord1usv, |
| 80 | glMultiTexCoord1iv, |
| 81 | glMultiTexCoord1fv, |
| 82 | glMultiTexCoord1dv }, |
| 83 | |
| 84 | { glMultiTexCoord2bv, |
| 85 | glMultiTexCoord2ub, |
| 86 | glMultiTexCoord2sv, |
| 87 | glMultiTexCoord2usv, |
| 88 | glMultiTexCoord2iv, |
| 89 | glMultiTexCoord2fv, |
| 90 | glMultiTexCoord2dv }, |
| 91 | |
| 92 | { glMultiTexCoord3bv, |
| 93 | glMultiTexCoord3ub, |
| 94 | glMultiTexCoord3sv, |
| 95 | glMultiTexCoord3usv, |
| 96 | glMultiTexCoord3iv, |
| 97 | glMultiTexCoord3fv, |
| 98 | glMultiTexCoord3dv }, |
| 99 | |
| 100 | { glMultiTexCoord4bv, |
| 101 | glMultiTexCoord4ub, |
| 102 | glMultiTexCoord4sv, |
| 103 | glMultiTexCoord4usv, |
| 104 | glMultiTexCoord4iv, |
| 105 | glMultiTexCoord4fv, |
| 106 | glMultiTexCoord4dv } |
| 107 | }; |
| 108 | |
| 109 | static void *indexfuncs[7] = { |
| 110 | { glIndexbv, |
| 111 | glIndexub, |
| 112 | glIndexsv, |
| 113 | glIndexusv, |
| 114 | glIndexiv, |
| 115 | glIndexfv, |
| 116 | glIndexdv }, |
| 117 | }; |
| 118 | |
| 119 | static void *edgeflagfuncs[7] = { |
| 120 | { glEdgeFlagbv, |
| 121 | glEdgeFlagub, |
| 122 | glEdgeFlagsv, |
| 123 | glEdgeFlagusv, |
| 124 | glEdgeFlagiv, |
| 125 | glEdgeFlagfv, |
| 126 | glEdgeFlagdv }, |
| 127 | }; |
| 128 | |
| 129 | static void *normalfuncs[7] = { |
| 130 | { glNormal3bv, |
| 131 | glNormal3ub, |
| 132 | glNormal3sv, |
| 133 | glNormal3usv, |
| 134 | glNormal3iv, |
| 135 | glNormal3fv, |
| 136 | glNormal3dv }, |
| 137 | }; |
| 138 | |
| 139 | static void *fogcoordfuncs[7] = { |
| 140 | { glFogCoordbv, |
| 141 | glFogCoordub, |
| 142 | glFogCoordsv, |
| 143 | glFogCoordusv, |
| 144 | glFogCoordiv, |
| 145 | glFogCoordfv, |
| 146 | glFogCoorddv }, |
| 147 | }; |
| 148 | |
| 149 | static void *secondarycolorfuncs[7] = { |
| 150 | { glSecondaryColor3bv, |
| 151 | glSecondaryColor3ub, |
| 152 | glSecondaryColor3sv, |
| 153 | glSecondaryColor3usv, |
| 154 | glSecondaryColor3iv, |
| 155 | glSecondaryColor3fv, |
| 156 | glSecondaryColor3dv }, |
| 157 | }; |
| 158 | |
| 159 | |
| 160 | void _aa_create_context( GLcontext *ctx ) |
| 161 | { |
| 162 | ctx->aa_context = MALLOC( sizeof(AAcontext) ); |
| 163 | AA_CONTEXT(ctx)->NewState = ~0; |
| 164 | } |
| 165 | |
| 166 | static void _aa_update_state( GLcontext *ctx ) |
| 167 | { |
| 168 | AAcontext *actx = AA_CONTEXT(ctx); |
| 169 | AAtexarray *ta = actx->texarrays; |
| 170 | AAarray *aa = actx->arrays; |
| 171 | int i; |
| 172 | |
| 173 | for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) |
| 174 | if (ctx->Array.TexCoord[i].Enabled) { |
| 175 | ta->unit = i; |
| 176 | ta->array = &ctx->Array.TexCoord[i]; |
| 177 | ta->func = multitexfuncs[ta->array->Size-1][TYPE_IDX(ta->array->Type)]; |
| 178 | ta++; |
| 179 | } |
| 180 | |
| 181 | ta->func = 0; |
| 182 | |
| 183 | if (ctx->Array.Color.Enabled) { |
| 184 | aa->array = &ctx->Array.Color; |
| 185 | aa->func = colorfuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)]; |
| 186 | aa++; |
| 187 | } |
| 188 | |
| 189 | if (ctx->Array.Normal.Enabled) { |
| 190 | aa->array = &ctx->Array.Normal; |
| 191 | aa->func = normalfuncs[TYPE_IDX(aa->array->Type)]; |
| 192 | aa++; |
| 193 | } |
| 194 | |
| 195 | if (ctx->Array.Index.Enabled) { |
| 196 | aa->array = &ctx->Array.Index; |
| 197 | aa->func = indexfuncs[TYPE_IDX(aa->array->Type)]; |
| 198 | aa++; |
| 199 | } |
| 200 | |
| 201 | if (ctx->Array.EdgeFlag.Enabled) { |
| 202 | aa->array = &ctx->Array.Edgeflag; |
| 203 | aa->func = edgeflagfuncs[TYPE_IDX(aa->array->Type)]; |
| 204 | aa++; |
| 205 | } |
| 206 | |
| 207 | if (ctx->Array.FogCoord.Enabled) { |
| 208 | aa->array = &ctx->Array.Fogcoord; |
| 209 | aa->func = fogcoordfuncs[TYPE_IDX(aa->array->Type)]; |
| 210 | aa++; |
| 211 | } |
| 212 | |
| 213 | if (ctx->Array.SecondaryColor.Enabled) { |
| 214 | aa->array = &ctx->Array.SecondaryColor; |
| 215 | aa->func = secondarycolorfuncs[TYPE_IDX(aa->array->Type)]; |
| 216 | aa++; |
| 217 | } |
| 218 | |
| 219 | /* Must be last |
| 220 | */ |
| 221 | if (ctx->Array.Vertex.Enabled) { |
| 222 | aa->array = &ctx->Array.Vertex; |
| 223 | aa->func = vertexfuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)]; |
| 224 | aa++; |
| 225 | } |
| 226 | |
| 227 | aa->func = 0; |
| 228 | actx->NewState = 0; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | static void _aa_loopback_array_elt( GLint elt ) |
| 233 | { |
| 234 | GET_CURRENT_CONTEXT(ctx); |
| 235 | AAcontext *actx = AA_CONTEXT(ctx); |
| 236 | AAtexarray *ta; |
| 237 | AAarray *aa; |
| 238 | |
| 239 | for (ta = actx->texarrays ; ta->func ; ta++) { |
| 240 | void (*func)( GLint, const void * ) = |
| 241 | (void (*)( GLint, const void * )) ta->func; |
| 242 | func( ta->unit, (char *)ta->array->Ptr + elt * ta->array->SizeB ); |
| 243 | } |
| 244 | |
| 245 | for (aa = actx->arrays ; aa->func ; aa++) { |
| 246 | void (*func)( GLint, const void * ) = |
| 247 | (void (*)( GLint, const void * )) aa->func; |
| 248 | func( (char *)aa->array->Ptr + elt * aa->array->SizeB ); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void _aa_exec_array_elt( GLint elt ) |
| 254 | { |
| 255 | GET_CURRENT_CONTEXT(ctx); |
| 256 | AAcontext *actx = AA_CONTEXT(ctx); |
| 257 | |
| 258 | if (actx->NewState) |
| 259 | _aa_update_state( ctx ); |
| 260 | |
| 261 | ctx->Exec->ArrayElement = _aa_loopback_array_elt; |
| 262 | _aa_loopback_array_elt( elt ); |
| 263 | } |
| 264 | |
| 265 | /* This works for save as well: |
| 266 | */ |
| 267 | void _aa_save_array_elt( GLint elt ) |
| 268 | { |
| 269 | GET_CURRENT_CONTEXT(ctx); |
| 270 | AAcontext *actx = AA_CONTEXT(ctx); |
| 271 | |
| 272 | if (actx->NewState) |
| 273 | _aa_update_state( ctx ); |
| 274 | |
| 275 | ctx->Save->ArrayElement = _aa_loopback_array_elt; |
| 276 | _aa_loopback_array_elt( elt ); |
| 277 | } |
| 278 | |
| 279 | |
| 280 | void aa_invalidate_state( GLcontext *ctx, GLuint new_state ) |
| 281 | { |
| 282 | if (AA_CONTEXT(ctx)) |
| 283 | AA_CONTEXT(ctx)->NewState |= new_state; |
| 284 | } |