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

« back to all changes in this revision

Viewing changes to unix/xc/lib/GL/mesa/src/drv/ffb/ffb_vb.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
/* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_vb.c,v 1.4 2002/02/22 21:32:59 dawes Exp $
 
2
 *
 
3
 * GLX Hardware Device Driver for Sun Creator/Creator3D
 
4
 * Copyright (C) 2000, 2001 David S. Miller
 
5
 *
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a
 
7
 * copy of this software and associated documentation files (the "Software"),
 
8
 * to deal in the Software without restriction, including without limitation
 
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
10
 * and/or sell copies of the Software, and to permit persons to whom the
 
11
 * Software is furnished to do so, subject to the following conditions:
 
12
 *
 
13
 * The above copyright notice and this permission notice shall be included
 
14
 * in all copies or substantial portions of the Software.
 
15
 *
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
17
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
19
 * DAVID MILLER, OR ANY OTHER CONTRIBUTORS 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 
 
22
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
23
 *
 
24
 *
 
25
 *    David S. Miller <davem@redhat.com>
 
26
 */
 
27
 
 
28
#include "ffb_xmesa.h"
 
29
#include "ffb_context.h"
 
30
#include "ffb_vb.h"
 
31
#include "mem.h"
 
32
#include "tnl/t_context.h"
 
33
#include "swrast_setup/swrast_setup.h"
 
34
#include "math/m_translate.h"
 
35
 
 
36
#undef VB_DEBUG
 
37
 
 
38
static void ffb_copy_pv_oneside(GLcontext *ctx, GLuint edst, GLuint esrc)
 
39
{
 
40
        ffbContextPtr fmesa = FFB_CONTEXT(ctx);
 
41
        ffb_vertex *dst = &fmesa->verts[edst];
 
42
        ffb_vertex *src = &fmesa->verts[esrc];
 
43
 
 
44
#ifdef VB_DEBUG
 
45
        fprintf(stderr, "ffb_copy_pv_oneside: edst(%d) esrc(%d)\n", edst, esrc);
 
46
#endif
 
47
        dst->color[0].alpha = src->color[0].alpha;
 
48
        dst->color[0].red   = src->color[0].red;
 
49
        dst->color[0].green = src->color[0].green;
 
50
        dst->color[0].blue  = src->color[0].blue;
 
51
}
 
52
 
 
53
static void ffb_copy_pv_twoside(GLcontext *ctx, GLuint edst, GLuint esrc)
 
54
{
 
55
        ffbContextPtr fmesa = FFB_CONTEXT(ctx);
 
56
        ffb_vertex *dst = &fmesa->verts[edst];
 
57
        ffb_vertex *src = &fmesa->verts[esrc];
 
58
 
 
59
#ifdef VB_DEBUG
 
60
        fprintf(stderr, "ffb_copy_pv_twoside: edst(%d) esrc(%d)\n", edst, esrc);
 
61
#endif
 
62
        dst->color[0].alpha = src->color[0].alpha;
 
63
        dst->color[0].red   = src->color[0].red;
 
64
        dst->color[0].green = src->color[0].green;
 
65
        dst->color[0].blue  = src->color[0].blue;
 
66
        dst->color[1].alpha = src->color[1].alpha;
 
67
        dst->color[1].red   = src->color[1].red;
 
68
        dst->color[1].green = src->color[1].green;
 
69
        dst->color[1].blue  = src->color[1].blue;
 
70
}
 
71
 
 
72
#define FFB_VB_RGBA_BIT         0x01
 
73
#define FFB_VB_XYZ_BIT          0x02
 
74
#define FFB_VB_TWOSIDE_BIT      0x04
 
75
#define FFB_VB_MAX              0x08
 
76
 
 
77
typedef void (*emit_func)(GLcontext *, GLuint, GLuint);
 
78
 
 
79
static struct {
 
80
        emit_func       emit;
 
81
        interp_func     interp;
 
82
} setup_tab[FFB_VB_MAX];
 
83
 
 
84
static void do_import(struct vertex_buffer *VB,
 
85
                      struct gl_client_array *to,
 
86
                      struct gl_client_array *from)
 
87
{
 
88
        GLuint count = VB->Count;
 
89
 
 
90
        if (!to->Ptr) {
 
91
                to->Ptr = ALIGN_MALLOC( VB->Size * 4 * sizeof(GLfloat), 32 );
 
92
                to->Type = GL_FLOAT;
 
93
        }
 
94
 
 
95
        /* No need to transform the same value 3000 times. */
 
96
        if (!from->StrideB) {
 
97
                to->StrideB = 0;
 
98
                count = 1;
 
99
        } else
 
100
                to->StrideB = 4 * sizeof(GLfloat);
 
101
   
 
102
        _math_trans_4f((GLfloat (*)[4]) to->Ptr,
 
103
                       from->Ptr, from->StrideB,
 
104
                       from->Type, from->Size,
 
105
                       0, count);
 
106
}
 
107
 
 
108
static __inline__ void ffbImportColors(ffbContextPtr fmesa, GLcontext *ctx, int index)
 
109
{
 
110
        struct gl_client_array *to = &fmesa->FloatColor;
 
111
        struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
 
112
        do_import(VB, to, VB->ColorPtr[index]);
 
113
        VB->ColorPtr[index] = to;
 
114
}
 
115
 
 
116
#define IND     (FFB_VB_XYZ_BIT)
 
117
#define TAG(x)  x##_w
 
118
#include "ffb_vbtmp.h"
 
119
 
 
120
#define IND     (FFB_VB_RGBA_BIT)
 
121
#define TAG(x)  x##_g
 
122
#include "ffb_vbtmp.h"
 
123
 
 
124
#define IND     (FFB_VB_XYZ_BIT | FFB_VB_RGBA_BIT)
 
125
#define TAG(x)  x##_wg
 
126
#include "ffb_vbtmp.h"
 
127
 
 
128
#define IND     (FFB_VB_TWOSIDE_BIT)
 
129
#define TAG(x)  x##_t
 
130
#include "ffb_vbtmp.h"
 
131
 
 
132
#define IND     (FFB_VB_XYZ_BIT | FFB_VB_TWOSIDE_BIT)
 
133
#define TAG(x)  x##_wt
 
134
#include "ffb_vbtmp.h"
 
135
 
 
136
#define IND     (FFB_VB_RGBA_BIT | FFB_VB_TWOSIDE_BIT)
 
137
#define TAG(x)  x##_gt
 
138
#include "ffb_vbtmp.h"
 
139
 
 
140
#define IND     (FFB_VB_XYZ_BIT | FFB_VB_RGBA_BIT | FFB_VB_TWOSIDE_BIT)
 
141
#define TAG(x)  x##_wgt
 
142
#include "ffb_vbtmp.h"
 
143
 
 
144
static void init_setup_tab( void )
 
145
{
 
146
        init_w();
 
147
        init_g();
 
148
        init_wg();
 
149
        init_t();
 
150
        init_wt();
 
151
        init_gt();
 
152
        init_wgt();
 
153
}
 
154
 
 
155
#ifdef VB_DEBUG
 
156
static void ffbPrintSetupFlags(char *msg, GLuint flags)
 
157
{
 
158
   fprintf(stderr, "%s(%x): %s%s%s\n",
 
159
           msg,
 
160
           (int)flags,
 
161
           (flags & FFB_VB_XYZ_BIT)     ? " xyz," : "", 
 
162
           (flags & FFB_VB_RGBA_BIT)    ? " rgba," : "",
 
163
           (flags & FFB_VB_TWOSIDE_BIT) ? " twoside," : "");
 
164
}
 
165
#endif
 
166
 
 
167
static void ffbDDBuildVertices(GLcontext *ctx, GLuint start, GLuint count, 
 
168
                               GLuint newinputs)
 
169
{
 
170
        ffbContextPtr fmesa = FFB_CONTEXT(ctx);
 
171
 
 
172
        newinputs |= fmesa->setupnewinputs;
 
173
        fmesa->setupnewinputs = 0;
 
174
 
 
175
        if (!newinputs)
 
176
                return;
 
177
 
 
178
        if (newinputs & VERT_CLIP) {
 
179
                setup_tab[fmesa->setupindex].emit(ctx, start, count);
 
180
        } else {
 
181
                GLuint ind = 0;
 
182
 
 
183
                if (newinputs & VERT_RGBA)
 
184
                        ind |= (FFB_VB_RGBA_BIT | FFB_VB_TWOSIDE_BIT);
 
185
 
 
186
                ind &= fmesa->setupindex;
 
187
 
 
188
                if (ind)
 
189
                        setup_tab[ind].emit(ctx, start, count);
 
190
        }
 
191
}
 
192
 
 
193
void ffbChooseVertexState( GLcontext *ctx )
 
194
{
 
195
        TNLcontext *tnl = TNL_CONTEXT(ctx);
 
196
        ffbContextPtr fmesa = FFB_CONTEXT(ctx);
 
197
        int ind = FFB_VB_XYZ_BIT | FFB_VB_RGBA_BIT;
 
198
 
 
199
        if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE)
 
200
                ind |= FFB_VB_TWOSIDE_BIT;
 
201
 
 
202
#ifdef VB_DEBUG
 
203
        ffbPrintSetupFlags("ffb: full setup function", ind);
 
204
#endif
 
205
 
 
206
        fmesa->setupindex = ind;
 
207
 
 
208
        tnl->Driver.Render.BuildVertices = ffbDDBuildVertices;
 
209
        tnl->Driver.Render.Interp = setup_tab[ind].interp;
 
210
        if (ind & FFB_VB_TWOSIDE_BIT)
 
211
                tnl->Driver.Render.CopyPV = ffb_copy_pv_twoside;
 
212
        else
 
213
                tnl->Driver.Render.CopyPV = ffb_copy_pv_oneside;
 
214
}
 
215
 
 
216
void ffbInitVB( GLcontext *ctx )
 
217
{
 
218
        ffbContextPtr fmesa = FFB_CONTEXT(ctx);
 
219
        GLuint size = TNL_CONTEXT(ctx)->vb.Size;
 
220
 
 
221
        fmesa->verts = (ffb_vertex *)ALIGN_MALLOC(size * sizeof(ffb_vertex), 32);
 
222
 
 
223
        {
 
224
                static int firsttime = 1;
 
225
                if (firsttime) {
 
226
                        init_setup_tab();
 
227
                        firsttime = 0;
 
228
                }
 
229
        }
 
230
}
 
231
 
 
232
 
 
233
void ffbFreeVB( GLcontext *ctx )
 
234
{
 
235
        ffbContextPtr fmesa = FFB_CONTEXT(ctx);
 
236
        if (fmesa->verts) {
 
237
                ALIGN_FREE(fmesa->verts);
 
238
                fmesa->verts = 0;
 
239
        }
 
240
}