Merge pull request #6133 from samuele3hu/develop_new_label

fix the error about `draw` of GLNode and modify the related test cases
This commit is contained in:
James Chen 2014-04-03 17:34:27 +08:00
commit cb8edabb30
9 changed files with 192 additions and 21 deletions

View File

@ -780,6 +780,44 @@ bool luaval_to_fontdefinition(lua_State* L, int lo, FontDefinition* outValue )
return ok;
}
bool luaval_to_kmMat4(lua_State* L, int lo, kmMat4* outValue )
{
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);
ok = false;
#endif
}
if (ok)
{
size_t len = lua_objlen(L, lo);
for (int i = 0; i < len; i++)
{
lua_pushnumber(L,i + 1);
lua_gettable(L,lo);
if (tolua_isnumber(L, -1, 0, &tolua_err))
{
outValue->mat[i] = tolua_tonumber(L, -1, 0);
}
else
{
outValue->mat[i] = 0;
}
lua_pop(L, 1);
}
}
return ok;
}
bool luaval_to_array(lua_State* L,int lo, __Array** outValue)
{
if (NULL == L || NULL == outValue)

View File

@ -67,6 +67,7 @@ extern bool luaval_to_color4f(lua_State* L,int lo,Color4F* outValue);
extern bool luaval_to_physics_material(lua_State* L,int lo, cocos2d::PhysicsMaterial* outValue);
extern bool luaval_to_affinetransform(lua_State* L,int lo, AffineTransform* outValue);
extern bool luaval_to_fontdefinition(lua_State* L, int lo, FontDefinition* outValue );
extern bool luaval_to_kmMat4(lua_State* L, int lo, kmMat4* outValue );
extern bool luaval_to_array(lua_State* L,int lo, __Array** outValue);
extern bool luaval_to_dictionary(lua_State* L,int lo, __Dictionary** outValue);
extern bool luaval_to_array_of_Point(lua_State* L,int lo,Point **points, int *numPoints);

View File

@ -1 +1 @@
0bdb68570761c39f7a34fe78107f59f37790e849
9f759dc3875d5cbbe9b00da054338f2bde85efa0

View File

@ -33,10 +33,16 @@ extern "C" {
#endif
#include "CCNode.h"
#include "renderer/CCCustomCommand.h"
class GLNode:public cocos2d::Node
{
public:
virtual ~GLNode(){}
virtual void draw(cocos2d::Renderer *renderer, const kmMat4& transform, bool transformUpdated) override;
protected:
cocos2d::CustomCommand _renderCmd;
void onDraw(const kmMat4 &transform, bool transformUpdated);
};
TOLUA_API int tolua_opengl_open(lua_State* tolua_S);

View File

@ -1506,6 +1506,46 @@ tolua_lerror:
#endif
}
static int tolua_cocos2d_kmGLLoadMatrix00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!tolua_istable(tolua_S, 1, 0, &tolua_err)||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
kmMat4 mat4;
size_t len = lua_objlen(tolua_S, 1);
for (int i = 0; i < len; i++)
{
lua_pushnumber(tolua_S,i + 1);
lua_gettable(tolua_S,1);
#ifndef TOLUA_RELEASE
if (!tolua_isnumber(tolua_S, -1, 0, &tolua_err))
{
lua_pop(tolua_S, 1);
goto tolua_lerror;
}
else
#endif
{
mat4.mat[i] = tolua_tonumber(tolua_S, -1, 0);
lua_pop(tolua_S, 1);
}
}
kmGLLoadMatrix(&mat4);
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'kmGLLoadMatrix'.",&tolua_err);
return 0;
#endif
}
static int tolua_Cocos2d_CCString_intValue00(lua_State* tolua_S)
{
@ -1934,6 +1974,7 @@ int register_all_cocos2dx_deprecated(lua_State* tolua_S)
tolua_function(tolua_S,"kmGLPushMatrix",tolua_cocos2d_kmGLPushMatrix00);
tolua_function(tolua_S,"kmGLTranslatef",tolua_cocos2d_kmGLTranslatef00);
tolua_function(tolua_S,"kmGLPopMatrix",tolua_cocos2d_kmGLPopMatrix00);
tolua_function(tolua_S,"kmGLLoadMatrix",tolua_cocos2d_kmGLLoadMatrix00);
tolua_endmodule(tolua_S);
return 0;

View File

@ -87,7 +87,11 @@ local function drawPrimitivesMainLayer()
glNode:setContentSize(cc.size(size.width, size.height))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
local function primitivesDraw()
local function primitivesDraw(transform, transformUpdated)
kmGLPushMatrix()
kmGLLoadMatrix(transform)
cc.DrawPrimitives.drawLine(VisibleRect:leftBottom(), VisibleRect:rightTop() )
gl.lineWidth( 5.0 )
@ -152,6 +156,8 @@ local function drawPrimitivesMainLayer()
gl.lineWidth(1)
cc.DrawPrimitives.drawColor4B(255,255,255,255)
cc.DrawPrimitives.setPointSize(1)
kmGLPopMatrix()
end
glNode:registerScriptDrawHandler(primitivesDraw)

View File

@ -1338,7 +1338,7 @@ function LabelShadowTest.create()
layer:addChild(bg)
local ttfConfig = {}
ttfConfig.fontFilePath = "fonts/arial.ttf.ttf"
ttfConfig.fontFilePath = "fonts/arial.ttf"
ttfConfig.fontSize = 40
ttfConfig.glyphs = cc.GLYPHCOLLECTION_DYNAMIC
ttfConfig.customGlyphs = nil
@ -1666,6 +1666,83 @@ function LabelIssue4428Test.create()
return layer
end
--------------------------------------------------------
----- LabelTTFOldNew
--------------------------------------------------------
local LabelTTFOldNew = { }
function LabelTTFOldNew.create()
local layer = cc.Layer:create()
Helper.initWithLayer(layer)
Helper.titleLabel:setString("New / Old TTF")
Helper.subtitleLabel:setString("Comparison between old(red) and new(white) TTF label")
local s = cc.Director:getInstance():getWinSize()
local delta = s.height/4
local label1 = cc.Label:create("Cocos2d-x Label Test", "arial", 24)
layer:addChild(label1, 0, kTagBitmapAtlas1)
label1:setPosition(cc.p(s.width/2, delta * 2))
label1:setColor(cc.c3b(255, 0, 0))
local ttfConfig = {}
ttfConfig.fontFilePath = "fonts/arial.ttf"
ttfConfig.fontSize = 24
local label2 = cc.Label:createWithTTF(ttfConfig, "Cocos2d-x Label Test")
layer:addChild(label2, 0, kTagBitmapAtlas2)
label2:setPosition(cc.p(s.width/2, delta * 2))
local function onDraw(transform, transformUpdated)
kmGLPushMatrix()
kmGLLoadMatrix(transform)
local label1 = layer:getChildByTag(kTagBitmapAtlas1)
local labelSize = label1:getContentSize()
local origin = cc.Director:getInstance():getWinSize()
origin.width = origin.width / 2 - (labelSize.width / 2)
origin.height = origin.height / 2 - (labelSize.height / 2)
local vertices =
{
cc.p(origin.width, origin.height),
cc.p(labelSize.width + origin.width, origin.height),
cc.p(labelSize.width + origin.width, labelSize.height + origin.height),
cc.p(origin.width, labelSize.height + origin.height),
}
cc.DrawPrimitives.drawColor4B(255, 0, 0, 255)
cc.DrawPrimitives.drawPoly(vertices, 4, true)
local label2 = layer:getChildByTag(kTagBitmapAtlas2)
labelSize = label2:getContentSize()
origin = cc.Director:getInstance():getWinSize()
origin.width = origin.width / 2 - (labelSize.width / 2)
origin.height = origin.height / 2 - (labelSize.height / 2)
local vertices2 =
{
cc.p(origin.width, origin.height),
cc.p(labelSize.width + origin.width, origin.height),
cc.p(labelSize.width + origin.width, labelSize.height + origin.height),
cc.p(origin.width, labelSize.height + origin.height),
}
cc.DrawPrimitives.drawColor4B(255, 255, 255, 255)
cc.DrawPrimitives.drawPoly(vertices2, 4, true)
kmGLPopMatrix()
end
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(s.width, s.height))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:setPosition( s.width / 2, s.height / 2)
glNode:registerScriptDrawHandler(onDraw)
layer:addChild(glNode,-10)
return layer
end
------------
@ -1705,6 +1782,7 @@ function LabelTestNew()
LabelCharMapTest.create,
LabelCharMapColorTest.create,
LabelCrashTest.create,
LabelTTFOldNew.create,
LabelFontNameTest.create,
LabelAlignmentTest.create,
LabelIssue4428Test.create,

View File

@ -191,7 +191,7 @@ local function OpenGLTestMainLayer()
local program = shader:getProgram()
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(256,256))
glNode:setContentSize(cc.size(256, 256))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
uniformCenter = gl.getUniformLocation(program,"center")
uniformResolution = gl.getUniformLocation( program, "resolution")
@ -209,10 +209,10 @@ local function OpenGLTestMainLayer()
time = time + fTime
end
local function majoriDraw()
local function majoriDraw(transform, transformUpdated)
if nil ~= shader then
shader:use()
shader:setUniformsForBuiltins()
shader:setUniformsForBuiltins(transform)
--Uniforms
shader:setUniformLocationF32( uniformCenter, size.width/2, size.height/2)
shader:setUniformLocationF32( uniformResolution, 256, 256)
@ -231,6 +231,7 @@ local function OpenGLTestMainLayer()
glNode:registerScriptDrawHandler(majoriDraw)
time = 0
majorLayer:addChild(glNode,-10)
print("pos is ", size.width/2, size.height/2)
glNode:setPosition( size.width/2, size.height/2)
return majorLayer
end
@ -271,10 +272,10 @@ local function OpenGLTestMainLayer()
time = time + fTime
end
local function mandelbrotDraw()
local function mandelbrotDraw(transform, transformUpdated)
if nil ~= shader then
shader:use()
shader:setUniformsForBuiltins()
shader:setUniformsForBuiltins(transform)
--Uniforms
shader:setUniformLocationF32( uniformCenter, size.width/2, size.height/2)
shader:setUniformLocationF32( uniformResolution, 256, 256)
@ -333,10 +334,10 @@ local function OpenGLTestMainLayer()
time = time + fTime
end
local function heartDraw()
local function heartDraw(transform, transformUpdated)
if nil ~= shader then
shader:use()
shader:setUniformsForBuiltins()
shader:setUniformsForBuiltins(transform)
--Uniforms
shader:setUniformLocationF32( uniformCenter, size.width/2, size.height/2)
shader:setUniformLocationF32( uniformResolution, 256, 256)
@ -395,10 +396,10 @@ local function OpenGLTestMainLayer()
time = time + fTime
end
local function plasmaDraw()
local function plasmaDraw(transform, transformUpdated)
if nil ~= shader then
shader:use()
shader:setUniformsForBuiltins()
shader:setUniformsForBuiltins(transform)
--Uniforms
shader:setUniformLocationF32( uniformCenter, size.width/2, size.height/2)
shader:setUniformLocationF32( uniformResolution, 256, 256)
@ -457,10 +458,10 @@ local function OpenGLTestMainLayer()
time = time + fTime
end
local function flowerDraw()
local function flowerDraw(transform, transformUpdated)
if nil ~= shader then
shader:use()
shader:setUniformsForBuiltins()
shader:setUniformsForBuiltins(transform)
--Uniforms
shader:setUniformLocationF32( uniformCenter, size.width/2, size.height/2)
shader:setUniformLocationF32( uniformResolution, 256, 256)
@ -519,10 +520,10 @@ local function OpenGLTestMainLayer()
time = time + fTime
end
local function juliaDraw()
local function juliaDraw(transform, transformUpdated)
if nil ~= shader then
shader:use()
shader:setUniformsForBuiltins()
shader:setUniformsForBuiltins(transform)
--Uniforms
shader:setUniformLocationF32( uniformCenter, size.width/2, size.height/2)
shader:setUniformLocationF32( uniformResolution, 256, 256)
@ -639,10 +640,10 @@ local function OpenGLTestMainLayer()
gl.bindBuffer(gl.ARRAY_BUFFER,0)
end
local function TexImage2DDraw()
local function TexImage2DDraw(transform, transformUpdated)
if nil ~= shader then
shader:use()
shader:setUniformsForBuiltins()
shader:setUniformsForBuiltins(transform)
gl.bindTexture(gl.TEXTURE_2D, texture.texture_id)
gl.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_TEX_COORDS or cc.VERTEX_ATTRIB_FLAG_POSITION)
@ -1022,9 +1023,9 @@ local function OpenGLTestMainLayer()
gl.bindBuffer(gl.ARRAY_BUFFER, 0)
end
local function GLNodeCCAPIDraw()
local function GLNodeCCAPIDraw(transform, transformUpdated)
shader:use()
shader:setUniformsForBuiltins()
shader:setUniformsForBuiltins(transform)
gl.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_COLOR or cc.VERTEX_ATTRIB_FLAG_POSITION)
--

@ -1 +1 @@
Subproject commit 83818aec3cbe1ecf2db5380df254bab489d44f46
Subproject commit 3bd2143c9b031dd1de1b4ccbcf5b3d507b406b45