blob: 39aa332597ae1794abf05811664feda6ec079735 [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)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000033 : INHERITED(gpu,
34 texture,
35 viewport.fWidth,
36 viewport.fHeight,
37 texture->allocatedWidth(),
38 texture->allocatedHeight(),
39 desc.fConfig,
40 desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000041 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);
46 this->init(desc, viewport, texID);
47}
48
49GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
50 const Desc& desc,
51 const GrGLIRect& viewport)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000052 : INHERITED(gpu,
53 NULL,
54 viewport.fWidth,
55 viewport.fHeight,
56 viewport.fWidth, // don't really need separate alloc w/h for
57 viewport.fHeight, // non-texture RTs, repeat viewport values
58 desc.fConfig,
59 desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000060 this->init(desc, viewport, NULL);
61}
62
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000063void GrGLRenderTarget::onRelease() {
64 GPUGL->notifyRenderTargetDelete(this);
65 if (fOwnIDs) {
66 if (fTexFBOID) {
67 GR_GL(DeleteFramebuffers(1, &fTexFBOID));
68 }
69 if (fRTFBOID && fRTFBOID != fTexFBOID) {
70 GR_GL(DeleteFramebuffers(1, &fRTFBOID));
71 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000072 if (fMSColorRenderbufferID) {
73 GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
74 }
75 }
76 fRTFBOID = 0;
77 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000078 fMSColorRenderbufferID = 0;
79 GrSafeUnref(fTexIDObj);
80 fTexIDObj = NULL;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000081 GrSafeSetNull(fStencilBuffer);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000082}
83
84void GrGLRenderTarget::onAbandon() {
85 fRTFBOID = 0;
86 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000087 fMSColorRenderbufferID = 0;
88 if (NULL != fTexIDObj) {
89 fTexIDObj->abandon();
90 fTexIDObj = NULL;
91 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000092 GrSafeSetNull(fStencilBuffer);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000093}
94