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