mirror of https://github.com/axmolengine/axmol.git
Merge pull request #261 from IPubby/texturecube_modify
Texturecube modify: add test case for lua project
This commit is contained in:
commit
4ea27173da
|
@ -78,8 +78,10 @@
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCPlane.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCPlane.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCRay.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCRay.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSkeleton3D.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSkeleton3D.h" />
|
||||||
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSkybox.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSprite3D.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSprite3D.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSprite3DMaterial.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSprite3DMaterial.h" />
|
||||||
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCTextureCube.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\cocos3d.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\cocos3d.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\include\AudioEngine.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\include\AudioEngine.h" />
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\include\Export.h" />
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\include\Export.h" />
|
||||||
|
@ -504,8 +506,10 @@
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCPlane.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCPlane.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCRay.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCRay.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSkeleton3D.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSkeleton3D.cpp" />
|
||||||
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSkybox.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSprite3D.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSprite3D.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSprite3DMaterial.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSprite3DMaterial.cpp" />
|
||||||
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCTextureCube.cpp" />
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\winrt\Audio.cpp">
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\audio\winrt\Audio.cpp">
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<ForcedIncludeFiles>
|
<ForcedIncludeFiles>
|
||||||
|
|
|
@ -1291,6 +1291,12 @@
|
||||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsHelper.h">
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsHelper.h">
|
||||||
<Filter>physics</Filter>
|
<Filter>physics</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSkybox.h">
|
||||||
|
<Filter>3d</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCTextureCube.h">
|
||||||
|
<Filter>3d</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\cocos2d.cpp" />
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\cocos2d.cpp" />
|
||||||
|
@ -2378,6 +2384,12 @@
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\allocator\CCAllocatorGlobalNewDelete.cpp">
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\allocator\CCAllocatorGlobalNewDelete.cpp">
|
||||||
<Filter>base\allocator</Filter>
|
<Filter>base\allocator</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCSkybox.cpp">
|
||||||
|
<Filter>3d</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCTextureCube.cpp">
|
||||||
|
<Filter>3d</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="2d">
|
<Filter Include="2d">
|
||||||
|
|
|
@ -56,27 +56,13 @@ Skybox::~Skybox()
|
||||||
bool Skybox::init()
|
bool Skybox::init()
|
||||||
{
|
{
|
||||||
// create and set our custom shader
|
// create and set our custom shader
|
||||||
auto shader = GLProgram::createWithFilenames("Sprite3DTest/skybox.vert", "Sprite3DTest/skybox.frag");
|
auto shader = GLProgram::createWithFilenames("Shaders3D/Skybox.vert", "Shaders3D/Skybox.frag");
|
||||||
auto state = GLProgramState::create(shader);
|
auto state = GLProgramState::create(shader);
|
||||||
state->setVertexAttribPointer(GLProgram::ATTRIBUTE_NAME_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vec3), nullptr);
|
state->setVertexAttribPointer(GLProgram::ATTRIBUTE_NAME_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vec3), nullptr);
|
||||||
setGLProgramState(state);
|
setGLProgramState(state);
|
||||||
|
|
||||||
if (Configuration::getInstance()->supportsShareableVAO())
|
|
||||||
{
|
|
||||||
glGenVertexArrays(1, &_vao);
|
|
||||||
GL::bindVAO(_vao);
|
|
||||||
}
|
|
||||||
|
|
||||||
initBuffers();
|
initBuffers();
|
||||||
|
|
||||||
if (Configuration::getInstance()->supportsShareableVAO())
|
|
||||||
{
|
|
||||||
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
|
|
||||||
state->applyAttributes(false);
|
|
||||||
|
|
||||||
GL::bindVAO(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -84,6 +70,12 @@ bool Skybox::init()
|
||||||
|
|
||||||
void Skybox::initBuffers()
|
void Skybox::initBuffers()
|
||||||
{
|
{
|
||||||
|
if (Configuration::getInstance()->supportsShareableVAO())
|
||||||
|
{
|
||||||
|
glGenVertexArrays(1, &_vao);
|
||||||
|
GL::bindVAO(_vao);
|
||||||
|
}
|
||||||
|
|
||||||
// init vertex buffer object
|
// init vertex buffer object
|
||||||
Vec3 vexBuf[] =
|
Vec3 vexBuf[] =
|
||||||
{
|
{
|
||||||
|
@ -96,7 +88,7 @@ void Skybox::initBuffers()
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vexBuf), vexBuf, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vexBuf), vexBuf, GL_STATIC_DRAW);
|
||||||
|
|
||||||
// init index buffer object
|
// init index buffer object
|
||||||
unsigned char idxBuf[] = { 2, 1, 0, 3, 2, 0, // font
|
const unsigned char idxBuf[] = { 2, 1, 0, 3, 2, 0, // font
|
||||||
1, 5, 4, 1, 4, 0, // right
|
1, 5, 4, 1, 4, 0, // right
|
||||||
4, 5, 6, 4, 6, 7, // back
|
4, 5, 6, 4, 6, 7, // back
|
||||||
7, 6, 2, 7, 2, 3, // left
|
7, 6, 2, 7, 2, 3, // left
|
||||||
|
@ -107,6 +99,14 @@ void Skybox::initBuffers()
|
||||||
glGenBuffers(1, &_indexBuffer);
|
glGenBuffers(1, &_indexBuffer);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idxBuf), idxBuf, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idxBuf), idxBuf, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
if (Configuration::getInstance()->supportsShareableVAO())
|
||||||
|
{
|
||||||
|
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
|
||||||
|
getGLProgramState()->applyAttributes(false);
|
||||||
|
|
||||||
|
GL::bindVAO(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skybox::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
void Skybox::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
||||||
|
@ -167,11 +167,25 @@ void Skybox::setTexture(TextureCube* texture)
|
||||||
{
|
{
|
||||||
CCASSERT(texture != nullptr, __FUNCTION__);
|
CCASSERT(texture != nullptr, __FUNCTION__);
|
||||||
|
|
||||||
_texture = texture;
|
texture->retain();
|
||||||
_texture->retain();
|
|
||||||
|
|
||||||
auto state = getGLProgramState();
|
if (_texture)
|
||||||
state->setUniformTexture("u_Env", _texture);
|
_texture->release();
|
||||||
|
|
||||||
|
_texture = texture;
|
||||||
|
|
||||||
|
getGLProgramState()->setUniformTexture("u_Env", _texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Skybox::reload()
|
||||||
|
{
|
||||||
|
auto glProgram = getGLProgramState()->getGLProgram();
|
||||||
|
glProgram->reset();
|
||||||
|
glProgram->initWithFilenames("Shaders3D/Skybox.vert", "Shaders3D/Skybox.frag");
|
||||||
|
glProgram->link();
|
||||||
|
glProgram->updateUniforms();
|
||||||
|
|
||||||
|
initBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -43,6 +43,8 @@ public:
|
||||||
// Overrides
|
// Overrides
|
||||||
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
|
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
|
||||||
|
|
||||||
|
void reload();
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
Skybox();
|
Skybox();
|
||||||
virtual ~Skybox();
|
virtual ~Skybox();
|
||||||
|
|
|
@ -146,6 +146,7 @@ Image* createImage(const std::string& path)
|
||||||
|
|
||||||
TextureCube::TextureCube()
|
TextureCube::TextureCube()
|
||||||
{
|
{
|
||||||
|
_imgPath.resize(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureCube::~TextureCube()
|
TextureCube::~TextureCube()
|
||||||
|
@ -170,6 +171,13 @@ bool TextureCube::init(const std::string& positive_x, const std::string& negativ
|
||||||
const std::string& positive_y, const std::string& negative_y,
|
const std::string& positive_y, const std::string& negative_y,
|
||||||
const std::string& positive_z, const std::string& negative_z)
|
const std::string& positive_z, const std::string& negative_z)
|
||||||
{
|
{
|
||||||
|
_imgPath[0] = positive_x;
|
||||||
|
_imgPath[1] = negative_x;
|
||||||
|
_imgPath[2] = positive_y;
|
||||||
|
_imgPath[3] = negative_y;
|
||||||
|
_imgPath[4] = positive_z;
|
||||||
|
_imgPath[5] = negative_z;
|
||||||
|
|
||||||
std::vector<Image*> images(6);
|
std::vector<Image*> images(6);
|
||||||
|
|
||||||
images[0] = createImage(positive_x);
|
images[0] = createImage(positive_x);
|
||||||
|
@ -247,4 +255,9 @@ void TextureCube::setTexParameters(const TexParams& texParams)
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TextureCube::reloadTexture()
|
||||||
|
{
|
||||||
|
return init(_imgPath[0], _imgPath[1], _imgPath[2], _imgPath[3], _imgPath[4], _imgPath[5]);
|
||||||
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -51,6 +51,8 @@ public:
|
||||||
const std::string& positive_z, const std::string& negative_z);
|
const std::string& positive_z, const std::string& negative_z);
|
||||||
|
|
||||||
void setTexParameters(const TexParams&);
|
void setTexParameters(const TexParams&);
|
||||||
|
|
||||||
|
bool reloadTexture();
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
TextureCube();
|
TextureCube();
|
||||||
TextureCube(const TextureCube&);
|
TextureCube(const TextureCube&);
|
||||||
|
@ -60,6 +62,8 @@ protected:
|
||||||
bool init(const std::string& positive_x, const std::string& negative_x,
|
bool init(const std::string& positive_x, const std::string& negative_x,
|
||||||
const std::string& positive_y, const std::string& negative_y,
|
const std::string& positive_y, const std::string& negative_y,
|
||||||
const std::string& positive_z, const std::string& negative_z);
|
const std::string& positive_z, const std::string& negative_z);
|
||||||
|
private:
|
||||||
|
std::vector<std::string> _imgPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -285,6 +285,8 @@ THE SOFTWARE.
|
||||||
#include "3d/CCBillBoard.h"
|
#include "3d/CCBillBoard.h"
|
||||||
#include "3d/CCFrustum.h"
|
#include "3d/CCFrustum.h"
|
||||||
#include "3d/CCPlane.h"
|
#include "3d/CCPlane.h"
|
||||||
|
#include "3d/CCTextureCube.h"
|
||||||
|
#include "3d/CCSkybox.h"
|
||||||
|
|
||||||
// Deprecated include
|
// Deprecated include
|
||||||
#include "deprecated/CCDictionary.h"
|
#include "deprecated/CCDictionary.h"
|
||||||
|
|
|
@ -2291,8 +2291,9 @@ void UseCaseSprite3D::update(float delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite3DCubeMapTest::Sprite3DCubeMapTest() :
|
Sprite3DCubeMapTest::Sprite3DCubeMapTest() :
|
||||||
_sprite(nullptr),
|
_textureCube(nullptr),
|
||||||
_textureCube(nullptr)
|
_skyBox(nullptr),
|
||||||
|
_teapot(nullptr)
|
||||||
{
|
{
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
addNewSpriteWithCoords(Vec2(s.width / 2, s.height / 2));
|
addNewSpriteWithCoords(Vec2(s.width / 2, s.height / 2));
|
||||||
|
@ -2300,6 +2301,12 @@ _textureCube(nullptr)
|
||||||
|
|
||||||
Sprite3DCubeMapTest::~Sprite3DCubeMapTest()
|
Sprite3DCubeMapTest::~Sprite3DCubeMapTest()
|
||||||
{
|
{
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||||
|
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_teapot->release();
|
||||||
|
_skyBox->release();
|
||||||
_textureCube->release();
|
_textureCube->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2320,18 +2327,18 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
_camera->setCameraFlag(CameraFlag::USER1);
|
_camera->setCameraFlag(CameraFlag::USER1);
|
||||||
|
|
||||||
// create a teapot
|
// create a teapot
|
||||||
auto teapot = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
_teapot = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
||||||
|
_teapot->retain();
|
||||||
|
|
||||||
//create and set our custom shader
|
//create and set our custom shader
|
||||||
auto shader = GLProgram::createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag");
|
auto shader = GLProgram::createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag");
|
||||||
auto _state = GLProgramState::create(shader);
|
auto state = GLProgramState::create(shader);
|
||||||
|
|
||||||
// create the second texture for cylinder
|
// create the second texture for cylinder
|
||||||
_textureCube = TextureCube::create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg",
|
_textureCube = TextureCube::create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg",
|
||||||
"Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg",
|
"Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg",
|
||||||
"Sprite3DTest/skybox/front.jpg", "Sprite3DTest/skybox/back.jpg");
|
"Sprite3DTest/skybox/front.jpg", "Sprite3DTest/skybox/back.jpg");
|
||||||
|
|
||||||
// temporary solution
|
|
||||||
_textureCube->retain();
|
_textureCube->retain();
|
||||||
|
|
||||||
//set texture parameters
|
//set texture parameters
|
||||||
|
@ -2343,40 +2350,67 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
_textureCube->setTexParameters(tRepeatParams);
|
_textureCube->setTexParameters(tRepeatParams);
|
||||||
|
|
||||||
// pass the texture sampler to our custom shader
|
// pass the texture sampler to our custom shader
|
||||||
_state->setUniformTexture("u_cubeTex", _textureCube);
|
state->setUniformTexture("u_cubeTex", _textureCube);
|
||||||
|
|
||||||
teapot->setGLProgramState(_state);
|
_teapot->setGLProgramState(state);
|
||||||
teapot->setPosition3D(Vec3(0, -5, -20));
|
_teapot->setPosition3D(Vec3(0, -5, -20));
|
||||||
teapot->setRotation3D(Vec3(-90, 180, 0));
|
_teapot->setRotation3D(Vec3(-90, 180, 0));
|
||||||
|
|
||||||
auto rotate_action = RotateBy::create(1.5, Vec3(0, 30, 0));
|
auto rotate_action = RotateBy::create(1.5, Vec3(0, 30, 0));
|
||||||
teapot->runAction(RepeatForever::create(rotate_action));
|
_teapot->runAction(RepeatForever::create(rotate_action));
|
||||||
|
|
||||||
//pass mesh's attribute to shader
|
//pass mesh's attribute to shader
|
||||||
long offset = 0;
|
long offset = 0;
|
||||||
auto attributeCount = teapot->getMesh()->getMeshVertexAttribCount();
|
auto attributeCount = _teapot->getMesh()->getMeshVertexAttribCount();
|
||||||
for (auto i = 0; i < attributeCount; i++)
|
for (auto i = 0; i < attributeCount; i++)
|
||||||
{
|
{
|
||||||
auto meshattribute = teapot->getMesh()->getMeshVertexAttribute(i);
|
auto meshattribute = _teapot->getMesh()->getMeshVertexAttribute(i);
|
||||||
_state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
||||||
meshattribute.size,
|
meshattribute.size,
|
||||||
meshattribute.type,
|
meshattribute.type,
|
||||||
GL_FALSE,
|
GL_FALSE,
|
||||||
teapot->getMesh()->getVertexSizeInBytes(),
|
_teapot->getMesh()->getVertexSizeInBytes(),
|
||||||
(GLvoid*)offset);
|
(GLvoid*)offset);
|
||||||
|
|
||||||
offset += meshattribute.attribSizeBytes;
|
offset += meshattribute.attribSizeBytes;
|
||||||
}
|
}
|
||||||
addChild(teapot);
|
addChild(_teapot);
|
||||||
addChild(_camera);
|
addChild(_camera);
|
||||||
setCameraMask(2);
|
setCameraMask(2);
|
||||||
|
|
||||||
{
|
{
|
||||||
// config skybox
|
// config skybox
|
||||||
Skybox* box = Skybox::create();
|
_skyBox = Skybox::create();
|
||||||
box->setTexture(_textureCube);
|
_skyBox->retain();
|
||||||
addChild(box);
|
|
||||||
|
|
||||||
//auto rotate_action = RotateBy::create(1.5, Vec3(0, -30, 0));
|
_skyBox->setTexture(_textureCube);
|
||||||
//box->runAction(RepeatForever::create(rotate_action));
|
addChild(_skyBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||||
|
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
|
||||||
|
[this](EventCustom*)
|
||||||
|
{
|
||||||
|
auto state = _teapot->getGLProgramState();
|
||||||
|
auto glProgram = state->getGLProgram();
|
||||||
|
glProgram->reset();
|
||||||
|
glProgram->initWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag");
|
||||||
|
glProgram->link();
|
||||||
|
glProgram->updateUniforms();
|
||||||
|
|
||||||
|
_textureCube->reloadTexture();
|
||||||
|
|
||||||
|
Texture2D::TexParams tRepeatParams;
|
||||||
|
tRepeatParams.magFilter = GL_NEAREST;
|
||||||
|
tRepeatParams.minFilter = GL_NEAREST;
|
||||||
|
tRepeatParams.wrapS = GL_MIRRORED_REPEAT;
|
||||||
|
tRepeatParams.wrapT = GL_MIRRORED_REPEAT;
|
||||||
|
_textureCube->setTexParameters(tRepeatParams);
|
||||||
|
state->setUniformTexture("u_cubeTex", _textureCube);
|
||||||
|
|
||||||
|
_skyBox->reload();
|
||||||
|
_skyBox->setTexture(_textureCube);
|
||||||
|
});
|
||||||
|
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -492,6 +492,7 @@ public:
|
||||||
namespace cocos2d
|
namespace cocos2d
|
||||||
{
|
{
|
||||||
class TextureCube;
|
class TextureCube;
|
||||||
|
class Skybox;
|
||||||
}
|
}
|
||||||
class Sprite3DCubeMapTest : public Sprite3DTestDemo
|
class Sprite3DCubeMapTest : public Sprite3DTestDemo
|
||||||
{
|
{
|
||||||
|
@ -505,8 +506,13 @@ public:
|
||||||
void addNewSpriteWithCoords(Vec2);
|
void addNewSpriteWithCoords(Vec2);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
cocos2d::Sprite3D* _sprite;
|
|
||||||
cocos2d::TextureCube* _textureCube;
|
cocos2d::TextureCube* _textureCube;
|
||||||
|
Skybox* _skyBox;
|
||||||
|
Sprite3D* _teapot;
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||||
|
EventListenerCustom* _backToForegroundListener;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -919,6 +919,71 @@ function Sprite3DMirrorTest.create()
|
||||||
return layer
|
return layer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
----Sprite3DCubeTexture
|
||||||
|
----------------------------------------
|
||||||
|
local Sprite3DCubeMap = {}
|
||||||
|
Sprite3DCubeMap.__index = Sprite3DCubeMap
|
||||||
|
|
||||||
|
function Sprite3DCubeMap.create()
|
||||||
|
local layer = cc.Layer:create()
|
||||||
|
Helper.initWithLayer(layer)
|
||||||
|
Helper.titleLabel:setString("Sprite3D CubeMap/Skybox Test")
|
||||||
|
|
||||||
|
local visSize = cc.Director:getInstance():getVisibleSize()
|
||||||
|
local camera = cc.Camera:createPerspective(68, visSize.width / visSize.height, 0.1, 200)
|
||||||
|
camera:setCameraFlag(2)
|
||||||
|
layer:addChild(camera)
|
||||||
|
|
||||||
|
local fileName = "Sprite3DTest/teapot.c3b"
|
||||||
|
local teapot = cc.Sprite3D:create(fileName)
|
||||||
|
teapot:setPosition3D({x = 0, y = -5, z = -20})
|
||||||
|
teapot:setRotation3D({x = -90, y = 180, z = 0})
|
||||||
|
|
||||||
|
local texCube = cc.TextureCube:create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg",
|
||||||
|
"Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg",
|
||||||
|
"Sprite3DTest/skybox/front.jpg", "Sprite3DTest/skybox/back.jpg");
|
||||||
|
|
||||||
|
local program = cc.GLProgram:createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag")
|
||||||
|
local state = cc.GLProgramState:create(program)
|
||||||
|
|
||||||
|
attriNames = {
|
||||||
|
"a_position", "a_color",
|
||||||
|
"a_texCoord", "a_texCoord1", "a_texCoord2", "a_texCoord3",
|
||||||
|
"a_normal", "a_blendWeight", "a_blendIndex"
|
||||||
|
}
|
||||||
|
|
||||||
|
--pass mesh's attribute to shader
|
||||||
|
local offset = 0
|
||||||
|
local attributeCount = teapot:getMesh():getMeshVertexAttribCount()
|
||||||
|
for i = 0, attributeCount-1 do
|
||||||
|
local meshattribute = teapot:getMesh():getMeshVertexAttribute(i)
|
||||||
|
state:setVertexAttribPointer(attriNames[meshattribute.vertexAttrib+1],
|
||||||
|
meshattribute.size,
|
||||||
|
meshattribute.type,
|
||||||
|
false,
|
||||||
|
teapot:getMesh():getVertexSizeInBytes(),
|
||||||
|
offset);
|
||||||
|
offset = offset + meshattribute.attribSizeBytes
|
||||||
|
end
|
||||||
|
|
||||||
|
state:setUniformTexture("u_cubeTex", texCube:getName())
|
||||||
|
|
||||||
|
teapot:setGLProgramState(state)
|
||||||
|
teapot:setCameraMask(2)
|
||||||
|
|
||||||
|
local rotate_action = cc.RotateBy:create(1.5, { x = 0.0, y = 30.0, z = 0.0})
|
||||||
|
teapot:runAction(cc.RepeatForever:create(rotate_action));
|
||||||
|
layer:addChild(teapot)
|
||||||
|
|
||||||
|
local skybox = cc.Skybox:create()
|
||||||
|
skybox:setTexture(texCube)
|
||||||
|
layer:addChild(skybox)
|
||||||
|
|
||||||
|
return layer
|
||||||
|
end
|
||||||
|
|
||||||
function Sprite3DTest()
|
function Sprite3DTest()
|
||||||
local scene = cc.Scene:create()
|
local scene = cc.Scene:create()
|
||||||
|
|
||||||
|
@ -932,6 +997,7 @@ function Sprite3DTest()
|
||||||
Sprite3DReskinTest.create,
|
Sprite3DReskinTest.create,
|
||||||
Sprite3DWithOBBPerfromanceTest.create,
|
Sprite3DWithOBBPerfromanceTest.create,
|
||||||
Sprite3DMirrorTest.create,
|
Sprite3DMirrorTest.create,
|
||||||
|
Sprite3DCubeMap.create,
|
||||||
}
|
}
|
||||||
|
|
||||||
scene:addChild(Sprite3DBasicTest.create())
|
scene:addChild(Sprite3DBasicTest.create())
|
||||||
|
|
Loading…
Reference in New Issue