~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/extras/Mesa/src/tnl/t_vb_light.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Mesa 3-D graphics library
 
4
 * Version:  3.5
 
5
 *
 
6
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining a
 
9
 * copy of this software and associated documentation files (the "Software"),
 
10
 * to deal in the Software without restriction, including without limitation
 
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
12
 * and/or sell copies of the Software, and to permit persons to whom the
 
13
 * Software is furnished to do so, subject to the following conditions:
 
14
 *
 
15
 * The above copyright notice and this permission notice shall be included
 
16
 * in all copies or substantial portions 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 MERCHANTABILITY,
 
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
21
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
22
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
23
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
24
 */
 
25
 
 
26
 
 
27
 
 
28
#include "glheader.h"
 
29
#include "colormac.h"
 
30
#include "light.h"
 
31
#include "macros.h"
 
32
#include "mem.h"
 
33
#include "mmath.h"
 
34
#include "simple_list.h"
 
35
#include "mtypes.h"
 
36
 
 
37
#include "math/m_translate.h"
 
38
 
 
39
#include "t_context.h"
 
40
#include "t_pipeline.h"
 
41
 
 
42
#define LIGHT_FLAGS         0x1 /* must be first */
 
43
#define LIGHT_TWOSIDE       0x2
 
44
#define LIGHT_COLORMATERIAL 0x4
 
45
#define MAX_LIGHT_FUNC      0x8
 
46
 
 
47
typedef void (*light_func)( GLcontext *ctx,
 
48
                            struct vertex_buffer *VB,
 
49
                            struct gl_pipeline_stage *stage,
 
50
                            GLvector4f *input );
 
51
 
 
52
struct light_stage_data {
 
53
   struct gl_client_array FloatColor; 
 
54
   struct gl_client_array LitColor[2];
 
55
   struct gl_client_array LitSecondary[2];
 
56
   GLvector1ui LitIndex[2];
 
57
   light_func *light_func_tab;
 
58
};
 
59
 
 
60
 
 
61
#define LIGHT_STAGE_DATA(stage) ((struct light_stage_data *)(stage->privatePtr))
 
62
 
 
63
 
 
64
static void import_color_material( GLcontext *ctx,
 
65
                                   struct gl_pipeline_stage *stage )
 
66
{
 
67
   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
 
68
   struct gl_client_array *to = &LIGHT_STAGE_DATA(stage)->FloatColor;
 
69
   struct gl_client_array *from = VB->ColorPtr[0];
 
70
   GLuint count = VB->Count;
 
71
 
 
72
   if (!to->Ptr) {
 
73
      to->Ptr = ALIGN_MALLOC( VB->Size * 4 * sizeof(GLfloat), 32 );
 
74
      to->Type = GL_FLOAT;
 
75
   }
 
76
 
 
77
   /* No need to transform the same value 3000 times.
 
78
    */
 
79
   if (!from->StrideB) {
 
80
      to->StrideB = 0;
 
81
      count = 1;
 
82
   }
 
83
   else
 
84
      to->StrideB = 4 * sizeof(GLfloat);
 
85
   
 
86
   _math_trans_4f( (GLfloat (*)[4]) to->Ptr,
 
87
                   from->Ptr,
 
88
                   from->StrideB,
 
89
                   from->Type,
 
90
                   from->Size,
 
91
                   0,
 
92
                   count);
 
93
 
 
94
   VB->ColorPtr[0] = to;
 
95
}
 
96
 
 
97
 
 
98
/* Tables for all the shading functions.
 
99
 */
 
100
static light_func _tnl_light_tab[MAX_LIGHT_FUNC];
 
101
static light_func _tnl_light_fast_tab[MAX_LIGHT_FUNC];
 
102
static light_func _tnl_light_fast_single_tab[MAX_LIGHT_FUNC];
 
103
static light_func _tnl_light_spec_tab[MAX_LIGHT_FUNC];
 
104
static light_func _tnl_light_ci_tab[MAX_LIGHT_FUNC];
 
105
 
 
106
#define TAG(x)           x
 
107
#define IDX              (0)
 
108
#include "t_vb_lighttmp.h"
 
109
 
 
110
#define TAG(x)           x##_tw
 
111
#define IDX              (LIGHT_TWOSIDE)
 
112
#include "t_vb_lighttmp.h"
 
113
 
 
114
#define TAG(x)           x##_fl
 
115
#define IDX              (LIGHT_FLAGS)
 
116
#include "t_vb_lighttmp.h"
 
117
 
 
118
#define TAG(x)           x##_tw_fl
 
119
#define IDX              (LIGHT_FLAGS|LIGHT_TWOSIDE)
 
120
#include "t_vb_lighttmp.h"
 
121
 
 
122
#define TAG(x)           x##_cm
 
123
#define IDX              (LIGHT_COLORMATERIAL)
 
124
#include "t_vb_lighttmp.h"
 
125
 
 
126
#define TAG(x)           x##_tw_cm
 
127
#define IDX              (LIGHT_TWOSIDE|LIGHT_COLORMATERIAL)
 
128
#include "t_vb_lighttmp.h"
 
129
 
 
130
#define TAG(x)           x##_fl_cm
 
131
#define IDX              (LIGHT_FLAGS|LIGHT_COLORMATERIAL)
 
132
#include "t_vb_lighttmp.h"
 
133
 
 
134
#define TAG(x)           x##_tw_fl_cm
 
135
#define IDX              (LIGHT_FLAGS|LIGHT_TWOSIDE|LIGHT_COLORMATERIAL)
 
136
#include "t_vb_lighttmp.h"
 
137
 
 
138
 
 
139
static void init_lighting( void )
 
140
{
 
141
   static int done;
 
142
 
 
143
   if (!done) {
 
144
      init_light_tab();
 
145
      init_light_tab_tw();
 
146
      init_light_tab_fl();
 
147
      init_light_tab_tw_fl();
 
148
      init_light_tab_cm();
 
149
      init_light_tab_tw_cm();
 
150
      init_light_tab_fl_cm();
 
151
      init_light_tab_tw_fl_cm();
 
152
      done = 1;
 
153
   }
 
154
}
 
155
 
 
156
 
 
157
static GLboolean run_lighting( GLcontext *ctx, struct gl_pipeline_stage *stage )
 
158
{
 
159
   struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
 
160
   TNLcontext *tnl = TNL_CONTEXT(ctx);
 
161
   struct vertex_buffer *VB = &tnl->vb;
 
162
   GLvector4f *input = ctx->_NeedEyeCoords ? VB->EyePtr : VB->ObjPtr;
 
163
   GLuint ind;
 
164
 
 
165
/*     _tnl_print_vert_flags( __FUNCTION__, stage->changed_inputs ); */
 
166
 
 
167
   /* Make sure we can talk about elements 0..2 in the vector we are
 
168
    * lighting.
 
169
    */
 
170
   if (stage->changed_inputs & (VERT_EYE|VERT_OBJ)) {
 
171
      if (input->size <= 2) {
 
172
         if (input->flags & VEC_NOT_WRITEABLE) {
 
173
            ASSERT(VB->importable_data & VERT_OBJ);
 
174
 
 
175
            VB->import_data( ctx, VERT_OBJ, VEC_NOT_WRITEABLE );
 
176
            input = ctx->_NeedEyeCoords ? VB->EyePtr : VB->ObjPtr;
 
177
 
 
178
            ASSERT((input->flags & VEC_NOT_WRITEABLE) == 0);
 
179
         }
 
180
 
 
181
         _mesa_vector4f_clean_elem(input, VB->Count, 2);
 
182
      }
 
183
   }
 
184
 
 
185
   if (VB->Flag)
 
186
      ind = LIGHT_FLAGS;
 
187
   else
 
188
      ind = 0;
 
189
 
 
190
   /* The individual functions know about replaying side-effects
 
191
    * vs. full re-execution. 
 
192
    */
 
193
   store->light_func_tab[ind]( ctx, VB, stage, input );
 
194
 
 
195
   return GL_TRUE;
 
196
}
 
197
 
 
198
 
 
199
/* Called in place of do_lighting when the light table may have changed.
 
200
 */
 
201
static GLboolean run_validate_lighting( GLcontext *ctx,
 
202
                                        struct gl_pipeline_stage *stage )
 
203
{
 
204
   GLuint ind = 0;
 
205
   light_func *tab;
 
206
 
 
207
   if (ctx->Visual.rgbMode) {
 
208
      if (ctx->Light._NeedVertices) {
 
209
         if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
 
210
            tab = _tnl_light_spec_tab;
 
211
         else
 
212
            tab = _tnl_light_tab;
 
213
      }
 
214
      else {
 
215
         if (ctx->Light.EnabledList.next == ctx->Light.EnabledList.prev)
 
216
            tab = _tnl_light_fast_single_tab;
 
217
         else
 
218
            tab = _tnl_light_fast_tab;
 
219
      }
 
220
   }
 
221
   else
 
222
      tab = _tnl_light_ci_tab;
 
223
 
 
224
   if (ctx->Light.ColorMaterialEnabled)
 
225
      ind |= LIGHT_COLORMATERIAL;
 
226
 
 
227
   if (ctx->Light.Model.TwoSide)
 
228
      ind |= LIGHT_TWOSIDE;
 
229
 
 
230
   LIGHT_STAGE_DATA(stage)->light_func_tab = &tab[ind];
 
231
 
 
232
   /* This and the above should only be done on _NEW_LIGHT:
 
233
    */
 
234
   TNL_CONTEXT(ctx)->Driver.NotifyMaterialChange( ctx );
 
235
 
 
236
   /* Now run the stage...
 
237
    */
 
238
   stage->run = run_lighting;
 
239
   return stage->run( ctx, stage );
 
240
}
 
241
 
 
242
static void alloc_4chan( struct gl_client_array *a, GLuint sz )
 
243
{
 
244
   a->Ptr = ALIGN_MALLOC( sz * sizeof(GLchan) * 4, 32 );
 
245
   a->Size = 4;
 
246
   a->Type = CHAN_TYPE;
 
247
   a->Stride = 0;
 
248
   a->StrideB = sizeof(GLchan) * 4;
 
249
   a->Enabled = 0;
 
250
   a->Flags = 0;
 
251
}
 
252
 
 
253
 
 
254
/* Called the first time stage->run is called.  In effect, don't
 
255
 * allocate data until the first time the stage is run.
 
256
 */
 
257
static GLboolean run_init_lighting( GLcontext *ctx,
 
258
                                    struct gl_pipeline_stage *stage )
 
259
{
 
260
   TNLcontext *tnl = TNL_CONTEXT(ctx);
 
261
   struct light_stage_data *store;
 
262
   GLuint size = tnl->vb.Size;
 
263
 
 
264
   stage->privatePtr = MALLOC(sizeof(*store));
 
265
   store = LIGHT_STAGE_DATA(stage);
 
266
   if (!store)
 
267
      return GL_FALSE;
 
268
 
 
269
   /* Do onetime init.
 
270
    */
 
271
   init_lighting();
 
272
 
 
273
   store->FloatColor.Ptr = 0;
 
274
 
 
275
   alloc_4chan( &store->LitColor[0], size );
 
276
   alloc_4chan( &store->LitColor[1], size );
 
277
   alloc_4chan( &store->LitSecondary[0], size );
 
278
   alloc_4chan( &store->LitSecondary[1], size );
 
279
 
 
280
   _mesa_vector1ui_alloc( &store->LitIndex[0], 0, size, 32 );
 
281
   _mesa_vector1ui_alloc( &store->LitIndex[1], 0, size, 32 );
 
282
 
 
283
   /* Now validate the stage derived data...
 
284
    */
 
285
   stage->run = run_validate_lighting;
 
286
   return stage->run( ctx, stage );
 
287
}
 
288
 
 
289
 
 
290
 
 
291
/*
 
292
 * Check if lighting is enabled.  If so, configure the pipeline stage's
 
293
 * type, inputs, and outputs.
 
294
 */
 
295
static void check_lighting( GLcontext *ctx, struct gl_pipeline_stage *stage )
 
296
{
 
297
   stage->active = ctx->Light.Enabled;
 
298
   if (stage->active) {
 
299
      if (stage->privatePtr)
 
300
         stage->run = run_validate_lighting;
 
301
      stage->inputs = VERT_NORM|VERT_MATERIAL;
 
302
      if (ctx->Light._NeedVertices)
 
303
         stage->inputs |= VERT_EYE; /* effectively, even when lighting in obj */
 
304
      if (ctx->Light.ColorMaterialEnabled)
 
305
         stage->inputs |= VERT_RGBA;
 
306
 
 
307
      stage->outputs = VERT_RGBA;
 
308
      if (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
 
309
         stage->outputs |= VERT_SPEC_RGB;
 
310
   }
 
311
}
 
312
 
 
313
 
 
314
static void dtr( struct gl_pipeline_stage *stage )
 
315
{
 
316
   struct light_stage_data *store = LIGHT_STAGE_DATA(stage);
 
317
 
 
318
   if (store) {
 
319
      ALIGN_FREE( store->LitColor[0].Ptr );
 
320
      ALIGN_FREE( store->LitColor[1].Ptr );
 
321
      ALIGN_FREE( store->LitSecondary[0].Ptr );
 
322
      ALIGN_FREE( store->LitSecondary[1].Ptr );
 
323
 
 
324
      if (store->FloatColor.Ptr)
 
325
         ALIGN_FREE( store->FloatColor.Ptr );
 
326
 
 
327
      _mesa_vector1ui_free( &store->LitIndex[0] );
 
328
      _mesa_vector1ui_free( &store->LitIndex[1] );
 
329
      FREE( store );
 
330
      stage->privatePtr = 0;
 
331
   }
 
332
}
 
333
 
 
334
const struct gl_pipeline_stage _tnl_lighting_stage =
 
335
{
 
336
   "lighting",
 
337
   _NEW_LIGHT,                  /* recheck */
 
338
   _NEW_LIGHT|_NEW_MODELVIEW,   /* recalc -- modelview dependency
 
339
                                 * otherwise not captured by inputs
 
340
                                 * (which may be VERT_OBJ) */
 
341
   0,0,0,                       /* active, inputs, outputs */
 
342
   0,0,                         /* changed_inputs, private_data */
 
343
   dtr,                         /* destroy */
 
344
   check_lighting,              /* check */
 
345
   run_init_lighting            /* run -- initially set to ctr */
 
346
};