Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3_5_test

This commit is contained in:
samuele3hu 2015-03-30 15:51:01 +08:00
commit 6c528c4a42
14 changed files with 320 additions and 70 deletions

View File

@ -108,10 +108,13 @@ class CC_DLL TextFieldTTF : public Label, public IMEDelegate
{
public:
/**
* Default constructor.
* @js ctor
*/
TextFieldTTF();
/**
* Default destructor.
* @js NA
* @lua NA
*/

View File

@ -120,6 +120,9 @@ void Skybox::onDraw(const Mat4& transform, uint32_t flags)
{
auto state = getGLProgramState();
state->apply(transform);
Vec4 color(_displayedColor.r / 255.f, _displayedColor.g / 255.f, _displayedColor.b / 255.f, 1.f);
state->setUniformVec4("u_color", color);
GLboolean depthFlag = glIsEnabled(GL_DEPTH_TEST);
GLint depthFunc;
@ -179,12 +182,6 @@ void Skybox::setTexture(TextureCube* texture)
void Skybox::reload()
{
auto glProgram = getGLProgramState()->getGLProgram();
glProgram->reset();
glProgram->initWithFilenames("Shaders3D/Skybox.vert", "Shaders3D/Skybox.frag");
glProgram->link();
glProgram->updateUniforms();
initBuffers();
}

View File

@ -58,15 +58,22 @@ class CC_DLL IMEDelegate
{
public:
/**
* Default constructor.
* @js NA
* @lua NA
*/
virtual ~IMEDelegate();
/**
* Default destructor.
* @js NA
* @lua NA
*/
virtual bool attachWithIME();
/**
* Determine whether the IME is detached or not.
* @js NA
* @lua NA
*/
virtual bool detachWithIME();

View File

@ -5,9 +5,10 @@ varying mediump vec3 v_reflect;
varying vec3 v_reflect;
\n#endif\n
uniform samplerCube u_Env;
uniform vec4 u_color;
void main(void)
{
gl_FragColor = textureCube(u_Env, v_reflect);
gl_FragColor = textureCube(u_Env, v_reflect) * u_color;
}
);
);

View File

@ -2056,6 +2056,47 @@ bool luaval_to_quaternion(lua_State* L,int lo,cocos2d::Quaternion* outValue, con
return ok;
}
bool luaval_to_texparams(lua_State* L,int lo,cocos2d::Texture2D::TexParams* outValue, const char* funcName)
{
if (nullptr == L || nullptr == outValue)
return false;
bool ok = true;
tolua_Error tolua_err;
if (!tolua_istable(L, lo, 0, &tolua_err) )
{
#if COCOS2D_DEBUG >=1
luaval_to_native_err(L,"#ferror:",&tolua_err,funcName);
#endif
ok = false;
}
if (ok)
{
lua_pushstring(L, "minFilter");
lua_gettable(L, lo);
outValue->minFilter = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "magFilter");
lua_gettable(L, lo);
outValue->magFilter = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "wrapS");
lua_gettable(L, lo);
outValue->wrapS = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "wrapT");
lua_gettable(L, lo);
outValue->wrapT = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
lua_pop(L, 1);
}
return ok;
}
void vec2_array_to_luaval(lua_State* L,const cocos2d::Vec2* points, int count)
{
if (NULL == L)
@ -3020,3 +3061,24 @@ void quaternion_to_luaval(lua_State* L,const cocos2d::Quaternion& inValue)
lua_pushnumber(L, (lua_Number) inValue.w); /* L: table key value*/
lua_rawset(L, -3);
}
void texParams_to_luaval(lua_State* L, const cocos2d::Texture2D::TexParams& inValue)
{
if (nullptr == L)
return;
lua_newtable(L); /* L: table */
lua_pushstring(L, "minFilter"); /* L: table key */
lua_pushnumber(L, (lua_Number) inValue.minFilter); /* L: table key value*/
lua_rawset(L, -3); /* table[key] = value, L: table */
lua_pushstring(L, "magFilter"); /* L: table key */
lua_pushnumber(L, (lua_Number) inValue.magFilter); /* L: table key value*/
lua_rawset(L, -3);
lua_pushstring(L, "wrapS"); /* L: table key */
lua_pushnumber(L, (lua_Number) inValue.wrapS); /* L: table key value*/
lua_rawset(L, -3);
lua_pushstring(L, "wrapT"); /* L: table key */
lua_pushnumber(L, (lua_Number) inValue.wrapT); /* L: table key value*/
lua_rawset(L, -3);
}

View File

@ -759,6 +759,18 @@ extern bool luaval_to_std_vector_ushort(lua_State* L, int lo, std::vector<unsign
*/
extern bool luaval_to_quaternion(lua_State* L,int lo,cocos2d::Quaternion* outValue, const char* funcName = "");
/**
* Get a cocos2d::Texture2D::TexParams object value from the given accpetable index of stack.
* If the value at the given accpetable index of stack is a table it returns true, otherwise returns false.
* If the table has the `minFilter`, `magFilter`, `wrapS` and `wrapT` keys and the corresponding values are not nil, this function would assign the values to the corresponding members of outValue.Otherwise, the value of members of outValue would be 0.
* @param L the current lua_State.
* @param lo the given accpetable index of stack.
* @param outValue the pointer to a cocos2d::Quaternion object which stores the values from the Lua table.
* @param funcName the name of calling function, it is used for error output in the debug model.
* @return true if the value at the given accpetable index of stack is a table, otherwise return false.
*/
extern bool luaval_to_texparams(lua_State* L,int lo,cocos2d::Texture2D::TexParams* outValue, const char* funcName = "");
/**@}**/
// from native
@ -1195,6 +1207,15 @@ void ccvector_ushort_to_luaval(lua_State* L, const std::vector<unsigned short>&
*/
void quaternion_to_luaval(lua_State* L,const cocos2d::Quaternion& inValue);
/**
* Push a table converted from a cocos2d::Texture2D::TexParams object into the Lua stack.
* The format of table as follows: {minFilter=numberValue1, magFilter=numberValue2, wrapS=numberValue3, wrapT=numberValue4}
*
* @param L the current lua_State.
* @param inValue a cocos2d::Texture2D::TexParams object.
*/
void texParams_to_luaval(lua_State* L, const cocos2d::Texture2D::TexParams& inValue);
// end group
/// @}
#endif //__COCOS2DX_SCRIPTING_LUA_COCOS2DXSUPPORT_LUABAISCCONVERSIONS_H__

View File

@ -52,12 +52,42 @@ class Scale9Sprite;
class CC_GUI_DLL LayoutProtocol
{
public:
/**
*@brief Default constructor.
*/
LayoutProtocol(){}
/**
*@brief Default destructor.
*/
virtual ~LayoutProtocol(){}
/**
* @brief Create a custom layout manager.
*
* @return A LayoutManager descendants instance.
*/
virtual LayoutManager* createLayoutManager() = 0;
/**
* @brief Return the content size of layout.
*
* @return A content size in Size.
*/
virtual Size getLayoutContentSize()const = 0;
/**
* @brief Get all elements of the layout.
*
* @return A vector of Node pointers.
*/
virtual const Vector<Node*>& getLayoutElements()const = 0;
/**
* @brief The main function to do the layout job.
* Different layout manager should implement its own layout algorithm.
*
*/
virtual void doLayout() = 0;
};

View File

@ -48,6 +48,9 @@ namespace experimental{
class VideoPlayer : public cocos2d::ui::Widget
{
public:
/**
* Videoplayer play event type.
*/
enum class EventType
{
PLAYING = 0,
@ -55,15 +58,27 @@ namespace experimental{
STOPPED,
COMPLETED
};
/**
* A callback which will be called after specific VideoPlayer event happens.
*/
typedef std::function<void(Ref*,VideoPlayer::EventType)> ccVideoPlayerCallback;
/**
*Static create method for instancing a VideoPlayer.
*/
CREATE_FUNC(VideoPlayer);
/**
* Sets a file path as a video source for VideoPlayer.
*/
virtual void setFileName(const std::string& videoPath);
/**
* @brief Get the local video filie name.
*
* @return The video file name.
*/
virtual const std::string& getFileName() const { return _videoURL;}
/**
@ -71,6 +86,12 @@ namespace experimental{
*/
virtual void setURL(const std::string& _videoURL);
/**
* @brief Get the URL of remoting video source.
*
* @return A remoting URL address.
*/
virtual const std::string& getURL() const { return _videoURL;}
/**
@ -140,7 +161,13 @@ namespace experimental{
* @param callback The callback that will be run.
*/
virtual void addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback);
/**
* @brief A function which will be called when video is playing.
*
* @param event @see VideoPlayer::EventType.
*/
virtual void onPlayEvent(int event);
virtual void setVisible(bool visible) override;
virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags) override;

View File

@ -152,6 +152,9 @@ public:
*/
void setOnShouldStartLoading(const std::function<bool(WebView *sender, const std::string &url)>& callback);
/**
* A callback which will be called when a WebView event happens.
*/
typedef std::function<void(WebView *sender, const std::string &url)> ccWebViewCallback;
/**
@ -173,13 +176,31 @@ public:
*/
void setOnJSCallback(const ccWebViewCallback& callback);
/**
* Get the callback when WebView is about to start.
*/
std::function<bool(WebView *sender, const std::string &url)> getOnShouldStartLoading()const;
/**
* Get the callback when WebView has finished loading.
*/
ccWebViewCallback getOnDidFinishLoading()const;
/**
* Get the callback when WebView has failed loading.
*/
ccWebViewCallback getOnDidFailLoading()const;
/**
*Get the Javascript callback.
*/
ccWebViewCallback getOnJSCallback()const;
virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) override;
/**
* Toggle visibility of WebView.
*/
virtual void setVisible(bool visible) override;
protected:

View File

@ -2560,6 +2560,6 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p)
_skyBox->reload();
_skyBox->setTexture(_textureCube);
});
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1);
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, 1);
#endif
}

View File

@ -1,8 +1,12 @@
#ifdef GL_ES
precision mediump float;
#endif
varying vec3 v_reflect;
varying vec3 v_reflect;
uniform samplerCube u_cubeTex;
uniform vec4 u_color;
void main(void)
{
gl_FragColor = textureCube(u_cubeTex, v_reflect);
}
gl_FragColor = textureCube(u_cubeTex, v_reflect) * u_color;
}

View File

@ -1025,70 +1025,147 @@ function AsyncLoadSprite3DTest:onEnter()
end
function AsyncLoadSprite3DTest:onExit()
end
----------------------------------------
----Sprite3DCubeTexture
----------------------------------------
local Sprite3DCubeMap = {}
Sprite3DCubeMap.__index = Sprite3DCubeMap
local Sprite3DCubeMapTest = class("Sprite3DCubeMapTest", function ()
local layer = cc.Layer:create()
Helper.initWithLayer(layer)
return layer
end)
function Sprite3DCubeMap.create()
local layer = cc.Layer:create()
Helper.initWithLayer(layer)
Helper.titleLabel:setString("Sprite3D CubeMap/Skybox Test")
local visSize = cc.Director:getInstance():getVisibleSize()
local camera = cc.Camera:createPerspective(68, visSize.width / visSize.height, 0.1, 200)
camera:setCameraFlag(2)
layer:addChild(camera)
local fileName = "Sprite3DTest/teapot.c3b"
local teapot = cc.Sprite3D:create(fileName)
teapot:setPosition3D({x = 0, y = -5, z = -20})
teapot:setRotation3D({x = -90, y = 180, z = 0})
local texCube = cc.TextureCube:create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg",
"Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg",
"Sprite3DTest/skybox/front.jpg", "Sprite3DTest/skybox/back.jpg");
local program = cc.GLProgram:createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag")
local state = cc.GLProgramState:create(program)
attriNames = {
"a_position", "a_color",
"a_texCoord", "a_texCoord1", "a_texCoord2", "a_texCoord3",
"a_normal", "a_blendWeight", "a_blendIndex"
}
--pass mesh's attribute to shader
local offset = 0
local attributeCount = teapot:getMesh():getMeshVertexAttribCount()
for i = 0, attributeCount-1 do
local meshattribute = teapot:getMesh():getMeshVertexAttribute(i)
state:setVertexAttribPointer(attriNames[meshattribute.vertexAttrib+1],
meshattribute.size,
meshattribute.type,
false,
teapot:getMesh():getVertexSizeInBytes(),
offset);
offset = offset + meshattribute.attribSizeBytes
function Sprite3DCubeMapTest:ctor()
-- body
self:init()
self._textureCube = nil
self._skyBox = nil
self._teapot = nil
end
state:setUniformTexture("u_cubeTex", texCube:getName())
function Sprite3DCubeMapTest:init()
Helper.titleLabel:setString(self:title())
Helper.subtitleLabel:setString(self:subtitle())
teapot:setGLProgramState(state)
teapot:setCameraMask(2)
self:registerScriptHandler(function (event)
if event == "enter" then
self:onEnter()
elseif event == "exit" then
self:onExit()
end
end)
end
local rotate_action = cc.RotateBy:create(1.5, { x = 0.0, y = 30.0, z = 0.0})
teapot:runAction(cc.RepeatForever:create(rotate_action));
layer:addChild(teapot)
function Sprite3DCubeMapTest:title()
return "CubeMap & Skybox Test"
end
local skybox = cc.Skybox:create()
skybox:setTexture(texCube)
layer:addChild(skybox)
function Sprite3DCubeMapTest:subtitle()
return ""
end
return layer
>>>>>>> 4ea27173daf6b04cf0b917faa7911dde448cbdca
function Sprite3DCubeMapTest:onEnter()
local s = cc.Director:getInstance():getWinSize()
self:addNewSpriteWithCoords(cc.p(s.width / 2, s.height / 2))
end
function Sprite3DCubeMapTest:onExit()
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
if targetPlatform == cc.PLATFORM_OS_ANDROID or targetPlatform == cc.PLATFORM_OS_WINRT or targetPlatform == cc.PLATFORM_OS_WP8 then
cc.Director:getInstance():getEventDispatcher():removeEventListener(self._backToForegroundListener)
end
end
function Sprite3DCubeMapTest:addNewSpriteWithCoords(pos)
local visibleSize = cc.Director:getInstance():getVisibleSize()
local camera = cc.Camera:createPerspective(60, visibleSize.width / visibleSize.height, 0.1, 200)
camera:setCameraFlag(cc.CameraFlag.USER1)
--create a teapot
self._teapot = cc.Sprite3D:create("Sprite3DTest/teapot.c3b")
local shader = cc.GLProgram:createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag")
local state = cc.GLProgramState:create(shader)
self._textureCube = cc.TextureCube:create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg",
"Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg",
"Sprite3DTest/skybox/front.jpg", "Sprite3DTest/skybox/back.jpg")
--set texture parameters
local tRepeatParams = { magFilter=gl.NEAREST , minFilter=gl.NEAREST , wrapS=gl.MIRRORED_REPEAT , wrapT=gl.MIRRORED_REPEAT }
self._textureCube:setTexParameters(tRepeatParams)
--pass the texture sampler to our custom shader
state:setUniformTexture("u_cubeTex", self._textureCube)
self._teapot:setGLProgramState(state)
self._teapot:setPosition3D(cc.vec3(0, -5, -20))
self._teapot:setRotation3D(cc.vec3(-90, 180, 0))
local rotate_action = cc.RotateBy:create(1.5, cc.vec3(0, 30, 0))
self._teapot:runAction(cc.RepeatForever:create(rotate_action))
--pass mesh's attribute to shader
local attributeNames =
{
"a_position",
"a_color",
"a_texCoord",
"a_texCoord1",
"a_texCoord2",
"a_texCoord3",
"a_normal",
"a_blendWeight",
"a_blendIndex",
}
local offset = 0
local attributeCount = self._teapot:getMesh():getMeshVertexAttribCount()
for i = 1, attributeCount do
local meshattribute = self._teapot:getMesh():getMeshVertexAttribute(i - 1)
state:setVertexAttribPointer(attributeNames[meshattribute.vertexAttrib+1],
meshattribute.size,
meshattribute.type,
false,
self._teapot:getMesh():getVertexSizeInBytes(),
offset)
offset = offset + meshattribute.attribSizeBytes
end
self:addChild(self._teapot)
self:addChild(camera)
self:setCameraMask(2)
--config skybox
self._skyBox = cc.Skybox:create()
self._skyBox:setTexture(self._textureCube)
self:addChild(self._skyBox)
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
if targetPlatform == cc.PLATFORM_OS_ANDROID or targetPlatform == cc.PLATFORM_OS_WINRT or targetPlatform == cc.PLATFORM_OS_WP8 then
self._backToForegroundListener = cc.EventListenerCustom:create("event_renderer_recreated", function (eventCustom)
local state = self._teapot:getGLProgramState()
local glProgram = state:getGLProgram()
glProgramreset()
glProgram:initWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag")
glProgram:link()
glProgram:updateUniforms()
self._textureCube:reloadTexture()
local tRepeatParams = { magFilter=gl.NEAREST , minFilter=gl.NEAREST , wrapS=gl.MIRRORED_REPEAT , wrapT=gl.MIRRORED_REPEAT }
self._textureCube:setTexParameters(tRepeatParams)
state:setUniformTexture("u_cubeTex", self._textureCube)
self._skyBox:reload()
self._skyBox:setTexture(self._textureCube)
end)
cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(self._backToForegroundListener, -1)
end
end
function Sprite3DTest()
@ -1105,7 +1182,7 @@ function Sprite3DTest()
Sprite3DWithOBBPerfromanceTest.create,
Sprite3DMirrorTest.create,
AsyncLoadSprite3DTest.create,
Sprite3DCubeMap.create,
Sprite3DCubeMapTest.create,
}
scene:addChild(Sprite3DBasicTest.create())

@ -1 +1 @@
Subproject commit d20bd95b520374565d2c12b37f9fefc732f41891
Subproject commit af67671bfd8394e8a5e13d702e57f3fd7eaa5c78

View File

@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/cocos2d.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = Animate3D Sprite3D Animation3D Skeleton3D ^Mesh$ AttachNode BillBoard Sprite3DCache
classes = Animate3D Sprite3D Animation3D Skeleton3D ^Mesh$ AttachNode BillBoard Sprite3DCache TextureCube Skybox
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also