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