blob: 38b9eb7a530f1648bc34e51dc212599a5c0b2364 [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001
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.com5bfc2172011-07-29 20:29:05 +000016void 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.comaa5b6732011-07-29 15:13:20 +000022 fViewport = viewport;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000023 fOwnIDs = desc.fOwnIDs;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000024 fTexIDObj = texID;
25 GrSafeRef(fTexIDObj);
26}
27
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000028GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
29 const Desc& desc,
30 const GrGLIRect& viewport,
31 GrGLTexID* texID,
32 GrGLTexture* texture)
33 : INHERITED(gpu, texture, viewport.fWidth,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000034 viewport.fHeight, desc.fConfig, desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000035 GrAssert(NULL != texID);
36 GrAssert(NULL != texture);
37 // FBO 0 can't also be a texture, right?
38 GrAssert(0 != desc.fRTFBOID);
39 GrAssert(0 != desc.fTexFBOID);
40 this->init(desc, viewport, texID);
41}
42
43GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
44 const Desc& desc,
45 const GrGLIRect& viewport)
46 : INHERITED(gpu, NULL, viewport.fWidth,
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000047 viewport.fHeight, desc.fConfig, desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000048 this->init(desc, viewport, NULL);
49}
50
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000051void GrGLRenderTarget::onRelease() {
52 GPUGL->notifyRenderTargetDelete(this);
53 if (fOwnIDs) {
54 if (fTexFBOID) {
55 GR_GL(DeleteFramebuffers(1, &fTexFBOID));
56 }
57 if (fRTFBOID && fRTFBOID != fTexFBOID) {
58 GR_GL(DeleteFramebuffers(1, &fRTFBOID));
59 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000060 if (fMSColorRenderbufferID) {
61 GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
62 }
63 }
64 fRTFBOID = 0;
65 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000066 fMSColorRenderbufferID = 0;
67 GrSafeUnref(fTexIDObj);
68 fTexIDObj = NULL;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000069 GrSafeSetNull(fStencilBuffer);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000070}
71
72void GrGLRenderTarget::onAbandon() {
73 fRTFBOID = 0;
74 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000075 fMSColorRenderbufferID = 0;
76 if (NULL != fTexIDObj) {
77 fTexIDObj->abandon();
78 fTexIDObj = NULL;
79 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000080 GrSafeSetNull(fStencilBuffer);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000081}
82