1848b8605Smrg/* 2848b8605Smrg * Mesa 3-D graphics library 3848b8605Smrg * 4848b8605Smrg * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5848b8605Smrg * Copyright (c) 2008-2009 VMware, Inc. 6848b8605Smrg * 7848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 8848b8605Smrg * copy of this software and associated documentation files (the "Software"), 9848b8605Smrg * to deal in the Software without restriction, including without limitation 10848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 12848b8605Smrg * Software is furnished to do so, subject to the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice shall be included 15848b8605Smrg * in all copies or substantial portions of the Software. 16848b8605Smrg * 17848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 24848b8605Smrg */ 25848b8605Smrg 26848b8605Smrg 27848b8605Smrg/** 28848b8605Smrg * \file texfetch_tmp.h 29848b8605Smrg * Texel fetch functions template. 30848b8605Smrg * 31848b8605Smrg * This template file is used by texfetch.c to generate texel fetch functions 32848b8605Smrg * for 1-D, 2-D and 3-D texture images. 33848b8605Smrg * 34848b8605Smrg * It should be expanded by defining \p DIM as the number texture dimensions 35848b8605Smrg * (1, 2 or 3). According to the value of \p DIM a series of macros is defined 36848b8605Smrg * for the texel lookup in the gl_texture_image::Data. 37848b8605Smrg * 38848b8605Smrg * \author Gareth Hughes 39848b8605Smrg * \author Brian Paul 40848b8605Smrg */ 41848b8605Smrg 42b8e80941Smrg#include <format_unpack.h> 43848b8605Smrg 44848b8605Smrg#if DIM == 1 45848b8605Smrg 46848b8605Smrg#define TEXEL_ADDR( type, image, i, j, k, size ) \ 47848b8605Smrg ((void) (j), (void) (k), ((type *)(image)->ImageSlices[0] + (i) * (size))) 48848b8605Smrg 49848b8605Smrg#define FETCH(x) fetch_texel_1d_##x 50848b8605Smrg 51848b8605Smrg#elif DIM == 2 52848b8605Smrg 53848b8605Smrg#define TEXEL_ADDR( type, image, i, j, k, size ) \ 54848b8605Smrg ((void) (k), \ 55848b8605Smrg ((type *)((GLubyte *) (image)->ImageSlices[0] + (image)->RowStride * (j)) + \ 56848b8605Smrg (i) * (size))) 57848b8605Smrg 58848b8605Smrg#define FETCH(x) fetch_texel_2d_##x 59848b8605Smrg 60848b8605Smrg#elif DIM == 3 61848b8605Smrg 62848b8605Smrg#define TEXEL_ADDR( type, image, i, j, k, size ) \ 63848b8605Smrg ((type *)((GLubyte *) (image)->ImageSlices[k] + \ 64848b8605Smrg (image)->RowStride * (j)) + (i) * (size)) 65848b8605Smrg 66848b8605Smrg#define FETCH(x) fetch_texel_3d_##x 67848b8605Smrg 68848b8605Smrg#else 69848b8605Smrg#error illegal number of texture dimensions 70848b8605Smrg#endif 71848b8605Smrg 72b8e80941Smrg#define FETCH_Z(x, type, size) \ 73b8e80941Smrg static void \ 74b8e80941Smrg FETCH(x) (const struct swrast_texture_image *texImage, \ 75b8e80941Smrg GLint i, GLint j, GLint k, GLfloat *texel) \ 76b8e80941Smrg { \ 77b8e80941Smrg const type *src = TEXEL_ADDR(type, texImage, i, j, k, size); \ 78b8e80941Smrg _mesa_unpack_float_z_row(MESA_FORMAT_##x, 1, src, texel); \ 79b8e80941Smrg } 80b8e80941Smrg 81b8e80941Smrg#define FETCH_RGBA(x, type, size) \ 82b8e80941Smrg static void \ 83b8e80941Smrg FETCH(x) (const struct swrast_texture_image *texImage, \ 84b8e80941Smrg GLint i, GLint j, GLint k, GLfloat *texel) \ 85b8e80941Smrg { \ 86b8e80941Smrg const type *src = TEXEL_ADDR(type, texImage, i, j, k, size); \ 87b8e80941Smrg _mesa_unpack_rgba_row(MESA_FORMAT_##x, 1, src, (GLvoid *)texel); \ 88b8e80941Smrg } 89b8e80941Smrg 90b8e80941SmrgFETCH_Z(Z_UNORM32, GLuint, 1) 91b8e80941SmrgFETCH_Z(Z_UNORM16, GLushort, 1) 92b8e80941SmrgFETCH_Z(S8_UINT_Z24_UNORM, GLuint, 1) /* only return Z, not stencil data */ 93b8e80941SmrgFETCH_Z(Z24_UNORM_S8_UINT, GLuint, 1) /* only return Z, not stencil data */ 94b8e80941SmrgFETCH_Z(Z32_FLOAT_S8X24_UINT, GLfloat, 2) 95b8e80941Smrg 96b8e80941SmrgFETCH_RGBA(RGBA_FLOAT32, GLfloat, 4) 97b8e80941SmrgFETCH_RGBA(RGBA_FLOAT16, GLhalfARB, 4) 98b8e80941SmrgFETCH_RGBA(RGB_FLOAT32, GLfloat, 3) 99b8e80941SmrgFETCH_RGBA(RGB_FLOAT16, GLhalfARB, 3) 100b8e80941SmrgFETCH_RGBA(A_FLOAT32, GLfloat, 1) 101b8e80941SmrgFETCH_RGBA(A_FLOAT16, GLhalfARB, 1) 102b8e80941SmrgFETCH_RGBA(L_FLOAT32, GLfloat, 1) 103b8e80941SmrgFETCH_RGBA(L_FLOAT16, GLhalfARB, 1) 104b8e80941SmrgFETCH_RGBA(LA_FLOAT32, GLfloat, 2) 105b8e80941SmrgFETCH_RGBA(LA_FLOAT16, GLhalfARB, 2) 106b8e80941SmrgFETCH_RGBA(I_FLOAT32, GLfloat, 1) 107b8e80941SmrgFETCH_RGBA(I_FLOAT16, GLhalfARB, 1) 108b8e80941SmrgFETCH_RGBA(R_FLOAT32, GLfloat, 1) 109b8e80941SmrgFETCH_RGBA(R_FLOAT16, GLhalfARB, 1) 110b8e80941SmrgFETCH_RGBA(RG_FLOAT32, GLfloat, 2) 111b8e80941SmrgFETCH_RGBA(RG_FLOAT16, GLhalfARB, 2) 112b8e80941SmrgFETCH_RGBA(A8B8G8R8_UNORM, GLuint, 1) 113b8e80941SmrgFETCH_RGBA(R8G8B8A8_UNORM, GLuint, 1) 114b8e80941SmrgFETCH_RGBA(B8G8R8A8_UNORM, GLuint, 1) 115b8e80941SmrgFETCH_RGBA(A8R8G8B8_UNORM, GLuint, 1) 116b8e80941SmrgFETCH_RGBA(X8B8G8R8_UNORM, GLuint, 1) 117b8e80941SmrgFETCH_RGBA(R8G8B8X8_UNORM, GLuint, 1) 118b8e80941SmrgFETCH_RGBA(B8G8R8X8_UNORM, GLuint, 1) 119b8e80941SmrgFETCH_RGBA(X8R8G8B8_UNORM, GLuint, 1) 120b8e80941SmrgFETCH_RGBA(BGR_UNORM8, GLubyte, 3) 121b8e80941SmrgFETCH_RGBA(RGB_UNORM8, GLubyte, 3) 122b8e80941SmrgFETCH_RGBA(B5G6R5_UNORM, GLushort, 1) 123b8e80941SmrgFETCH_RGBA(R5G6B5_UNORM, GLushort, 1) 124b8e80941SmrgFETCH_RGBA(B4G4R4A4_UNORM, GLushort, 1) 125b8e80941SmrgFETCH_RGBA(A4R4G4B4_UNORM, GLushort, 1) 126b8e80941SmrgFETCH_RGBA(A1B5G5R5_UNORM, GLushort, 1) 127b8e80941SmrgFETCH_RGBA(B5G5R5A1_UNORM, GLushort, 1) 128b8e80941SmrgFETCH_RGBA(A1R5G5B5_UNORM, GLushort, 1) 129b8e80941SmrgFETCH_RGBA(B10G10R10A2_UNORM, GLuint, 1) 130b8e80941SmrgFETCH_RGBA(R10G10B10A2_UNORM, GLuint, 1) 131b8e80941SmrgFETCH_RGBA(R8G8_UNORM, GLushort, 1) 132b8e80941SmrgFETCH_RGBA(G8R8_UNORM, GLushort, 1) 133b8e80941SmrgFETCH_RGBA(L4A4_UNORM, GLubyte, 1) 134b8e80941SmrgFETCH_RGBA(L8A8_UNORM, GLushort, 1) 135b8e80941SmrgFETCH_RGBA(R_UNORM8, GLubyte, 1) 136b8e80941SmrgFETCH_RGBA(R_UNORM16, GLushort, 1) 137b8e80941SmrgFETCH_RGBA(A8L8_UNORM, GLushort, 1) 138b8e80941SmrgFETCH_RGBA(R16G16_UNORM, GLuint, 1) 139b8e80941SmrgFETCH_RGBA(G16R16_UNORM, GLuint, 1) 140b8e80941SmrgFETCH_RGBA(L16A16_UNORM, GLuint, 1) 141b8e80941SmrgFETCH_RGBA(A16L16_UNORM, GLuint, 1) 142b8e80941SmrgFETCH_RGBA(B2G3R3_UNORM, GLubyte, 1) 143b8e80941SmrgFETCH_RGBA(A_UNORM8, GLubyte, 1) 144b8e80941SmrgFETCH_RGBA(A_UNORM16, GLushort, 1) 145b8e80941SmrgFETCH_RGBA(L_UNORM8, GLubyte, 1) 146b8e80941SmrgFETCH_RGBA(L_UNORM16, GLushort, 1) 147b8e80941SmrgFETCH_RGBA(I_UNORM8, GLubyte, 1) 148b8e80941SmrgFETCH_RGBA(I_UNORM16, GLushort, 1) 149b8e80941SmrgFETCH_RGBA(BGR_SRGB8, GLubyte, 3) 150b8e80941SmrgFETCH_RGBA(A8B8G8R8_SRGB, GLuint, 1) 151b8e80941SmrgFETCH_RGBA(B8G8R8A8_SRGB, GLuint, 1) 152b8e80941SmrgFETCH_RGBA(A8R8G8B8_SRGB, GLuint, 1) 153b8e80941SmrgFETCH_RGBA(R8G8B8A8_SRGB, GLuint, 1) 154b8e80941SmrgFETCH_RGBA(R8G8B8X8_SRGB, GLuint, 1) 155b8e80941SmrgFETCH_RGBA(X8B8G8R8_SRGB, GLuint, 1) 156b8e80941SmrgFETCH_RGBA(R_SRGB8, GLubyte, 1) 157b8e80941SmrgFETCH_RGBA(L_SRGB8, GLubyte, 1) 158b8e80941SmrgFETCH_RGBA(L8A8_SRGB, GLushort, 1) 159b8e80941SmrgFETCH_RGBA(A8L8_SRGB, GLushort, 2) 160b8e80941SmrgFETCH_RGBA(RGBA_SINT8, GLbyte, 4) 161b8e80941SmrgFETCH_RGBA(RGBA_SINT16, GLshort, 4) 162b8e80941SmrgFETCH_RGBA(RGBA_SINT32, GLint, 4) 163b8e80941SmrgFETCH_RGBA(RGBA_UINT8, GLubyte, 4) 164b8e80941SmrgFETCH_RGBA(RGBA_UINT16, GLushort, 4) 165b8e80941SmrgFETCH_RGBA(RGBA_UINT32, GLuint, 4) 166b8e80941SmrgFETCH_RGBA(R_SNORM8, GLbyte, 1) 167b8e80941SmrgFETCH_RGBA(A_SNORM8, GLbyte, 1) 168b8e80941SmrgFETCH_RGBA(L_SNORM8, GLbyte, 1) 169b8e80941SmrgFETCH_RGBA(I_SNORM8, GLbyte, 1) 170b8e80941SmrgFETCH_RGBA(R8G8_SNORM, GLshort, 1) 171b8e80941SmrgFETCH_RGBA(L8A8_SNORM, GLshort, 1) 172b8e80941SmrgFETCH_RGBA(A8L8_SNORM, GLshort, 1) 173b8e80941SmrgFETCH_RGBA(X8B8G8R8_SNORM, GLint, 1) 174b8e80941SmrgFETCH_RGBA(A8B8G8R8_SNORM, GLint, 1) 175b8e80941SmrgFETCH_RGBA(R8G8B8A8_SNORM, GLint, 1) 176b8e80941SmrgFETCH_RGBA(R_SNORM16, GLshort, 1) 177b8e80941SmrgFETCH_RGBA(A_SNORM16, GLshort, 1) 178b8e80941SmrgFETCH_RGBA(L_SNORM16, GLshort, 1) 179b8e80941SmrgFETCH_RGBA(I_SNORM16, GLshort, 1) 180b8e80941SmrgFETCH_RGBA(R16G16_SNORM, GLshort, 2) 181b8e80941SmrgFETCH_RGBA(LA_SNORM16, GLshort, 2) 182b8e80941SmrgFETCH_RGBA(RGB_SNORM16, GLshort, 3) 183b8e80941SmrgFETCH_RGBA(RGBA_SNORM16, GLshort, 4) 184b8e80941SmrgFETCH_RGBA(RGBA_UNORM16, GLushort, 4) 185b8e80941SmrgFETCH_RGBA(RGBX_UNORM16, GLushort, 4) 186b8e80941SmrgFETCH_RGBA(RGBX_FLOAT16, GLhalfARB, 4) 187b8e80941SmrgFETCH_RGBA(RGBX_FLOAT32, GLfloat, 4) 188b8e80941SmrgFETCH_RGBA(YCBCR, GLushort, 1) /* Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA. */ 189b8e80941SmrgFETCH_RGBA(YCBCR_REV, GLushort, 1) /* Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA. */ 190b8e80941SmrgFETCH_RGBA(R9G9B9E5_FLOAT, GLuint, 1) 191b8e80941SmrgFETCH_RGBA(R11G11B10_FLOAT, GLuint, 1) 192848b8605Smrg 193848b8605Smrg#undef TEXEL_ADDR 194848b8605Smrg#undef DIM 195848b8605Smrg#undef FETCH 196b8e80941Smrg#undef FETCH_Z 197b8e80941Smrg#undef FETCH_RGBA 198