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 | |
| 7 | // Renderbuffer.cpp: the gl::Renderbuffer class and its derived classes |
| 8 | // Colorbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer |
| 9 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108. |
| 10 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 11 | #include "libGLESv2/Renderbuffer.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 12 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 13 | #include "libGLESv2/main.h" |
enne@chromium.org | 0fa7463 | 2010-09-21 16:18:52 +0000 | [diff] [blame] | 14 | #include "libGLESv2/Texture.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 15 | #include "libGLESv2/utilities.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 16 | |
| 17 | namespace gl |
| 18 | { |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 19 | unsigned int RenderbufferStorage::mCurrentSerial = 1; |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 20 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 21 | RenderbufferInterface::RenderbufferInterface() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 22 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 23 | } |
| 24 | |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 25 | // The default case for classes inherited from RenderbufferInterface is not to |
| 26 | // need to do anything upon the reference count to the parent Renderbuffer incrementing |
| 27 | // or decrementing. |
| 28 | void RenderbufferInterface::addProxyRef(const Renderbuffer *proxy) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | void RenderbufferInterface::releaseProxy(const Renderbuffer *proxy) |
| 33 | { |
| 34 | } |
| 35 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 36 | GLuint RenderbufferInterface::getRedSize() const |
| 37 | { |
| 38 | return dx2es::GetRedSize(getD3DFormat()); |
| 39 | } |
| 40 | |
| 41 | GLuint RenderbufferInterface::getGreenSize() const |
| 42 | { |
| 43 | return dx2es::GetGreenSize(getD3DFormat()); |
| 44 | } |
| 45 | |
| 46 | GLuint RenderbufferInterface::getBlueSize() const |
| 47 | { |
| 48 | return dx2es::GetBlueSize(getD3DFormat()); |
| 49 | } |
| 50 | |
| 51 | GLuint RenderbufferInterface::getAlphaSize() const |
| 52 | { |
| 53 | return dx2es::GetAlphaSize(getD3DFormat()); |
| 54 | } |
| 55 | |
| 56 | GLuint RenderbufferInterface::getDepthSize() const |
| 57 | { |
| 58 | return dx2es::GetDepthSize(getD3DFormat()); |
| 59 | } |
| 60 | |
| 61 | GLuint RenderbufferInterface::getStencilSize() const |
| 62 | { |
| 63 | return dx2es::GetStencilSize(getD3DFormat()); |
| 64 | } |
| 65 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 66 | ///// RenderbufferTexture2D Implementation //////// |
| 67 | |
| 68 | RenderbufferTexture2D::RenderbufferTexture2D(Texture2D *texture, GLenum target) : mTarget(target) |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 69 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 70 | mTexture2D.set(texture); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 71 | } |
| 72 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 73 | RenderbufferTexture2D::~RenderbufferTexture2D() |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 74 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 75 | mTexture2D.set(NULL); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 76 | } |
| 77 | |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 78 | // Textures need to maintain their own reference count for references via |
| 79 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 80 | void RenderbufferTexture2D::addProxyRef(const Renderbuffer *proxy) |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 81 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 82 | mTexture2D->addProxyRef(proxy); |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 83 | } |
| 84 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 85 | void RenderbufferTexture2D::releaseProxy(const Renderbuffer *proxy) |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 86 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 87 | mTexture2D->releaseProxy(proxy); |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 88 | } |
| 89 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 90 | IDirect3DSurface9 *RenderbufferTexture2D::getRenderTarget() |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 91 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 92 | return mTexture2D->getRenderTarget(mTarget); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 93 | } |
| 94 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 95 | IDirect3DSurface9 *RenderbufferTexture2D::getDepthStencil() |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 96 | { |
| 97 | return NULL; |
| 98 | } |
| 99 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 100 | GLsizei RenderbufferTexture2D::getWidth() const |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 101 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 102 | return mTexture2D->getWidth(0); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 103 | } |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 104 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 105 | GLsizei RenderbufferTexture2D::getHeight() const |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 106 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 107 | return mTexture2D->getHeight(0); |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 108 | } |
| 109 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 110 | GLenum RenderbufferTexture2D::getInternalFormat() const |
| 111 | { |
daniel@transgaming.com | 92f4992 | 2012-05-09 15:49:19 +0000 | [diff] [blame] | 112 | return mTexture2D->getInternalFormat(0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | D3DFORMAT RenderbufferTexture2D::getD3DFormat() const |
| 116 | { |
daniel@transgaming.com | 92f4992 | 2012-05-09 15:49:19 +0000 | [diff] [blame] | 117 | return mTexture2D->getD3DFormat(0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | GLsizei RenderbufferTexture2D::getSamples() const |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 121 | { |
| 122 | return 0; |
| 123 | } |
| 124 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 125 | unsigned int RenderbufferTexture2D::getSerial() const |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 126 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 127 | return mTexture2D->getRenderTargetSerial(mTarget); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 128 | } |
| 129 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 130 | ///// RenderbufferTextureCubeMap Implementation //////// |
| 131 | |
| 132 | RenderbufferTextureCubeMap::RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target) : mTarget(target) |
| 133 | { |
| 134 | mTextureCubeMap.set(texture); |
| 135 | } |
| 136 | |
| 137 | RenderbufferTextureCubeMap::~RenderbufferTextureCubeMap() |
| 138 | { |
| 139 | mTextureCubeMap.set(NULL); |
| 140 | } |
| 141 | |
| 142 | // Textures need to maintain their own reference count for references via |
| 143 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
| 144 | void RenderbufferTextureCubeMap::addProxyRef(const Renderbuffer *proxy) |
| 145 | { |
| 146 | mTextureCubeMap->addProxyRef(proxy); |
| 147 | } |
| 148 | |
| 149 | void RenderbufferTextureCubeMap::releaseProxy(const Renderbuffer *proxy) |
| 150 | { |
| 151 | mTextureCubeMap->releaseProxy(proxy); |
| 152 | } |
| 153 | |
| 154 | IDirect3DSurface9 *RenderbufferTextureCubeMap::getRenderTarget() |
| 155 | { |
| 156 | return mTextureCubeMap->getRenderTarget(mTarget); |
| 157 | } |
| 158 | |
| 159 | IDirect3DSurface9 *RenderbufferTextureCubeMap::getDepthStencil() |
| 160 | { |
| 161 | return NULL; |
| 162 | } |
| 163 | |
| 164 | GLsizei RenderbufferTextureCubeMap::getWidth() const |
| 165 | { |
daniel@transgaming.com | 4df88e8 | 2012-05-09 15:49:24 +0000 | [diff] [blame] | 166 | return mTextureCubeMap->getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | GLsizei RenderbufferTextureCubeMap::getHeight() const |
| 170 | { |
daniel@transgaming.com | 4df88e8 | 2012-05-09 15:49:24 +0000 | [diff] [blame] | 171 | return mTextureCubeMap->getHeight(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | GLenum RenderbufferTextureCubeMap::getInternalFormat() const |
| 175 | { |
daniel@transgaming.com | 4df88e8 | 2012-05-09 15:49:24 +0000 | [diff] [blame] | 176 | return mTextureCubeMap->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | D3DFORMAT RenderbufferTextureCubeMap::getD3DFormat() const |
| 180 | { |
daniel@transgaming.com | 4df88e8 | 2012-05-09 15:49:24 +0000 | [diff] [blame] | 181 | return mTextureCubeMap->getD3DFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | GLsizei RenderbufferTextureCubeMap::getSamples() const |
| 185 | { |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | unsigned int RenderbufferTextureCubeMap::getSerial() const |
| 190 | { |
| 191 | return mTextureCubeMap->getRenderTargetSerial(mTarget); |
| 192 | } |
| 193 | |
| 194 | ////// Renderbuffer Implementation ////// |
| 195 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 196 | Renderbuffer::Renderbuffer(GLuint id, RenderbufferInterface *instance) : RefCountObject(id) |
| 197 | { |
| 198 | ASSERT(instance != NULL); |
| 199 | mInstance = instance; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | Renderbuffer::~Renderbuffer() |
| 203 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 204 | delete mInstance; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 205 | } |
| 206 | |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 207 | // The RenderbufferInterface contained in this Renderbuffer may need to maintain |
| 208 | // its own reference count, so we pass it on here. |
| 209 | void Renderbuffer::addRef() const |
| 210 | { |
| 211 | mInstance->addProxyRef(this); |
| 212 | |
| 213 | RefCountObject::addRef(); |
| 214 | } |
| 215 | |
| 216 | void Renderbuffer::release() const |
| 217 | { |
| 218 | mInstance->releaseProxy(this); |
| 219 | |
| 220 | RefCountObject::release(); |
| 221 | } |
| 222 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 223 | IDirect3DSurface9 *Renderbuffer::getRenderTarget() |
| 224 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 225 | return mInstance->getRenderTarget(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | IDirect3DSurface9 *Renderbuffer::getDepthStencil() |
| 229 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 230 | return mInstance->getDepthStencil(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 231 | } |
| 232 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 233 | GLsizei Renderbuffer::getWidth() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 234 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 235 | return mInstance->getWidth(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 236 | } |
| 237 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 238 | GLsizei Renderbuffer::getHeight() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 239 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 240 | return mInstance->getHeight(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 241 | } |
| 242 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 243 | GLenum Renderbuffer::getInternalFormat() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 244 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 245 | return mInstance->getInternalFormat(); |
| 246 | } |
| 247 | |
| 248 | D3DFORMAT Renderbuffer::getD3DFormat() const |
| 249 | { |
| 250 | return mInstance->getD3DFormat(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 251 | } |
| 252 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 253 | GLuint Renderbuffer::getRedSize() const |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 254 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 255 | return mInstance->getRedSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | GLuint Renderbuffer::getGreenSize() const |
| 259 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 260 | return mInstance->getGreenSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | GLuint Renderbuffer::getBlueSize() const |
| 264 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 265 | return mInstance->getBlueSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | GLuint Renderbuffer::getAlphaSize() const |
| 269 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 270 | return mInstance->getAlphaSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | GLuint Renderbuffer::getDepthSize() const |
| 274 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 275 | return mInstance->getDepthSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | GLuint Renderbuffer::getStencilSize() const |
| 279 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 280 | return mInstance->getStencilSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | GLsizei Renderbuffer::getSamples() const |
| 284 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 285 | return mInstance->getSamples(); |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 286 | } |
| 287 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 288 | unsigned int Renderbuffer::getSerial() const |
| 289 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 290 | return mInstance->getSerial(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void Renderbuffer::setStorage(RenderbufferStorage *newStorage) |
| 294 | { |
| 295 | ASSERT(newStorage != NULL); |
| 296 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 297 | delete mInstance; |
| 298 | mInstance = newStorage; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 299 | } |
| 300 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 301 | RenderbufferStorage::RenderbufferStorage() : mSerial(issueSerial()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 302 | { |
daniel@transgaming.com | 73a5db6 | 2010-10-15 17:58:13 +0000 | [diff] [blame] | 303 | mWidth = 0; |
| 304 | mHeight = 0; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 305 | mInternalFormat = GL_RGBA4; |
daniel@transgaming.com | 73a5db6 | 2010-10-15 17:58:13 +0000 | [diff] [blame] | 306 | mD3DFormat = D3DFMT_A8R8G8B8; |
| 307 | mSamples = 0; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | RenderbufferStorage::~RenderbufferStorage() |
| 311 | { |
| 312 | } |
| 313 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 314 | IDirect3DSurface9 *RenderbufferStorage::getRenderTarget() |
| 315 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 316 | return NULL; |
| 317 | } |
| 318 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 319 | IDirect3DSurface9 *RenderbufferStorage::getDepthStencil() |
| 320 | { |
| 321 | return NULL; |
| 322 | } |
| 323 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 324 | GLsizei RenderbufferStorage::getWidth() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 325 | { |
| 326 | return mWidth; |
| 327 | } |
| 328 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 329 | GLsizei RenderbufferStorage::getHeight() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 330 | { |
| 331 | return mHeight; |
| 332 | } |
| 333 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 334 | GLenum RenderbufferStorage::getInternalFormat() const |
daniel@transgaming.com | 866f318 | 2010-05-20 19:28:22 +0000 | [diff] [blame] | 335 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 336 | return mInternalFormat; |
daniel@transgaming.com | 866f318 | 2010-05-20 19:28:22 +0000 | [diff] [blame] | 337 | } |
| 338 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 339 | D3DFORMAT RenderbufferStorage::getD3DFormat() const |
| 340 | { |
| 341 | return mD3DFormat; |
| 342 | } |
| 343 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 344 | GLsizei RenderbufferStorage::getSamples() const |
| 345 | { |
| 346 | return mSamples; |
| 347 | } |
| 348 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 349 | unsigned int RenderbufferStorage::getSerial() const |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 350 | { |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 351 | return mSerial; |
| 352 | } |
| 353 | |
| 354 | unsigned int RenderbufferStorage::issueSerial() |
| 355 | { |
| 356 | return mCurrentSerial++; |
| 357 | } |
| 358 | |
| 359 | unsigned int RenderbufferStorage::issueCubeSerials() |
| 360 | { |
| 361 | unsigned int firstSerial = mCurrentSerial; |
| 362 | mCurrentSerial += 6; |
| 363 | return firstSerial; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 364 | } |
| 365 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 366 | Colorbuffer::Colorbuffer(IDirect3DSurface9 *renderTarget) : mRenderTarget(renderTarget) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 367 | { |
| 368 | if (renderTarget) |
| 369 | { |
| 370 | renderTarget->AddRef(); |
| 371 | |
| 372 | D3DSURFACE_DESC description; |
| 373 | renderTarget->GetDesc(&description); |
| 374 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 375 | mWidth = description.Width; |
| 376 | mHeight = description.Height; |
| 377 | mInternalFormat = dx2es::ConvertBackBufferFormat(description.Format); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 378 | mD3DFormat = description.Format; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 379 | mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 380 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 381 | } |
| 382 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 383 | Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(NULL) |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 384 | { |
| 385 | IDirect3DDevice9 *device = getDevice(); |
| 386 | |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 387 | D3DFORMAT requestedFormat = es2dx::ConvertRenderbufferFormat(format); |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 388 | int supportedSamples = getContext()->getNearestSupportedSamples(requestedFormat, samples); |
| 389 | |
| 390 | if (supportedSamples == -1) |
| 391 | { |
| 392 | error(GL_OUT_OF_MEMORY); |
| 393 | |
| 394 | return; |
| 395 | } |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 396 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 397 | if (width > 0 && height > 0) |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 398 | { |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 399 | HRESULT result = device->CreateRenderTarget(width, height, requestedFormat, |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 400 | es2dx::GetMultisampleTypeFromSamples(supportedSamples), 0, FALSE, &mRenderTarget, NULL); |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 401 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 402 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 403 | { |
| 404 | error(GL_OUT_OF_MEMORY); |
| 405 | |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 410 | } |
| 411 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 412 | mWidth = width; |
| 413 | mHeight = height; |
| 414 | mInternalFormat = format; |
| 415 | mD3DFormat = requestedFormat; |
| 416 | mSamples = supportedSamples; |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 417 | } |
| 418 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 419 | Colorbuffer::~Colorbuffer() |
| 420 | { |
| 421 | if (mRenderTarget) |
| 422 | { |
| 423 | mRenderTarget->Release(); |
| 424 | } |
| 425 | } |
| 426 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 427 | IDirect3DSurface9 *Colorbuffer::getRenderTarget() |
| 428 | { |
daniel@transgaming.com | 5e4dbb3 | 2011-11-11 04:10:18 +0000 | [diff] [blame] | 429 | if (mRenderTarget) |
| 430 | { |
| 431 | mRenderTarget->AddRef(); |
| 432 | } |
| 433 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 434 | return mRenderTarget; |
| 435 | } |
| 436 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 437 | DepthStencilbuffer::DepthStencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 438 | { |
| 439 | if (depthStencil) |
| 440 | { |
| 441 | depthStencil->AddRef(); |
| 442 | |
| 443 | D3DSURFACE_DESC description; |
| 444 | depthStencil->GetDesc(&description); |
| 445 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 446 | mWidth = description.Width; |
| 447 | mHeight = description.Height; |
| 448 | mInternalFormat = dx2es::ConvertDepthStencilFormat(description.Format); |
| 449 | mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 450 | mD3DFormat = description.Format; |
| 451 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 452 | } |
| 453 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 454 | DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 455 | { |
| 456 | IDirect3DDevice9 *device = getDevice(); |
| 457 | |
| 458 | mDepthStencil = NULL; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 459 | |
| 460 | int supportedSamples = getContext()->getNearestSupportedSamples(D3DFMT_D24S8, samples); |
| 461 | |
| 462 | if (supportedSamples == -1) |
| 463 | { |
| 464 | error(GL_OUT_OF_MEMORY); |
| 465 | |
| 466 | return; |
| 467 | } |
| 468 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 469 | if (width > 0 && height > 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 470 | { |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 471 | HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples), |
| 472 | 0, FALSE, &mDepthStencil, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 473 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 474 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 475 | { |
| 476 | error(GL_OUT_OF_MEMORY); |
| 477 | |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 482 | } |
| 483 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 484 | mWidth = width; |
| 485 | mHeight = height; |
| 486 | mInternalFormat = GL_DEPTH24_STENCIL8_OES; |
| 487 | mD3DFormat = D3DFMT_D24S8; |
| 488 | mSamples = supportedSamples; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 489 | } |
| 490 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 491 | DepthStencilbuffer::~DepthStencilbuffer() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 492 | { |
| 493 | if (mDepthStencil) |
| 494 | { |
| 495 | mDepthStencil->Release(); |
| 496 | } |
| 497 | } |
| 498 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 499 | IDirect3DSurface9 *DepthStencilbuffer::getDepthStencil() |
| 500 | { |
| 501 | return mDepthStencil; |
| 502 | } |
| 503 | |
| 504 | Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 505 | { |
| 506 | if (depthStencil) |
| 507 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 508 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 509 | // will expect one of the valid renderbuffer formats for use in |
| 510 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 514 | Depthbuffer::Depthbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 515 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 516 | if (mDepthStencil) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 517 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 518 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 519 | // will expect one of the valid renderbuffer formats for use in |
| 520 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
| 524 | Depthbuffer::~Depthbuffer() |
| 525 | { |
| 526 | } |
| 527 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 528 | Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 529 | { |
| 530 | if (depthStencil) |
| 531 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 532 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 533 | // will expect one of the valid renderbuffer formats for use in |
| 534 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 538 | Stencilbuffer::Stencilbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 539 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 540 | if (mDepthStencil) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 541 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 542 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 543 | // will expect one of the valid renderbuffer formats for use in |
| 544 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
| 548 | Stencilbuffer::~Stencilbuffer() |
| 549 | { |
| 550 | } |
| 551 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 552 | } |