From 2e73f631568aef097cdb8c1741936cd30321f189 Mon Sep 17 00:00:00 2001 From: elsanide Date: Tue, 10 Jun 2014 18:15:07 +0900 Subject: [PATCH 01/20] #5506 bug fix when Director->convertToUI() called, returned wrong value. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kazmath code (under 3.0 version.) //******************************************************** kmVec3* kmVec3TransformCoord(kmVec3* pOut, const kmVec3* pV, const kmMat4* pM) { /* a = (Vx, Vy, Vz, 1) b = (a×M)T Out = 1 ⁄ bw(bx, by, bz) */ kmVec4 v; kmVec4 inV; kmVec4Fill(&inV, pV->x, pV->y, pV->z, 1.0); kmVec4Transform(&v, &inV,pM); pOut->x = v.x / v.w; pOut->y = v.y / v.w; pOut->z = v.z / v.w; return pOut; } //******************************************************** Mat4.h & MathUtil version (3.1 or later) //******************************************************** inline void MathUtil::transformVec4(const float* m, const float* v, float* dst) { // Handle case where v == dst. float x = v[0] * m[0] + v[1] * m[4] + v[2] * m[8] + v[3] * m[12]; float y = v[0] * m[1] + v[1] * m[5] + v[2] * m[9] + v[3] * m[13]; float z = v[0] * m[2] + v[1] * m[6] + v[2] * m[10] + v[3] * m[14]; float w = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15]; dst[0] = x; dst[1] = y; dst[2] = z; dst[3] = w; } //**************************************************** Transforms 3-D vector or an array of 3-D vectors using a given matrix, projecting the result back into w = 1. but, it is not apply w = 1. --- cocos/base/CCDirector.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 9d1e02f187..ac7519a062 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** Copyright (c) 2008-2010 Ricardo Quesada Copyright (c) 2010-2013 cocos2d-x.org Copyright (c) 2011 Zynga Inc. @@ -763,6 +763,18 @@ Vec2 Director::convertToUI(const Vec2& glPoint) Vec4 glCoord(glPoint.x, glPoint.y, 0.0, 1); transform.transformVector(glCoord, &clipCoord); + /* + BUG-FIX #5506 + + a = (Vx, Vy, Vz, 1) + b = (a×M)T + Out = 1 ⁄ bw(bx, by, bz) + */ + + clipCoord.x = clipCoord.x / clipCoord.w; + clipCoord.y = clipCoord.y / clipCoord.w; + clipCoord.z = clipCoord.z / clipCoord.w; + Size glSize = _openGLView->getDesignResolutionSize(); float factor = 1.0/glCoord.w; return Vec2(glSize.width*(clipCoord.x*0.5 + 0.5) * factor, glSize.height*(-clipCoord.y*0.5 + 0.5) * factor); From 8ba4c7a083426e42122d263799b3d1476d249dc1 Mon Sep 17 00:00:00 2001 From: Sachin Garg Date: Tue, 10 Jun 2014 17:59:15 +0530 Subject: [PATCH 02/20] GLProgram should not abort() if shader compilation fails, returning false will allow app to show custom error message to user (or use other simple shaders if a complicated shader fails to compile on some device). --- cocos/renderer/CCGLProgram.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cocos/renderer/CCGLProgram.cpp b/cocos/renderer/CCGLProgram.cpp index e198cfa2c4..a95e7e714a 100644 --- a/cocos/renderer/CCGLProgram.cpp +++ b/cocos/renderer/CCGLProgram.cpp @@ -138,9 +138,17 @@ GLProgram::~GLProgram() { CCLOGINFO("%s %d deallocing GLProgram: %p", __FUNCTION__, __LINE__, this); - // there is no need to delete the shaders. They should have been already deleted. - CCASSERT(_vertShader == 0, "Vertex Shaders should have been already deleted"); - CCASSERT(_fragShader == 0, "Fragment Shaders should have been already deleted"); + if (_vertShader) + { + glDeleteShader(_vertShader); + } + + if (_fragShader) + { + glDeleteShader(_fragShader); + } + + _vertShader = _fragShader = 0; if (_program) { @@ -436,7 +444,7 @@ bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source } free(src); - abort(); + return false;; } return (status == GL_TRUE); } From e2c75c1f113002babf0b108a128fc1cda2ccef39 Mon Sep 17 00:00:00 2001 From: vision Date: Wed, 11 Jun 2014 14:54:14 +0800 Subject: [PATCH 03/20] New shader for the blur effect, the old one is ineffecient and difficult to maintain. --- .../Classes/ShaderTest/ShaderTest.cpp | 64 +++------------ .../Classes/ShaderTest/ShaderTest2.cpp | 71 +++------------- .../Resources/Shaders/example_Blur.fsh | 82 ++++++++----------- 3 files changed, 59 insertions(+), 158 deletions(-) diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp index 9aa84d87e0..07d764601b 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp @@ -421,22 +421,14 @@ class SpriteBlur : public Sprite { public: ~SpriteBlur(); - void setBlurSize(float f); + void setBlurRadius(float radius); bool initWithTexture(Texture2D* texture, const Rect& rect); void initGLProgram(); static SpriteBlur* create(const char *pszFileName); protected: - - int _blurRadius; - Vec2 _pixelSize; - - int _samplingRadius; - //gaussian = cons * exp( (dx*dx + dy*dy) * scale); - float _scale; - float _cons; - float _weightSum; + float _blurRadius; }; SpriteBlur::~SpriteBlur() @@ -472,14 +464,7 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect) _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); #endif - auto s = getTexture()->getContentSizeInPixels(); - - _pixelSize = Vec2(1/s.width, 1/s.height); - - _samplingRadius = 0; - this->initGLProgram(); - - getGLProgramState()->setUniformVec2("onePixelSize", _pixelSize); + initGLProgram(); return true; } @@ -495,43 +480,16 @@ void SpriteBlur::initGLProgram() auto glProgramState = GLProgramState::getOrCreateWithGLProgram(program); setGLProgramState(glProgramState); + + auto size = getTexture()->getContentSizeInPixels(); + getGLProgramState()->setUniformVec2("resolution", size); + getGLProgramState()->setUniformFloat("blurRadius", _blurRadius); } -void SpriteBlur::setBlurSize(float f) +void SpriteBlur::setBlurRadius(float radius) { - if(_blurRadius == (int)f) - return; - _blurRadius = (int)f; - - _samplingRadius = _blurRadius; - if (_samplingRadius > 10) - { - _samplingRadius = 10; - } - if (_blurRadius > 0) - { - float sigma = _blurRadius / 2.0f; - _scale = -0.5f / (sigma * sigma); - _cons = -1.0f * _scale / 3.141592f; - _weightSum = -_cons; - - float weight; - int squareX; - for(int dx = 0; dx <= _samplingRadius; ++dx) - { - squareX = dx * dx; - weight = _cons * exp(squareX * _scale); - _weightSum += 2.0 * weight; - for (int dy = 1; dy <= _samplingRadius; ++dy) - { - weight = _cons * exp((squareX + dy * dy) * _scale); - _weightSum += 4.0 * weight; - } - } - } - log("_blurRadius:%d",_blurRadius); - - getGLProgramState()->setUniformVec4("gaussianCoefficient", Vec4(_samplingRadius, _scale, _cons, _weightSum)); + _blurRadius = radius; + getGLProgramState()->setUniformFloat("blurRadius", _blurRadius); } // ShaderBlur @@ -597,7 +555,7 @@ bool ShaderBlur::init() void ShaderBlur::sliderAction(Ref* sender, Control::EventType controlEvent) { ControlSlider* slider = (ControlSlider*)sender; - _blurSprite->setBlurSize(slider->getValue()); + _blurSprite->setBlurRadius(slider->getValue()); } // ShaderRetroEffect diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp index dfd250e781..f406ae8cd7 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp @@ -249,80 +249,33 @@ class EffectBlur : public Effect { public: CREATE_FUNC(EffectBlur); - virtual void setTarget(EffectSprite *sprite) override; - - void setGaussian(float value); - void setCustomUniforms(); - void setBlurSize(float f); + void setBlurRadius(float radius); protected: - bool init(float blurSize=3.0); - - int _blurRadius; - Vec2 _pixelSize; - - int _samplingRadius; - float _scale; - float _cons; - float _weightSum; + bool init(float blurRadius = 10.0f); + + float _blurRadius; }; void EffectBlur::setTarget(EffectSprite *sprite) { - Size s = sprite->getTexture()->getContentSizeInPixels(); - _pixelSize = Vec2(1/s.width, 1/s.height); - _glprogramstate->setUniformVec2("onePixelSize", _pixelSize); + Size size = sprite->getTexture()->getContentSizeInPixels(); + _glprogramstate->setUniformVec2("resolution", size); + _glprogramstate->setUniformFloat("blurRadius", _blurRadius); } -bool EffectBlur::init(float blurSize) +bool EffectBlur::init(float blurRadius) { initGLProgramState("Shaders/example_Blur.fsh"); - auto s = Size(100,100); - - _blurRadius = 0; - _pixelSize = Vec2(1/s.width, 1/s.height); - _samplingRadius = 0; - - setBlurSize(blurSize); - - _glprogramstate->setUniformVec2("onePixelSize", _pixelSize); - _glprogramstate->setUniformVec4("gaussianCoefficient", Vec4(_samplingRadius, _scale, _cons, _weightSum)); + _blurRadius = blurRadius; + return true; } -void EffectBlur::setBlurSize(float f) +void EffectBlur::setBlurRadius(float radius) { - if(_blurRadius == (int)f) - return; - _blurRadius = (int)f; - - _samplingRadius = _blurRadius; - if (_samplingRadius > 10) - { - _samplingRadius = 10; - } - if (_blurRadius > 0) - { - float sigma = _blurRadius / 2.0f; - _scale = -0.5f / (sigma * sigma); - _cons = -1.0f * _scale / 3.141592f; - _weightSum = -_cons; - - float weight; - int squareX; - for(int dx = 0; dx <= _samplingRadius; ++dx) - { - squareX = dx * dx; - weight = _cons * exp(squareX * _scale); - _weightSum += 2.0 * weight; - for (int dy = 1; dy <= _samplingRadius; ++dy) - { - weight = _cons * exp((squareX + dy * dy) * _scale); - _weightSum += 4.0 * weight; - } - } - } + _blurRadius = radius; } // Outline diff --git a/tests/cpp-tests/Resources/Shaders/example_Blur.fsh b/tests/cpp-tests/Resources/Shaders/example_Blur.fsh index 169795bc0e..c0f94933cd 100644 --- a/tests/cpp-tests/Resources/Shaders/example_Blur.fsh +++ b/tests/cpp-tests/Resources/Shaders/example_Blur.fsh @@ -1,5 +1,3 @@ -// Shader taken from: http://webglsamples.googlecode.com/hg/electricflower/electricflower.html - #ifdef GL_ES precision mediump float; #endif @@ -7,50 +5,42 @@ precision mediump float; varying vec4 v_fragmentColor; varying vec2 v_texCoord; -uniform vec4 gaussianCoefficient; -uniform vec2 onePixelSize; +uniform vec2 resolution; +uniform float blurRadius; -void main() { - if(gaussianCoefficient.x > 0.0) { - vec4 sum = vec4(0.0); - vec2 offset; - float weight; - float squareX; - - for(float dx = 0.0; dx <= gaussianCoefficient.x; dx += 1.0) { - squareX = dx * dx; - weight = gaussianCoefficient.z * exp(squareX * gaussianCoefficient.y); - - offset.x = -dx * onePixelSize.x; - offset.y = 0.0; - sum += texture2D(CC_Texture0, v_texCoord + offset) * weight; - - offset.x = dx * onePixelSize.x; - sum += texture2D(CC_Texture0, v_texCoord + offset) * weight; - - for(float dy = 1.0; dy <= gaussianCoefficient.x; dy += 1.0) { - weight = gaussianCoefficient.z * exp((squareX + dy * dy) * gaussianCoefficient.y); - - offset.x = -dx * onePixelSize.x; - offset.y = -dy * onePixelSize.y; - sum += texture2D(CC_Texture0, v_texCoord + offset) * weight; - - offset.y = dy * onePixelSize.y; - sum += texture2D(CC_Texture0, v_texCoord + offset) * weight; - - offset.x = dx * onePixelSize.x; - sum += texture2D(CC_Texture0, v_texCoord + offset) * weight; - - offset.y = -dy * onePixelSize.y; - sum += texture2D(CC_Texture0, v_texCoord + offset) * weight; - } - } - sum -= texture2D(CC_Texture0, v_texCoord) * gaussianCoefficient.z; - sum /= gaussianCoefficient.w; - gl_FragColor = sum * v_fragmentColor; - } - else { - gl_FragColor = texture2D(CC_Texture0, v_texCoord) * v_fragmentColor; - } +vec3 blur(vec2); + +void main(void) +{ + vec3 col = blur(v_texCoord); + gl_FragColor = vec4(col, 1.0); +} + +vec3 blur(vec2 p) +{ + if (blurRadius > 0.0) + { + vec3 col = vec3(0); + vec2 unit = 1.0 / resolution.xy; + + float r = blurRadius; + float sampleStep = r / 7.37; + + float count = 0.0; + + for(float x = -r; x < r; x += sampleStep) + { + for(float y = -r; y < r; y += sampleStep) + { + float weight = (r - abs(x)) * (r - abs(y)); + col += texture2D(CC_Texture0, p + vec2(x * unit.x, y * unit.y)).rgb * weight; + count += weight; + } + } + + return col / count; + } + + return texture2D(CC_Texture0, p).rgb; } From 63a68632a5b97a2d2292cff7a70a809564d3d7c0 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Wed, 11 Jun 2014 21:49:08 +0800 Subject: [PATCH 04/20] fixed calculating height of multi-line string was incorrect on IOS. --- cocos/platform/ios/CCDevice.mm | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/cocos/platform/ios/CCDevice.mm b/cocos/platform/ios/CCDevice.mm index 5eeaf7ccaa..9246327882 100644 --- a/cocos/platform/ios/CCDevice.mm +++ b/cocos/platform/ios/CCDevice.mm @@ -215,26 +215,14 @@ static inline void lazyCheckIOS7() static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize) { - NSArray *listItems = [str componentsSeparatedByString: @"\n"]; - CGSize dim = CGSizeZero; CGSize textRect = CGSizeZero; textRect.width = constrainSize->width > 0 ? constrainSize->width : 0x7fffffff; textRect.height = constrainSize->height > 0 ? constrainSize->height : 0x7fffffff; - for (NSString *s in listItems) - { - CGSize tmp = [s sizeWithFont:font constrainedToSize:textRect]; - - if (tmp.width > dim.width) - { - dim.width = tmp.width; - } - - dim.height += tmp.height; - } - + CGSize dim = [s sizeWithFont:font constrainedToSize:textRect]; + dim.width = ceilf(dim.width); dim.height = ceilf(dim.height); From 7cc38792578df1b49bece114ea73ca8812144d85 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Wed, 11 Jun 2014 22:03:10 +0800 Subject: [PATCH 05/20] Ensuring release cache texture in timely. --- cocos/2d/CCLabel.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 39ef02f014..d01925bbd0 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -392,16 +392,12 @@ void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false * if (_reusedLetter == nullptr) { - _reusedLetter = Sprite::createWithTexture(_fontAtlas->getTexture(0)); + _reusedLetter = Sprite::create(); _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); _reusedLetter->retain(); _reusedLetter->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); - _reusedLetter->setBatchNode(this); - } - else - { - _reusedLetter->setTexture(_fontAtlas->getTexture(0)); } + _reusedLetter->setBatchNode(this); if (_fontAtlas) { From 775832a710e24788e4b1748caf23cd5abc3c006f Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Wed, 11 Jun 2014 13:18:10 -0700 Subject: [PATCH 06/20] added missing files --- cocos/2d/cocos2d_wp8.vcxproj | 2 ++ cocos/2d/cocos2d_wp8.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/cocos/2d/cocos2d_wp8.vcxproj b/cocos/2d/cocos2d_wp8.vcxproj index af64540683..37a477357f 100644 --- a/cocos/2d/cocos2d_wp8.vcxproj +++ b/cocos/2d/cocos2d_wp8.vcxproj @@ -280,6 +280,7 @@ + @@ -476,6 +477,7 @@ + diff --git a/cocos/2d/cocos2d_wp8.vcxproj.filters b/cocos/2d/cocos2d_wp8.vcxproj.filters index e7f75c3fd6..010792145b 100644 --- a/cocos/2d/cocos2d_wp8.vcxproj.filters +++ b/cocos/2d/cocos2d_wp8.vcxproj.filters @@ -593,6 +593,9 @@ renderer + + base + @@ -1205,6 +1208,9 @@ renderer + + base + From b26853638540ed8ad8dd8e4bc156f51cf6547b37 Mon Sep 17 00:00:00 2001 From: LinWenhai Date: Thu, 12 Jun 2014 09:46:18 +0800 Subject: [PATCH 07/20] fixed typo. --- cocos/platform/ios/CCDevice.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/platform/ios/CCDevice.mm b/cocos/platform/ios/CCDevice.mm index 9246327882..fb14b01f71 100644 --- a/cocos/platform/ios/CCDevice.mm +++ b/cocos/platform/ios/CCDevice.mm @@ -221,7 +221,7 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize textRect.height = constrainSize->height > 0 ? constrainSize->height : 0x7fffffff; - CGSize dim = [s sizeWithFont:font constrainedToSize:textRect]; + CGSize dim = [str sizeWithFont:font constrainedToSize:textRect]; dim.width = ceilf(dim.width); dim.height = ceilf(dim.height); From 97b578185d2a7b84c33dffd85384fafa89ef6b37 Mon Sep 17 00:00:00 2001 From: vision Date: Thu, 12 Jun 2014 09:49:48 +0800 Subject: [PATCH 08/20] new parameter for setting blur shader effect --- .../Classes/ShaderTest/ShaderTest.cpp | 69 ++++++++++++++----- .../cpp-tests/Classes/ShaderTest/ShaderTest.h | 9 ++- .../Classes/ShaderTest/ShaderTest2.cpp | 13 +++- .../Resources/Shaders/example_Blur.fsh | 39 ++++++++++- 4 files changed, 104 insertions(+), 26 deletions(-) diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp index 07d764601b..b4150a8383 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp @@ -421,14 +421,16 @@ class SpriteBlur : public Sprite { public: ~SpriteBlur(); - void setBlurRadius(float radius); bool initWithTexture(Texture2D* texture, const Rect& rect); void initGLProgram(); static SpriteBlur* create(const char *pszFileName); + void setBlurRadius(float radius); + void setBlurSampleNum(float num); protected: float _blurRadius; + float _blurSampleNum; }; SpriteBlur::~SpriteBlur() @@ -484,6 +486,7 @@ void SpriteBlur::initGLProgram() auto size = getTexture()->getContentSizeInPixels(); getGLProgramState()->setUniformVec2("resolution", size); getGLProgramState()->setUniformFloat("blurRadius", _blurRadius); + getGLProgramState()->setUniformFloat("sampleNum", 7.0f); } void SpriteBlur::setBlurRadius(float radius) @@ -492,6 +495,12 @@ void SpriteBlur::setBlurRadius(float radius) getGLProgramState()->setUniformFloat("blurRadius", _blurRadius); } +void SpriteBlur::setBlurSampleNum(float num) +{ + _blurSampleNum = num; + getGLProgramState()->setUniformFloat("sampleNum", _blurSampleNum); +} + // ShaderBlur ShaderBlur::ShaderBlur() @@ -509,22 +518,43 @@ std::string ShaderBlur::subtitle() const return "Gaussian blur"; } -ControlSlider* ShaderBlur::createSliderCtl() +void ShaderBlur::createSliderCtls() { auto screenSize = Director::getInstance()->getWinSize(); - ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); - slider->setAnchorPoint(Vec2(0.5f, 1.0f)); - slider->setMinimumValue(0.0f); // Sets the min value of range - slider->setMaximumValue(25.0f); // Sets the max value of range + { + ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); + slider->setAnchorPoint(Vec2(0.5f, 1.0f)); + slider->setMinimumValue(0.0f); + slider->setMaximumValue(25.0f); + slider->setScale(0.6f); + slider->setPosition(Vec2(screenSize.width / 4.0f, screenSize.height / 3.0f)); + slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::onRadiusChanged), Control::EventType::VALUE_CHANGED); + slider->setValue(2.0f); + addChild(slider); + _sliderRadiusCtl = slider; + + auto label = Label::createWithTTF("Blur Radius", "fonts/arial.ttf", 12.0f); + addChild(label); + label->setPosition(Vec2(screenSize.width / 4.0f, screenSize.height / 3.0f - 24.0f)); + } - slider->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 3.0f)); - - // When the value of the slider will change, the given selector will be call - slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::sliderAction), Control::EventType::VALUE_CHANGED); - slider->setValue(2.0f); - - return slider; + { + ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png"); + slider->setAnchorPoint(Vec2(0.5f, 1.0f)); + slider->setMinimumValue(0.0f); + slider->setMaximumValue(11.0f); + slider->setScale(0.6f); + slider->setPosition(Vec2(screenSize.width * 3 / 4.0f, screenSize.height / 3.0f)); + slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::onSampleNumChanged), Control::EventType::VALUE_CHANGED); + slider->setValue(7.0f); + addChild(slider); + _sliderNumCtrl = slider; + + auto label = Label::createWithTTF("Blur Sample Num", "fonts/arial.ttf", 12.0f); + addChild(label); + label->setPosition(Vec2(screenSize.width * 3 / 4.0f, screenSize.height / 3.0f - 24.0f)); + } } @@ -533,9 +563,7 @@ bool ShaderBlur::init() if( ShaderTestDemo::init() ) { _blurSprite = SpriteBlur::create("Images/grossini.png"); - auto sprite = Sprite::create("Images/grossini.png"); - auto s = Director::getInstance()->getWinSize(); _blurSprite->setPosition(Vec2(s.width/3, s.height/2)); sprite->setPosition(Vec2(2*s.width/3, s.height/2)); @@ -543,21 +571,26 @@ bool ShaderBlur::init() addChild(_blurSprite); addChild(sprite); - _sliderCtl = createSliderCtl(); + createSliderCtls(); - addChild(_sliderCtl); return true; } return false; } -void ShaderBlur::sliderAction(Ref* sender, Control::EventType controlEvent) +void ShaderBlur::onRadiusChanged(Ref* sender, Control::EventType) { ControlSlider* slider = (ControlSlider*)sender; _blurSprite->setBlurRadius(slider->getValue()); } +void ShaderBlur::onSampleNumChanged(Ref* sender, Control::EventType) +{ + ControlSlider* slider = (ControlSlider*)sender; + _blurSprite->setBlurSampleNum(slider->getValue()); +} + // ShaderRetroEffect ShaderRetroEffect::ShaderRetroEffect() diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h index 798466dae1..e3788de8bd 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h @@ -92,11 +92,14 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; virtual bool init(); - ControlSlider* createSliderCtl(); - void sliderAction(Ref* sender, Control::EventType controlEvent); + void createSliderCtls(); + void onRadiusChanged(Ref* sender, Control::EventType controlEvent); + void onSampleNumChanged(Ref* sender, Control::EventType controlEvent); + protected: SpriteBlur* _blurSprite; - ControlSlider* _sliderCtl; + ControlSlider* _sliderRadiusCtl; + ControlSlider* _sliderNumCtrl; }; class ShaderRetroEffect : public ShaderTestDemo diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp index f406ae8cd7..5c7fa92f11 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp @@ -251,11 +251,13 @@ public: CREATE_FUNC(EffectBlur); virtual void setTarget(EffectSprite *sprite) override; void setBlurRadius(float radius); + void setBlurSampleNum(float num); protected: - bool init(float blurRadius = 10.0f); + bool init(float blurRadius = 10.0f, float sampleNum = 5.0f); float _blurRadius; + float _blurSampleNum; }; void EffectBlur::setTarget(EffectSprite *sprite) @@ -263,12 +265,14 @@ void EffectBlur::setTarget(EffectSprite *sprite) Size size = sprite->getTexture()->getContentSizeInPixels(); _glprogramstate->setUniformVec2("resolution", size); _glprogramstate->setUniformFloat("blurRadius", _blurRadius); + _glprogramstate->setUniformFloat("sampleNum", _blurSampleNum); } -bool EffectBlur::init(float blurRadius) +bool EffectBlur::init(float blurRadius, float sampleNum) { initGLProgramState("Shaders/example_Blur.fsh"); _blurRadius = blurRadius; + _blurSampleNum = sampleNum; return true; } @@ -278,6 +282,11 @@ void EffectBlur::setBlurRadius(float radius) _blurRadius = radius; } +void EffectBlur::setBlurSampleNum(float num) +{ + _blurSampleNum = num; +} + // Outline class EffectOutline : public Effect { diff --git a/tests/cpp-tests/Resources/Shaders/example_Blur.fsh b/tests/cpp-tests/Resources/Shaders/example_Blur.fsh index c0f94933cd..6082e7f748 100644 --- a/tests/cpp-tests/Resources/Shaders/example_Blur.fsh +++ b/tests/cpp-tests/Resources/Shaders/example_Blur.fsh @@ -7,24 +7,25 @@ varying vec2 v_texCoord; uniform vec2 resolution; uniform float blurRadius; +uniform float sampleNum; vec3 blur(vec2); void main(void) { vec3 col = blur(v_texCoord); - gl_FragColor = vec4(col, 1.0); + gl_FragColor = vec4(col, 1.0) * v_fragmentColor; } vec3 blur(vec2 p) { - if (blurRadius > 0.0) + if (blurRadius > 0.0 && sampleNum > 1.0) { vec3 col = vec3(0); vec2 unit = 1.0 / resolution.xy; float r = blurRadius; - float sampleStep = r / 7.37; + float sampleStep = r / sampleNum; float count = 0.0; @@ -44,3 +45,35 @@ vec3 blur(vec2 p) return texture2D(CC_Texture0, p).rgb; } +//vec3 blur(vec2 p) +//{ +// if (blurRadius > 0.0) +// { +// vec3 col = vec3(0); +// vec2 unit = 1.0 / resolution.xy; +// +// float r = blurRadius; +// float sampleStep = r / 5.4; +// float count = 0.0; +// for (float x = 0.0; x < r; x += sampleStep) +// { +// for (float y = 0.0; y < r; y += sampleStep) +// { +// float weight = (r - x) * (r - y); +// col += texture2D(CC_Texture0, p + vec2(-x * unit.x, y * unit.y)).rgb * weight; +// col += texture2D(CC_Texture0, p + vec2(x * unit.x, -y * unit.y)).rgb * weight; +// col += texture2D(CC_Texture0, p + vec2(x * unit.x, y * unit.y)).rgb * weight; +// col += texture2D(CC_Texture0, p + vec2(-x * unit.x, -y * unit.y)).rgb * weight; +// count += 4.0 * weight; +// } +// } +// +// float centerWeight = 3.0 * r * r; +// count -= centerWeight; +// col -= texture2D(CC_Texture0, p).rgb * centerWeight; +// +// return col / count; +// } +// +// return texture2D(CC_Texture0, p).rgb; +//} From dc4cdc9c0fd8a8277aa95b86eb0af888bb323456 Mon Sep 17 00:00:00 2001 From: vision Date: Thu, 12 Jun 2014 10:19:08 +0800 Subject: [PATCH 09/20] remove the comments --- .../Resources/Shaders/example_Blur.fsh | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/cpp-tests/Resources/Shaders/example_Blur.fsh b/tests/cpp-tests/Resources/Shaders/example_Blur.fsh index 6082e7f748..74eefdf0fe 100644 --- a/tests/cpp-tests/Resources/Shaders/example_Blur.fsh +++ b/tests/cpp-tests/Resources/Shaders/example_Blur.fsh @@ -44,36 +44,3 @@ vec3 blur(vec2 p) return texture2D(CC_Texture0, p).rgb; } - -//vec3 blur(vec2 p) -//{ -// if (blurRadius > 0.0) -// { -// vec3 col = vec3(0); -// vec2 unit = 1.0 / resolution.xy; -// -// float r = blurRadius; -// float sampleStep = r / 5.4; -// float count = 0.0; -// for (float x = 0.0; x < r; x += sampleStep) -// { -// for (float y = 0.0; y < r; y += sampleStep) -// { -// float weight = (r - x) * (r - y); -// col += texture2D(CC_Texture0, p + vec2(-x * unit.x, y * unit.y)).rgb * weight; -// col += texture2D(CC_Texture0, p + vec2(x * unit.x, -y * unit.y)).rgb * weight; -// col += texture2D(CC_Texture0, p + vec2(x * unit.x, y * unit.y)).rgb * weight; -// col += texture2D(CC_Texture0, p + vec2(-x * unit.x, -y * unit.y)).rgb * weight; -// count += 4.0 * weight; -// } -// } -// -// float centerWeight = 3.0 * r * r; -// count -= centerWeight; -// col -= texture2D(CC_Texture0, p).rgb * centerWeight; -// -// return col / count; -// } -// -// return texture2D(CC_Texture0, p).rgb; -//} From d755b7ffcb7b29ee0e2d31479ca1e85571b9e967 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 12 Jun 2014 11:21:42 +0800 Subject: [PATCH 10/20] issue #3341:fix TextureCache::addImageAsync repeatedly generate Image for the same image file. --- cocos/renderer/CCTextureCache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/renderer/CCTextureCache.cpp b/cocos/renderer/CCTextureCache.cpp index 16643adeb9..d7db2feaa8 100644 --- a/cocos/renderer/CCTextureCache.cpp +++ b/cocos/renderer/CCTextureCache.cpp @@ -206,11 +206,11 @@ void TextureCache::loadImage() for (; pos < infoSize; pos++) { imageInfo = (*_imageInfoQueue)[pos]; - if(imageInfo->asyncStruct->filename.compare(asyncStruct->filename)) + if(imageInfo->asyncStruct->filename.compare(asyncStruct->filename) == 0) break; } _imageInfoMutex.unlock(); - if(infoSize == 0 || pos < infoSize) + if(infoSize == 0 || pos == infoSize) generateImage = true; } From 87ac4c660dddc5ee35542b4ee0bf22c757203dd0 Mon Sep 17 00:00:00 2001 From: heliclei Date: Thu, 12 Jun 2014 11:30:37 +0800 Subject: [PATCH 11/20] [ci skip] Set github commit status context & description --- tools/jenkins-scripts/job-comment-trigger.py | 2 +- tools/jenkins-scripts/job-trigger.py | 2 +- tools/jenkins-scripts/post-build.py | 5 +++-- tools/jenkins-scripts/pull-request-builder.py | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/jenkins-scripts/job-comment-trigger.py b/tools/jenkins-scripts/job-comment-trigger.py index 8ba9d710af..b425040948 100644 --- a/tools/jenkins-scripts/job-comment-trigger.py +++ b/tools/jenkins-scripts/job-comment-trigger.py @@ -79,7 +79,7 @@ def main(): print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered' return(0) - data = {"state":"pending", "target_url":target_url} + data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Wait available build machine..."} access_token = os.environ['GITHUB_ACCESS_TOKEN'] Headers = {"Authorization":"token " + access_token} diff --git a/tools/jenkins-scripts/job-trigger.py b/tools/jenkins-scripts/job-trigger.py index 54e566e94c..fbdcf0c3e1 100755 --- a/tools/jenkins-scripts/job-trigger.py +++ b/tools/jenkins-scripts/job-trigger.py @@ -90,7 +90,7 @@ def main(): print 'skip build for pull request #' + str(pr_num) return(0) - data = {"state":"pending", "target_url":target_url} + data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Waiting available build machine..."} access_token = os.environ['GITHUB_ACCESS_TOKEN'] Headers = {"Authorization":"token " + access_token} diff --git a/tools/jenkins-scripts/post-build.py b/tools/jenkins-scripts/post-build.py index 78f7ddf735..fb99727de8 100644 --- a/tools/jenkins-scripts/post-build.py +++ b/tools/jenkins-scripts/post-build.py @@ -18,7 +18,7 @@ statuses_url = payload['statuses_url'] J = Jenkins(os.environ['JENKINS_URL']) target_url = os.environ['BUILD_URL'] build_number = int(os.environ['BUILD_NUMBER']) -data = {"state":"pending", "target_url":target_url} +data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Build finished!"} access_token = os.environ['GITHUB_ACCESS_TOKEN'] Headers = {"Authorization":"token " + access_token} @@ -26,9 +26,10 @@ result = J[os.environ['JOB_NAME']].get_build(build_number).get_status() if(result == STATUS_SUCCESS): data['state'] = "success" + data['description'] = "Build successfully!" else: data['state'] = "failure" - + data['description'] = "Build failed!" http_proxy = '' if(os.environ.has_key('HTTP_PROXY')): http_proxy = os.environ['HTTP_PROXY'] diff --git a/tools/jenkins-scripts/pull-request-builder.py b/tools/jenkins-scripts/pull-request-builder.py index d506bb0df5..eb36154c49 100755 --- a/tools/jenkins-scripts/pull-request-builder.py +++ b/tools/jenkins-scripts/pull-request-builder.py @@ -104,7 +104,7 @@ def main(): set_description(pr_desc, target_url) - data = {"state":"pending", "target_url":target_url} + data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Build started..."} access_token = os.environ['GITHUB_ACCESS_TOKEN'] Headers = {"Authorization":"token " + access_token} From 70147e9a20b18222dcae4829bbc7bd6365ecd49d Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 11:38:28 +0800 Subject: [PATCH 12/20] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 9b745809d9..c17a53bf37 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,6 +27,7 @@ cocos2d-x-3.2 ??? [FIX] Schedule: schedulePerFrame() can not be called twice [FIX] SpriteFrameCache: fix memory leak [FIX] Texture2D: use image's pixel format to create texture + [FIX] TextureCache: addImageAsync() may repeatedly generate Image for the same image file [FIX] WP8: will restart if app goes to background, then touches icon to go to foreground [FIX] WP8: will be black if: 1. 3rd pops up a view; 2. go to background; 3. come to foreground [FIX] WP8: project name of new project created by console is wrong From cc683ff00f60afaf1f75708981bc2dfb3f10e10e Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 11:40:41 +0800 Subject: [PATCH 13/20] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index c17a53bf37..f9a3fc15cb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,7 @@ cocos2d-x-3.2 ??? [FIX] Image: premultiply alpha when loading png file to resolve black border issue [FIX] Label: label is unsharp if it's created by smaller font [FIX] Label: Label's display may go bonkers if invoking Label::setString() with outline feature enabled + [FIX] Label: don't release cached texture in time [FIX] Lua-binding: compiling error on release mode [FIX] Lua-binding: Add xxtea encrypt support [FIX] Node: setPhysicsBody() can not work correctly if it is added to a Node From 22f445d56f86ff925c71a6f5291e602792422950 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 14:47:42 +0800 Subject: [PATCH 14/20] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index f9a3fc15cb..223dd5bb51 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ cocos2d-x-3.2 ??? [FIX] Label: label is unsharp if it's created by smaller font [FIX] Label: Label's display may go bonkers if invoking Label::setString() with outline feature enabled [FIX] Label: don't release cached texture in time + [FIX] Label: calculated height of multi-line string was incorrect on iOS [FIX] Lua-binding: compiling error on release mode [FIX] Lua-binding: Add xxtea encrypt support [FIX] Node: setPhysicsBody() can not work correctly if it is added to a Node From 77fdd124a1497a9801ff6168a084e9dcde23d6fa Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 15:05:31 +0800 Subject: [PATCH 15/20] [ci skip] --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 6beee8bf55..90e96f068e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -841,6 +841,7 @@ Developers: sachingarg05 Re-added orientation change callback in java activity + GLProgram should not abort() if shader compilation fails, returning false is better. dplusic Fixed that cc.pGetAngle may return wrong value From bb5471ca8b8ce625fc68da26065ca3ff60c5b6ee Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 15:07:29 +0800 Subject: [PATCH 16/20] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 223dd5bb51..166f24f723 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ cocos2d-x-3.2 ??? [FIX] Android: 3d model will be black when coming from background [FIX] Android: don't trigger EVENT_COME_TO_BACKGROUND event when go to background [FIX] Cocos2dxGLSurfaceView.java: prevent flickering when opening another activity + [FIX] GLProgram: not abort if shader compilation fails, just retuan false. [FIX] GLProgramState: sampler can not be changed [FIX] Image: Set jpeg save quality to 90 [FIX] Image: premultiply alpha when loading png file to resolve black border issue From f6913fc9314773a701bb066b440fa0969dd39578 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 16:12:03 +0800 Subject: [PATCH 17/20] [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 90e96f068e..4ac6ffa9c4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -882,6 +882,9 @@ Developers: zhouxiaoxiaoxujian Added TextField::getStringLength() Add shadow, outline, glow filter support for UIText + + QiuleiWang + Fix the bug that calculated height of multi-line string was incorrect on iOS Retired Core Developers: WenSheng Yang From d1ca81634aa111644ca2ce838bf1c0a5271a32d3 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 16:18:22 +0800 Subject: [PATCH 18/20] [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 4ac6ffa9c4..52009d3146 100644 --- a/AUTHORS +++ b/AUTHORS @@ -885,6 +885,9 @@ Developers: QiuleiWang Fix the bug that calculated height of multi-line string was incorrect on iOS + + Rumist + Fix the bug that the result of Director->convertToUI() is error. Retired Core Developers: WenSheng Yang From 1187cfff6d5bd26316327ccefe168474ced89c07 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 16:19:05 +0800 Subject: [PATCH 19/20] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 166f24f723..b42ad6f8ac 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ cocos2d-x-3.2 ??? [FIX] Android: 3d model will be black when coming from background [FIX] Android: don't trigger EVENT_COME_TO_BACKGROUND event when go to background [FIX] Cocos2dxGLSurfaceView.java: prevent flickering when opening another activity + [FIX] Director: Director->convertToUI() returns wrong value. [FIX] GLProgram: not abort if shader compilation fails, just retuan false. [FIX] GLProgramState: sampler can not be changed [FIX] Image: Set jpeg save quality to 90 From 1b24af95f18a585b6cd1b5d7ca19b834718e3c36 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 12 Jun 2014 18:23:31 +0800 Subject: [PATCH 20/20] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index b42ad6f8ac..4d58d944e0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -29,6 +29,7 @@ cocos2d-x-3.2 ??? [FIX] Repeat: will run one more over in rare situations [FIX] Scale9Sprite: support culling [FIX] Schedule: schedulePerFrame() can not be called twice + [FIX] ShaderTest: 7 times performance improved of blur effect [FIX] SpriteFrameCache: fix memory leak [FIX] Texture2D: use image's pixel format to create texture [FIX] TextureCache: addImageAsync() may repeatedly generate Image for the same image file