blob: cce3def89a5bceb8fc2981838dfee5b1ca28ebbd [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00008#include "GrGLRenderTarget.h"
9
10#include "GrGpuGL.h"
11
12#define GPUGL static_cast<GrGpuGL*>(getGpu())
13
bsalomon@google.com0b77d682011-08-19 13:28:54 +000014#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
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,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000037 desc.fConfig,
38 desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000039 GrAssert(NULL != texID);
40 GrAssert(NULL != texture);
41 // FBO 0 can't also be a texture, right?
42 GrAssert(0 != desc.fRTFBOID);
43 GrAssert(0 != desc.fTexFBOID);
bsalomon@google.com99621082011-11-15 16:47:16 +000044
45 // we assume this is true, TODO: get rid of viewport as a param.
46 GrAssert(viewport.fWidth == texture->width());
47 GrAssert(viewport.fHeight == texture->height());
48
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000049 this->init(desc, viewport, texID);
50}
51
52GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
53 const Desc& desc,
54 const GrGLIRect& viewport)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000055 : INHERITED(gpu,
56 NULL,
57 viewport.fWidth,
58 viewport.fHeight,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000059 desc.fConfig,
60 desc.fSampleCnt) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000061 this->init(desc, viewport, NULL);
62}
63
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000064void GrGLRenderTarget::onRelease() {
65 GPUGL->notifyRenderTargetDelete(this);
66 if (fOwnIDs) {
67 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000068 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000069 }
70 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000071 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000072 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000073 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000074 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000075 }
76 }
77 fRTFBOID = 0;
78 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000079 fMSColorRenderbufferID = 0;
80 GrSafeUnref(fTexIDObj);
81 fTexIDObj = NULL;
bsalomon@google.com558a75b2011-08-08 17:01:14 +000082 this->setStencilBuffer(NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000083}
84
85void GrGLRenderTarget::onAbandon() {
86 fRTFBOID = 0;
87 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000088 fMSColorRenderbufferID = 0;
89 if (NULL != fTexIDObj) {
90 fTexIDObj->abandon();
91 fTexIDObj = NULL;
92 }
bsalomon@google.com558a75b2011-08-08 17:01:14 +000093 this->setStencilBuffer(NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000094}
95