tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ImageIndex.h (4485B)


      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 
     29    TextureType getType() const { return mType; }
     30    GLint getLevelIndex() const { return mLevelIndex; }
     31    GLint getLayerIndex() const { return mLayerIndex; }
     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 MakeBuffer();
     49    static ImageIndex Make2D(GLint levelIndex);
     50    static ImageIndex MakeRectangle(GLint levelIndex);
     51    static ImageIndex MakeCubeMapFace(TextureTarget target, GLint levelIndex);
     52    static ImageIndex Make2DArray(GLint levelIndex, GLint layerIndex = kEntireLevel);
     53    static ImageIndex Make2DArrayRange(GLint levelIndex, GLint layerIndex, GLint layerCount);
     54    static ImageIndex Make3D(GLint levelIndex, GLint layerIndex = kEntireLevel);
     55    static ImageIndex MakeFromTarget(TextureTarget target, GLint levelIndex, GLint depth = 0);
     56    static ImageIndex MakeFromType(TextureType type,
     57                                   GLint levelIndex,
     58                                   GLint layerIndex = kEntireLevel,
     59                                   GLint layerCount = 1);
     60    static ImageIndex Make2DMultisample();
     61    static ImageIndex Make2DMultisampleArray(GLint layerIndex = kEntireLevel);
     62    static ImageIndex Make2DMultisampleArrayRange(GLint layerIndex, GLint layerCount);
     63 
     64    static constexpr GLint kEntireLevel = static_cast<GLint>(-1);
     65 
     66    bool operator<(const ImageIndex &b) const;
     67    bool operator==(const ImageIndex &b) const;
     68    bool operator!=(const ImageIndex &b) const;
     69 
     70    // Only valid for 3D/Cube textures with layers.
     71    ImageIndexIterator getLayerIterator(GLint layerCount) const;
     72 
     73  private:
     74    friend class ImageIndexIterator;
     75 
     76    ImageIndex(TextureType type, GLint leveIndex, GLint layerIndex, GLint layerCount);
     77 
     78    TextureType mType;
     79    GLint mLevelIndex;
     80    GLint mLayerIndex;
     81    GLint mLayerCount;
     82 };
     83 
     84 // To be used like this:
     85 //
     86 // ImageIndexIterator it = ...;
     87 // while (it.hasNext())
     88 // {
     89 //     ImageIndex current = it.next();
     90 // }
     91 class ImageIndexIterator
     92 {
     93  public:
     94    ImageIndexIterator(const ImageIndexIterator &other);
     95 
     96    static ImageIndexIterator MakeBuffer();
     97    static ImageIndexIterator Make2D(GLint minMip, GLint maxMip);
     98    static ImageIndexIterator MakeRectangle(GLint minMip, GLint maxMip);
     99    static ImageIndexIterator MakeCube(GLint minMip, GLint maxMip);
    100    static ImageIndexIterator Make3D(GLint minMip, GLint maxMip, GLint minLayer, GLint maxLayer);
    101    static ImageIndexIterator Make2DArray(GLint minMip, GLint maxMip, const GLsizei *layerCounts);
    102    static ImageIndexIterator Make2DMultisample();
    103    static ImageIndexIterator Make2DMultisampleArray(const GLsizei *layerCounts);
    104    static ImageIndexIterator MakeGeneric(TextureType type,
    105                                          GLint minMip,
    106                                          GLint maxMip,
    107                                          GLint minLayer,
    108                                          GLint maxLayer);
    109 
    110    ImageIndex next();
    111    ImageIndex current() const;
    112    bool hasNext() const;
    113 
    114  private:
    115    ImageIndexIterator(TextureType type,
    116                       const Range<GLint> &mipRange,
    117                       const Range<GLint> &layerRange,
    118                       const GLsizei *layerCounts);
    119 
    120    GLint maxLayer() const;
    121 
    122    const Range<GLint> mMipRange;
    123    const Range<GLint> mLayerRange;
    124    const GLsizei *const mLayerCounts;
    125 
    126    ImageIndex mCurrentIndex;
    127 };
    128 
    129 TextureTarget TextureTypeToTarget(TextureType type, GLint layerIndex);
    130 
    131 }  // namespace gl
    132 
    133 #endif  // LIBANGLE_IMAGE_INDEX_H_