blob: 9bbc842e7277aa64d81df6518db8c4dc5f562cda [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
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000028namespace {
29GrTextureDesc MakeDesc(GrTextureFlags flags,
30 int width, int height,
robertphillips@google.com9c2ea842012-08-13 17:47:59 +000031 GrPixelConfig config, int sampleCnt) {
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000032 GrTextureDesc temp;
33 temp.fFlags = flags;
34 temp.fWidth = width;
35 temp.fHeight = height;
36 temp.fConfig = config;
37 temp.fSampleCnt = sampleCnt;
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000038 return temp;
39}
40
41};
42
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000043GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
44 const Desc& desc,
45 const GrGLIRect& viewport,
46 GrGLTexID* texID,
47 GrGLTexture* texture)
bsalomon@google.com0168afc2011-08-08 13:21:05 +000048 : INHERITED(gpu,
49 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,
72 NULL,
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000073 MakeDesc(kNone_GrTextureFlags,
74 viewport.fWidth, viewport.fHeight,
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000075 desc.fConfig, desc.fSampleCnt),
76 kBottomLeft_Origin) {
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000077 this->init(desc, viewport, NULL);
78}
79
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000080void GrGLRenderTarget::onRelease() {
81 GPUGL->notifyRenderTargetDelete(this);
82 if (fOwnIDs) {
83 if (fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000084 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000085 }
86 if (fRTFBOID && fRTFBOID != fTexFBOID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000087 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000088 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000089 if (fMSColorRenderbufferID) {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000090 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000091 }
92 }
93 fRTFBOID = 0;
94 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000095 fMSColorRenderbufferID = 0;
96 GrSafeUnref(fTexIDObj);
97 fTexIDObj = NULL;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000098 INHERITED::onRelease();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000099}
100
101void GrGLRenderTarget::onAbandon() {
102 fRTFBOID = 0;
103 fTexFBOID = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000104 fMSColorRenderbufferID = 0;
105 if (NULL != fTexIDObj) {
106 fTexIDObj->abandon();
107 fTexIDObj = NULL;
108 }
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000109 INHERITED::onAbandon();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000110}
111