📄 texformat_tmp.h
字号:
/* $XFree86$ */
/*
* Mesa 3-D graphics library
* Version: 6.3.2
*
* Copyright (C) 1999-2005 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_tmp.h
* Texel fetch functions template.
*
* This template file is used by texformat.c to generate texel fetch functions
* for 1-D, 2-D and 3-D texture images.
*
* It should be expanded by defining \p DIM as the number texture dimensions
* (1, 2 or 3). According to the value of \p DIM a series of macros is defined
* for the texel lookup in the gl_texture_image::Data.
*
* \sa texformat.c and FetchTexel.
*
* \author Gareth Hughes
* \author Brian Paul
*/
#if DIM == 1
#define CHAN_ADDR( t, i, j, k, sz ) \
((GLchan *)(t)->Data + (i) * (sz))
#define UBYTE_ADDR( t, i, j, k, sz ) \
((GLubyte *)(t)->Data + (i) * (sz))
#define USHORT_ADDR( t, i, j, k ) \
((GLushort *)(t)->Data + (i))
#define UINT_ADDR( t, i, j, k ) \
((GLuint *)(t)->Data + (i))
#define FLOAT_ADDR( t, i, j, k, sz ) \
((GLfloat *)(t)->Data + (i) * (sz))
#define HALF_ADDR( t, i, j, k, sz ) \
((GLhalfARB *)(t)->Data + (i) * (sz))
#define FETCH(x) fetch_texel_1d_##x
#elif DIM == 2
#define CHAN_ADDR( t, i, j, k, sz ) \
((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
#define UBYTE_ADDR( t, i, j, k, sz ) \
((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
#define USHORT_ADDR( t, i, j, k ) \
((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
#define UINT_ADDR( t, i, j, k ) \
((GLuint *)(t)->Data + ((t)->RowStride * (j) + (i)))
#define FLOAT_ADDR( t, i, j, k, sz ) \
((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
#define HALF_ADDR( t, i, j, k, sz ) \
((GLhalfARB *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
#define FETCH(x) fetch_texel_2d_##x
#elif DIM == 3
#define CHAN_ADDR( t, i, j, k, sz ) \
(GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
(t)->RowStride + (i)) * (sz)
#define UBYTE_ADDR( t, i, j, k, sz ) \
((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
(t)->RowStride + (i)) * (sz))
#define USHORT_ADDR( t, i, j, k ) \
((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
(t)->RowStride + (i)))
#define UINT_ADDR( t, i, j, k ) \
((GLuint *)(t)->Data + (((t)->Height * (k) + (j)) * \
(t)->RowStride + (i)))
#define FLOAT_ADDR( t, i, j, k, sz ) \
((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
(t)->RowStride + (i)) * (sz))
#define HALF_ADDR( t, i, j, k, sz ) \
((GLhalfARB *)(t)->Data + (((t)->Height * (k) + (j)) * \
(t)->RowStride + (i)) * (sz))
#define FETCH(x) fetch_texel_3d_##x
#else
#error illegal number of texture dimensions
#endif
/* MESA_FORMAT_RGBA **********************************************************/
/* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
static void FETCH(rgba)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLchan *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 4 );
COPY_CHAN4( texel, src );
}
/* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 4 );
texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
}
#if DIM == 3
/* Store a GLchan RGBA texel */
static void store_texel_rgba(struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, const void *texel)
{
const GLchan *rgba = (const GLchan *) texel;
GLchan *dst = CHAN_ADDR(texImage, i, j, k, 4);
dst[0] = rgba[RCOMP];
dst[1] = rgba[GCOMP];
dst[2] = rgba[BCOMP];
dst[3] = rgba[ACOMP];
}
#endif
/* MESA_FORMAT_RGB ***********************************************************/
/* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
static void FETCH(rgb)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLchan *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 3 );
texel[RCOMP] = src[0];
texel[GCOMP] = src[1];
texel[BCOMP] = src[2];
texel[ACOMP] = CHAN_MAX;
}
/* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 3 );
texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
texel[ACOMP] = 1.0F;
}
#if DIM == 3
static void store_texel_rgb(struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, const void *texel)
{
const GLchan *rgba = (const GLchan *) texel;
GLchan *dst = CHAN_ADDR(texImage, i, j, k, 3);
dst[0] = rgba[RCOMP];
dst[1] = rgba[GCOMP];
dst[2] = rgba[BCOMP];
}
#endif
/* MESA_FORMAT_ALPHA *********************************************************/
/* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
static void FETCH(alpha)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLchan *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 1 );
texel[RCOMP] =
texel[GCOMP] =
texel[BCOMP] = 0;
texel[ACOMP] = src[0];
}
/* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
static void FETCH(f_alpha)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 1 );
texel[RCOMP] =
texel[GCOMP] =
texel[BCOMP] = 0.0;
texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
}
#if DIM == 3
static void store_texel_alpha(struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, const void *texel)
{
const GLchan *rgba = (const GLchan *) texel;
GLchan *dst = CHAN_ADDR(texImage, i, j, k, 1);
dst[0] = rgba[ACOMP];
}
#endif
/* MESA_FORMAT_LUMINANCE *****************************************************/
/* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
static void FETCH(luminance)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLchan *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 1 );
texel[RCOMP] =
texel[GCOMP] =
texel[BCOMP] = src[0];
texel[ACOMP] = CHAN_MAX;
}
/* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLfloats */
static void FETCH(f_luminance)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 1 );
texel[RCOMP] =
texel[GCOMP] =
texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
texel[ACOMP] = 1.0F;
}
#if DIM == 3
static void store_texel_luminance(struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, const void *texel)
{
const GLchan *rgba = (const GLchan *) texel;
GLchan *dst = CHAN_ADDR(texImage, i, j, k, 1);
dst[0] = rgba[RCOMP];
}
#endif
/* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
/* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
static void FETCH(luminance_alpha)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLchan *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 2 );
texel[RCOMP] = src[0];
texel[GCOMP] = src[0];
texel[BCOMP] = src[0];
texel[ACOMP] = src[1];
}
/* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
static void FETCH(f_luminance_alpha)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 2 );
texel[RCOMP] =
texel[GCOMP] =
texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
texel[ACOMP] = CHAN_TO_FLOAT(src[1]);
}
#if DIM == 3
static void store_texel_luminance_alpha(struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, const void *texel)
{
const GLchan *rgba = (const GLchan *) texel;
GLchan *dst = CHAN_ADDR(texImage, i, j, k, 2);
dst[0] = rgba[RCOMP];
dst[1] = rgba[ACOMP];
}
#endif
/* MESA_FORMAT_INTENSITY *****************************************************/
/* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
static void FETCH(intensity)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLchan *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 1 );
texel[RCOMP] = src[0];
texel[GCOMP] = src[0];
texel[BCOMP] = src[0];
texel[ACOMP] = src[0];
}
/* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
static void FETCH(f_intensity)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLchan *src = CHAN_ADDR( texImage, i, j, k, 1 );
texel[RCOMP] =
texel[GCOMP] =
texel[BCOMP] =
texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
}
#if DIM == 3
static void store_texel_intensity(struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, const void *texel)
{
const GLchan *rgba = (const GLchan *) texel;
GLchan *dst = CHAN_ADDR(texImage, i, j, k, 1);
dst[0] = rgba[RCOMP];
}
#endif
/* MESA_FORMAT_DEPTH_COMPONENT_F32 *******************************************/
/* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
* returning 1 GLfloat.
* Note: no GLchan version of this function.
*/
static void FETCH(f_depth_component_f32)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLfloat *src = FLOAT_ADDR( texImage, i, j, k, 1 );
texel[0] = src[0];
}
#if DIM == 3
static void store_texel_depth_component_f32(struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, const void *texel)
{
const GLfloat *depth = (const GLfloat *) texel;
GLfloat *dst = FLOAT_ADDR(texImage, i, j, k, 1);
dst[0] = *depth;
}
#endif
/* MESA_FORMAT_DEPTH_COMPONENT16 *********************************************/
/* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
* returning 1 GLfloat.
* Note: no GLchan version of this function.
*/
static void FETCH(f_depth_component16)(const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
const GLushort *src = USHORT_ADDR( texImage, i, j, k );
texel[0] = src[0] * (1.0F / 65535.0F);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -