Merge branch 'v3' into wp8-shader-fix

This commit is contained in:
Dale Stammen 2014-10-28 22:08:04 -07:00
commit 32a5a2cbb8
15 changed files with 196 additions and 72 deletions

19
AUTHORS
View File

@ -938,6 +938,7 @@ Developers:
Fixed compiling error on WP8.
Added method for custom precompiled shader program loading on WP8
Enable screen orientation change handling on WP8
Enabled GLProgramState restoring on render recreated on WP8
chareice
Make `setup.py` work on zsh
@ -1032,6 +1033,21 @@ Developers:
coldfog
Fix bug that ActionManagerEx::initWithBinary can only load one UI animation
timur-losev
Fix a bug that GLProgramCache::addGLProgram() can not replace existing program
TimothyZhang
Fixed a potential memory leak in GLProgram::setGLProgram()
ahlwong
Fix Label Kerning on Single Characters
Svenito
Add greater than operator to Vec2
liamcindy
update ui button size changed logic
Retired Core Developers:
WenSheng Yang
@ -1044,9 +1060,6 @@ Retired Core Developers:
RongHong Huang (flyingpaper)
Author of cocos2d-xna and spent all his time on wp7.
timur-losev
Fix a bug that GLProgramCache::addGLProgram() can not replace existing program
Cocos2d-x can not grow so fast without the active community.
Thanks to all developers who report & trace bugs, discuss the engine usage in forum & QQ groups!

View File

@ -1,7 +1,13 @@
cocos2d-x-3.3 ??
[FIX] WP/WinRT: Windows 8.1 universal app support; `UIEditBox` support
[NEW] Vec2: added greater than operator
[FIX] GrawNode: drawPoint() may cause crash
[FIX] GLProgramCache: doesn't release old program with the same key before adding a new one
[FIX] GLProgramState: enabled GLProgramState restoring on render recreated on WP8
[FIX] Label: label shifting when outline feature enabled
[FIX] Label: when applying additionalKerning to a Label that displays a string with only 1 character, the character is shifted
[FIX] Sprite3D: did not create attached sprite from cache
[FIX] WP/WinRT: Windows 8.1 universal app support; `UIEditBox` support
cocos2d-x-3.3-rc0 Oct.21 2014
[NEW] 3d: added light support: direction light, point light, spot light and ambient light

View File

@ -346,9 +346,8 @@ void DrawNode::onDraw(const Mat4 &transform, uint32_t flags)
// texcood
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
}
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glDrawArrays(GL_TRIANGLES, 0, _bufferCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCount);
CHECK_GL_ERROR_DEBUG();
@ -382,9 +381,7 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags)
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
}
glLineWidth(2);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
glDrawArrays(GL_LINES, 0, _bufferCountGLLine);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLLine);
CHECK_GL_ERROR_DEBUG();
@ -399,15 +396,28 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags)
glProgram->setUniformLocationWith4fv(glProgram->getUniformLocation("u_color"), (GLfloat*) &_pointColor.r, 1);
glProgram->setUniformLocationWith1f(glProgram->getUniformLocation("u_pointSize"), _pointSize);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
if (_dirtyGLPoint)
{
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW);
_dirtyGLPoint = false;
}
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(_vaoGLPoint);
}
else
{
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
}
glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLPoint);
CHECK_GL_ERROR_DEBUG();
@ -415,6 +425,8 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags)
void DrawNode::drawPoint(const Vec2& position, const float pointSize, const Color4F &color)
{
ensureCapacityGLPoint(1);
V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint);
V2F_C4B_T2F a = {position, Color4B(color), Tex2F(0.0, 0.0) };
*point = a;
@ -423,6 +435,7 @@ void DrawNode::drawPoint(const Vec2& position, const float pointSize, const Colo
_pointColor = color;
_bufferCountGLPoint += 1;
_dirtyGLPoint = true;
}
void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, const Color4F &color)
@ -440,6 +453,7 @@ void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, con
_pointColor = color;
_bufferCountGLPoint += numberOfPoints;
_dirtyGLPoint = true;
}
void DrawNode::drawLine(const Vec2 &origin, const Vec2 &destination, const Color4F &color)

View File

@ -387,13 +387,16 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
log("WARNING: can't find letter definition in font file for letter: %c", c);
continue;
}
nextFontPositionX += charAdvance + kernings[i] + theLabel->_additionalKerning;
nextFontPositionX += charAdvance + kernings[i];
if (longestLine < nextFontPositionX)
{
longestLine = nextFontPositionX;
}
// check longest line before adding additional kerning
nextFontPositionX += theLabel->_additionalKerning;
}
float lastCharWidth = tempDefinition.width * contentScaleFactor;

View File

@ -418,6 +418,15 @@ public:
* @return True if this vector is less than the given vector, false otherwise.
*/
inline bool operator<(const Vec2& v) const;
/**
* Determines if this vector is greater than the given vector.
*
* @param v The vector to compare against.
*
* @return True if this vector is greater than the given vector, false otherwise.
*/
inline bool operator>(const Vec2& v) const;
/**
* Determines if this vector is equal to the given vector.

View File

@ -82,6 +82,15 @@ inline bool Vec2::operator<(const Vec2& v) const
return x < v.x;
}
inline bool Vec2::operator>(const Vec2& v) const
{
if (x == v.x)
{
return y > v.y;
}
return x > v.x;
}
inline bool Vec2::operator==(const Vec2& v) const
{
return x==v.x && y==v.y;

View File

@ -438,9 +438,16 @@ GLProgram* GLProgramCache::getGLProgram(const std::string &key)
void GLProgramCache::addGLProgram(GLProgram* program, const std::string &key)
{
// release old one
auto prev = getProgram(key);
if( prev == program )
return;
_programs.erase(key);
CC_SAFE_RELEASE_NULL(prev);
if (program)
program->retain();
program->retain();
_programs[key] = program;
}

View File

@ -279,7 +279,7 @@ GLProgramState::GLProgramState()
, _textureUnitIndex(1)
, _uniformAttributeValueDirty(true)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
/** listen the event that renderer was recreated on Android/WP8 */
CCLOG("create rendererRecreatedListener for GLProgramState");
_backToForegroundlistener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom*) { _uniformAttributeValueDirty = true; });
@ -289,7 +289,7 @@ GLProgramState::GLProgramState()
GLProgramState::~GLProgramState()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundlistener);
#endif

View File

@ -217,8 +217,8 @@ protected:
int _textureUnitIndex;
uint32_t _vertexAttribsFlags;
GLProgram *_glprogram;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
EventListenerCustom* _backToForegroundlistener;
#endif
};

View File

@ -2922,7 +2922,7 @@ void ccvector_std_string_to_luaval(lua_State* L, const std::vector<std::string>&
int index = 1;
for (const std::string value : inValue)
for (const std::string& value : inValue)
{
lua_pushnumber(L, (lua_Number)index);
lua_pushstring(L, value.c_str());

View File

@ -194,16 +194,7 @@ void Button::ignoreContentAdaptWithSize(bool ignore)
{
if (_unifySize)
{
if (_scale9Enabled)
{
ProtectedNode::setContentSize(_customSize);
}
else
{
Size s = getVirtualRendererSize();
ProtectedNode::setContentSize(s);
}
onSizeChanged();
this->updateContentSize();
return;
}
if (!_scale9Enabled || (_scale9Enabled && !ignore))
@ -249,7 +240,17 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType)
updateFlippedY();
this->updateChildrenDisplayedRGBA();
updateContentSizeWithTextureSize(_normalTextureSize);
if (_unifySize )
{
if (!_scale9Enabled)
{
updateContentSizeWithTextureSize(this->getNormalSize());
}
}
else
{
updateContentSizeWithTextureSize(_normalTextureSize);
}
_normalTextureLoaded = true;
_normalTextureAdaptDirty = true;
}
@ -434,7 +435,15 @@ void Button::onPressStateChangedToNormal()
_buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize);
_titleRenderer->stopAllActions();
_titleRenderer->runAction(zoomAction->clone());
if (_unifySize)
{
Action *zoomTitleAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1, 1);
_titleRenderer->runAction(zoomTitleAction);
}
else
{
_titleRenderer->runAction(zoomAction->clone());
}
}
}
else
@ -449,8 +458,16 @@ void Button::onPressStateChangedToNormal()
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
_titleRenderer->stopAllActions();
_titleRenderer->setScaleX(_normalTextureScaleXInSize);
_titleRenderer->setScaleY(_normalTextureScaleYInSize);
if (_unifySize)
{
_titleRenderer->setScaleX(1.0f);
_titleRenderer->setScaleY(1.0f);
}
else
{
_titleRenderer->setScaleX(_normalTextureScaleXInSize);
_titleRenderer->setScaleY(_normalTextureScaleYInSize);
}
}
}
}
@ -474,6 +491,15 @@ void Button::onPressStateChangedToPressed()
_titleRenderer->stopAllActions();
//we must call zoomAction->clone here
_titleRenderer->runAction(zoomAction->clone());
if (_unifySize)
{
Action *zoomTitleAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1 + _zoomScale, 1 + _zoomScale);
_titleRenderer->runAction(zoomTitleAction);
}
else
{
_titleRenderer->runAction(zoomAction->clone());
}
}
}
else
@ -491,8 +517,16 @@ void Button::onPressStateChangedToPressed()
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize +_zoomScale, _normalTextureScaleYInSize + _zoomScale);
_titleRenderer->stopAllActions();
_titleRenderer->setScaleX(_normalTextureScaleXInSize + _zoomScale);
_titleRenderer->setScaleY(_normalTextureScaleYInSize + _zoomScale);
if (_unifySize)
{
_titleRenderer->setScaleX(1.0f + _zoomScale);
_titleRenderer->setScaleY(1.0f + _zoomScale);
}
else
{
_titleRenderer->setScaleX(_normalTextureScaleXInSize + _zoomScale);
_titleRenderer->setScaleY(_normalTextureScaleYInSize + _zoomScale);
}
}
}
}
@ -532,9 +566,23 @@ void Button::updateTitleLocation()
void Button::updateContentSize()
{
if (_ignoreSize) {
this->setContentSize(getVirtualRendererSize());
}
if (_unifySize)
{
if (_scale9Enabled)
{
ProtectedNode::setContentSize(_customSize);
}
else
{
Size s = getNormalSize();
ProtectedNode::setContentSize(s);
}
onSizeChanged();
return;
}
if (_ignoreSize) {
this->setContentSize(getVirtualRendererSize());
}
}
void Button::onSizeChanged()
@ -567,6 +615,10 @@ void Button::adaptRenderers()
Size Button::getVirtualRendererSize() const
{
if (_unifySize)
{
return this->getNormalSize();
}
Size titleSize = _titleRenderer->getContentSize();
if (!_normalTextureLoaded && _titleRenderer->getString().size() > 0) {
return titleSize;
@ -596,11 +648,8 @@ Node* Button::getVirtualRenderer()
void Button::normalTextureScaleChangedWithSize()
{
if (_unifySize)
{
_buttonNormalRenderer->setPreferredSize(_contentSize);
}
else if (_ignoreSize)
if (_ignoreSize && !_unifySize)
{
if (!_scale9Enabled)
{
@ -638,11 +687,8 @@ void Button::normalTextureScaleChangedWithSize()
void Button::pressedTextureScaleChangedWithSize()
{
if (_unifySize)
{
_buttonClickedRenderer->setPreferredSize(_contentSize);
}
else if (_ignoreSize)
if (_ignoreSize && !_unifySize)
{
if (!_scale9Enabled)
{
@ -679,11 +725,8 @@ void Button::pressedTextureScaleChangedWithSize()
void Button::disabledTextureScaleChangedWithSize()
{
if (_unifySize)
{
_buttonDisableRenderer->setPreferredSize(_contentSize);
}
else if (_ignoreSize)
if (_ignoreSize && !_unifySize)
{
if (!_scale9Enabled)
{
@ -784,9 +827,11 @@ void Button::setTitleFontName(const std::string& fontName)
{
_titleRenderer->requestSystemFontRefresh();
}
_titleRenderer->setSystemFontSize(_fontSize);
_type = FontType::SYSTEM;
}
_fontName = fontName;
this->updateContentSize();
}
Label* Button::getTitleRenderer()const
@ -829,6 +874,24 @@ void Button::copySpecialProperties(Widget *widget)
setPressedActionEnabled(button->_pressedActionEnabled);
setZoomScale(button->_zoomScale);
}
}
Size Button::getNormalSize() const
{
Size titleSize;
if (_titleRenderer != nullptr)
{
titleSize = _titleRenderer->getContentSize();
}
Size imageSize;
if (_buttonNormalRenderer != nullptr)
{
imageSize = _buttonNormalRenderer->getContentSize();
}
float width = titleSize.width > imageSize.width ? titleSize.width : imageSize.width;
float height = titleSize.height > imageSize.height ? titleSize.height : imageSize.height;
return Size(width,height);
}
}

View File

@ -234,6 +234,7 @@ protected:
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
virtual Size getNormalSize() const;
protected:
Scale9Sprite* _buttonNormalRenderer;
Scale9Sprite* _buttonClickedRenderer;

View File

@ -375,6 +375,10 @@ DrawNodeTest::DrawNodeTest()
// Draw triangle
draw->drawTriangle(Vec2(10, 10), Vec2(70, 30), Vec2(100, 140), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
for (int i = 0; i < 100; i++) {
draw->drawPoint(Vec2(i*7, 5), 5, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
}
}
string DrawNodeTest::title() const

View File

@ -1259,7 +1259,7 @@ void Sprite3DWithOBBPerfromanceTest::addNewOBBWithCoords(Vec2 p)
void Sprite3DWithOBBPerfromanceTest::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
{
for (auto touch: touches)
for (const auto& touch: touches)
{
auto location = touch->getLocationInView();
auto obbSize = _obb.size();
@ -1287,7 +1287,7 @@ void Sprite3DWithOBBPerfromanceTest::onTouchesEnded(const std::vector<Touch*>& t
void Sprite3DWithOBBPerfromanceTest::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
{
for (auto touch: touches)
for (const auto& touch: touches)
{
auto location = touch->getLocation();
auto obbSize = _obb.size();
@ -1447,8 +1447,7 @@ void Sprite3DWithOBBPerfromanceTest::calculateRayByLocationInView(Ray* ray, cons
{
auto dir = Director::getInstance();
auto view = dir->getWinSize();
Mat4 mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Mat4 mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Vec3 src = Vec3(location.x, location.y, -1);
Vec3 nearPoint;

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -108,10 +108,8 @@
<TargetMachine>MachineX86</TargetMachine>
</Link>
<PreBuildEvent>
<Command>xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script\cocos2d" "$(ProjectDir)..\..\" /e /Y
xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script\cocosdenshion" "$(ProjectDir)..\..\" /e /Y
xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script\network" "$(ProjectDir)..\..\" /e /Y
xcopy "$(ProjectDir)..\..\..\..\external\lua\luasocket\*.lua" "$(ProjectDir)..\..\" /e /Y</Command>
<Command>if not exist "$(ProjectDir)..\..\src\cocos" mkdir "$(ProjectDir)..\..\src\cocos"
xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script" "$(ProjectDir)..\..\src\cocos" /e /Y</Command>
</PreBuildEvent>
<PreLinkEvent>
<Command>
@ -162,10 +160,8 @@ xcopy "$(ProjectDir)..\..\..\..\external\lua\luasocket\*.lua" "$(ProjectDir)..\.
</Command>
</PreLinkEvent>
<PreBuildEvent>
<Command>xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script\cocos2d" "$(ProjectDir)..\..\" /e /Y
xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script\cocosdenshion" "$(ProjectDir)..\..\" /e /Y
xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script\network" "$(ProjectDir)..\..\" /e /Y
xcopy "$(ProjectDir)..\..\..\..\external\lua\luasocket\*.lua" "$(ProjectDir)..\..\" /e /Y</Command>
<Command>if not exist "$(ProjectDir)..\..\src\cocos" mkdir "$(ProjectDir)..\..\src\cocos"
xcopy "$(ProjectDir)..\..\..\..\cocos\scripting\lua-bindings\script" "$(ProjectDir)..\..\src\cocos" /e /Y</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
@ -185,4 +181,4 @@ xcopy "$(ProjectDir)..\..\..\..\external\lua\luasocket\*.lua" "$(ProjectDir)..\.
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>