GteTexture.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Graphics/GteDataFormat.h>
11 #include <Graphics/GteResource.h>
12 #include <array>
13 #include <functional>
14 #include <vector>
15 
16 namespace gte
17 {
18 
19 class GTE_IMPEXP Texture : public Resource
20 {
21 protected:
22  // Abstract base class. All items in the array have the same format,
23  // number of dimensions, dimension values, and mipmap status.
24  Texture(unsigned int numItems, DFType format, unsigned int numDimensions,
25  unsigned int dim0, unsigned int dim1, unsigned int dim2,
26  bool hasMipmaps, bool createStorage);
27 
28 public:
29  // Member access.
30  inline unsigned int GetNumItems() const;
31  inline DFType GetFormat() const;
32  inline unsigned int GetNumDimensions() const;
33  inline unsigned int GetDimension(int i) const;
34 
35  // Subresource information.
36  struct Subresource
37  {
38  unsigned int item;
39  unsigned int level;
40  char* data;
41  unsigned int rowPitch;
42  unsigned int slicePitch;
43  };
44 
45  // Mipmap information.
46  enum { MAX_MIPMAP_LEVELS = 16 };
47  inline bool HasMipmaps() const;
48  inline unsigned int GetNumLevels() const;
49  inline unsigned int GetDimensionFor(unsigned int level, int i) const;
50  inline unsigned int GetNumElementsFor(unsigned int level) const;
51  inline unsigned int GetNumBytesFor(unsigned int level) const;
52  inline unsigned int GetOffsetFor(unsigned int item,
53  unsigned int level) const;
54  inline char const* GetDataFor(unsigned int item,
55  unsigned int level) const;
56  inline char* GetDataFor(unsigned int item, unsigned int level);
57  template <typename T> inline T const* GetFor(unsigned int item,
58  unsigned int level) const;
59  template <typename T> inline T* GetFor(unsigned int item,
60  unsigned int level);
61 
62  // Subresource indexing: index = numLevels*item + level
63  inline unsigned int GetNumSubresources() const;
64  unsigned int GetIndex(unsigned int item, unsigned int level) const;
65  Subresource GetSubresource(unsigned int index) const;
66 
67  // Request that the GPU compute mipmap levels when the base-level texture
68  // data is modified. The AutogenerateMipmaps call should be made before
69  // binding the texture to the engine. If the texture does not have mipmaps,
70  // the AutogenerateMipmaps call will not set mAutogenerateMipmaps to true.
71  void AutogenerateMipmaps();
72  inline bool WantAutogenerateMipmaps() const;
73 
74 protected:
75  // Support for computing the numElements parameter for the Resource
76  // constructor. This is necessary when mipmaps are requested.
77  static unsigned int GetTotalElements(unsigned int numItems,
78  unsigned int dim0, unsigned int dim1, unsigned int dim2,
79  bool hasMipmaps);
80 
81  unsigned int mNumItems;
82  DFType mFormat;
83  unsigned int mNumDimensions;
84  unsigned int mNumLevels;
85  std::array<std::array<unsigned int, 3>, MAX_MIPMAP_LEVELS> mLDimension;
86  std::array<unsigned int, MAX_MIPMAP_LEVELS> mLNumBytes;
87  std::vector<std::array<unsigned int, MAX_MIPMAP_LEVELS>> mLOffset;
90 };
91 
92 typedef std::function<void(std::shared_ptr<Texture> const&)> TextureUpdater;
93 typedef std::function<void(std::shared_ptr<Texture> const&, unsigned int)> TextureLevelUpdater;
94 
95 inline unsigned int Texture::GetNumItems() const
96 {
97  return mNumItems;
98 }
99 
100 inline DFType Texture::GetFormat() const
101 {
102  return mFormat;
103 }
104 
105 inline unsigned int Texture::GetNumDimensions() const
106 {
107  return mNumDimensions;
108 }
109 
110 inline unsigned int Texture::GetDimension(int i) const
111 {
112  return mLDimension[0][i];
113 }
114 
115 inline bool Texture::HasMipmaps() const
116 {
117  return mHasMipmaps;
118 }
119 
120 inline unsigned int Texture::GetNumLevels() const
121 {
122  return mNumLevels;
123 }
124 
125 inline unsigned int Texture::GetDimensionFor(unsigned int level, int i)
126 const
127 {
128  return mLDimension[level][i];
129 }
130 
131 inline unsigned int Texture::GetNumElementsFor(unsigned int level) const
132 {
133  return mLNumBytes[level] / mElementSize;
134 }
135 
136 inline unsigned int Texture::GetNumBytesFor(unsigned int level) const
137 {
138  return mLNumBytes[level];
139 }
140 
141 inline unsigned int Texture::GetOffsetFor(unsigned int item,
142  unsigned int level) const
143 {
144  return mLOffset[item][level];
145 }
146 
147 inline char const* Texture::GetDataFor(unsigned int item,
148  unsigned int level) const
149 {
150  return mData ? (mData + mLOffset[item][level]) : nullptr;
151 }
152 
153 inline char* Texture::GetDataFor(unsigned int item, unsigned int level)
154 {
155  return mData ? (mData + mLOffset[item][level]) : nullptr;
156 }
157 
158 template <typename T> inline T
159 const* Texture::GetFor(unsigned int item, unsigned int level) const
160 {
161  return reinterpret_cast<T const*>(GetDataFor(item, level));
162 }
163 
164 template <typename T> inline
165 T* Texture::GetFor(unsigned int item, unsigned int level)
166 {
167  return reinterpret_cast<T*>(GetDataFor(item, level));
168 }
169 
170 inline unsigned int Texture::GetNumSubresources() const
171 {
172  return mNumItems * mNumLevels;
173 }
174 
176 {
177  return mAutogenerateMipmaps;
178 }
179 
180 
181 }
std::array< unsigned int, MAX_MIPMAP_LEVELS > mLNumBytes
Definition: GteTexture.h:86
bool mHasMipmaps
Definition: GteTexture.h:88
std::function< void(std::shared_ptr< Texture > const &)> TextureUpdater
Definition: GteTexture.h:92
bool HasMipmaps() const
Definition: GteTexture.h:115
unsigned int mNumDimensions
Definition: GteTexture.h:83
bool mAutogenerateMipmaps
Definition: GteTexture.h:89
GLint level
Definition: glcorearb.h:103
std::vector< std::array< unsigned int, MAX_MIPMAP_LEVELS > > mLOffset
Definition: GteTexture.h:87
std::function< void(std::shared_ptr< Texture > const &, unsigned int)> TextureLevelUpdater
Definition: GteTexture.h:93
char const * GetDataFor(unsigned int item, unsigned int level) const
Definition: GteTexture.h:147
unsigned int GetNumDimensions() const
Definition: GteTexture.h:105
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
unsigned int GetNumBytesFor(unsigned int level) const
Definition: GteTexture.h:136
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:103
unsigned int GetDimensionFor(unsigned int level, int i) const
Definition: GteTexture.h:125
unsigned int GetNumItems() const
Definition: GteTexture.h:95
unsigned int GetNumLevels() const
Definition: GteTexture.h:120
unsigned int GetDimension(int i) const
Definition: GteTexture.h:110
unsigned int GetNumElementsFor(unsigned int level) const
Definition: GteTexture.h:131
DFType mFormat
Definition: GteTexture.h:82
unsigned int slicePitch
Definition: GteTexture.h:42
GLuint index
Definition: glcorearb.h:781
unsigned int mNumItems
Definition: GteTexture.h:81
bool WantAutogenerateMipmaps() const
Definition: GteTexture.h:175
T const * GetFor(unsigned int item, unsigned int level) const
Definition: GteTexture.h:159
unsigned int mNumLevels
Definition: GteTexture.h:84
unsigned int GetOffsetFor(unsigned int item, unsigned int level) const
Definition: GteTexture.h:141
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
unsigned int GetNumSubresources() const
Definition: GteTexture.h:170
DFType GetFormat() const
Definition: GteTexture.h:100
std::array< std::array< unsigned int, 3 >, MAX_MIPMAP_LEVELS > mLDimension
Definition: GteTexture.h:85


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01