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