1 /*
2  * Copyright 2011-2016 Blender Foundation
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 #ifndef __UTIL_TEXTURE_H__
18 #define __UTIL_TEXTURE_H__
19 
20 #include "util_transform.h"
21 
22 CCL_NAMESPACE_BEGIN
23 
24 /* Texture limits on devices. */
25 #define TEX_NUM_MAX (INT_MAX >> 4)
26 
27 /* Color to use when textures are not found. */
28 #define TEX_IMAGE_MISSING_R 1
29 #define TEX_IMAGE_MISSING_G 0
30 #define TEX_IMAGE_MISSING_B 1
31 #define TEX_IMAGE_MISSING_A 1
32 
33 /* Texture type. */
34 #define kernel_tex_type(tex) (tex & IMAGE_DATA_TYPE_MASK)
35 
36 /* Interpolation types for textures
37  * cuda also use texture space to store other objects */
38 typedef enum InterpolationType {
39   INTERPOLATION_NONE = -1,
40   INTERPOLATION_LINEAR = 0,
41   INTERPOLATION_CLOSEST = 1,
42   INTERPOLATION_CUBIC = 2,
43   INTERPOLATION_SMART = 3,
44 
45   INTERPOLATION_NUM_TYPES,
46 } InterpolationType;
47 
48 /* Texture types
49  * Since we store the type in the lower bits of a flat index,
50  * the shift and bit mask constant below need to be kept in sync. */
51 typedef enum ImageDataType {
52   IMAGE_DATA_TYPE_FLOAT4 = 0,
53   IMAGE_DATA_TYPE_BYTE4 = 1,
54   IMAGE_DATA_TYPE_HALF4 = 2,
55   IMAGE_DATA_TYPE_FLOAT = 3,
56   IMAGE_DATA_TYPE_BYTE = 4,
57   IMAGE_DATA_TYPE_HALF = 5,
58   IMAGE_DATA_TYPE_USHORT4 = 6,
59   IMAGE_DATA_TYPE_USHORT = 7,
60   IMAGE_DATA_TYPE_NANOVDB_FLOAT = 8,
61   IMAGE_DATA_TYPE_NANOVDB_FLOAT3 = 9,
62 
63   IMAGE_DATA_NUM_TYPES
64 } ImageDataType;
65 
66 /* Alpha types
67  * How to treat alpha in images. */
68 typedef enum ImageAlphaType {
69   IMAGE_ALPHA_UNASSOCIATED = 0,
70   IMAGE_ALPHA_ASSOCIATED = 1,
71   IMAGE_ALPHA_CHANNEL_PACKED = 2,
72   IMAGE_ALPHA_IGNORE = 3,
73   IMAGE_ALPHA_AUTO = 4,
74 
75   IMAGE_ALPHA_NUM_TYPES,
76 } ImageAlphaType;
77 
78 #define IMAGE_DATA_TYPE_SHIFT 4
79 #define IMAGE_DATA_TYPE_MASK 0xF
80 
81 /* Extension types for textures.
82  *
83  * Defines how the image is extrapolated past its original bounds. */
84 typedef enum ExtensionType {
85   /* Cause the image to repeat horizontally and vertically. */
86   EXTENSION_REPEAT = 0,
87   /* Extend by repeating edge pixels of the image. */
88   EXTENSION_EXTEND = 1,
89   /* Clip to image size and set exterior pixels as transparent. */
90   EXTENSION_CLIP = 2,
91 
92   EXTENSION_NUM_TYPES,
93 } ExtensionType;
94 
95 typedef struct TextureInfo {
96   /* Pointer, offset or texture depending on device. */
97   uint64_t data;
98   /* Data Type */
99   uint data_type;
100   /* Buffer number for OpenCL. */
101   uint cl_buffer;
102   /* Interpolation and extension type. */
103   uint interpolation, extension;
104   /* Dimensions. */
105   uint width, height, depth;
106   /* Transform for 3D textures. */
107   uint use_transform_3d;
108   Transform transform_3d;
109 } TextureInfo;
110 
111 CCL_NAMESPACE_END
112 
113 #endif /* __UTIL_TEXTURE_H__ */
114