Skip to content

Commit f225f94

Browse files
authored
Update and re-enable Scene3D test (#2562)
* Update and re-enable Scene3D test * Replace direct OpenGL call * Fix crash when clicking crystal image due to null texture * Remove unnecessary method call
1 parent e5f262e commit f225f94

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

tests/cpp-tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ list(APPEND GAME_HEADER
194194
Source/ReleasePoolTest/ReleasePoolTest.h
195195
Source/InputTest/MouseTest.h
196196
Source/SpineTest/SpineTest.h
197-
# Source/Scene3DTest/Scene3DTest.h
197+
Source/Scene3DTest/Scene3DTest.h
198198
Source/ParticleTest/ParticleTest.h
199199
Source/EffectsTest/EffectsTest.h
200200
Source/UITest/UITest.h
@@ -319,7 +319,7 @@ list(APPEND GAME_SOURCE
319319
Source/ShaderTest/ShaderTest.cpp
320320
Source/ShaderTest/ShaderTest2.cpp
321321
Source/SpineTest/SpineTest.cpp
322-
# Source/Scene3DTest/Scene3DTest.cpp
322+
Source/Scene3DTest/Scene3DTest.cpp
323323
Source/MeshRendererTest/DrawNode3D.cpp
324324
Source/DrawNodeTest/DrawNodeTest.cpp
325325
Source/MeshRendererTest/MeshRendererTest.cpp

tests/cpp-tests/Source/Scene3DTest/Scene3DTest.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/****************************************************************************
22
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3+
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
34
45
https://axmol.dev/
56
@@ -26,33 +27,35 @@
2627

2728
#include "ui/CocosGUI.h"
2829
#include "renderer/RenderState.h"
29-
#include <spine/spine-cocos2dx.h>
30+
#include <spine/spine-axmol.h>
3031

3132
#include "../testResource.h"
3233
#include "../TerrainTest/TerrainTest.h"
3334

3435
using namespace ax;
3536
using namespace spine;
3637

38+
static AxmolTextureLoader textureLoader;
39+
3740
class SkeletonAnimationCullingFix : public SkeletonAnimation
3841
{
3942
public:
4043
SkeletonAnimationCullingFix() : SkeletonAnimation() {}
4144

4245
virtual void draw(ax::Renderer* renderer, const ax::Mat4& transform, uint32_t transformFlags) override
4346
{
44-
glDisable(GL_CULL_FACE);
47+
renderer->setCullMode(CullMode::NONE);
4548
SkeletonAnimation::draw(renderer, transform, transformFlags);
46-
RenderState::StateBlock::invalidate(ax::RenderState::StateBlock::RS_ALL_ONES);
49+
//RenderState::StateBlock::invalidate(ax::RenderState::StateBlock::RS_ALL_ONES);
4750
}
4851

4952
static SkeletonAnimationCullingFix* createWithFile(std::string_view skeletonDataFile,
5053
std::string_view atlasFile,
5154
float scale = 1)
5255
{
5356
SkeletonAnimationCullingFix* node = new SkeletonAnimationCullingFix();
54-
spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
55-
node->initWithJsonFile(skeletonDataFile, atlas, scale);
57+
spine::Atlas* atlas = new spine::Atlas(std::string(atlasFile).c_str(), &textureLoader);
58+
node->initWithJsonFile(std::string(skeletonDataFile), atlas, scale);
5659
node->autorelease();
5760
return node;
5861
}
@@ -77,12 +80,12 @@ class Scene3DTestScene : public TestCase
7780
public:
7881
CREATE_FUNC(Scene3DTestScene);
7982

80-
bool onTouchBegan(Touch* touch, Event* event) { return true; }
81-
void onTouchEnd(Touch*, Event*);
83+
bool onTouchBegan(Touch* touch, ax::Event* event) { return true; }
84+
void onTouchEnd(Touch*, ax::Event*);
8285

8386
private:
8487
Scene3DTestScene();
85-
virtual ~Scene3DTestScene();
88+
~Scene3DTestScene() override;
8689
bool init() override;
8790

8891
void createWorld3D();
@@ -364,23 +367,24 @@ void Scene3DTestScene::createWorld3D()
364367
{
365368
// create skybox
366369
// create and set our custom shader
367-
auto shader = GLProgram::createWithFilenames("MeshRendererTest/cube_map.vert", "MeshRendererTest/cube_map.frag");
368-
auto state = GLProgramState::create(shader);
370+
auto shader = ProgramManager::getInstance()->loadProgram("custom/cube_map_vs", "custom/cube_map_fs");
371+
auto state = new ProgramState(shader);
369372

370373
// create the second texture for cylinder
371374
_textureCube = TextureCube::create("MeshRendererTest/skybox/left.jpg", "MeshRendererTest/skybox/right.jpg",
372375
"MeshRendererTest/skybox/top.jpg", "MeshRendererTest/skybox/bottom.jpg",
373376
"MeshRendererTest/skybox/front.jpg", "MeshRendererTest/skybox/back.jpg");
374377
// set texture parameters
375378
Texture2D::TexParams tRepeatParams;
376-
tRepeatParams.magFilter = GL_LINEAR;
377-
tRepeatParams.minFilter = GL_LINEAR;
378-
tRepeatParams.sAddressMode = GL_MIRRORED_REPEAT;
379-
tRepeatParams.tAddressMode = GL_MIRRORED_REPEAT;
379+
tRepeatParams.magFilter = backend::SamplerFilter::LINEAR;
380+
tRepeatParams.minFilter = backend::SamplerFilter::LINEAR;
381+
tRepeatParams.sAddressMode = backend::SamplerAddressMode::MIRROR_REPEAT;
382+
tRepeatParams.tAddressMode = backend::SamplerAddressMode::MIRROR_REPEAT;
380383
_textureCube->setTexParameters(tRepeatParams);
381384

382385
// pass the texture sampler to our custom shader
383-
state->setUniformTexture("u_cubeTex", _textureCube);
386+
const auto cubeTexLoc = state->getUniformLocation("u_cubeTex");
387+
state->setUniform(cubeTexLoc, _textureCube, sizeof(ax::TextureCube));
384388

385389
// add skybox
386390
_skyBox = Skybox::create();
@@ -419,7 +423,7 @@ void Scene3DTestScene::createWorld3D()
419423
rootps->setPosition3D(Vec3(0, 150, 0));
420424
auto moveby = MoveBy::create(2.0f, Vec2(50.0f, 0.0f));
421425
auto moveby1 = MoveBy::create(2.0f, Vec2(-50.0f, 0.0f));
422-
rootps->runAction(RepeatForever::create(Sequence::create(moveby, moveby1, nullptr)));
426+
rootps->runAction(RepeatForever::create(ax::Sequence::create(moveby, moveby1, nullptr)));
423427
rootps->startParticleSystem();
424428

425429
_player->addChild(rootps, 0);
@@ -831,7 +835,7 @@ void Scene3DTestScene::createDescDlg()
831835
}
832836
}
833837

834-
void Scene3DTestScene::onTouchEnd(Touch* touch, Event* event)
838+
void Scene3DTestScene::onTouchEnd(Touch* touch, ax::Event* event)
835839
{
836840
auto location = touch->getLocation();
837841
auto camera = _gameCameras[CAMERA_WORLD_3D_SCENE];
@@ -861,7 +865,7 @@ void Scene3DTestScene::onTouchEnd(Touch* touch, Event* event)
861865
dir.y = 0;
862866
dir.normalize();
863867
_player->_headingAngle = -1 * acos(dir.dot(Vec3(0, 0, -1)));
864-
dir.cross(dir, Vec3(0, 0, -1), &_player->_headingAxis);
868+
Vec3::cross(dir, Vec3(0, 0, -1), &_player->_headingAxis);
865869
_player->_targetPos = collisionPoint;
866870
_player->forward();
867871
}

tests/cpp-tests/Source/Scene3DTest/Scene3DTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/****************************************************************************
22
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3+
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
34
45
https://axmol.dev/
56

tests/cpp-tests/Source/controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RootTests : public TestList
4646
# pragma message("The optional extension Effekseer is enabled.")
4747
addTest("Effekseer", []() { return new EffekseerTests(); });
4848
#endif
49-
// addTest("Node: Scene3D", [](){return new Scene3DTests(); });
49+
addTest("Node: Scene3D", [](){return new Scene3DTests(); });
5050
#if defined(AX_PLATFORM_PC) || (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) || defined(__EMSCRIPTEN__)
5151
addTest("ImGui", []() { return new ImGuiTests(); });
5252
#endif

0 commit comments

Comments
 (0)