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 | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 16 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 17 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 18 | void GrGLRenderTarget::init(const Desc& desc, |
| 19 | const GrGLIRect& viewport, |
| 20 | GrGLTexID* texID) { |
| 21 | fRTFBOID = desc.fRTFBOID; |
| 22 | fTexFBOID = desc.fTexFBOID; |
| 23 | fMSColorRenderbufferID = desc.fMSColorRenderbufferID; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 24 | fViewport = viewport; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 25 | fOwnIDs = desc.fOwnIDs; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 26 | fTexIDObj = texID; |
| 27 | GrSafeRef(fTexIDObj); |
| 28 | } |
| 29 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 30 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 31 | const Desc& desc, |
| 32 | const GrGLIRect& viewport, |
| 33 | GrGLTexID* texID, |
| 34 | GrGLTexture* texture) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 35 | : INHERITED(gpu, |
| 36 | texture, |
| 37 | viewport.fWidth, |
| 38 | viewport.fHeight, |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 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); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame^] | 46 | |
| 47 | // we assume this is true, TODO: get rid of viewport as a param. |
| 48 | GrAssert(viewport.fWidth == texture->width()); |
| 49 | GrAssert(viewport.fHeight == texture->height()); |
| 50 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 51 | this->init(desc, viewport, texID); |
| 52 | } |
| 53 | |
| 54 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 55 | const Desc& desc, |
| 56 | const GrGLIRect& viewport) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 57 | : INHERITED(gpu, |
| 58 | NULL, |
| 59 | viewport.fWidth, |
| 60 | viewport.fHeight, |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 61 | desc.fConfig, |
| 62 | desc.fSampleCnt) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 63 | this->init(desc, viewport, NULL); |
| 64 | } |
| 65 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 66 | void GrGLRenderTarget::onRelease() { |
| 67 | GPUGL->notifyRenderTargetDelete(this); |
| 68 | if (fOwnIDs) { |
| 69 | if (fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 70 | GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 71 | } |
| 72 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 73 | GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 74 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 75 | if (fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 76 | GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | fRTFBOID = 0; |
| 80 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 81 | fMSColorRenderbufferID = 0; |
| 82 | GrSafeUnref(fTexIDObj); |
| 83 | fTexIDObj = NULL; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 84 | this->setStencilBuffer(NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void GrGLRenderTarget::onAbandon() { |
| 88 | fRTFBOID = 0; |
| 89 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 90 | fMSColorRenderbufferID = 0; |
| 91 | if (NULL != fTexIDObj) { |
| 92 | fTexIDObj->abandon(); |
| 93 | fTexIDObj = NULL; |
| 94 | } |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 95 | this->setStencilBuffer(NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 96 | } |
| 97 | |