blob: c68283e64847f379228a79f54eeeb100b3a4e33e [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.comaa5b6732011-07-29 15:13:20 +000023 fTexIDObj = texID;
24 GrSafeRef(fTexIDObj);
25}
26
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000027namespace {
28GrTextureDesc MakeDesc(GrTextureFlags flags,
29 int width, int height,
robertphillips@google.com9c2ea842012-08-13 17:47:59 +000030 GrPixelConfig config, int sampleCnt) {
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000031 GrTextureDesc temp;
32 temp.fFlags = flags;
33 temp.fWidth = width;
34 temp.fHeight = height;
35 temp.fConfig = config;
36 temp.fSampleCnt = sampleCnt;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000037 return temp;
38}
39
40};
41
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000042GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
43 const Desc& desc,
44 const GrGLIRect& viewport,
45 GrGLTexID* texID,
46 GrGLTexture* texture)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000047 : INHERITED(gpu,
bsalomon@google.com72830222013-01-23 20:25:22 +000048 desc.fIsWrapped,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000049 texture,
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000050 MakeDesc(kNone_GrTextureFlags,
51 viewport.fWidth, viewport.fHeight,
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000052 desc.fConfig, desc.fSampleCnt),
53 texture->origin()) {
54 GrAssert(kBottomLeft_Origin == texture->origin());
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000055 GrAssert(NULL != texID);
56 GrAssert(NULL != texture);
57 // FBO 0 can't also be a texture, right?
58 GrAssert(0 != desc.fRTFBOID);
59 GrAssert(0 != desc.fTexFBOID);
bsalomon@google.com99621082011-11-15 16:47:16 +000060
61 // we assume this is true, TODO: get rid of viewport as a param.
62 GrAssert(viewport.fWidth == texture->width());
63 GrAssert(viewport.fHeight == texture->height());
64
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000065 this->init(desc, viewport, texID);
66}
67
68GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
69 const Desc& desc,
70 const GrGLIRect& viewport)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000071 : INHERITED(gpu,
bsalomon@google.com72830222013-01-23 20:25:22 +000072 desc.fIsWrapped,
bsalomon@google.com0168afc2011-08-08 13:21:05 +000073 NULL,
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000074 MakeDesc(kNone_GrTextureFlags,
75 viewport.fWidth, viewport.fHeight,
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000076 desc.fConfig, desc.fSampleCnt),
77 kBottomLeft_Origin) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000078 this->init(desc, viewport, NULL);
79}
80
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000081void GrGLRenderTarget::onRelease() {
82 GPUGL->notifyRenderTargetDelete(this);
bsalomon@google.com72830222013-01-23 20:25:22 +000083 if (!this->isWrapped()) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000084 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000085 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000086 }
87 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000088 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000089 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000090 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000091 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000092 }
93 }
94 fRTFBOID = 0;
95 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000096 fMSColorRenderbufferID = 0;
97 GrSafeUnref(fTexIDObj);
98 fTexIDObj = NULL;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000099 INHERITED::onRelease();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000100}
101
102void GrGLRenderTarget::onAbandon() {
103 fRTFBOID = 0;
104 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000105 fMSColorRenderbufferID = 0;
106 if (NULL != fTexIDObj) {
107 fTexIDObj->abandon();
108 fTexIDObj = NULL;
109 }
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000110 INHERITED::onAbandon();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000111}