2 * Author: Max Lingua <sunmax@libero.it>
8 #include "main/glheader.h"
9 #include "main/mtypes.h"
10 #include "main/simple_list.h"
11 #include "main/enums.h"
13 #include "main/texstore.h"
14 #include "main/texformat.h"
15 #include "main/teximage.h"
16 #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
,
135 const GLfloat color
[4])
138 CLAMPED_FLOAT_TO_UBYTE(c
[0], color
[0]);
139 CLAMPED_FLOAT_TO_UBYTE(c
[1], color
[1]);
140 CLAMPED_FLOAT_TO_UBYTE(c
[2], color
[2]);
141 CLAMPED_FLOAT_TO_UBYTE(c
[3], color
[3]);
144 static unsigned int times
=0;
145 DEBUG_TEX(("*** s3vSetTexBorderColor: #%i ***\n", ++times
));
148 /*FIXME: it should depend on tex col format */
149 /* switch(t0 ... t->TextureColorMode) */
151 /* case TEX_COL_ARGB1555: */
152 t
->TextureBorderColor
= S3VIRGEPACKCOLOR555(c
[0], c
[1], c
[2], c
[3]);
154 DEBUG(("TextureBorderColor = 0x%x\n", t
->TextureBorderColor
));
156 vmesa
->TextureBorderColor
= t
->TextureBorderColor
;
159 static void s3vTexParameter( GLcontext
*ctx
, GLenum target
,
160 struct gl_texture_object
*tObj
,
161 GLenum pname
, const GLfloat
*params
)
163 s3vContextPtr vmesa
= S3V_CONTEXT(ctx
);
164 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) tObj
->DriverData
;
166 static unsigned int times
=0;
167 DEBUG_TEX(("*** s3vTexParameter: #%i ***\n", ++times
));
172 /* Can't do the update now as we don't know whether to flush
173 * vertices or not. Setting vmesa->new_state means that
174 * s3vUpdateTextureState() will be called before any triangles are
175 * rendered. If a statechange has occurred, it will be detected at
176 * that point, and buffered vertices flushed.
179 case GL_TEXTURE_MIN_FILTER
:
180 case GL_TEXTURE_MAG_FILTER
:
181 s3vSetTexFilter( vmesa
, t
, tObj
->MinFilter
, tObj
->MagFilter
);
184 case GL_TEXTURE_WRAP_S
:
185 case GL_TEXTURE_WRAP_T
:
186 s3vSetTexWrapping( vmesa
, t
, tObj
->WrapS
, tObj
->WrapT
);
189 case GL_TEXTURE_BORDER_COLOR
:
190 s3vSetTexBorderColor( vmesa
, t
, tObj
->BorderColor
);
193 case GL_TEXTURE_BASE_LEVEL
:
194 case GL_TEXTURE_MAX_LEVEL
:
195 case GL_TEXTURE_MIN_LOD
:
196 case GL_TEXTURE_MAX_LOD
:
197 /* This isn't the most efficient solution but there doesn't appear to
198 * be a nice alternative for Virge. Since there's no LOD clamping,
199 * we just have to rely on loading the right subset of mipmap levels
200 * to simulate a clamped LOD.
202 s3vSwapOutTexObj( vmesa
, t
);
209 if (t
== vmesa
->CurrentTexObj
[0])
210 vmesa
->dirty
|= S3V_UPLOAD_TEX0
;
213 if (t
== vmesa
->CurrentTexObj
[1]) {
214 vmesa
->dirty
|= S3V_UPLOAD_TEX1
;
220 static void s3vTexEnv( GLcontext
*ctx
, GLenum target
,
221 GLenum pname
, const GLfloat
*param
)
223 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
224 GLuint unit
= ctx
->Texture
.CurrentUnit
;
226 static unsigned int times
=0;
227 DEBUG_TEX(("*** s3vTexEnv: #%i ***\n", ++times
));
230 /* Only one env color. Need a fallback if env colors are different
231 * and texture setup references env color in both units.
234 case GL_TEXTURE_ENV_COLOR
: {
235 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
236 GLfloat
*fc
= texUnit
->EnvColor
;
237 GLuint r
, g
, b
, a
, col
;
238 CLAMPED_FLOAT_TO_UBYTE(r
, fc
[0]);
239 CLAMPED_FLOAT_TO_UBYTE(g
, fc
[1]);
240 CLAMPED_FLOAT_TO_UBYTE(b
, fc
[2]);
241 CLAMPED_FLOAT_TO_UBYTE(a
, fc
[3]);
250 case GL_TEXTURE_ENV_MODE
:
251 vmesa
->TexEnvImageFmt
[unit
] = 0; /* force recalc of env state */
253 case GL_TEXTURE_LOD_BIAS_EXT
: {
255 struct gl_texture_object *tObj =
256 ctx->Texture.Unit[unit]._Current;
258 s3vTextureObjectPtr t = (s3vTextureObjectPtr) tObj->DriverData;
267 static void s3vTexImage1D( GLcontext
*ctx
, GLenum target
, GLint level
,
268 GLint internalFormat
,
269 GLint width
, GLint border
,
270 GLenum format
, GLenum type
,
271 const GLvoid
*pixels
,
272 const struct gl_pixelstore_attrib
*pack
,
273 struct gl_texture_object
*texObj
,
274 struct gl_texture_image
*texImage
)
276 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
277 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) texObj
->DriverData
;
279 static unsigned int times
=0;
280 DEBUG_TEX(("*** s3vTexImage1D: #%i ***\n", ++times
));
288 s3vSwapOutTexObj( vmesa
, t
);
290 s3vDestroyTexObj( vmesa, t );
291 texObj->DriverData = 0;
295 _mesa_store_teximage1d( ctx
, target
, level
, internalFormat
,
296 width
, border
, format
, type
,
297 pixels
, pack
, texObj
, texImage
);
300 static void s3vTexSubImage1D( GLcontext
*ctx
,
305 GLenum format
, GLenum type
,
306 const GLvoid
*pixels
,
307 const struct gl_pixelstore_attrib
*pack
,
308 struct gl_texture_object
*texObj
,
309 struct gl_texture_image
*texImage
)
311 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
312 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) texObj
->DriverData
;
314 static unsigned int times
=0;
315 DEBUG_TEX(("*** s3vTexSubImage1D: #%i ***\n", ++times
));
323 s3vSwapOutTexObj( vmesa
, t
);
325 s3vDestroyTexObj( vmesa, t );
326 texObj->DriverData = 0;
330 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
331 format
, type
, pixels
, pack
, texObj
,
335 static void s3vTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
336 GLint internalFormat
,
337 GLint width
, GLint height
, GLint border
,
338 GLenum format
, GLenum type
, const GLvoid
*pixels
,
339 const struct gl_pixelstore_attrib
*packing
,
340 struct gl_texture_object
*texObj
,
341 struct gl_texture_image
*texImage
)
343 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
344 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) texObj
->DriverData
;
347 static unsigned int times
=0;
348 DEBUG_TEX(("*** s3vTexImage2D: #%i ***\n", ++times
));
356 s3vSwapOutTexObj( vmesa
, t
);
358 s3vDestroyTexObj( vmesa, t );
359 texObj->DriverData = 0;
363 _mesa_store_teximage2d( ctx
, target
, level
, internalFormat
,
364 width
, height
, border
, format
, type
,
365 pixels
, packing
, texObj
, texImage
);
368 static void s3vTexSubImage2D( GLcontext
*ctx
,
371 GLint xoffset
, GLint yoffset
,
372 GLsizei width
, GLsizei height
,
373 GLenum format
, GLenum type
,
374 const GLvoid
*pixels
,
375 const struct gl_pixelstore_attrib
*packing
,
376 struct gl_texture_object
*texObj
,
377 struct gl_texture_image
*texImage
)
379 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
380 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) texObj
->DriverData
;
382 static unsigned int times
=0;
383 DEBUG_TEX(("*** s3vTexSubImage2D: #%i ***\n", ++times
));
391 s3vSwapOutTexObj( vmesa
, t
);
393 s3vDestroyTexObj( vmesa, t );
394 texObj->DriverData = 0;
398 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
399 height
, format
, type
, pixels
, packing
, texObj
,
404 static void s3vBindTexture( GLcontext
*ctx
, GLenum target
,
405 struct gl_texture_object
*tObj
)
407 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
408 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
) tObj
->DriverData
;
409 GLuint cmd
= vmesa
->CMD
;
411 static unsigned int times
=0;
412 DEBUG_TEX(("*** s3vBindTexture: #%i ***\n", ++times
));
417 GLfloat bias = ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias;
419 t
= CALLOC_STRUCT(s3v_texture_object_t
);
421 /* Initialize non-image-dependent parts of the state:
425 if (target
== GL_TEXTURE_2D
) {
427 if (target
== GL_TEXTURE_1D
) {
430 #if X_BYTE_ORDER == X_LITTLE_ENDIAN
431 t
->TextureFormat
= (TF_LittleEndian
|
433 t
->TextureFormat
= (TF_BigEndian
|
436 t
->dirty_images
= ~0;
438 tObj
->DriverData
= t
;
439 make_empty_list( t
);
441 s3vSetTexWrapping( vmesa
, t
, tObj
->WrapS
, tObj
->WrapT
);
442 s3vSetTexFilter( vmesa
, t
, tObj
->MinFilter
, tObj
->MagFilter
);
443 s3vSetTexBorderColor( vmesa
, t
, tObj
->BorderColor
);
447 cmd
= vmesa
->CMD
& ~MIP_MASK
;
448 vmesa
->dirty
|= S3V_UPLOAD_TEX0
;
449 vmesa
->TexOffset
= t
->TextureBaseAddr
[tObj
->BaseLevel
];
450 vmesa
->TexStride
= t
->Pitch
;
451 cmd
|= MIPMAP_LEVEL(t
->WidthLog2
);
453 vmesa
->restore_primitive
= -1;
455 printf("t->TextureBaseAddr[0] = 0x%x\n", t
->TextureBaseAddr
[0]);
456 printf("t->TextureBaseAddr[1] = 0x%x\n", t
->TextureBaseAddr
[1]);
457 printf("t->TextureBaseAddr[2] = 0x%x\n", t
->TextureBaseAddr
[2]);
462 static void s3vDeleteTexture( GLcontext
*ctx
, struct gl_texture_object
*tObj
)
464 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
)tObj
->DriverData
;
466 static unsigned int times
=0;
467 DEBUG_TEX(("*** s3vDeleteTexture: #%i ***\n", ++times
));
471 s3vContextPtr vmesa
= S3V_CONTEXT( ctx
);
479 s3vDestroyTexObj( vmesa
, t
);
480 tObj
->DriverData
= 0;
485 static GLboolean
s3vIsTextureResident( GLcontext
*ctx
,
486 struct gl_texture_object
*tObj
)
488 s3vTextureObjectPtr t
= (s3vTextureObjectPtr
)tObj
->DriverData
;
490 static unsigned int times
=0;
491 DEBUG_TEX(("*** s3vIsTextureResident: #%i ***\n", ++times
));
494 return (t
&& t
->MemBlock
);
497 static void s3vInitTextureObjects( GLcontext
*ctx
)
499 /* s3vContextPtr vmesa = S3V_CONTEXT(ctx); */
500 struct gl_texture_object
*texObj
;
501 GLuint tmp
= ctx
->Texture
.CurrentUnit
;
503 static unsigned int times
=0;
504 DEBUG_TEX(("*** s3vInitTextureObjects: #%i ***\n", ++times
));
508 ctx
->Texture
.CurrentUnit
= 0;
510 texObj
= ctx
->Texture
.Unit
[0].CurrentTex
[TEXTURE_1D_INDEX
];
511 s3vBindTexture( ctx
, GL_TEXTURE_1D
, texObj
);
513 texObj
= ctx
->Texture
.Unit
[0].CurrentTex
[TEXTURE_2D_INDEX
];
514 s3vBindTexture( ctx
, GL_TEXTURE_2D
, texObj
);
518 ctx
->Texture
.CurrentUnit
= 1;
520 texObj
= ctx
->Texture
.Unit
[1].CurrentTex
[TEXTURE_1D_INDEX
];
521 s3vBindTexture( ctx
, GL_TEXTURE_1D
, texObj
);
523 texObj
= ctx
->Texture
.Unit
[1].CurrentTex
[TEXTURE_2D_INDEX
];
524 s3vBindTexture( ctx
, GL_TEXTURE_2D
, texObj
);
527 ctx
->Texture
.CurrentUnit
= tmp
;
531 void s3vInitTextureFuncs( GLcontext
*ctx
)
534 static unsigned int times
=0;
535 DEBUG_TEX(("*** s3vInitTextureFuncs: #%i ***\n", ++times
));
538 ctx
->Driver
.TexEnv
= s3vTexEnv
;
539 ctx
->Driver
.ChooseTextureFormat
= _mesa_choose_tex_format
;
540 ctx
->Driver
.TexImage1D
= _mesa_store_teximage1d
;
541 ctx
->Driver
.TexImage2D
= s3vTexImage2D
;
542 ctx
->Driver
.TexImage3D
= _mesa_store_teximage3d
;
543 ctx
->Driver
.TexSubImage1D
= _mesa_store_texsubimage1d
;
544 ctx
->Driver
.TexSubImage2D
= s3vTexSubImage2D
;
545 ctx
->Driver
.TexSubImage3D
= _mesa_store_texsubimage3d
;
546 ctx
->Driver
.CopyTexImage1D
= _swrast_copy_teximage1d
;
547 ctx
->Driver
.CopyTexImage2D
= _swrast_copy_teximage2d
;
548 ctx
->Driver
.CopyTexSubImage1D
= _swrast_copy_texsubimage1d
;
549 ctx
->Driver
.CopyTexSubImage2D
= _swrast_copy_texsubimage2d
;
550 ctx
->Driver
.CopyTexSubImage3D
= _swrast_copy_texsubimage3d
;
551 ctx
->Driver
.BindTexture
= s3vBindTexture
;
552 ctx
->Driver
.DeleteTexture
= s3vDeleteTexture
;
553 ctx
->Driver
.TexParameter
= s3vTexParameter
;
554 ctx
->Driver
.UpdateTexturePalette
= 0;
555 ctx
->Driver
.IsTextureResident
= s3vIsTextureResident
;
556 ctx
->Driver
.TestProxyTexImage
= _mesa_test_proxy_teximage
;
558 s3vInitTextureObjects( ctx
);