Home | History | Annotate | Download | only in renderer
      1 //
      2 // Copyright (c) 2002-2013 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 // TextureStorage.h: Defines the abstract rx::TextureStorageInterface class and its concrete derived
      8 // classes TextureStorageInterface2D and TextureStorageInterfaceCube, which act as the interface to the
      9 // GPU-side texture.
     10 
     11 #ifndef LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
     12 #define LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
     13 
     14 #include "common/debug.h"
     15 
     16 namespace rx
     17 {
     18 class Renderer;
     19 class SwapChain;
     20 class RenderTarget;
     21 
     22 class TextureStorage
     23 {
     24   public:
     25     TextureStorage() {};
     26     virtual ~TextureStorage() {};
     27 
     28     virtual int getTopLevel() const = 0;
     29     virtual bool isRenderTarget() const = 0;
     30     virtual bool isManaged() const = 0;
     31     virtual int getLevelCount() const = 0;
     32 
     33     virtual RenderTarget *getRenderTarget(int level) = 0;
     34     virtual RenderTarget *getRenderTargetFace(GLenum faceTarget, int level) = 0;
     35     virtual RenderTarget *getRenderTargetLayer(int mipLevel, int layer) = 0;
     36     virtual void generateMipmap(int level) = 0;
     37     virtual void generateMipmap(int face, int level) = 0;
     38 
     39   private:
     40     DISALLOW_COPY_AND_ASSIGN(TextureStorage);
     41 
     42 };
     43 
     44 class TextureStorageInterface
     45 {
     46   public:
     47     TextureStorageInterface();
     48     virtual ~TextureStorageInterface();
     49 
     50     TextureStorage *getStorageInstance() { return mInstance; }
     51 
     52     unsigned int getTextureSerial() const;
     53 
     54     virtual int getTopLevel() const;
     55     virtual bool isRenderTarget() const;
     56     virtual bool isManaged() const;
     57     virtual int getLevelCount() const;
     58 
     59   protected:
     60     TextureStorage *mInstance;
     61 
     62   private:
     63     DISALLOW_COPY_AND_ASSIGN(TextureStorageInterface);
     64 
     65     const unsigned int mTextureSerial;
     66     static unsigned int issueTextureSerial();
     67 
     68     static unsigned int mCurrentTextureSerial;
     69 };
     70 
     71 class TextureStorageInterface2D : public TextureStorageInterface
     72 {
     73   public:
     74     TextureStorageInterface2D(Renderer *renderer, SwapChain *swapchain);
     75     TextureStorageInterface2D(Renderer *renderer, GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels);
     76     virtual ~TextureStorageInterface2D();
     77 
     78     void generateMipmap(int level);
     79     RenderTarget *getRenderTarget(GLint level) const;
     80 
     81     unsigned int getRenderTargetSerial(GLint level) const;
     82 
     83   private:
     84     DISALLOW_COPY_AND_ASSIGN(TextureStorageInterface2D);
     85 
     86     unsigned int mFirstRenderTargetSerial;
     87 };
     88 
     89 class TextureStorageInterfaceCube : public TextureStorageInterface
     90 {
     91   public:
     92     TextureStorageInterfaceCube(Renderer *renderer, GLenum internalformat, bool renderTarget, int size, int levels);
     93     virtual ~TextureStorageInterfaceCube();
     94 
     95     void generateMipmap(int faceIndex, int level);
     96     RenderTarget *getRenderTarget(GLenum faceTarget, GLint level) const;
     97 
     98     virtual unsigned int getRenderTargetSerial(GLenum target, GLint level) const;
     99 
    100   private:
    101     DISALLOW_COPY_AND_ASSIGN(TextureStorageInterfaceCube);
    102 
    103     unsigned int mFirstRenderTargetSerial;
    104 };
    105 
    106 class TextureStorageInterface3D : public TextureStorageInterface
    107 {
    108   public:
    109     TextureStorageInterface3D(Renderer *renderer, GLenum internalformat, bool renderTarget,
    110                               GLsizei width, GLsizei height, GLsizei depth, int levels);
    111     virtual ~TextureStorageInterface3D();
    112 
    113     void generateMipmap(int level);
    114     RenderTarget *getRenderTarget(GLint level) const;
    115     RenderTarget *getRenderTarget(GLint level, GLint layer) const;
    116 
    117     virtual unsigned int getRenderTargetSerial(GLint level, GLint layer) const;
    118 
    119   private:
    120     DISALLOW_COPY_AND_ASSIGN(TextureStorageInterface3D);
    121 
    122     unsigned int mFirstRenderTargetSerial;
    123 };
    124 
    125 class TextureStorageInterface2DArray : public TextureStorageInterface
    126 {
    127   public:
    128     TextureStorageInterface2DArray(Renderer *renderer, GLenum internalformat, bool renderTarget,
    129                                    GLsizei width, GLsizei height, GLsizei depth, int levels);
    130     virtual ~TextureStorageInterface2DArray();
    131 
    132     void generateMipmap(int level);
    133     RenderTarget *getRenderTarget(GLint level, GLint layer) const;
    134 
    135     virtual unsigned int getRenderTargetSerial(GLint level, GLint layer) const;
    136 
    137   private:
    138     DISALLOW_COPY_AND_ASSIGN(TextureStorageInterface2DArray);
    139 
    140     unsigned int mFirstRenderTargetSerial;
    141 };
    142 
    143 }
    144 
    145 #endif // LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
    146