blob: 7be8b32f83c7e9b5cf0680fc0e112c68f5671394 [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.com4043ae22011-08-02 14:19:11 +000022 fStencilRenderbufferID = desc.fStencilRenderbufferID;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000023 fViewport = viewport;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000024 fOwnIDs = desc.fOwnIDs;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000025 fTexIDObj = texID;
26 GrSafeRef(fTexIDObj);
27}
28
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000029GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
30 const Desc& desc,
31 const GrGLIRect& viewport,
32 GrGLTexID* texID,
33 GrGLTexture* texture)
34 : INHERITED(gpu, texture, viewport.fWidth,
bsalomon@google.com4043ae22011-08-02 14:19:11 +000035 viewport.fHeight, desc.fConfig,
36 desc.fStencilBits, desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000037 GrAssert(NULL != texID);
38 GrAssert(NULL != texture);
39 // FBO 0 can't also be a texture, right?
40 GrAssert(0 != desc.fRTFBOID);
41 GrAssert(0 != desc.fTexFBOID);
42 this->init(desc, viewport, texID);
43}
44
45GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
46 const Desc& desc,
47 const GrGLIRect& viewport)
48 : INHERITED(gpu, NULL, viewport.fWidth,
bsalomon@google.com4043ae22011-08-02 14:19:11 +000049 viewport.fHeight, desc.fConfig,
50 desc.fStencilBits, desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000051 this->init(desc, viewport, NULL);
52}
53
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000054void GrGLRenderTarget::onRelease() {
55 GPUGL->notifyRenderTargetDelete(this);
56 if (fOwnIDs) {
57 if (fTexFBOID) {
58 GR_GL(DeleteFramebuffers(1, &fTexFBOID));
59 }
60 if (fRTFBOID && fRTFBOID != fTexFBOID) {
61 GR_GL(DeleteFramebuffers(1, &fRTFBOID));
62 }
bsalomon@google.com4043ae22011-08-02 14:19:11 +000063 if (fStencilRenderbufferID) {
64 GR_GL(DeleteRenderbuffers(1, &fStencilRenderbufferID));
65 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000066 if (fMSColorRenderbufferID) {
67 GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
68 }
69 }
70 fRTFBOID = 0;
71 fTexFBOID = 0;
bsalomon@google.com4043ae22011-08-02 14:19:11 +000072 fStencilRenderbufferID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000073 fMSColorRenderbufferID = 0;
74 GrSafeUnref(fTexIDObj);
75 fTexIDObj = NULL;
76}
77
78void GrGLRenderTarget::onAbandon() {
79 fRTFBOID = 0;
80 fTexFBOID = 0;
bsalomon@google.com4043ae22011-08-02 14:19:11 +000081 fStencilRenderbufferID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000082 fMSColorRenderbufferID = 0;
83 if (NULL != fTexIDObj) {
84 fTexIDObj->abandon();
85 fTexIDObj = NULL;
86 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000087}
88