HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_Texture2DArrayMap.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Render Library (C++)
7  *
8  * COMMENTS:
9  * Handle to a 2D array texture stored in the texture cache. This class is
10  * primarily responsible for fetching images from various 2D sources and
11  * creating the texture for them.
12  * A 2D texture array is made up of multiple 2D texture sources. It can
13  * also support UDIM texturing.
14  *
15  */
16 #ifndef __RE_Texture2DArrayMap_h__
17 #define __RE_Texture2DArrayMap_h__
18 
19 #include "RE_API.h"
20 #include "RE_TextureMap.h"
21 #include "RE_Utils.h"
22 
23 #include <IMG/IMG_FileTypes.h>
24 #include <UT/UT_Rect.h>
25 #include <UT/UT_UniquePtr.h>
26 #include <UT/UT_VectorTypes.h>
27 
28 
29 class PXL_Raster;
30 
32 {
33 public:
34  RE_Texture2DArrayMap(bool is_tiled_texture = false,
35  int u_stride = 10);
36  ~RE_Texture2DArrayMap() override;
37 
40 
41  const char *className() const override { return "RE_Texture2DArrayMap"; }
42 
43  /// This texture array represents a UDIM or UV tile sequence for a tiled
44  /// texture when this is enabled. The U stride is normally 10 for UDIM,
45  /// and ignored for UV tile textures.
46  void enableTileSource(bool e, int u_stride = 10);
47 
48  /// Returns the detected udim stride (not the u_stride above). This is the
49  /// number of images in the U direction for tiled textures.
50  int getTileStride() const { return myTileArea.w(); }
51 
52  /// Returns the bounding area of the populated tiles
53  UT_DimRect getTileArea() const { return myTileArea; }
54 
55  /// Sets a series of image files for the 2D array. They will appear in
56  /// the texture layers in the same order as passed. The resolution of the
57  /// array will be files.entries() layers, and the width and height will
58  /// be the maximum width and height of all images, up to max_width and
59  /// max_height if they are non-zero. An empty string can be passed to
60  /// fill that layer with (1,1,1,1).
61  void setImageList(const UT_StringArray &files,
62  int max_width = 0,
63  int max_height = 0);
64 
65  /// Returns the amount of main memory owned by this object.
66  /// GL Textures are shared in the texture cache itself.
67  int64 getMemoryUsage(bool inclusive) const override;
68 
70  RE_TextureMap *clone() const override;
71 
72  /// Returns true if the string is a tiled texture (UDIM or UV Tile) based
73  /// on the prescense of %(UDIM), %(U), %(V) or %(UVTILE) in the filename.
74  /// Optional udim_marker and uv_marker allow UDIM and/or UVTILE to be
75  /// customized
76  static bool isArrayMap(const char *map_filename,
77  const char *uv_marker = nullptr);
78 
79  void invalidateCached() override;
80 
81  /// Custom markers for %(UVTILE)d
82  void setUVTileMarker(const UT_StringRef &marker);
83 
84  // Public interface is in RE_TextureMap
85 
87  { theHDAFileResolver = cb; }
88 private:
89  bool buildTexture(RE_Render *r, RE_Texture *tex,
90  void *data) override;
91  bool getNodeSource(const char *map, const char *rel,
92  void **mapptr,
93  RE_TextureDimension &textype,
94  RE_GPUType &datatype,
95  int &vectorsize,
96  int &w, int &h, int &d) override;
97  bool getFileSource(const char *map,
98  void **mapptr,
99  RE_TextureDimension &textype,
100  RE_GPUType &datatype,
101  int &vectorsize,
102  int &w, int &h, int &d,
103  bool preload_only) override;
104 
105  void cachedTextureFound(RE_Texture *tex) override;
106 
107  // UDIM-style tiled textures (1001+)
108  bool determineUDIMBounds(const char *map);
109 
110  // Mari-style u#v# textures
111  bool determineTileBounds(const char *map);
112 
113  // for %(U)d %(V)d syntax, mari-style texures
114  bool determineUVBounds(const char *map);
115  // for %(UVTILE)d syntax, mari-style texures
116  bool determineUVTileBounds(const char *map,
117  const char *marker);
118 
119  bool findUVTileFiles(bool is_opdef,
120  const char *pattern,
121  const char *path,
122  int base_length,
123  int ext_length,
124  bool u_first);
125 
126  bool determineFileBounds();
127  void loadTiledTexture();
128  void loadArrayTexture();
129 
130  // TODO: for File COP support.
131  // fpreal myOpTime;
132  // unsigned long myOpVersion;
133 
134  bool myIsTiledTexture;
135 
136  // image file details, per file
137  IMG_DataType myDataType;
138  IMG_ColorModel myColorModel;
139  RE_GPUType myFormat;
140  int myVectorSize;
141  int myResW;
142  int myResH;
143  int myResD;
144 
145  // for non-UDIM 2D image collections
146  UT_StringArray myFiles;
147  int myMaxW, myMaxH;
148  bool myFilesDirty;
149 
150  int myTileStride;
151  UT_DimRect myTileArea;
152 
154  UT_StringHolder myLastMap;
155  UT_StringHolder myUDIMMarker;
156  UT_StringHolder myUVTileMarker;
158  myImages;
159  bool myDeferredLoadFlag;
160 
161  // For resolving files inside HDAs.
162  static RE_TextureHDAResolverCB theHDAFileResolver;
163 };
164 
165 #endif
virtual RE_TextureMap * clone() const =0
#define RE_API
Definition: RE_API.h:10
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
virtual bool getNodeSource(const char *map, const char *rel, void **mapptr, RE_TextureDimension &textype, RE_GPUType &datatype, int &vectorsize, int &w, int &h, int &d)
RE_TextureDimension
RE_TextureDimension getMapType() override
const char * className() const override
RE_GPUType
Definition: RE_Types.h:44
UT_DimRect getTileArea() const
Returns the bounding area of the populated tiles.
virtual void cachedTextureFound(RE_Texture *tex)
IMG_DataType
Definition: IMG_FileTypes.h:17
virtual void invalidateCached()
long long int64
Definition: SYS_Types.h:116
static void installHDACallback(RE_TextureHDAResolverCB cb)
virtual int64 getMemoryUsage(bool inclusive) const
GLushort pattern
Definition: glad.h:2583
RE_API bool determineUDIMBounds(const UT_StringHolder &filepath, UT_DimRect &udim_area, int &max_tile, UT_Array< std::pair< UT_StringHolder, UT_Vector2i >> &tiles, int tile_stride, RE_TextureHDAResolverCB hda_resolver)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
virtual bool getFileSource(const char *map, void **mapptr, RE_TextureDimension &textype, RE_GPUType &datatype, int &vectorsize, int &w, int &h, int &d, bool preload_only)
LeafData & operator=(const LeafData &)=delete
IMG_ColorModel
Definition: IMG_FileTypes.h:52
void(* RE_TextureHDAResolverCB)(const char *optable_optype, const char *pattern, UT_StringArray &files)
Definition: RE_Utils.h:25
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GLboolean r
Definition: glcorearb.h:1222
virtual bool buildTexture(RE_Render *r, RE_Texture *tex, void *data)=0
Definition: format.h:895