bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "GrGLRenderTarget.h" |
| 11 | |
| 12 | #include "GrGpuGL.h" |
| 13 | |
| 14 | #define GPUGL static_cast<GrGpuGL*>(getGpu()) |
| 15 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 16 | void GrGLRenderTarget::init(const Desc& desc, |
| 17 | const GrGLIRect& viewport, |
| 18 | GrGLTexID* texID) { |
| 19 | fRTFBOID = desc.fRTFBOID; |
| 20 | fTexFBOID = desc.fTexFBOID; |
| 21 | fMSColorRenderbufferID = desc.fMSColorRenderbufferID; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 22 | fViewport = viewport; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 23 | fOwnIDs = desc.fOwnIDs; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 24 | fTexIDObj = texID; |
| 25 | GrSafeRef(fTexIDObj); |
| 26 | } |
| 27 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 28 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 29 | const Desc& desc, |
| 30 | const GrGLIRect& viewport, |
| 31 | GrGLTexID* texID, |
| 32 | GrGLTexture* texture) |
| 33 | : INHERITED(gpu, texture, viewport.fWidth, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 34 | viewport.fHeight, desc.fConfig, desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 35 | GrAssert(NULL != texID); |
| 36 | GrAssert(NULL != texture); |
| 37 | // FBO 0 can't also be a texture, right? |
| 38 | GrAssert(0 != desc.fRTFBOID); |
| 39 | GrAssert(0 != desc.fTexFBOID); |
| 40 | this->init(desc, viewport, texID); |
| 41 | } |
| 42 | |
| 43 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 44 | const Desc& desc, |
| 45 | const GrGLIRect& viewport) |
| 46 | : INHERITED(gpu, NULL, viewport.fWidth, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 47 | viewport.fHeight, desc.fConfig, desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 48 | this->init(desc, viewport, NULL); |
| 49 | } |
| 50 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 51 | void GrGLRenderTarget::onRelease() { |
| 52 | GPUGL->notifyRenderTargetDelete(this); |
| 53 | if (fOwnIDs) { |
| 54 | if (fTexFBOID) { |
| 55 | GR_GL(DeleteFramebuffers(1, &fTexFBOID)); |
| 56 | } |
| 57 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
| 58 | GR_GL(DeleteFramebuffers(1, &fRTFBOID)); |
| 59 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 60 | if (fMSColorRenderbufferID) { |
| 61 | GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
| 62 | } |
| 63 | } |
| 64 | fRTFBOID = 0; |
| 65 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 66 | fMSColorRenderbufferID = 0; |
| 67 | GrSafeUnref(fTexIDObj); |
| 68 | fTexIDObj = NULL; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 69 | GrSafeSetNull(fStencilBuffer); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void GrGLRenderTarget::onAbandon() { |
| 73 | fRTFBOID = 0; |
| 74 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 75 | fMSColorRenderbufferID = 0; |
| 76 | if (NULL != fTexIDObj) { |
| 77 | fTexIDObj->abandon(); |
| 78 | fTexIDObj = NULL; |
| 79 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 80 | GrSafeSetNull(fStencilBuffer); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 81 | } |
| 82 | |