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" |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 20 | #include "libGLESv2/RefCountObject.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | |
| 22 | namespace gl |
| 23 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 24 | class Texture; |
daniel@transgaming.com | f45e81d | 2011-11-09 17:46:02 +0000 | [diff] [blame] | 25 | class Colorbuffer; |
| 26 | class DepthStencilbuffer; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 27 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 28 | class RenderbufferInterface |
| 29 | { |
| 30 | public: |
| 31 | RenderbufferInterface(); |
| 32 | |
| 33 | virtual ~RenderbufferInterface() {}; |
| 34 | |
| 35 | virtual IDirect3DSurface9 *getRenderTarget() = 0; |
| 36 | virtual IDirect3DSurface9 *getDepthStencil() = 0; |
| 37 | |
| 38 | virtual GLsizei getWidth() const = 0; |
| 39 | virtual GLsizei getHeight() const = 0; |
| 40 | virtual GLenum getInternalFormat() const = 0; |
| 41 | virtual D3DFORMAT getD3DFormat() const = 0; |
| 42 | virtual GLsizei getSamples() const = 0; |
| 43 | |
| 44 | GLuint getRedSize() const; |
| 45 | GLuint getGreenSize() const; |
| 46 | GLuint getBlueSize() const; |
| 47 | GLuint getAlphaSize() const; |
| 48 | GLuint getDepthSize() const; |
| 49 | GLuint getStencilSize() const; |
| 50 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame^] | 51 | virtual unsigned int getSerial() const = 0; |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | DISALLOW_COPY_AND_ASSIGN(RenderbufferInterface); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | class RenderbufferTexture : public RenderbufferInterface |
| 58 | { |
| 59 | public: |
| 60 | RenderbufferTexture(Texture *texture, GLenum target); |
| 61 | |
| 62 | virtual ~RenderbufferTexture(); |
| 63 | |
| 64 | IDirect3DSurface9 *getRenderTarget(); |
| 65 | IDirect3DSurface9 *getDepthStencil(); |
| 66 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame^] | 67 | virtual GLsizei getWidth() const; |
| 68 | virtual GLsizei getHeight() const; |
| 69 | virtual GLenum getInternalFormat() const; |
| 70 | virtual D3DFORMAT getD3DFormat() const; |
| 71 | virtual GLsizei getSamples() const; |
| 72 | |
| 73 | virtual unsigned int getSerial() const; |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 74 | |
| 75 | private: |
| 76 | DISALLOW_COPY_AND_ASSIGN(RenderbufferTexture); |
| 77 | |
| 78 | Texture *mTexture; |
| 79 | GLenum mTarget; |
| 80 | }; |
| 81 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 82 | // A class derived from RenderbufferStorage is created whenever glRenderbufferStorage |
| 83 | // is called. The specific concrete type depends on whether the internal format is |
| 84 | // colour depth, stencil or packed depth/stencil. |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 85 | class RenderbufferStorage : public RenderbufferInterface |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 86 | { |
| 87 | public: |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 88 | RenderbufferStorage(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 89 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 90 | virtual ~RenderbufferStorage() = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 91 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 92 | virtual IDirect3DSurface9 *getRenderTarget(); |
| 93 | virtual IDirect3DSurface9 *getDepthStencil(); |
| 94 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 95 | virtual GLsizei getWidth() const; |
| 96 | virtual GLsizei getHeight() const; |
| 97 | virtual GLenum getInternalFormat() const; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 98 | virtual D3DFORMAT getD3DFormat() const; |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 99 | virtual GLsizei getSamples() const; |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 100 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame^] | 101 | virtual unsigned int getSerial() const; |
| 102 | |
| 103 | static unsigned int issueSerial(); |
| 104 | static unsigned int issueCubeSerials(); |
| 105 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 106 | protected: |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 107 | GLsizei mWidth; |
| 108 | GLsizei mHeight; |
| 109 | GLenum mInternalFormat; |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 110 | D3DFORMAT mD3DFormat; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 111 | GLsizei mSamples; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 112 | |
| 113 | private: |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 114 | DISALLOW_COPY_AND_ASSIGN(RenderbufferStorage); |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame^] | 115 | |
| 116 | const unsigned int mSerial; |
| 117 | |
| 118 | static unsigned int mCurrentSerial; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 121 | // Renderbuffer implements the GL renderbuffer object. |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 122 | // 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] | 123 | // can change whenever glRenderbufferStorage is called. |
| 124 | class Renderbuffer : public RefCountObject |
| 125 | { |
| 126 | public: |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 127 | Renderbuffer(GLuint id, RenderbufferInterface *storage); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 128 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 129 | virtual ~Renderbuffer(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 130 | |
| 131 | IDirect3DSurface9 *getRenderTarget(); |
| 132 | IDirect3DSurface9 *getDepthStencil(); |
| 133 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 134 | GLsizei getWidth() const; |
| 135 | GLsizei getHeight() const; |
| 136 | GLenum getInternalFormat() const; |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 137 | D3DFORMAT getD3DFormat() const; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 138 | GLuint getRedSize() const; |
| 139 | GLuint getGreenSize() const; |
| 140 | GLuint getBlueSize() const; |
| 141 | GLuint getAlphaSize() const; |
| 142 | GLuint getDepthSize() const; |
| 143 | GLuint getStencilSize() const; |
| 144 | GLsizei getSamples() const; |
| 145 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 146 | unsigned int getSerial() const; |
| 147 | |
| 148 | void setStorage(RenderbufferStorage *newStorage); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 149 | |
| 150 | private: |
| 151 | DISALLOW_COPY_AND_ASSIGN(Renderbuffer); |
| 152 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 153 | RenderbufferInterface *mInstance; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | class Colorbuffer : public RenderbufferStorage |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 157 | { |
| 158 | public: |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 159 | explicit Colorbuffer(IDirect3DSurface9 *renderTarget); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 160 | Colorbuffer(GLsizei width, GLsizei height, GLenum format, GLsizei samples); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 161 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 162 | virtual ~Colorbuffer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 163 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 164 | virtual IDirect3DSurface9 *getRenderTarget(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 165 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 166 | private: |
| 167 | DISALLOW_COPY_AND_ASSIGN(Colorbuffer); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 168 | |
| 169 | IDirect3DSurface9 *mRenderTarget; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 172 | class DepthStencilbuffer : public RenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 173 | { |
| 174 | public: |
| 175 | explicit DepthStencilbuffer(IDirect3DSurface9 *depthStencil); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 176 | DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples); |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 177 | |
| 178 | ~DepthStencilbuffer(); |
| 179 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 180 | virtual IDirect3DSurface9 *getDepthStencil(); |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 181 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 182 | protected: |
| 183 | IDirect3DSurface9 *mDepthStencil; |
| 184 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 185 | private: |
| 186 | DISALLOW_COPY_AND_ASSIGN(DepthStencilbuffer); |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | class Depthbuffer : public DepthStencilbuffer |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 190 | { |
| 191 | public: |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 192 | explicit Depthbuffer(IDirect3DSurface9 *depthStencil); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 193 | Depthbuffer(GLsizei width, GLsizei height, GLsizei samples); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 194 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 195 | virtual ~Depthbuffer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 196 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 197 | private: |
| 198 | DISALLOW_COPY_AND_ASSIGN(Depthbuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 199 | }; |
| 200 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 201 | class Stencilbuffer : public DepthStencilbuffer |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 202 | { |
| 203 | public: |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 204 | explicit Stencilbuffer(IDirect3DSurface9 *depthStencil); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 205 | Stencilbuffer(GLsizei width, GLsizei height, 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 ~Stencilbuffer(); |
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(Stencilbuffer); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 211 | }; |
| 212 | } |
| 213 | |
| 214 | #endif // LIBGLESV2_RENDERBUFFER_H_ |