⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 texstore.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Mesa 3-D graphics library * Version:  7.1 * * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//* * Authors: *   Brian Paul *//** * The GL texture image functions in teximage.c basically just do * error checking and data structure allocation.  They in turn call * device driver functions which actually copy/convert/store the user's * texture image data. * * However, most device drivers will be able to use the fallback functions * in this file.  That is, most drivers will have the following bit of * code: *   ctx->Driver.TexImage1D = _mesa_store_teximage1d; *   ctx->Driver.TexImage2D = _mesa_store_teximage2d; *   ctx->Driver.TexImage3D = _mesa_store_teximage3d; *   etc... * * Texture image processing is actually kind of complicated.  We have to do: *    Format/type conversions *    pixel unpacking *    pixel transfer (scale, bais, lookup, convolution!, etc) * * These functions can handle most everything, including processing full * images and sub-images. */#include "glheader.h"#include "bufferobj.h"#include "colormac.h"#include "context.h"#include "convolve.h"#include "image.h"#include "macros.h"#include "mipmap.h"#include "imports.h"#include "texcompress.h"#include "texformat.h"#include "teximage.h"#include "texstore.h"#include "enums.h"enum {   ZERO = 4,    ONE = 5};/** * Return GL_TRUE if the given image format is one that be converted * to another format by swizzling. */static GLbooleancan_swizzle(GLenum logicalBaseFormat){   switch (logicalBaseFormat) {   case GL_RGBA:   case GL_RGB:   case GL_LUMINANCE_ALPHA:   case GL_INTENSITY:   case GL_ALPHA:   case GL_LUMINANCE:   case GL_RED:   case GL_GREEN:   case GL_BLUE:   case GL_BGR:   case GL_BGRA:   case GL_ABGR_EXT:      return GL_TRUE;   default:      return GL_FALSE;   }}enum {   IDX_LUMINANCE = 0,   IDX_ALPHA,   IDX_INTENSITY,   IDX_LUMINANCE_ALPHA,   IDX_RGB,   IDX_RGBA,   IDX_RED,   IDX_GREEN,   IDX_BLUE,   IDX_BGR,   IDX_BGRA,   IDX_ABGR,   MAX_IDX};#define MAP1(x)       MAP4(x, ZERO, ZERO, ZERO)#define MAP2(x,y)     MAP4(x, y, ZERO, ZERO)#define MAP3(x,y,z)   MAP4(x, y, z, ZERO)#define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }static const struct {   GLubyte format_idx;   GLubyte to_rgba[6];   GLubyte from_rgba[6];} mappings[MAX_IDX] = {   {      IDX_LUMINANCE,      MAP4(0,0,0,ONE),      MAP1(0)   },   {      IDX_ALPHA,      MAP4(ZERO, ZERO, ZERO, 0),      MAP1(3)   },   {      IDX_INTENSITY,      MAP4(0, 0, 0, 0),      MAP1(0),   },   {      IDX_LUMINANCE_ALPHA,      MAP4(0,0,0,1),      MAP2(0,3)   },   {      IDX_RGB,      MAP4(0,1,2,ONE),      MAP3(0,1,2)   },   {      IDX_RGBA,      MAP4(0,1,2,3),      MAP4(0,1,2,3),   },   {      IDX_RED,      MAP4(0, ZERO, ZERO, ONE),      MAP1(0),   },   {      IDX_GREEN,      MAP4(ZERO, 0, ZERO, ONE),      MAP1(1),   },   {      IDX_BLUE,      MAP4(ZERO, ZERO, 0, ONE),      MAP1(2),   },   {      IDX_BGR,      MAP4(2,1,0,ONE),      MAP3(2,1,0)   },   {      IDX_BGRA,      MAP4(2,1,0,3),      MAP4(2,1,0,3)   },   {      IDX_ABGR,      MAP4(3,2,1,0),      MAP4(3,2,1,0)   },};/** * Convert a GL image format enum to an IDX_* value (see above). */static intget_map_idx(GLenum value){   switch (value) {   case GL_LUMINANCE: return IDX_LUMINANCE;   case GL_ALPHA: return IDX_ALPHA;   case GL_INTENSITY: return IDX_INTENSITY;   case GL_LUMINANCE_ALPHA: return IDX_LUMINANCE_ALPHA;   case GL_RGB: return IDX_RGB;   case GL_RGBA: return IDX_RGBA;   case GL_RED: return IDX_RED;   case GL_GREEN: return IDX_GREEN;   case GL_BLUE: return IDX_BLUE;   case GL_BGR: return IDX_BGR;   case GL_BGRA: return IDX_BGRA;   case GL_ABGR_EXT: return IDX_ABGR;   default:      _mesa_problem(NULL, "Unexpected inFormat");      return 0;   }}   /** * When promoting texture formats (see below) we need to compute the * mapping of dest components back to source components. * This function does that. * \param inFormat  the incoming format of the texture * \param outFormat  the final texture format * \return map[6]  a full 6-component map */static voidcompute_component_mapping(GLenum inFormat, GLenum outFormat, 			  GLubyte *map){   const int inFmt = get_map_idx(inFormat);   const int outFmt = get_map_idx(outFormat);   const GLubyte *in2rgba = mappings[inFmt].to_rgba;   const GLubyte *rgba2out = mappings[outFmt].from_rgba;   int i;      for (i = 0; i < 4; i++)      map[i] = in2rgba[rgba2out[i]];   map[ZERO] = ZERO;   map[ONE] = ONE;   /*   _mesa_printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",		inFormat, _mesa_lookup_enum_by_nr(inFormat),		outFormat, _mesa_lookup_enum_by_nr(outFormat),		map[0], 		map[1], 		map[2], 		map[3], 		map[4], 		map[5]); */}/** * Make a temporary (color) texture image with GLfloat components. * Apply all needed pixel unpacking and pixel transfer operations. * Note that there are both logicalBaseFormat and textureBaseFormat parameters. * Suppose the user specifies GL_LUMINANCE as the internal texture format * but the graphics hardware doesn't support luminance textures.  So, might * use an RGB hardware format instead. * If logicalBaseFormat != textureBaseFormat we have some extra work to do. * * \param ctx  the rendering context * \param dims  image dimensions: 1, 2 or 3 * \param logicalBaseFormat  basic texture derived from the user's *    internal texture format value * \param textureBaseFormat  the actual basic format of the texture * \param srcWidth  source image width * \param srcHeight  source image height * \param srcDepth  source image depth * \param srcFormat  source image format * \param srcType  source image type * \param srcAddr  source image address * \param srcPacking  source image pixel packing * \return resulting image with format = textureBaseFormat and type = GLfloat. */static GLfloat *make_temp_float_image(GLcontext *ctx, GLuint dims,                      GLenum logicalBaseFormat,                      GLenum textureBaseFormat,                      GLint srcWidth, GLint srcHeight, GLint srcDepth,                      GLenum srcFormat, GLenum srcType,                      const GLvoid *srcAddr,                      const struct gl_pixelstore_attrib *srcPacking){   GLuint transferOps = ctx->_ImageTransferState;   GLfloat *tempImage;   ASSERT(dims >= 1 && dims <= 3);   ASSERT(logicalBaseFormat == GL_RGBA ||          logicalBaseFormat == GL_RGB ||          logicalBaseFormat == GL_LUMINANCE_ALPHA ||          logicalBaseFormat == GL_LUMINANCE ||          logicalBaseFormat == GL_ALPHA ||          logicalBaseFormat == GL_INTENSITY ||          logicalBaseFormat == GL_COLOR_INDEX ||          logicalBaseFormat == GL_DEPTH_COMPONENT);   ASSERT(textureBaseFormat == GL_RGBA ||          textureBaseFormat == GL_RGB ||          textureBaseFormat == GL_LUMINANCE_ALPHA ||          textureBaseFormat == GL_LUMINANCE ||          textureBaseFormat == GL_ALPHA ||          textureBaseFormat == GL_INTENSITY ||          textureBaseFormat == GL_COLOR_INDEX ||          textureBaseFormat == GL_DEPTH_COMPONENT);   /* conventional color image */   if ((dims == 1 && ctx->Pixel.Convolution1DEnabled) ||       (dims >= 2 && ctx->Pixel.Convolution2DEnabled) ||       (dims >= 2 && ctx->Pixel.Separable2DEnabled)) {      /* need image convolution */      const GLuint preConvTransferOps         = (transferOps & IMAGE_PRE_CONVOLUTION_BITS) | IMAGE_CLAMP_BIT;      const GLuint postConvTransferOps         = (transferOps & IMAGE_POST_CONVOLUTION_BITS) | IMAGE_CLAMP_BIT;      GLint img, row;      GLint convWidth, convHeight;      GLfloat *convImage;      /* pre-convolution image buffer (3D) */      tempImage = (GLfloat *) _mesa_malloc(srcWidth * srcHeight * srcDepth                                           * 4 * sizeof(GLfloat));      if (!tempImage)         return NULL;      /* post-convolution image buffer (2D) */      convImage = (GLfloat *) _mesa_malloc(srcWidth * srcHeight                                           * 4 * sizeof(GLfloat));      if (!convImage) {         _mesa_free(tempImage);         return NULL;      }      /* loop over 3D image slices */      for (img = 0; img < srcDepth; img++) {         GLfloat *dst = tempImage + img * (srcWidth * srcHeight * 4);         /* unpack and do transfer ops up to convolution */         for (row = 0; row < srcHeight; row++) {            const GLvoid *src = _mesa_image_address(dims, srcPacking,                                              srcAddr, srcWidth, srcHeight,                                              srcFormat, srcType, img, row, 0);            _mesa_unpack_color_span_float(ctx, srcWidth, GL_RGBA, dst,                                          srcFormat, srcType, src,                                          srcPacking,                                          preConvTransferOps);            dst += srcWidth * 4;         }         /* size after optional convolution */         convWidth = srcWidth;         convHeight = srcHeight;         /* do convolution */         {            GLfloat *src = tempImage + img * (srcWidth * srcHeight * 4);            if (dims == 1) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -