From: Gareth H. <ga...@va...> - 2001-02-04 20:14:08
|
After looking into the current single-copy texture mechanism, I'd like to propose a couple of changes. This will involve completely removing the old interface, as well as providing a much more driver-friendly approach to texture image storage. Many of these ideas are similar to features found in the SI, at least from the top level. The implementation of these ideas would be quite different in our case, however. First, we add a struct gl_texture_format as follows: struct gl_texture_format { GLint internalFormat; /* Mesa format */ GLint redSize; GLint greenSize; GLint blueSize; GLint alphaSize; GLint luminanceSize; GLint intensitySize; GLint indexSize; GLint bytesPerTexel; /* Functions to return individual texels. */ void (*extractTexel)(...); ... }; We define a set of these structures: const struct gl_texture_format gl_tex_format_argb8888 = { MESA_FORMAT_ARGB8888, 8, 8, 8, 8, 0, 0, 0, 4, ... }; const struct gl_texture_format gl_tex_format_rgb565 = { MESA_FORMAT_RGB565, 5, 6, 5, 0, 0, 0, 0, 2, ... }; and so on. We add a pointer to such a structure to struct gl_texture_image, and add a driver callback to allow the driver to select the best format. Thus, _mesa_TexImage*() has something like the following: struct gl_texture_format *texFormat; texFormat = (*ctx->Driver.ChooseTextureFormat)( ... ); texImage->texFormat = texFormat; texImage->RedBits = texFormat->redSize; texImage->GreenBits = texFormat->greenSize; texImage->BlueBits = texFormat->blueSize; texImage->AlphaBits = texFormat->alphaSize; texImage->IntensityBits = texFormat->intensitySize; texImage->LuminanceBits = texFormat->luminanceSize; texImage->IndexBits = texFormat->indexSize; The Driver.TexImage* callbacks are now no longer allowed to fail. _mesa_TexImage* hands control over to the driver, which does any driver-specific work (such as the tdfx driver making sure the aspect ratio is okay), before calling the _mesa_convert_teximage helper function. I still have to work out the nicest way to handle this, as _mesa_convert_teximage or equivalent has changed quite a bit. It may be that the core Mesa code actually does the image conversion with the information returned from the driver callback. Basically, _mesa_convert_teximage has a couple of layers of conversion function tables, depending on the input and output formats etc. This allows MMX-optimized conversion routines to be used in a variety of situations. Things like the current pixelstore attributes, whether the image needs rescaling, and whether the input and output types are supported are used to determine if a fast conversion can be done. If a fast conversion can be done, the function tables are used to select the correct function and we're done. If not, _mesa_convert_teximage will fall back to doing a generic image conversion. The critical difference here is that the driver selects the internal format to be used (like MESA_FORMAT_ARGB4444, MESA_FORMAT_AL88 etc), and the conversion function is guaranteed to return a tightly-packed image with that type. The conversion function is smart enough to pack RGB input data into RGBA textures, or alpha/luminance only data into an AL88 texture and so on. We do not need extra internal types to handle this. The software rasterizer uses the texFormat->extractTexel()-like functions to extract individual or blocks of texels. The SI has a number of texel extraction functions per format, to support textures with and without borders and so on. The correct one would be plugged into texImage->extract(). This means that the image can be converted once only, stored in a hardware-friendly format, and interacted with by the software rasterizer. I think this is nicer than having to unconvert the entire image when there's a software fallback. Brian, I'm not sure if you're going to get this, and I know you said you were going to look into a texel extraction interface as well. I wanted to let you know where I'm going with this to avoid duplicate work and let you comment on my thoughts. -- Gareth |