blob: f251b553580d3ca13439af5251eae58badb60f7a [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
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.combbf56f72010-04-20 18:52:13 +000011#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000013#include "libGLESv2/main.h"
enne@chromium.org0fa74632010-09-21 16:18:52 +000014#include "libGLESv2/Texture.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015#include "libGLESv2/utilities.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000016
17namespace gl
18{
daniel@transgaming.comfbc39522011-11-11 04:10:28 +000019unsigned int RenderbufferStorage::mCurrentSerial = 1;
daniel@transgaming.com092bd482010-05-12 03:39:36 +000020
daniel@transgaming.comfbc39522011-11-11 04:10:28 +000021RenderbufferInterface::RenderbufferInterface()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000023}
24
daniel@transgaming.com2678b342012-01-18 16:29:40 +000025// 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.
28void RenderbufferInterface::addProxyRef(const Renderbuffer *proxy)
29{
30}
31
32void RenderbufferInterface::releaseProxy(const Renderbuffer *proxy)
33{
34}
35
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000036GLuint RenderbufferInterface::getRedSize() const
37{
38 return dx2es::GetRedSize(getD3DFormat());
39}
40
41GLuint RenderbufferInterface::getGreenSize() const
42{
43 return dx2es::GetGreenSize(getD3DFormat());
44}
45
46GLuint RenderbufferInterface::getBlueSize() const
47{
48 return dx2es::GetBlueSize(getD3DFormat());
49}
50
51GLuint RenderbufferInterface::getAlphaSize() const
52{
53 return dx2es::GetAlphaSize(getD3DFormat());
54}
55
56GLuint RenderbufferInterface::getDepthSize() const
57{
58 return dx2es::GetDepthSize(getD3DFormat());
59}
60
61GLuint RenderbufferInterface::getStencilSize() const
62{
63 return dx2es::GetStencilSize(getD3DFormat());
64}
65
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000066///// RenderbufferTexture2D Implementation ////////
67
68RenderbufferTexture2D::RenderbufferTexture2D(Texture2D *texture, GLenum target) : mTarget(target)
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000069{
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000070 mTexture2D.set(texture);
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000071}
72
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000073RenderbufferTexture2D::~RenderbufferTexture2D()
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000074{
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000075 mTexture2D.set(NULL);
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000076}
77
daniel@transgaming.com2678b342012-01-18 16:29:40 +000078// 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.com46f2d0a2012-05-09 15:49:06 +000080void RenderbufferTexture2D::addProxyRef(const Renderbuffer *proxy)
daniel@transgaming.com2678b342012-01-18 16:29:40 +000081{
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000082 mTexture2D->addProxyRef(proxy);
daniel@transgaming.com2678b342012-01-18 16:29:40 +000083}
84
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000085void RenderbufferTexture2D::releaseProxy(const Renderbuffer *proxy)
daniel@transgaming.com2678b342012-01-18 16:29:40 +000086{
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000087 mTexture2D->releaseProxy(proxy);
daniel@transgaming.com2678b342012-01-18 16:29:40 +000088}
89
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000090IDirect3DSurface9 *RenderbufferTexture2D::getRenderTarget()
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000091{
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000092 return mTexture2D->getRenderTarget(mTarget);
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000093}
94
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +000095IDirect3DSurface9 *RenderbufferTexture2D::getDepthStencil()
daniel@transgaming.comd14558a2011-11-09 17:46:18 +000096{
97 return NULL;
98}
99
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000100GLsizei RenderbufferTexture2D::getWidth() const
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000101{
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000102 return mTexture2D->getWidth(0);
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000103}
daniel@transgaming.comfbc39522011-11-11 04:10:28 +0000104
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000105GLsizei RenderbufferTexture2D::getHeight() const
daniel@transgaming.comfbc39522011-11-11 04:10:28 +0000106{
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000107 return mTexture2D->getHeight(0);
daniel@transgaming.comfbc39522011-11-11 04:10:28 +0000108}
109
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000110GLenum RenderbufferTexture2D::getInternalFormat() const
111{
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000112 return mTexture2D->getInternalFormat(0);
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000113}
114
115D3DFORMAT RenderbufferTexture2D::getD3DFormat() const
116{
daniel@transgaming.com92f49922012-05-09 15:49:19 +0000117 return mTexture2D->getD3DFormat(0);
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000118}
119
120GLsizei RenderbufferTexture2D::getSamples() const
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000121{
122 return 0;
123}
124
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000125unsigned int RenderbufferTexture2D::getSerial() const
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000126{
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000127 return mTexture2D->getRenderTargetSerial(mTarget);
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000128}
129
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000130///// RenderbufferTextureCubeMap Implementation ////////
131
132RenderbufferTextureCubeMap::RenderbufferTextureCubeMap(TextureCubeMap *texture, GLenum target) : mTarget(target)
133{
134 mTextureCubeMap.set(texture);
135}
136
137RenderbufferTextureCubeMap::~RenderbufferTextureCubeMap()
138{
139 mTextureCubeMap.set(NULL);
140}
141
142// Textures need to maintain their own reference count for references via
143// Renderbuffers acting as proxies. Here, we notify the texture of a reference.
144void RenderbufferTextureCubeMap::addProxyRef(const Renderbuffer *proxy)
145{
146 mTextureCubeMap->addProxyRef(proxy);
147}
148
149void RenderbufferTextureCubeMap::releaseProxy(const Renderbuffer *proxy)
150{
151 mTextureCubeMap->releaseProxy(proxy);
152}
153
154IDirect3DSurface9 *RenderbufferTextureCubeMap::getRenderTarget()
155{
156 return mTextureCubeMap->getRenderTarget(mTarget);
157}
158
159IDirect3DSurface9 *RenderbufferTextureCubeMap::getDepthStencil()
160{
161 return NULL;
162}
163
164GLsizei RenderbufferTextureCubeMap::getWidth() const
165{
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000166 return mTextureCubeMap->getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000167}
168
169GLsizei RenderbufferTextureCubeMap::getHeight() const
170{
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000171 return mTextureCubeMap->getHeight(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000172}
173
174GLenum RenderbufferTextureCubeMap::getInternalFormat() const
175{
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000176 return mTextureCubeMap->getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000177}
178
179D3DFORMAT RenderbufferTextureCubeMap::getD3DFormat() const
180{
daniel@transgaming.com4df88e82012-05-09 15:49:24 +0000181 return mTextureCubeMap->getD3DFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
daniel@transgaming.com46f2d0a2012-05-09 15:49:06 +0000182}
183
184GLsizei RenderbufferTextureCubeMap::getSamples() const
185{
186 return 0;
187}
188
189unsigned int RenderbufferTextureCubeMap::getSerial() const
190{
191 return mTextureCubeMap->getRenderTargetSerial(mTarget);
192}
193
194////// Renderbuffer Implementation //////
195
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000196Renderbuffer::Renderbuffer(GLuint id, RenderbufferInterface *instance) : RefCountObject(id)
197{
198 ASSERT(instance != NULL);
199 mInstance = instance;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000200}
201
202Renderbuffer::~Renderbuffer()
203{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000204 delete mInstance;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000205}
206
daniel@transgaming.com2678b342012-01-18 16:29:40 +0000207// The RenderbufferInterface contained in this Renderbuffer may need to maintain
208// its own reference count, so we pass it on here.
209void Renderbuffer::addRef() const
210{
211 mInstance->addProxyRef(this);
212
213 RefCountObject::addRef();
214}
215
216void Renderbuffer::release() const
217{
218 mInstance->releaseProxy(this);
219
220 RefCountObject::release();
221}
222
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000223IDirect3DSurface9 *Renderbuffer::getRenderTarget()
224{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000225 return mInstance->getRenderTarget();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000226}
227
228IDirect3DSurface9 *Renderbuffer::getDepthStencil()
229{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000230 return mInstance->getDepthStencil();
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000231}
232
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000233GLsizei Renderbuffer::getWidth() const
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000234{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000235 return mInstance->getWidth();
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000236}
237
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000238GLsizei Renderbuffer::getHeight() const
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000239{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000240 return mInstance->getHeight();
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000241}
242
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000243GLenum Renderbuffer::getInternalFormat() const
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000244{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000245 return mInstance->getInternalFormat();
246}
247
248D3DFORMAT Renderbuffer::getD3DFormat() const
249{
250 return mInstance->getD3DFormat();
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000251}
252
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000253GLuint Renderbuffer::getRedSize() const
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +0000254{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000255 return mInstance->getRedSize();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000256}
257
258GLuint Renderbuffer::getGreenSize() const
259{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000260 return mInstance->getGreenSize();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000261}
262
263GLuint Renderbuffer::getBlueSize() const
264{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000265 return mInstance->getBlueSize();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000266}
267
268GLuint Renderbuffer::getAlphaSize() const
269{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000270 return mInstance->getAlphaSize();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000271}
272
273GLuint Renderbuffer::getDepthSize() const
274{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000275 return mInstance->getDepthSize();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000276}
277
278GLuint Renderbuffer::getStencilSize() const
279{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000280 return mInstance->getStencilSize();
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000281}
282
283GLsizei Renderbuffer::getSamples() const
284{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000285 return mInstance->getSamples();
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +0000286}
287
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000288unsigned int Renderbuffer::getSerial() const
289{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000290 return mInstance->getSerial();
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000291}
292
293void Renderbuffer::setStorage(RenderbufferStorage *newStorage)
294{
295 ASSERT(newStorage != NULL);
296
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000297 delete mInstance;
298 mInstance = newStorage;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000299}
300
daniel@transgaming.comfbc39522011-11-11 04:10:28 +0000301RenderbufferStorage::RenderbufferStorage() : mSerial(issueSerial())
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000302{
daniel@transgaming.com73a5db62010-10-15 17:58:13 +0000303 mWidth = 0;
304 mHeight = 0;
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000305 mInternalFormat = GL_RGBA4;
daniel@transgaming.com73a5db62010-10-15 17:58:13 +0000306 mD3DFormat = D3DFMT_A8R8G8B8;
307 mSamples = 0;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000308}
309
310RenderbufferStorage::~RenderbufferStorage()
311{
312}
313
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000314IDirect3DSurface9 *RenderbufferStorage::getRenderTarget()
315{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316 return NULL;
317}
318
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000319IDirect3DSurface9 *RenderbufferStorage::getDepthStencil()
320{
321 return NULL;
322}
323
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000324GLsizei RenderbufferStorage::getWidth() const
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000325{
326 return mWidth;
327}
328
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000329GLsizei RenderbufferStorage::getHeight() const
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000330{
331 return mHeight;
332}
333
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000334GLenum RenderbufferStorage::getInternalFormat() const
daniel@transgaming.com866f3182010-05-20 19:28:22 +0000335{
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000336 return mInternalFormat;
daniel@transgaming.com866f3182010-05-20 19:28:22 +0000337}
338
daniel@transgaming.comfbc39522011-11-11 04:10:28 +0000339D3DFORMAT RenderbufferStorage::getD3DFormat() const
340{
341 return mD3DFormat;
342}
343
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000344GLsizei RenderbufferStorage::getSamples() const
345{
346 return mSamples;
347}
348
daniel@transgaming.comfbc39522011-11-11 04:10:28 +0000349unsigned int RenderbufferStorage::getSerial() const
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000350{
daniel@transgaming.comfbc39522011-11-11 04:10:28 +0000351 return mSerial;
352}
353
354unsigned int RenderbufferStorage::issueSerial()
355{
356 return mCurrentSerial++;
357}
358
359unsigned int RenderbufferStorage::issueCubeSerials()
360{
361 unsigned int firstSerial = mCurrentSerial;
362 mCurrentSerial += 6;
363 return firstSerial;
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000364}
365
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000366Colorbuffer::Colorbuffer(IDirect3DSurface9 *renderTarget) : mRenderTarget(renderTarget)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000367{
368 if (renderTarget)
369 {
370 renderTarget->AddRef();
371
372 D3DSURFACE_DESC description;
373 renderTarget->GetDesc(&description);
374
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000375 mWidth = description.Width;
376 mHeight = description.Height;
377 mInternalFormat = dx2es::ConvertBackBufferFormat(description.Format);
daniel@transgaming.comca7c0082010-08-24 19:20:20 +0000378 mD3DFormat = description.Format;
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000379 mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType);
daniel@transgaming.comca7c0082010-08-24 19:20:20 +0000380 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000381}
382
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000383Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(NULL)
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000384{
385 IDirect3DDevice9 *device = getDevice();
386
daniel@transgaming.comca7c0082010-08-24 19:20:20 +0000387 D3DFORMAT requestedFormat = es2dx::ConvertRenderbufferFormat(format);
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000388 int supportedSamples = getContext()->getNearestSupportedSamples(requestedFormat, samples);
389
390 if (supportedSamples == -1)
391 {
392 error(GL_OUT_OF_MEMORY);
393
394 return;
395 }
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000396
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000397 if (width > 0 && height > 0)
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000398 {
daniel@transgaming.comca7c0082010-08-24 19:20:20 +0000399 HRESULT result = device->CreateRenderTarget(width, height, requestedFormat,
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000400 es2dx::GetMultisampleTypeFromSamples(supportedSamples), 0, FALSE, &mRenderTarget, NULL);
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000401
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000402 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
403 {
404 error(GL_OUT_OF_MEMORY);
405
406 return;
407 }
408
409 ASSERT(SUCCEEDED(result));
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000410 }
411
apatrick@chromium.org831fe2a2011-03-17 18:44:29 +0000412 mWidth = width;
413 mHeight = height;
414 mInternalFormat = format;
415 mD3DFormat = requestedFormat;
416 mSamples = supportedSamples;
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000417}
418
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000419Colorbuffer::~Colorbuffer()
420{
421 if (mRenderTarget)
422 {
423 mRenderTarget->Release();
424 }
425}
426
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000427IDirect3DSurface9 *Colorbuffer::getRenderTarget()
428{
daniel@transgaming.com5e4dbb32011-11-11 04:10:18 +0000429 if (mRenderTarget)
430 {
431 mRenderTarget->AddRef();
432 }
433
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000434 return mRenderTarget;
435}
436
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000437DepthStencilbuffer::DepthStencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000438{
439 if (depthStencil)
440 {
441 depthStencil->AddRef();
442
443 D3DSURFACE_DESC description;
444 depthStencil->GetDesc(&description);
445
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000446 mWidth = description.Width;
447 mHeight = description.Height;
448 mInternalFormat = dx2es::ConvertDepthStencilFormat(description.Format);
449 mSamples = dx2es::GetSamplesFromMultisampleType(description.MultiSampleType);
daniel@transgaming.comca7c0082010-08-24 19:20:20 +0000450 mD3DFormat = description.Format;
451 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000452}
453
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000454DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000455{
456 IDirect3DDevice9 *device = getDevice();
457
458 mDepthStencil = NULL;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000459
460 int supportedSamples = getContext()->getNearestSupportedSamples(D3DFMT_D24S8, samples);
461
462 if (supportedSamples == -1)
463 {
464 error(GL_OUT_OF_MEMORY);
465
466 return;
467 }
468
apatrick@chromium.org831fe2a2011-03-17 18:44:29 +0000469 if (width > 0 && height > 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000470 {
apatrick@chromium.org831fe2a2011-03-17 18:44:29 +0000471 HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, es2dx::GetMultisampleTypeFromSamples(supportedSamples),
472 0, FALSE, &mDepthStencil, 0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000473
apatrick@chromium.org831fe2a2011-03-17 18:44:29 +0000474 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
475 {
476 error(GL_OUT_OF_MEMORY);
477
478 return;
479 }
480
481 ASSERT(SUCCEEDED(result));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000482 }
483
apatrick@chromium.org831fe2a2011-03-17 18:44:29 +0000484 mWidth = width;
485 mHeight = height;
486 mInternalFormat = GL_DEPTH24_STENCIL8_OES;
487 mD3DFormat = D3DFMT_D24S8;
488 mSamples = supportedSamples;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000489}
490
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000491DepthStencilbuffer::~DepthStencilbuffer()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000492{
493 if (mDepthStencil)
494 {
495 mDepthStencil->Release();
496 }
497}
498
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000499IDirect3DSurface9 *DepthStencilbuffer::getDepthStencil()
500{
501 return mDepthStencil;
502}
503
504Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil)
505{
506 if (depthStencil)
507 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000508 mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function
509 // will expect one of the valid renderbuffer formats for use in
510 // glRenderbufferStorage
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000511 }
512}
513
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000514Depthbuffer::Depthbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples)
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000515{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000516 if (mDepthStencil)
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000517 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000518 mInternalFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function
519 // will expect one of the valid renderbuffer formats for use in
520 // glRenderbufferStorage
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000521 }
522}
523
524Depthbuffer::~Depthbuffer()
525{
526}
527
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000528Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : DepthStencilbuffer(depthStencil)
529{
530 if (depthStencil)
531 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000532 mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function
533 // will expect one of the valid renderbuffer formats for use in
534 // glRenderbufferStorage
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000535 }
536}
537
daniel@transgaming.com1f135d82010-08-24 19:20:36 +0000538Stencilbuffer::Stencilbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples)
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000539{
daniel@transgaming.comd14558a2011-11-09 17:46:18 +0000540 if (mDepthStencil)
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000541 {
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000542 mInternalFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function
543 // will expect one of the valid renderbuffer formats for use in
544 // glRenderbufferStorage
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000545 }
546}
547
548Stencilbuffer::~Stencilbuffer()
549{
550}
551
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000552}