Home | History | Annotate | Download | only in libGLESv2
      1 //
      2 // Copyright (c) 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 // FramebufferAttachment.h: Defines the wrapper class gl::FramebufferAttachment, as well as the
      8 // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108.
      9 
     10 #ifndef LIBGLESV2_FRAMEBUFFERATTACHMENT_H_
     11 #define LIBGLESV2_FRAMEBUFFERATTACHMENT_H_
     12 
     13 #include <GLES3/gl3.h>
     14 #include <GLES2/gl2.h>
     15 
     16 #include "common/angleutils.h"
     17 #include "common/RefCountObject.h"
     18 
     19 namespace rx
     20 {
     21 class Renderer;
     22 class RenderTarget;
     23 class TextureStorage;
     24 }
     25 
     26 namespace gl
     27 {
     28 class Texture2D;
     29 class TextureCubeMap;
     30 class Texture3D;
     31 class Texture2DArray;
     32 class FramebufferAttachment;
     33 class FramebufferAttachmentInterface;
     34 class RenderbufferStorage;
     35 
     36 // FramebufferAttachment implements the GL renderbuffer object.
     37 // It's only a proxy for a FramebufferAttachmentInterface instance; the internal object
     38 // can change whenever glRenderbufferStorage is called.
     39 class FramebufferAttachment : public RefCountObject
     40 {
     41   public:
     42     FramebufferAttachment(rx::Renderer *renderer, GLuint id, FramebufferAttachmentInterface *storage);
     43 
     44     virtual ~FramebufferAttachment();
     45 
     46     // These functions from RefCountObject are overloaded here because
     47     // Textures need to maintain their own count of references to them via
     48     // Renderbuffers/RenderbufferTextures. These functions invoke those
     49     // reference counting functions on the FramebufferAttachmentInterface.
     50     void addRef() const;
     51     void release() const;
     52 
     53     rx::RenderTarget *getRenderTarget();
     54     rx::RenderTarget *getDepthStencil();
     55     rx::TextureStorage *getTextureStorage();
     56 
     57     GLsizei getWidth() const;
     58     GLsizei getHeight() const;
     59     GLenum getInternalFormat() const;
     60     GLenum getActualFormat() const;
     61     GLuint getRedSize() const;
     62     GLuint getGreenSize() const;
     63     GLuint getBlueSize() const;
     64     GLuint getAlphaSize() const;
     65     GLuint getDepthSize() const;
     66     GLuint getStencilSize() const;
     67     GLenum getComponentType() const;
     68     GLenum getColorEncoding() const;
     69     GLsizei getSamples() const;
     70 
     71     unsigned int getSerial() const;
     72 
     73     bool isTexture() const;
     74     unsigned int getTextureSerial() const;
     75 
     76     void setStorage(RenderbufferStorage *newStorage);
     77 
     78   private:
     79     DISALLOW_COPY_AND_ASSIGN(FramebufferAttachment);
     80 
     81     rx::Renderer const *mRenderer;
     82     FramebufferAttachmentInterface *mInstance;
     83 };
     84 
     85 class FramebufferAttachmentInterface
     86 {
     87   public:
     88     FramebufferAttachmentInterface();
     89 
     90     virtual ~FramebufferAttachmentInterface() {};
     91 
     92     virtual void addProxyRef(const FramebufferAttachment *proxy);
     93     virtual void releaseProxy(const FramebufferAttachment *proxy);
     94 
     95     virtual rx::RenderTarget *getRenderTarget() = 0;
     96     virtual rx::RenderTarget *getDepthStencil() = 0;
     97     virtual rx::TextureStorage *getTextureStorage() = 0;
     98 
     99     virtual GLsizei getWidth() const = 0;
    100     virtual GLsizei getHeight() const = 0;
    101     virtual GLenum getInternalFormat() const = 0;
    102     virtual GLenum getActualFormat() const = 0;
    103     virtual GLsizei getSamples() const = 0;
    104 
    105     virtual unsigned int getSerial() const = 0;
    106 
    107     virtual bool isTexture() const = 0;
    108     virtual unsigned int getTextureSerial() const = 0;
    109 
    110   private:
    111     DISALLOW_COPY_AND_ASSIGN(FramebufferAttachmentInterface);
    112 };
    113 
    114 class Texture2DAttachment : public FramebufferAttachmentInterface
    115 {
    116   public:
    117     Texture2DAttachment(Texture2D *texture, GLint level);
    118 
    119     virtual ~Texture2DAttachment();
    120 
    121     void addProxyRef(const FramebufferAttachment *proxy);
    122     void releaseProxy(const FramebufferAttachment *proxy);
    123 
    124     rx::RenderTarget *getRenderTarget();
    125     rx::RenderTarget *getDepthStencil();
    126     rx::TextureStorage *getTextureStorage();
    127 
    128     virtual GLsizei getWidth() const;
    129     virtual GLsizei getHeight() const;
    130     virtual GLenum getInternalFormat() const;
    131     virtual GLenum getActualFormat() const;
    132     virtual GLsizei getSamples() const;
    133 
    134     virtual unsigned int getSerial() const;
    135 
    136     virtual bool isTexture() const;
    137     virtual unsigned int getTextureSerial() const;
    138 
    139   private:
    140     DISALLOW_COPY_AND_ASSIGN(Texture2DAttachment);
    141 
    142     BindingPointer <Texture2D> mTexture2D;
    143     const GLint mLevel;
    144 };
    145 
    146 class TextureCubeMapAttachment : public FramebufferAttachmentInterface
    147 {
    148   public:
    149     TextureCubeMapAttachment(TextureCubeMap *texture, GLenum faceTarget, GLint level);
    150 
    151     virtual ~TextureCubeMapAttachment();
    152 
    153     void addProxyRef(const FramebufferAttachment *proxy);
    154     void releaseProxy(const FramebufferAttachment *proxy);
    155 
    156     rx::RenderTarget *getRenderTarget();
    157     rx::RenderTarget *getDepthStencil();
    158     rx::TextureStorage *getTextureStorage();
    159 
    160     virtual GLsizei getWidth() const;
    161     virtual GLsizei getHeight() const;
    162     virtual GLenum getInternalFormat() const;
    163     virtual GLenum getActualFormat() const;
    164     virtual GLsizei getSamples() const;
    165 
    166     virtual unsigned int getSerial() const;
    167 
    168     virtual bool isTexture() const;
    169     virtual unsigned int getTextureSerial() const;
    170 
    171   private:
    172     DISALLOW_COPY_AND_ASSIGN(TextureCubeMapAttachment);
    173 
    174     BindingPointer <TextureCubeMap> mTextureCubeMap;
    175     const GLint mLevel;
    176     const GLenum mFaceTarget;
    177 };
    178 
    179 class Texture3DAttachment : public FramebufferAttachmentInterface
    180 {
    181   public:
    182     Texture3DAttachment(Texture3D *texture, GLint level, GLint layer);
    183 
    184     virtual ~Texture3DAttachment();
    185 
    186     void addProxyRef(const FramebufferAttachment *proxy);
    187     void releaseProxy(const FramebufferAttachment *proxy);
    188 
    189     rx::RenderTarget *getRenderTarget();
    190     rx::RenderTarget *getDepthStencil();
    191     rx::TextureStorage *getTextureStorage();
    192 
    193     virtual GLsizei getWidth() const;
    194     virtual GLsizei getHeight() const;
    195     virtual GLenum getInternalFormat() const;
    196     virtual GLenum getActualFormat() const;
    197     virtual GLsizei getSamples() const;
    198 
    199     virtual unsigned int getSerial() const;
    200 
    201     virtual bool isTexture() const;
    202     virtual unsigned int getTextureSerial() const;
    203 
    204   private:
    205     DISALLOW_COPY_AND_ASSIGN(Texture3DAttachment);
    206 
    207     BindingPointer<Texture3D> mTexture3D;
    208     const GLint mLevel;
    209     const GLint mLayer;
    210 };
    211 
    212 class Texture2DArrayAttachment : public FramebufferAttachmentInterface
    213 {
    214   public:
    215     Texture2DArrayAttachment(Texture2DArray *texture, GLint level, GLint layer);
    216 
    217     virtual ~Texture2DArrayAttachment();
    218 
    219     void addProxyRef(const FramebufferAttachment *proxy);
    220     void releaseProxy(const FramebufferAttachment *proxy);
    221 
    222     rx::RenderTarget *getRenderTarget();
    223     rx::RenderTarget *getDepthStencil();
    224     rx::TextureStorage *getTextureStorage();
    225 
    226     virtual GLsizei getWidth() const;
    227     virtual GLsizei getHeight() const;
    228     virtual GLenum getInternalFormat() const;
    229     virtual GLenum getActualFormat() const;
    230     virtual GLsizei getSamples() const;
    231 
    232     virtual unsigned int getSerial() const;
    233 
    234     virtual bool isTexture() const;
    235     virtual unsigned int getTextureSerial() const;
    236 
    237   private:
    238     DISALLOW_COPY_AND_ASSIGN(Texture2DArrayAttachment);
    239 
    240     BindingPointer<Texture2DArray> mTexture2DArray;
    241     const GLint mLevel;
    242     const GLint mLayer;
    243 };
    244 
    245 }
    246 
    247 #endif // LIBGLESV2_FRAMEBUFFERATTACHMENT_H_
    248