blob: eb817df6f0f7a3a4c3c6379eb0988d41490c9e06 [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef GrGLRenderTarget_DEFINED
11#define GrGLRenderTarget_DEFINED
12
13#include "GrGLIRect.h"
14#include "GrRenderTarget.h"
15#include "GrScalar.h"
16
17class GrGpuGL;
18class GrGLTexture;
19class GrGLTexID;
20
21class GrGLRenderTarget : public GrRenderTarget {
22
23public:
24 // set fTexFBOID to this value to indicate that it is multisampled but
25 // Gr doesn't know how to resolve it.
26 enum { kUnresolvableFBOID = 0 };
27
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000028 struct Desc {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000029 GrGLuint fRTFBOID;
30 GrGLuint fTexFBOID;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000031 GrGLuint fMSColorRenderbufferID;
32 bool fOwnIDs;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000033 GrPixelConfig fConfig;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000034 int fSampleCnt;
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
54 // The following two functions return the same ID when a
55 // texture-rendertarget is multisampled, and different IDs when
56 // 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
62 // override of GrRenderTarget
63 virtual intptr_t getRenderTargetHandle() const {
64 return this->renderFBOID();
65 }
66 virtual intptr_t getRenderTargetResolvedHandle() const {
67 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
84 virtual void onAbandon();
85 virtual void onRelease();
86
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
93 // Should this object delete IDs when it is destroyed or does someone
94 // else own them.
95 bool fOwnIDs;
96
97 // when we switch to this rendertarget we want to set the viewport to
98 // only render to to content area (as opposed to the whole allocation) and
99 // we want the rendering to be at top left (GL has origin in bottom left)
100 GrGLIRect fViewport;
101
102 // non-NULL if this RT was created by Gr with an associated GrGLTexture.
103 GrGLTexID* fTexIDObj;
104
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000105 void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
106
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000107 typedef GrRenderTarget INHERITED;
108};
109
110#endif