1
1
/* ***************************************************************************
2
2
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
+ Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
3
4
4
5
https://axmol.dev/
5
6
26
27
27
28
#include " ui/CocosGUI.h"
28
29
#include " renderer/RenderState.h"
29
- #include < spine/spine-cocos2dx .h>
30
+ #include < spine/spine-axmol .h>
30
31
31
32
#include " ../testResource.h"
32
33
#include " ../TerrainTest/TerrainTest.h"
33
34
34
35
using namespace ax ;
35
36
using namespace spine ;
36
37
38
+ static AxmolTextureLoader textureLoader;
39
+
37
40
class SkeletonAnimationCullingFix : public SkeletonAnimation
38
41
{
39
42
public:
40
43
SkeletonAnimationCullingFix () : SkeletonAnimation() {}
41
44
42
45
virtual void draw (ax::Renderer* renderer, const ax::Mat4& transform, uint32_t transformFlags) override
43
46
{
44
- glDisable (GL_CULL_FACE );
47
+ renderer-> setCullMode (CullMode::NONE );
45
48
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);
47
50
}
48
51
49
52
static SkeletonAnimationCullingFix* createWithFile (std::string_view skeletonDataFile,
50
53
std::string_view atlasFile,
51
54
float scale = 1 )
52
55
{
53
56
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);
56
59
node->autorelease ();
57
60
return node;
58
61
}
@@ -77,12 +80,12 @@ class Scene3DTestScene : public TestCase
77
80
public:
78
81
CREATE_FUNC (Scene3DTestScene);
79
82
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*);
82
85
83
86
private:
84
87
Scene3DTestScene ();
85
- virtual ~Scene3DTestScene ();
88
+ ~Scene3DTestScene () override ;
86
89
bool init () override ;
87
90
88
91
void createWorld3D ();
@@ -364,23 +367,24 @@ void Scene3DTestScene::createWorld3D()
364
367
{
365
368
// create skybox
366
369
// 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);
369
372
370
373
// create the second texture for cylinder
371
374
_textureCube = TextureCube::create (" MeshRendererTest/skybox/left.jpg" , " MeshRendererTest/skybox/right.jpg" ,
372
375
" MeshRendererTest/skybox/top.jpg" , " MeshRendererTest/skybox/bottom.jpg" ,
373
376
" MeshRendererTest/skybox/front.jpg" , " MeshRendererTest/skybox/back.jpg" );
374
377
// set texture parameters
375
378
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 ;
380
383
_textureCube->setTexParameters (tRepeatParams);
381
384
382
385
// 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));
384
388
385
389
// add skybox
386
390
_skyBox = Skybox::create ();
@@ -419,7 +423,7 @@ void Scene3DTestScene::createWorld3D()
419
423
rootps->setPosition3D (Vec3 (0 , 150 , 0 ));
420
424
auto moveby = MoveBy::create (2 .0f , Vec2 (50 .0f , 0 .0f ));
421
425
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 )));
423
427
rootps->startParticleSystem ();
424
428
425
429
_player->addChild (rootps, 0 );
@@ -831,7 +835,7 @@ void Scene3DTestScene::createDescDlg()
831
835
}
832
836
}
833
837
834
- void Scene3DTestScene::onTouchEnd (Touch* touch, Event* event)
838
+ void Scene3DTestScene::onTouchEnd (Touch* touch, ax:: Event* event)
835
839
{
836
840
auto location = touch->getLocation ();
837
841
auto camera = _gameCameras[CAMERA_WORLD_3D_SCENE];
@@ -861,7 +865,7 @@ void Scene3DTestScene::onTouchEnd(Touch* touch, Event* event)
861
865
dir.y = 0 ;
862
866
dir.normalize ();
863
867
_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 );
865
869
_player->_targetPos = collisionPoint;
866
870
_player->forward ();
867
871
}
0 commit comments