blob: 64b0d2190201d679a0fb05f9c9c224cfb61e6da9 [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"
14#include "GrScalar.h"
15
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 {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000028 GrGLuint fRTFBOID;
29 GrGLuint fTexFBOID;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000030 GrGLuint fMSColorRenderbufferID;
31 bool fOwnIDs;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000032 GrPixelConfig fConfig;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000033 int fSampleCnt;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000034 };
35
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000036 // creates a GrGLRenderTarget associated with a texture
37 GrGLRenderTarget(GrGpuGL* gpu,
38 const Desc& desc,
39 const GrGLIRect& viewport,
40 GrGLTexID* texID,
41 GrGLTexture* texture);
42
43 // creates an independent GrGLRenderTarget
44 GrGLRenderTarget(GrGpuGL* gpu,
45 const Desc& desc,
46 const GrGLIRect& viewport);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000047
48 virtual ~GrGLRenderTarget() { this->release(); }
49
50 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
51 const GrGLIRect& getViewport() const { return fViewport; }
52
rmistry@google.comfbfcd562012-08-23 18:09:54 +000053 // The following two functions return the same ID when a
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000054 // texture-rendertarget is multisampled, and different IDs when
55 // it is.
56 // FBO ID used to render into
57 GrGLuint renderFBOID() const { return fRTFBOID; }
58 // FBO ID that has texture ID attached.
59 GrGLuint textureFBOID() const { return fTexFBOID; }
60
rmistry@google.comfbfcd562012-08-23 18:09:54 +000061 // override of GrRenderTarget
bsalomon@google.com08afc842012-10-25 18:56:10 +000062 virtual GrBackendObject getRenderTargetHandle() const {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000063 return this->renderFBOID();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000064 }
bsalomon@google.com08afc842012-10-25 18:56:10 +000065 virtual GrBackendObject getRenderTargetResolvedHandle() const {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000066 return this->textureFBOID();
67 }
68 virtual ResolveType getResolveType() const {
bsalomon@google.come269f212011-11-07 13:29:52 +000069
70 if (!this->isMultisampled() ||
71 fRTFBOID == fTexFBOID) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000072 // catches FBO 0 and non MSAA case
73 return kAutoResolves_ResolveType;
74 } else if (kUnresolvableFBOID == fTexFBOID) {
75 return kCantResolve_ResolveType;
76 } else {
77 return kCanResolve_ResolveType;
78 }
79 }
80
81protected:
82 // override of GrResource
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000083 virtual void onAbandon() SK_OVERRIDE;
84 virtual void onRelease() SK_OVERRIDE;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000085
86private:
87 GrGLuint fRTFBOID;
88 GrGLuint fTexFBOID;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000089
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000090 GrGLuint fMSColorRenderbufferID;
91
92 // Should this object delete IDs when it is destroyed or does someone
93 // else own them.
94 bool fOwnIDs;
95
96 // when we switch to this rendertarget we want to set the viewport to
97 // only render to to content area (as opposed to the whole allocation) and
98 // we want the rendering to be at top left (GL has origin in bottom left)
99 GrGLIRect fViewport;
100
101 // non-NULL if this RT was created by Gr with an associated GrGLTexture.
102 GrGLTexID* fTexIDObj;
103
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000104 void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
105
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000106 typedef GrRenderTarget INHERITED;
107};
108
109#endif