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 | { |
| 308 | return mRenderTarget; |
| 309 | } |
| 310 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 311 | DepthStencilbuffer::DepthStencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 312 | { |
| 313 | if (depthStencil) |
| 314 | { |
| 315 | depthStencil->AddRef(); |
| 316 | |
| 317 | D3DSURFACE_DESC description; |
| 318 | depthStencil->GetDesc(&description); |
| 319 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 320 | mWidth = description.Width; |
| 321 | mHeight = description.Height; |
| 322 | mInternalFormat = dx2es::ConvertDepthStencilFormat(description.Format); |
| 323 | mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 324 | mD3DFormat = description.Format; |
| 325 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 326 | } |
| 327 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 328 | DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 329 | { |
| 330 | IDirect3DDevice9 *device = getDevice(); |
| 331 | |
| 332 | mDepthStencil = NULL; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 333 | |
| 334 | int supportedSamples = getContext()->getNearestSupportedSamples(D3DFMT_D24S8, samples); |
| 335 | |
| 336 | if (supportedSamples == -1) |
| 337 | { |
| 338 | error(GL_OUT_OF_MEMORY); |
| 339 | |
| 340 | return; |
| 341 | } |
| 342 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 343 | if (width > 0 && height > 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 344 | { |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 345 | HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples), |
| 346 | 0, FALSE, &mDepthStencil, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 347 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 348 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 349 | { |
| 350 | error(GL_OUT_OF_MEMORY); |
| 351 | |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 356 | } |
| 357 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 358 | mWidth = width; |
| 359 | mHeight = height; |
| 360 | mInternalFormat = GL_DEPTH24_STENCIL8_OES; |
| 361 | mD3DFormat = D3DFMT_D24S8; |
| 362 | mSamples = supportedSamples; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 363 | } |
| 364 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 365 | DepthStencilbuffer::~DepthStencilbuffer() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 366 | { |
| 367 | if (mDepthStencil) |
| 368 | { |
| 369 | mDepthStencil->Release(); |
| 370 | } |
| 371 | } |
| 372 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 373 | IDirect3DSurface9 *DepthStencilbuffer::getDepthStencil() |
| 374 | { |
| 375 | return mDepthStencil; |
| 376 | } |
| 377 | |
| 378 | Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 379 | { |
| 380 | if (depthStencil) |
| 381 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 382 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 383 | // will expect one of the valid renderbuffer formats for use in |
| 384 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 388 | 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] | 389 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 390 | if (mDepthStencil) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 391 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 392 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 393 | // will expect one of the valid renderbuffer formats for use in |
| 394 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
| 398 | Depthbuffer::~Depthbuffer() |
| 399 | { |
| 400 | } |
| 401 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 402 | Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 403 | { |
| 404 | if (depthStencil) |
| 405 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 406 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 407 | // will expect one of the valid renderbuffer formats for use in |
| 408 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 412 | 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] | 413 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 414 | if (mDepthStencil) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 415 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 416 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 417 | // will expect one of the valid renderbuffer formats for use in |
| 418 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
| 422 | Stencilbuffer::~Stencilbuffer() |
| 423 | { |
| 424 | } |
| 425 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 426 | } |