blob: c98914a3b81c580c89e6590c7400d036379fffb0 [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,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000039 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);
bsalomon@google.com99621082011-11-15 16:47:16 +000046
47 // we assume this is true, TODO: get rid of viewport as a param.
48 GrAssert(viewport.fWidth == texture->width());
49 GrAssert(viewport.fHeight == texture->height());
50
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000051 this->init(desc, viewport, texID);
52}
53
54GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
55 const Desc& desc,
56 const GrGLIRect& viewport)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000057 : INHERITED(gpu,
58 NULL,
59 viewport.fWidth,
60 viewport.fHeight,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000061 desc.fConfig,
62 desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000063 this->init(desc, viewport, NULL);
64}
65
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000066void GrGLRenderTarget::onRelease() {
67 GPUGL->notifyRenderTargetDelete(this);
68 if (fOwnIDs) {
69 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000070 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000071 }
72 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000073 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000074 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000075 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000076 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000077 }
78 }
79 fRTFBOID = 0;
80 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000081 fMSColorRenderbufferID = 0;
82 GrSafeUnref(fTexIDObj);
83 fTexIDObj = NULL;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000084 this->setStencilBuffer(NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000085}
86
87void GrGLRenderTarget::onAbandon() {
88 fRTFBOID = 0;
89 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000090 fMSColorRenderbufferID = 0;
91 if (NULL != fTexIDObj) {
92 fTexIDObj->abandon();
93 fTexIDObj = NULL;
94 }
bsalomon@google.com558a75b2011-08-08 17:01:14 +000095 this->setStencilBuffer(NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000096}
97