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