1 #include "SkGLDevice_FBO.h" 2 #include "SkRegion.h" 3 4 SkGLDevice_FBO::SkGLDevice_FBO(const SkBitmap& bitmap, bool offscreen) 5 : SkGLDevice(bitmap, offscreen) { 6 fFBO = 0; 7 fTextureID = 0; 8 9 if (offscreen) { 10 int nw = SkNextPow2(bitmap.rowBytesAsPixels()); 11 int nh = SkNextPow2(bitmap.height()); 12 13 glGenFramebuffersEXT(1, &fFBO); 14 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fFBO); 15 16 glGenTextures(1, &fTextureID); 17 glBindTexture(GL_TEXTURE_2D, fTextureID); 18 SkGL::SetTexParamsClamp(false); 19 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nw, nh, 0, 20 GL_RGBA, GL_UNSIGNED_BYTE, NULL); 21 22 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, 23 GL_TEXTURE_2D, fTextureID, 0); 24 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 25 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { 26 SkDebugf("-- glCheckFramebufferStatusEXT %x\n", status); 27 } 28 29 // now reset back to "normal" drawing target 30 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 31 } 32 } 33 34 SkGLDevice_FBO::~SkGLDevice_FBO() { 35 if (fTextureID) { 36 glDeleteTextures(1, &fTextureID); 37 } 38 if (fFBO) { 39 glDeleteFramebuffersEXT(1, &fFBO); 40 } 41 } 42 43 SkGLDevice::TexOrientation SkGLDevice_FBO::bindDeviceAsTexture() { 44 if (fTextureID) { 45 glBindTexture(GL_TEXTURE_2D, fTextureID); 46 return kBottomToTop_TexOrientation; 47 } 48 return kNo_TexOrientation; 49 } 50 51 void SkGLDevice_FBO::gainFocus(SkCanvas* canvas) { 52 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fFBO); 53 54 // now we're ready for the viewport and projection matrix 55 this->INHERITED::gainFocus(canvas); 56 } 57 58