Merge pull request #6722 from ricardoquesada/multitexturing_fixes

Adds simple sample for multitexturing
This commit is contained in:
Ricardo Quesada 2014-05-13 14:09:47 -07:00
commit 0866c0121d
24 changed files with 102 additions and 58 deletions

View File

@ -71,7 +71,6 @@ void UniformValue::apply()
switch (_uniform->type) {
case GL_SAMPLER_2D:
_glprogram->setUniformLocationWith1i(_uniform->location, _value.tex.textureUnit);
GL::activeTexture(_value.tex.textureUnit);
GL::bindTexture2DN(_value.tex.textureUnit, _value.tex.textureId);
break;

View File

@ -4,23 +4,23 @@
static int sceneIdx = -1;
#define MAX_LAYER 10
#define MAX_LAYER 11
static Layer* createShaderLayer(int nIndex)
{
switch (sceneIdx)
{
case 0: return new ShaderLensFlare();
case 1: return new ShaderMandelbrot();
case 2: return new ShaderJulia();
case 3: return new ShaderHeart();
case 4: return new ShaderFlower();
case 5: return new ShaderPlasma();
case 6: return new ShaderBlur();
case 7: return new ShaderRetroEffect();
case 8: return new ShaderMonjori();
//case 9: return new ShaderFireBall();
case 9: return new ShaderGlow();
case 0: return new ShaderLensFlare();
case 1: return new ShaderMandelbrot();
case 2: return new ShaderJulia();
case 3: return new ShaderHeart();
case 4: return new ShaderFlower();
case 5: return new ShaderPlasma();
case 6: return new ShaderBlur();
case 7: return new ShaderRetroEffect();
case 8: return new ShaderMonjori();
case 9: return new ShaderGlow();
case 10: return new ShaderMultiTexture();
}
return NULL;
}
@ -694,39 +694,9 @@ bool ShaderLensFlare::init()
return false;
}
ShaderFireBall::ShaderFireBall()
{
init();
}
std::string ShaderFireBall::title() const
{
return "ShaderToy Test";
}
std::string ShaderFireBall::subtitle() const
{
return "Fire Ball";
}
bool ShaderFireBall::init()
{
if (ShaderTestDemo::init())
{
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/shadertoy_FireBall.fsh");
auto s = Director::getInstance()->getWinSize();
sn->setPosition(Vector2(s.width/2, s.height/2));
sn->setContentSize(Size(s.width/2,s.height/2));
addChild(sn);
return true;
}
return false;
}
//
// ShaderGlow
//
ShaderGlow::ShaderGlow()
{
init();
@ -759,6 +729,48 @@ bool ShaderGlow::init()
return false;
}
//
// ShaderMultiTexture
//
ShaderMultiTexture::ShaderMultiTexture()
{
init();
}
std::string ShaderMultiTexture::title() const
{
return "MultiTexture test";
}
std::string ShaderMultiTexture::subtitle() const
{
return "MultiTexture";
}
bool ShaderMultiTexture::init()
{
if (ShaderTestDemo::init())
{
auto s = Director::getInstance()->getWinSize();
auto sprite = Sprite::create("Images/grossinis_sister1.png");
Texture2D *texture1 = Director::getInstance()->getTextureCache()->addImage("Images/grossinis_sister2.png");
addChild(sprite);
sprite->setPosition(Vector2(s.width/2, s.height/2));
auto glprogram = GLProgram::createWithFilenames("Shaders/example_MultiTexture.vsh", "Shaders/example_MultiTexture.fsh");
auto glprogramstate = GLProgramState::getOrCreate(glprogram);
sprite->setGLProgramState(glprogramstate);
glprogramstate->setUniformTexture("u_texture1", texture1);
return true;
}
return false;
}
///---------------------------------------
//

View File

@ -152,16 +152,6 @@ public:
virtual bool init();
};
class ShaderFireBall : public ShaderTestDemo
{
public:
ShaderFireBall();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init();
};
class ShaderGlow : public ShaderTestDemo
{
public:
@ -172,8 +162,14 @@ public:
virtual bool init();
};
class ShaderMultiTexture : public ShaderTestDemo
{
public:
ShaderMultiTexture();
//CCLayer* nextAction();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init();
};
#endif

0
tests/cpp-tests/Resources/Shaders/example_Blur.fsh Executable file → Normal file
View File

View File

View File

0
tests/cpp-tests/Resources/Shaders/example_Flower.fsh Executable file → Normal file
View File

0
tests/cpp-tests/Resources/Shaders/example_Heart.fsh Executable file → Normal file
View File

View File

0
tests/cpp-tests/Resources/Shaders/example_Julia.fsh Executable file → Normal file
View File

View File

0
tests/cpp-tests/Resources/Shaders/example_Monjori.fsh Executable file → Normal file
View File

View File

@ -0,0 +1,18 @@
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform sampler2D CC_Texture0;
uniform sampler2D u_texture1;
void main() {
vec4 color1 = texture2D(CC_Texture0, v_texCoord) * vec4(1,1,1,CC_SinTime[3]);
vec4 color2 = texture2D(u_texture1, v_texCoord) * vec4(1,1,1,CC_CosTime[3]);
gl_FragColor = (color1 + color2) * v_fragmentColor;
}

View File

@ -0,0 +1,19 @@
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif
void main()
{
gl_Position = CC_PMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}

0
tests/cpp-tests/Resources/Shaders/example_Noisy.fsh Executable file → Normal file
View File

0
tests/cpp-tests/Resources/Shaders/example_Plasma.fsh Executable file → Normal file
View File

0
tests/cpp-tests/Resources/Shaders/example_Twist.fsh Executable file → Normal file
View File

0
tests/cpp-tests/Resources/Shaders/example_bloom.fsh Executable file → Normal file
View File

View File

View File

View File

View File

0
tests/cpp-tests/Resources/Shaders/example_normal.fsh Executable file → Normal file
View File

0
tests/cpp-tests/Resources/Shaders/example_outline.fsh Executable file → Normal file
View File