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 18 #include "common/angleutils.h" 19 #include "common/RefCountObject.h" 20 21 namespace rx 22 { 23 class Renderer; 24 class SwapChain; 25 class RenderTarget; 26 } 27 28 namespace gl 29 { 30 class Texture2D; 31 class TextureCubeMap; 32 class Renderbuffer; 33 class Colorbuffer; 34 class DepthStencilbuffer; 35 36 class RenderbufferInterface 37 { 38 public: 39 RenderbufferInterface(); 40 ~RenderbufferInterface()41 virtual ~RenderbufferInterface() {}; 42 43 virtual void addProxyRef(const Renderbuffer *proxy); 44 virtual void releaseProxy(const Renderbuffer *proxy); 45 46 virtual rx::RenderTarget *getRenderTarget() = 0; 47 virtual rx::RenderTarget *getDepthStencil() = 0; 48 49 virtual GLsizei getWidth() const = 0; 50 virtual GLsizei getHeight() const = 0; 51 virtual GLenum getInternalFormat() const = 0; 52 virtual GLenum getActualFormat() const = 0; 53 virtual GLsizei getSamples() const = 0; 54 55 GLuint getRedSize() const; 56 GLuint getGreenSize() const; 57 GLuint getBlueSize() const; 58 GLuint getAlphaSize() const; 59 GLuint getDepthSize() const; 60 GLuint getStencilSize() const; 61 62 virtual unsigned int getSerial() const = 0; 63 virtual unsigned int getTextureSerial() const = 0; 64 65 private: 66 DISALLOW_COPY_AND_ASSIGN(RenderbufferInterface); 67 }; 68 69 class RenderbufferTexture2D : public RenderbufferInterface 70 { 71 public: 72 RenderbufferTexture2D(Texture2D *texture, GLenum target); 73 74 virtual ~RenderbufferTexture2D(); 75 76 void addProxyRef(const Renderbuffer *proxy); 77 void releaseProxy(const Renderbuffer *proxy); 78 79 rx::RenderTarget *getRenderTarget(); 80 rx::RenderTarget *getDepthStencil(); 81 82 virtual GLsizei getWidth() const; 83 virtual GLsizei getHeight() const; 84 virtual GLenum getInternalFormat() const; 85 virtual GLenum getActualFormat() const; 86 virtual GLsizei getSamples() const; 87 88 virtual unsigned int getSerial() const; 89 virtual unsigned int getTextureSerial() const; 90 91 private: 92 DISALLOW_COPY_AND_ASSIGN(RenderbufferTexture2D); 93 94 BindingPointer <Texture2D> mTexture2D; 95 GLenum mTarget; 96 }; 97 98 class RenderbufferTextureCubeMap : public RenderbufferInterface 99 { 100 public: 101 RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target); 102 103 virtual ~RenderbufferTextureCubeMap(); 104 105 void addProxyRef(const Renderbuffer *proxy); 106 void releaseProxy(const Renderbuffer *proxy); 107 108 rx::RenderTarget *getRenderTarget(); 109 rx::RenderTarget *getDepthStencil(); 110 111 virtual GLsizei getWidth() const; 112 virtual GLsizei getHeight() const; 113 virtual GLenum getInternalFormat() const; 114 virtual GLenum getActualFormat() const; 115 virtual GLsizei getSamples() const; 116 117 virtual unsigned int getSerial() const; 118 virtual unsigned int getTextureSerial() const; 119 120 private: 121 DISALLOW_COPY_AND_ASSIGN(RenderbufferTextureCubeMap); 122 123 BindingPointer <TextureCubeMap> mTextureCubeMap; 124 GLenum mTarget; 125 }; 126 127 // A class derived from RenderbufferStorage is created whenever glRenderbufferStorage 128 // is called. The specific concrete type depends on whether the internal format is 129 // colour depth, stencil or packed depth/stencil. 130 class RenderbufferStorage : public RenderbufferInterface 131 { 132 public: 133 RenderbufferStorage(); 134 135 virtual ~RenderbufferStorage() = 0; 136 137 virtual rx::RenderTarget *getRenderTarget(); 138 virtual rx::RenderTarget *getDepthStencil(); 139 140 virtual GLsizei getWidth() const; 141 virtual GLsizei getHeight() const; 142 virtual GLenum getInternalFormat() const; 143 virtual GLenum getActualFormat() const; 144 virtual GLsizei getSamples() const; 145 146 virtual unsigned int getSerial() const; getTextureSerial()147 virtual unsigned int getTextureSerial() const { return 0; } 148 149 static unsigned int issueSerial(); 150 static unsigned int issueCubeSerials(); 151 152 protected: 153 GLsizei mWidth; 154 GLsizei mHeight; 155 GLenum mInternalFormat; 156 GLenum mActualFormat; 157 GLsizei mSamples; 158 159 private: 160 DISALLOW_COPY_AND_ASSIGN(RenderbufferStorage); 161 162 const unsigned int mSerial; 163 164 static unsigned int mCurrentSerial; 165 }; 166 167 // Renderbuffer implements the GL renderbuffer object. 168 // It's only a proxy for a RenderbufferInterface instance; the internal object 169 // can change whenever glRenderbufferStorage is called. 170 class Renderbuffer : public RefCountObject 171 { 172 public: 173 Renderbuffer(rx::Renderer *renderer, GLuint id, RenderbufferInterface *storage); 174 175 virtual ~Renderbuffer(); 176 177 // These functions from RefCountObject are overloaded here because 178 // Textures need to maintain their own count of references to them via 179 // Renderbuffers/RenderbufferTextures. These functions invoke those 180 // reference counting functions on the RenderbufferInterface. 181 void addRef() const; 182 void release() const; 183 184 rx::RenderTarget *getRenderTarget(); 185 rx::RenderTarget *getDepthStencil(); 186 187 GLsizei getWidth() const; 188 GLsizei getHeight() const; 189 GLenum getInternalFormat() const; 190 GLenum getActualFormat() const; 191 GLuint getRedSize() const; 192 GLuint getGreenSize() const; 193 GLuint getBlueSize() const; 194 GLuint getAlphaSize() const; 195 GLuint getDepthSize() const; 196 GLuint getStencilSize() const; 197 GLsizei getSamples() const; 198 199 unsigned int getSerial() const; 200 unsigned int getTextureSerial() const; 201 202 void setStorage(RenderbufferStorage *newStorage); 203 204 private: 205 DISALLOW_COPY_AND_ASSIGN(Renderbuffer); 206 207 RenderbufferInterface *mInstance; 208 }; 209 210 class Colorbuffer : public RenderbufferStorage 211 { 212 public: 213 Colorbuffer(rx::Renderer *renderer, rx::SwapChain *swapChain); 214 Colorbuffer(rx::Renderer *renderer, GLsizei width, GLsizei height, GLenum format, GLsizei samples); 215 216 virtual ~Colorbuffer(); 217 218 virtual rx::RenderTarget *getRenderTarget(); 219 220 private: 221 DISALLOW_COPY_AND_ASSIGN(Colorbuffer); 222 223 rx::RenderTarget *mRenderTarget; 224 }; 225 226 class DepthStencilbuffer : public RenderbufferStorage 227 { 228 public: 229 DepthStencilbuffer(rx::Renderer *renderer, rx::SwapChain *swapChain); 230 DepthStencilbuffer(rx::Renderer *renderer, GLsizei width, GLsizei height, GLsizei samples); 231 232 ~DepthStencilbuffer(); 233 234 virtual rx::RenderTarget *getDepthStencil(); 235 236 protected: 237 rx::RenderTarget *mDepthStencil; 238 239 private: 240 DISALLOW_COPY_AND_ASSIGN(DepthStencilbuffer); 241 }; 242 243 class Depthbuffer : public DepthStencilbuffer 244 { 245 public: 246 Depthbuffer(rx::Renderer *renderer, GLsizei width, GLsizei height, GLsizei samples); 247 248 virtual ~Depthbuffer(); 249 250 private: 251 DISALLOW_COPY_AND_ASSIGN(Depthbuffer); 252 }; 253 254 class Stencilbuffer : public DepthStencilbuffer 255 { 256 public: 257 Stencilbuffer(rx::Renderer *renderer, GLsizei width, GLsizei height, GLsizei samples); 258 259 virtual ~Stencilbuffer(); 260 261 private: 262 DISALLOW_COPY_AND_ASSIGN(Stencilbuffer); 263 }; 264 } 265 266 #endif // LIBGLESV2_RENDERBUFFER_H_ 267