bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 8 | #include "GrGLRenderTarget.h" |
| 9 | |
| 10 | #include "GrGpuGL.h" |
| 11 | |
| 12 | #define GPUGL static_cast<GrGpuGL*>(getGpu()) |
| 13 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 14 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 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, |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 37 | desc.fConfig, |
| 38 | desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 39 | GrAssert(NULL != texID); |
| 40 | GrAssert(NULL != texture); |
| 41 | // FBO 0 can't also be a texture, right? |
| 42 | GrAssert(0 != desc.fRTFBOID); |
| 43 | GrAssert(0 != desc.fTexFBOID); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 44 | |
| 45 | // we assume this is true, TODO: get rid of viewport as a param. |
| 46 | GrAssert(viewport.fWidth == texture->width()); |
| 47 | GrAssert(viewport.fHeight == texture->height()); |
| 48 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 49 | this->init(desc, viewport, texID); |
| 50 | } |
| 51 | |
| 52 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 53 | const Desc& desc, |
| 54 | const GrGLIRect& viewport) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 55 | : INHERITED(gpu, |
| 56 | NULL, |
| 57 | viewport.fWidth, |
| 58 | viewport.fHeight, |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 59 | desc.fConfig, |
| 60 | desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 61 | this->init(desc, viewport, NULL); |
| 62 | } |
| 63 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 64 | void GrGLRenderTarget::onRelease() { |
| 65 | GPUGL->notifyRenderTargetDelete(this); |
| 66 | if (fOwnIDs) { |
| 67 | if (fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 68 | GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 69 | } |
| 70 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 71 | GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 72 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 73 | if (fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 74 | GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | fRTFBOID = 0; |
| 78 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 79 | fMSColorRenderbufferID = 0; |
| 80 | GrSafeUnref(fTexIDObj); |
| 81 | fTexIDObj = NULL; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 82 | this->setStencilBuffer(NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void GrGLRenderTarget::onAbandon() { |
| 86 | fRTFBOID = 0; |
| 87 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 88 | fMSColorRenderbufferID = 0; |
| 89 | if (NULL != fTexIDObj) { |
| 90 | fTexIDObj->abandon(); |
| 91 | fTexIDObj = NULL; |
| 92 | } |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 93 | this->setStencilBuffer(NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 94 | } |
| 95 | |