Skip to content

Instantly share code, notes, and snippets.

@t-takasaka
Last active August 29, 2015 14:06
Show Gist options
  • Save t-takasaka/4845ac03cdfc87ecb121 to your computer and use it in GitHub Desktop.
Save t-takasaka/4845ac03cdfc87ecb121 to your computer and use it in GitHub Desktop.
#include "HelloWorldScene.h"
USING_NS_CC;
Scene* HelloWorld::createScene(){
auto scene = Scene::create();
auto layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init(){
if ( !Layer::init()){ return false; }
Size visibleSize = Director::getInstance()->getVisibleSize();
//スプライトを作成
auto sprite1 = Sprite::create("HelloWorld512.png");
auto textureSize = sprite1->getTexture()->getContentSizeInPixels();
sprite1->setPosition(visibleSize.width / 2.0f, visibleSize.height / 2.0f);
sprite1->setScale(2.0);
//シェーダをスプライトに紐付け
GLProgram *shader1 = new GLProgram();
sprite1->setShaderProgram(shader1);
shader1->initWithFilenames("shaders/tegra_check.vsh", "shaders/tegra_check.fsh");
shader1->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
shader1->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
shader1->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
shader1->link();
shader1->updateUniforms();
shader1->setUniformLocationWith1f(shader1->getUniformLocationForName("u_loop"), 10);
float u_array[3] = { 1.0, 2.0, 3.0 };
glUniform1fv(shader1->getUniformLocationForName("u_array"), sizeof(u_array), (GLfloat*)u_array);
shader1->setUniformLocationWith1i(shader1->getUniformLocationForName("u_index"), 2);
addChild(sprite1);
return true;
}
void HelloWorld::menuCloseCallback(Ref* pSender){
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
return;
#endif
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texCoord;
varying lowp vec4 v_color;
uniform sampler2D u_texture;
uniform int u_loop;
uniform float u_array[3];
uniform int u_index;
//検証に使った端末
//Nexus7(2012) Android4.2.2 Tegra 3
//ArrowsZ ISW13F Android4.0.3 Tegra 3
//Optimus X IS11LG Android4.0.4 Tegra 250
//MOTOROLA PHOTON ISW11M Android2.3.4 Tegra 250
//AQUOS PHONE CL IS17SH Android4.0.4 Adreno 205
//MEDIAS BR IS11N Android2.3.5 Adreno 205
//ArrowsZ ISW11F Android2.3.5 PowerVR SGX540
//GalaxySII ISW11SC Android2.3.6 ARM Mali-400MP4
//GALAPAGOS EB-W51GJ Android2.3.3 Z430
void main(){
//////////////////////////////////////////////////////////
float array[3];
array[0] = 1.0;
array[1] = 2.0;
array[2] = 3.0;
//全端末でOK
gl_FragColor = texture2D(u_texture, v_texCoord) / 3.0;
//全端末でOK
// gl_FragColor = texture2D(u_texture, v_texCoord) / array[2];
//全端末でOK
// gl_FragColor = texture2D(u_texture, v_texCoord) / u_array[2];
//IS17SH:初期化中に固まる
//Nexus7、ISW13F、IS11LG、ISW11M、IS11N、EB-W51GJ:シェーダの処理が反映されない
//ISW11F:0.0扱い
// gl_FragColor = texture2D(u_texture, v_texCoord) / array[u_index];
//IS17SH、IS11N、EB-W51GJ:0.0扱い
//Nexus7、ISW13F、IS11LG、ISW11M:シェーダの処理が反映されない
//※なぜかISW11Fはちゃんと動く
// gl_FragColor = texture2D(u_texture, v_texCoord) / u_array[u_index];
//////////////////////////////////////////////////////////
float tmp = 3.0;
int dummy_loop = 20;
//全端末でOK
// for(int i = 0; i < 10; i++){ tmp *= 1.0; }
//Nexus7、ISW13F、IS11LG、ISW11M:シェーダの処理が反映されない
// for(int i = 0; i < u_loop; i++){ tmp *= 1.0; }
//全端末でOK
// for(int i = 0; i < dummy_loop; i++){
// if(u_loop > i){ tmp *= 1.0; }
// }
//全端末でOK
// for(int i = 0; i < dummy_loop; i++){
// if(u_loop == i){ break; }
// tmp *= 1.0;
// }
//Nexus7、ISW13F、IS11LG、ISW11M:シェーダの処理が反映されない
// for(int i = -u_loop; i < 0; i++){ tmp *= 1.0; }
//全端末でOK
// for(int i = -dummy_loop; i < 0; i++){
// if(-u_loop <= i){ tmp *= 1.0; }
// }
// gl_FragColor = texture2D(u_texture, v_texCoord) / tmp;
}
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
varying vec2 v_texCoord;
varying vec4 v_color;
void main() {
gl_Position = CC_PMatrix * a_position;
v_color = a_color;
v_texCoord = a_texCoord;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment