Home | History | Annotate | Download | only in renderer
      1 //
      2 // Copyright (c) 2012 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 // TextureStorage11.h: Defines the abstract rx::TextureStorage11 class and its concrete derived
      8 // classes TextureStorage11_2D and TextureStorage11_Cube, which act as the interface to the D3D11 texture.
      9 
     10 #ifndef LIBGLESV2_RENDERER_TEXTURESTORAGE11_H_
     11 #define LIBGLESV2_RENDERER_TEXTURESTORAGE11_H_
     12 
     13 #include "libGLESv2/Texture.h"
     14 #include "libGLESv2/renderer/TextureStorage.h"
     15 
     16 namespace rx
     17 {
     18 class RenderTarget;
     19 class RenderTarget11;
     20 class Renderer;
     21 class Renderer11;
     22 class SwapChain11;
     23 
     24 class TextureStorage11 : public TextureStorage
     25 {
     26   public:
     27     TextureStorage11(Renderer *renderer, UINT bindFlags);
     28     virtual ~TextureStorage11();
     29 
     30     static TextureStorage11 *makeTextureStorage11(TextureStorage *storage);
     31 
     32     static DWORD GetTextureBindFlags(DXGI_FORMAT d3dfmt, GLenum glusage, bool forceRenderable);
     33     static bool IsTextureFormatRenderable(DXGI_FORMAT format);
     34 
     35     UINT getBindFlags() const;
     36 
     37     virtual ID3D11Texture2D *getBaseTexture() const;
     38     virtual ID3D11ShaderResourceView *getSRV() = 0;
     39     virtual RenderTarget *getRenderTarget() { return getRenderTarget(0); }
     40     virtual RenderTarget *getRenderTarget(int level) { return NULL; }
     41     virtual RenderTarget *getRenderTarget(GLenum faceTarget) { return getRenderTarget(faceTarget, 0); }
     42     virtual RenderTarget *getRenderTarget(GLenum faceTarget, int level) { return NULL; }
     43 
     44     virtual void generateMipmap(int level) {};
     45     virtual void generateMipmap(int face, int level) {};
     46 
     47     virtual int getLodOffset() const;
     48     virtual bool isRenderTarget() const;
     49     virtual bool isManaged() const;
     50     virtual int levelCount();
     51     UINT getSubresourceIndex(int level, int faceTarget);
     52 
     53     bool updateSubresourceLevel(ID3D11Texture2D *texture, unsigned int sourceSubresource, int level,
     54                                 int faceTarget, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
     55 
     56   protected:
     57     void generateMipmapLayer(RenderTarget11 *source, RenderTarget11 *dest);
     58 
     59     Renderer11 *mRenderer;
     60     int mLodOffset;
     61     unsigned int mMipLevels;
     62 
     63     ID3D11Texture2D *mTexture;
     64     DXGI_FORMAT mTextureFormat;
     65     DXGI_FORMAT mShaderResourceFormat;
     66     DXGI_FORMAT mRenderTargetFormat;
     67     DXGI_FORMAT mDepthStencilFormat;
     68     unsigned int mTextureWidth;
     69     unsigned int mTextureHeight;
     70 
     71     ID3D11ShaderResourceView *mSRV;
     72 
     73   private:
     74     DISALLOW_COPY_AND_ASSIGN(TextureStorage11);
     75 
     76     const UINT mBindFlags;
     77 };
     78 
     79 class TextureStorage11_2D : public TextureStorage11
     80 {
     81   public:
     82     TextureStorage11_2D(Renderer *renderer, SwapChain11 *swapchain);
     83     TextureStorage11_2D(Renderer *renderer, int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height);
     84     virtual ~TextureStorage11_2D();
     85 
     86     static TextureStorage11_2D *makeTextureStorage11_2D(TextureStorage *storage);
     87 
     88     virtual ID3D11ShaderResourceView *getSRV();
     89     virtual RenderTarget *getRenderTarget(int level);
     90 
     91     virtual void generateMipmap(int level);
     92 
     93   private:
     94     DISALLOW_COPY_AND_ASSIGN(TextureStorage11_2D);
     95 
     96     RenderTarget11 *mRenderTarget[gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
     97 };
     98 
     99 class TextureStorage11_Cube : public TextureStorage11
    100 {
    101   public:
    102     TextureStorage11_Cube(Renderer *renderer, int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size);
    103     virtual ~TextureStorage11_Cube();
    104 
    105     static TextureStorage11_Cube *makeTextureStorage11_Cube(TextureStorage *storage);
    106 
    107     virtual ID3D11ShaderResourceView *getSRV();
    108     virtual RenderTarget *getRenderTarget(GLenum faceTarget, int level);
    109 
    110     virtual void generateMipmap(int face, int level);
    111 
    112   private:
    113     DISALLOW_COPY_AND_ASSIGN(TextureStorage11_Cube);
    114 
    115     RenderTarget11 *mRenderTarget[6][gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
    116 };
    117 
    118 }
    119 
    120 #endif // LIBGLESV2_RENDERER_TEXTURESTORAGE11_H_
    121