Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | #include "precompiled.h" |
michael@0 | 2 | // |
michael@0 | 3 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
michael@0 | 4 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | // found in the LICENSE file. |
michael@0 | 6 | // |
michael@0 | 7 | |
michael@0 | 8 | // Framebuffer.cpp: Implements the gl::Framebuffer class. Implements GL framebuffer |
michael@0 | 9 | // objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105. |
michael@0 | 10 | |
michael@0 | 11 | #include "libGLESv2/Framebuffer.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "libGLESv2/main.h" |
michael@0 | 14 | #include "libGLESv2/utilities.h" |
michael@0 | 15 | #include "libGLESv2/Texture.h" |
michael@0 | 16 | #include "libGLESv2/Context.h" |
michael@0 | 17 | #include "libGLESv2/renderer/Renderer.h" |
michael@0 | 18 | #include "libGLESv2/Renderbuffer.h" |
michael@0 | 19 | |
michael@0 | 20 | namespace gl |
michael@0 | 21 | { |
michael@0 | 22 | |
michael@0 | 23 | Framebuffer::Framebuffer(rx::Renderer *renderer) |
michael@0 | 24 | : mRenderer(renderer) |
michael@0 | 25 | { |
michael@0 | 26 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 27 | { |
michael@0 | 28 | mColorbufferTypes[colorAttachment] = GL_NONE; |
michael@0 | 29 | mDrawBufferStates[colorAttachment] = GL_NONE; |
michael@0 | 30 | } |
michael@0 | 31 | mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; |
michael@0 | 32 | mReadBufferState = GL_COLOR_ATTACHMENT0_EXT; |
michael@0 | 33 | |
michael@0 | 34 | mDepthbufferType = GL_NONE; |
michael@0 | 35 | mStencilbufferType = GL_NONE; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | Framebuffer::~Framebuffer() |
michael@0 | 39 | { |
michael@0 | 40 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 41 | { |
michael@0 | 42 | mColorbufferPointers[colorAttachment].set(NULL); |
michael@0 | 43 | } |
michael@0 | 44 | mDepthbufferPointer.set(NULL); |
michael@0 | 45 | mStencilbufferPointer.set(NULL); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle) const |
michael@0 | 49 | { |
michael@0 | 50 | gl::Context *context = gl::getContext(); |
michael@0 | 51 | Renderbuffer *buffer = NULL; |
michael@0 | 52 | |
michael@0 | 53 | if (type == GL_NONE) |
michael@0 | 54 | { |
michael@0 | 55 | buffer = NULL; |
michael@0 | 56 | } |
michael@0 | 57 | else if (type == GL_RENDERBUFFER) |
michael@0 | 58 | { |
michael@0 | 59 | buffer = context->getRenderbuffer(handle); |
michael@0 | 60 | } |
michael@0 | 61 | else if (IsInternalTextureTarget(type)) |
michael@0 | 62 | { |
michael@0 | 63 | buffer = context->getTexture(handle)->getRenderbuffer(type); |
michael@0 | 64 | } |
michael@0 | 65 | else |
michael@0 | 66 | { |
michael@0 | 67 | UNREACHABLE(); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | return buffer; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void Framebuffer::setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer) |
michael@0 | 74 | { |
michael@0 | 75 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
michael@0 | 76 | mColorbufferTypes[colorAttachment] = (colorbuffer != 0) ? type : GL_NONE; |
michael@0 | 77 | mColorbufferPointers[colorAttachment].set(lookupRenderbuffer(type, colorbuffer)); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer) |
michael@0 | 81 | { |
michael@0 | 82 | mDepthbufferType = (depthbuffer != 0) ? type : GL_NONE; |
michael@0 | 83 | mDepthbufferPointer.set(lookupRenderbuffer(type, depthbuffer)); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer) |
michael@0 | 87 | { |
michael@0 | 88 | mStencilbufferType = (stencilbuffer != 0) ? type : GL_NONE; |
michael@0 | 89 | mStencilbufferPointer.set(lookupRenderbuffer(type, stencilbuffer)); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | void Framebuffer::detachTexture(GLuint texture) |
michael@0 | 93 | { |
michael@0 | 94 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 95 | { |
michael@0 | 96 | if (mColorbufferPointers[colorAttachment].id() == texture && IsInternalTextureTarget(mColorbufferTypes[colorAttachment])) |
michael@0 | 97 | { |
michael@0 | 98 | mColorbufferTypes[colorAttachment] = GL_NONE; |
michael@0 | 99 | mColorbufferPointers[colorAttachment].set(NULL); |
michael@0 | 100 | } |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | if (mDepthbufferPointer.id() == texture && IsInternalTextureTarget(mDepthbufferType)) |
michael@0 | 104 | { |
michael@0 | 105 | mDepthbufferType = GL_NONE; |
michael@0 | 106 | mDepthbufferPointer.set(NULL); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | if (mStencilbufferPointer.id() == texture && IsInternalTextureTarget(mStencilbufferType)) |
michael@0 | 110 | { |
michael@0 | 111 | mStencilbufferType = GL_NONE; |
michael@0 | 112 | mStencilbufferPointer.set(NULL); |
michael@0 | 113 | } |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | void Framebuffer::detachRenderbuffer(GLuint renderbuffer) |
michael@0 | 117 | { |
michael@0 | 118 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 119 | { |
michael@0 | 120 | if (mColorbufferPointers[colorAttachment].id() == renderbuffer && mColorbufferTypes[colorAttachment] == GL_RENDERBUFFER) |
michael@0 | 121 | { |
michael@0 | 122 | mColorbufferTypes[colorAttachment] = GL_NONE; |
michael@0 | 123 | mColorbufferPointers[colorAttachment].set(NULL); |
michael@0 | 124 | } |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | if (mDepthbufferPointer.id() == renderbuffer && mDepthbufferType == GL_RENDERBUFFER) |
michael@0 | 128 | { |
michael@0 | 129 | mDepthbufferType = GL_NONE; |
michael@0 | 130 | mDepthbufferPointer.set(NULL); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | if (mStencilbufferPointer.id() == renderbuffer && mStencilbufferType == GL_RENDERBUFFER) |
michael@0 | 134 | { |
michael@0 | 135 | mStencilbufferType = GL_NONE; |
michael@0 | 136 | mStencilbufferPointer.set(NULL); |
michael@0 | 137 | } |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | unsigned int Framebuffer::getRenderTargetSerial(unsigned int colorAttachment) const |
michael@0 | 141 | { |
michael@0 | 142 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
michael@0 | 143 | |
michael@0 | 144 | Renderbuffer *colorbuffer = mColorbufferPointers[colorAttachment].get(); |
michael@0 | 145 | |
michael@0 | 146 | if (colorbuffer) |
michael@0 | 147 | { |
michael@0 | 148 | return colorbuffer->getSerial(); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | return 0; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | unsigned int Framebuffer::getDepthbufferSerial() const |
michael@0 | 155 | { |
michael@0 | 156 | Renderbuffer *depthbuffer = mDepthbufferPointer.get(); |
michael@0 | 157 | |
michael@0 | 158 | if (depthbuffer) |
michael@0 | 159 | { |
michael@0 | 160 | return depthbuffer->getSerial(); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | return 0; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | unsigned int Framebuffer::getStencilbufferSerial() const |
michael@0 | 167 | { |
michael@0 | 168 | Renderbuffer *stencilbuffer = mStencilbufferPointer.get(); |
michael@0 | 169 | |
michael@0 | 170 | if (stencilbuffer) |
michael@0 | 171 | { |
michael@0 | 172 | return stencilbuffer->getSerial(); |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | return 0; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | Renderbuffer *Framebuffer::getColorbuffer(unsigned int colorAttachment) const |
michael@0 | 179 | { |
michael@0 | 180 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
michael@0 | 181 | return mColorbufferPointers[colorAttachment].get(); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | Renderbuffer *Framebuffer::getDepthbuffer() const |
michael@0 | 185 | { |
michael@0 | 186 | return mDepthbufferPointer.get(); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | Renderbuffer *Framebuffer::getStencilbuffer() const |
michael@0 | 190 | { |
michael@0 | 191 | return mStencilbufferPointer.get(); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | Renderbuffer *Framebuffer::getDepthOrStencilbuffer() const |
michael@0 | 195 | { |
michael@0 | 196 | Renderbuffer *depthstencilbuffer = mDepthbufferPointer.get(); |
michael@0 | 197 | |
michael@0 | 198 | if (!depthstencilbuffer) |
michael@0 | 199 | { |
michael@0 | 200 | depthstencilbuffer = mStencilbufferPointer.get(); |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | return depthstencilbuffer; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | Renderbuffer *Framebuffer::getReadColorbuffer() const |
michael@0 | 207 | { |
michael@0 | 208 | // Will require more logic if glReadBuffers is supported |
michael@0 | 209 | return mColorbufferPointers[0].get(); |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | GLenum Framebuffer::getReadColorbufferType() const |
michael@0 | 213 | { |
michael@0 | 214 | // Will require more logic if glReadBuffers is supported |
michael@0 | 215 | return mColorbufferTypes[0]; |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | Renderbuffer *Framebuffer::getFirstColorbuffer() const |
michael@0 | 219 | { |
michael@0 | 220 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 221 | { |
michael@0 | 222 | if (mColorbufferTypes[colorAttachment] != GL_NONE) |
michael@0 | 223 | { |
michael@0 | 224 | return mColorbufferPointers[colorAttachment].get(); |
michael@0 | 225 | } |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | return NULL; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | GLenum Framebuffer::getColorbufferType(unsigned int colorAttachment) const |
michael@0 | 232 | { |
michael@0 | 233 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
michael@0 | 234 | return mColorbufferTypes[colorAttachment]; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | GLenum Framebuffer::getDepthbufferType() const |
michael@0 | 238 | { |
michael@0 | 239 | return mDepthbufferType; |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | GLenum Framebuffer::getStencilbufferType() const |
michael@0 | 243 | { |
michael@0 | 244 | return mStencilbufferType; |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | GLuint Framebuffer::getColorbufferHandle(unsigned int colorAttachment) const |
michael@0 | 248 | { |
michael@0 | 249 | ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); |
michael@0 | 250 | return mColorbufferPointers[colorAttachment].id(); |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | GLuint Framebuffer::getDepthbufferHandle() const |
michael@0 | 254 | { |
michael@0 | 255 | return mDepthbufferPointer.id(); |
michael@0 | 256 | } |
michael@0 | 257 | |
michael@0 | 258 | GLuint Framebuffer::getStencilbufferHandle() const |
michael@0 | 259 | { |
michael@0 | 260 | return mStencilbufferPointer.id(); |
michael@0 | 261 | } |
michael@0 | 262 | |
michael@0 | 263 | GLenum Framebuffer::getDrawBufferState(unsigned int colorAttachment) const |
michael@0 | 264 | { |
michael@0 | 265 | return mDrawBufferStates[colorAttachment]; |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | void Framebuffer::setDrawBufferState(unsigned int colorAttachment, GLenum drawBuffer) |
michael@0 | 269 | { |
michael@0 | 270 | mDrawBufferStates[colorAttachment] = drawBuffer; |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | bool Framebuffer::isEnabledColorAttachment(unsigned int colorAttachment) const |
michael@0 | 274 | { |
michael@0 | 275 | return (mColorbufferTypes[colorAttachment] != GL_NONE && mDrawBufferStates[colorAttachment] != GL_NONE); |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | bool Framebuffer::hasEnabledColorAttachment() const |
michael@0 | 279 | { |
michael@0 | 280 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 281 | { |
michael@0 | 282 | if (isEnabledColorAttachment(colorAttachment)) |
michael@0 | 283 | { |
michael@0 | 284 | return true; |
michael@0 | 285 | } |
michael@0 | 286 | } |
michael@0 | 287 | |
michael@0 | 288 | return false; |
michael@0 | 289 | } |
michael@0 | 290 | |
michael@0 | 291 | bool Framebuffer::hasStencil() const |
michael@0 | 292 | { |
michael@0 | 293 | if (mStencilbufferType != GL_NONE) |
michael@0 | 294 | { |
michael@0 | 295 | const Renderbuffer *stencilbufferObject = getStencilbuffer(); |
michael@0 | 296 | |
michael@0 | 297 | if (stencilbufferObject) |
michael@0 | 298 | { |
michael@0 | 299 | return stencilbufferObject->getStencilSize() > 0; |
michael@0 | 300 | } |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | return false; |
michael@0 | 304 | } |
michael@0 | 305 | |
michael@0 | 306 | bool Framebuffer::usingExtendedDrawBuffers() const |
michael@0 | 307 | { |
michael@0 | 308 | for (unsigned int colorAttachment = 1; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 309 | { |
michael@0 | 310 | if (isEnabledColorAttachment(colorAttachment)) |
michael@0 | 311 | { |
michael@0 | 312 | return true; |
michael@0 | 313 | } |
michael@0 | 314 | } |
michael@0 | 315 | |
michael@0 | 316 | return false; |
michael@0 | 317 | } |
michael@0 | 318 | |
michael@0 | 319 | GLenum Framebuffer::completeness() const |
michael@0 | 320 | { |
michael@0 | 321 | int width = 0; |
michael@0 | 322 | int height = 0; |
michael@0 | 323 | int colorbufferSize = 0; |
michael@0 | 324 | int samples = -1; |
michael@0 | 325 | bool missingAttachment = true; |
michael@0 | 326 | |
michael@0 | 327 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 328 | { |
michael@0 | 329 | if (mColorbufferTypes[colorAttachment] != GL_NONE) |
michael@0 | 330 | { |
michael@0 | 331 | const Renderbuffer *colorbuffer = getColorbuffer(colorAttachment); |
michael@0 | 332 | |
michael@0 | 333 | if (!colorbuffer) |
michael@0 | 334 | { |
michael@0 | 335 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | if (colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0) |
michael@0 | 339 | { |
michael@0 | 340 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 341 | } |
michael@0 | 342 | |
michael@0 | 343 | if (mColorbufferTypes[colorAttachment] == GL_RENDERBUFFER) |
michael@0 | 344 | { |
michael@0 | 345 | if (!gl::IsColorRenderable(colorbuffer->getInternalFormat())) |
michael@0 | 346 | { |
michael@0 | 347 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 348 | } |
michael@0 | 349 | } |
michael@0 | 350 | else if (IsInternalTextureTarget(mColorbufferTypes[colorAttachment])) |
michael@0 | 351 | { |
michael@0 | 352 | GLint internalformat = colorbuffer->getInternalFormat(); |
michael@0 | 353 | GLenum format = gl::ExtractFormat(internalformat); |
michael@0 | 354 | |
michael@0 | 355 | if (IsCompressed(format) || |
michael@0 | 356 | format == GL_ALPHA || |
michael@0 | 357 | format == GL_LUMINANCE || |
michael@0 | 358 | format == GL_LUMINANCE_ALPHA) |
michael@0 | 359 | { |
michael@0 | 360 | return GL_FRAMEBUFFER_UNSUPPORTED; |
michael@0 | 361 | } |
michael@0 | 362 | |
michael@0 | 363 | bool filtering, renderable; |
michael@0 | 364 | |
michael@0 | 365 | if ((gl::IsFloat32Format(internalformat) && !mRenderer->getFloat32TextureSupport(&filtering, &renderable)) || |
michael@0 | 366 | (gl::IsFloat16Format(internalformat) && !mRenderer->getFloat16TextureSupport(&filtering, &renderable))) |
michael@0 | 367 | { |
michael@0 | 368 | return GL_FRAMEBUFFER_UNSUPPORTED; |
michael@0 | 369 | } |
michael@0 | 370 | |
michael@0 | 371 | if (gl::IsDepthTexture(internalformat) || gl::IsStencilTexture(internalformat)) |
michael@0 | 372 | { |
michael@0 | 373 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 374 | } |
michael@0 | 375 | } |
michael@0 | 376 | else |
michael@0 | 377 | { |
michael@0 | 378 | UNREACHABLE(); |
michael@0 | 379 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 380 | } |
michael@0 | 381 | |
michael@0 | 382 | if (!missingAttachment) |
michael@0 | 383 | { |
michael@0 | 384 | // all color attachments must have the same width and height |
michael@0 | 385 | if (colorbuffer->getWidth() != width || colorbuffer->getHeight() != height) |
michael@0 | 386 | { |
michael@0 | 387 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
michael@0 | 388 | } |
michael@0 | 389 | |
michael@0 | 390 | // APPLE_framebuffer_multisample, which EXT_draw_buffers refers to, requires that |
michael@0 | 391 | // all color attachments have the same number of samples for the FBO to be complete. |
michael@0 | 392 | if (colorbuffer->getSamples() != samples) |
michael@0 | 393 | { |
michael@0 | 394 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT; |
michael@0 | 395 | } |
michael@0 | 396 | |
michael@0 | 397 | // all color attachments attachments must have the same number of bitplanes |
michael@0 | 398 | if (gl::ComputePixelSize(colorbuffer->getInternalFormat()) != colorbufferSize) |
michael@0 | 399 | { |
michael@0 | 400 | return GL_FRAMEBUFFER_UNSUPPORTED; |
michael@0 | 401 | } |
michael@0 | 402 | |
michael@0 | 403 | // D3D11 does not allow for overlapping RenderTargetViews, so ensure uniqueness |
michael@0 | 404 | for (unsigned int previousColorAttachment = 0; previousColorAttachment < colorAttachment; previousColorAttachment++) |
michael@0 | 405 | { |
michael@0 | 406 | if (mColorbufferPointers[colorAttachment].get() == mColorbufferPointers[previousColorAttachment].get()) |
michael@0 | 407 | { |
michael@0 | 408 | return GL_FRAMEBUFFER_UNSUPPORTED; |
michael@0 | 409 | } |
michael@0 | 410 | } |
michael@0 | 411 | } |
michael@0 | 412 | else |
michael@0 | 413 | { |
michael@0 | 414 | width = colorbuffer->getWidth(); |
michael@0 | 415 | height = colorbuffer->getHeight(); |
michael@0 | 416 | samples = colorbuffer->getSamples(); |
michael@0 | 417 | colorbufferSize = gl::ComputePixelSize(colorbuffer->getInternalFormat()); |
michael@0 | 418 | missingAttachment = false; |
michael@0 | 419 | } |
michael@0 | 420 | } |
michael@0 | 421 | } |
michael@0 | 422 | |
michael@0 | 423 | const Renderbuffer *depthbuffer = NULL; |
michael@0 | 424 | const Renderbuffer *stencilbuffer = NULL; |
michael@0 | 425 | |
michael@0 | 426 | if (mDepthbufferType != GL_NONE) |
michael@0 | 427 | { |
michael@0 | 428 | depthbuffer = getDepthbuffer(); |
michael@0 | 429 | |
michael@0 | 430 | if (!depthbuffer) |
michael@0 | 431 | { |
michael@0 | 432 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 433 | } |
michael@0 | 434 | |
michael@0 | 435 | if (depthbuffer->getWidth() == 0 || depthbuffer->getHeight() == 0) |
michael@0 | 436 | { |
michael@0 | 437 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 438 | } |
michael@0 | 439 | |
michael@0 | 440 | if (mDepthbufferType == GL_RENDERBUFFER) |
michael@0 | 441 | { |
michael@0 | 442 | if (!gl::IsDepthRenderable(depthbuffer->getInternalFormat())) |
michael@0 | 443 | { |
michael@0 | 444 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 445 | } |
michael@0 | 446 | } |
michael@0 | 447 | else if (IsInternalTextureTarget(mDepthbufferType)) |
michael@0 | 448 | { |
michael@0 | 449 | GLint internalformat = depthbuffer->getInternalFormat(); |
michael@0 | 450 | |
michael@0 | 451 | // depth texture attachments require OES/ANGLE_depth_texture |
michael@0 | 452 | if (!mRenderer->getDepthTextureSupport()) |
michael@0 | 453 | { |
michael@0 | 454 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 455 | } |
michael@0 | 456 | |
michael@0 | 457 | if (!gl::IsDepthTexture(internalformat)) |
michael@0 | 458 | { |
michael@0 | 459 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 460 | } |
michael@0 | 461 | } |
michael@0 | 462 | else |
michael@0 | 463 | { |
michael@0 | 464 | UNREACHABLE(); |
michael@0 | 465 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 466 | } |
michael@0 | 467 | |
michael@0 | 468 | if (missingAttachment) |
michael@0 | 469 | { |
michael@0 | 470 | width = depthbuffer->getWidth(); |
michael@0 | 471 | height = depthbuffer->getHeight(); |
michael@0 | 472 | samples = depthbuffer->getSamples(); |
michael@0 | 473 | missingAttachment = false; |
michael@0 | 474 | } |
michael@0 | 475 | else if (width != depthbuffer->getWidth() || height != depthbuffer->getHeight()) |
michael@0 | 476 | { |
michael@0 | 477 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
michael@0 | 478 | } |
michael@0 | 479 | else if (samples != depthbuffer->getSamples()) |
michael@0 | 480 | { |
michael@0 | 481 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
michael@0 | 482 | } |
michael@0 | 483 | } |
michael@0 | 484 | |
michael@0 | 485 | if (mStencilbufferType != GL_NONE) |
michael@0 | 486 | { |
michael@0 | 487 | stencilbuffer = getStencilbuffer(); |
michael@0 | 488 | |
michael@0 | 489 | if (!stencilbuffer) |
michael@0 | 490 | { |
michael@0 | 491 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 492 | } |
michael@0 | 493 | |
michael@0 | 494 | if (stencilbuffer->getWidth() == 0 || stencilbuffer->getHeight() == 0) |
michael@0 | 495 | { |
michael@0 | 496 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 497 | } |
michael@0 | 498 | |
michael@0 | 499 | if (mStencilbufferType == GL_RENDERBUFFER) |
michael@0 | 500 | { |
michael@0 | 501 | if (!gl::IsStencilRenderable(stencilbuffer->getInternalFormat())) |
michael@0 | 502 | { |
michael@0 | 503 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 504 | } |
michael@0 | 505 | } |
michael@0 | 506 | else if (IsInternalTextureTarget(mStencilbufferType)) |
michael@0 | 507 | { |
michael@0 | 508 | GLint internalformat = stencilbuffer->getInternalFormat(); |
michael@0 | 509 | |
michael@0 | 510 | // texture stencil attachments come along as part |
michael@0 | 511 | // of OES_packed_depth_stencil + OES/ANGLE_depth_texture |
michael@0 | 512 | if (!mRenderer->getDepthTextureSupport()) |
michael@0 | 513 | { |
michael@0 | 514 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 515 | } |
michael@0 | 516 | |
michael@0 | 517 | if (!gl::IsStencilTexture(internalformat)) |
michael@0 | 518 | { |
michael@0 | 519 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 520 | } |
michael@0 | 521 | } |
michael@0 | 522 | else |
michael@0 | 523 | { |
michael@0 | 524 | UNREACHABLE(); |
michael@0 | 525 | return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; |
michael@0 | 526 | } |
michael@0 | 527 | |
michael@0 | 528 | if (missingAttachment) |
michael@0 | 529 | { |
michael@0 | 530 | width = stencilbuffer->getWidth(); |
michael@0 | 531 | height = stencilbuffer->getHeight(); |
michael@0 | 532 | samples = stencilbuffer->getSamples(); |
michael@0 | 533 | missingAttachment = false; |
michael@0 | 534 | } |
michael@0 | 535 | else if (width != stencilbuffer->getWidth() || height != stencilbuffer->getHeight()) |
michael@0 | 536 | { |
michael@0 | 537 | return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; |
michael@0 | 538 | } |
michael@0 | 539 | else if (samples != stencilbuffer->getSamples()) |
michael@0 | 540 | { |
michael@0 | 541 | return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE; |
michael@0 | 542 | } |
michael@0 | 543 | } |
michael@0 | 544 | |
michael@0 | 545 | // if we have both a depth and stencil buffer, they must refer to the same object |
michael@0 | 546 | // since we only support packed_depth_stencil and not separate depth and stencil |
michael@0 | 547 | if (depthbuffer && stencilbuffer && (depthbuffer != stencilbuffer)) |
michael@0 | 548 | { |
michael@0 | 549 | return GL_FRAMEBUFFER_UNSUPPORTED; |
michael@0 | 550 | } |
michael@0 | 551 | |
michael@0 | 552 | // we need to have at least one attachment to be complete |
michael@0 | 553 | if (missingAttachment) |
michael@0 | 554 | { |
michael@0 | 555 | return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; |
michael@0 | 556 | } |
michael@0 | 557 | |
michael@0 | 558 | return GL_FRAMEBUFFER_COMPLETE; |
michael@0 | 559 | } |
michael@0 | 560 | |
michael@0 | 561 | DefaultFramebuffer::DefaultFramebuffer(rx::Renderer *renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil) |
michael@0 | 562 | : Framebuffer(renderer) |
michael@0 | 563 | { |
michael@0 | 564 | mColorbufferPointers[0].set(new Renderbuffer(mRenderer, 0, colorbuffer)); |
michael@0 | 565 | |
michael@0 | 566 | Renderbuffer *depthStencilRenderbuffer = new Renderbuffer(mRenderer, 0, depthStencil); |
michael@0 | 567 | mDepthbufferPointer.set(depthStencilRenderbuffer); |
michael@0 | 568 | mStencilbufferPointer.set(depthStencilRenderbuffer); |
michael@0 | 569 | |
michael@0 | 570 | mColorbufferTypes[0] = GL_RENDERBUFFER; |
michael@0 | 571 | mDepthbufferType = (depthStencilRenderbuffer->getDepthSize() != 0) ? GL_RENDERBUFFER : GL_NONE; |
michael@0 | 572 | mStencilbufferType = (depthStencilRenderbuffer->getStencilSize() != 0) ? GL_RENDERBUFFER : GL_NONE; |
michael@0 | 573 | |
michael@0 | 574 | mDrawBufferStates[0] = GL_BACK; |
michael@0 | 575 | mReadBufferState = GL_BACK; |
michael@0 | 576 | } |
michael@0 | 577 | |
michael@0 | 578 | int Framebuffer::getSamples() const |
michael@0 | 579 | { |
michael@0 | 580 | if (completeness() == GL_FRAMEBUFFER_COMPLETE) |
michael@0 | 581 | { |
michael@0 | 582 | // for a complete framebuffer, all attachments must have the same sample count |
michael@0 | 583 | // in this case return the first nonzero sample size |
michael@0 | 584 | for (unsigned int colorAttachment = 0; colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
michael@0 | 585 | { |
michael@0 | 586 | if (mColorbufferTypes[colorAttachment] != GL_NONE) |
michael@0 | 587 | { |
michael@0 | 588 | return getColorbuffer(colorAttachment)->getSamples(); |
michael@0 | 589 | } |
michael@0 | 590 | } |
michael@0 | 591 | } |
michael@0 | 592 | |
michael@0 | 593 | return 0; |
michael@0 | 594 | } |
michael@0 | 595 | |
michael@0 | 596 | GLenum DefaultFramebuffer::completeness() const |
michael@0 | 597 | { |
michael@0 | 598 | // The default framebuffer *must* always be complete, though it may not be |
michael@0 | 599 | // subject to the same rules as application FBOs. ie, it could have 0x0 size. |
michael@0 | 600 | return GL_FRAMEBUFFER_COMPLETE; |
michael@0 | 601 | } |
michael@0 | 602 | |
michael@0 | 603 | } |