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 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame^] | 28 | namespace { |
| 29 | GrTextureDesc MakeDesc(GrTextureFlags flags, |
| 30 | int width, int height, |
| 31 | GrPixelConfig config, int sampleCnt, |
| 32 | uint64_t clientCacheID) { |
| 33 | GrTextureDesc temp; |
| 34 | temp.fFlags = flags; |
| 35 | temp.fWidth = width; |
| 36 | temp.fHeight = height; |
| 37 | temp.fConfig = config; |
| 38 | temp.fSampleCnt = sampleCnt; |
| 39 | temp.fClientCacheID = clientCacheID; |
| 40 | return temp; |
| 41 | } |
| 42 | |
| 43 | }; |
| 44 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 45 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 46 | const Desc& desc, |
| 47 | const GrGLIRect& viewport, |
| 48 | GrGLTexID* texID, |
| 49 | GrGLTexture* texture) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 50 | : INHERITED(gpu, |
| 51 | texture, |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame^] | 52 | MakeDesc(kNone_GrTextureFlags, |
| 53 | viewport.fWidth, viewport.fHeight, |
| 54 | desc.fConfig, desc.fSampleCnt, |
| 55 | kDefault_CacheID)) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 56 | GrAssert(NULL != texID); |
| 57 | GrAssert(NULL != texture); |
| 58 | // FBO 0 can't also be a texture, right? |
| 59 | GrAssert(0 != desc.fRTFBOID); |
| 60 | GrAssert(0 != desc.fTexFBOID); |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 61 | |
| 62 | // we assume this is true, TODO: get rid of viewport as a param. |
| 63 | GrAssert(viewport.fWidth == texture->width()); |
| 64 | GrAssert(viewport.fHeight == texture->height()); |
| 65 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 66 | this->init(desc, viewport, texID); |
| 67 | } |
| 68 | |
| 69 | GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, |
| 70 | const Desc& desc, |
| 71 | const GrGLIRect& viewport) |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 72 | : INHERITED(gpu, |
| 73 | NULL, |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame^] | 74 | MakeDesc(kNone_GrTextureFlags, |
| 75 | viewport.fWidth, viewport.fHeight, |
| 76 | desc.fConfig, desc.fSampleCnt, |
| 77 | kDefault_CacheID)) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 78 | this->init(desc, viewport, NULL); |
| 79 | } |
| 80 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 81 | void GrGLRenderTarget::onRelease() { |
| 82 | GPUGL->notifyRenderTargetDelete(this); |
| 83 | if (fOwnIDs) { |
| 84 | if (fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 85 | GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 86 | } |
| 87 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 88 | GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 89 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 90 | if (fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 91 | GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | fRTFBOID = 0; |
| 95 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 96 | fMSColorRenderbufferID = 0; |
| 97 | GrSafeUnref(fTexIDObj); |
| 98 | fTexIDObj = NULL; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 99 | this->setStencilBuffer(NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void GrGLRenderTarget::onAbandon() { |
| 103 | fRTFBOID = 0; |
| 104 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 105 | fMSColorRenderbufferID = 0; |
| 106 | if (NULL != fTexIDObj) { |
| 107 | fTexIDObj->abandon(); |
| 108 | fTexIDObj = NULL; |
| 109 | } |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 110 | this->setStencilBuffer(NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 111 | } |
| 112 | |