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" |
| 14 | #include "libGLESv2/utilities.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 15 | |
| 16 | namespace gl |
| 17 | { |
| 18 | Renderbuffer::Renderbuffer() |
| 19 | { |
| 20 | mWidth = 0; |
| 21 | mHeight = 0; |
| 22 | } |
| 23 | |
| 24 | Renderbuffer::~Renderbuffer() |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | bool Renderbuffer::isColorbuffer() |
| 29 | { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | bool Renderbuffer::isDepthbuffer() |
| 34 | { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | bool Renderbuffer::isStencilbuffer() |
| 39 | { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | IDirect3DSurface9 *Renderbuffer::getRenderTarget() |
| 44 | { |
| 45 | return NULL; |
| 46 | } |
| 47 | |
| 48 | IDirect3DSurface9 *Renderbuffer::getDepthStencil() |
| 49 | { |
| 50 | return NULL; |
| 51 | } |
| 52 | |
| 53 | int Renderbuffer::getWidth() |
| 54 | { |
| 55 | return mWidth; |
| 56 | } |
| 57 | |
| 58 | int Renderbuffer::getHeight() |
| 59 | { |
| 60 | return mHeight; |
| 61 | } |
| 62 | |
| 63 | Colorbuffer::Colorbuffer(IDirect3DSurface9 *renderTarget) : mRenderTarget(renderTarget) |
| 64 | { |
| 65 | if (renderTarget) |
| 66 | { |
| 67 | renderTarget->AddRef(); |
| 68 | |
| 69 | D3DSURFACE_DESC description; |
| 70 | renderTarget->GetDesc(&description); |
| 71 | |
| 72 | mWidth = description.Width; |
| 73 | mHeight = description.Height; |
| 74 | } |
| 75 | } |
| 76 | |
daniel@transgaming.com | 70d312a | 2010-04-20 18:52:38 +0000 | [diff] [blame^] | 77 | Colorbuffer::Colorbuffer(int width, int height, GLenum format) |
| 78 | { |
| 79 | IDirect3DDevice9 *device = getDevice(); |
| 80 | |
| 81 | mRenderTarget = NULL; |
| 82 | HRESULT result = device->CreateRenderTarget(width, height, es2dx::ConvertRenderbufferFormat(format), |
| 83 | D3DMULTISAMPLE_NONE, 0, FALSE, &mRenderTarget, NULL); |
| 84 | |
| 85 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 86 | { |
| 87 | error(GL_OUT_OF_MEMORY); |
| 88 | |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | ASSERT(SUCCEEDED(result)); |
| 93 | |
| 94 | if (mRenderTarget) |
| 95 | { |
| 96 | mWidth = width; |
| 97 | mHeight = height; |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | mWidth = 0; |
| 102 | mHeight = 0; |
| 103 | } |
| 104 | } |
| 105 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 106 | Colorbuffer::~Colorbuffer() |
| 107 | { |
| 108 | if (mRenderTarget) |
| 109 | { |
| 110 | mRenderTarget->Release(); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | bool Colorbuffer::isColorbuffer() |
| 115 | { |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | GLuint Colorbuffer::getRedSize() |
| 120 | { |
| 121 | if (mRenderTarget) |
| 122 | { |
| 123 | D3DSURFACE_DESC description; |
| 124 | mRenderTarget->GetDesc(&description); |
| 125 | |
| 126 | return es2dx::GetRedSize(description.Format); |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | GLuint Colorbuffer::getGreenSize() |
| 133 | { |
| 134 | if (mRenderTarget) |
| 135 | { |
| 136 | D3DSURFACE_DESC description; |
| 137 | mRenderTarget->GetDesc(&description); |
| 138 | |
| 139 | return es2dx::GetGreenSize(description.Format); |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | GLuint Colorbuffer::getBlueSize() |
| 146 | { |
| 147 | if (mRenderTarget) |
| 148 | { |
| 149 | D3DSURFACE_DESC description; |
| 150 | mRenderTarget->GetDesc(&description); |
| 151 | |
| 152 | return es2dx::GetBlueSize(description.Format); |
| 153 | } |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | GLuint Colorbuffer::getAlphaSize() |
| 159 | { |
| 160 | if (mRenderTarget) |
| 161 | { |
| 162 | D3DSURFACE_DESC description; |
| 163 | mRenderTarget->GetDesc(&description); |
| 164 | |
| 165 | return es2dx::GetAlphaSize(description.Format); |
| 166 | } |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | IDirect3DSurface9 *Colorbuffer::getRenderTarget() |
| 172 | { |
| 173 | return mRenderTarget; |
| 174 | } |
| 175 | |
| 176 | Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) |
| 177 | { |
| 178 | if (depthStencil) |
| 179 | { |
| 180 | depthStencil->AddRef(); |
| 181 | |
| 182 | D3DSURFACE_DESC description; |
| 183 | depthStencil->GetDesc(&description); |
| 184 | |
| 185 | mWidth = description.Width; |
| 186 | mHeight = description.Height; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | Depthbuffer::Depthbuffer(int width, int height) |
| 191 | { |
| 192 | IDirect3DDevice9 *device = getDevice(); |
| 193 | |
| 194 | mDepthStencil = NULL; |
| 195 | HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0); |
| 196 | |
| 197 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 198 | { |
| 199 | error(GL_OUT_OF_MEMORY); |
| 200 | |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | ASSERT(SUCCEEDED(result)); |
| 205 | |
| 206 | if (mDepthStencil) |
| 207 | { |
| 208 | mWidth = width; |
| 209 | mHeight = height; |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | mWidth = 0; |
| 214 | mHeight = 0; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | Depthbuffer::~Depthbuffer() |
| 219 | { |
| 220 | if (mDepthStencil) |
| 221 | { |
| 222 | mDepthStencil->Release(); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | bool Depthbuffer::isDepthbuffer() |
| 227 | { |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | GLuint Depthbuffer::getDepthSize() |
| 232 | { |
| 233 | if (mDepthStencil) |
| 234 | { |
| 235 | D3DSURFACE_DESC description; |
| 236 | mDepthStencil->GetDesc(&description); |
| 237 | |
daniel@transgaming.com | 7a2c280 | 2010-03-16 06:23:33 +0000 | [diff] [blame] | 238 | return es2dx::GetDepthSize(description.Format); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | IDirect3DSurface9 *Depthbuffer::getDepthStencil() |
| 245 | { |
| 246 | return mDepthStencil; |
| 247 | } |
| 248 | |
| 249 | Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil) |
daniel@transgaming.com | 4a9d65c | 2010-03-08 21:30:56 +0000 | [diff] [blame] | 250 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 251 | if (depthStencil) |
| 252 | { |
| 253 | depthStencil->AddRef(); |
| 254 | |
| 255 | D3DSURFACE_DESC description; |
| 256 | depthStencil->GetDesc(&description); |
| 257 | |
| 258 | mWidth = description.Width; |
| 259 | mHeight = description.Height; |
| 260 | } |
daniel@transgaming.com | 4a9d65c | 2010-03-08 21:30:56 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | Stencilbuffer::Stencilbuffer(int width, int height) |
| 264 | { |
| 265 | IDirect3DDevice9 *device = getDevice(); |
| 266 | |
| 267 | mDepthStencil = NULL; |
| 268 | HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0); |
| 269 | |
| 270 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) |
| 271 | { |
| 272 | error(GL_OUT_OF_MEMORY); |
| 273 | |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | ASSERT(SUCCEEDED(result)); |
| 278 | |
| 279 | if (mDepthStencil) |
| 280 | { |
| 281 | mWidth = width; |
| 282 | mHeight = height; |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | mWidth = 0; |
| 287 | mHeight = 0; |
| 288 | } |
| 289 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 290 | |
| 291 | Stencilbuffer::~Stencilbuffer() |
| 292 | { |
| 293 | if (mDepthStencil) |
| 294 | { |
| 295 | mDepthStencil->Release(); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | GLuint Stencilbuffer::getStencilSize() |
| 300 | { |
| 301 | if (mDepthStencil) |
| 302 | { |
| 303 | D3DSURFACE_DESC description; |
| 304 | mDepthStencil->GetDesc(&description); |
| 305 | |
| 306 | return es2dx::GetStencilSize(description.Format); |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | bool Stencilbuffer::isStencilbuffer() |
| 313 | { |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | IDirect3DSurface9 *Stencilbuffer::getDepthStencil() |
| 318 | { |
| 319 | return mDepthStencil; |
| 320 | } |
| 321 | } |