Hash :
74ba598f
Author :
Date :
2018-03-13T11:22:16
Fix cubemap robust resource init for GenerateMipmap The code in gl::Texture would only check whether the first cube map face is correctly initialized but not for the others. BUG=angleproject:2169 Change-Id: Ib565579a4570e731da785b5c74c8d1a6511ebcd4 Reviewed-on: https://chromium-review.googlesource.com/960571 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
#include "ImageIndex.h"
//
// Copyright 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ImageIndex.cpp: Implementation for ImageIndex methods.
#include "libANGLE/ImageIndex.h"
#include "libANGLE/Constants.h"
#include "common/utilities.h"
#include <tuple>
namespace gl
{
ImageIndex::ImageIndex(const ImageIndex &other) = default;
ImageIndex &ImageIndex::operator=(const ImageIndex &other) = default;
bool ImageIndex::is3D() const
{
return type == TextureType::_3D || type == TextureType::_2DArray;
}
GLint ImageIndex::cubeMapFaceIndex() const
{
ASSERT(type == TextureType::CubeMap);
ASSERT(TextureTargetToType(target) == TextureType::CubeMap);
return static_cast<GLint>(CubeMapTextureTargetToFaceIndex(target));
}
bool ImageIndex::valid() const
{
return type != TextureType::InvalidEnum;
}
ImageIndex ImageIndex::Make2D(GLint mipIndex)
{
return ImageIndex(TextureType::_2D, TextureTarget::_2D, mipIndex, ENTIRE_LEVEL, 1);
}
ImageIndex ImageIndex::MakeRectangle(GLint mipIndex)
{
return ImageIndex(TextureType::Rectangle, TextureTarget::Rectangle, mipIndex, ENTIRE_LEVEL, 1);
}
ImageIndex ImageIndex::MakeCube(TextureTarget target, GLint mipIndex)
{
ASSERT(TextureTargetToType(target) == TextureType::CubeMap);
return ImageIndex(TextureType::CubeMap, target, mipIndex, ENTIRE_LEVEL, 1);
}
ImageIndex ImageIndex::Make2DArray(GLint mipIndex, GLint layerIndex)
{
return ImageIndex(TextureType::_2DArray, TextureTarget::_2DArray, mipIndex, layerIndex, 1);
}
ImageIndex ImageIndex::Make2DArrayRange(GLint mipIndex, GLint layerIndex, GLint numLayers)
{
return ImageIndex(TextureType::_2DArray, TextureTarget::_2DArray, mipIndex, layerIndex,
numLayers);
}
ImageIndex ImageIndex::Make3D(GLint mipIndex, GLint layerIndex)
{
return ImageIndex(TextureType::_3D, TextureTarget::_3D, mipIndex, layerIndex, 1);
}
ImageIndex ImageIndex::MakeGeneric(TextureTarget target, GLint mipIndex)
{
return ImageIndex(TextureTargetToType(target), target, mipIndex, ENTIRE_LEVEL, 1);
}
ImageIndex ImageIndex::Make2DMultisample()
{
return ImageIndex(TextureType::_2DMultisample, TextureTarget::_2DMultisample, 0, ENTIRE_LEVEL,
1);
}
ImageIndex ImageIndex::MakeInvalid()
{
return ImageIndex(TextureType::InvalidEnum, TextureTarget::InvalidEnum, -1, -1, -1);
}
bool operator<(const ImageIndex &a, const ImageIndex &b)
{
return std::tie(a.type, a.target, a.mipIndex, a.layerIndex, a.numLayers) <
std::tie(b.type, b.target, b.mipIndex, b.layerIndex, b.numLayers);
}
bool operator==(const ImageIndex &a, const ImageIndex &b)
{
return std::tie(a.type, a.target, a.mipIndex, a.layerIndex, a.numLayers) ==
std::tie(b.type, b.target, b.mipIndex, b.layerIndex, b.numLayers);
}
bool operator!=(const ImageIndex &a, const ImageIndex &b)
{
return !(a == b);
}
ImageIndex::ImageIndex(TextureType typeIn,
TextureTarget targetIn,
GLint mipIndexIn,
GLint layerIndexIn,
GLint numLayersIn)
: type(typeIn),
target(targetIn),
mipIndex(mipIndexIn),
layerIndex(layerIndexIn),
numLayers(numLayersIn)
{}
ImageIndexIterator::ImageIndexIterator(const ImageIndexIterator &other) = default;
ImageIndexIterator ImageIndexIterator::Make2D(GLint minMip, GLint maxMip)
{
return ImageIndexIterator(
TextureType::_2D, TextureTarget::_2D, TextureTarget::_2D, Range<GLint>(minMip, maxMip),
Range<GLint>(ImageIndex::ENTIRE_LEVEL, ImageIndex::ENTIRE_LEVEL), nullptr);
}
ImageIndexIterator ImageIndexIterator::MakeRectangle(GLint minMip, GLint maxMip)
{
return ImageIndexIterator(TextureType::Rectangle, TextureTarget::Rectangle,
TextureTarget::Rectangle, Range<GLint>(minMip, maxMip),
Range<GLint>(ImageIndex::ENTIRE_LEVEL, ImageIndex::ENTIRE_LEVEL),
nullptr);
}
ImageIndexIterator ImageIndexIterator::MakeCube(GLint minMip, GLint maxMip)
{
return ImageIndexIterator(TextureType::CubeMap, kFirstCubeMapTextureTarget,
kLastCubeMapTextureTarget, Range<GLint>(minMip, maxMip),
Range<GLint>(ImageIndex::ENTIRE_LEVEL, ImageIndex::ENTIRE_LEVEL),
nullptr);
}
ImageIndexIterator ImageIndexIterator::Make3D(GLint minMip, GLint maxMip,
GLint minLayer, GLint maxLayer)
{
return ImageIndexIterator(TextureType::_3D, TextureTarget::_3D, TextureTarget::_3D,
Range<GLint>(minMip, maxMip), Range<GLint>(minLayer, maxLayer),
nullptr);
}
ImageIndexIterator ImageIndexIterator::Make2DArray(GLint minMip, GLint maxMip,
const GLsizei *layerCounts)
{
return ImageIndexIterator(TextureType::_2DArray, TextureTarget::_2DArray,
TextureTarget::_2DArray, Range<GLint>(minMip, maxMip),
Range<GLint>(0, IMPLEMENTATION_MAX_2D_ARRAY_TEXTURE_LAYERS),
layerCounts);
}
ImageIndexIterator ImageIndexIterator::Make2DMultisample()
{
return ImageIndexIterator(TextureType::_2DMultisample, TextureTarget::_2DMultisample,
TextureTarget::_2DMultisample, Range<GLint>(0, 0),
Range<GLint>(ImageIndex::ENTIRE_LEVEL, ImageIndex::ENTIRE_LEVEL),
nullptr);
}
ImageIndexIterator ImageIndexIterator::MakeGeneric(TextureType type, GLint minMip, GLint maxMip)
{
if (type == TextureType::CubeMap)
{
return MakeCube(minMip, maxMip);
}
TextureTarget target = NonCubeTextureTypeToTarget(type);
return ImageIndexIterator(type, target, target, Range<GLint>(minMip, maxMip),
Range<GLint>(ImageIndex::ENTIRE_LEVEL, ImageIndex::ENTIRE_LEVEL),
nullptr);
}
ImageIndexIterator::ImageIndexIterator(TextureType type,
angle::EnumIterator<TextureTarget> targetLow,
angle::EnumIterator<TextureTarget> targetHigh,
const Range<GLint> &mipRange,
const Range<GLint> &layerRange,
const GLsizei *layerCounts)
: mTargetLow(targetLow),
mTargetHigh(targetHigh),
mMipRange(mipRange),
mLayerRange(layerRange),
mLayerCounts(layerCounts),
mCurrentIndex(type, *targetLow, mipRange.low(), layerRange.low(), 1)
{}
GLint ImageIndexIterator::maxLayer() const
{
if (mLayerCounts)
{
ASSERT(mCurrentIndex.hasLayer());
return (mCurrentIndex.mipIndex < mMipRange.high()) ? mLayerCounts[mCurrentIndex.mipIndex]
: 0;
}
return mLayerRange.high();
}
ImageIndex ImageIndexIterator::next()
{
ASSERT(hasNext());
// Make a copy of the current index to return
ImageIndex previousIndex = mCurrentIndex;
// Iterate layers in the inner loop for now. We can add switchable
// layer or mip iteration if we need it.
angle::EnumIterator<TextureTarget> currentTarget = mCurrentIndex.target;
if (currentTarget != mTargetHigh)
{
++currentTarget;
mCurrentIndex.target = *currentTarget;
}
else if (mCurrentIndex.hasLayer() && mCurrentIndex.layerIndex < maxLayer() - 1)
{
mCurrentIndex.target = *mTargetLow;
mCurrentIndex.layerIndex++;
}
else if (mCurrentIndex.mipIndex < mMipRange.high() - 1)
{
mCurrentIndex.target = *mTargetLow;
mCurrentIndex.layerIndex = mLayerRange.low();
mCurrentIndex.mipIndex++;
}
else
{
mCurrentIndex = ImageIndex::MakeInvalid();
}
return previousIndex;
}
ImageIndex ImageIndexIterator::current() const
{
return mCurrentIndex;
}
bool ImageIndexIterator::hasNext() const
{
return mCurrentIndex.valid();
}
} // namespace gl