blob: ea6ae87b99420557cdd8334b1afce8c609b232a8 [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
8
9#ifndef GrGLRenderTarget_DEFINED
10#define GrGLRenderTarget_DEFINED
11
12#include "GrGLIRect.h"
13#include "GrRenderTarget.h"
bsalomon@google.com81712882012-11-01 17:12:34 +000014#include "SkScalar.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000015
16class GrGpuGL;
17class GrGLTexture;
18class GrGLTexID;
19
20class GrGLRenderTarget : public GrRenderTarget {
21
22public:
23 // set fTexFBOID to this value to indicate that it is multisampled but
24 // Gr doesn't know how to resolve it.
25 enum { kUnresolvableFBOID = 0 };
26
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000027 struct Desc {
senorblanco@chromium.org3cb406b2013-02-05 19:50:46 +000028 GrGLuint fRTFBOID;
29 GrGLuint fTexFBOID;
30 GrGLuint fMSColorRenderbufferID;
31 bool fIsWrapped;
32 GrPixelConfig fConfig;
33 int fSampleCnt;
34 GrSurfaceOrigin fOrigin;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000035 };
36
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000037 // creates a GrGLRenderTarget associated with a texture
38 GrGLRenderTarget(GrGpuGL* gpu,
39 const Desc& desc,
40 const GrGLIRect& viewport,
41 GrGLTexID* texID,
42 GrGLTexture* texture);
43
44 // creates an independent GrGLRenderTarget
45 GrGLRenderTarget(GrGpuGL* gpu,
46 const Desc& desc,
47 const GrGLIRect& viewport);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000048
49 virtual ~GrGLRenderTarget() { this->release(); }
50
51 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
52 const GrGLIRect& getViewport() const { return fViewport; }
53
rmistry@google.comfbfcd562012-08-23 18:09:54 +000054 // The following two functions return the same ID when a
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000055 // texture/render target is multisampled, and different IDs when
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000056 // it is.
57 // FBO ID used to render into
58 GrGLuint renderFBOID() const { return fRTFBOID; }
59 // FBO ID that has texture ID attached.
60 GrGLuint textureFBOID() const { return fTexFBOID; }
61
rmistry@google.comfbfcd562012-08-23 18:09:54 +000062 // override of GrRenderTarget
bsalomon@google.com08afc842012-10-25 18:56:10 +000063 virtual GrBackendObject getRenderTargetHandle() const {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000064 return this->renderFBOID();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000065 }
bsalomon@google.com08afc842012-10-25 18:56:10 +000066 virtual GrBackendObject getRenderTargetResolvedHandle() const {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000067 return this->textureFBOID();
68 }
69 virtual ResolveType getResolveType() const {
bsalomon@google.come269f212011-11-07 13:29:52 +000070
71 if (!this->isMultisampled() ||
72 fRTFBOID == fTexFBOID) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000073 // catches FBO 0 and non MSAA case
74 return kAutoResolves_ResolveType;
75 } else if (kUnresolvableFBOID == fTexFBOID) {
76 return kCantResolve_ResolveType;
77 } else {
78 return kCanResolve_ResolveType;
79 }
80 }
81
82protected:
83 // override of GrResource
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000084 virtual void onAbandon() SK_OVERRIDE;
85 virtual void onRelease() SK_OVERRIDE;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000086
87private:
88 GrGLuint fRTFBOID;
89 GrGLuint fTexFBOID;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000090
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000091 GrGLuint fMSColorRenderbufferID;
92
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000093 // when we switch to this render target we want to set the viewport to
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000094 // only render to to content area (as opposed to the whole allocation) and
95 // we want the rendering to be at top left (GL has origin in bottom left)
96 GrGLIRect fViewport;
97
98 // non-NULL if this RT was created by Gr with an associated GrGLTexture.
99 GrGLTexID* fTexIDObj;
100
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000101 void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
102
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000103 typedef GrRenderTarget INHERITED;
104};
105
106#endif