michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef GrGLRenderTarget_DEFINED michael@0: #define GrGLRenderTarget_DEFINED michael@0: michael@0: #include "GrGLIRect.h" michael@0: #include "GrRenderTarget.h" michael@0: #include "SkScalar.h" michael@0: michael@0: class GrGpuGL; michael@0: class GrGLTexture; michael@0: class GrGLTexID; michael@0: michael@0: class GrGLRenderTarget : public GrRenderTarget { michael@0: michael@0: public: michael@0: // set fTexFBOID to this value to indicate that it is multisampled but michael@0: // Gr doesn't know how to resolve it. michael@0: enum { kUnresolvableFBOID = 0 }; michael@0: michael@0: struct Desc { michael@0: GrGLuint fRTFBOID; michael@0: GrGLuint fTexFBOID; michael@0: GrGLuint fMSColorRenderbufferID; michael@0: bool fIsWrapped; michael@0: GrPixelConfig fConfig; michael@0: int fSampleCnt; michael@0: GrSurfaceOrigin fOrigin; michael@0: bool fCheckAllocation; michael@0: }; michael@0: michael@0: // creates a GrGLRenderTarget associated with a texture michael@0: GrGLRenderTarget(GrGpuGL* gpu, michael@0: const Desc& desc, michael@0: const GrGLIRect& viewport, michael@0: GrGLTexID* texID, michael@0: GrGLTexture* texture); michael@0: michael@0: // creates an independent GrGLRenderTarget michael@0: GrGLRenderTarget(GrGpuGL* gpu, michael@0: const Desc& desc, michael@0: const GrGLIRect& viewport); michael@0: michael@0: virtual ~GrGLRenderTarget() { this->release(); } michael@0: michael@0: void setViewport(const GrGLIRect& rect) { fViewport = rect; } michael@0: const GrGLIRect& getViewport() const { return fViewport; } michael@0: michael@0: // The following two functions return the same ID when a michael@0: // texture/render target is multisampled, and different IDs when michael@0: // it is. michael@0: // FBO ID used to render into michael@0: GrGLuint renderFBOID() const { return fRTFBOID; } michael@0: // FBO ID that has texture ID attached. michael@0: GrGLuint textureFBOID() const { return fTexFBOID; } michael@0: michael@0: // override of GrRenderTarget michael@0: virtual GrBackendObject getRenderTargetHandle() const { michael@0: return this->renderFBOID(); michael@0: } michael@0: virtual GrBackendObject getRenderTargetResolvedHandle() const { michael@0: return this->textureFBOID(); michael@0: } michael@0: virtual ResolveType getResolveType() const { michael@0: michael@0: if (!this->isMultisampled() || michael@0: fRTFBOID == fTexFBOID) { michael@0: // catches FBO 0 and non MSAA case michael@0: return kAutoResolves_ResolveType; michael@0: } else if (kUnresolvableFBOID == fTexFBOID) { michael@0: return kCantResolve_ResolveType; michael@0: } else { michael@0: return kCanResolve_ResolveType; michael@0: } michael@0: } michael@0: michael@0: protected: michael@0: // override of GrResource michael@0: virtual void onAbandon() SK_OVERRIDE; michael@0: virtual void onRelease() SK_OVERRIDE; michael@0: michael@0: private: michael@0: GrGLuint fRTFBOID; michael@0: GrGLuint fTexFBOID; michael@0: michael@0: GrGLuint fMSColorRenderbufferID; michael@0: michael@0: // when we switch to this render target we want to set the viewport to michael@0: // only render to to content area (as opposed to the whole allocation) and michael@0: // we want the rendering to be at top left (GL has origin in bottom left) michael@0: GrGLIRect fViewport; michael@0: michael@0: // non-NULL if this RT was created by Gr with an associated GrGLTexture. michael@0: SkAutoTUnref fTexIDObj; michael@0: michael@0: void init(const Desc& desc, const GrGLIRect& viewport, GrGLTexID* texID); michael@0: michael@0: typedef GrRenderTarget INHERITED; michael@0: }; michael@0: michael@0: #endif