1 /**************************************************************************** 2 Copyright (c) 2010-2012 cocos2d-x.org 3 Copyright (c) 2008-2010 Ricardo Quesada 4 Copyright (c) 2011 Zynga Inc. 5 6 http://www.cocos2d-x.org 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this software and associated documentation files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE. 25 ****************************************************************************/ 26 27 var cc = cc = cc || {}; 28 29 /** FBO class that grabs the the contents of the screen */ 30 cc.Grabber = cc.Class.extend({ 31 _fbo:0, 32 _oldFBO:0, 33 _glesVersion:null, 34 ctor:function () { 35 // generate FBO 36 //todo gl 37 //ccglGenFramebuffers(1, this._fbo); 38 }, 39 grab:function (texture) { 40 //todo gl 41 /*glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, this._oldFBO); 42 43 // bind 44 ccglBindFramebuffer(CC_GL_FRAMEBUFFER, this._fbo); 45 46 // associate texture with FBO 47 ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 48 texture.getName(), 0); 49 50 // check if it worked (probably worth doing :) ) 51 var status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER); 52 if (status != CC_GL_FRAMEBUFFER_COMPLETE) { 53 cc.log("Frame Grabber: could not attach texture to frmaebuffer"); 54 } 55 56 ccglBindFramebuffer(CC_GL_FRAMEBUFFER, this._oldFBO);*/ 57 }, 58 beforeRender:function (texture) { 59 //todo gl 60 /*glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, this._oldFBO); 61 ccglBindFramebuffer(CC_GL_FRAMEBUFFER, this._fbo); 62 63 // BUG XXX: doesn't work with RGB565. 64 65 */ 66 /*glClearColor(0, 0, 0, 0);*/ 67 /* 68 69 // BUG #631: To fix #631, uncomment the lines with #631 70 // Warning: But it CCGrabber won't work with 2 effects at the same time 71 glClearColor(0.0, 0.0, 0.0, 1.0); // #631 72 73 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 74 75 glColorMask(true, true, true, false); // #631*/ 76 }, 77 afterRender:function (texture) { 78 //todo gl 79 /* ccglBindFramebuffer(CC_GL_FRAMEBUFFER, this._oldFBO); 80 glColorMask(true, true, true, true); // #631*/ 81 } 82 }); 83