blob: de9f4c1aa08c15198a8c00e29c1b25be0fe76b74 [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;
senorblanco@chromium.orgd0925242013-06-10 15:06:09 +000035 bool fCheckAllocation;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000036 };
37
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000038 // creates a GrGLRenderTarget associated with a texture
39 GrGLRenderTarget(GrGpuGL* gpu,
40 const Desc& desc,
41 const GrGLIRect& viewport,
42 GrGLTexID* texID,
43 GrGLTexture* texture);
44
45 // creates an independent GrGLRenderTarget
46 GrGLRenderTarget(GrGpuGL* gpu,
47 const Desc& desc,
48 const GrGLIRect& viewport);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000049
50 virtual ~GrGLRenderTarget() { this->release(); }
51
52 void setViewport(const GrGLIRect& rect) { fViewport = rect; }
53 const GrGLIRect& getViewport() const { return fViewport; }
54
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055 // The following two functions return the same ID when a
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000056 // texture/render target is multisampled, and different IDs when
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000057 // it is.
58 // FBO ID used to render into
59 GrGLuint renderFBOID() const { return fRTFBOID; }
60 // FBO ID that has texture ID attached.
61 GrGLuint textureFBOID() const { return fTexFBOID; }
62
rmistry@google.comfbfcd562012-08-23 18:09:54 +000063 // override of GrRenderTarget
bsalomon@google.com08afc842012-10-25 18:56:10 +000064 virtual GrBackendObject getRenderTargetHandle() const {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000065 return this->renderFBOID();
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000066 }
bsalomon@google.com08afc842012-10-25 18:56:10 +000067 virtual GrBackendObject getRenderTargetResolvedHandle() const {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000068 return this->textureFBOID();
69 }
70 virtual ResolveType getResolveType() const {
bsalomon@google.come269f212011-11-07 13:29:52 +000071
72 if (!this->isMultisampled() ||
73 fRTFBOID == fTexFBOID) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000074 // catches FBO 0 and non MSAA case
75 return kAutoResolves_ResolveType;
76 } else if (kUnresolvableFBOID == fTexFBOID) {
77 return kCantResolve_ResolveType;
78 } else {
79 return kCanResolve_ResolveType;
80 }
81 }
82
83protected:
84 // override of GrResource
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000085 virtual void onAbandon() SK_OVERRIDE;
86 virtual void onRelease() SK_OVERRIDE;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000087
88private:
89 GrGLuint fRTFBOID;
90 GrGLuint fTexFBOID;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000091
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000092 GrGLuint fMSColorRenderbufferID;
93
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000094 // when we switch to this render target we want to set the viewport to
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000095 // only render to to content area (as opposed to the whole allocation) and
96 // we want the rendering to be at top left (GL has origin in bottom left)
97 GrGLIRect fViewport;
98
99 // non-NULL if this RT was created by Gr with an associated GrGLTexture.
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +0000100 SkAutoTUnref<GrGLTexID> fTexIDObj;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000101
bsalomon@google.com5bfc2172011-07-29 20:29:05 +0000102 void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID);
103
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000104 typedef GrRenderTarget INHERITED;
105};
106
107#endif