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