1/* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5 * Copyright (c) 2008-2009 VMware, Inc. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 * OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26 27/** 28 * \file texfetch_tmp.h 29 * Texel fetch functions template. 30 * 31 * This template file is used by texfetch.c to generate texel fetch functions 32 * for 1-D, 2-D and 3-D texture images. 33 * 34 * It should be expanded by defining \p DIM as the number texture dimensions 35 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined 36 * for the texel lookup in the gl_texture_image::Data. 37 * 38 * \author Gareth Hughes 39 * \author Brian Paul 40 */ 41 42#include <format_unpack.h> 43 44#if DIM == 1 45 46#define TEXEL_ADDR( type, image, i, j, k, size ) \ 47 ((void) (j), (void) (k), ((type *)(image)->ImageSlices[0] + (i) * (size))) 48 49#define FETCH(x) fetch_texel_1d_##x 50 51#elif DIM == 2 52 53#define TEXEL_ADDR( type, image, i, j, k, size ) \ 54 ((void) (k), \ 55 ((type *)((GLubyte *) (image)->ImageSlices[0] + (image)->RowStride * (j)) + \ 56 (i) * (size))) 57 58#define FETCH(x) fetch_texel_2d_##x 59 60#elif DIM == 3 61 62#define TEXEL_ADDR( type, image, i, j, k, size ) \ 63 ((type *)((GLubyte *) (image)->ImageSlices[k] + \ 64 (image)->RowStride * (j)) + (i) * (size)) 65 66#define FETCH(x) fetch_texel_3d_##x 67 68#else 69#error illegal number of texture dimensions 70#endif 71 72#define FETCH_Z(x, type, size) \ 73 static void \ 74 FETCH(x) (const struct swrast_texture_image *texImage, \ 75 GLint i, GLint j, GLint k, GLfloat *texel) \ 76 { \ 77 const type *src = TEXEL_ADDR(type, texImage, i, j, k, size); \ 78 _mesa_unpack_float_z_row(MESA_FORMAT_##x, 1, src, texel); \ 79 } 80 81#define FETCH_RGBA(x, type, size) \ 82 static void \ 83 FETCH(x) (const struct swrast_texture_image *texImage, \ 84 GLint i, GLint j, GLint k, GLfloat *texel) \ 85 { \ 86 const type *src = TEXEL_ADDR(type, texImage, i, j, k, size); \ 87 _mesa_unpack_rgba_row(MESA_FORMAT_##x, 1, src, (GLvoid *)texel); \ 88 } 89 90FETCH_Z(Z_UNORM32, GLuint, 1) 91FETCH_Z(Z_UNORM16, GLushort, 1) 92FETCH_Z(S8_UINT_Z24_UNORM, GLuint, 1) /* only return Z, not stencil data */ 93FETCH_Z(Z24_UNORM_S8_UINT, GLuint, 1) /* only return Z, not stencil data */ 94FETCH_Z(Z32_FLOAT_S8X24_UINT, GLfloat, 2) 95 96FETCH_RGBA(RGBA_FLOAT32, GLfloat, 4) 97FETCH_RGBA(RGBA_FLOAT16, GLhalfARB, 4) 98FETCH_RGBA(RGB_FLOAT32, GLfloat, 3) 99FETCH_RGBA(RGB_FLOAT16, GLhalfARB, 3) 100FETCH_RGBA(A_FLOAT32, GLfloat, 1) 101FETCH_RGBA(A_FLOAT16, GLhalfARB, 1) 102FETCH_RGBA(L_FLOAT32, GLfloat, 1) 103FETCH_RGBA(L_FLOAT16, GLhalfARB, 1) 104FETCH_RGBA(LA_FLOAT32, GLfloat, 2) 105FETCH_RGBA(LA_FLOAT16, GLhalfARB, 2) 106FETCH_RGBA(I_FLOAT32, GLfloat, 1) 107FETCH_RGBA(I_FLOAT16, GLhalfARB, 1) 108FETCH_RGBA(R_FLOAT32, GLfloat, 1) 109FETCH_RGBA(R_FLOAT16, GLhalfARB, 1) 110FETCH_RGBA(RG_FLOAT32, GLfloat, 2) 111FETCH_RGBA(RG_FLOAT16, GLhalfARB, 2) 112FETCH_RGBA(A8B8G8R8_UNORM, GLuint, 1) 113FETCH_RGBA(R8G8B8A8_UNORM, GLuint, 1) 114FETCH_RGBA(B8G8R8A8_UNORM, GLuint, 1) 115FETCH_RGBA(A8R8G8B8_UNORM, GLuint, 1) 116FETCH_RGBA(X8B8G8R8_UNORM, GLuint, 1) 117FETCH_RGBA(R8G8B8X8_UNORM, GLuint, 1) 118FETCH_RGBA(B8G8R8X8_UNORM, GLuint, 1) 119FETCH_RGBA(X8R8G8B8_UNORM, GLuint, 1) 120FETCH_RGBA(BGR_UNORM8, GLubyte, 3) 121FETCH_RGBA(RGB_UNORM8, GLubyte, 3) 122FETCH_RGBA(B5G6R5_UNORM, GLushort, 1) 123FETCH_RGBA(R5G6B5_UNORM, GLushort, 1) 124FETCH_RGBA(B4G4R4A4_UNORM, GLushort, 1) 125FETCH_RGBA(A4R4G4B4_UNORM, GLushort, 1) 126FETCH_RGBA(A1B5G5R5_UNORM, GLushort, 1) 127FETCH_RGBA(B5G5R5A1_UNORM, GLushort, 1) 128FETCH_RGBA(A1R5G5B5_UNORM, GLushort, 1) 129FETCH_RGBA(B10G10R10A2_UNORM, GLuint, 1) 130FETCH_RGBA(R10G10B10A2_UNORM, GLuint, 1) 131FETCH_RGBA(R8G8_UNORM, GLushort, 1) 132FETCH_RGBA(G8R8_UNORM, GLushort, 1) 133FETCH_RGBA(L4A4_UNORM, GLubyte, 1) 134FETCH_RGBA(L8A8_UNORM, GLushort, 1) 135FETCH_RGBA(R_UNORM8, GLubyte, 1) 136FETCH_RGBA(R_UNORM16, GLushort, 1) 137FETCH_RGBA(A8L8_UNORM, GLushort, 1) 138FETCH_RGBA(R16G16_UNORM, GLuint, 1) 139FETCH_RGBA(G16R16_UNORM, GLuint, 1) 140FETCH_RGBA(L16A16_UNORM, GLuint, 1) 141FETCH_RGBA(A16L16_UNORM, GLuint, 1) 142FETCH_RGBA(B2G3R3_UNORM, GLubyte, 1) 143FETCH_RGBA(A_UNORM8, GLubyte, 1) 144FETCH_RGBA(A_UNORM16, GLushort, 1) 145FETCH_RGBA(L_UNORM8, GLubyte, 1) 146FETCH_RGBA(L_UNORM16, GLushort, 1) 147FETCH_RGBA(I_UNORM8, GLubyte, 1) 148FETCH_RGBA(I_UNORM16, GLushort, 1) 149FETCH_RGBA(BGR_SRGB8, GLubyte, 3) 150FETCH_RGBA(A8B8G8R8_SRGB, GLuint, 1) 151FETCH_RGBA(B8G8R8A8_SRGB, GLuint, 1) 152FETCH_RGBA(A8R8G8B8_SRGB, GLuint, 1) 153FETCH_RGBA(R8G8B8A8_SRGB, GLuint, 1) 154FETCH_RGBA(R8G8B8X8_SRGB, GLuint, 1) 155FETCH_RGBA(X8B8G8R8_SRGB, GLuint, 1) 156FETCH_RGBA(R_SRGB8, GLubyte, 1) 157FETCH_RGBA(L_SRGB8, GLubyte, 1) 158FETCH_RGBA(L8A8_SRGB, GLushort, 1) 159FETCH_RGBA(A8L8_SRGB, GLushort, 2) 160FETCH_RGBA(RGBA_SINT8, GLbyte, 4) 161FETCH_RGBA(RGBA_SINT16, GLshort, 4) 162FETCH_RGBA(RGBA_SINT32, GLint, 4) 163FETCH_RGBA(RGBA_UINT8, GLubyte, 4) 164FETCH_RGBA(RGBA_UINT16, GLushort, 4) 165FETCH_RGBA(RGBA_UINT32, GLuint, 4) 166FETCH_RGBA(R_SNORM8, GLbyte, 1) 167FETCH_RGBA(A_SNORM8, GLbyte, 1) 168FETCH_RGBA(L_SNORM8, GLbyte, 1) 169FETCH_RGBA(I_SNORM8, GLbyte, 1) 170FETCH_RGBA(R8G8_SNORM, GLshort, 1) 171FETCH_RGBA(L8A8_SNORM, GLshort, 1) 172FETCH_RGBA(A8L8_SNORM, GLshort, 1) 173FETCH_RGBA(X8B8G8R8_SNORM, GLint, 1) 174FETCH_RGBA(A8B8G8R8_SNORM, GLint, 1) 175FETCH_RGBA(R8G8B8A8_SNORM, GLint, 1) 176FETCH_RGBA(R_SNORM16, GLshort, 1) 177FETCH_RGBA(A_SNORM16, GLshort, 1) 178FETCH_RGBA(L_SNORM16, GLshort, 1) 179FETCH_RGBA(I_SNORM16, GLshort, 1) 180FETCH_RGBA(R16G16_SNORM, GLshort, 2) 181FETCH_RGBA(LA_SNORM16, GLshort, 2) 182FETCH_RGBA(RGB_SNORM16, GLshort, 3) 183FETCH_RGBA(RGBA_SNORM16, GLshort, 4) 184FETCH_RGBA(RGBA_UNORM16, GLushort, 4) 185FETCH_RGBA(RGBX_UNORM16, GLushort, 4) 186FETCH_RGBA(RGBX_FLOAT16, GLhalfARB, 4) 187FETCH_RGBA(RGBX_FLOAT32, GLfloat, 4) 188FETCH_RGBA(YCBCR, GLushort, 1) /* Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA. */ 189FETCH_RGBA(YCBCR_REV, GLushort, 1) /* Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA. */ 190FETCH_RGBA(R9G9B9E5_FLOAT, GLuint, 1) 191FETCH_RGBA(R11G11B10_FLOAT, GLuint, 1) 192 193#undef TEXEL_ADDR 194#undef DIM 195#undef FETCH 196#undef FETCH_Z 197#undef FETCH_RGBA 198