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