1 // 2 // Copyright 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // ImageIndex.h: A helper struct for indexing into an Image array 8 9 #ifndef LIBANGLE_IMAGE_INDEX_H_ 10 #define LIBANGLE_IMAGE_INDEX_H_ 11 12 #include "common/PackedEnums.h" 13 #include "common/mathutil.h" 14 15 #include "angle_gl.h" 16 17 namespace gl 18 { 19 20 class ImageIndexIterator; 21 22 class ImageIndex 23 { 24 public: 25 ImageIndex(); 26 ImageIndex(const ImageIndex &other); 27 ImageIndex &operator=(const ImageIndex &other); 28 getType()29 TextureType getType() const { return mType; } getLevelIndex()30 GLint getLevelIndex() const { return mLevelIndex; } getLayerIndex()31 GLint getLayerIndex() const { return mLayerIndex; } getLayerCount()32 GLint getLayerCount() const { return mLayerCount; } 33 34 bool hasLayer() const; 35 bool has3DLayer() const; 36 bool usesTex3D() const; 37 GLint cubeMapFaceIndex() const; 38 bool valid() const; 39 // Note that you cannot use this function when the ImageIndex represents an entire level of cube 40 // map. 41 TextureTarget getTarget() const; 42 43 TextureTarget getTargetOrFirstCubeFace() const; 44 45 bool isLayered() const; 46 bool isEntireLevelCubeMap() const; 47 48 static ImageIndex Make2D(GLint levelIndex); 49 static ImageIndex MakeRectangle(GLint levelIndex); 50 static ImageIndex MakeCubeMapFace(TextureTarget target, GLint levelIndex); 51 static ImageIndex Make2DArray(GLint levelIndex, GLint layerIndex = kEntireLevel); 52 static ImageIndex Make2DArrayRange(GLint levelIndex, GLint layerIndex, GLint layerCount); 53 static ImageIndex Make3D(GLint levelIndex, GLint layerIndex = kEntireLevel); 54 static ImageIndex MakeFromTarget(TextureTarget target, GLint levelIndex, GLint depth = 0); 55 static ImageIndex MakeFromType(TextureType type, 56 GLint levelIndex, 57 GLint layerIndex = kEntireLevel, 58 GLint layerCount = 1); 59 static ImageIndex Make2DMultisample(); 60 static ImageIndex Make2DMultisampleArray(GLint layerIndex = kEntireLevel); 61 static ImageIndex Make2DMultisampleArrayRange(GLint layerIndex, GLint layerCount); 62 63 static constexpr GLint kEntireLevel = static_cast<GLint>(-1); 64 65 bool operator<(const ImageIndex &b) const; 66 bool operator==(const ImageIndex &b) const; 67 bool operator!=(const ImageIndex &b) const; 68 69 // Only valid for 3D/Cube textures with layers. 70 ImageIndexIterator getLayerIterator(GLint layerCount) const; 71 72 private: 73 friend class ImageIndexIterator; 74 75 ImageIndex(TextureType type, GLint leveIndex, GLint layerIndex, GLint layerCount); 76 77 TextureType mType; 78 GLint mLevelIndex; 79 GLint mLayerIndex; 80 GLint mLayerCount; 81 }; 82 83 // To be used like this: 84 // 85 // ImageIndexIterator it = ...; 86 // while (it.hasNext()) 87 // { 88 // ImageIndex current = it.next(); 89 // } 90 class ImageIndexIterator 91 { 92 public: 93 ImageIndexIterator(const ImageIndexIterator &other); 94 95 static ImageIndexIterator Make2D(GLint minMip, GLint maxMip); 96 static ImageIndexIterator MakeRectangle(GLint minMip, GLint maxMip); 97 static ImageIndexIterator MakeCube(GLint minMip, GLint maxMip); 98 static ImageIndexIterator Make3D(GLint minMip, GLint maxMip, GLint minLayer, GLint maxLayer); 99 static ImageIndexIterator Make2DArray(GLint minMip, GLint maxMip, const GLsizei *layerCounts); 100 static ImageIndexIterator Make2DMultisample(); 101 static ImageIndexIterator Make2DMultisampleArray(const GLsizei *layerCounts); 102 static ImageIndexIterator MakeGeneric(TextureType type, 103 GLint minMip, 104 GLint maxMip, 105 GLint minLayer, 106 GLint maxLayer); 107 108 ImageIndex next(); 109 ImageIndex current() const; 110 bool hasNext() const; 111 112 private: 113 ImageIndexIterator(TextureType type, 114 const Range<GLint> &mipRange, 115 const Range<GLint> &layerRange, 116 const GLsizei *layerCounts); 117 118 GLint maxLayer() const; 119 120 const Range<GLint> mMipRange; 121 const Range<GLint> mLayerRange; 122 const GLsizei *const mLayerCounts; 123 124 ImageIndex mCurrentIndex; 125 }; 126 127 TextureTarget TextureTypeToTarget(TextureType type, GLint layerIndex); 128 129 } // namespace gl 130 131 #endif // LIBANGLE_IMAGE_INDEX_H_ 132