1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
|
/*
* Author: Max Lingua <sunmax@libero.it>
*/
#include <stdlib.h>
#include <stdio.h>
#include "glheader.h"
#include "mtypes.h"
#include "mem.h"
#include "simple_list.h"
#include "enums.h"
#include "texstore.h"
#include "texformat.h"
#include "swrast/swrast.h"
#include "mm.h"
#include "mmath.h"
#include "s3v_context.h"
#include "s3v_tex.h"
extern void s3vSwapOutTexObj(s3vContextPtr vmesa, s3vTextureObjectPtr t);
extern void s3vDestroyTexObj(s3vContextPtr vmesa, s3vTextureObjectPtr t);
/*
static GLuint s3vComputeLodBias(GLfloat bias)
{
#if TEX_DEBUG_ON
DEBUG_TEX(("*** s3vComputeLodBias ***\n"));
#endif
return bias;
}
*/
static void s3vSetTexWrapping(s3vContextPtr vmesa,
s3vTextureObjectPtr t,
GLenum wraps, GLenum wrapt)
{
CARD32 t0 = t->TextureCMD;
CARD32 cmd = vmesa->CMD;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vSetTexWrapping: #%i ***\n", ++times));
#endif
t0 &= ~TEX_WRAP_MASK;
cmd &= ~TEX_WRAP_MASK;
if ((wraps != GL_CLAMP) || (wrapt != GL_CLAMP)) {
DEBUG(("TEX_WRAP_ON\n"));
t0 |= TEX_WRAP_ON;
cmd |= TEX_WRAP_ON;
}
cmd |= TEX_WRAP_ON; /* FIXME: broken if off */
t->TextureCMD = t0;
vmesa->CMD = cmd;
}
static void s3vSetTexFilter(s3vContextPtr vmesa,
s3vTextureObjectPtr t,
GLenum minf, GLenum magf)
{
CARD32 t0 = t->TextureCMD;
CARD32 cmd = vmesa->CMD;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vSetTexFilter: #%i ***\n", ++times));
#endif
t0 &= ~TEX_FILTER_MASK;
cmd &= ~TEX_FILTER_MASK;
switch (minf) {
case GL_NEAREST:
DEBUG(("GL_NEAREST\n"));
t0 |= NEAREST;
cmd |= NEAREST;
break;
case GL_LINEAR:
DEBUG(("GL_LINEAR\n"));
t0 |= LINEAR;
cmd |= LINEAR;
break;
case GL_NEAREST_MIPMAP_NEAREST:
DEBUG(("GL_MIPMAP_NEAREST\n"));
t0 |= MIP_NEAREST;
cmd |= MIP_NEAREST;
break;
case GL_LINEAR_MIPMAP_NEAREST:
DEBUG(("GL_LINEAR_MIPMAP_NEAREST\n"));
t0 |= LINEAR_MIP_NEAREST;
cmd |= LINEAR_MIP_NEAREST;
break;
case GL_NEAREST_MIPMAP_LINEAR:
DEBUG(("GL_NEAREST_MIPMAP_LINEAR\n"));
t0 |= MIP_LINEAR;
cmd |= MIP_LINEAR;
break;
case GL_LINEAR_MIPMAP_LINEAR:
DEBUG(("GL_LINEAR_MIPMAP_LINEAR\n"));
t0 |= LINEAR_MIP_LINEAR;
cmd |= LINEAR_MIP_LINEAR;
break;
default:
break;
}
/* FIXME: bilinear? */
#if 0
switch (magf) {
case GL_NEAREST:
break;
case GL_LINEAR:
break;
default:
break;
}
#endif
t->TextureCMD = t0;
DEBUG(("CMD was = 0x%x\n", vmesa->CMD));
DEBUG(("CMD is = 0x%x\n", cmd));
vmesa->CMD = cmd;
/* CMDCHANGE(); */
}
static void s3vSetTexBorderColor(s3vContextPtr vmesa,
s3vTextureObjectPtr t,
GLubyte color[4])
{
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vSetTexBorderColor: #%i ***\n", ++times));
#endif
/*FIXME: it should depend on tex col format */
/* switch(t0 ... t->TextureColorMode) */
/* case TEX_COL_ARGB1555: */
t->TextureBorderColor =
S3VIRGEPACKCOLOR555(color[0], color[1], color[2], color[3]);
DEBUG(("TextureBorderColor = 0x%x\n", t->TextureBorderColor));
vmesa->TextureBorderColor = t->TextureBorderColor;
}
static void s3vTexParameter( GLcontext *ctx, GLenum target,
struct gl_texture_object *tObj,
GLenum pname, const GLfloat *params )
{
s3vContextPtr vmesa = S3V_CONTEXT(ctx);
s3vTextureObjectPtr t = (s3vTextureObjectPtr) tObj->DriverData;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vTexParameter: #%i ***\n", ++times));
#endif
if (!t) return;
/* Can't do the update now as we don't know whether to flush
* vertices or not. Setting vmesa->new_state means that
* s3vUpdateTextureState() will be called before any triangles are
* rendered. If a statechange has occurred, it will be detected at
* that point, and buffered vertices flushed.
*/
switch (pname) {
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_MAG_FILTER:
s3vSetTexFilter( vmesa, t, tObj->MinFilter, tObj->MagFilter );
break;
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
s3vSetTexWrapping( vmesa, t, tObj->WrapS, tObj->WrapT );
break;
case GL_TEXTURE_BORDER_COLOR:
s3vSetTexBorderColor( vmesa, t, tObj->BorderColor );
break;
case GL_TEXTURE_BASE_LEVEL:
case GL_TEXTURE_MAX_LEVEL:
case GL_TEXTURE_MIN_LOD:
case GL_TEXTURE_MAX_LOD:
/* This isn't the most efficient solution but there doesn't appear to
* be a nice alternative for Virge. Since there's no LOD clamping,
* we just have to rely on loading the right subset of mipmap levels
* to simulate a clamped LOD.
*/
s3vSwapOutTexObj( vmesa, t );
break;
default:
return;
}
if (t == vmesa->CurrentTexObj[0])
vmesa->dirty |= S3V_UPLOAD_TEX0;
#if 0
if (t == vmesa->CurrentTexObj[1]) {
vmesa->dirty |= S3V_UPLOAD_TEX1;
}
#endif
}
static void s3vTexEnv( GLcontext *ctx, GLenum target,
GLenum pname, const GLfloat *param )
{
s3vContextPtr vmesa = S3V_CONTEXT( ctx );
GLuint unit = ctx->Texture.CurrentUnit;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vTexEnv: #%i ***\n", ++times));
#endif
/* Only one env color. Need a fallback if env colors are different
* and texture setup references env color in both units.
*/
switch (pname) {
case GL_TEXTURE_ENV_COLOR: {
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
GLfloat *fc = texUnit->EnvColor;
GLuint r, g, b, a, col;
CLAMPED_FLOAT_TO_UBYTE(r, fc[0]);
CLAMPED_FLOAT_TO_UBYTE(g, fc[1]);
CLAMPED_FLOAT_TO_UBYTE(b, fc[2]);
CLAMPED_FLOAT_TO_UBYTE(a, fc[3]);
col = ((a << 24) |
(r << 16) |
(g << 8) |
(b << 0));
break;
}
case GL_TEXTURE_ENV_MODE:
vmesa->TexEnvImageFmt[unit] = 0; /* force recalc of env state */
break;
case GL_TEXTURE_LOD_BIAS_EXT: {
/*
struct gl_texture_object *tObj =
ctx->Texture.Unit[unit]._Current;
s3vTextureObjectPtr t = (s3vTextureObjectPtr) tObj->DriverData;
*/
break;
}
default:
break;
}
}
static void s3vTexImage1D( GLcontext *ctx, GLenum target, GLint level,
GLint internalFormat,
GLint width, GLint border,
GLenum format, GLenum type,
const GLvoid *pixels,
const struct gl_pixelstore_attrib *pack,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage )
{
s3vContextPtr vmesa = S3V_CONTEXT( ctx );
s3vTextureObjectPtr t = (s3vTextureObjectPtr) texObj->DriverData;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vTexImage1D: #%i ***\n", ++times));
#endif
#if 1
if (t) {
#if _TEXFLUSH
DMAFLUSH();
#endif
s3vSwapOutTexObj( vmesa, t );
/*
s3vDestroyTexObj( vmesa, t );
texObj->DriverData = 0;
*/
}
#endif
_mesa_store_teximage1d( ctx, target, level, internalFormat,
width, border, format, type,
pixels, pack, texObj, texImage );
}
static void s3vTexSubImage1D( GLcontext *ctx,
GLenum target,
GLint level,
GLint xoffset,
GLsizei width,
GLenum format, GLenum type,
const GLvoid *pixels,
const struct gl_pixelstore_attrib *pack,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage )
{
s3vContextPtr vmesa = S3V_CONTEXT( ctx );
s3vTextureObjectPtr t = (s3vTextureObjectPtr) texObj->DriverData;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vTexSubImage1D: #%i ***\n", ++times));
#endif
#if 1
if (t) {
#if _TEXFLUSH
DMAFLUSH();
#endif
s3vSwapOutTexObj( vmesa, t );
/*
s3vDestroyTexObj( vmesa, t );
texObj->DriverData = 0;
*/
}
#endif
_mesa_store_texsubimage1d(ctx, target, level, xoffset, width,
format, type, pixels, pack, texObj,
texImage);
}
static void s3vTexImage2D( GLcontext *ctx, GLenum target, GLint level,
GLint internalFormat,
GLint width, GLint height, GLint border,
GLenum format, GLenum type, const GLvoid *pixels,
const struct gl_pixelstore_attrib *packing,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage )
{
s3vContextPtr vmesa = S3V_CONTEXT( ctx );
s3vTextureObjectPtr t = (s3vTextureObjectPtr) texObj->DriverData;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vTexImage2D: #%i ***\n", ++times));
#endif
#if 1
if (t) {
#if _TEXFLUSH
DMAFLUSH();
#endif
s3vSwapOutTexObj( vmesa, t );
/*
s3vDestroyTexObj( vmesa, t );
texObj->DriverData = 0;
*/
}
#endif
_mesa_store_teximage2d( ctx, target, level, internalFormat,
width, height, border, format, type,
pixels, packing, texObj, texImage );
}
static void s3vTexSubImage2D( GLcontext *ctx,
GLenum target,
GLint level,
GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height,
GLenum format, GLenum type,
const GLvoid *pixels,
const struct gl_pixelstore_attrib *packing,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage )
{
s3vContextPtr vmesa = S3V_CONTEXT( ctx );
s3vTextureObjectPtr t = (s3vTextureObjectPtr) texObj->DriverData;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vTexSubImage2D: #%i ***\n", ++times));
#endif
#if 1
if (t) {
#if _TEXFLUSH
DMAFLUSH();
#endif
s3vSwapOutTexObj( vmesa, t );
/*
s3vDestroyTexObj( vmesa, t );
texObj->DriverData = 0;
*/
}
#endif
_mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width,
height, format, type, pixels, packing, texObj,
texImage);
}
static void s3vBindTexture( GLcontext *ctx, GLenum target,
struct gl_texture_object *tObj )
{
s3vContextPtr vmesa = S3V_CONTEXT( ctx );
s3vTextureObjectPtr t = (s3vTextureObjectPtr) tObj->DriverData;
CARD32 cmd = vmesa->CMD;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vBindTexture: #%i ***\n", ++times));
#endif
if (!t) {
/*
GLfloat bias = ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias;
*/
t = CALLOC_STRUCT(s3v_texture_object_t);
/* Initialize non-image-dependent parts of the state:
*/
t->globj = tObj;
#if 0
if (target == GL_TEXTURE_2D) {
} else
if (target == GL_TEXTURE_1D) {
}
#if X_BYTE_ORDER == X_LITTLE_ENDIAN
t->TextureFormat = (TF_LittleEndian |
#else
t->TextureFormat = (TF_BigEndian |
#endif
#endif
t->dirty_images = ~0;
tObj->DriverData = t;
make_empty_list( t );
#if 0
s3vSetTexWrapping( vmesa, t, tObj->WrapS, tObj->WrapT );
s3vSetTexFilter( vmesa, t, tObj->MinFilter, tObj->MagFilter );
s3vSetTexBorderColor( vmesa, t, tObj->BorderColor );
#endif
}
if (!ctx->Texture._ReallyEnabled) {
DEBUG_TEX(("!ctx->Texture._ReallyEnabled\n"));
return;
}
cmd = vmesa->CMD & ~MIP_MASK;
vmesa->dirty |= S3V_UPLOAD_TEX0;
vmesa->TexOffset = t->TextureBaseAddr[tObj->BaseLevel];
vmesa->TexStride = t->Pitch;
cmd |= MIPMAP_LEVEL(t->WidthLog2);
vmesa->CMD = cmd;
vmesa->restore_primitive = -1;
#if 0
printf("t->TextureBaseAddr[0] = 0x%x\n", t->TextureBaseAddr[0]);
printf("t->TextureBaseAddr[1] = 0x%x\n", t->TextureBaseAddr[1]);
printf("t->TextureBaseAddr[2] = 0x%x\n", t->TextureBaseAddr[2]);
#endif
}
static void s3vDeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj )
{
s3vTextureObjectPtr t = (s3vTextureObjectPtr)tObj->DriverData;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vDeleteTexture: #%i ***\n", ++times));
#endif
if (t) {
s3vContextPtr vmesa = S3V_CONTEXT( ctx );
#if _TEXFLUSH
if (vmesa) {
DMAFLUSH();
}
#endif
s3vDestroyTexObj( vmesa, t );
tObj->DriverData = 0;
}
}
static GLboolean s3vIsTextureResident( GLcontext *ctx,
struct gl_texture_object *tObj )
{
s3vTextureObjectPtr t = (s3vTextureObjectPtr)tObj->DriverData;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vIsTextureResident: #%i ***\n", ++times));
#endif
return (t && t->MemBlock);
}
static void s3vInitTextureObjects( GLcontext *ctx )
{
/* s3vContextPtr vmesa = S3V_CONTEXT(ctx); */
struct gl_texture_object *texObj;
GLuint tmp = ctx->Texture.CurrentUnit;
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vInitTextureObjects: #%i ***\n", ++times));
#endif
#if 1
ctx->Texture.CurrentUnit = 0;
texObj = ctx->Texture.Unit[0].Current1D;
s3vBindTexture( ctx, GL_TEXTURE_1D, texObj );
texObj = ctx->Texture.Unit[0].Current2D;
s3vBindTexture( ctx, GL_TEXTURE_2D, texObj );
#endif
#if 0
ctx->Texture.CurrentUnit = 1;
texObj = ctx->Texture.Unit[1].Current1D;
s3vBindTexture( ctx, GL_TEXTURE_1D, texObj );
texObj = ctx->Texture.Unit[1].Current2D;
s3vBindTexture( ctx, GL_TEXTURE_2D, texObj );
#endif
ctx->Texture.CurrentUnit = tmp;
}
void s3vInitTextureFuncs( GLcontext *ctx )
{
#if TEX_DEBUG_ON
static unsigned int times=0;
DEBUG_TEX(("*** s3vInitTextureFuncs: #%i ***\n", ++times));
#endif
ctx->Driver.TexEnv = s3vTexEnv;
ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
ctx->Driver.TexImage1D = _mesa_store_teximage1d;
ctx->Driver.TexImage2D = s3vTexImage2D;
ctx->Driver.TexImage3D = _mesa_store_teximage3d;
ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
ctx->Driver.TexSubImage2D = s3vTexSubImage2D;
ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;
ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;
ctx->Driver.BindTexture = s3vBindTexture;
ctx->Driver.DeleteTexture = s3vDeleteTexture;
ctx->Driver.TexParameter = s3vTexParameter;
ctx->Driver.UpdateTexturePalette = 0;
ctx->Driver.IsTextureResident = s3vIsTextureResident;
ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
s3vInitTextureObjects( ctx );
}
|