ReactOS Fundraising Campaign 2012
 
€ 3,873 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

texcompress.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.5.1
00004  *
00005  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 
00032 #include "glheader.h"
00033 #include "imports.h"
00034 #include "colormac.h"
00035 #include "context.h"
00036 #include "image.h"
00037 #include "mipmap.h"
00038 #include "texcompress.h"
00039 #include "texformat.h"
00040 #include "texstore.h"
00041 
00042 
00055 GLuint
00056 _mesa_get_compressed_formats(GLcontext *ctx, GLint *formats, GLboolean all)
00057 {
00058    GLuint n = 0;
00059    if (ctx->Extensions.ARB_texture_compression) {
00060       if (ctx->Extensions.TDFX_texture_compression_FXT1) {
00061          if (formats) {
00062             formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX;
00063             formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX;
00064          }
00065          else {
00066             n += 2;
00067          }
00068       }
00069       if (ctx->Extensions.EXT_texture_compression_s3tc) {
00070          if (formats) {
00071             formats[n++] = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
00072             /* This format has some restrictions/limitations and so should
00073              * not be returned via the GL_COMPRESSED_TEXTURE_FORMATS query.
00074              * Specifically, all transparent pixels become black.  NVIDIA
00075              * omits this format too.
00076              */
00077             if (all)
00078                formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
00079             formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
00080             formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
00081          }
00082          else {
00083             n += 3;
00084             if (all)
00085                n += 1;
00086          }
00087       }
00088       if (ctx->Extensions.S3_s3tc) {
00089          if (formats) {
00090             formats[n++] = GL_RGB_S3TC;
00091             formats[n++] = GL_RGB4_S3TC;
00092             formats[n++] = GL_RGBA_S3TC;
00093             formats[n++] = GL_RGBA4_S3TC;
00094          }
00095          else {
00096             n += 4;
00097          }
00098       }
00099 #if FEATURE_EXT_texture_sRGB
00100       if (ctx->Extensions.EXT_texture_sRGB) {
00101          if (formats) {
00102             formats[n++] = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
00103             formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
00104             formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
00105             formats[n++] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
00106          }
00107          else {
00108             n += 4;
00109          }
00110       }
00111 #endif /* FEATURE_EXT_texture_sRGB */
00112    }
00113    return n;
00114 }
00115 
00116 
00117 
00131 GLuint
00132 _mesa_compressed_texture_size( GLcontext *ctx,
00133                                GLsizei width, GLsizei height, GLsizei depth,
00134                                GLuint mesaFormat )
00135 {
00136    GLuint size;
00137 
00138    ASSERT(depth == 1);
00139    (void) depth;
00140 
00141    switch (mesaFormat) {
00142    case MESA_FORMAT_RGB_FXT1:
00143    case MESA_FORMAT_RGBA_FXT1:
00144       /* round up width to next multiple of 8, height to next multiple of 4 */
00145       width = (width + 7) & ~7;
00146       height = (height + 3) & ~3;
00147       /* 16 bytes per 8x4 tile of RGB[A] texels */
00148       size = width * height / 2;
00149       /* Textures smaller than 8x4 will effectively be made into 8x4 and
00150        * take 16 bytes.
00151        */
00152       return size;
00153    case MESA_FORMAT_RGB_DXT1:
00154    case MESA_FORMAT_RGBA_DXT1:
00155       /* round up width, height to next multiple of 4 */
00156       width = (width + 3) & ~3;
00157       height = (height + 3) & ~3;
00158       /* 8 bytes per 4x4 tile of RGB[A] texels */
00159       size = width * height / 2;
00160       /* Textures smaller than 4x4 will effectively be made into 4x4 and
00161        * take 8 bytes.
00162        */
00163       return size;
00164    case MESA_FORMAT_RGBA_DXT3:
00165    case MESA_FORMAT_RGBA_DXT5:
00166       /* round up width, height to next multiple of 4 */
00167       width = (width + 3) & ~3;
00168       height = (height + 3) & ~3;
00169       /* 16 bytes per 4x4 tile of RGBA texels */
00170       size = width * height; /* simple! */
00171       /* Textures smaller than 4x4 will effectively be made into 4x4 and
00172        * take 16 bytes.
00173        */
00174       return size;
00175    default:
00176       _mesa_problem(ctx, "bad mesaFormat in _mesa_compressed_texture_size");
00177       return 0;
00178    }
00179 }
00180 
00181 
00191 GLuint
00192 _mesa_compressed_texture_size_glenum(GLcontext *ctx,
00193                                      GLsizei width, GLsizei height,
00194                                      GLsizei depth, GLenum glformat)
00195 {
00196    GLuint mesaFormat;
00197 
00198    switch (glformat) {
00199    case GL_COMPRESSED_RGB_FXT1_3DFX:
00200       mesaFormat = MESA_FORMAT_RGB_FXT1;
00201       break;
00202    case GL_COMPRESSED_RGBA_FXT1_3DFX:
00203       mesaFormat = MESA_FORMAT_RGBA_FXT1;
00204       break;
00205    case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
00206    case GL_RGB_S3TC:
00207       mesaFormat = MESA_FORMAT_RGB_DXT1;
00208       break;
00209    case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
00210    case GL_RGB4_S3TC:
00211       mesaFormat = MESA_FORMAT_RGBA_DXT1;
00212       break;
00213    case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
00214    case GL_RGBA_S3TC:
00215       mesaFormat = MESA_FORMAT_RGBA_DXT3;
00216       break;
00217    case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
00218    case GL_RGBA4_S3TC:
00219       mesaFormat = MESA_FORMAT_RGBA_DXT5;
00220       break;
00221    default:
00222       return 0;
00223    }
00224 
00225    return _mesa_compressed_texture_size(ctx, width, height, depth, mesaFormat);
00226 }
00227 
00228 
00229 /*
00230  * Compute the bytes per row in a compressed texture image.
00231  * We use this for computing the destination address for sub-texture updates.
00232  * \param mesaFormat  one of the MESA_FORMAT_* compressed formats
00233  * \param width  image width in pixels
00234  * \return stride, in bytes, between rows for compressed image
00235  */
00236 GLint
00237 _mesa_compressed_row_stride(GLuint mesaFormat, GLsizei width)
00238 {
00239    GLint stride;
00240 
00241    switch (mesaFormat) {
00242    case MESA_FORMAT_RGB_FXT1:
00243    case MESA_FORMAT_RGBA_FXT1:
00244       stride = ((width + 7) / 8) * 16; /* 16 bytes per 8x4 tile */
00245       break;
00246    case MESA_FORMAT_RGB_DXT1:
00247    case MESA_FORMAT_RGBA_DXT1:
00248       stride = ((width + 3) / 4) * 8; /* 8 bytes per 4x4 tile */
00249       break;
00250    case MESA_FORMAT_RGBA_DXT3:
00251    case MESA_FORMAT_RGBA_DXT5:
00252       stride = ((width + 3) / 4) * 16; /* 16 bytes per 4x4 tile */
00253       break;
00254    default:
00255       _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_row_stride");
00256       return 0;
00257    }
00258 
00259    return stride;
00260 }
00261 
00262 
00263 /*
00264  * Return the address of the pixel at (col, row, img) in a
00265  * compressed texture image.
00266  * \param col, row, img - image position (3D)
00267  * \param format - compressed image format
00268  * \param width - image width
00269  * \param image - the image address
00270  * \return address of pixel at (row, col)
00271  */
00272 GLubyte *
00273 _mesa_compressed_image_address(GLint col, GLint row, GLint img,
00274                                GLuint mesaFormat,
00275                                GLsizei width, const GLubyte *image)
00276 {
00277    GLubyte *addr;
00278 
00279    (void) img;
00280 
00281    /* We try to spot a "complete" subtexture "above" ROW, COL;
00282     * this texture is given by appropriate rounding of WIDTH x ROW.
00283     * Then we just add the amount left (usually on the left).
00284     *
00285     * Example for X*Y microtiles (Z bytes each)
00286     * offset = Z * (((width + X - 1) / X) * (row / Y) + col / X);
00287     */
00288 
00289    switch (mesaFormat) {
00290    case MESA_FORMAT_RGB_FXT1:
00291    case MESA_FORMAT_RGBA_FXT1:
00292       addr = (GLubyte *) image + 16 * (((width + 7) / 8) * (row / 4) + col / 8);
00293       break;
00294    case MESA_FORMAT_RGB_DXT1:
00295    case MESA_FORMAT_RGBA_DXT1:
00296       addr = (GLubyte *) image + 8 * (((width + 3) / 4) * (row / 4) + col / 4);
00297       break;
00298    case MESA_FORMAT_RGBA_DXT3:
00299    case MESA_FORMAT_RGBA_DXT5:
00300       addr = (GLubyte *) image + 16 * (((width + 3) / 4) * (row / 4) + col / 4);
00301       break;
00302    default:
00303       _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_image_address");
00304       addr = NULL;
00305    }
00306 
00307    return addr;
00308 }

Generated on Sat May 19 2012 04:18:24 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.