summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/glide
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2001-04-24 03:02:23 +0000
committerBrian Paul <[email protected]>2001-04-24 03:02:23 +0000
commit691f58930b84f5baa566052a270dc2df05806a81 (patch)
tree9577825c45cb349da3e836ee233ea46de194251b /src/mesa/drivers/glide
parent29acfe5bd40e1741c07959c4b44a9bf46d250283 (diff)
texture image code updates (not finished)
Diffstat (limited to 'src/mesa/drivers/glide')
-rw-r--r--src/mesa/drivers/glide/fxdd.c1
-rw-r--r--src/mesa/drivers/glide/fxddtex.c333
-rw-r--r--src/mesa/drivers/glide/fxdrv.h4
3 files changed, 143 insertions, 195 deletions
diff --git a/src/mesa/drivers/glide/fxdd.c b/src/mesa/drivers/glide/fxdd.c
index d18c34a32af..658fc88e097 100644
--- a/src/mesa/drivers/glide/fxdd.c
+++ b/src/mesa/drivers/glide/fxdd.c
@@ -1073,6 +1073,7 @@ fxSetupDDPointers(GLcontext * ctx)
ctx->Driver.ResizeBuffersMESA = _swrast_alloc_buffers;
ctx->Driver.Finish = fxDDFinish;
ctx->Driver.Flush = NULL;
+ ctx->Driver.ChooseTextureFormat = fxDDChooseTextureFormat;
ctx->Driver.TexImage1D = _mesa_store_teximage1d;
ctx->Driver.TexImage2D = fxDDTexImage2D;
ctx->Driver.TexImage3D = _mesa_store_teximage3d;
diff --git a/src/mesa/drivers/glide/fxddtex.c b/src/mesa/drivers/glide/fxddtex.c
index 23bc9e41f8d..166278d51d9 100644
--- a/src/mesa/drivers/glide/fxddtex.c
+++ b/src/mesa/drivers/glide/fxddtex.c
@@ -1025,110 +1025,30 @@ PrintTexture(int w, int h, int c, const GLubyte * data)
}
-static const struct gl_texture_format *
-choose_format(GLenum format, GLenum type)
+const struct gl_texture_format *
+fxDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
+ GLenum srcFormat, GLenum srcType )
{
- if (type == CHAN_TYPE) {
- switch (format) {
- case GL_ALPHA:
- return &_mesa_texformat_alpha;
- case GL_LUMINANCE:
- return &_mesa_texformat_luminance;
- case GL_LUMINANCE_ALPHA:
- return &_mesa_texformat_luminance_alpha;
- case GL_INTENSITY:
- return &_mesa_texformat_intensity;
- case GL_RGB:
- return &_mesa_texformat_rgb;
- case GL_RGBA:
- return &_mesa_texformat_rgba;
- case GL_COLOR_INDEX:
- return &_mesa_texformat_color_index;
- default:
- _mesa_problem(NULL, "Unexpected CHAN format in choose_format\n");
- return NULL;
- }
- }
- else if (format == GL_DEPTH_COMPONENT && type == GL_FLOAT) {
- return &_mesa_texformat_depth_component;
- }
- else {
- _mesa_problem(NULL, "Unexpected format/type in choose_format\n");
- return NULL;
- }
-}
-
-
-void
-fxDDTexImage2D(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)
-{
- fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
- GrTextureFormat_t gldformat;
- tfxTexInfo *ti;
- tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);
- const struct gl_texture_format *mesaTexFormat;
- GLint texelSize;
- GLboolean success;
-
- if (!fxIsTexSupported(target, internalFormat, texImage)) {
- _mesa_problem(NULL, "fx Driver: unsupported texture in fxDDTexImg()\n");
- return;
- }
-
- if (!texObj->DriverData)
- texObj->DriverData = fxAllocTexObjData(fxMesa);
- ti = fxTMGetTexInfo(texObj);
-
- if (!mml) {
- texImage->DriverData = MALLOC(sizeof(tfxMipMapLevel));
- mml = FX_MIPMAP_DATA(texImage);
- }
-
- fxTexGetFormat(internalFormat, &gldformat, NULL);
-
- fxTexGetInfo(width, height, NULL, NULL, NULL, NULL,
- NULL, NULL, &mml->wScale, &mml->hScale);
-
- mml->width = width * mml->wScale;
- mml->height = height * mml->hScale;
-
switch (internalFormat) {
case GL_INTENSITY:
case GL_INTENSITY4:
case GL_INTENSITY8:
case GL_INTENSITY12:
case GL_INTENSITY16:
- texImage->Format = GL_INTENSITY;
- texImage->FetchTexel = fetch_intensity8;
- texelSize = 1;
- mesaTexFormat = &_mesa_texformat_i8;
- break;
+ return &_mesa_texformat_i8;
case 1:
case GL_LUMINANCE:
case GL_LUMINANCE4:
case GL_LUMINANCE8:
case GL_LUMINANCE12:
case GL_LUMINANCE16:
- texImage->Format = GL_LUMINANCE;
- texImage->FetchTexel = fetch_luminance8;
- texelSize = 1;
- mesaTexFormat = &_mesa_texformat_l8;
- break;
+ return &_mesa_texformat_l8;
case GL_ALPHA:
case GL_ALPHA4:
case GL_ALPHA8:
case GL_ALPHA12:
case GL_ALPHA16:
- texImage->Format = GL_ALPHA;
- texImage->FetchTexel = fetch_alpha8;
- texelSize = 1;
- mesaTexFormat = &_mesa_texformat_a8;
- break;
+ return &_mesa_texformat_a8;
case GL_COLOR_INDEX:
case GL_COLOR_INDEX1_EXT:
case GL_COLOR_INDEX2_EXT:
@@ -1136,11 +1056,7 @@ fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level,
case GL_COLOR_INDEX8_EXT:
case GL_COLOR_INDEX12_EXT:
case GL_COLOR_INDEX16_EXT:
- texImage->Format = GL_COLOR_INDEX;
- texImage->FetchTexel = fetch_index8;
- texelSize = 1;
- mesaTexFormat = &_mesa_texformat_ci8;
- break;
+ return &_mesa_texformat_ci8;
case 2:
case GL_LUMINANCE_ALPHA:
case GL_LUMINANCE4_ALPHA4:
@@ -1149,11 +1065,7 @@ fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level,
case GL_LUMINANCE12_ALPHA4:
case GL_LUMINANCE12_ALPHA12:
case GL_LUMINANCE16_ALPHA16:
- texImage->Format = GL_LUMINANCE_ALPHA;
- texImage->FetchTexel = fetch_luminance8_alpha8;
- texelSize = 2;
- mesaTexFormat = &_mesa_texformat_al88;
- break;
+ return &_mesa_texformat_al88;
case 3:
case GL_RGB:
case GL_R3_G3_B2:
@@ -1163,11 +1075,7 @@ fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level,
case GL_RGB10:
case GL_RGB12:
case GL_RGB16:
- texImage->Format = GL_RGB;
- texImage->FetchTexel = fetch_r5g6b5;
- texelSize = 2;
- mesaTexFormat = &_mesa_texformat_rgb565;
- break;
+ return &_mesa_texformat_rgb565;
case 4:
case GL_RGBA:
case GL_RGBA2:
@@ -1176,113 +1084,143 @@ fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level,
case GL_RGB10_A2:
case GL_RGBA12:
case GL_RGBA16:
- texImage->Format = GL_RGBA;
- texImage->FetchTexel = fetch_r4g4b4a4;
- texelSize = 2;
- mesaTexFormat = &_mesa_texformat_argb4444;
- break;
+ return &_mesa_texformat_argb4444;
case GL_RGB5_A1:
- texImage->Format = GL_RGBA;
- texImage->FetchTexel = fetch_r5g5b5a1;
- texelSize = 2;
- mesaTexFormat = &_mesa_texformat_argb1555;
- break;
+ return &_mesa_texformat_argb1555;
default:
- _mesa_problem(NULL, "tdfx driver: texbuildimagemap() bad format");
- return;
+ _mesa_problem(NULL, "unexpected format in fxDDChooseTextureFormat");
+ return NULL;
}
+}
+
- texImage->TexFormat = mesaTexFormat;
+static GrTextureFormat_t
+fxGlideFormat(GLint mesaFormat)
+{
+ switch (mesaFormat) {
+ case MESA_FORMAT_I8:
+ return GR_TEXFMT_ALPHA_8;
+ case MESA_FORMAT_A8:
+ return GR_TEXFMT_ALPHA_8;
+ case MESA_FORMAT_L8:
+ return GR_TEXFMT_INTENSITY_8;
+ case MESA_FORMAT_CI8:
+ return GR_TEXFMT_P_8;
+ case MESA_FORMAT_AL88:
+ return GR_TEXFMT_ALPHA_INTENSITY_88;
+ case MESA_FORMAT_RGB565:
+ return GR_TEXFMT_RGB_565;
+ case MESA_FORMAT_ARGB4444:
+ return GR_TEXFMT_ARGB_4444;
+ case MESA_FORMAT_ARGB1555:
+ return GR_TEXFMT_ARGB_1555;
+ default:
+ _mesa_problem(NULL, "Unexpected format in fxGlideFormat");
+ return 0;
+ }
+}
+
+
+static FetchTexelFunc
+fxFetchFunction(GLint mesaFormat)
+{
+ switch (mesaFormat) {
+ case MESA_FORMAT_I8:
+ return fetch_intensity8;
+ case MESA_FORMAT_A8:
+ return fetch_alpha8;
+ case MESA_FORMAT_L8:
+ return fetch_luminance8;
+ case MESA_FORMAT_CI8:
+ return fetch_index8;
+ case MESA_FORMAT_AL88:
+ return fetch_luminance8_alpha8;
+ case MESA_FORMAT_RGB565:
+ return fetch_r5g6b5;
+ case MESA_FORMAT_ARGB4444:
+ return fetch_r4g4b4a4;
+ case MESA_FORMAT_ARGB1555:
+ return fetch_r5g5b5a1;
+ default:
+ _mesa_problem(NULL, "Unexpected format in fxGlideFormat");
+ return NULL;
+ }
+}
+
+void
+fxDDTexImage2D(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)
+{
+ fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
+ GrTextureFormat_t gldformat;
+ tfxTexInfo *ti;
+ tfxMipMapLevel *mml = FX_MIPMAP_DATA(texImage);
+ GLint texelBytes;
- /* allocate storage for texture image */
- texImage->Data = MALLOC(mml->width * mml->height * texelSize);
- if (!texImage->Data)
+ if (!fxIsTexSupported(target, internalFormat, texImage)) {
+ _mesa_problem(NULL, "fx Driver: unsupported texture in fxDDTexImg()\n");
return;
+ }
- mml->glideFormat = gldformat;
- fxTexInvalidate(ctx, texObj);
+ if (!texObj->DriverData)
+ texObj->DriverData = fxAllocTexObjData(fxMesa);
+ ti = fxTMGetTexInfo(texObj);
- /* store the texture image */
- if (ctx->_ImageTransferState ||
- mml->width != width ||
- mml->height != height) {
- /* Need to image transfer ops or image rescale */
- success = GL_FALSE;
+ if (!mml) {
+ texImage->DriverData = MALLOC(sizeof(tfxMipMapLevel));
+ mml = FX_MIPMAP_DATA(texImage);
}
- else {
- success = _mesa_convert_texsubimage2d(mesaTexFormat->MesaFormat,
- 0, 0, /* xoffset, yoffset */
- mml->width, mml->height,
- mml->width, /* destImageWidth */
- format, type, /* user fmt/type */
- packing, /* user packing params */
- pixels, texImage->Data);
+
+ fxTexGetFormat(internalFormat, &gldformat, NULL);
+
+ fxTexGetInfo(width, height, NULL, NULL, NULL, NULL,
+ NULL, NULL, &mml->wScale, &mml->hScale);
+
+ mml->width = width * mml->wScale;
+ mml->height = height * mml->hScale;
+
+ if (mml->wScale != 1 || mml->hScale != 1) {
+ /* rescale image to overcome 1:8 aspect limitation */
+
+ /* XXX TO-DO! */
}
- if (!success) {
- /* First attempt at texture conversion failed. We may need to
- * do fancy pixel transfer ops or convert from an obscure texture
- * format.
- */
- GLenum simpleFormat = _mesa_base_tex_format(ctx, internalFormat);
- GLint comps = _mesa_components_in_format(simpleFormat);
- GLubyte *tempImage;
- tempImage = MALLOC(width * height * comps * sizeof(GLubyte));
+ /*** This code basically comes from _mesa_store_teximage2d() ***/
- /* Apply pixel transfer ops and convert image format to something
- * simple (format = simpleFormat, type = CHAN_TYPE).
- */
-#if 000
- /** XXX THIS HAS TO BE REWRITTEN! **/
- _mesa_transfer_teximage(ctx, 2, /* dimensions */
- simpleFormat, /* base int format */
- simpleFormat, /* dest format */
- tempImage, /* dest addr */
- width, height, 1, /* src size */
- 0, 0, 0, /* dst offsets */
- width * comps, /* dstRowStride */
- 0, /* dstImageStride */
- format, type, pixels, packing /* src info */ );
-#endif
- if (mml->width != width || mml->height != height) {
- /* Upscale image to accomodate Glide's image aspect limitations. */
- const struct gl_texture_format *texFormat
- = choose_format(simpleFormat, CHAN_TYPE);
- GLvoid *rescaledImage = MALLOC(mml->width * mml->height
- * texFormat->TexelBytes);
- if (!rescaledImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
- return;
- }
- _mesa_rescale_teximage2d(texFormat,
- width, height, mml->width, mml->height,
- tempImage, rescaledImage);
- success = _mesa_convert_texsubimage2d(mesaTexFormat->MesaFormat,
- 0, 0, /* xoffset, yoffset */
- mml->width, mml->height,
- mml->width, /* destImageWidth */
- simpleFormat, /* source format */
- CHAN_TYPE, /* source type */
- &_mesa_native_packing,
- rescaledImage, texImage->Data);
- FREE(rescaledImage);
- }
- else {
- success = _mesa_convert_texsubimage2d(mesaTexFormat->MesaFormat,
- 0, 0, /* xoffset, yoffset */
- mml->width, mml->height,
- mml->width, /* destImageWidth */
- simpleFormat, /* source format */
- CHAN_TYPE, /* source type */
- &_mesa_native_packing,
- tempImage, texImage->Data);
- }
- /* the conversion had better of worked! */
- assert(success);
- FREE(tempImage);
+ /* choose the texture format */
+ assert(ctx->Driver.ChooseTextureFormat);
+ texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
+ internalFormat, format, type);
+ assert(texImage->TexFormat);
+
+ texelBytes = texImage->TexFormat->TexelBytes;
+
+ /* allocate memory */
+ texImage->Data = MALLOC(mml->width * mml->height * texelBytes);
+ if (!texImage->Data) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
+ return;
}
+ /* unpack image, apply transfer ops and store in texImage->Data */
+ _mesa_transfer_teximage(ctx, 2, _mesa_base_tex_format(ctx, internalFormat),
+ texImage->TexFormat, texImage->Data,
+ width, height, 1, 0, 0, 0,
+ texImage->Width * texelBytes,
+ 0, /* dstImageStride */
+ format, type, pixels, packing);
+
+
+ mml->glideFormat = fxGlideFormat(texImage->TexFormat->MesaFormat);
+ texImage->FetchTexel = fxFetchFunction(texImage->TexFormat->MesaFormat);
+
+ fxTexInvalidate(ctx, texObj);
+
if (ti->validated && ti->isInTM) {
/*printf("reloadmipmaplevels\n"); */
fxTMReloadMipMapLevel(fxMesa, texObj, level);
@@ -1306,7 +1244,6 @@ fxDDTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
tfxTexInfo *ti;
tfxMipMapLevel *mml;
- GLboolean success;
if (!texObj->DriverData) {
_mesa_problem(ctx, "problem in fxDDTexSubImage2D");
@@ -1321,7 +1258,11 @@ fxDDTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
assert(texImage->Data); /* must have an existing texture image! */
assert(texImage->Format);
- /* XXX check for image rescale */
+#if 000
+ /* XXX redo all of this */
+
+
+ /* check for image rescale */
if (ctx->_ImageTransferState ||
texImage->Width != mml->width ||
texImage->Height != mml->height) {
@@ -1405,6 +1346,8 @@ fxDDTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
assert(success);
FREE(tempImage);
}
+#endif
+
if (ti->validated && ti->isInTM)
fxTMReloadMipMapLevel(fxMesa, texObj, level);
diff --git a/src/mesa/drivers/glide/fxdrv.h b/src/mesa/drivers/glide/fxdrv.h
index 1349d5079c9..0a9944ea88a 100644
--- a/src/mesa/drivers/glide/fxdrv.h
+++ b/src/mesa/drivers/glide/fxdrv.h
@@ -562,6 +562,10 @@ extern void fxUpdateDDSpanPointers(GLcontext *);
extern void fxSetupDDSpanPointers(GLcontext *);
extern void fxPrintTextureData(tfxTexInfo * ti);
+
+extern const struct gl_texture_format *
+fxDDChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
+ GLenum srcFormat, GLenum srcType );
extern void fxDDTexImage2D(GLcontext * ctx, GLenum target, GLint level,
GLint internalFormat, GLint width, GLint height,
GLint border, GLenum format, GLenum type,