FastUIDraw
fastuidraw_read_texels_from_data.glsl.hpp
Go to the documentation of this file.
1 /*!
2  * \file fastuidraw_read_texels_from_data.glsl.hpp
3  * \brief file fastuidraw_read_texels_from_data.glsl.hpp
4  *
5  * Copyright 2018 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 /*!\addtogroup GLSLVertFragCode
20  * @{
21  */
22 
23 /*!
24  * \brief
25  * Read 8-bit texel data from 32-bit linear data as packed into a \ref
26  * fastuidraw::GlyphAtlas by \ref fastuidraw::GlyphRenderDataTexels
27  * \param coord texel coordinate to read
28  * \param dims dimension of texel data (i.e. \ref fastuidraw::GlyphRenderDataTexels::resolution())
29  * \param location location into \ref fastuidraw::GlyphAtlas of the data
30  */
31 uint
32 fastuidraw_read_texel_from_data(in ivec2 coord, in uvec2 dims, in uint location)
33 {
34  uint x, y, block_offset, block;
35  uint bit0x, bit0y;
36 
37  if (coord.x < 0 || coord.y < 0)
38  {
39  return 0u;
40  }
41 
42  x = uint(coord.x);
43  y = uint(coord.y);
44 
45  if (x >= dims.x || y >= dims.y)
46  {
47  return 0u;
48  }
49 
50  /* note the (dims.x() + 1u), this is because each block is 2x2
51  * texels and if w is odd, the dimension is rounded -UP-,
52  * thus adding 1u before the bitshift does the job of
53  * rounding up.
54  */
55  block_offset = location + (x >> 1u) + (y >> 1u) * ((dims.x + 1u) >> 1u);
56  block = fastuidraw_fetch_glyph_data(block_offset);
57 
58  /* now read the correct 8-bits from the block */
59  bit0x = ((x & 1u) != 0u) ? 8u : 0u;
60  bit0y = ((y & 1u) != 0u) ? 16u : 0u;
61  return FASTUIDRAW_EXTRACT_BITS(bit0x + bit0y, 8u, block);
62 }
63 /*! @} */
uint fastuidraw_read_texel_from_data(in ivec2 coord, in uvec2 dims, in uint location)
Read 8-bit texel data from 32-bit linear data as packed into a fastuidraw::GlyphAtlas by fastuidraw::...
vecN< uint32_t, 2 > uvec2
Definition: vecN.hpp:1282
#define FASTUIDRAW_EXTRACT_BITS(bit0, num_bits, src)
#define fastuidraw_fetch_glyph_data(X)
vecN< int32_t, 2 > ivec2
Definition: vecN.hpp:1265