1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.xr.runtime.internal
18 
19 import androidx.annotation.RestrictTo
20 
21 /**
22  * TextureSampler class used to define the way a texture gets sampled. The fields of this sampler
23  * are based on the public Filament TextureSampler class but may diverge over time.
24  * https://github.com/google/filament/blob/main/android/filament-android/src/main/java/com/google/android/filament/TextureSampler.java
25  *
26  * @param wrapModeS wrap mode S for the texture sampler.
27  * @param wrapModeT wrap mode T for the texture sampler.
28  * @param wrapModeR wrap mode R for the texture sampler.
29  * @param minFilter min filter for the texture sampler.
30  * @param magFilter mag filter for the texture sampler.
31  * @param compareMode compare mode for the texture sampler.
32  * @param compareFunc compare function for the texture sampler.
33  * @param anisotropyLog2 anisotropy log 2 for the texture sampler.
34  */
35 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
36 public class TextureSampler(
37     @TextureSampler.WrapMode public val wrapModeS: Int,
38     @TextureSampler.WrapMode public val wrapModeT: Int,
39     @TextureSampler.WrapMode public val wrapModeR: Int,
40     @TextureSampler.WrapMode public val minFilter: Int,
41     @TextureSampler.WrapMode public val magFilter: Int,
42     @TextureSampler.WrapMode public val compareMode: Int,
43     @TextureSampler.WrapMode public val compareFunc: Int,
44     @TextureSampler.WrapMode public val anisotropyLog2: Int,
45 ) {
46     /**
47      * Defines how texture coordinates outside the range [0, 1] are handled. Although these values
48      * are based on the public Filament values, they may diverge over time.
49      */
50     public annotation class WrapMode {
51         public companion object {
52             public const val CLAMP_TO_EDGE: Int = 0
53             public const val REPEAT: Int = 1
54             public const val MIRRORED_REPEAT: Int = 2
55         }
56     }
57 
58     /**
59      * Specifies how the texture is sampled when it's minified (appears smaller than its original
60      * size). Although these values are based on the public Filament values, they may diverge over
61      * time.
62      */
63     public annotation class MinFilter {
64         public companion object {
65             public const val NEAREST: Int = 0
66             public const val LINEAR: Int = 1
67             public const val NEAREST_MIPMAP_NEAREST: Int = 2
68             public const val LINEAR_MIPMAP_NEAREST: Int = 3
69             public const val NEAREST_MIPMAP_LINEAR: Int = 4
70             public const val LINEAR_MIPMAP_LINEAR: Int = 5
71         }
72     }
73 
74     /**
75      * Specifies how the texture is sampled when it's magnified (appears larger than its original
76      * size). Although these values are based on the public Filament values, they may diverge over
77      * time.
78      */
79     public annotation class MagFilter {
80         public companion object {
81             public const val NEAREST: Int = 0
82             public const val LINEAR: Int = 1
83         }
84     }
85 
86     /**
87      * Used for depth texture comparisons, determining how the sampled depth value is compared to a
88      * reference depth. Although these values are based on the public Filament values, they may
89      * diverge over time.
90      */
91     public annotation class CompareMode {
92         public companion object {
93             public const val NONE: Int = 0
94             public const val COMPARE_TO_TEXTURE: Int = 1
95         }
96     }
97 
98     /**
99      * Comparison functions for the depth sampler. Although these values are based on the public
100      * Filament values, they may diverge over time.
101      */
102     public annotation class CompareFunc {
103         public companion object {
104             public const val LE: Int = 0
105             public const val GE: Int = 1
106             public const val L: Int = 2
107             public const val G: Int = 3
108             public const val E: Int = 4
109             public const val NE: Int = 5
110             public const val A: Int = 6
111             public const val N: Int = 7
112         }
113     }
114 
115     public companion object {
116         /** The edge of the texture extends to infinity. */
117         public const val CLAMP_TO_EDGE: Int = 0
118 
119         /** The texture infinitely repeats in the wrap direction. */
120         public const val REPEAT: Int = 1
121 
122         /** The texture infinitely repeats and mirrors in the wrap direction. */
123         public const val MIRRORED_REPEAT: Int = 2
124 
125         /** No filtering. Nearest neighbor is used. */
126         public const val NEAREST: Int = 0
127 
128         /** Box filtering. Weighted average of 4 neighbors is used. */
129         public const val LINEAR: Int = 1
130 
131         /** Mip-mapping is activated. But no filtering occurs. */
132         public const val NEAREST_MIPMAP_NEAREST: Int = 2
133 
134         /** Box filtering within a mip-map level. */
135         public const val LINEAR_MIPMAP_NEAREST: Int = 3
136 
137         /** Mip-map levels are interpolated, but no other filtering occurs. */
138         public const val NEAREST_MIPMAP_LINEAR: Int = 4
139 
140         /** Both interpolated Mip-mapping and linear filtering are used. */
141         public const val LINEAR_MIPMAP_LINEAR: Int = 5
142 
143         /** No filtering. Nearest neighbor is used. */
144         public const val MAG_NEAREST: Int = 0
145 
146         /** Box filtering. Weighted average of 4 neighbors is used. */
147         public const val MAG_LINEAR: Int = 1
148 
149         public const val NONE: Int = 0
150 
151         public const val COMPARE_TO_TEXTURE: Int = 1
152 
153         /** Less or equal */
154         public const val LE: Int = 0
155 
156         /** Greater or equal */
157         public const val GE: Int = 1
158 
159         /** Strictly less than */
160         public const val L: Int = 2
161 
162         /** Strictly greater than */
163         public const val G: Int = 3
164 
165         /** Equal */
166         public const val E: Int = 4
167 
168         /** Not equal */
169         public const val NE: Int = 5
170 
171         /** Always. Depth testing is deactivated. */
172         public const val A: Int = 6
173 
174         /** Never. The depth test always fails. */
175         public const val N: Int = 7
176     }
177 }
178