Home | History | Annotate | Download | only in libGLESv2
      1 //
      2 // Copyright (c) 2002-2010 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 // Renderbuffer.h: Defines the wrapper class gl::Renderbuffer, as well as the
      8 // class hierarchy used to store its contents: RenderbufferStorage, Colorbuffer,
      9 // DepthStencilbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer
     10 // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108.
     11 
     12 #ifndef LIBGLESV2_RENDERBUFFER_H_
     13 #define LIBGLESV2_RENDERBUFFER_H_
     14 
     15 #define GL_APICALL
     16 #include <GLES2/gl2.h>
     17 #include <d3d9.h>
     18 
     19 #include "common/angleutils.h"
     20 #include "libGLESv2/RefCountObject.h"
     21 
     22 namespace gl
     23 {
     24     class Texture;
     25 
     26 // A class derived from RenderbufferStorage is created whenever glRenderbufferStorage
     27 // is called. The specific concrete type depends on whether the internal format is
     28 // colour depth, stencil or packed depth/stencil.
     29 class RenderbufferStorage
     30 {
     31   public:
     32     RenderbufferStorage();
     33 
     34     virtual ~RenderbufferStorage() = 0;
     35 
     36     virtual bool isColorbuffer() const;
     37     virtual bool isDepthbuffer() const;
     38     virtual bool isStencilbuffer() const;
     39 
     40     virtual IDirect3DSurface9 *getRenderTarget();
     41     virtual IDirect3DSurface9 *getDepthStencil();
     42 
     43     virtual int getWidth() const;
     44     virtual int getHeight() const;
     45     virtual GLenum getFormat() const;
     46     virtual bool isFloatingPoint() const;
     47     D3DFORMAT getD3DFormat() const;
     48     GLsizei getSamples() const;
     49     unsigned int getSerial() const;
     50 
     51     static unsigned int issueSerial();
     52 
     53   protected:
     54     void setSize(int width, int height);
     55     GLenum mFormat;
     56     D3DFORMAT mD3DFormat;
     57     GLsizei mSamples;
     58     const unsigned int mSerial;
     59 
     60   private:
     61     DISALLOW_COPY_AND_ASSIGN(RenderbufferStorage);
     62 
     63     static unsigned int mCurrentSerial;
     64 
     65     int mWidth;
     66     int mHeight;
     67 };
     68 
     69 // Renderbuffer implements the GL renderbuffer object.
     70 // It's only a wrapper for a RenderbufferStorage, but the internal object
     71 // can change whenever glRenderbufferStorage is called.
     72 class Renderbuffer : public RefCountObject
     73 {
     74   public:
     75     Renderbuffer(GLuint id, RenderbufferStorage *storage);
     76 
     77     ~Renderbuffer();
     78 
     79     bool isColorbuffer() const;
     80     bool isDepthbuffer() const;
     81     bool isStencilbuffer() const;
     82 
     83     IDirect3DSurface9 *getRenderTarget();
     84     IDirect3DSurface9 *getDepthStencil();
     85 
     86     int getWidth() const;
     87     int getHeight() const;
     88     GLenum getFormat() const;
     89     D3DFORMAT getD3DFormat() const;
     90     unsigned int getSerial() const;
     91 
     92     void setStorage(RenderbufferStorage *newStorage);
     93     RenderbufferStorage *getStorage() { return mStorage; }
     94 
     95   private:
     96     DISALLOW_COPY_AND_ASSIGN(Renderbuffer);
     97 
     98     RenderbufferStorage *mStorage;
     99 };
    100 
    101 class Colorbuffer : public RenderbufferStorage
    102 {
    103   public:
    104     explicit Colorbuffer(IDirect3DSurface9 *renderTarget);
    105     explicit Colorbuffer(const Texture* texture);
    106     Colorbuffer(int width, int height, GLenum format, GLsizei samples);
    107 
    108     ~Colorbuffer();
    109 
    110     bool isColorbuffer() const;
    111 
    112     GLuint getRedSize() const;
    113     GLuint getGreenSize() const;
    114     GLuint getBlueSize() const;
    115     GLuint getAlphaSize() const;
    116 
    117     IDirect3DSurface9 *getRenderTarget();
    118 
    119   protected:
    120     IDirect3DSurface9 *mRenderTarget;
    121 
    122   private:
    123     DISALLOW_COPY_AND_ASSIGN(Colorbuffer);
    124 };
    125 
    126 class DepthStencilbuffer : public RenderbufferStorage
    127 {
    128   public:
    129     explicit DepthStencilbuffer(IDirect3DSurface9 *depthStencil);
    130     DepthStencilbuffer(int width, int height, GLsizei samples);
    131 
    132     ~DepthStencilbuffer();
    133 
    134     virtual bool isDepthbuffer() const;
    135     virtual bool isStencilbuffer() const;
    136 
    137     GLuint getDepthSize() const;
    138     GLuint getStencilSize() const;
    139 
    140     IDirect3DSurface9 *getDepthStencil();
    141 
    142   private:
    143     DISALLOW_COPY_AND_ASSIGN(DepthStencilbuffer);
    144     IDirect3DSurface9 *mDepthStencil;
    145 };
    146 
    147 class Depthbuffer : public DepthStencilbuffer
    148 {
    149   public:
    150     explicit Depthbuffer(IDirect3DSurface9 *depthStencil);
    151     Depthbuffer(int width, int height, GLsizei samples);
    152 
    153     ~Depthbuffer();
    154 
    155     bool isDepthbuffer() const;
    156     bool isStencilbuffer() const;
    157 
    158   private:
    159     DISALLOW_COPY_AND_ASSIGN(Depthbuffer);
    160 };
    161 
    162 class Stencilbuffer : public DepthStencilbuffer
    163 {
    164   public:
    165     explicit Stencilbuffer(IDirect3DSurface9 *depthStencil);
    166     Stencilbuffer(int width, int height, GLsizei samples);
    167 
    168     ~Stencilbuffer();
    169 
    170     bool isDepthbuffer() const;
    171     bool isStencilbuffer() const;
    172 
    173   private:
    174     DISALLOW_COPY_AND_ASSIGN(Stencilbuffer);
    175 };
    176 }
    177 
    178 #endif   // LIBGLESV2_RENDERBUFFER_H_
    179