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