Commit 710e5775 by Jamie Madill

Make commitRegion a base method of TextureD3D.

Use a helper method isValidIndex to preserve ASSERT checks. Refactoring patch only. BUG=angle:741 Change-Id: Ie19fa21db51cd0239a3b391de362584a9fbab2df Reviewed-on: https://chromium-review.googlesource.com/222268Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent e76bdda2
......@@ -438,6 +438,25 @@ bool TextureD3D::canCreateRenderTargetForImage(const gl::ImageIndex &index) cons
return (image->isRenderableFormat() && levelsComplete);
}
gl::Error TextureD3D::commitRegion(const gl::ImageIndex &index, const gl::Box &region)
{
if (mTexStorage)
{
ASSERT(isValidIndex(index));
Image *image = getImage(index);
ImageD3D *imageD3D = ImageD3D::makeImageD3D(image);
gl::Error error = imageD3D->copyToStorage(mTexStorage, index, region);
if (error.isError())
{
return error;
}
image->markClean();
}
return gl::Error(GL_NO_ERROR);
}
TextureD3D_2D::TextureD3D_2D(Renderer *renderer)
: TextureD3D(renderer)
{
......@@ -1034,26 +1053,6 @@ void TextureD3D_2D::redefineImage(GLint level, GLenum internalformat, GLsizei wi
}
}
gl::Error TextureD3D_2D::commitRegion(const gl::ImageIndex &index, const gl::Box &region)
{
ASSERT(!index.hasLayer());
GLint level = index.mipIndex;
if (isValidLevel(level))
{
ImageD3D *image = mImageArray[level];
gl::Error error = image->copyToStorage(mTexStorage, index, region);
if (error.isError())
{
return error;
}
image->markClean();
}
return gl::Error(GL_NO_ERROR);
}
gl::ImageIndexIterator TextureD3D_2D::imageIterator() const
{
return gl::ImageIndexIterator::Make2D(0, mTexStorage->getLevelCount());
......@@ -1065,6 +1064,12 @@ gl::ImageIndex TextureD3D_2D::getImageIndex(GLint mip, GLint /*layer*/) const
return gl::ImageIndex::Make2D(mip);
}
bool TextureD3D_2D::isValidIndex(const gl::ImageIndex &index) const
{
return (mTexStorage && index.type == GL_TEXTURE_2D &&
index.mipIndex >= 0 && index.mipIndex < mTexStorage->getLevelCount());
}
TextureD3D_Cube::TextureD3D_Cube(Renderer *renderer)
: TextureD3D(renderer)
{
......@@ -1594,28 +1599,6 @@ void TextureD3D_Cube::redefineImage(int faceIndex, GLint level, GLenum internalf
}
}
gl::Error TextureD3D_Cube::commitRegion(const gl::ImageIndex &index, const gl::Box &region)
{
ASSERT(index.hasLayer());
GLint level = index.mipIndex;
int faceIndex = static_cast<int>(index.layerIndex);
if (isValidFaceLevel(faceIndex, level))
{
ImageD3D *image = mImageArray[faceIndex][level];
gl::Error error = image->copyToStorage(mTexStorage, index, region);
if (error.isError())
{
return error;
}
image->markClean();
}
return gl::Error(GL_NO_ERROR);
}
gl::ImageIndexIterator TextureD3D_Cube::imageIterator() const
{
return gl::ImageIndexIterator::MakeCube(0, mTexStorage->getLevelCount());
......@@ -1627,6 +1610,12 @@ gl::ImageIndex TextureD3D_Cube::getImageIndex(GLint mip, GLint layer) const
return gl::ImageIndex::MakeCube(gl::TextureCubeMap::layerIndexToTarget(layer), mip);
}
bool TextureD3D_Cube::isValidIndex(const gl::ImageIndex &index) const
{
return (mTexStorage && gl::IsCubemapTextureTarget(index.type) &&
index.mipIndex >= 0 && index.mipIndex < mTexStorage->getLevelCount());
}
TextureD3D_3D::TextureD3D_3D(Renderer *renderer)
: TextureD3D(renderer)
{
......@@ -2173,26 +2162,6 @@ void TextureD3D_3D::redefineImage(GLint level, GLenum internalformat, GLsizei wi
}
}
gl::Error TextureD3D_3D::commitRegion(const gl::ImageIndex &index, const gl::Box &region)
{
ASSERT(!index.hasLayer());
GLint level = index.mipIndex;
if (isValidLevel(level))
{
ImageD3D *image = mImageArray[level];
gl::Error error = image->copyToStorage(mTexStorage, index, region);
if (error.isError())
{
return error;
}
image->markClean();
}
return gl::Error(GL_NO_ERROR);
}
gl::ImageIndexIterator TextureD3D_3D::imageIterator() const
{
return gl::ImageIndexIterator::Make3D(0, mTexStorage->getLevelCount(),
......@@ -2205,6 +2174,12 @@ gl::ImageIndex TextureD3D_3D::getImageIndex(GLint mip, GLint /*layer*/) const
return gl::ImageIndex::Make3D(mip);
}
bool TextureD3D_3D::isValidIndex(const gl::ImageIndex &index) const
{
return (mTexStorage && index.type == GL_TEXTURE_3D &&
index.mipIndex >= 0 && index.mipIndex < mTexStorage->getLevelCount());
}
TextureD3D_2DArray::TextureD3D_2DArray(Renderer *renderer)
: TextureD3D(renderer)
{
......@@ -2753,27 +2728,6 @@ void TextureD3D_2DArray::redefineImage(GLint level, GLenum internalformat, GLsiz
}
}
gl::Error TextureD3D_2DArray::commitRegion(const gl::ImageIndex &index, const gl::Box &region)
{
ASSERT(index.hasLayer());
GLint level = index.mipIndex;
GLint layerTarget = index.layerIndex;
if (isValidLevel(level) && layerTarget < getLayerCount(level))
{
ImageD3D *image = mImageArray[level][layerTarget];
gl::Error error = image->copyToStorage(mTexStorage, index, region);
if (error.isError())
{
return error;
}
image->markClean();
}
return gl::Error(GL_NO_ERROR);
}
gl::ImageIndexIterator TextureD3D_2DArray::imageIterator() const
{
return gl::ImageIndexIterator::Make2DArray(0, mTexStorage->getLevelCount(), mLayerCounts);
......@@ -2784,4 +2738,22 @@ gl::ImageIndex TextureD3D_2DArray::getImageIndex(GLint mip, GLint layer) const
return gl::ImageIndex::Make2DArray(mip, layer);
}
bool TextureD3D_2DArray::isValidIndex(const gl::ImageIndex &index) const
{
// Check for having a storage and the right type of index
if (!mTexStorage || index.type != GL_TEXTURE_2D_ARRAY)
{
return false;
}
// Check the mip index
if (index.mipIndex < 0 || index.mipIndex >= mTexStorage->getLevelCount())
{
return false;
}
// Check the layer index
return (!index.hasLayer() || (index.layerIndex >= 0 && index.layerIndex < mLayerCounts[index.mipIndex]));
}
}
......@@ -57,6 +57,7 @@ class TextureD3D : public TextureImpl
// Returns an ImageIndex for a particular "Image". 3D Textures do not have images for
// slices of their depth texures, so 3D textures ignore the layer parameter.
virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const = 0;
virtual bool isValidIndex(const gl::ImageIndex &index) const = 0;
virtual void generateMipmaps();
TextureStorage *getStorage();
......@@ -84,7 +85,7 @@ class TextureD3D : public TextureImpl
virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const = 0;
virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage) = 0;
virtual gl::Error commitRegion(const gl::ImageIndex &index, const gl::Box &region) = 0;
gl::Error commitRegion(const gl::ImageIndex &index, const gl::Box &region);
Renderer *mRenderer;
......@@ -137,14 +138,14 @@ class TextureD3D_2D : public TextureD3D
virtual gl::ImageIndexIterator imageIterator() const;
virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const;
virtual bool isValidIndex(const gl::ImageIndex &index) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D_2D);
virtual gl::Error initializeStorage(bool renderTarget);
gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const;
gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
gl::Error commitRegion(const gl::ImageIndex &index, const gl::Box &region);
virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const;
virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
virtual gl::Error updateStorage();
virtual void initMipmapsImages();
......@@ -193,14 +194,14 @@ class TextureD3D_Cube : public TextureD3D
virtual gl::ImageIndexIterator imageIterator() const;
virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const;
virtual bool isValidIndex(const gl::ImageIndex &index) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D_Cube);
virtual gl::Error initializeStorage(bool renderTarget);
gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const;
gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
virtual gl::Error commitRegion(const gl::ImageIndex &index, const gl::Box &region);
virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const;
virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
virtual gl::Error updateStorage();
virtual void initMipmapsImages();
......@@ -248,14 +249,14 @@ class TextureD3D_3D : public TextureD3D
virtual gl::ImageIndexIterator imageIterator() const;
virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const;
virtual bool isValidIndex(const gl::ImageIndex &index) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D_3D);
virtual gl::Error initializeStorage(bool renderTarget);
gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outStorage) const;
gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
virtual gl::Error commitRegion(const gl::ImageIndex &index, const gl::Box &region);
virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outStorage) const;
virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
virtual gl::Error updateStorage();
virtual void initMipmapsImages();
......@@ -301,14 +302,14 @@ class TextureD3D_2DArray : public TextureD3D
virtual gl::ImageIndexIterator imageIterator() const;
virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const;
virtual bool isValidIndex(const gl::ImageIndex &index) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D_2DArray);
virtual gl::Error initializeStorage(bool renderTarget);
gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outStorage) const;
gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
virtual gl::Error commitRegion(const gl::ImageIndex &index, const gl::Box &region);
virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outStorage) const;
virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
virtual gl::Error updateStorage();
virtual void initMipmapsImages();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment