blob: 290ae2e47d8973d3ce5526be2ee421fd6e03b02a [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.com0b77d682011-08-19 13:28:54 +000016#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
17
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000018void GrGLRenderTarget::init(const Desc& desc,
19 const GrGLIRect& viewport,
20 GrGLTexID* texID) {
21 fRTFBOID = desc.fRTFBOID;
22 fTexFBOID = desc.fTexFBOID;
23 fMSColorRenderbufferID = desc.fMSColorRenderbufferID;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000024 fViewport = viewport;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000025 fOwnIDs = desc.fOwnIDs;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000026 fTexIDObj = texID;
27 GrSafeRef(fTexIDObj);
28}
29
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000030GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
31 const Desc& desc,
32 const GrGLIRect& viewport,
33 GrGLTexID* texID,
34 GrGLTexture* texture)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000035 : INHERITED(gpu,
36 texture,
37 viewport.fWidth,
38 viewport.fHeight,
39 texture->allocatedWidth(),
40 texture->allocatedHeight(),
41 desc.fConfig,
42 desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000043 GrAssert(NULL != texID);
44 GrAssert(NULL != texture);
45 // FBO 0 can't also be a texture, right?
46 GrAssert(0 != desc.fRTFBOID);
47 GrAssert(0 != desc.fTexFBOID);
48 this->init(desc, viewport, texID);
49}
50
51GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
52 const Desc& desc,
53 const GrGLIRect& viewport)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000054 : INHERITED(gpu,
55 NULL,
56 viewport.fWidth,
57 viewport.fHeight,
58 viewport.fWidth, // don't really need separate alloc w/h for
59 viewport.fHeight, // non-texture RTs, repeat viewport values
60 desc.fConfig,
61 desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000062 this->init(desc, viewport, NULL);
63}
64
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000065void GrGLRenderTarget::onRelease() {
66 GPUGL->notifyRenderTargetDelete(this);
67 if (fOwnIDs) {
68 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000069 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000070 }
71 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000072 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000073 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000074 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000075 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000076 }
77 }
78 fRTFBOID = 0;
79 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000080 fMSColorRenderbufferID = 0;
81 GrSafeUnref(fTexIDObj);
82 fTexIDObj = NULL;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000083 this->setStencilBuffer(NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000084}
85
86void GrGLRenderTarget::onAbandon() {
87 fRTFBOID = 0;
88 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000089 fMSColorRenderbufferID = 0;
90 if (NULL != fTexIDObj) {
91 fTexIDObj->abandon();
92 fTexIDObj = NULL;
93 }
bsalomon@google.com558a75b2011-08-08 17:01:14 +000094 this->setStencilBuffer(NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000095}
96