HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_IconTextureCache.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: RE_IconTextureCache.h (RE Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __RE_IconTextureCache__
12 #define __RE_IconTextureCache__
13 
14 #include "RE_API.h"
15 #include "RE_Texture.h"
16 #include "RE_TextureTypes.h"
17 
18 #include <UT/UT_Array.h>
19 #include <UT/UT_IntArray.h>
20 #include <UT/UT_NonCopyable.h>
21 #include <UT/UT_Rect.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <SYS/SYS_TypeDecorate.h>
24 #include <SYS/SYS_Types.h>
25 
26 class RE_Render;
27 class PXL_Raster;
28 
30 {
31 public:
33  { }
35  short x, short y, short w, short h,
36  float alpha, float z)
37  : myTex(tex),
38  myClip(clip),
39  myX(x),
40  myY(y),
41  myW(w),
42  myH(h),
43  myAlpha(alpha),
44  myZ(z)
45  { }
46 
49  short myX;
50  short myY;
51  short myW;
52  short myH;
53  float myAlpha;
54  float myZ;
55 };
57 
59 {
60 public:
62 
64 
65  /// Add a regular texture from a raster and return its unique ID.
66  RE_Texture *addTexture(RE_Render *r, PXL_Raster *texture);
67 
68  /// Add a texture from a raster, and automatically generate the mip-map
69  /// levels for it.
70  RE_Texture *addMipMapTexture(RE_Render *r, PXL_Raster *texture);
71 
72  /// Add a mip-mapped texture, with many levels defined by the rasters passed
73  /// as levels, and return its unique ID. The levels must all be powers of
74  /// two in size, and must follow the progression from 2^Nx2^N,
75  /// 2^(N-1)x2^(N-1), ..., 1x1.
76  RE_Texture *addMipMapTexture(RE_Render *r,
78 
79  /// Remove a texture from the cache.
80  void removeTexture(RE_Texture *tex);
81 
82  /// Free all textures.
83  void clearTextureCache();
84 
85  /// Returns a version # for the cache; every time it is cleared, this
86  /// number is bumped;
87  int getTextureVersion() const { return myVersion; }
88 
89  /// Render a given texture at (x, y) with width and height w, h.
90  void renderTexture(RE_Render *r, int x, int y, int w, int h,
91  RE_Texture *tex, float alpha, float z);
92 
93  /// These methods record the textures to be drawn, and draws them all at
94  /// once when endTextureDefer() is called. If you need all cached textures
95  /// to be drawn immediately without doing an end, call flushTextureDefer().
96  void beginTextureDefer(RE_Render *r);
97  void endTextureDefer(RE_Render *r);
98  void flushTextureDefer(RE_Render *r);
99 
100  int64 getCacheSize() const { return myCacheSize; }
101 
102 private:
104  createTextureObject(RE_Render *r, PXL_Raster *image,
106  bool mipmap, bool autogen,
107  RE_TexFiltType min_filter,
109  RE_Texture *addTextureObject(UT_UniquePtr<RE_Texture> texture);
110 
111  /// An array of OpenGL texture IDs.
113 
114  /// Cache Version #; bumped at every cache clear.
115  int myVersion;
116  int64 myCacheSize;
117 
118  /// Data for the texture defer system, which batches icon rendering together
119  /// for improved GL performance.
120  UT_Array<re_DeferTexDraw> myDeferTexDraw;
121  UT_Array<int> myTextureDeferStart;
122 };
123 
124 /// Get the one and only texture cache.
126 
127 #endif
128 
GLenum clamp
Definition: glcorearb.h:1234
#define RE_API
Definition: RE_API.h:10
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
GLint y
Definition: glcorearb.h:103
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
RE_TexFiltType
int64 getCacheSize() const
RE_TexClampType
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
long long int64
Definition: SYS_Types.h:116
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
GLint GLenum GLint x
Definition: glcorearb.h:409
GLsizei levels
Definition: glcorearb.h:2224
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
SYS_DECLARE_IS_POD(re_DeferTexDraw)
re_DeferTexDraw(RE_Texture *tex, const UT_DimRect &clip, short x, short y, short w, short h, float alpha, float z)
GLuint texture
Definition: glcorearb.h:415
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GLboolean r
Definition: glcorearb.h:1222
RE_TextureCompress
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
Definition: ImathBoxAlgo.h:29
RE_API RE_IconTextureCache * REgetIconTextureCache()
Get the one and only texture cache.
int getTextureVersion() const