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) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame^] | 33 | : INHERITED(gpu, |
| 34 | texture, |
| 35 | viewport.fWidth, |
| 36 | viewport.fHeight, |
| 37 | texture->allocatedWidth(), |
| 38 | texture->allocatedHeight(), |
| 39 | desc.fConfig, |
| 40 | desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 41 | GrAssert(NULL != texID); |
| 42 | GrAssert(NULL != texture); |
| 43 | // FBO 0 can't also be a texture, right? |
| 44 | GrAssert(0 != desc.fRTFBOID); |
| 45 | GrAssert(0 != desc.fTexFBOID); |
| 46 | this->init(desc, viewport, texID); |
| 47 | } |
| 48 | |
| 49 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 50 | const Desc& desc, |
| 51 | const GrGLIRect& viewport) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame^] | 52 | : INHERITED(gpu, |
| 53 | NULL, |
| 54 | viewport.fWidth, |
| 55 | viewport.fHeight, |
| 56 | viewport.fWidth, // don't really need separate alloc w/h for |
| 57 | viewport.fHeight, // non-texture RTs, repeat viewport values |
| 58 | desc.fConfig, |
| 59 | desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 60 | this->init(desc, viewport, NULL); |
| 61 | } |
| 62 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 63 | void GrGLRenderTarget::onRelease() { |
| 64 | GPUGL->notifyRenderTargetDelete(this); |
| 65 | if (fOwnIDs) { |
| 66 | if (fTexFBOID) { |
| 67 | GR_GL(DeleteFramebuffers(1, &fTexFBOID)); |
| 68 | } |
| 69 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
| 70 | GR_GL(DeleteFramebuffers(1, &fRTFBOID)); |
| 71 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 72 | if (fMSColorRenderbufferID) { |
| 73 | GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
| 74 | } |
| 75 | } |
| 76 | fRTFBOID = 0; |
| 77 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 78 | fMSColorRenderbufferID = 0; |
| 79 | GrSafeUnref(fTexIDObj); |
| 80 | fTexIDObj = NULL; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 81 | GrSafeSetNull(fStencilBuffer); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void GrGLRenderTarget::onAbandon() { |
| 85 | fRTFBOID = 0; |
| 86 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 87 | fMSColorRenderbufferID = 0; |
| 88 | if (NULL != fTexIDObj) { |
| 89 | fTexIDObj->abandon(); |
| 90 | fTexIDObj = NULL; |
| 91 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 92 | GrSafeSetNull(fStencilBuffer); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |