2 * Author: Max Lingua <sunmax@libero.it>
10 #include "simple_list.h"
13 #include "texformat.h"
15 #include "swrast/swrast.h"
18 #include "s3v_context.h"
22 extern void s3vSwapOutTexObj(s3vContextPtr vmesa
, s3vTextureObjectPtr t
);
23 extern void s3vDestroyTexObj(s3vContextPtr vmesa
, s3vTextureObjectPtr t
);
26 static GLuint s3vComputeLodBias(GLfloat bias)
29 DEBUG_TEX(("*** s3vComputeLodBias ***\n"));
35 static void s3vSetTexWrapping(s3vContextPtr vmesa
,
36 s3vTextureObjectPtr t
,
37 GLenum wraps
, GLenum wrapt
)
39 GLuint t0
= t
->TextureCMD
;
40 GLuint cmd
= vmesa
->CMD
;
42 static unsigned int times
=0;
43 DEBUG_TEX(("*** s3vSetTexWrapping: #%i ***\n", ++times
));
48 cmd
&= ~TEX_WRAP_MASK
;
50 if ((wraps
!= GL_CLAMP
) || (wrapt
!= GL_CLAMP
)) {
51 DEBUG(("TEX_WRAP_ON\n"));
56 cmd
|= TEX_WRAP_ON
; /* FIXME: broken if off */
62 static void s3vSetTexFilter(s3vContextPtr vmesa
,
63 s3vTextureObjectPtr t
,
64 GLenum minf
, GLenum magf
)
66 GLuint t0
= t
->TextureCMD
;
67 GLuint cmd
= vmesa
->CMD
;
69 static unsigned int times
=0;
70 DEBUG_TEX(("*** s3vSetTexFilter: #%i ***\n", ++times
));
73 t0
&= ~TEX_FILTER_MASK
;
74 cmd
&= ~TEX_FILTER_MASK
;
78 DEBUG(("GL_NEAREST\n"));
83 DEBUG(("GL_LINEAR\n"));
87 case GL_NEAREST_MIPMAP_NEAREST
:
88 DEBUG(("GL_MIPMAP_NEAREST\n"));
92 case GL_LINEAR_MIPMAP_NEAREST
:
93 DEBUG(("GL_LINEAR_MIPMAP_NEAREST\n"));
94 t0
|= LINEAR_MIP_NEAREST
;
95 cmd
|= LINEAR_MIP_NEAREST
;
97 case GL_NEAREST_MIPMAP_LINEAR
:
98 DEBUG(("GL_NEAREST_MIPMAP_LINEAR\n"));
102 case GL_LINEAR_MIPMAP_LINEAR
:
103 DEBUG(("GL_LINEAR_MIPMAP_LINEAR\n"));
104 t0
|= LINEAR_MIP_LINEAR
;
105 cmd
|= LINEAR_MIP_LINEAR
;
110 /* FIXME: bilinear? */
125 DEBUG(("CMD was = 0x%x\n", vmesa
->CMD
));
126 DEBUG(("CMD is = 0x%x\n", cmd
));
133 static void s3vSetTexBorderColor(s3vContextPtr vmesa
,
134 s3vTextureObjectPtr t
,
138 static unsigned int times
=0;
139 DEBUG_TEX(("*** s3vSetTexBorderColor: #%i ***\n", ++times
));
142 /*FIXME: it should depend on tex col format */
143 /* switch(t0 ... t->TextureColorMode) */
145 /* case TEX_COL_ARGB1555: */
146 t
->TextureBorderColor
=
147 S3VIRGEPACKCOLOR555(color
[0], color
[1], color
[2], color
[3]);
149 DEBUG(("TextureBorderColor = 0x%x\n", t
->TextureBorderColor
));
151 vmesa
->TextureBorderColor
= t
->TextureBorderColor
;
154 static void s3vTexParameter( GLcontext
*ctx
, GLenum target
,
155 struct gl_texture_object
*tObj
,
156 GLenum pname
, const GLfloat
*params
)
158 s3vContextPtr vmesa
= S3V_CONTEXT(ctx
);
159 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) tObj
->DriverData
;
161 static unsigned int times
=0;
162 DEBUG_TEX(("*** s3vTexParameter: #%i ***\n", ++times
));
167 /* Can't do the update now as we don't know whether to flush
168 * vertices or not. Setting vmesa->new_state means that
169 * s3vUpdateTextureState() will be called before any triangles are
170 * rendered. If a statechange has occurred, it will be detected at
171 * that point, and buffered vertices flushed.
174 case GL_TEXTURE_MIN_FILTER
:
175 case GL_TEXTURE_MAG_FILTER
:
176 s3vSetTexFilter( vmesa
, t
, tObj
->MinFilter
, tObj
->MagFilter
);
179 case GL_TEXTURE_WRAP_S
:
180 case GL_TEXTURE_WRAP_T
:
181 s3vSetTexWrapping( vmesa
, t
, tObj
->WrapS
, tObj
->WrapT
);
184 case GL_TEXTURE_BORDER_COLOR
:
185 s3vSetTexBorderColor( vmesa
, t
, tObj
->_BorderChan
);
188 case GL_TEXTURE_BASE_LEVEL
:
189 case GL_TEXTURE_MAX_LEVEL
:
190 case GL_TEXTURE_MIN_LOD
:
191 case GL_TEXTURE_MAX_LOD
:
192 /* This isn't the most efficient solution but there doesn't appear to
193 * be a nice alternative for Virge. Since there's no LOD clamping,
194 * we just have to rely on loading the right subset of mipmap levels
195 * to simulate a clamped LOD.
197 s3vSwapOutTexObj( vmesa
, t
);
204 if (t
== vmesa
->CurrentTexObj
[0])
205 vmesa
->dirty
|= S3V_UPLOAD_TEX0
;
208 if (t
== vmesa
->CurrentTexObj
[1]) {
209 vmesa
->dirty
|= S3V_UPLOAD_TEX1
;
215 static void s3vTexEnv( GLcontext
*ctx
, GLenum target
,
216 GLenum pname
, const GLfloat
*param
)
218 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
219 GLuint unit
= ctx
->Texture
.CurrentUnit
;
221 static unsigned int times
=0;
222 DEBUG_TEX(("*** s3vTexEnv: #%i ***\n", ++times
));
225 /* Only one env color. Need a fallback if env colors are different
226 * and texture setup references env color in both units.
229 case GL_TEXTURE_ENV_COLOR
: {
230 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
231 GLfloat
*fc
= texUnit
->EnvColor
;
232 GLuint r
, g
, b
, a
, col
;
233 CLAMPED_FLOAT_TO_UBYTE(r
, fc
[0]);
234 CLAMPED_FLOAT_TO_UBYTE(g
, fc
[1]);
235 CLAMPED_FLOAT_TO_UBYTE(b
, fc
[2]);
236 CLAMPED_FLOAT_TO_UBYTE(a
, fc
[3]);
245 case GL_TEXTURE_ENV_MODE
:
246 vmesa
->TexEnvImageFmt
[unit
] = 0; /* force recalc of env state */
248 case GL_TEXTURE_LOD_BIAS_EXT
: {
250 struct gl_texture_object *tObj =
251 ctx->Texture.Unit[unit]._Current;
253 s3vTextureObjectPtr t = (s3vTextureObjectPtr) tObj->DriverData;
262 static void s3vTexImage1D( GLcontext
*ctx
, GLenum target
, GLint level
,
263 GLint internalFormat
,
264 GLint width
, GLint border
,
265 GLenum format
, GLenum type
,
266 const GLvoid
*pixels
,
267 const struct gl_pixelstore_attrib
*pack
,
268 struct gl_texture_object
*texObj
,
269 struct gl_texture_image
*texImage
)
271 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
272 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) texObj
->DriverData
;
274 static unsigned int times
=0;
275 DEBUG_TEX(("*** s3vTexImage1D: #%i ***\n", ++times
));
283 s3vSwapOutTexObj( vmesa
, t
);
285 s3vDestroyTexObj( vmesa, t );
286 texObj->DriverData = 0;
290 _mesa_store_teximage1d( ctx
, target
, level
, internalFormat
,
291 width
, border
, format
, type
,
292 pixels
, pack
, texObj
, texImage
);
295 static void s3vTexSubImage1D( GLcontext
*ctx
,
300 GLenum format
, GLenum type
,
301 const GLvoid
*pixels
,
302 const struct gl_pixelstore_attrib
*pack
,
303 struct gl_texture_object
*texObj
,
304 struct gl_texture_image
*texImage
)
306 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
307 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) texObj
->DriverData
;
309 static unsigned int times
=0;
310 DEBUG_TEX(("*** s3vTexSubImage1D: #%i ***\n", ++times
));
318 s3vSwapOutTexObj( vmesa
, t
);
320 s3vDestroyTexObj( vmesa, t );
321 texObj->DriverData = 0;
325 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
326 format
, type
, pixels
, pack
, texObj
,
330 static void s3vTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
331 GLint internalFormat
,
332 GLint width
, GLint height
, GLint border
,
333 GLenum format
, GLenum type
, const GLvoid
*pixels
,
334 const struct gl_pixelstore_attrib
*packing
,
335 struct gl_texture_object
*texObj
,
336 struct gl_texture_image
*texImage
)
338 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
339 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) texObj
->DriverData
;
342 static unsigned int times
=0;
343 DEBUG_TEX(("*** s3vTexImage2D: #%i ***\n", ++times
));
351 s3vSwapOutTexObj( vmesa
, t
);
353 s3vDestroyTexObj( vmesa, t );
354 texObj->DriverData = 0;
358 _mesa_store_teximage2d( ctx
, target
, level
, internalFormat
,
359 width
, height
, border
, format
, type
,
360 pixels
, packing
, texObj
, texImage
);
363 static void s3vTexSubImage2D( GLcontext
*ctx
,
366 GLint xoffset
, GLint yoffset
,
367 GLsizei width
, GLsizei height
,
368 GLenum format
, GLenum type
,
369 const GLvoid
*pixels
,
370 const struct gl_pixelstore_attrib
*packing
,
371 struct gl_texture_object
*texObj
,
372 struct gl_texture_image
*texImage
)
374 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
375 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) texObj
->DriverData
;
377 static unsigned int times
=0;
378 DEBUG_TEX(("*** s3vTexSubImage2D: #%i ***\n", ++times
));
386 s3vSwapOutTexObj( vmesa
, t
);
388 s3vDestroyTexObj( vmesa, t );
389 texObj->DriverData = 0;
393 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
394 height
, format
, type
, pixels
, packing
, texObj
,
399 static void s3vBindTexture( GLcontext
*ctx
, GLenum target
,
400 struct gl_texture_object
*tObj
)
402 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
403 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) tObj
->DriverData
;
404 GLuint cmd
= vmesa
->CMD
;
406 static unsigned int times
=0;
407 DEBUG_TEX(("*** s3vBindTexture: #%i ***\n", ++times
));
412 GLfloat bias = ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias;
414 t
= CALLOC_STRUCT(s3v_texture_object_t
);
416 /* Initialize non-image-dependent parts of the state:
420 if (target
== GL_TEXTURE_2D
) {
422 if (target
== GL_TEXTURE_1D
) {
425 #if X_BYTE_ORDER == X_LITTLE_ENDIAN
426 t
->TextureFormat
= (TF_LittleEndian
|
428 t
->TextureFormat
= (TF_BigEndian
|
431 t
->dirty_images
= ~0;
433 tObj
->DriverData
= t
;
434 make_empty_list( t
);
436 s3vSetTexWrapping( vmesa
, t
, tObj
->WrapS
, tObj
->WrapT
);
437 s3vSetTexFilter( vmesa
, t
, tObj
->MinFilter
, tObj
->MagFilter
);
438 s3vSetTexBorderColor( vmesa
, t
, tObj
->BorderColor
);
442 cmd
= vmesa
->CMD
& ~MIP_MASK
;
443 vmesa
->dirty
|= S3V_UPLOAD_TEX0
;
444 vmesa
->TexOffset
= t
->TextureBaseAddr
[tObj
->BaseLevel
];
445 vmesa
->TexStride
= t
->Pitch
;
446 cmd
|= MIPMAP_LEVEL(t
->WidthLog2
);
448 vmesa
->restore_primitive
= -1;
450 printf("t->TextureBaseAddr[0] = 0x%x\n", t
->TextureBaseAddr
[0]);
451 printf("t->TextureBaseAddr[1] = 0x%x\n", t
->TextureBaseAddr
[1]);
452 printf("t->TextureBaseAddr[2] = 0x%x\n", t
->TextureBaseAddr
[2]);
457 static void s3vDeleteTexture( GLcontext
*ctx
, struct gl_texture_object
*tObj
)
459 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
)tObj
->DriverData
;
461 static unsigned int times
=0;
462 DEBUG_TEX(("*** s3vDeleteTexture: #%i ***\n", ++times
));
466 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
474 s3vDestroyTexObj( vmesa
, t
);
475 tObj
->DriverData
= 0;
480 static GLboolean
s3vIsTextureResident( GLcontext
*ctx
,
481 struct gl_texture_object
*tObj
)
483 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
)tObj
->DriverData
;
485 static unsigned int times
=0;
486 DEBUG_TEX(("*** s3vIsTextureResident: #%i ***\n", ++times
));
489 return (t
&& t
->MemBlock
);
492 static void s3vInitTextureObjects( GLcontext
*ctx
)
494 /* s3vContextPtr vmesa = S3V_CONTEXT(ctx); */
495 struct gl_texture_object
*texObj
;
496 GLuint tmp
= ctx
->Texture
.CurrentUnit
;
498 static unsigned int times
=0;
499 DEBUG_TEX(("*** s3vInitTextureObjects: #%i ***\n", ++times
));
503 ctx
->Texture
.CurrentUnit
= 0;
505 texObj
= ctx
->Texture
.Unit
[0].Current1D
;
506 s3vBindTexture( ctx
, GL_TEXTURE_1D
, texObj
);
508 texObj
= ctx
->Texture
.Unit
[0].Current2D
;
509 s3vBindTexture( ctx
, GL_TEXTURE_2D
, texObj
);
513 ctx
->Texture
.CurrentUnit
= 1;
515 texObj
= ctx
->Texture
.Unit
[1].Current1D
;
516 s3vBindTexture( ctx
, GL_TEXTURE_1D
, texObj
);
518 texObj
= ctx
->Texture
.Unit
[1].Current2D
;
519 s3vBindTexture( ctx
, GL_TEXTURE_2D
, texObj
);
522 ctx
->Texture
.CurrentUnit
= tmp
;
526 void s3vInitTextureFuncs( GLcontext
*ctx
)
529 static unsigned int times
=0;
530 DEBUG_TEX(("*** s3vInitTextureFuncs: #%i ***\n", ++times
));
533 ctx
->Driver
.TexEnv
= s3vTexEnv
;
534 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
535 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
536 ctx
->Driver
.TexImage2D
= s3vTexImage2D
;
537 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
538 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
539 ctx
->Driver
.TexSubImage2D
= s3vTexSubImage2D
;
540 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
541 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
542 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
543 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
544 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
545 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
546 ctx
->Driver
.BindTexture
= s3vBindTexture
;
547 ctx
->Driver
.DeleteTexture
= s3vDeleteTexture
;
548 ctx
->Driver
.TexParameter
= s3vTexParameter
;
549 ctx
->Driver
.UpdateTexturePalette
= 0;
550 ctx
->Driver
.IsTextureResident
= s3vIsTextureResident
;
551 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
553 s3vInitTextureObjects( ctx
);