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 | |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 283 | if (mRenderTarget) |
| 284 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 285 | mWidth = width; |
| 286 | mHeight = height; |
| 287 | mInternalFormat = format; |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 288 | mD3DFormat = requestedFormat; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 289 | mSamples = supportedSamples; |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 290 | } |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 291 | } |
| 292 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 293 | Colorbuffer::~Colorbuffer() |
| 294 | { |
| 295 | if (mRenderTarget) |
| 296 | { |
| 297 | mRenderTarget->Release(); |
| 298 | } |
| 299 | } |
| 300 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 301 | GLsizei Colorbuffer::getWidth() const |
| 302 | { |
| 303 | if (mTexture) |
| 304 | { |
| 305 | return mTexture->getWidth(); |
| 306 | } |
| 307 | |
| 308 | return mWidth; |
| 309 | } |
| 310 | |
| 311 | GLsizei Colorbuffer::getHeight() const |
| 312 | { |
| 313 | if (mTexture) |
| 314 | { |
| 315 | return mTexture->getHeight(); |
| 316 | } |
| 317 | |
| 318 | return mHeight; |
| 319 | } |
| 320 | |
| 321 | GLenum Colorbuffer::getInternalFormat() const |
| 322 | { |
| 323 | if (mTexture) |
| 324 | { |
| 325 | return mTexture->getInternalFormat(); |
| 326 | } |
| 327 | |
| 328 | return mInternalFormat; |
| 329 | } |
| 330 | |
| 331 | D3DFORMAT Colorbuffer::getD3DFormat() const |
| 332 | { |
| 333 | if (mTexture) |
| 334 | { |
| 335 | return mTexture->getD3DFormat(); |
| 336 | } |
| 337 | |
| 338 | return mD3DFormat; |
| 339 | } |
| 340 | |
| 341 | bool Colorbuffer::isFloatingPoint() const |
| 342 | { |
| 343 | if (mTexture) |
| 344 | { |
| 345 | return mTexture->isFloatingPoint(); |
| 346 | } |
| 347 | |
| 348 | return false; |
| 349 | } |
| 350 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 351 | bool Colorbuffer::isColorbuffer() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 352 | { |
| 353 | return true; |
| 354 | } |
| 355 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 356 | IDirect3DSurface9 *Colorbuffer::getRenderTarget() |
| 357 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 358 | if (mTexture) |
| 359 | { |
| 360 | if (mRenderTarget) |
| 361 | { |
| 362 | mRenderTarget->Release(); |
| 363 | } |
| 364 | |
| 365 | mRenderTarget = mTexture->getRenderTarget(mTarget); |
| 366 | } |
| 367 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 368 | return mRenderTarget; |
| 369 | } |
| 370 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 371 | DepthStencilbuffer::DepthStencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 372 | { |
| 373 | if (depthStencil) |
| 374 | { |
| 375 | depthStencil->AddRef(); |
| 376 | |
| 377 | D3DSURFACE_DESC description; |
| 378 | depthStencil->GetDesc(&description); |
| 379 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 380 | mWidth = description.Width; |
| 381 | mHeight = description.Height; |
| 382 | mInternalFormat = dx2es::ConvertDepthStencilFormat(description.Format); |
| 383 | mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 384 | mD3DFormat = description.Format; |
| 385 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 386 | } |
| 387 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 388 | DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 389 | { |
| 390 | IDirect3DDevice9 *device = getDevice(); |
| 391 | |
| 392 | mDepthStencil = NULL; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 393 | |
| 394 | int supportedSamples = getContext()->getNearestSupportedSamples(D3DFMT_D24S8, samples); |
| 395 | |
| 396 | if (supportedSamples == -1) |
| 397 | { |
| 398 | error(GL_OUT_OF_MEMORY); |
| 399 | |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples), |
| 404 | 0, FALSE, &mDepthStencil, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 405 | |
| 406 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 407 | { |
| 408 | error(GL_OUT_OF_MEMORY); |
| 409 | |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | ASSERT(SUCCEEDED(result)); |
| 414 | |
| 415 | if (mDepthStencil) |
| 416 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 417 | mWidth = width; |
| 418 | mHeight = height; |
| 419 | mInternalFormat = GL_DEPTH24_STENCIL8_OES; |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 420 | mD3DFormat = D3DFMT_D24S8; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 421 | mSamples = supportedSamples; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 422 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 423 | } |
| 424 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 425 | DepthStencilbuffer::~DepthStencilbuffer() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 426 | { |
| 427 | if (mDepthStencil) |
| 428 | { |
| 429 | mDepthStencil->Release(); |
| 430 | } |
| 431 | } |
| 432 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 433 | bool DepthStencilbuffer::isDepthbuffer() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 434 | { |
| 435 | return true; |
| 436 | } |
| 437 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 438 | bool DepthStencilbuffer::isStencilbuffer() const |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 439 | { |
| 440 | return true; |
| 441 | } |
| 442 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 443 | IDirect3DSurface9 *DepthStencilbuffer::getDepthStencil() |
| 444 | { |
| 445 | return mDepthStencil; |
| 446 | } |
| 447 | |
| 448 | Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 449 | { |
| 450 | if (depthStencil) |
| 451 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 452 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 453 | // will expect one of the valid renderbuffer formats for use in |
| 454 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 458 | 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] | 459 | { |
| 460 | if (getDepthStencil()) |
| 461 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 462 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 463 | // will expect one of the valid renderbuffer formats for use in |
| 464 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
| 468 | Depthbuffer::~Depthbuffer() |
| 469 | { |
| 470 | } |
| 471 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 472 | bool Depthbuffer::isDepthbuffer() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 473 | { |
| 474 | return true; |
| 475 | } |
| 476 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 477 | bool Depthbuffer::isStencilbuffer() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 478 | { |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 479 | return false; |
| 480 | } |
| 481 | |
| 482 | Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 483 | { |
| 484 | if (depthStencil) |
| 485 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 486 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 487 | // will expect one of the valid renderbuffer formats for use in |
| 488 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 492 | 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] | 493 | { |
| 494 | if (getDepthStencil()) |
| 495 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame^] | 496 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 497 | // will expect one of the valid renderbuffer formats for use in |
| 498 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
| 502 | Stencilbuffer::~Stencilbuffer() |
| 503 | { |
| 504 | } |
| 505 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 506 | bool Stencilbuffer::isDepthbuffer() const |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 507 | { |
| 508 | return false; |
| 509 | } |
| 510 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 511 | bool Stencilbuffer::isStencilbuffer() const |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 512 | { |
| 513 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 514 | } |
| 515 | } |