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 | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 19 | unsigned int RenderbufferInterface::mCurrentSerial = 1; |
daniel@transgaming.com | 092bd48 | 2010-05-12 03:39:36 +0000 | [diff] [blame] | 20 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 21 | RenderbufferInterface::RenderbufferInterface() : mSerial(issueSerial()) |
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 | |
| 25 | GLuint RenderbufferInterface::getRedSize() const |
| 26 | { |
| 27 | return dx2es::GetRedSize(getD3DFormat()); |
| 28 | } |
| 29 | |
| 30 | GLuint RenderbufferInterface::getGreenSize() const |
| 31 | { |
| 32 | return dx2es::GetGreenSize(getD3DFormat()); |
| 33 | } |
| 34 | |
| 35 | GLuint RenderbufferInterface::getBlueSize() const |
| 36 | { |
| 37 | return dx2es::GetBlueSize(getD3DFormat()); |
| 38 | } |
| 39 | |
| 40 | GLuint RenderbufferInterface::getAlphaSize() const |
| 41 | { |
| 42 | return dx2es::GetAlphaSize(getD3DFormat()); |
| 43 | } |
| 44 | |
| 45 | GLuint RenderbufferInterface::getDepthSize() const |
| 46 | { |
| 47 | return dx2es::GetDepthSize(getD3DFormat()); |
| 48 | } |
| 49 | |
| 50 | GLuint RenderbufferInterface::getStencilSize() const |
| 51 | { |
| 52 | return dx2es::GetStencilSize(getD3DFormat()); |
| 53 | } |
| 54 | |
| 55 | unsigned int RenderbufferInterface::getSerial() const |
| 56 | { |
| 57 | return mSerial; |
| 58 | } |
| 59 | |
| 60 | unsigned int RenderbufferInterface::issueSerial() |
| 61 | { |
| 62 | return mCurrentSerial++; |
| 63 | } |
| 64 | |
| 65 | RenderbufferTexture::RenderbufferTexture(Texture *texture, GLenum target) : mTexture(texture), mTarget(target) |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | RenderbufferTexture::~RenderbufferTexture() |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | IDirect3DSurface9 *RenderbufferTexture::getRenderTarget() |
| 74 | { |
| 75 | return mTexture->getRenderTarget(mTarget); |
| 76 | } |
| 77 | |
| 78 | IDirect3DSurface9 *RenderbufferTexture::getDepthStencil() |
| 79 | { |
| 80 | return NULL; |
| 81 | } |
| 82 | |
| 83 | GLsizei RenderbufferTexture::getWidth() const |
| 84 | { |
| 85 | return mTexture->getWidth(); |
| 86 | } |
| 87 | |
| 88 | GLsizei RenderbufferTexture::getHeight() const |
| 89 | { |
| 90 | return mTexture->getHeight(); |
| 91 | } |
| 92 | |
| 93 | GLenum RenderbufferTexture::getInternalFormat() const |
| 94 | { |
| 95 | return mTexture->getInternalFormat(); |
| 96 | } |
| 97 | |
| 98 | GLsizei RenderbufferTexture::getSamples() const |
| 99 | { |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | D3DFORMAT RenderbufferTexture::getD3DFormat() const |
| 104 | { |
| 105 | return mTexture->getD3DFormat(); |
| 106 | } |
| 107 | |
| 108 | Renderbuffer::Renderbuffer(GLuint id, RenderbufferInterface *instance) : RefCountObject(id) |
| 109 | { |
| 110 | ASSERT(instance != NULL); |
| 111 | mInstance = instance; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | Renderbuffer::~Renderbuffer() |
| 115 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 116 | delete mInstance; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | IDirect3DSurface9 *Renderbuffer::getRenderTarget() |
| 120 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 121 | return mInstance->getRenderTarget(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | IDirect3DSurface9 *Renderbuffer::getDepthStencil() |
| 125 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 126 | return mInstance->getDepthStencil(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 127 | } |
| 128 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 129 | GLsizei Renderbuffer::getWidth() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 130 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 131 | return mInstance->getWidth(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 132 | } |
| 133 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 134 | GLsizei Renderbuffer::getHeight() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 135 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 136 | return mInstance->getHeight(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 137 | } |
| 138 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 139 | GLenum Renderbuffer::getInternalFormat() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 140 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 141 | return mInstance->getInternalFormat(); |
| 142 | } |
| 143 | |
| 144 | D3DFORMAT Renderbuffer::getD3DFormat() const |
| 145 | { |
| 146 | return mInstance->getD3DFormat(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 147 | } |
| 148 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 149 | GLuint Renderbuffer::getRedSize() const |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 150 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 151 | return mInstance->getRedSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | GLuint Renderbuffer::getGreenSize() const |
| 155 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 156 | return mInstance->getGreenSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | GLuint Renderbuffer::getBlueSize() const |
| 160 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 161 | return mInstance->getBlueSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | GLuint Renderbuffer::getAlphaSize() const |
| 165 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 166 | return mInstance->getAlphaSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | GLuint Renderbuffer::getDepthSize() const |
| 170 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 171 | return mInstance->getDepthSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | GLuint Renderbuffer::getStencilSize() const |
| 175 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 176 | return mInstance->getStencilSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | GLsizei Renderbuffer::getSamples() const |
| 180 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 181 | return mInstance->getSamples(); |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 182 | } |
| 183 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 184 | unsigned int Renderbuffer::getSerial() const |
| 185 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 186 | return mInstance->getSerial(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | void Renderbuffer::setStorage(RenderbufferStorage *newStorage) |
| 190 | { |
| 191 | ASSERT(newStorage != NULL); |
| 192 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 193 | delete mInstance; |
| 194 | mInstance = newStorage; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 195 | } |
| 196 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 197 | RenderbufferStorage::RenderbufferStorage() |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 198 | { |
daniel@transgaming.com | 73a5db6 | 2010-10-15 17:58:13 +0000 | [diff] [blame] | 199 | mWidth = 0; |
| 200 | mHeight = 0; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 201 | mInternalFormat = GL_RGBA4; |
daniel@transgaming.com | 73a5db6 | 2010-10-15 17:58:13 +0000 | [diff] [blame] | 202 | mD3DFormat = D3DFMT_A8R8G8B8; |
| 203 | mSamples = 0; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | RenderbufferStorage::~RenderbufferStorage() |
| 207 | { |
| 208 | } |
| 209 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 210 | IDirect3DSurface9 *RenderbufferStorage::getRenderTarget() |
| 211 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 212 | return NULL; |
| 213 | } |
| 214 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 215 | IDirect3DSurface9 *RenderbufferStorage::getDepthStencil() |
| 216 | { |
| 217 | return NULL; |
| 218 | } |
| 219 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 220 | GLsizei RenderbufferStorage::getWidth() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 221 | { |
| 222 | return mWidth; |
| 223 | } |
| 224 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 225 | GLsizei RenderbufferStorage::getHeight() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 226 | { |
| 227 | return mHeight; |
| 228 | } |
| 229 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 230 | GLenum RenderbufferStorage::getInternalFormat() const |
daniel@transgaming.com | 866f318 | 2010-05-20 19:28:22 +0000 | [diff] [blame] | 231 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 232 | return mInternalFormat; |
daniel@transgaming.com | 866f318 | 2010-05-20 19:28:22 +0000 | [diff] [blame] | 233 | } |
| 234 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 235 | GLsizei RenderbufferStorage::getSamples() const |
| 236 | { |
| 237 | return mSamples; |
| 238 | } |
| 239 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 240 | D3DFORMAT RenderbufferStorage::getD3DFormat() const |
| 241 | { |
| 242 | return mD3DFormat; |
| 243 | } |
| 244 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 245 | Colorbuffer::Colorbuffer(IDirect3DSurface9 *renderTarget) : mRenderTarget(renderTarget) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 246 | { |
| 247 | if (renderTarget) |
| 248 | { |
| 249 | renderTarget->AddRef(); |
| 250 | |
| 251 | D3DSURFACE_DESC description; |
| 252 | renderTarget->GetDesc(&description); |
| 253 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 254 | mWidth = description.Width; |
| 255 | mHeight = description.Height; |
| 256 | mInternalFormat = dx2es::ConvertBackBufferFormat(description.Format); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 257 | mD3DFormat = description.Format; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 258 | mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 259 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 260 | } |
| 261 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 262 | 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] | 263 | { |
| 264 | IDirect3DDevice9 *device = getDevice(); |
| 265 | |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 266 | D3DFORMAT requestedFormat = es2dx::ConvertRenderbufferFormat(format); |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 267 | int supportedSamples = getContext()->getNearestSupportedSamples(requestedFormat, samples); |
| 268 | |
| 269 | if (supportedSamples == -1) |
| 270 | { |
| 271 | error(GL_OUT_OF_MEMORY); |
| 272 | |
| 273 | return; |
| 274 | } |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 275 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 276 | if (width > 0 && height > 0) |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 277 | { |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 278 | HRESULT result = device->CreateRenderTarget(width, height, requestedFormat, |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 279 | es2dx::GetMultisampleTypeFromSamples(supportedSamples), 0, FALSE, &mRenderTarget, NULL); |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 280 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 281 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 282 | { |
| 283 | error(GL_OUT_OF_MEMORY); |
| 284 | |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 289 | } |
| 290 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 291 | mWidth = width; |
| 292 | mHeight = height; |
| 293 | mInternalFormat = format; |
| 294 | mD3DFormat = requestedFormat; |
| 295 | mSamples = supportedSamples; |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 296 | } |
| 297 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 298 | Colorbuffer::~Colorbuffer() |
| 299 | { |
| 300 | if (mRenderTarget) |
| 301 | { |
| 302 | mRenderTarget->Release(); |
| 303 | } |
| 304 | } |
| 305 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 306 | IDirect3DSurface9 *Colorbuffer::getRenderTarget() |
| 307 | { |
daniel@transgaming.com | 5e4dbb3 | 2011-11-11 04:10:18 +0000 | [diff] [blame^] | 308 | if (mRenderTarget) |
| 309 | { |
| 310 | mRenderTarget->AddRef(); |
| 311 | } |
| 312 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 313 | return mRenderTarget; |
| 314 | } |
| 315 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 316 | DepthStencilbuffer::DepthStencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 317 | { |
| 318 | if (depthStencil) |
| 319 | { |
| 320 | depthStencil->AddRef(); |
| 321 | |
| 322 | D3DSURFACE_DESC description; |
| 323 | depthStencil->GetDesc(&description); |
| 324 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 325 | mWidth = description.Width; |
| 326 | mHeight = description.Height; |
| 327 | mInternalFormat = dx2es::ConvertDepthStencilFormat(description.Format); |
| 328 | mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 329 | mD3DFormat = description.Format; |
| 330 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 331 | } |
| 332 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 333 | DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 334 | { |
| 335 | IDirect3DDevice9 *device = getDevice(); |
| 336 | |
| 337 | mDepthStencil = NULL; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 338 | |
| 339 | int supportedSamples = getContext()->getNearestSupportedSamples(D3DFMT_D24S8, samples); |
| 340 | |
| 341 | if (supportedSamples == -1) |
| 342 | { |
| 343 | error(GL_OUT_OF_MEMORY); |
| 344 | |
| 345 | return; |
| 346 | } |
| 347 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 348 | if (width > 0 && height > 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 349 | { |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 350 | HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples), |
| 351 | 0, FALSE, &mDepthStencil, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 352 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 353 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 354 | { |
| 355 | error(GL_OUT_OF_MEMORY); |
| 356 | |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 361 | } |
| 362 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 363 | mWidth = width; |
| 364 | mHeight = height; |
| 365 | mInternalFormat = GL_DEPTH24_STENCIL8_OES; |
| 366 | mD3DFormat = D3DFMT_D24S8; |
| 367 | mSamples = supportedSamples; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 368 | } |
| 369 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 370 | DepthStencilbuffer::~DepthStencilbuffer() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 371 | { |
| 372 | if (mDepthStencil) |
| 373 | { |
| 374 | mDepthStencil->Release(); |
| 375 | } |
| 376 | } |
| 377 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 378 | IDirect3DSurface9 *DepthStencilbuffer::getDepthStencil() |
| 379 | { |
| 380 | return mDepthStencil; |
| 381 | } |
| 382 | |
| 383 | Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 384 | { |
| 385 | if (depthStencil) |
| 386 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 387 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 388 | // will expect one of the valid renderbuffer formats for use in |
| 389 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 393 | 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] | 394 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 395 | if (mDepthStencil) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 396 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 397 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 398 | // will expect one of the valid renderbuffer formats for use in |
| 399 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
| 403 | Depthbuffer::~Depthbuffer() |
| 404 | { |
| 405 | } |
| 406 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 407 | Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 408 | { |
| 409 | if (depthStencil) |
| 410 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 411 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 412 | // will expect one of the valid renderbuffer formats for use in |
| 413 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 417 | 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] | 418 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 419 | if (mDepthStencil) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 420 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 421 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 422 | // will expect one of the valid renderbuffer formats for use in |
| 423 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
| 427 | Stencilbuffer::~Stencilbuffer() |
| 428 | { |
| 429 | } |
| 430 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 431 | } |