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 | |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 25 | // The default case for classes inherited from RenderbufferInterface is not to |
| 26 | // need to do anything upon the reference count to the parent Renderbuffer incrementing |
| 27 | // or decrementing. |
| 28 | void RenderbufferInterface::addProxyRef(const Renderbuffer *proxy) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | void RenderbufferInterface::releaseProxy(const Renderbuffer *proxy) |
| 33 | { |
| 34 | } |
| 35 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 36 | GLuint RenderbufferInterface::getRedSize() const |
| 37 | { |
| 38 | return dx2es::GetRedSize(getD3DFormat()); |
| 39 | } |
| 40 | |
| 41 | GLuint RenderbufferInterface::getGreenSize() const |
| 42 | { |
| 43 | return dx2es::GetGreenSize(getD3DFormat()); |
| 44 | } |
| 45 | |
| 46 | GLuint RenderbufferInterface::getBlueSize() const |
| 47 | { |
| 48 | return dx2es::GetBlueSize(getD3DFormat()); |
| 49 | } |
| 50 | |
| 51 | GLuint RenderbufferInterface::getAlphaSize() const |
| 52 | { |
| 53 | return dx2es::GetAlphaSize(getD3DFormat()); |
| 54 | } |
| 55 | |
| 56 | GLuint RenderbufferInterface::getDepthSize() const |
| 57 | { |
| 58 | return dx2es::GetDepthSize(getD3DFormat()); |
| 59 | } |
| 60 | |
| 61 | GLuint RenderbufferInterface::getStencilSize() const |
| 62 | { |
| 63 | return dx2es::GetStencilSize(getD3DFormat()); |
| 64 | } |
| 65 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 66 | ///// RenderbufferTexture2D Implementation //////// |
| 67 | |
| 68 | RenderbufferTexture2D::RenderbufferTexture2D(Texture2D *texture, GLenum target) : mTarget(target) |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 69 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 70 | mTexture2D.set(texture); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 71 | } |
| 72 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 73 | RenderbufferTexture2D::~RenderbufferTexture2D() |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 74 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 75 | mTexture2D.set(NULL); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 76 | } |
| 77 | |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 78 | // Textures need to maintain their own reference count for references via |
| 79 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 80 | void RenderbufferTexture2D::addProxyRef(const Renderbuffer *proxy) |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 81 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 82 | mTexture2D->addProxyRef(proxy); |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 83 | } |
| 84 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 85 | void RenderbufferTexture2D::releaseProxy(const Renderbuffer *proxy) |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 86 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 87 | mTexture2D->releaseProxy(proxy); |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 88 | } |
| 89 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 90 | // Increments refcount on surface. |
| 91 | // caller must Release() the returned surface |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 92 | IDirect3DSurface9 *RenderbufferTexture2D::getRenderTarget() |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 93 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 94 | return mTexture2D->getRenderTarget(mTarget); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 95 | } |
| 96 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 97 | // Increments refcount on surface. |
| 98 | // caller must Release() the returned surface |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 99 | IDirect3DSurface9 *RenderbufferTexture2D::getDepthStencil() |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 100 | { |
daniel@transgaming.com | 68145c6 | 2012-05-31 01:14:46 +0000 | [diff] [blame] | 101 | return mTexture2D->getDepthStencil(mTarget); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 102 | } |
| 103 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 104 | GLsizei RenderbufferTexture2D::getWidth() const |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 105 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 106 | return mTexture2D->getWidth(0); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 107 | } |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 108 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 109 | GLsizei RenderbufferTexture2D::getHeight() const |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 110 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 111 | return mTexture2D->getHeight(0); |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 112 | } |
| 113 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 114 | GLenum RenderbufferTexture2D::getInternalFormat() const |
| 115 | { |
daniel@transgaming.com | 92f4992 | 2012-05-09 15:49:19 +0000 | [diff] [blame] | 116 | return mTexture2D->getInternalFormat(0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | D3DFORMAT RenderbufferTexture2D::getD3DFormat() const |
| 120 | { |
daniel@transgaming.com | 92f4992 | 2012-05-09 15:49:19 +0000 | [diff] [blame] | 121 | return mTexture2D->getD3DFormat(0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | GLsizei RenderbufferTexture2D::getSamples() const |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 129 | unsigned int RenderbufferTexture2D::getSerial() const |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 130 | { |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 131 | return mTexture2D->getRenderTargetSerial(mTarget); |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 132 | } |
| 133 | |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 134 | ///// RenderbufferTextureCubeMap Implementation //////// |
| 135 | |
| 136 | RenderbufferTextureCubeMap::RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target) : mTarget(target) |
| 137 | { |
| 138 | mTextureCubeMap.set(texture); |
| 139 | } |
| 140 | |
| 141 | RenderbufferTextureCubeMap::~RenderbufferTextureCubeMap() |
| 142 | { |
| 143 | mTextureCubeMap.set(NULL); |
| 144 | } |
| 145 | |
| 146 | // Textures need to maintain their own reference count for references via |
| 147 | // Renderbuffers acting as proxies. Here, we notify the texture of a reference. |
| 148 | void RenderbufferTextureCubeMap::addProxyRef(const Renderbuffer *proxy) |
| 149 | { |
| 150 | mTextureCubeMap->addProxyRef(proxy); |
| 151 | } |
| 152 | |
| 153 | void RenderbufferTextureCubeMap::releaseProxy(const Renderbuffer *proxy) |
| 154 | { |
| 155 | mTextureCubeMap->releaseProxy(proxy); |
| 156 | } |
| 157 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 158 | // Increments refcount on surface. |
| 159 | // caller must Release() the returned surface |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 160 | IDirect3DSurface9 *RenderbufferTextureCubeMap::getRenderTarget() |
| 161 | { |
| 162 | return mTextureCubeMap->getRenderTarget(mTarget); |
| 163 | } |
| 164 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 165 | // Increments refcount on surface. |
| 166 | // caller must Release() the returned surface |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 167 | IDirect3DSurface9 *RenderbufferTextureCubeMap::getDepthStencil() |
| 168 | { |
| 169 | return NULL; |
| 170 | } |
| 171 | |
| 172 | GLsizei RenderbufferTextureCubeMap::getWidth() const |
| 173 | { |
daniel@transgaming.com | 4df88e8 | 2012-05-09 15:49:24 +0000 | [diff] [blame] | 174 | return mTextureCubeMap->getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | GLsizei RenderbufferTextureCubeMap::getHeight() const |
| 178 | { |
daniel@transgaming.com | 4df88e8 | 2012-05-09 15:49:24 +0000 | [diff] [blame] | 179 | return mTextureCubeMap->getHeight(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | GLenum RenderbufferTextureCubeMap::getInternalFormat() const |
| 183 | { |
daniel@transgaming.com | 4df88e8 | 2012-05-09 15:49:24 +0000 | [diff] [blame] | 184 | return mTextureCubeMap->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | D3DFORMAT RenderbufferTextureCubeMap::getD3DFormat() const |
| 188 | { |
daniel@transgaming.com | 4df88e8 | 2012-05-09 15:49:24 +0000 | [diff] [blame] | 189 | return mTextureCubeMap->getD3DFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
daniel@transgaming.com | 46f2d0a | 2012-05-09 15:49:06 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | GLsizei RenderbufferTextureCubeMap::getSamples() const |
| 193 | { |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | unsigned int RenderbufferTextureCubeMap::getSerial() const |
| 198 | { |
| 199 | return mTextureCubeMap->getRenderTargetSerial(mTarget); |
| 200 | } |
| 201 | |
| 202 | ////// Renderbuffer Implementation ////// |
| 203 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 204 | Renderbuffer::Renderbuffer(GLuint id, RenderbufferInterface *instance) : RefCountObject(id) |
| 205 | { |
| 206 | ASSERT(instance != NULL); |
| 207 | mInstance = instance; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | Renderbuffer::~Renderbuffer() |
| 211 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 212 | delete mInstance; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 213 | } |
| 214 | |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 215 | // The RenderbufferInterface contained in this Renderbuffer may need to maintain |
| 216 | // its own reference count, so we pass it on here. |
| 217 | void Renderbuffer::addRef() const |
| 218 | { |
| 219 | mInstance->addProxyRef(this); |
| 220 | |
| 221 | RefCountObject::addRef(); |
| 222 | } |
| 223 | |
| 224 | void Renderbuffer::release() const |
| 225 | { |
| 226 | mInstance->releaseProxy(this); |
| 227 | |
| 228 | RefCountObject::release(); |
| 229 | } |
| 230 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 231 | // Increments refcount on surface. |
| 232 | // caller must Release() the returned surface |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 233 | IDirect3DSurface9 *Renderbuffer::getRenderTarget() |
| 234 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 235 | return mInstance->getRenderTarget(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 236 | } |
| 237 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 238 | // Increments refcount on surface. |
| 239 | // caller must Release() the returned surface |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 240 | IDirect3DSurface9 *Renderbuffer::getDepthStencil() |
| 241 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 242 | return mInstance->getDepthStencil(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 243 | } |
| 244 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 245 | GLsizei Renderbuffer::getWidth() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 246 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 247 | return mInstance->getWidth(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 248 | } |
| 249 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 250 | GLsizei Renderbuffer::getHeight() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 251 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 252 | return mInstance->getHeight(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 253 | } |
| 254 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 255 | GLenum Renderbuffer::getInternalFormat() const |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 256 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 257 | return mInstance->getInternalFormat(); |
| 258 | } |
| 259 | |
| 260 | D3DFORMAT Renderbuffer::getD3DFormat() const |
| 261 | { |
| 262 | return mInstance->getD3DFormat(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 263 | } |
| 264 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 265 | GLuint Renderbuffer::getRedSize() const |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 266 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 267 | return mInstance->getRedSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | GLuint Renderbuffer::getGreenSize() const |
| 271 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 272 | return mInstance->getGreenSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | GLuint Renderbuffer::getBlueSize() const |
| 276 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 277 | return mInstance->getBlueSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | GLuint Renderbuffer::getAlphaSize() const |
| 281 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 282 | return mInstance->getAlphaSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | GLuint Renderbuffer::getDepthSize() const |
| 286 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 287 | return mInstance->getDepthSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | GLuint Renderbuffer::getStencilSize() const |
| 291 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 292 | return mInstance->getStencilSize(); |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | GLsizei Renderbuffer::getSamples() const |
| 296 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 297 | return mInstance->getSamples(); |
daniel@transgaming.com | 4cbc590 | 2010-08-24 19:20:26 +0000 | [diff] [blame] | 298 | } |
| 299 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 300 | unsigned int Renderbuffer::getSerial() const |
| 301 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 302 | return mInstance->getSerial(); |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void Renderbuffer::setStorage(RenderbufferStorage *newStorage) |
| 306 | { |
| 307 | ASSERT(newStorage != NULL); |
| 308 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 309 | delete mInstance; |
| 310 | mInstance = newStorage; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 311 | } |
| 312 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 313 | RenderbufferStorage::RenderbufferStorage() : mSerial(issueSerial()) |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 314 | { |
daniel@transgaming.com | 73a5db6 | 2010-10-15 17:58:13 +0000 | [diff] [blame] | 315 | mWidth = 0; |
| 316 | mHeight = 0; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 317 | mInternalFormat = GL_RGBA4; |
daniel@transgaming.com | 73a5db6 | 2010-10-15 17:58:13 +0000 | [diff] [blame] | 318 | mD3DFormat = D3DFMT_A8R8G8B8; |
| 319 | mSamples = 0; |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | RenderbufferStorage::~RenderbufferStorage() |
| 323 | { |
| 324 | } |
| 325 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 326 | // Increments refcount on surface. |
| 327 | // caller must Release() the returned surface |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 328 | IDirect3DSurface9 *RenderbufferStorage::getRenderTarget() |
| 329 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 330 | return NULL; |
| 331 | } |
| 332 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 333 | // Increments refcount on surface. |
| 334 | // caller must Release() the returned surface |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 335 | IDirect3DSurface9 *RenderbufferStorage::getDepthStencil() |
| 336 | { |
| 337 | return NULL; |
| 338 | } |
| 339 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 340 | GLsizei RenderbufferStorage::getWidth() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 341 | { |
| 342 | return mWidth; |
| 343 | } |
| 344 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 345 | GLsizei RenderbufferStorage::getHeight() const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 346 | { |
| 347 | return mHeight; |
| 348 | } |
| 349 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 350 | GLenum RenderbufferStorage::getInternalFormat() const |
daniel@transgaming.com | 866f318 | 2010-05-20 19:28:22 +0000 | [diff] [blame] | 351 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 352 | return mInternalFormat; |
daniel@transgaming.com | 866f318 | 2010-05-20 19:28:22 +0000 | [diff] [blame] | 353 | } |
| 354 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 355 | D3DFORMAT RenderbufferStorage::getD3DFormat() const |
| 356 | { |
| 357 | return mD3DFormat; |
| 358 | } |
| 359 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 360 | GLsizei RenderbufferStorage::getSamples() const |
| 361 | { |
| 362 | return mSamples; |
| 363 | } |
| 364 | |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 365 | unsigned int RenderbufferStorage::getSerial() const |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 366 | { |
daniel@transgaming.com | fbc3952 | 2011-11-11 04:10:28 +0000 | [diff] [blame] | 367 | return mSerial; |
| 368 | } |
| 369 | |
| 370 | unsigned int RenderbufferStorage::issueSerial() |
| 371 | { |
| 372 | return mCurrentSerial++; |
| 373 | } |
| 374 | |
| 375 | unsigned int RenderbufferStorage::issueCubeSerials() |
| 376 | { |
| 377 | unsigned int firstSerial = mCurrentSerial; |
| 378 | mCurrentSerial += 6; |
| 379 | return firstSerial; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 380 | } |
| 381 | |
daniel@transgaming.com | 96c3893 | 2012-10-31 18:42:52 +0000 | [diff] [blame^] | 382 | Colorbuffer::Colorbuffer(renderer::SwapChain *swapChain) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 383 | { |
daniel@transgaming.com | 96c3893 | 2012-10-31 18:42:52 +0000 | [diff] [blame^] | 384 | mRenderTarget = swapChain->getRenderTarget(); |
| 385 | if (mRenderTarget) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 386 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 387 | D3DSURFACE_DESC description; |
daniel@transgaming.com | 96c3893 | 2012-10-31 18:42:52 +0000 | [diff] [blame^] | 388 | mRenderTarget->GetDesc(&description); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 389 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 390 | mWidth = description.Width; |
| 391 | mHeight = description.Height; |
| 392 | mInternalFormat = dx2es::ConvertBackBufferFormat(description.Format); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 393 | mD3DFormat = description.Format; |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 394 | mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 395 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 396 | } |
| 397 | |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 398 | 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] | 399 | { |
daniel@transgaming.com | 06eef17 | 2012-10-31 18:31:50 +0000 | [diff] [blame] | 400 | renderer::Renderer *renderer = getDisplay()->getRenderer(); |
| 401 | IDirect3DDevice9 *device = renderer->getDevice(); // D3D9_REPLACE |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 402 | |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 403 | D3DFORMAT requestedFormat = es2dx::ConvertRenderbufferFormat(format); |
daniel@transgaming.com | 06eef17 | 2012-10-31 18:31:50 +0000 | [diff] [blame] | 404 | int supportedSamples = renderer->getNearestSupportedSamples(requestedFormat, samples); |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 405 | |
| 406 | if (supportedSamples == -1) |
| 407 | { |
| 408 | error(GL_OUT_OF_MEMORY); |
| 409 | |
| 410 | return; |
| 411 | } |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 412 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 413 | if (width > 0 && height > 0) |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 414 | { |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 415 | HRESULT result = device->CreateRenderTarget(width, height, requestedFormat, |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 416 | es2dx::GetMultisampleTypeFromSamples(supportedSamples), 0, FALSE, &mRenderTarget, NULL); |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 417 | |
daniel@transgaming.com | 9ecb9f9 | 2010-07-28 19:21:12 +0000 | [diff] [blame] | 418 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 419 | { |
| 420 | error(GL_OUT_OF_MEMORY); |
| 421 | |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 426 | } |
| 427 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 428 | mWidth = width; |
| 429 | mHeight = height; |
| 430 | mInternalFormat = format; |
| 431 | mD3DFormat = requestedFormat; |
| 432 | mSamples = supportedSamples; |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame] | 433 | } |
| 434 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 435 | Colorbuffer::~Colorbuffer() |
| 436 | { |
| 437 | if (mRenderTarget) |
| 438 | { |
| 439 | mRenderTarget->Release(); |
| 440 | } |
| 441 | } |
| 442 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 443 | // Increments refcount on surface. |
| 444 | // caller must Release() the returned surface |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 445 | IDirect3DSurface9 *Colorbuffer::getRenderTarget() |
| 446 | { |
daniel@transgaming.com | 5e4dbb3 | 2011-11-11 04:10:18 +0000 | [diff] [blame] | 447 | if (mRenderTarget) |
| 448 | { |
| 449 | mRenderTarget->AddRef(); |
| 450 | } |
| 451 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 452 | return mRenderTarget; |
| 453 | } |
| 454 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 455 | DepthStencilbuffer::DepthStencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 456 | { |
| 457 | if (depthStencil) |
| 458 | { |
| 459 | depthStencil->AddRef(); |
| 460 | |
| 461 | D3DSURFACE_DESC description; |
| 462 | depthStencil->GetDesc(&description); |
| 463 | |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 464 | mWidth = description.Width; |
| 465 | mHeight = description.Height; |
| 466 | mInternalFormat = dx2es::ConvertDepthStencilFormat(description.Format); |
| 467 | mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType); |
daniel@transgaming.com | ca7c008 | 2010-08-24 19:20:20 +0000 | [diff] [blame] | 468 | mD3DFormat = description.Format; |
| 469 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 470 | } |
| 471 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 472 | DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 473 | { |
daniel@transgaming.com | 06eef17 | 2012-10-31 18:31:50 +0000 | [diff] [blame] | 474 | renderer::Renderer *renderer = getDisplay()->getRenderer(); |
| 475 | IDirect3DDevice9 *device = renderer->getDevice(); // D3D9_REPLACE |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 476 | |
| 477 | mDepthStencil = NULL; |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 478 | |
daniel@transgaming.com | 06eef17 | 2012-10-31 18:31:50 +0000 | [diff] [blame] | 479 | int supportedSamples = renderer->getNearestSupportedSamples(D3DFMT_D24S8, samples); |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 480 | |
| 481 | if (supportedSamples == -1) |
| 482 | { |
| 483 | error(GL_OUT_OF_MEMORY); |
| 484 | |
| 485 | return; |
| 486 | } |
| 487 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 488 | if (width > 0 && height > 0) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 489 | { |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 490 | HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples), |
| 491 | 0, FALSE, &mDepthStencil, 0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 492 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 493 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 494 | { |
| 495 | error(GL_OUT_OF_MEMORY); |
| 496 | |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 501 | } |
| 502 | |
apatrick@chromium.org | 831fe2a | 2011-03-17 18:44:29 +0000 | [diff] [blame] | 503 | mWidth = width; |
| 504 | mHeight = height; |
| 505 | mInternalFormat = GL_DEPTH24_STENCIL8_OES; |
| 506 | mD3DFormat = D3DFMT_D24S8; |
| 507 | mSamples = supportedSamples; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 508 | } |
| 509 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 510 | DepthStencilbuffer::~DepthStencilbuffer() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 511 | { |
| 512 | if (mDepthStencil) |
| 513 | { |
| 514 | mDepthStencil->Release(); |
| 515 | } |
| 516 | } |
| 517 | |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 518 | // Increments refcount on surface. |
| 519 | // caller must Release() the returned surface |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 520 | IDirect3DSurface9 *DepthStencilbuffer::getDepthStencil() |
| 521 | { |
daniel@transgaming.com | 63e6afe | 2012-05-31 01:14:42 +0000 | [diff] [blame] | 522 | if (mDepthStencil) |
| 523 | { |
| 524 | mDepthStencil->AddRef(); |
| 525 | } |
| 526 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 527 | return mDepthStencil; |
| 528 | } |
| 529 | |
| 530 | Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 531 | { |
| 532 | if (depthStencil) |
| 533 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 534 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 535 | // will expect one of the valid renderbuffer formats for use in |
| 536 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 540 | 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] | 541 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 542 | if (mDepthStencil) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 543 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 544 | mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function |
| 545 | // will expect one of the valid renderbuffer formats for use in |
| 546 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
| 550 | Depthbuffer::~Depthbuffer() |
| 551 | { |
| 552 | } |
| 553 | |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 554 | Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil) |
| 555 | { |
| 556 | if (depthStencil) |
| 557 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 558 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 559 | // will expect one of the valid renderbuffer formats for use in |
| 560 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
daniel@transgaming.com | 1f135d8 | 2010-08-24 19:20:36 +0000 | [diff] [blame] | 564 | 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] | 565 | { |
daniel@transgaming.com | d14558a | 2011-11-09 17:46:18 +0000 | [diff] [blame] | 566 | if (mDepthStencil) |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 567 | { |
daniel@transgaming.com | d2fd4f2 | 2011-02-01 18:49:11 +0000 | [diff] [blame] | 568 | mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function |
| 569 | // will expect one of the valid renderbuffer formats for use in |
| 570 | // glRenderbufferStorage |
daniel@transgaming.com | cdacc8e | 2010-07-28 19:20:50 +0000 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
| 574 | Stencilbuffer::~Stencilbuffer() |
| 575 | { |
| 576 | } |
| 577 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 578 | } |