Merge pull request #11810 from ricardoquesada/api_fixes

More material samples
This commit is contained in:
Ricardo Quesada 2015-05-12 23:03:40 -07:00
commit f23b15c6d3
6 changed files with 135 additions and 55 deletions

View File

@ -361,7 +361,7 @@ void Mesh::draw(Renderer* renderer, float globalZOrder, const Mat4& transform, u
programState->setUniformVec4("u_color", color);
if (_skin)
programState->setUniformVec4v("u_matrixPalette", _skin->getMatrixPalette(), (GLsizei)_skin->getMatrixPaletteSize());
programState->setUniformVec4v("u_matrixPalette", (GLsizei)_skin->getMatrixPaletteSize(), _skin->getMatrixPalette());
if (scene && scene->getLights().size() > 0)
setLightUniforms(pass, scene, color, lightMask);
@ -564,25 +564,25 @@ void Mesh::setLightUniforms(Pass* pass, Scene* scene, const Vec4& color, unsigne
if (0 < maxDirLight)
{
glProgramState->setUniformVec3v(s_dirLightUniformColorName, &s_dirLightUniformColorValues[0], s_dirLightUniformColorValues.size());
glProgramState->setUniformVec3v(s_dirLightUniformDirName, &s_dirLightUniformDirValues[0], s_dirLightUniformDirValues.size());
glProgramState->setUniformVec3v(s_dirLightUniformColorName, s_dirLightUniformColorValues.size(), &s_dirLightUniformColorValues[0]);
glProgramState->setUniformVec3v(s_dirLightUniformDirName, s_dirLightUniformDirValues.size(), &s_dirLightUniformDirValues[0]);
}
if (0 < maxPointLight)
{
glProgramState->setUniformVec3v(s_pointLightUniformColorName, &s_pointLightUniformColorValues[0], s_pointLightUniformColorValues.size());
glProgramState->setUniformVec3v(s_pointLightUniformPositionName, &s_pointLightUniformPositionValues[0], s_pointLightUniformPositionValues.size());
glProgramState->setUniformFloatv(s_pointLightUniformRangeInverseName, &s_pointLightUniformRangeInverseValues[0], s_pointLightUniformRangeInverseValues.size());
glProgramState->setUniformVec3v(s_pointLightUniformColorName, s_pointLightUniformColorValues.size(), &s_pointLightUniformColorValues[0]);
glProgramState->setUniformVec3v(s_pointLightUniformPositionName, s_pointLightUniformPositionValues.size(), &s_pointLightUniformPositionValues[0]);
glProgramState->setUniformFloatv(s_pointLightUniformRangeInverseName, s_pointLightUniformRangeInverseValues.size(), &s_pointLightUniformRangeInverseValues[0]);
}
if (0 < maxSpotLight)
{
glProgramState->setUniformVec3v(s_spotLightUniformColorName, &s_spotLightUniformColorValues[0], s_spotLightUniformColorValues.size());
glProgramState->setUniformVec3v(s_spotLightUniformPositionName, &s_spotLightUniformPositionValues[0], s_spotLightUniformPositionValues.size());
glProgramState->setUniformVec3v(s_spotLightUniformDirName, &s_spotLightUniformDirValues[0], s_spotLightUniformDirValues.size());
glProgramState->setUniformFloatv(s_spotLightUniformInnerAngleCosName, &s_spotLightUniformInnerAngleCosValues[0], s_spotLightUniformInnerAngleCosValues.size());
glProgramState->setUniformFloatv(s_spotLightUniformOuterAngleCosName, &s_spotLightUniformOuterAngleCosValues[0], s_spotLightUniformOuterAngleCosValues.size());
glProgramState->setUniformFloatv(s_spotLightUniformRangeInverseName, &s_spotLightUniformRangeInverseValues[0], s_spotLightUniformRangeInverseValues.size());
glProgramState->setUniformVec3v(s_spotLightUniformColorName, s_spotLightUniformColorValues.size(), &s_spotLightUniformColorValues[0]);
glProgramState->setUniformVec3v(s_spotLightUniformPositionName, s_spotLightUniformPositionValues.size(), &s_spotLightUniformPositionValues[0]);
glProgramState->setUniformVec3v(s_spotLightUniformDirName, s_spotLightUniformDirValues.size(), &s_spotLightUniformDirValues[0]);
glProgramState->setUniformFloatv(s_spotLightUniformInnerAngleCosName, s_spotLightUniformInnerAngleCosValues.size(), &s_spotLightUniformInnerAngleCosValues[0]);
glProgramState->setUniformFloatv(s_spotLightUniformOuterAngleCosName, s_spotLightUniformOuterAngleCosValues.size(), &s_spotLightUniformOuterAngleCosValues[0]);
glProgramState->setUniformFloatv(s_spotLightUniformRangeInverseName, s_spotLightUniformRangeInverseValues.size(), &s_spotLightUniformRangeInverseValues[0]);
}
glProgramState->setUniformVec3(s_ambientLightUniformColorName, Vec3(ambientColor.x, ambientColor.y, ambientColor.z));

View File

@ -177,7 +177,7 @@ void UniformValue::setFloat(float value)
_type = Type::VALUE;
}
void UniformValue::setFloatv(const float* pointer, ssize_t size)
void UniformValue::setFloatv(ssize_t size, const float* pointer)
{
CCASSERT(_uniform->type == GL_FLOAT, "Wrong type: expecting GL_FLOAT");
_value.floatv.pointer = (const float*)pointer;
@ -192,7 +192,7 @@ void UniformValue::setVec2(const Vec2& value)
_type = Type::VALUE;
}
void UniformValue::setVec2v(const Vec2* pointer, ssize_t size)
void UniformValue::setVec2v(ssize_t size, const Vec2* pointer)
{
CCASSERT(_uniform->type == GL_FLOAT_VEC2, "Wrong type: expecting GL_FLOAT_VEC2");
_value.v2f.pointer = (const float*)pointer;
@ -208,7 +208,7 @@ void UniformValue::setVec3(const Vec3& value)
}
void UniformValue::setVec3v(const Vec3* pointer, ssize_t size)
void UniformValue::setVec3v(ssize_t size, const Vec3* pointer)
{
CCASSERT(_uniform->type == GL_FLOAT_VEC3, "Wrong type: expecting GL_FLOAT_VEC3");
_value.v3f.pointer = (const float*)pointer;
@ -224,7 +224,7 @@ void UniformValue::setVec4(const Vec4& value)
_type = Type::VALUE;
}
void UniformValue::setVec4v(const Vec4* pointer, ssize_t size)
void UniformValue::setVec4v(ssize_t size, const Vec4* pointer)
{
CCASSERT (_uniform->type == GL_FLOAT_VEC4, "Wrong type: expecting GL_FLOAT_VEC4");
_value.v4f.pointer = (const float*)pointer;
@ -632,20 +632,20 @@ void GLProgramState::setUniformInt(GLint uniformLocation, int value)
}
void GLProgramState::setUniformFloatv(const std::string &uniformName, const float* pointer, ssize_t size)
void GLProgramState::setUniformFloatv(const std::string &uniformName, ssize_t size, const float* pointer)
{
auto v = getUniformValue(uniformName);
if (v)
v->setFloatv(pointer, size);
v->setFloatv(size, pointer);
else
CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
}
void GLProgramState::setUniformFloatv(GLint uniformLocation, const float* pointer, ssize_t size)
void GLProgramState::setUniformFloatv(GLint uniformLocation, ssize_t size, const float* pointer)
{
auto v = getUniformValue(uniformLocation);
if (v)
v->setFloatv(pointer, size);
v->setFloatv(size, pointer);
else
CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
@ -668,20 +668,20 @@ void GLProgramState::setUniformVec2(GLint uniformLocation, const Vec2& value)
CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
void GLProgramState::setUniformVec2v(const std::string &uniformName, const Vec2* pointer, ssize_t size)
void GLProgramState::setUniformVec2v(const std::string &uniformName, ssize_t size, const Vec2* pointer)
{
auto v = getUniformValue(uniformName);
if (v)
v->setVec2v(pointer, size);
v->setVec2v(size, pointer);
else
CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
}
void GLProgramState::setUniformVec2v(GLint uniformLocation, const Vec2* pointer, ssize_t size)
void GLProgramState::setUniformVec2v(GLint uniformLocation, ssize_t size, const Vec2* pointer)
{
auto v = getUniformValue(uniformLocation);
if (v)
v->setVec2v(pointer, size);
v->setVec2v(size, pointer);
else
CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
@ -704,20 +704,20 @@ void GLProgramState::setUniformVec3(GLint uniformLocation, const Vec3& value)
CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
void GLProgramState::setUniformVec3v(const std::string &uniformName, const Vec3* pointer, ssize_t size)
void GLProgramState::setUniformVec3v(const std::string &uniformName, ssize_t size, const Vec3* pointer)
{
auto v = getUniformValue(uniformName);
if (v)
v->setVec3v(pointer, size);
v->setVec3v(size, pointer);
else
CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
}
void GLProgramState::setUniformVec3v(GLint uniformLocation, const Vec3* pointer, ssize_t size)
void GLProgramState::setUniformVec3v(GLint uniformLocation, ssize_t size, const Vec3* pointer)
{
auto v = getUniformValue(uniformLocation);
if (v)
v->setVec3v(pointer, size);
v->setVec3v(size, pointer);
else
CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
@ -740,20 +740,20 @@ void GLProgramState::setUniformVec4(GLint uniformLocation, const Vec4& value)
CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}
void GLProgramState::setUniformVec4v(const std::string &uniformName, const Vec4* value, ssize_t size)
void GLProgramState::setUniformVec4v(const std::string &uniformName, ssize_t size, const Vec4* value)
{
auto v = getUniformValue(uniformName);
if (v)
v->setVec4v(value, size);
v->setVec4v(size, value);
else
CCLOG("cocos2d: warning: Uniform not found: %s", uniformName.c_str());
}
void GLProgramState::setUniformVec4v(GLint uniformLocation, const Vec4* value, ssize_t size)
void GLProgramState::setUniformVec4v(GLint uniformLocation, ssize_t size, const Vec4* pointer)
{
auto v = getUniformValue(uniformLocation);
if (v)
v->setVec4v(value, size);
v->setVec4v(size, pointer);
else
CCLOG("cocos2d: warning: Uniform at location not found: %i", uniformLocation);
}

View File

@ -77,13 +77,13 @@ public:
*/
void setFloat(float value);
void setInt(int value);
void setFloatv(const float* pointer, ssize_t size);
void setFloatv(ssize_t size, const float* pointer);
void setVec2(const Vec2& value);
void setVec2v(const Vec2* pointer, ssize_t size);
void setVec2v(ssize_t size, const Vec2* pointer);
void setVec3(const Vec3& value);
void setVec3v(const Vec3* pointer, ssize_t size);
void setVec3v(ssize_t size, const Vec3* pointer);
void setVec4(const Vec4& value);
void setVec4v(const Vec4* pointer, ssize_t size);
void setVec4v(ssize_t size, const Vec4* pointer);
void setMat4(const Mat4& value);
/**
@}
@ -301,13 +301,13 @@ public:
*/
void setUniformInt(const std::string &uniformName, int value);
void setUniformFloat(const std::string &uniformName, float value);
void setUniformFloatv(const std::string &uniformName, const float* pointer, ssize_t size);
void setUniformFloatv(const std::string &uniformName, ssize_t size, const float* pointer);
void setUniformVec2(const std::string &uniformName, const Vec2& value);
void setUniformVec2v(const std::string &uniformName, const Vec2* pointer, ssize_t size);
void setUniformVec2v(const std::string &uniformName, ssize_t size, const Vec2* pointer);
void setUniformVec3(const std::string &uniformName, const Vec3& value);
void setUniformVec3v(const std::string &uniformName, const Vec3* pointer, ssize_t size);
void setUniformVec3v(const std::string &uniformName, ssize_t size, const Vec3* pointer);
void setUniformVec4(const std::string &uniformName, const Vec4& value);
void setUniformVec4v(const std::string &uniformName, const Vec4* pointer, ssize_t size);
void setUniformVec4v(const std::string &uniformName, ssize_t size, const Vec4* pointer);
void setUniformMat4(const std::string &uniformName, const Mat4& value);
void setUniformCallback(const std::string &uniformName, const std::function<void(GLProgram*, Uniform*)> &callback);
void setUniformTexture(const std::string &uniformName, Texture2D *texture);
@ -319,13 +319,13 @@ public:
*/
void setUniformInt(GLint uniformLocation, int value);
void setUniformFloat(GLint uniformLocation, float value);
void setUniformFloatv(GLint uniformLocation, const float* pointer, ssize_t size);
void setUniformFloatv(GLint uniformLocation, ssize_t size, const float* pointer);
void setUniformVec2(GLint uniformLocation, const Vec2& value);
void setUniformVec2v(GLint uniformLocation, const Vec2* pointer, ssize_t size);
void setUniformVec2v(GLint uniformLocation, ssize_t size, const Vec2* pointer);
void setUniformVec3(GLint uniformLocation, const Vec3& value);
void setUniformVec3v(GLint uniformLocation, const Vec3* pointer, ssize_t size);
void setUniformVec3v(GLint uniformLocation, ssize_t size, const Vec3* pointer);
void setUniformVec4(GLint uniformLocation, const Vec4& value);
void setUniformVec4v(GLint uniformLocation, const Vec4* pointer, ssize_t size);
void setUniformVec4v(GLint uniformLocation, ssize_t size, const Vec4* pointer);
void setUniformMat4(GLint uniformLocation, const Mat4& value);
void setUniformCallback(GLint uniformLocation, const std::function<void(GLProgram*, Uniform*)> &callback);
void setUniformTexture(GLint uniformLocation, Texture2D *texture);

View File

@ -220,12 +220,15 @@ void Material_3DEffects::changeMaterial(float dt)
case 1:
_sprite->getMaterial(0)->setTechnique("unlit");
break;
case 2:
_sprite->getMaterial(0)->setTechnique("outline");
break;
default:
break;
}
_techniqueState++;
if (_techniqueState>1)
if (_techniqueState>2)
_techniqueState = 0;
}

View File

@ -1023,11 +1023,6 @@ void Effect3DOutline::setTarget(EffectSprite3D *sprite)
}
static void MatrixPalleteCallBack( GLProgram* glProgram, Uniform* uniform, int paletteSize, const float* palette)
{
glUniform4fv( uniform->location, (GLsizei)paletteSize, (const float*)palette );
}
void Effect3DOutline::draw(const Mat4 &transform)
{
//draw
@ -1046,9 +1041,7 @@ void Effect3DOutline::draw(const Mat4 &transform)
auto skin = _sprite->getMesh()->getSkin();
if(_sprite && skin)
{
auto function = std::bind(MatrixPalleteCallBack, std::placeholders::_1, std::placeholders::_2,
skin->getMatrixPaletteSize(), (float*)skin->getMatrixPalette());
_glProgramState->setUniformCallback("u_matrixPalette", function);
_glProgramState->setUniformVec4v("u_matrixPalette", skin->getMatrixPaletteSize(), skin->getMatrixPalette());
}
if(_sprite)
@ -1132,7 +1125,6 @@ void Sprite3DEffectTest::addNewSpriteWithCoords(Vec2 p)
sprite->addEffect(effect2, -2);
effect2->setOutlineWidth(0.02f);
effect2->setOutlineColor(Vec3(1,1,0));
//sprite->setEffect3D(effect);
sprite->setScale(6.f);
//add to scene

View File

@ -12,7 +12,6 @@ material spaceship
}
shader
{
defines = THIS_IS_AN_EXAMPLE 1;TOMORROW_IS_HOLIDAY 2
vertexShader = Shaders3D/3d_position_tex.vert
fragmentShader = Shaders3D/3d_color_tex.frag
}
@ -55,4 +54,90 @@ material spaceship
}
}
}
technique outline
{
pass outline thin
{
renderState
{
blend = true
blendSrc = ONE
blendDst = ONE_MINUS_SRC_ALPHA
cullFace = true
cullFaceSide = FRONT
depthTest = true
}
shader
{
vertexShader = Shaders3D/OutLine.vert
fragmentShader = Shaders3D/OutLine.frag
OutLineColor = 1,0,0
OutlineWidth = 0.01
}
sampler 0
{
path = Sprite3DTest/boss.png
wrapS = CLAMP_TO_EDGE
wrapT = CLAMP_TO_EDGE
minFilter = LINEAR
magFilter = LINEAR
mipmap = false
}
}
pass outline thick
{
renderState
{
blend = true
blendSrc = ONE
blendDst = ONE_MINUS_SRC_ALPHA
cullFace = true
cullFaceSide = FRONT
depthTest = true
}
shader
{
vertexShader = Shaders3D/OutLine.vert
fragmentShader = Shaders3D/OutLine.frag
OutLineColor = 0,0,1
OutlineWidth = 0.02
}
sampler 0
{
path = Sprite3DTest/boss.png
wrapS = CLAMP_TO_EDGE
wrapT = CLAMP_TO_EDGE
minFilter = LINEAR
magFilter = LINEAR
mipmap = false
}
}
pass 1
{
renderState
{
blend = true
blendSrc = ONE
blendDst = ONE_MINUS_SRC_ALPHA
}
shader
{
vertexShader = Shaders3D/3d_position_tex.vert
fragmentShader = Shaders3D/3d_color_tex.frag
}
sampler 0
{
path = Sprite3DTest/boss.png
wrapS = CLAMP_TO_EDGE
wrapT = CLAMP_TO_EDGE
minFilter = LINEAR
magFilter = LINEAR
mipmap = false
}
}
}
}