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