This commit is contained in:
lvlong 2014-06-16 19:30:45 +08:00
commit 32cc5b12d6
30 changed files with 1340 additions and 1333 deletions

View File

@ -841,6 +841,7 @@ Developers:
sachingarg05 sachingarg05
Re-added orientation change callback in java activity Re-added orientation change callback in java activity
GLProgram should not abort() if shader compilation fails, returning false is better.
dplusic dplusic
Fixed that cc.pGetAngle may return wrong value Fixed that cc.pGetAngle may return wrong value
@ -881,6 +882,12 @@ Developers:
zhouxiaoxiaoxujian zhouxiaoxiaoxujian
Added TextField::getStringLength() Added TextField::getStringLength()
Add shadow, outline, glow filter support for UIText Add shadow, outline, glow filter support for UIText
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: Retired Core Developers:
WenSheng Yang WenSheng Yang

View File

@ -11,11 +11,15 @@ cocos2d-x-3.2 ???
[FIX] Android: 3d model will be black when coming from background [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] Android: don't trigger EVENT_COME_TO_BACKGROUND event when go to background
[FIX] Cocos2dxGLSurfaceView.java: prevent flickering when opening another activity [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] GLProgramState: sampler can not be changed
[FIX] Image: Set jpeg save quality to 90 [FIX] Image: Set jpeg save quality to 90
[FIX] Image: premultiply alpha when loading png file to resolve black border issue [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 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: 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: compiling error on release mode
[FIX] Lua-binding: Add xxtea encrypt support [FIX] Lua-binding: Add xxtea encrypt support
[FIX] Node: setPhysicsBody() can not work correctly if it is added to a Node [FIX] Node: setPhysicsBody() can not work correctly if it is added to a Node
@ -25,8 +29,10 @@ cocos2d-x-3.2 ???
[FIX] Repeat: will run one more over in rare situations [FIX] Repeat: will run one more over in rare situations
[FIX] Scale9Sprite: support culling [FIX] Scale9Sprite: support culling
[FIX] Schedule: schedulePerFrame() can not be called twice [FIX] Schedule: schedulePerFrame() can not be called twice
[FIX] ShaderTest: 7 times performance improved of blur effect
[FIX] SpriteFrameCache: fix memory leak [FIX] SpriteFrameCache: fix memory leak
[FIX] Texture2D: use image's pixel format to create texture [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 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: 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 [FIX] WP8: project name of new project created by console is wrong

View File

@ -528,6 +528,8 @@ void RepeatForever::step(float dt)
if (_innerAction->isDone()) if (_innerAction->isDone())
{ {
float diff = _innerAction->getElapsed() - _innerAction->getDuration(); float diff = _innerAction->getElapsed() - _innerAction->getDuration();
if (diff > _innerAction->getDuration())
diff = fmodf(diff, _innerAction->getDuration());
_innerAction->startWithTarget(_target); _innerAction->startWithTarget(_target);
// to prevent jerk. issue #390, 1247 // to prevent jerk. issue #390, 1247
_innerAction->step(0.0f); _innerAction->step(0.0f);

View File

@ -392,16 +392,12 @@ void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false *
if (_reusedLetter == nullptr) if (_reusedLetter == nullptr)
{ {
_reusedLetter = Sprite::createWithTexture(_fontAtlas->getTexture(0)); _reusedLetter = Sprite::create();
_reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB);
_reusedLetter->retain(); _reusedLetter->retain();
_reusedLetter->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); _reusedLetter->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
_reusedLetter->setBatchNode(this);
}
else
{
_reusedLetter->setTexture(_fontAtlas->getTexture(0));
} }
_reusedLetter->setBatchNode(this);
if (_fontAtlas) if (_fontAtlas)
{ {

View File

@ -280,6 +280,7 @@
<ClCompile Include="..\base\ccUtils.cpp" /> <ClCompile Include="..\base\ccUtils.cpp" />
<ClCompile Include="..\base\CCValue.cpp" /> <ClCompile Include="..\base\CCValue.cpp" />
<ClCompile Include="..\base\etc1.cpp" /> <ClCompile Include="..\base\etc1.cpp" />
<ClCompile Include="..\base\ObjectFactory.cpp" />
<ClCompile Include="..\base\s3tc.cpp" /> <ClCompile Include="..\base\s3tc.cpp" />
<ClCompile Include="..\base\TGAlib.cpp" /> <ClCompile Include="..\base\TGAlib.cpp" />
<ClCompile Include="..\base\ZipUtils.cpp" /> <ClCompile Include="..\base\ZipUtils.cpp" />
@ -476,6 +477,7 @@
<ClInclude Include="..\base\CCVector.h" /> <ClInclude Include="..\base\CCVector.h" />
<ClInclude Include="..\base\etc1.h" /> <ClInclude Include="..\base\etc1.h" />
<ClInclude Include="..\base\firePngData.h" /> <ClInclude Include="..\base\firePngData.h" />
<ClInclude Include="..\base\ObjectFactory.h" />
<ClInclude Include="..\base\s3tc.h" /> <ClInclude Include="..\base\s3tc.h" />
<ClInclude Include="..\base\TGAlib.h" /> <ClInclude Include="..\base\TGAlib.h" />
<ClInclude Include="..\base\uthash.h" /> <ClInclude Include="..\base\uthash.h" />

View File

@ -593,6 +593,9 @@
<Filter>renderer</Filter> <Filter>renderer</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\platform\wp8\pch.cpp" /> <ClCompile Include="..\platform\wp8\pch.cpp" />
<ClCompile Include="..\base\ObjectFactory.cpp">
<Filter>base</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\physics\CCPhysicsBody.h"> <ClInclude Include="..\physics\CCPhysicsBody.h">
@ -1205,6 +1208,9 @@
<Filter>renderer</Filter> <Filter>renderer</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\platform\wp8\pch.h" /> <ClInclude Include="..\platform\wp8\pch.h" />
<ClInclude Include="..\base\ObjectFactory.h">
<Filter>base</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\math\Mat4.inl"> <None Include="..\math\Mat4.inl">

View File

@ -101,7 +101,8 @@ void Animate3D::update(float t)
{ {
if (_target) if (_target)
{ {
float dst[4]; float transDst[3], rotDst[4], scaleDst[3];
float* trans = nullptr, *rot = nullptr, *scale = nullptr;
if (_playBack) if (_playBack)
t = 1 - t; t = 1 - t;
@ -110,19 +111,20 @@ void Animate3D::update(float t)
auto curve = it.second; auto curve = it.second;
if (curve->translateCurve) if (curve->translateCurve)
{ {
curve->translateCurve->evaluate(t, dst, Linear); curve->translateCurve->evaluate(t, transDst, Linear);
bone->setAnimationValueTranslation(dst); trans = &transDst[0];
} }
if (curve->rotCurve) if (curve->rotCurve)
{ {
curve->rotCurve->evaluate(t, dst, QuatSlerp); curve->rotCurve->evaluate(t, rotDst, QuatSlerp);
bone->setAnimationValueRotation(dst); rot = &rotDst[0];
} }
if (curve->scaleCurve) if (curve->scaleCurve)
{ {
curve->scaleCurve->evaluate(t, dst, Linear); curve->scaleCurve->evaluate(t, scaleDst, Linear);
bone->setAnimationValueScale(dst); scale = &scaleDst[0];
} }
bone->setAnimationValue(trans, rot, scale, _weight);
} }
} }
@ -130,6 +132,7 @@ void Animate3D::update(float t)
Animate3D::Animate3D() Animate3D::Animate3D()
: _speed(1) : _speed(1)
, _weight(1.f)
, _animation(nullptr) , _animation(nullptr)
, _playBack(false) , _playBack(false)
{ {

View File

@ -70,6 +70,7 @@ protected:
Animation3D* _animation; Animation3D* _animation;
float _speed; float _speed;
float _weight;
bool _playBack; bool _playBack;
std::map<Bone*, Animation3D::Curve*> _boneCurves; //weak ref std::map<Bone*, Animation3D::Curve*> _boneCurves; //weak ref
}; };

View File

@ -12,7 +12,7 @@ void AnimationCurve<componentSize>::evaluate(float time, float* dst, EvaluateTyp
} }
else if (time >= _keytime[_count - 1]) else if (time >= _keytime[_count - 1])
{ {
memcpy(dst, &_value[(_count - 1) * floatSize], _componentSizeByte); memcpy(dst, &_value[(_count - 1) * componentSize], _componentSizeByte);
return; return;
} }

View File

@ -99,19 +99,29 @@ void Bundle3D::purgeBundle3D()
bool Bundle3D::load(const std::string& path) bool Bundle3D::load(const std::string& path)
{ {
std::string fullpath = FileUtils::getInstance()->getStringFromFile(path);
getModelPath(path); getModelPath(path);
ssize_t size = fullpath.length(); std::string strFileString = FileUtils::getInstance()->getStringFromFile(path);
ssize_t size = strFileString.length();
CC_SAFE_DELETE_ARRAY(_documentBuffer); CC_SAFE_DELETE_ARRAY(_documentBuffer);
_documentBuffer = new char[size + 1]; _documentBuffer = new char[size + 1];
memcpy(_documentBuffer, fullpath.c_str(), size); memcpy(_documentBuffer, strFileString.c_str(), size);
_documentBuffer[size] = '\0'; _documentBuffer[size] = '\0';
if (_document.ParseInsitu<0>(_documentBuffer).HasParseError()) if (_document.ParseInsitu<0>(_documentBuffer).HasParseError())
{ {
assert(0); ssize_t size = strFileString.length();
return false;
CC_SAFE_DELETE_ARRAY(_documentBuffer);
_documentBuffer = new char[size + 1];
memcpy(_documentBuffer, strFileString.c_str(), size);
_documentBuffer[size] = '\0';
if (_document.ParseInsitu<0>(_documentBuffer).HasParseError())
{
assert(0);
return false;
}
_fullPath = strFileString;
} }
return true; return true;
@ -142,7 +152,7 @@ bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
meshdata->vertexSizeInFloat = mesh_data_body_array_0["vertexsize"].GetInt(); meshdata->vertexSizeInFloat = mesh_data_body_array_0["vertexsize"].GetInt();
// vertices // vertices
meshdata->vertex = new float[meshdata->vertexSizeInFloat]; meshdata->vertex.resize(meshdata->vertexSizeInFloat);
const rapidjson::Value& mesh_data_body_vertices = mesh_data_body_array_0["vertices"]; const rapidjson::Value& mesh_data_body_vertices = mesh_data_body_array_0["vertices"];
for (rapidjson::SizeType i = 0; i < mesh_data_body_vertices.Size(); i++) for (rapidjson::SizeType i = 0; i < mesh_data_body_vertices.Size(); i++)
meshdata->vertex[i] = mesh_data_body_vertices[i].GetDouble(); meshdata->vertex[i] = mesh_data_body_vertices[i].GetDouble();
@ -151,7 +161,7 @@ bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
meshdata->numIndex = mesh_data_body_array_0["indexnum"].GetUint(); meshdata->numIndex = mesh_data_body_array_0["indexnum"].GetUint();
// indices // indices
meshdata->indices = new unsigned short[meshdata->numIndex]; meshdata->indices.resize(meshdata->numIndex);
const rapidjson::Value& mesh_data_body_indices_val = mesh_data_body_array_0["indices"]; const rapidjson::Value& mesh_data_body_indices_val = mesh_data_body_array_0["indices"];
for (rapidjson::SizeType i = 0; i < mesh_data_body_indices_val.Size(); i++) for (rapidjson::SizeType i = 0; i < mesh_data_body_indices_val.Size(); i++)
meshdata->indices[i] = (unsigned short)mesh_data_body_indices_val[i].GetUint(); meshdata->indices[i] = (unsigned short)mesh_data_body_indices_val[i].GetUint();
@ -159,7 +169,7 @@ bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
// mesh_vertex_attribute // mesh_vertex_attribute
const rapidjson::Value& mesh_vertex_attribute = mash_data_val["attributes"]; const rapidjson::Value& mesh_vertex_attribute = mash_data_val["attributes"];
meshdata->attribCount = mesh_vertex_attribute.Size(); meshdata->attribCount = mesh_vertex_attribute.Size();
meshdata->attribs = new MeshVertexAttrib[meshdata->attribCount]; meshdata->attribs.resize(meshdata->attribCount);
for (rapidjson::SizeType i = 0; i < mesh_vertex_attribute.Size(); i++) for (rapidjson::SizeType i = 0; i < mesh_vertex_attribute.Size(); i++)
{ {
const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i]; const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i];

View File

@ -95,6 +95,7 @@ protected:
std::string _modelRelativePath; std::string _modelRelativePath;
char* _documentBuffer; char* _documentBuffer;
std::string _fullPath;
rapidjson::Document _document; rapidjson::Document _document;

View File

@ -49,29 +49,26 @@ struct MeshVertexAttrib
struct MeshData struct MeshData
{ {
float* vertex; std::vector<float> vertex;
int vertexSizeInFloat; int vertexSizeInFloat;
unsigned short* indices; std::vector<unsigned short> indices;
int numIndex; int numIndex;
MeshVertexAttrib* attribs; std::vector<MeshVertexAttrib> attribs;
int attribCount; int attribCount;
public: public:
void resetData() void resetData()
{ {
CC_SAFE_DELETE_ARRAY(vertex); vertex.clear();
CC_SAFE_DELETE_ARRAY(indices); indices.clear();
CC_SAFE_DELETE_ARRAY(attribs); attribs.clear();
vertexSizeInFloat = 0; vertexSizeInFloat = 0;
numIndex = 0; numIndex = 0;
attribCount = 0; attribCount = 0;
} }
MeshData() MeshData()
: vertex(nullptr) : vertexSizeInFloat(0)
, vertexSizeInFloat(0)
, indices(nullptr)
, numIndex(0) , numIndex(0)
, attribs(nullptr)
, attribCount(0) , attribCount(0)
{ {
} }
@ -120,6 +117,7 @@ struct MaterialData
struct Animation3DData struct Animation3DData
{ {
public:
struct Vec3Key struct Vec3Key
{ {
Vec3Key() Vec3Key()
@ -155,13 +153,15 @@ struct Animation3DData
float _time; float _time;
Quaternion _key; Quaternion _key;
}; };
public:
std::map<std::string, std::vector<Vec3Key>> _translationKeys; std::map<std::string, std::vector<Vec3Key>> _translationKeys;
std::map<std::string, std::vector<QuatKey>> _rotationKeys; std::map<std::string, std::vector<QuatKey>> _rotationKeys;
std::map<std::string, std::vector<Vec3Key>> _scaleKeys; std::map<std::string, std::vector<Vec3Key>> _scaleKeys;
float _totalTime; float _totalTime;
public:
Animation3DData() Animation3DData()
:_totalTime(0) :_totalTime(0)
{ {

View File

@ -118,15 +118,14 @@ bool RenderMeshData::initFrom(const std::vector<float>& positions,
return true; return true;
} }
bool RenderMeshData::initFrom(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount) bool RenderMeshData::initFrom(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount)
{ {
_vertexs.assign(vertex, vertex + vertexSizeInFloat); _vertexs = vertices;
_indices.assign(indices, indices + numIndex); _indices = indices;
_vertexAttribs.assign(attribs, attribs + attribCount); _vertexAttribs = attribs;
_vertexsizeBytes = calVertexSizeBytes(); _vertexsizeBytes = calVertexSizeBytes();
return true; return true;
} }
@ -168,10 +167,10 @@ Mesh* Mesh::create(const std::vector<float>& positions, const std::vector<float>
return nullptr; return nullptr;
} }
Mesh* Mesh::create(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount) Mesh* Mesh::create(const std::vector<float> &vertices, int vertexSizeInFloat, const std::vector<unsigned short> &indices, int numIndex, const std::vector<MeshVertexAttrib> &attribs, int attribCount)
{ {
auto mesh = new Mesh(); auto mesh = new Mesh();
if (mesh && mesh->init(vertex, vertexSizeInFloat, indices, numIndex, attribs, attribCount)) if (mesh && mesh->init(vertices, vertexSizeInFloat, indices, numIndex, attribs, attribCount))
{ {
mesh->autorelease(); mesh->autorelease();
return mesh; return mesh;
@ -190,9 +189,9 @@ bool Mesh::init(const std::vector<float>& positions, const std::vector<float>& n
return true; return true;
} }
bool Mesh::init(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount) bool Mesh::init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount)
{ {
bool bRet = _renderdata.initFrom(vertex, vertexSizeInFloat, indices, numIndex, attribs, attribCount); bool bRet = _renderdata.initFrom(vertices, vertexSizeInFloat, indices, numIndex, attribs, attribCount);
if (!bRet) if (!bRet)
return false; return false;

View File

@ -46,7 +46,7 @@ public:
} }
bool hasVertexAttrib(int attrib); bool hasVertexAttrib(int attrib);
bool initFrom(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices); bool initFrom(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
bool initFrom(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount); bool initFrom(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
protected: protected:
@ -83,7 +83,7 @@ public:
//create //create
static Mesh* create(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices); static Mesh* create(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
static Mesh* create(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount); static Mesh* create(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
//get vertex buffer //get vertex buffer
inline GLuint getVertexBuffer() const { return _vertexBuffer; } inline GLuint getVertexBuffer() const { return _vertexBuffer; }
@ -110,7 +110,7 @@ protected:
virtual ~Mesh(); virtual ~Mesh();
bool init(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices); bool init(const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<float>& texs, const std::vector<unsigned short>& indices);
bool init(const float* vertex, int vertexSizeInFloat, unsigned short* indices, int numIndex, const MeshVertexAttrib* attribs, int attribCount); bool init(const std::vector<float>& vertices, int vertexSizeInFloat, const std::vector<unsigned short>& indices, int numIndex, const std::vector<MeshVertexAttrib>& attribs, int attribCount);
//build buffer //build buffer
void buildBuffer(); void buildBuffer();

View File

@ -46,17 +46,12 @@ const Mat4& Bone::getInverseBindPose()
return _bindPose; return _bindPose;
} }
bool Bone::needUpdateWorldMat() const void Bone::setWorldMatDirty(bool dirty)
{ {
bool needupdate = _worldDirty; _worldDirty = dirty;
auto bone = _parent; for (auto it : _children) {
while (!needupdate && bone) { it->setWorldMatDirty(dirty);
needupdate = bone->_worldDirty;
bone = bone->_parent;
} }
return true;
//return needupdate;
} }
//update own world matrix and children's //update own world matrix and children's
@ -70,7 +65,7 @@ void Bone::updateWorldMat()
const Mat4& Bone::getWorldMat() const Mat4& Bone::getWorldMat()
{ {
if (needUpdateWorldMat()) if (_worldDirty)
{ {
updateLocalMat(); updateLocalMat();
if (_parent) if (_parent)
@ -79,39 +74,34 @@ const Mat4& Bone::getWorldMat()
} }
else else
_world = _local; _world = _local;
_worldDirty = false;
} }
return _world; return _world;
} }
/** void Bone::setAnimationValue(float* trans, float* rot, float* scale, float weight)
* Set AnimationValue. set to its transform
*/
void Bone::setAnimationValueTranslation(float* value)
{ {
static const int bytes = 3 * sizeof(float); BoneBlendState state;
if (memcmp(&_localTranslate.x, value, bytes) != 0) if (trans)
{ state.localTranslate.set(trans);
_dirtyFlag |= Dirty_Translate; if (rot)
_localTranslate.set(value); state.localRot.set(rot);
} if (scale)
state.localScale.set(scale);
state.weight = weight;
_blendStates.push_back(state);
_localDirty = true;
} }
void Bone::setAnimationValueRotation(float* value)
void Bone::clearBoneBlendState()
{ {
static const int bytes = 4 * sizeof(float); _blendStates.clear();
if (memcmp(&_localRot.x, value, bytes) != 0) for (auto it : _children) {
{ it->clearBoneBlendState();
_dirtyFlag |= Dirty_Rotation;
_localRot.set(value);
}
}
void Bone::setAnimationValueScale(float* value)
{
static const int bytes = 3 * sizeof(float);
if (memcmp(&_localScale.x, value, bytes) != 0)
{
_dirtyFlag |= Dirty_Scale;
_localScale.set(value);
} }
} }
@ -135,16 +125,10 @@ Bone* Bone::create(const std::string& id)
*/ */
void Bone::updateJointMatrix(const Mat4& bindShape, Vec4* matrixPalette) void Bone::updateJointMatrix(const Mat4& bindShape, Vec4* matrixPalette)
{ {
//if (_skinCount > 1 || _jointMatrixDirty)
{ {
//_jointMatrixDirty = false;
static Mat4 t; static Mat4 t;
Mat4::multiply(_world, getInverseBindPose(), &t); Mat4::multiply(_world, getInverseBindPose(), &t);
//Mat4::multiply(t, bindShape, &t);
//Mat4::multiply(getInverseBindPose(), _world, &t);
//t.setIdentity();
matrixPalette[0].set(t.m[0], t.m[4], t.m[8], t.m[12]); matrixPalette[0].set(t.m[0], t.m[4], t.m[8], t.m[12]);
matrixPalette[1].set(t.m[1], t.m[5], t.m[9], t.m[13]); matrixPalette[1].set(t.m[1], t.m[5], t.m[9], t.m[13]);
matrixPalette[2].set(t.m[2], t.m[6], t.m[10], t.m[14]); matrixPalette[2].set(t.m[2], t.m[6], t.m[10], t.m[14]);
@ -185,11 +169,8 @@ void Bone::removeAllChildBone()
Bone::Bone(const std::string& id) Bone::Bone(const std::string& id)
: _name(id) : _name(id)
, _parent(nullptr) , _parent(nullptr)
, _dirtyFlag(0) , _localDirty(true)
, _worldDirty(true) , _worldDirty(true)
, _localTranslate(Vec3::ZERO)
, _localScale(Vec3::ONE)
, _localRot(Quaternion::identity())
{ {
} }
@ -204,22 +185,63 @@ Bone::~Bone()
void Bone::updateLocalMat() void Bone::updateLocalMat()
{ {
// Mat4::createTranslation(_localTranslate, &_local); if (_blendStates.size())
// if (!_localRot.isZero()) {
// _local.rotate(_localRot); Vec3 translate(Vec3::ZERO), scale(Vec3::ONE);
// return; Quaternion quat(Quaternion::identity());
if(0 == _dirtyFlag) return;
float total = 0.f;
for (auto it: _blendStates) {
total += it.weight;
}
if (total)
{
//if (_blendStates.size() == 1)
if (true)
{
int cnt = _blendStates.size();
translate = _blendStates[cnt - 1].localTranslate;
scale = _blendStates[cnt - 1].localScale;
quat = _blendStates[cnt - 1].localRot;
}
else
{
float invTotal = 1.f / total;
for (auto it : _blendStates) {
float weight = (it.weight * invTotal);
translate += it.localTranslate * weight;
if (!it.localScale.isZero())
{
scale.x *= it.localScale.x * weight;
scale.y *= it.localScale.y * weight;
scale.z *= it.localScale.z * weight;
}
if (!it.localRot.isZero())
{
if (!quat.isZero())
{
Quaternion& q = _blendStates[0].localRot;
if (q.x * quat.x + q.y * quat.y + q.z * quat.z + q.w * quat.w < 0)
weight = -weight;
}
quat = Quaternion(it.localRot.x * weight + quat.x, it.localRot.y * weight + quat.y, it.localRot.z * weight + quat.z, it.localRot.w * weight + quat.w);
}
}
}
}
Mat4::createTranslation(translate, &_local);
_local.rotate(quat);
_local.scale(scale);
_blendStates.clear();
_localDirty = false;
}
else
{
CCLOG("use cached local");
}
Mat4 tmp;
Mat4::createScale(_localScale, &_local);
Mat4::createRotation(_localRot, &tmp);
_local = tmp * _local;
Mat4::createTranslation(_localTranslate, &tmp);
_local = tmp * _local;
return;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -266,7 +288,7 @@ MeshSkin* MeshSkin::create(const std::string& filename, const std::string& name)
{ {
auto skin = new MeshSkin(); auto skin = new MeshSkin();
skin->_bindShape = skindata.bindShape; skin->_bindShape = skindata.bindShape;
skin->setBoneCount(skindata.boneNames.size()); skin->setBoneCount((int)skindata.boneNames.size());
for (size_t i = 0; i < skindata.boneNames.size(); i++) { for (size_t i = 0; i < skindata.boneNames.size(); i++) {
auto bone = Bone::create(skindata.boneNames[i]); auto bone = Bone::create(skindata.boneNames[i]);
bone->_bindPose = skindata.inverseBindPoseMatrices[i]; bone->_bindPose = skindata.inverseBindPoseMatrices[i];
@ -391,6 +413,7 @@ unsigned int MeshSkin::getMatrixPaletteSize() const
//refresh bone world matrix //refresh bone world matrix
void MeshSkin::updateBoneMatrix() void MeshSkin::updateBoneMatrix()
{ {
_rootBone->setWorldMatDirty(true);
_rootBone->updateWorldMat(); _rootBone->updateWorldMat();
} }

View File

@ -50,22 +50,18 @@ public:
*/ */
const Mat4& getInverseBindPose(); const Mat4& getInverseBindPose();
bool needUpdateWorldMat() const;
//update own world matrix and children's //update own world matrix and children's
void updateWorldMat(); void updateWorldMat();
void setWorldMatDirty(bool dirty = true);
const Mat4& getWorldMat(); const Mat4& getWorldMat();
const std::string& getName() const { return _name; } const std::string& getName() const { return _name; }
/** void setAnimationValue(float* trans, float* rot, float* scale, float weight = 1.0f);
* Set AnimationValue. set to its transform
*/
void setAnimationValueTranslation(float* value);
void setAnimationValueRotation(float* value);
void setAnimationValueScale(float* value);
void clearBoneBlendState();
/** /**
* Creates C3DBone. * Creates C3DBone.
*/ */
@ -98,11 +94,21 @@ public:
protected: protected:
enum DirtyFlag
struct BoneBlendState
{ {
Dirty_Translate = 1, Vec3 localTranslate;
Dirty_Rotation = 2, Quaternion localRot;
Dirty_Scale = 4, Vec3 localScale;
float weight;
BoneBlendState()
: localTranslate(Vec3::ZERO)
, localRot(Quaternion::identity())
, localScale(Vec3::ONE)
, weight(1.f)
{
}
}; };
/** /**
* Constructor. * Constructor.
@ -125,27 +131,17 @@ protected:
*/ */
Mat4 _bindPose; Mat4 _bindPose;
// /**
// * Flag used to mark if the Joint's matrix is dirty.
// */
// bool _jointMatrixDirty;
//
// /**
// * The number of MeshSkin's influencing the Joint.
// */
// unsigned int _skinCount;
Bone* _parent; Bone* _parent;
Vector<Bone*> _children; Vector<Bone*> _children;
int _dirtyFlag; bool _localDirty;
bool _worldDirty; bool _worldDirty;
Mat4 _world; Mat4 _world;
Mat4 _local; Mat4 _local;
Vec3 _localTranslate;
Quaternion _localRot; std::vector<BoneBlendState> _blendStates;
Vec3 _localScale;
}; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -1,4 +1,4 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2013 cocos2d-x.org Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) 2011 Zynga Inc. Copyright (c) 2011 Zynga Inc.
@ -763,6 +763,18 @@ Vec2 Director::convertToUI(const Vec2& glPoint)
Vec4 glCoord(glPoint.x, glPoint.y, 0.0, 1); Vec4 glCoord(glPoint.x, glPoint.y, 0.0, 1);
transform.transformVector(glCoord, &clipCoord); 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(); Size glSize = _openGLView->getDesignResolutionSize();
float factor = 1.0/glCoord.w; 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); return Vec2(glSize.width*(clipCoord.x*0.5 + 0.5) * factor, glSize.height*(-clipCoord.y*0.5 + 0.5) * factor);

View File

@ -215,26 +215,14 @@ static inline void lazyCheckIOS7()
static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize) static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize)
{ {
NSArray *listItems = [str componentsSeparatedByString: @"\n"];
CGSize dim = CGSizeZero;
CGSize textRect = CGSizeZero; CGSize textRect = CGSizeZero;
textRect.width = constrainSize->width > 0 ? constrainSize->width textRect.width = constrainSize->width > 0 ? constrainSize->width
: 0x7fffffff; : 0x7fffffff;
textRect.height = constrainSize->height > 0 ? constrainSize->height textRect.height = constrainSize->height > 0 ? constrainSize->height
: 0x7fffffff; : 0x7fffffff;
for (NSString *s in listItems) CGSize dim = [str sizeWithFont:font constrainedToSize:textRect];
{
CGSize tmp = [s sizeWithFont:font constrainedToSize:textRect];
if (tmp.width > dim.width)
{
dim.width = tmp.width;
}
dim.height += tmp.height;
}
dim.width = ceilf(dim.width); dim.width = ceilf(dim.width);
dim.height = ceilf(dim.height); dim.height = ceilf(dim.height);

View File

@ -140,9 +140,17 @@ GLProgram::~GLProgram()
{ {
CCLOGINFO("%s %d deallocing GLProgram: %p", __FUNCTION__, __LINE__, this); CCLOGINFO("%s %d deallocing GLProgram: %p", __FUNCTION__, __LINE__, this);
// there is no need to delete the shaders. They should have been already deleted. if (_vertShader)
CCASSERT(_vertShader == 0, "Vertex Shaders should have been already deleted"); {
CCASSERT(_fragShader == 0, "Fragment Shaders should have been already deleted"); glDeleteShader(_vertShader);
}
if (_fragShader)
{
glDeleteShader(_fragShader);
}
_vertShader = _fragShader = 0;
if (_program) if (_program)
{ {
@ -444,7 +452,7 @@ bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source
} }
free(src); free(src);
abort(); return false;;
} }
return (status == GL_TRUE); return (status == GL_TRUE);
} }

View File

@ -206,11 +206,11 @@ void TextureCache::loadImage()
for (; pos < infoSize; pos++) for (; pos < infoSize; pos++)
{ {
imageInfo = (*_imageInfoQueue)[pos]; imageInfo = (*_imageInfoQueue)[pos];
if(imageInfo->asyncStruct->filename.compare(asyncStruct->filename)) if(imageInfo->asyncStruct->filename.compare(asyncStruct->filename) == 0)
break; break;
} }
_imageInfoMutex.unlock(); _imageInfoMutex.unlock();
if(infoSize == 0 || pos < infoSize) if(infoSize == 0 || pos == infoSize)
generateImage = true; generateImage = true;
} }

View File

@ -421,22 +421,16 @@ class SpriteBlur : public Sprite
{ {
public: public:
~SpriteBlur(); ~SpriteBlur();
void setBlurSize(float f);
bool initWithTexture(Texture2D* texture, const Rect& rect); bool initWithTexture(Texture2D* texture, const Rect& rect);
void initGLProgram(); void initGLProgram();
static SpriteBlur* create(const char *pszFileName); static SpriteBlur* create(const char *pszFileName);
void setBlurRadius(float radius);
void setBlurSampleNum(float num);
protected: protected:
float _blurRadius;
int _blurRadius; float _blurSampleNum;
Vec2 _pixelSize;
int _samplingRadius;
//gaussian = cons * exp( (dx*dx + dy*dy) * scale);
float _scale;
float _cons;
float _weightSum;
}; };
SpriteBlur::~SpriteBlur() SpriteBlur::~SpriteBlur()
@ -472,14 +466,7 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect)
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif #endif
auto s = getTexture()->getContentSizeInPixels(); initGLProgram();
_pixelSize = Vec2(1/s.width, 1/s.height);
_samplingRadius = 0;
this->initGLProgram();
getGLProgramState()->setUniformVec2("onePixelSize", _pixelSize);
return true; return true;
} }
@ -495,43 +482,23 @@ void SpriteBlur::initGLProgram()
auto glProgramState = GLProgramState::getOrCreateWithGLProgram(program); auto glProgramState = GLProgramState::getOrCreateWithGLProgram(program);
setGLProgramState(glProgramState); setGLProgramState(glProgramState);
auto size = getTexture()->getContentSizeInPixels();
getGLProgramState()->setUniformVec2("resolution", size);
getGLProgramState()->setUniformFloat("blurRadius", _blurRadius);
getGLProgramState()->setUniformFloat("sampleNum", 7.0f);
} }
void SpriteBlur::setBlurSize(float f) void SpriteBlur::setBlurRadius(float radius)
{ {
if(_blurRadius == (int)f) _blurRadius = radius;
return; getGLProgramState()->setUniformFloat("blurRadius", _blurRadius);
_blurRadius = (int)f; }
_samplingRadius = _blurRadius; void SpriteBlur::setBlurSampleNum(float num)
if (_samplingRadius > 10) {
{ _blurSampleNum = num;
_samplingRadius = 10; getGLProgramState()->setUniformFloat("sampleNum", _blurSampleNum);
}
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));
} }
// ShaderBlur // ShaderBlur
@ -551,22 +518,43 @@ std::string ShaderBlur::subtitle() const
return "Gaussian blur"; return "Gaussian blur";
} }
ControlSlider* ShaderBlur::createSliderCtl() void ShaderBlur::createSliderCtls()
{ {
auto screenSize = Director::getInstance()->getWinSize(); 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)); ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
slider->setMinimumValue(0.0f); // Sets the min value of range slider->setAnchorPoint(Vec2(0.5f, 1.0f));
slider->setMaximumValue(25.0f); // Sets the max value of range 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)); {
ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
// When the value of the slider will change, the given selector will be call slider->setAnchorPoint(Vec2(0.5f, 1.0f));
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::sliderAction), Control::EventType::VALUE_CHANGED); slider->setMinimumValue(0.0f);
slider->setValue(2.0f); slider->setMaximumValue(11.0f);
slider->setScale(0.6f);
return slider; 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));
}
} }
@ -575,9 +563,7 @@ bool ShaderBlur::init()
if( ShaderTestDemo::init() ) if( ShaderTestDemo::init() )
{ {
_blurSprite = SpriteBlur::create("Images/grossini.png"); _blurSprite = SpriteBlur::create("Images/grossini.png");
auto sprite = Sprite::create("Images/grossini.png"); auto sprite = Sprite::create("Images/grossini.png");
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();
_blurSprite->setPosition(Vec2(s.width/3, s.height/2)); _blurSprite->setPosition(Vec2(s.width/3, s.height/2));
sprite->setPosition(Vec2(2*s.width/3, s.height/2)); sprite->setPosition(Vec2(2*s.width/3, s.height/2));
@ -585,19 +571,24 @@ bool ShaderBlur::init()
addChild(_blurSprite); addChild(_blurSprite);
addChild(sprite); addChild(sprite);
_sliderCtl = createSliderCtl(); createSliderCtls();
addChild(_sliderCtl);
return true; return true;
} }
return false; return false;
} }
void ShaderBlur::sliderAction(Ref* sender, Control::EventType controlEvent) void ShaderBlur::onRadiusChanged(Ref* sender, Control::EventType)
{ {
ControlSlider* slider = (ControlSlider*)sender; ControlSlider* slider = (ControlSlider*)sender;
_blurSprite->setBlurSize(slider->getValue()); _blurSprite->setBlurRadius(slider->getValue());
}
void ShaderBlur::onSampleNumChanged(Ref* sender, Control::EventType)
{
ControlSlider* slider = (ControlSlider*)sender;
_blurSprite->setBlurSampleNum(slider->getValue());
} }
// ShaderRetroEffect // ShaderRetroEffect

View File

@ -92,11 +92,14 @@ public:
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
virtual bool init(); virtual bool init();
ControlSlider* createSliderCtl(); void createSliderCtls();
void sliderAction(Ref* sender, Control::EventType controlEvent); void onRadiusChanged(Ref* sender, Control::EventType controlEvent);
void onSampleNumChanged(Ref* sender, Control::EventType controlEvent);
protected: protected:
SpriteBlur* _blurSprite; SpriteBlur* _blurSprite;
ControlSlider* _sliderCtl; ControlSlider* _sliderRadiusCtl;
ControlSlider* _sliderNumCtrl;
}; };
class ShaderRetroEffect : public ShaderTestDemo class ShaderRetroEffect : public ShaderTestDemo

View File

@ -249,80 +249,42 @@ class EffectBlur : public Effect
{ {
public: public:
CREATE_FUNC(EffectBlur); CREATE_FUNC(EffectBlur);
virtual void setTarget(EffectSprite *sprite) override; virtual void setTarget(EffectSprite *sprite) override;
void setBlurRadius(float radius);
void setGaussian(float value); void setBlurSampleNum(float num);
void setCustomUniforms();
void setBlurSize(float f);
protected: protected:
bool init(float blurSize=3.0); bool init(float blurRadius = 10.0f, float sampleNum = 5.0f);
int _blurRadius; float _blurRadius;
Vec2 _pixelSize; float _blurSampleNum;
int _samplingRadius;
float _scale;
float _cons;
float _weightSum;
}; };
void EffectBlur::setTarget(EffectSprite *sprite) void EffectBlur::setTarget(EffectSprite *sprite)
{ {
Size s = sprite->getTexture()->getContentSizeInPixels(); Size size = sprite->getTexture()->getContentSizeInPixels();
_pixelSize = Vec2(1/s.width, 1/s.height); _glprogramstate->setUniformVec2("resolution", size);
_glprogramstate->setUniformVec2("onePixelSize", _pixelSize); _glprogramstate->setUniformFloat("blurRadius", _blurRadius);
_glprogramstate->setUniformFloat("sampleNum", _blurSampleNum);
} }
bool EffectBlur::init(float blurSize) bool EffectBlur::init(float blurRadius, float sampleNum)
{ {
initGLProgramState("Shaders/example_Blur.fsh"); initGLProgramState("Shaders/example_Blur.fsh");
auto s = Size(100,100); _blurRadius = blurRadius;
_blurSampleNum = sampleNum;
_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));
return true; return true;
} }
void EffectBlur::setBlurSize(float f) void EffectBlur::setBlurRadius(float radius)
{ {
if(_blurRadius == (int)f) _blurRadius = radius;
return; }
_blurRadius = (int)f;
_samplingRadius = _blurRadius; void EffectBlur::setBlurSampleNum(float num)
if (_samplingRadius > 10) {
{ _blurSampleNum = num;
_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;
}
}
}
} }
// Outline // Outline

View File

@ -541,12 +541,12 @@ std::string Sprite3DWithSkinTest::subtitle() const
void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p) void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p)
{ {
auto sprite = Sprite3D::create("Sprite3DTest/scene.c3t"); auto sprite = Sprite3D::create("Sprite3DTest/girl.c3t");
addChild(sprite); addChild(sprite);
sprite->setPosition( Vec2( p.x, p.y) ); sprite->setPosition( Vec2( p.x, p.y) );
auto animation = Animation3D::getOrCreate("Sprite3DTest/scene.c3t"); auto animation = Animation3D::getOrCreate("Sprite3DTest/girl.c3t");
if (animation) if (animation)
{ {
auto animate = Animate3D::create(animation); auto animate = Animate3D::create(animation);

View File

@ -1,5 +1,3 @@
// Shader taken from: http://webglsamples.googlecode.com/hg/electricflower/electricflower.html
#ifdef GL_ES #ifdef GL_ES
precision mediump float; precision mediump float;
#endif #endif
@ -7,50 +5,42 @@ precision mediump float;
varying vec4 v_fragmentColor; varying vec4 v_fragmentColor;
varying vec2 v_texCoord; varying vec2 v_texCoord;
uniform vec4 gaussianCoefficient; uniform vec2 resolution;
uniform vec2 onePixelSize; uniform float blurRadius;
uniform float sampleNum;
void main() { vec3 blur(vec2);
if(gaussianCoefficient.x > 0.0) {
vec4 sum = vec4(0.0); void main(void)
vec2 offset; {
float weight; vec3 col = blur(v_texCoord);
float squareX; gl_FragColor = vec4(col, 1.0) * v_fragmentColor;
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 p)
{
if (blurRadius > 0.0 && sampleNum > 1.0)
{
vec3 col = vec3(0);
vec2 unit = 1.0 / resolution.xy;
float r = blurRadius;
float sampleStep = r / sampleNum;
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;
}

File diff suppressed because it is too large Load Diff

View File

@ -79,7 +79,7 @@ def main():
print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered' print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered'
return(0) 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'] access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token} Headers = {"Authorization":"token " + access_token}

View File

@ -90,7 +90,7 @@ def main():
print 'skip build for pull request #' + str(pr_num) print 'skip build for pull request #' + str(pr_num)
return(0) 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'] access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token} Headers = {"Authorization":"token " + access_token}

View File

@ -18,7 +18,7 @@ statuses_url = payload['statuses_url']
J = Jenkins(os.environ['JENKINS_URL']) J = Jenkins(os.environ['JENKINS_URL'])
target_url = os.environ['BUILD_URL'] target_url = os.environ['BUILD_URL']
build_number = int(os.environ['BUILD_NUMBER']) 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'] access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + 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): if(result == STATUS_SUCCESS):
data['state'] = "success" data['state'] = "success"
data['description'] = "Build successfully!"
else: else:
data['state'] = "failure" data['state'] = "failure"
data['description'] = "Build failed!"
http_proxy = '' http_proxy = ''
if(os.environ.has_key('HTTP_PROXY')): if(os.environ.has_key('HTTP_PROXY')):
http_proxy = os.environ['HTTP_PROXY'] http_proxy = os.environ['HTTP_PROXY']

View File

@ -104,7 +104,7 @@ def main():
set_description(pr_desc, target_url) 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'] access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token} Headers = {"Authorization":"token " + access_token}