1
/* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_vb.c,v 1.4 2002/02/22 21:32:59 dawes Exp $
3
* GLX Hardware Device Driver for Sun Creator/Creator3D
4
* Copyright (C) 2000, 2001 David S. Miller
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:
13
* The above copyright notice and this permission notice shall be included
14
* in all copies or substantial portions of the Software.
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.
25
* David S. Miller <davem@redhat.com>
28
#include "ffb_xmesa.h"
29
#include "ffb_context.h"
32
#include "tnl/t_context.h"
33
#include "swrast_setup/swrast_setup.h"
34
#include "math/m_translate.h"
38
static void ffb_copy_pv_oneside(GLcontext *ctx, GLuint edst, GLuint esrc)
40
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
41
ffb_vertex *dst = &fmesa->verts[edst];
42
ffb_vertex *src = &fmesa->verts[esrc];
45
fprintf(stderr, "ffb_copy_pv_oneside: edst(%d) esrc(%d)\n", edst, esrc);
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;
53
static void ffb_copy_pv_twoside(GLcontext *ctx, GLuint edst, GLuint esrc)
55
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
56
ffb_vertex *dst = &fmesa->verts[edst];
57
ffb_vertex *src = &fmesa->verts[esrc];
60
fprintf(stderr, "ffb_copy_pv_twoside: edst(%d) esrc(%d)\n", edst, esrc);
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;
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
77
typedef void (*emit_func)(GLcontext *, GLuint, GLuint);
82
} setup_tab[FFB_VB_MAX];
84
static void do_import(struct vertex_buffer *VB,
85
struct gl_client_array *to,
86
struct gl_client_array *from)
88
GLuint count = VB->Count;
91
to->Ptr = ALIGN_MALLOC( VB->Size * 4 * sizeof(GLfloat), 32 );
95
/* No need to transform the same value 3000 times. */
100
to->StrideB = 4 * sizeof(GLfloat);
102
_math_trans_4f((GLfloat (*)[4]) to->Ptr,
103
from->Ptr, from->StrideB,
104
from->Type, from->Size,
108
static __inline__ void ffbImportColors(ffbContextPtr fmesa, GLcontext *ctx, int index)
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;
116
#define IND (FFB_VB_XYZ_BIT)
118
#include "ffb_vbtmp.h"
120
#define IND (FFB_VB_RGBA_BIT)
122
#include "ffb_vbtmp.h"
124
#define IND (FFB_VB_XYZ_BIT | FFB_VB_RGBA_BIT)
125
#define TAG(x) x##_wg
126
#include "ffb_vbtmp.h"
128
#define IND (FFB_VB_TWOSIDE_BIT)
130
#include "ffb_vbtmp.h"
132
#define IND (FFB_VB_XYZ_BIT | FFB_VB_TWOSIDE_BIT)
133
#define TAG(x) x##_wt
134
#include "ffb_vbtmp.h"
136
#define IND (FFB_VB_RGBA_BIT | FFB_VB_TWOSIDE_BIT)
137
#define TAG(x) x##_gt
138
#include "ffb_vbtmp.h"
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"
144
static void init_setup_tab( void )
156
static void ffbPrintSetupFlags(char *msg, GLuint flags)
158
fprintf(stderr, "%s(%x): %s%s%s\n",
161
(flags & FFB_VB_XYZ_BIT) ? " xyz," : "",
162
(flags & FFB_VB_RGBA_BIT) ? " rgba," : "",
163
(flags & FFB_VB_TWOSIDE_BIT) ? " twoside," : "");
167
static void ffbDDBuildVertices(GLcontext *ctx, GLuint start, GLuint count,
170
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
172
newinputs |= fmesa->setupnewinputs;
173
fmesa->setupnewinputs = 0;
178
if (newinputs & VERT_CLIP) {
179
setup_tab[fmesa->setupindex].emit(ctx, start, count);
183
if (newinputs & VERT_RGBA)
184
ind |= (FFB_VB_RGBA_BIT | FFB_VB_TWOSIDE_BIT);
186
ind &= fmesa->setupindex;
189
setup_tab[ind].emit(ctx, start, count);
193
void ffbChooseVertexState( GLcontext *ctx )
195
TNLcontext *tnl = TNL_CONTEXT(ctx);
196
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
197
int ind = FFB_VB_XYZ_BIT | FFB_VB_RGBA_BIT;
199
if (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE)
200
ind |= FFB_VB_TWOSIDE_BIT;
203
ffbPrintSetupFlags("ffb: full setup function", ind);
206
fmesa->setupindex = ind;
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;
213
tnl->Driver.Render.CopyPV = ffb_copy_pv_oneside;
216
void ffbInitVB( GLcontext *ctx )
218
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
219
GLuint size = TNL_CONTEXT(ctx)->vb.Size;
221
fmesa->verts = (ffb_vertex *)ALIGN_MALLOC(size * sizeof(ffb_vertex), 32);
224
static int firsttime = 1;
233
void ffbFreeVB( GLcontext *ctx )
235
ffbContextPtr fmesa = FFB_CONTEXT(ctx);
237
ALIGN_FREE(fmesa->verts);