From 4ca9ba254462b9be55b78df1d50519e10b2f4d73 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 1 Oct 2009 16:42:37 -0600 Subject: mesa: move mesa_set_fetch_functions() --- src/mesa/main/texfetch.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'src/mesa/main/texfetch.c') diff --git a/src/mesa/main/texfetch.c b/src/mesa/main/texfetch.c index 62a8b53409..3428f705be 100644 --- a/src/mesa/main/texfetch.c +++ b/src/mesa/main/texfetch.c @@ -565,3 +565,84 @@ _mesa_get_texel_store_func(gl_format format) } return NULL; } + + + +/** + * Adaptor for fetching a GLchan texel from a float-valued texture. + */ +static void +fetch_texel_float_to_chan(const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLchan *texelOut) +{ + GLfloat temp[4]; + GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat); + + ASSERT(texImage->FetchTexelf); + texImage->FetchTexelf(texImage, i, j, k, temp); + if (baseFormat == GL_DEPTH_COMPONENT || + baseFormat == GL_DEPTH_STENCIL_EXT) { + /* just one channel */ + UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]); + } + else { + /* four channels */ + UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]); + UNCLAMPED_FLOAT_TO_CHAN(texelOut[1], temp[1]); + UNCLAMPED_FLOAT_TO_CHAN(texelOut[2], temp[2]); + UNCLAMPED_FLOAT_TO_CHAN(texelOut[3], temp[3]); + } +} + + +/** + * Adaptor for fetching a float texel from a GLchan-valued texture. + */ +static void +fetch_texel_chan_to_float(const struct gl_texture_image *texImage, + GLint i, GLint j, GLint k, GLfloat *texelOut) +{ + GLchan temp[4]; + GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat); + + ASSERT(texImage->FetchTexelc); + texImage->FetchTexelc(texImage, i, j, k, temp); + if (baseFormat == GL_DEPTH_COMPONENT || + baseFormat == GL_DEPTH_STENCIL_EXT) { + /* just one channel */ + texelOut[0] = CHAN_TO_FLOAT(temp[0]); + } + else { + /* four channels */ + texelOut[0] = CHAN_TO_FLOAT(temp[0]); + texelOut[1] = CHAN_TO_FLOAT(temp[1]); + texelOut[2] = CHAN_TO_FLOAT(temp[2]); + texelOut[3] = CHAN_TO_FLOAT(temp[3]); + } +} + + +/** + * Initialize the texture image's FetchTexelc and FetchTexelf methods. + */ +void +_mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims) +{ + ASSERT(dims == 1 || dims == 2 || dims == 3); + ASSERT(texImage->TexFormat); + + texImage->FetchTexelf = + _mesa_get_texel_fetch_func(texImage->TexFormat, dims); + + /* now check if we need to use a float/chan adaptor */ + if (!texImage->FetchTexelc) { + texImage->FetchTexelc = fetch_texel_float_to_chan; + } + else if (!texImage->FetchTexelf) { + texImage->FetchTexelf = fetch_texel_chan_to_float; + } + + + ASSERT(texImage->FetchTexelc); + ASSERT(texImage->FetchTexelf); +} -- cgit v1.2.3