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 | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 22 | fStencilRenderbufferID = desc.fStencilRenderbufferID; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 23 | fViewport = viewport; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 24 | fOwnIDs = desc.fOwnIDs; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 25 | fTexIDObj = texID; |
| 26 | GrSafeRef(fTexIDObj); |
| 27 | } |
| 28 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 29 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 30 | const Desc& desc, |
| 31 | const GrGLIRect& viewport, |
| 32 | GrGLTexID* texID, |
| 33 | GrGLTexture* texture) |
| 34 | : INHERITED(gpu, texture, viewport.fWidth, |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 35 | viewport.fHeight, desc.fConfig, |
| 36 | desc.fStencilBits, desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 37 | GrAssert(NULL != texID); |
| 38 | GrAssert(NULL != texture); |
| 39 | // FBO 0 can't also be a texture, right? |
| 40 | GrAssert(0 != desc.fRTFBOID); |
| 41 | GrAssert(0 != desc.fTexFBOID); |
| 42 | this->init(desc, viewport, texID); |
| 43 | } |
| 44 | |
| 45 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 46 | const Desc& desc, |
| 47 | const GrGLIRect& viewport) |
| 48 | : INHERITED(gpu, NULL, viewport.fWidth, |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 49 | viewport.fHeight, desc.fConfig, |
| 50 | desc.fStencilBits, desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 51 | this->init(desc, viewport, NULL); |
| 52 | } |
| 53 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 54 | void GrGLRenderTarget::onRelease() { |
| 55 | GPUGL->notifyRenderTargetDelete(this); |
| 56 | if (fOwnIDs) { |
| 57 | if (fTexFBOID) { |
| 58 | GR_GL(DeleteFramebuffers(1, &fTexFBOID)); |
| 59 | } |
| 60 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
| 61 | GR_GL(DeleteFramebuffers(1, &fRTFBOID)); |
| 62 | } |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 63 | if (fStencilRenderbufferID) { |
| 64 | GR_GL(DeleteRenderbuffers(1, &fStencilRenderbufferID)); |
| 65 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 66 | if (fMSColorRenderbufferID) { |
| 67 | GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
| 68 | } |
| 69 | } |
| 70 | fRTFBOID = 0; |
| 71 | fTexFBOID = 0; |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 72 | fStencilRenderbufferID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 73 | fMSColorRenderbufferID = 0; |
| 74 | GrSafeUnref(fTexIDObj); |
| 75 | fTexIDObj = NULL; |
| 76 | } |
| 77 | |
| 78 | void GrGLRenderTarget::onAbandon() { |
| 79 | fRTFBOID = 0; |
| 80 | fTexFBOID = 0; |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 81 | fStencilRenderbufferID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 82 | fMSColorRenderbufferID = 0; |
| 83 | if (NULL != fTexIDObj) { |
| 84 | fTexIDObj->abandon(); |
| 85 | fTexIDObj = NULL; |
| 86 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 87 | } |
| 88 | |