GrGLRenderTarget.cpp revision 80bacfeb4bda06541e8695bd502229727bccfea
180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc. 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrGLRenderTarget.h" 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrGpuGL.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GPUGL static_cast<GrGpuGL*>(getGpu()) 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid GrGLRenderTarget::init(const Desc& desc, 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const GrGLIRect& viewport, 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrGLTexID* texID) { 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRTFBOID = desc.fRTFBOID; 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTexFBOID = desc.fTexFBOID; 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMSColorRenderbufferID = desc.fMSColorRenderbufferID; 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fViewport = viewport; 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fOwnIDs = desc.fOwnIDs; 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTexIDObj = texID; 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrSafeRef(fTexIDObj); 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querunamespace { 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGrTextureDesc MakeDesc(GrTextureFlags flags, 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int width, int height, 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrPixelConfig config, int sampleCnt) { 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrTextureDesc temp; 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru temp.fFlags = flags; 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru temp.fWidth = width; 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru temp.fHeight = height; 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru temp.fConfig = config; 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru temp.fSampleCnt = sampleCnt; 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return temp; 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Desc& desc, 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const GrGLIRect& viewport, 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrGLTexID* texID, 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrGLTexture* texture) 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru : INHERITED(gpu, 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru texture, 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru MakeDesc(kNone_GrTextureFlags, 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru viewport.fWidth, viewport.fHeight, 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru desc.fConfig, desc.fSampleCnt)) { 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrAssert(NULL != texID); 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrAssert(NULL != texture); 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // FBO 0 can't also be a texture, right? 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrAssert(0 != desc.fRTFBOID); 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrAssert(0 != desc.fTexFBOID); 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // we assume this is true, TODO: get rid of viewport as a param. 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrAssert(viewport.fWidth == texture->width()); 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrAssert(viewport.fHeight == texture->height()); 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->init(desc, viewport, texID); 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruGrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu, 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const Desc& desc, 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const GrGLIRect& viewport) 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru : INHERITED(gpu, 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru NULL, 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru MakeDesc(kNone_GrTextureFlags, 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru viewport.fWidth, viewport.fHeight, 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru desc.fConfig, desc.fSampleCnt)) { 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this->init(desc, viewport, NULL); 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid GrGLRenderTarget::onRelease() { 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GPUGL->notifyRenderTargetDelete(this); 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fOwnIDs) { 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fTexFBOID) { 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fRTFBOID && fRTFBOID != fTexFBOID) { 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (fMSColorRenderbufferID) { 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRTFBOID = 0; 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTexFBOID = 0; 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMSColorRenderbufferID = 0; 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru GrSafeUnref(fTexIDObj); 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTexIDObj = NULL; 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru INHERITED::onRelease(); 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid GrGLRenderTarget::onAbandon() { 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRTFBOID = 0; 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTexFBOID = 0; 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fMSColorRenderbufferID = 0; 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (NULL != fTexIDObj) { 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTexIDObj->abandon(); 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fTexIDObj = NULL; 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru INHERITED::onAbandon(); 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 109