| 0.8.2 API documentation

- Main Page
- Namespaces
- Classes
- Files

- File List

coord.hpp
1 #pragma once
2
3 #include "../type.hpp"
4
5 namespace gli{
6 namespace detail
7 {
8 template <typename T, precision P, template <typename, precision> class vecType>
9 inline vecType<bool, P> in_interval(vecType<T, P> const& Value, vecType<T, P> const& Min, vecType<T, P> const& Max)
10 {
11 return greaterThanEqual(Value, Min) && lessThanEqual(Value, Max);
12 }
13
14 template <typename extent_type, typename normalized_type>
15 struct coord_nearest
16 {
17 extent_type Texel;
18 typename extent_type::bool_type UseTexel;
19 };
20
21 template <typename extent_type, typename normalized_type>
22 inline coord_nearest<extent_type, normalized_type> make_coord_nearest(extent_type const& TexelExtent, normalized_type const& SampleCoord)
23 {
24 normalized_type const TexelLast(normalized_type(TexelExtent) - normalized_type(1));
25
26 coord_nearest<extent_type, normalized_type> Coord;
27 Coord.Texel = extent_type(round(SampleCoord * TexelLast));
28 Coord.UseTexel = in_interval(Coord.Texel, extent_type(0), TexelExtent - 1);
29 return Coord;
30 }
31
32 template <typename extent_type, typename normalized_type>
33 struct coord_linear
34 {
35 extent_type TexelFloor;
36 extent_type TexelCeil;
37 normalized_type Blend;
38 };
39
40 template <typename extent_type, typename normalized_type>
41 struct coord_linear_border : public coord_linear<extent_type, normalized_type>
42 {
43 typename extent_type::bool_type UseTexelFloor;
44 typename extent_type::bool_type UseTexelCeil;
45 };
46
47 template <typename extent_type, typename normalized_type>
48 GLI_FORCE_INLINE coord_linear<extent_type, normalized_type> make_coord_linear(extent_type const& TexelExtent, normalized_type const& SampleCoord)
49 {
50 coord_linear<extent_type, normalized_type> Coord;
51
52 normalized_type const TexelExtentF(TexelExtent);
53 normalized_type const TexelLast = TexelExtentF - normalized_type(1);
54 normalized_type const ScaledCoord(SampleCoord * TexelLast);
55 normalized_type const ScaledCoordFloor = normalized_type(extent_type(ScaledCoord));
56 normalized_type const ScaledCoordCeil = normalized_type(extent_type(ScaledCoord + normalized_type(0.5)));
57 //normalized_type const ScaledCoordFloor(floor(ScaledCoord));
58 //normalized_type const ScaledCoordCeil(ceil(ScaledCoord));
59
60 Coord.Blend = ScaledCoord - ScaledCoordFloor;
61 Coord.TexelFloor = extent_type(ScaledCoordFloor);
62 Coord.TexelCeil = extent_type(ScaledCoordCeil);
63
64 return Coord;
65 }
66
67 template <typename extent_type, typename normalized_type>
68 GLI_FORCE_INLINE coord_linear_border<extent_type, normalized_type> make_coord_linear_border(extent_type const& TexelExtent, normalized_type const& SampleCoord)
69 {
70 coord_linear_border<extent_type, normalized_type> Coord;
71
72 normalized_type const TexelExtentF(TexelExtent);
73 normalized_type const TexelLast = TexelExtentF - normalized_type(1);
74 normalized_type const ScaledCoord(SampleCoord * TexelLast);
75 normalized_type const ScaledCoordFloor(floor(ScaledCoord));
76 normalized_type const ScaledCoordCeil(ceil(ScaledCoord));
77
78 Coord.Blend = ScaledCoord - ScaledCoordFloor;
79 Coord.TexelFloor = extent_type(ScaledCoordFloor);
80 Coord.TexelCeil = extent_type(ScaledCoordCeil);
81 Coord.UseTexelFloor = in_interval(Coord.TexelFloor, extent_type(0), TexelExtent - 1);
82 Coord.UseTexelCeil = in_interval(Coord.TexelCeil, extent_type(0), TexelExtent - 1);
83
84 return Coord;
85 }
86 }//namespace detail
87 }//namespace gli
gli
Namespace where all the classes and functions provided by GLI are exposed.
Definition: clear.hpp:6