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
|
/* -*- mode: c; c-basic-offset: 3 -*- */
/*
* Copyright 2000 Gareth Hughes
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Authors:
* Gareth Hughes <gareth@valinux.com>
* Leif Delgass <ldelgass@retinalburn.net>
* José Fonseca <j_r_fonseca@yahoo.co.uk>
*/
#include "main/glheader.h"
#include "main/imports.h"
#include "main/context.h"
#include "main/macros.h"
#include "mach64_context.h"
#include "mach64_ioctl.h"
#include "mach64_tris.h"
#include "mach64_tex.h"
static void mach64SetTexImages( mach64ContextPtr mmesa,
const struct gl_texture_object *tObj )
{
mach64TexObjPtr t = (mach64TexObjPtr) tObj->DriverData;
struct gl_texture_image *baseImage = tObj->Image[0][tObj->BaseLevel];
int totalSize;
assert(t);
assert(baseImage);
if ( MACH64_DEBUG & DEBUG_VERBOSE_API )
fprintf( stderr, "%s( %p )\n", __FUNCTION__, tObj );
switch (baseImage->TexFormat) {
case MESA_FORMAT_ARGB8888:
t->textureFormat = MACH64_DATATYPE_ARGB8888;
break;
case MESA_FORMAT_ARGB4444:
t->textureFormat = MACH64_DATATYPE_ARGB4444;
break;
case MESA_FORMAT_RGB565:
t->textureFormat = MACH64_DATATYPE_RGB565;
break;
case MESA_FORMAT_ARGB1555:
t->textureFormat = MACH64_DATATYPE_ARGB1555;
break;
case MESA_FORMAT_RGB332:
t->textureFormat = MACH64_DATATYPE_RGB332;
break;
case MESA_FORMAT_RGB888:
t->textureFormat = MACH64_DATATYPE_RGB8;
break;
case MESA_FORMAT_CI8:
t->textureFormat = MACH64_DATATYPE_CI8;
break;
case MESA_FORMAT_YCBCR:
t->textureFormat = MACH64_DATATYPE_YVYU422;
break;
case MESA_FORMAT_YCBCR_REV:
t->textureFormat = MACH64_DATATYPE_VYUY422;
break;
default:
_mesa_problem(mmesa->glCtx, "Bad texture format in %s", __FUNCTION__);
};
totalSize = ( baseImage->Height *
baseImage->Width *
_mesa_get_format_bytes(baseImage->TexFormat) );
totalSize = (totalSize + 31) & ~31;
t->base.totalSize = totalSize;
t->base.firstLevel = tObj->BaseLevel;
t->base.lastLevel = tObj->BaseLevel;
/* Set the texture format */
if ( ( baseImage->_BaseFormat == GL_RGBA ) ||
( baseImage->_BaseFormat == GL_ALPHA ) ||
( baseImage->_BaseFormat == GL_LUMINANCE_ALPHA ) ) {
t->hasAlpha = 1;
} else {
t->hasAlpha = 0;
}
t->widthLog2 = baseImage->WidthLog2;
t->heightLog2 = baseImage->HeightLog2;
t->maxLog2 = baseImage->MaxLog2;
}
static void mach64UpdateTextureEnv( GLcontext *ctx, int unit )
{
mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
GLint source = mmesa->tmu_source[unit];
const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[source];
const struct gl_texture_object *tObj = texUnit->_Current;
const GLenum format = tObj->Image[0][tObj->BaseLevel]->_BaseFormat;
GLuint s = mmesa->setup.scale_3d_cntl;
if ( MACH64_DEBUG & DEBUG_VERBOSE_API ) {
fprintf( stderr, "%s( %p, %d )\n",
__FUNCTION__, ctx, unit );
}
/* REPLACE MODULATE DECAL GL_BLEND
*
* ALPHA C = Cf C = Cf undef C = Cf
* A = At A = AfAt A = AfAt
*
* LUMINANCE C = Ct C = CfCt undef C = Cf(1-Ct)+CcCt
* A = Af A = Af A = Af
*
* LUMINANCE_ALPHA C = Ct C = CfCt undef C = Cf(1-Ct)+CcCt
* A = At A = AfAt A = AfAt
*
* INTENSITY C = Ct C = CfCt undef C = Cf(1-Ct)+CcCt
* A = At A = AfAt A = Af(1-At)+AcAt
*
* RGB C = Ct C = CfCt C = Ct C = Cf(1-Ct)+CcCt
* A = Af A = Af A = Af A = Af
*
* RGBA C = Ct C = CfCt C = Cf(1-At)+CtAt C = Cf(1-Ct)+CcCt
* A = At A = AfAt A = Af A = AfAt
*/
if ( unit == 0 ) {
s &= ~MACH64_TEX_LIGHT_FCN_MASK;
/* Set the texture environment state
* Need to verify these are working correctly, but the
* texenv Mesa demo seems to work.
*/
switch ( texUnit->EnvMode ) {
case GL_REPLACE:
switch ( format ) {
case GL_ALPHA:
case GL_LUMINANCE_ALPHA:
case GL_INTENSITY:
/* Not compliant - can't get At */
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
default:
s |= MACH64_TEX_LIGHT_FCN_REPLACE;
}
break;
case GL_MODULATE:
switch ( format ) {
case GL_ALPHA:
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
case GL_RGB:
case GL_LUMINANCE:
/* These should be compliant */
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
case GL_LUMINANCE_ALPHA:
case GL_INTENSITY:
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
case GL_RGBA:
/* Should fallback when blending enabled for complete compliance */
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
default:
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
}
break;
case GL_DECAL:
switch ( format ) {
case GL_RGBA:
s |= MACH64_TEX_LIGHT_FCN_ALPHA_DECAL;
break;
case GL_RGB:
s |= MACH64_TEX_LIGHT_FCN_REPLACE;
break;
case GL_ALPHA:
case GL_LUMINANCE_ALPHA:
/* undefined - disable texturing, pass fragment unmodified */
/* Also, pass fragment alpha instead of texture alpha */
s &= ~MACH64_TEX_MAP_AEN;
s |= MACH64_TEXTURE_DISABLE;
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
case GL_LUMINANCE:
case GL_INTENSITY:
/* undefined - disable texturing, pass fragment unmodified */
s |= MACH64_TEXTURE_DISABLE;
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
default:
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
}
break;
case GL_BLEND:
/* GL_BLEND not supported by RagePRO, use software */
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
case GL_ADD:
case GL_COMBINE:
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
break;
default:
s |= MACH64_TEX_LIGHT_FCN_MODULATE;
}
if ( mmesa->setup.scale_3d_cntl != s ) {
mmesa->setup.scale_3d_cntl = s;
mmesa->dirty |= MACH64_UPLOAD_SCALE_3D_CNTL;
}
} else {
/* blend = 0, modulate = 1 - initialize to blend */
mmesa->setup.tex_cntl &= ~MACH64_COMP_COMBINE_MODULATE;
/* Set the texture composite function for multitexturing*/
switch ( texUnit->EnvMode ) {
case GL_BLEND:
/* GL_BLEND not supported by RagePRO, use software */
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
mmesa->setup.tex_cntl |= MACH64_COMP_COMBINE_MODULATE;
break;
case GL_MODULATE:
/* Should fallback when blending enabled for complete compliance */
mmesa->setup.tex_cntl |= MACH64_COMP_COMBINE_MODULATE;
break;
case GL_REPLACE:
switch ( format ) {
case GL_ALPHA:
mmesa->setup.tex_cntl |= MACH64_COMP_COMBINE_MODULATE;
break;
default: /* not supported by RagePRO */
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
mmesa->setup.tex_cntl |= MACH64_COMP_COMBINE_MODULATE;
}
break;
case GL_DECAL:
switch ( format ) {
case GL_ALPHA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
case GL_INTENSITY:
/* undefined, disable compositing and pass fragment unmodified */
mmesa->setup.tex_cntl &= ~MACH64_TEXTURE_COMPOSITE;
break;
default: /* not supported by RagePRO */
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
mmesa->setup.tex_cntl |= MACH64_COMP_COMBINE_MODULATE;
}
break;
case GL_ADD:
case GL_COMBINE:
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
mmesa->setup.tex_cntl |= MACH64_COMP_COMBINE_MODULATE;
break;
default:
mmesa->setup.tex_cntl |= MACH64_COMP_COMBINE_MODULATE;
}
}
}
static void mach64UpdateTextureUnit( GLcontext *ctx, int unit )
{
mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
int source = mmesa->tmu_source[unit];
const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[source];
const struct gl_texture_object *tObj = ctx->Texture.Unit[source]._Current;
mach64TexObjPtr t = tObj->DriverData;
GLuint d = mmesa->setup.dp_pix_width;
GLuint s = mmesa->setup.scale_3d_cntl;
assert(unit == 0 || unit == 1); /* only two tex units */
if ( MACH64_DEBUG & DEBUG_VERBOSE_API ) {
fprintf( stderr, "%s( %p, %d ) enabled=0x%x 0x%x\n",
__FUNCTION__, ctx, unit, ctx->Texture.Unit[0]._ReallyEnabled,
ctx->Texture.Unit[1]._ReallyEnabled);
}
if (texUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) {
assert(t); /* should have driver tex data by now */
/* Fallback if there's a texture border */
if ( tObj->Image[0][tObj->BaseLevel]->Border > 0 ) {
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
return;
}
/* Upload teximages */
if (t->base.dirty_images[0]) {
mach64SetTexImages( mmesa, tObj );
mmesa->dirty |= (MACH64_UPLOAD_TEX0IMAGE << unit);
}
/* Bind to the given texture unit */
mmesa->CurrentTexObj[unit] = t;
t->base.bound |= (1 << unit);
if ( t->base.memBlock )
driUpdateTextureLRU( (driTextureObject *) t ); /* XXX: should be locked! */
/* register setup */
if ( unit == 0 ) {
d &= ~MACH64_SCALE_PIX_WIDTH_MASK;
d |= (t->textureFormat << 28);
s &= ~(MACH64_TEXTURE_DISABLE |
MACH64_TEX_CACHE_SPLIT |
MACH64_TEX_BLEND_FCN_MASK |
MACH64_TEX_MAP_AEN);
if ( mmesa->multitex ) {
s |= MACH64_TEX_BLEND_FCN_TRILINEAR | MACH64_TEX_CACHE_SPLIT;
} else if ( t->BilinearMin ) {
s |= MACH64_TEX_BLEND_FCN_LINEAR;
} else {
s |= MACH64_TEX_BLEND_FCN_NEAREST;
}
if ( t->BilinearMag ) {
s |= MACH64_BILINEAR_TEX_EN;
} else {
s &= ~MACH64_BILINEAR_TEX_EN;
}
if ( t->hasAlpha ) {
s |= MACH64_TEX_MAP_AEN;
}
mmesa->setup.tex_cntl &= ~(MACH64_TEXTURE_CLAMP_S |
MACH64_TEXTURE_CLAMP_T |
MACH64_SECONDARY_STW);
if ( t->ClampS ) {
mmesa->setup.tex_cntl |= MACH64_TEXTURE_CLAMP_S;
}
if ( t->ClampT ) {
mmesa->setup.tex_cntl |= MACH64_TEXTURE_CLAMP_T;
}
mmesa->setup.tex_size_pitch |= ((t->widthLog2 << 0) |
(t->maxLog2 << 4) |
(t->heightLog2 << 8));
} else {
/* Enable texture mapping mode */
s &= ~MACH64_TEXTURE_DISABLE;
d &= ~MACH64_COMPOSITE_PIX_WIDTH_MASK;
d |= (t->textureFormat << 4);
mmesa->setup.tex_cntl &= ~(MACH64_COMP_ALPHA |
MACH64_SEC_TEX_CLAMP_S |
MACH64_SEC_TEX_CLAMP_T);
mmesa->setup.tex_cntl |= (MACH64_TEXTURE_COMPOSITE |
MACH64_SECONDARY_STW);
if ( t->BilinearMin ) {
mmesa->setup.tex_cntl |= MACH64_COMP_BLEND_BILINEAR;
} else {
mmesa->setup.tex_cntl &= ~MACH64_COMP_BLEND_BILINEAR;
}
if ( t->BilinearMag ) {
mmesa->setup.tex_cntl |= MACH64_COMP_FILTER_BILINEAR;
} else {
mmesa->setup.tex_cntl &= ~MACH64_COMP_FILTER_BILINEAR;
}
if ( t->hasAlpha ) {
mmesa->setup.tex_cntl |= MACH64_COMP_ALPHA;
}
if ( t->ClampS ) {
mmesa->setup.tex_cntl |= MACH64_SEC_TEX_CLAMP_S;
}
if ( t->ClampT ) {
mmesa->setup.tex_cntl |= MACH64_SEC_TEX_CLAMP_T;
}
mmesa->setup.tex_size_pitch |= ((t->widthLog2 << 16) |
(t->maxLog2 << 20) |
(t->heightLog2 << 24));
}
if ( mmesa->setup.scale_3d_cntl != s ) {
mmesa->setup.scale_3d_cntl = s;
mmesa->dirty |= MACH64_UPLOAD_SCALE_3D_CNTL;
}
if ( mmesa->setup.dp_pix_width != d ) {
mmesa->setup.dp_pix_width = d;
mmesa->dirty |= MACH64_UPLOAD_DP_PIX_WIDTH;
}
}
else if (texUnit->_ReallyEnabled) {
/* 3D or cube map texture enabled - fallback */
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_TRUE );
}
else {
/* texture unit disabled */
}
}
/* Update the hardware texture state */
void mach64UpdateTextureState( GLcontext *ctx )
{
mach64ContextPtr mmesa = MACH64_CONTEXT(ctx);
if ( MACH64_DEBUG & DEBUG_VERBOSE_API ) {
fprintf( stderr, "%s( %p ) en=0x%x 0x%x\n",
__FUNCTION__, ctx, ctx->Texture.Unit[0]._ReallyEnabled,
ctx->Texture.Unit[1]._ReallyEnabled);
}
/* Clear any texturing fallbacks */
FALLBACK( mmesa, MACH64_FALLBACK_TEXTURE, GL_FALSE );
/* Unbind any currently bound textures */
if ( mmesa->CurrentTexObj[0] ) mmesa->CurrentTexObj[0]->base.bound = 0;
if ( mmesa->CurrentTexObj[1] ) mmesa->CurrentTexObj[1]->base.bound = 0;
mmesa->CurrentTexObj[0] = NULL;
mmesa->CurrentTexObj[1] = NULL;
/* Disable all texturing until it is known to be good */
mmesa->setup.scale_3d_cntl |= MACH64_TEXTURE_DISABLE;
mmesa->setup.scale_3d_cntl &= ~MACH64_TEX_MAP_AEN;
mmesa->setup.tex_cntl &= ~MACH64_TEXTURE_COMPOSITE;
mmesa->setup.tex_size_pitch = 0x00000000;
mmesa->tmu_source[0] = 0;
mmesa->tmu_source[1] = 1;
mmesa->multitex = 0;
if (ctx->Texture._EnabledUnits & 0x2) {
/* unit 1 enabled */
if (ctx->Texture._EnabledUnits & 0x1) {
/* units 0 and 1 enabled */
mmesa->multitex = 1;
mach64UpdateTextureUnit( ctx, 0 );
mach64UpdateTextureEnv( ctx, 0 );
mach64UpdateTextureUnit( ctx, 1 );
mach64UpdateTextureEnv( ctx, 1 );
} else {
mmesa->tmu_source[0] = 1;
mmesa->tmu_source[1] = 0;
mach64UpdateTextureUnit( ctx, 0 );
mach64UpdateTextureEnv( ctx, 0 );
}
} else if (ctx->Texture._EnabledUnits & 0x1) {
/* only unit 0 enabled */
mach64UpdateTextureUnit( ctx, 0 );
mach64UpdateTextureEnv( ctx, 0 );
}
mmesa->dirty |= (MACH64_UPLOAD_SCALE_3D_CNTL |
MACH64_UPLOAD_TEXTURE);
}
/* Due to the way we must program texture state into the Rage Pro,
* we must leave these calculations to the absolute last minute.
*/
void mach64EmitTexStateLocked( mach64ContextPtr mmesa,
mach64TexObjPtr t0,
mach64TexObjPtr t1 )
{
drm_mach64_sarea_t *sarea = mmesa->sarea;
drm_mach64_context_regs_t *regs = &(mmesa->setup);
/* for multitex, both textures must be local or AGP */
if ( t0 && t1 )
assert(t0->heap == t1->heap);
if ( t0 ) {
if (t0->heap == MACH64_CARD_HEAP) {
#if ENABLE_PERF_BOXES
mmesa->c_texsrc_card++;
#endif
mmesa->setup.tex_cntl &= ~MACH64_TEX_SRC_AGP;
} else {
#if ENABLE_PERF_BOXES
mmesa->c_texsrc_agp++;
#endif
mmesa->setup.tex_cntl |= MACH64_TEX_SRC_AGP;
}
mmesa->setup.tex_offset = t0->bufAddr;
}
if ( t1 ) {
mmesa->setup.secondary_tex_off = t1->bufAddr;
}
memcpy( &sarea->context_state.tex_size_pitch, ®s->tex_size_pitch,
MACH64_NR_TEXTURE_REGS * sizeof(GLuint) );
}
|