📄 texformat.c
字号:
/* * Mesa 3-D graphics library * Version: 6.5.1 * * Copyright (C) 1999-2006 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. *//** * \file texformat.c * Texture formats. * * \author Gareth Hughes */#include "colormac.h"#include "context.h"#include "texformat.h"#include "texstore.h"#if FEATURE_EXT_texture_sRGB/** * Convert an 8-bit sRGB value from non-linear space to a * linear RGB value in [0, 1]. * Implemented with a 256-entry lookup table. */static INLINE GLfloatnonlinear_to_linear(GLubyte cs8){ static GLfloat table[256]; static GLboolean tableReady = GL_FALSE; if (!tableReady) { /* compute lookup table now */ GLuint i; for (i = 0; i < 256; i++) { const GLfloat cs = UBYTE_TO_FLOAT(i); if (cs <= 0.04045) { table[i] = cs / 12.92; } else { table[i] = _mesa_pow((cs + 0.055) / 1.055, 2.4); } } tableReady = GL_TRUE; } return table[cs8];}#endif /* FEATURE_EXT_texture_sRGB *//* Texel fetch routines for all supported formats */#define DIM 1#include "texformat_tmp.h"#define DIM 2#include "texformat_tmp.h"#define DIM 3#include "texformat_tmp.h"/** * Null texel fetch function. * * Have to have this so the FetchTexel function pointer is never NULL. */static void fetch_null_texel( const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLchan *texel ){ (void) texImage; (void) i; (void) j; (void) k; texel[RCOMP] = 0; texel[GCOMP] = 0; texel[BCOMP] = 0; texel[ACOMP] = 0; _mesa_warning(NULL, "fetch_null_texel() called!");}static void fetch_null_texelf( const struct gl_texture_image *texImage, GLint i, GLint j, GLint k, GLfloat *texel ){ (void) texImage; (void) i; (void) j; (void) k; texel[RCOMP] = 0.0; texel[GCOMP] = 0.0; texel[BCOMP] = 0.0; texel[ACOMP] = 0.0; _mesa_warning(NULL, "fetch_null_texelf() called!");}static void store_null_texel(struct gl_texture_image *texImage, GLint i, GLint j, GLint k, const void *texel){ (void) texImage; (void) i; (void) j; (void) k; (void) texel; /* no-op */}/** * Notes about the predefined gl_texture_formats: * * 1. There are 1D, 2D and 3D functions for fetching texels from texture * images, returning both GLchan values and GLfloat values. (six * functions in total) * You don't have to provide both the GLchan and GLfloat functions; * just one or the other is OK. Mesa will use an "adaptor" to convert * between GLchan/GLfloat when needed. * Since the adaptors have small performance penalty, we provide both * GLchan and GLfloat functions for some common formats like RGB, RGBA. *//***************************************************************//** \name Default GLchan-based formats *//*@{*/const struct gl_texture_format _mesa_texformat_rgba = { MESA_FORMAT_RGBA, /* MesaFormat */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ CHAN_BITS, /* RedBits */ CHAN_BITS, /* GreenBits */ CHAN_BITS, /* BlueBits */ CHAN_BITS, /* AlphaBits */ 0, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ 4 * sizeof(GLchan), /* TexelBytes */ _mesa_texstore_rgba, /* StoreTexImageFunc */ fetch_texel_1d_rgba, /* FetchTexel1D */ fetch_texel_2d_rgba, /* FetchTexel2D */ fetch_texel_3d_rgba, /* FetchTexel3D */ fetch_texel_1d_f_rgba, /* FetchTexel1Df */ fetch_texel_2d_f_rgba, /* FetchTexel2Df */ fetch_texel_3d_f_rgba, /* FetchTexel3Df */ store_texel_rgba /* StoreTexel */};const struct gl_texture_format _mesa_texformat_rgb = { MESA_FORMAT_RGB, /* MesaFormat */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ CHAN_BITS, /* RedBits */ CHAN_BITS, /* GreenBits */ CHAN_BITS, /* BlueBits */ 0, /* AlphaBits */ 0, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ 3 * sizeof(GLchan), /* TexelBytes */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_rgb, /* FetchTexel1D */ fetch_texel_2d_rgb, /* FetchTexel2D */ fetch_texel_3d_rgb, /* FetchTexel3D */ fetch_texel_1d_f_rgb, /* FetchTexel1Df */ fetch_texel_2d_f_rgb, /* FetchTexel2Df */ fetch_texel_3d_f_rgb, /* FetchTexel3Df */ store_texel_rgb /* StoreTexel */};const struct gl_texture_format _mesa_texformat_alpha = { MESA_FORMAT_ALPHA, /* MesaFormat */ GL_ALPHA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 0, /* RedBits */ 0, /* GreenBits */ 0, /* BlueBits */ CHAN_BITS, /* AlphaBits */ 0, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ sizeof(GLchan), /* TexelBytes */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_alpha, /* FetchTexel1D */ fetch_texel_2d_alpha, /* FetchTexel2D */ fetch_texel_3d_alpha, /* FetchTexel3D */ NULL, /* FetchTexel1Df */ NULL, /* FetchTexel2Df */ NULL, /* FetchTexel3Df */ store_texel_alpha /* StoreTexel */};const struct gl_texture_format _mesa_texformat_luminance = { MESA_FORMAT_LUMINANCE, /* MesaFormat */ GL_LUMINANCE, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 0, /* RedBits */ 0, /* GreenBits */ 0, /* BlueBits */ 0, /* AlphaBits */ CHAN_BITS, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ sizeof(GLchan), /* TexelBytes */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_luminance, /* FetchTexel1D */ fetch_texel_2d_luminance, /* FetchTexel2D */ fetch_texel_3d_luminance, /* FetchTexel3D */ NULL, /* FetchTexel1Df */ NULL, /* FetchTexel2Df */ NULL, /* FetchTexel3Df */ store_texel_luminance /* StoreTexel */};const struct gl_texture_format _mesa_texformat_luminance_alpha = { MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */ GL_LUMINANCE_ALPHA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 0, /* RedBits */ 0, /* GreenBits */ 0, /* BlueBits */ CHAN_BITS, /* AlphaBits */ CHAN_BITS, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ 2 * sizeof(GLchan), /* TexelBytes */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_luminance_alpha, /* FetchTexel1D */ fetch_texel_2d_luminance_alpha, /* FetchTexel2D */ fetch_texel_3d_luminance_alpha, /* FetchTexel3D */ NULL, /* FetchTexel1Df */ NULL, /* FetchTexel2Df */ NULL, /* FetchTexel3Df */ store_texel_luminance_alpha /* StoreTexel */};const struct gl_texture_format _mesa_texformat_intensity = { MESA_FORMAT_INTENSITY, /* MesaFormat */ GL_INTENSITY, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 0, /* RedBits */ 0, /* GreenBits */ 0, /* BlueBits */ 0, /* AlphaBits */ 0, /* LuminanceBits */ CHAN_BITS, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ sizeof(GLchan), /* TexelBytes */ _mesa_texstore_rgba,/*yes*/ /* StoreTexImageFunc */ fetch_texel_1d_intensity, /* FetchTexel1D */ fetch_texel_2d_intensity, /* FetchTexel2D */ fetch_texel_3d_intensity, /* FetchTexel3D */ NULL, /* FetchTexel1Df */ NULL, /* FetchTexel2Df */ NULL, /* FetchTexel3Df */ store_texel_intensity /* StoreTexel */};#if FEATURE_EXT_texture_sRGBconst struct gl_texture_format _mesa_texformat_srgb8 = { MESA_FORMAT_SRGB8, /* MesaFormat */ GL_RGB, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 8, /* RedBits */ 8, /* GreenBits */ 8, /* BlueBits */ 0, /* AlphaBits */ 0, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ 3, /* TexelBytes */ _mesa_texstore_srgb8, /* StoreTexImageFunc */ NULL, /* FetchTexel1D */ NULL, /* FetchTexel2D */ NULL, /* FetchTexel3D */ fetch_texel_1d_srgb8, /* FetchTexel1Df */ fetch_texel_2d_srgb8, /* FetchTexel2Df */ fetch_texel_3d_srgb8, /* FetchTexel3Df */ store_texel_srgb8 /* StoreTexel */};const struct gl_texture_format _mesa_texformat_srgba8 = { MESA_FORMAT_SRGBA8, /* MesaFormat */ GL_RGBA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 8, /* RedBits */ 8, /* GreenBits */ 8, /* BlueBits */ 8, /* AlphaBits */ 0, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ 4, /* TexelBytes */ _mesa_texstore_srgba8, /* StoreTexImageFunc */ NULL, /* FetchTexel1D */ NULL, /* FetchTexel2D */ NULL, /* FetchTexel3D */ fetch_texel_1d_srgba8, /* FetchTexel1Df */ fetch_texel_2d_srgba8, /* FetchTexel2Df */ fetch_texel_3d_srgba8, /* FetchTexel3Df */ store_texel_srgba8 /* StoreTexel */};const struct gl_texture_format _mesa_texformat_sl8 = { MESA_FORMAT_SL8, /* MesaFormat */ GL_LUMINANCE, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 0, /* RedBits */ 0, /* GreenBits */ 0, /* BlueBits */ 0, /* AlphaBits */ 8, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ 1, /* TexelBytes */ _mesa_texstore_sl8, /* StoreTexImageFunc */ NULL, /* FetchTexel1D */ NULL, /* FetchTexel2D */ NULL, /* FetchTexel3D */ fetch_texel_1d_sl8, /* FetchTexel1Df */ fetch_texel_2d_sl8, /* FetchTexel2Df */ fetch_texel_3d_sl8, /* FetchTexel3Df */ store_texel_sl8 /* StoreTexel */};const struct gl_texture_format _mesa_texformat_sla8 = { MESA_FORMAT_SLA8, /* MesaFormat */ GL_LUMINANCE_ALPHA, /* BaseFormat */ GL_UNSIGNED_NORMALIZED_ARB, /* DataType */ 0, /* RedBits */ 0, /* GreenBits */ 0, /* BlueBits */ 8, /* AlphaBits */ 8, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ 2, /* TexelBytes */ _mesa_texstore_sla8, /* StoreTexImageFunc */ NULL, /* FetchTexel1D */ NULL, /* FetchTexel2D */ NULL, /* FetchTexel3D */ fetch_texel_1d_sla8, /* FetchTexel1Df */ fetch_texel_2d_sla8, /* FetchTexel2Df */ fetch_texel_3d_sla8, /* FetchTexel3Df */ store_texel_sla8 /* StoreTexel */};#endif /* FEATURE_EXT_texture_sRGB */const struct gl_texture_format _mesa_texformat_rgba_float32 = { MESA_FORMAT_RGBA_FLOAT32, /* MesaFormat */ GL_RGBA, /* BaseFormat */ GL_FLOAT, /* DataType */ 8 * sizeof(GLfloat), /* RedBits */ 8 * sizeof(GLfloat), /* GreenBits */ 8 * sizeof(GLfloat), /* BlueBits */ 8 * sizeof(GLfloat), /* AlphaBits */ 0, /* LuminanceBits */ 0, /* IntensityBits */ 0, /* IndexBits */ 0, /* DepthBits */ 0, /* StencilBits */ 4 * sizeof(GLfloat), /* TexelBytes */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -