FastUIDraw
fastuidraw_atlases.glsl.hpp
Go to the documentation of this file.
1 /*!
2  * \file fastuidraw_atlases.glsl.hpp
3  * \brief file fastuidraw_atlases.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 #ifdef GLSL_DOXYGEN
24  /*!
25  * \def fastuidraw_colorStopFetch(x, L)
26  * Use this macro to read a color value from the colorstop atlas
27  * (see \ref fastuidraw::ColorStopAtlas). Recall that colorstops
28  * are stored as part of a GL_TEXTURE_1D_ARRAY or GL_TEXTURE_2D_ARRAY
29  * and that the interpolation of the color is to be handled by the
30  * the sampler.
31  * \param x texture coordinate (i.e. normalized to [0, 1]) to read from the atlas
32  * \param L which layer to read from the atlas
33  */
34  #define fastuidraw_colorStopFetch(x, L)
35 
36  /*!
37  * The sampler2Darray that backs the color tiles of the image
38  * atlas (\ref fastuidraw::ImageAtlas) whose magnification filtering
39  * is set to GL_LINEAR and whose minification filtering is set to
40  * GL_LINEAR_MIPMAP_NEAREST.
41  */
42  uniform sampler2DArray fastuidraw_imageAtlasLinear;
43 
44  /*!
45  * The sampler2Darray that backs the color tiles of the image
46  * atlas (\ref fastuidraw::ImageAtlas) whose magnification and
47  * minification filtering are set to GL_NEAREST.
48  */
49  uniform sampler2DArray fastuidraw_imageAtlasNearest;
50 
51  /*!
52  * The usampler2DArray that backes index tiles of the image
53  * atlas (\ref fastuidraw::ImageAtlas).
54  */
55  uniform usampler2DArray fastuidraw_imageIndexAtlas;
56 
57  /*!
58  * \def fastuidraw_fetch_glyph_data(X)
59  * Use this macro to read a single 32-bit value from the glyph atlas
60  * (\ref fastuidraw::GlyphAtlas).
61  * \param X offset into the glyph atlas to read
62  */
63  #define fastuidraw_fetch_glyph_data(X)
64 
65  /*!
66  * \def fastuidraw_fetch_glyph_data_fp16x2(X)
67  * Use this macro to read a single 32-bit value from the glyph atlas
68  * (\ref fastuidraw::GlyphAtlas) interpreted as a vec2 of 16-bit floats.
69  * \param X offset into the glyph atlas to read
70  */
71  #define fastuidraw_fetch_glyph_data_fp16x2(X)
72 
73 #endif
74 /*! @} */
75 
76 ///@cond
77 
78 //////////////////////////////////////////////
79 // Color Stop Atlas
80 #ifdef FASTUIDRAW_PAINTER_COLORSTOP_ATLAS_2D_ARRAY
81 
82  FASTUIDRAW_LAYOUT_BINDING(FASTUIDRAW_COLORSTOP_ATLAS_BINDING) uniform sampler2DArray fastuidraw_colorStopAtlas;
83  #define fastuidraw_colorStopFetch(x, L) textureLod(fastuidraw_colorStopAtlas, vec3(float(x), 0.0, float(L)), 0.0)
84 
85 #else
86 
87  FASTUIDRAW_LAYOUT_BINDING(FASTUIDRAW_COLORSTOP_ATLAS_BINDING) uniform sampler1DArray fastuidraw_colorStopAtlas;
88  #define fastuidraw_colorStopFetch(x, L) textureLod(fastuidraw_colorStopAtlas, vec2(float(x), float(L)), 0.0)
89 
90 #endif
91 ///////////////////////////////////////////////
92 
93 
94 //////////////////////////////////////////////////
95 // Image Atlas
96 #ifndef FASTUIDRAW_IMAGE_ATLAS_DISABLED
97  FASTUIDRAW_LAYOUT_BINDING(FASTUIDRAW_COLOR_TILE_LINEAR_BINDING) uniform sampler2DArray fastuidraw_imageAtlasLinear;
98  FASTUIDRAW_LAYOUT_BINDING(FASTUIDRAW_COLOR_TILE_NEAREST_BINDING) uniform sampler2DArray fastuidraw_imageAtlasNearest;
99  FASTUIDRAW_LAYOUT_BINDING(FASTUIDRAW_INDEX_TILE_BINDING) uniform usampler2DArray fastuidraw_imageIndexAtlas;
100 #endif
101 //////////////////////////////////////////////////
102 
103 ///////////////////////////////////////////////////
104 // Glyph Atlas Store
105 #ifdef FASTUIDRAW_GLYPH_DATA_STORE_SSBO
106 
107  FASTUIDRAW_LAYOUT_BINDING_ARGS(FASTUIDRAW_GLYPH_DATA_STORE_BINDING, std430) restrict readonly buffer fastuidraw_glyphDataStore
108  {
109  uint fastuidraw_glyphDataStore_data[];
110  };
111  #define fastuidraw_fetch_glyph_data(X) (fastuidraw_glyphDataStore_data[int(X)])
112  #define fastuidraw_fetch_glyph_data_fp16x2(X) fastuidraw_unpackHalf2x16(fastuidraw_glyphDataStore_data[int(X)])
113 
114 #elif defined(FASTUIDRAW_GLYPH_DATA_STORE_TEXTURE_ARRAY)
115 
116  /* The width and height of fastuidraw_glyphDataStore are
117  * powers of 2, the values given by FASTUIDRAW_GLYPH_DATA_WIDTH_LOG2
118  * and FASTUIDRAW_GLYPH_DATA_HEIGHT_LOG2. We want to use
119  * bit shifts and masking to get the correct layer, height and so on.
120  */
121  FASTUIDRAW_LAYOUT_BINDING(FASTUIDRAW_GLYPH_DATA_STORE_BINDING) uniform usampler2DArray fastuidraw_glyphDataStore;
122  #define FASTUIDRAW_GLYPH_DATA_WIDTH_PLUS_HEIGHT_LOG2 uint(FASTUIDRAW_GLYPH_DATA_WIDTH_LOG2 + FASTUIDRAW_GLYPH_DATA_HEIGHT_LOG2)
123  #define FASTUIDRAW_GLYPH_DATA_LAYER(T) (uint(T) >> FASTUIDRAW_GLYPH_DATA_WIDTH_PLUS_HEIGHT_LOG2)
124  #define FASTUIDRAW_GLYPH_DATA_Y(T) FASTUIDRAW_EXTRACT_BITS(FASTUIDRAW_GLYPH_DATA_WIDTH_LOG2, FASTUIDRAW_GLYPH_DATA_HEIGHT_LOG2, T)
125  #define FASTUIDRAW_GLYPH_DATA_X(T) FASTUIDRAW_EXTRACT_BITS(0, FASTUIDRAW_GLYPH_DATA_WIDTH_LOG2, T)
126  #define FASTUIDRAW_GLYPH_DATA_COORD(v) ivec3(FASTUIDRAW_GLYPH_DATA_X(v), FASTUIDRAW_GLYPH_DATA_Y(v), FASTUIDRAW_GLYPH_DATA_LAYER(v))
127 
128  #define fastuidraw_fetch_glyph_data(X) (texelFetch(fastuidraw_glyphDataStore, FASTUIDRAW_GLYPH_DATA_COORD(X), 0).r)
129  #define fastuidraw_fetch_glyph_data_fp16x2(X) fastuidraw_unpackHalf2x16(fastuidraw_fetch_glyph_data(X))
130 #else
131 
132  FASTUIDRAW_LAYOUT_BINDING(FASTUIDRAW_GLYPH_DATA_STORE_BINDING) uniform usamplerBuffer fastuidraw_glyphDataStore;
133 
134  #define fastuidraw_fetch_glyph_data(X) (texelFetch(fastuidraw_glyphDataStore, int(X)).r)
135  #define fastuidraw_fetch_glyph_data_fp16x2(X) fastuidraw_unpackHalf2x16(fastuidraw_fetch_glyph_data(X))
136 
137 #endif
138 ////////////////////////////////////////////////////
139 
140 
141 ///@endcond
uniform sampler2DArray fastuidraw_imageAtlasLinear
uniform sampler2DArray fastuidraw_imageAtlasNearest
uniform usampler2DArray fastuidraw_imageIndexAtlas