Merge pull request #13437 from fusijie/fix_lua_testcase_setPointer_error

Fixed setVertexAttribPointer luabinding and Test case.
This commit is contained in:
子龙山人 2015-08-19 11:43:18 +08:00
commit 1f735b4f0e
2 changed files with 79 additions and 297 deletions

View File

@ -7213,67 +7213,6 @@ static int lua_cocos2dx_GLProgramState_setVertexAttribPointer(lua_State* tolua_S
lua_settop(tolua_S, 1);
return 1;
}
else if (argc == 7)
{
std::string arg0;
int arg1;
unsigned int arg2;
bool arg3;
int arg4;
GLfloat* arg5;
int arg6;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.GLProgramState:setVertexAttribPointer");
ok &= luaval_to_int32(tolua_S, 3,(int *)&arg1, "cc.GLProgramState:setVertexAttribPointer");
ok &= luaval_to_uint32(tolua_S, 4,&arg2, "cc.GLProgramState:setVertexAttribPointer");
ok &= luaval_to_boolean(tolua_S, 5, &arg3, "cc.GLProgramState:setVertexAttribPointer");
ok &= luaval_to_int32(tolua_S, 6,(int *)&arg4, "cc.GLProgramState:setVertexAttribPointer");
ok &= luaval_to_int32(tolua_S, 8, (int *)&arg6, "cc.GLProgramState:setVertexAttribPointer");
size_t len = lua_objlen(tolua_S, 7);
if (len != arg6)
{
luaL_error(tolua_S, "table size is %zu,but input size is %d \n", len, arg6);
return 0;
}
arg5 = new (std::nothrow) GLfloat[len];
for (int i = 0; i < len; i++)
{
lua_pushnumber(tolua_S,i + 1);
lua_gettable(tolua_S,7);
bool isnum = true;
#if COCOS2D_DEBUG >= 1
if (!tolua_isnumber(tolua_S, -1, 0, &tolua_err))
{
isnum = false;
}
#endif
if (isnum)
{
arg5[i] = tolua_tonumber(tolua_S, -1, 0);
}
else
{
arg5[i] = 0;
}
lua_pop(tolua_S, 1);
}
cobj->setVertexAttribPointer(arg0, arg1, arg2, arg3, arg4, (void*)arg5);
CC_SAFE_DELETE(arg5);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.GLProgramState:setVertexAttribPointer",argc, 6);
return 0;

View File

@ -190,268 +190,111 @@ local function OpenGLTestMainLayer()
return RetroEffectlayer
end
local function createShaderMajoriTest()
local majorLayer = cc.Layer:create()
local function createShaderNodeLayer(vSource, fSource)
local shaderNodeLayer = cc.Layer:create()
InitTitle(majorLayer)
InitTitle(shaderNodeLayer)
local fileUtiles = cc.FileUtils:getInstance()
local vertSource = vertDefaultSource
local fragSource = fileUtiles:getStringFromFile("Shaders/example_Monjori.fsh")
local glProgam = cc.GLProgram:createWithByteArrays(vertSource, fragSource)
local glprogramstate = cc.GLProgramState:getOrCreateWithGLProgram(glProgam)
local resolution = cc.p(256, 256)
local vertSource = vSource
local fragSource = fSource
local glProgram = cc.GLProgram:createWithByteArrays(vertSource, fragSource)
glProgram:retain()
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(256, 256))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:setGLProgramState(glprogramstate)
glNode:getGLProgramState():setUniformVec2("resolution", resolution)
local function updateMajori(fTime)
local resolution = cc.p(256, 256)
local director = cc.Director:getInstance()
local frameSize = director:getOpenGLView():getFrameSize()
local visibleSize = director:getVisibleSize()
local retinaFactor = director:getOpenGLView():getRetinaFactor()
local center = cc.p( size.width / 2 * frameSize.width / visibleSize.width * retinaFactor, size.height / 2 * frameSize.height / visibleSize.height * retinaFactor)
local function initBuffers()
local w = 256
local h = 256
local x = size.width / 2 - w / 2
local y = size.height / 2 -h / 2
local vertices ={ x,y, x+w,y, x+w,y+h, x,y, x,y+h, x+w,y+h }
local vbo = gl.createBuffer()
gl.bindBuffer(gl.ARRAY_BUFFER, vbo)
gl.bufferData(gl.ARRAY_BUFFER, table.getn(vertices), vertices, gl.STATIC_DRAW)
gl.bindBuffer(gl.ARRAY_BUFFER, 0)
return vbo
end
local vbo = initBuffers()
local function update(fTime)
time = time + fTime
end
local function majoriDraw(transform, transformUpdated)
local w = 256
local h = 256
local function draw(transform, transformUpdated)
glProgram:use()
glProgram:setUniformsForBuiltins()
local vertices ={ 0,0, w,0, w,h, 0,0, 0,h, w,h }
local glProgramState = glNode:getGLProgramState()
glProgramState:setVertexAttribPointer("a_position", 2, gl.FLOAT, false, 0, vertices, #vertices)
glProgramState:apply(transform)
local uniformCenter = gl.getUniformLocation(glProgram:getProgram(), "center")
glProgram:setUniformLocationF32(uniformCenter, center.x, center.y)
local uniformResolution = gl.getUniformLocation(glProgram:getProgram(), "resolution")
glProgram:setUniformLocationF32(uniformResolution, resolution.x, resolution.y)
gl.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POSITION)
gl.bindBuffer(gl.ARRAY_BUFFER, vbo)
gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLES, 0, 6)
gl.bindBuffer(gl.ARRAY_BUFFER, 0)
end
majorLayer:scheduleUpdateWithPriorityLua(updateMajori,0)
glNode:registerScriptDrawHandler(majoriDraw)
shaderNodeLayer:scheduleUpdateWithPriorityLua(update,0)
glNode:registerScriptDrawHandler(draw)
time = 0
majorLayer:addChild(glNode,-10)
shaderNodeLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return majorLayer
local function onNodeEvent(event)
if "exit" == event then
glProgram:release()
end
end
shaderNodeLayer:registerScriptHandler(onNodeEvent)
return shaderNodeLayer
end
local function createShaderMajoriTest()
local vSource = vertDefaultSource
local fSource = cc.FileUtils:getInstance():getStringFromFile("Shaders/example_Monjori.fsh")
return createShaderNodeLayer(vSource, fSource)
end
local function createShaderMandelbrotTest()
local mandelbrotLayer = cc.Layer:create()
InitTitle(mandelbrotLayer)
local fileUtiles = cc.FileUtils:getInstance()
local vertSource = vertDefaultSource
local fragSource = fileUtiles:getStringFromFile("Shaders/example_Mandelbrot.fsh")
local glProgam = cc.GLProgram:createWithByteArrays(vertSource, fragSource)
local glprogramstate = cc.GLProgramState:getOrCreateWithGLProgram(glProgam)
local resolution = cc.p(256, 256)
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(256, 256))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:setGLProgramState(glprogramstate)
glNode:getGLProgramState():setUniformVec2("resolution", resolution)
local function updateMandelbrot(fTime)
time = time + fTime
end
local function mandelbrotDraw(transform, transformUpdated)
local w = 256
local h = 256
local vertices ={ 0,0, w,0, w,h, 0,0, 0,h, w,h }
local glProgramState = glNode:getGLProgramState()
glProgramState:setVertexAttribPointer("a_position", 2, gl.FLOAT, false, 0, vertices, #vertices)
glProgramState:apply(transform)
gl.drawArrays(gl.TRIANGLES, 0, 6)
end
mandelbrotLayer:scheduleUpdateWithPriorityLua(updateMandelbrot,0)
glNode:registerScriptDrawHandler(mandelbrotDraw)
time = 0
mandelbrotLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return mandelbrotLayer
local vSource = vertDefaultSource
local fSource = cc.FileUtils:getInstance():getStringFromFile("Shaders/example_Mandelbrot.fsh")
return createShaderNodeLayer(vSource, fSource)
end
local function createShaderHeartTest()
local heartLayer = cc.Layer:create()
InitTitle(heartLayer)
local fileUtiles = cc.FileUtils:getInstance()
local vertSource = vertDefaultSource
local fragSource = fileUtiles:getStringFromFile("Shaders/example_Heart.fsh")
local glProgam = cc.GLProgram:createWithByteArrays(vertSource, fragSource)
local glprogramstate = cc.GLProgramState:getOrCreateWithGLProgram(glProgam)
local resolution = cc.p(256, 256)
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(256, 256))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:setGLProgramState(glprogramstate)
glNode:getGLProgramState():setUniformVec2("resolution", resolution)
local function updateHeart(fTime)
time = time + fTime
end
local function heartDraw(transform, transformUpdated)
local w = 256
local h = 256
local vertices ={ 0,0, w,0, w,h, 0,0, 0,h, w,h }
local glProgramState = glNode:getGLProgramState()
glProgramState:setVertexAttribPointer("a_position", 2, gl.FLOAT, false, 0, vertices, #vertices)
glProgramState:apply(transform)
gl.drawArrays(gl.TRIANGLES, 0, 6)
end
heartLayer:scheduleUpdateWithPriorityLua(updateHeart,0)
glNode:registerScriptDrawHandler(heartDraw)
time = 0
heartLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return heartLayer
local vSource = vertDefaultSource
local fSource = cc.FileUtils:getInstance():getStringFromFile("Shaders/example_Heart.fsh")
return createShaderNodeLayer(vSource, fSource)
end
local function createShaderPlasmaTest()
local plasmaLayer = cc.Layer:create()
InitTitle(plasmaLayer)
local fileUtiles = cc.FileUtils:getInstance()
local vertSource = vertDefaultSource
local fragSource = fileUtiles:getStringFromFile("Shaders/example_Plasma.fsh")
local glProgam = cc.GLProgram:createWithByteArrays(vertSource, fragSource)
local glprogramstate = cc.GLProgramState:getOrCreateWithGLProgram(glProgam)
local resolution = cc.p(256, 256)
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(256, 256))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:setGLProgramState(glprogramstate)
glNode:getGLProgramState():setUniformVec2("resolution", resolution)
local function updatePlasma(fTime)
time = time + fTime
end
local function plasmaDraw(transform, transformUpdated)
local w = 256
local h = 256
local vertices ={ 0,0, w,0, w,h, 0,0, 0,h, w,h }
local glProgramState = glNode:getGLProgramState()
glProgramState:setVertexAttribPointer("a_position", 2, gl.FLOAT, false, 0, vertices, #vertices)
glProgramState:apply(transform)
gl.drawArrays(gl.TRIANGLES, 0, 6)
end
plasmaLayer:scheduleUpdateWithPriorityLua(updatePlasma,0)
glNode:registerScriptDrawHandler(plasmaDraw)
time = 0
plasmaLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return plasmaLayer
local vSource = vertDefaultSource
local fSource = cc.FileUtils:getInstance():getStringFromFile("Shaders/example_Plasma.fsh")
return createShaderNodeLayer(vSource, fSource)
end
local function createShaderFlowerTest()
local flowerLayer = cc.Layer:create()
InitTitle(flowerLayer)
local fileUtiles = cc.FileUtils:getInstance()
local vertSource = vertDefaultSource
local fragSource = fileUtiles:getStringFromFile("Shaders/example_Flower.fsh")
local glProgam = cc.GLProgram:createWithByteArrays(vertSource, fragSource)
local glprogramstate = cc.GLProgramState:getOrCreateWithGLProgram(glProgam)
local resolution = cc.p(256, 256)
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(256, 256))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:setGLProgramState(glprogramstate)
glNode:getGLProgramState():setUniformVec2("resolution", resolution)
local function updateFlower(fTime)
time = time + fTime
end
local function flowerDraw(transform, transformUpdated)
local w = 256
local h = 256
local vertices ={ 0,0, w,0, w,h, 0,0, 0,h, w,h }
local glProgramState = glNode:getGLProgramState()
glProgramState:setVertexAttribPointer("a_position", 2, gl.FLOAT, false, 0, vertices, #vertices)
glProgramState:apply(transform)
gl.drawArrays(gl.TRIANGLES, 0, 6)
end
flowerLayer:scheduleUpdateWithPriorityLua(updateFlower,0)
glNode:registerScriptDrawHandler(flowerDraw)
time = 0
flowerLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return flowerLayer
local vSource = vertDefaultSource
local fSource = cc.FileUtils:getInstance():getStringFromFile("Shaders/example_Flower.fsh")
return createShaderNodeLayer(vSource, fSource)
end
local function createShaderJuliaTest()
local juliaLayer = cc.Layer:create()
InitTitle(juliaLayer)
local fileUtiles = cc.FileUtils:getInstance()
local vertSource = vertDefaultSource
local fragSource = fileUtiles:getStringFromFile("Shaders/example_Julia.fsh")
local glProgam = cc.GLProgram:createWithByteArrays(vertSource, fragSource)
local glprogramstate = cc.GLProgramState:getOrCreateWithGLProgram(glProgam)
local resolution = cc.p(256, 256)
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(256, 256))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:setGLProgramState(glprogramstate)
glNode:getGLProgramState():setUniformVec2("resolution", resolution)
local function updateJulia(fTime)
time = time + fTime
end
local function juliaDraw(transform, transformUpdated)
local w = 256
local h = 256
local vertices ={ 0,0, w,0, w,h, 0,0, 0,h, w,h }
local glProgramState = glNode:getGLProgramState()
glProgramState:setVertexAttribPointer("a_position", 2, gl.FLOAT, false, 0, vertices, #vertices)
glProgramState:apply(transform)
gl.drawArrays(gl.TRIANGLES, 0, 6)
end
juliaLayer:scheduleUpdateWithPriorityLua(updateJulia,0)
glNode:registerScriptDrawHandler(juliaDraw)
time = 0
juliaLayer:addChild(glNode,-10)
glNode:setPosition( size.width/2, size.height/2)
local center = cc.p( size.width / 2 * scaleFactor, size.height / 2 * scaleFactor)
glNode:getGLProgramState():setUniformVec2("center", center)
return juliaLayer
local vSource = vertDefaultSource
local fSource = cc.FileUtils:getInstance():getStringFromFile("Shaders/example_Julia.fsh")
return createShaderNodeLayer(vSource, fSource)
end
local function createGLGetActiveTest()
@ -466,9 +309,9 @@ local function OpenGLTestMainLayer()
local function getCurrentResult()
local var = {}
local glProgam = sprite:getGLProgram()
if nil ~= glProgam then
local p = glProgam:getProgram()
local glProgram = sprite:getGLProgram()
if nil ~= glProgram then
local p = glProgram:getProgram()
local aaSize,aaType,aaName = gl.getActiveAttrib(p,0)
local strFmt = "size:"..aaSize.." type:"..aaType.." name:"..aaName
print(strFmt)