PuzzleSDK
RawStencilBufferTest类 参考

#include <ClippingNodeTest.h>

+ 类 RawStencilBufferTest 继承关系图:
+ RawStencilBufferTest 的协作图:

Public 成员函数

 CREATE_FUNC (RawStencilBufferTest)
 
 ~RawStencilBufferTest ()
 
virtual std::string title () const override
 
virtual std::string subtitle () const override
 
virtual void setup () override
 
virtual void draw (cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override
 
virtual void setupStencilForClippingOnPlane (int plane)
 
virtual void setupStencilForDrawingOnPlane (int plane)
 
- Public 成员函数 继承自 BaseClippingNodeTest
 CREATE_FUNC (BaseClippingNodeTest)
 
 ~BaseClippingNodeTest ()
 
virtual bool init () override
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 
virtual void onEnter () override
 

Protected 成员函数

void onBeforeDrawClip (int planeIndex)
 
void onBeforeDrawSprite (int planeIndex)
 
void initCommands ()
 

Protected 属性

std::vector< cocos2d::CustomCommand > _renderCmds
 
cocos2d::CallbackCommand _enableStencilCallback
 
cocos2d::CallbackCommand _disableStencilCallback
 
cocos2d::Vector< cocos2d::Sprite * > _sprites
 
cocos2d::Vector< cocos2d::Sprite * > _spritesStencil
 
cocos2d::backend::UniformLocation _locColor
 
cocos2d::backend::UniformLocation _locMVPMatrix
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 

详细描述

在文件 ClippingNodeTest.h168 行定义.

构造及析构函数说明

◆ ~RawStencilBufferTest()

RawStencilBufferTest::~RawStencilBufferTest ( )

在文件 ClippingNodeTest.cpp534 行定义.

535{
536}

成员函数说明

◆ CREATE_FUNC()

RawStencilBufferTest::CREATE_FUNC ( RawStencilBufferTest  )

◆ draw()

void RawStencilBufferTest::draw ( cocos2d::Renderer *  renderer,
const cocos2d::Mat4 &  transform,
uint32_t  flags 
)
overridevirtual

在文件 ClippingNodeTest.cpp640 行定义.

641{
642 auto winPoint = Vec2(Director::getInstance()->getWinSize());
643 auto planeSize = winPoint * (1.0 / _planeCount);
644
645 renderer->addCommand(&_enableStencilCallback);
646
647 for (int i = 0, cmdIndex = 0; i < _planeCount; i++)
648 {
649 auto spritePoint = planeSize * i;
650 spritePoint.x += planeSize.x / 2;
651 spritePoint.y = 0;
652 _sprites.at(i)->setPosition( spritePoint );
653 _spritesStencil.at(i)->setPosition( spritePoint );
654
655 renderer->clear(ClearFlag::STENCIL, Color4F::BLACK, 0.f, 0x0, _globalZOrder);
656
657 renderer->addCommand(&_renderCmds[cmdIndex]);
658 cmdIndex++;
659
660 Director* director = Director::getInstance();
661 CCASSERT(nullptr != director, "Director is null when setting matrix stack");
662 director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
663
664 _modelViewTransform = this->transform(transform);
665 _spritesStencil.at(i)->visit(renderer, _modelViewTransform, flags);
666 director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
667
668 renderer->addCommand(&_renderCmds[cmdIndex]);
669 cmdIndex++;
670
671 director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
672 _modelViewTransform = this->transform(transform);
673 _sprites.at(i)->visit(renderer, _modelViewTransform, flags);
674 director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
675 }
676
677 renderer->addCommand(&_disableStencilCallback);
678}
static const int _planeCount
cocos2d::Vector< cocos2d::Sprite * > _sprites
cocos2d::CallbackCommand _disableStencilCallback
std::vector< cocos2d::CustomCommand > _renderCmds
cocos2d::Vector< cocos2d::Sprite * > _spritesStencil
cocos2d::CallbackCommand _enableStencilCallback

引用了 _disableStencilCallback, _enableStencilCallback, _planeCount, _renderCmds, _sprites , 以及 _spritesStencil.

◆ initCommands()

void RawStencilBufferTest::initCommands ( )
protected

在文件 ClippingNodeTest.cpp566 行定义.

567{
568 auto renderer = Director::getInstance()->getRenderer();
569 _enableStencilCallback.func = [=](){
570 renderer->setStencilTest(true);
571 };
572 _enableStencilCallback.init(_globalZOrder);
573
574 _disableStencilCallback.func = [=](){
575 renderer->setStencilTest(false);
576 };
577 _disableStencilCallback.init(_globalZOrder);
578
579 auto program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_UCOLOR);
580 _programState = new (std::nothrow) backend::ProgramState(program);
581 _locColor = _programState->getProgram()->getUniformLocation("u_color");
582 _locMVPMatrix = _programState->getProgram()->getUniformLocation("u_MVPMatrix");
583 const auto& projectionMat = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
584 _programState->setUniform(_locMVPMatrix, projectionMat.m, sizeof(projectionMat.m));
585
586 size_t neededCmdSize = _planeCount * 2;
587 _renderCmds.resize(neededCmdSize);
588 auto winPoint = Vec2(Director::getInstance()->getWinSize());
589 auto planeSize = winPoint * (1.0 / _planeCount);
590 BlendFunc blend;
591 blend.src = backend::BlendFactor::ONE;
592 blend.dst = backend::BlendFactor::ONE_MINUS_SRC_ALPHA;
593 for (int i = 0, cmdIndex = 0; i < _planeCount; i++)
594 {
595 auto stencilPoint = planeSize * (_planeCount - i);
596 stencilPoint.x = winPoint.x;
597
598 auto& cmd = _renderCmds[cmdIndex];
599 cmdIndex++;
600 cmd.init(_globalZOrder, blend);
601 cmd.setBeforeCallback( CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawClip, this, i) );
602 Vec2 vertices[] = {
603 Vec2::ZERO,
604 Vec2(stencilPoint.x, 0.0f),
605 stencilPoint,
606 Vec2(0.0f, stencilPoint.y)
607 };
608 unsigned short indices[] = {0, 2, 1, 0, 3, 2};
609 cmd.createVertexBuffer(sizeof(Vec2), 4, backend::BufferUsage::STATIC);
610 cmd.updateVertexBuffer(vertices, sizeof(vertices));
611 cmd.createIndexBuffer(backend::IndexFormat::U_SHORT, 6, backend::BufferUsage::STATIC);
612 cmd.updateIndexBuffer(indices, sizeof(indices));
613 cmd.getPipelineDescriptor().programState = _programState;
614 auto vertexLayout = _programState->getVertexLayout();
615 auto& attributes = _programState->getProgram()->getActiveAttributes();
616 auto iter = attributes.find("a_position");
617 if (iter != attributes.end())
618 vertexLayout->setAttribute("a_position", iter->second.location, backend::VertexFormat::FLOAT2, 0, false);
619 vertexLayout->setLayout(sizeof(Vec2));
620
621
622 auto& cmd2 = _renderCmds[cmdIndex];
623 cmdIndex++;
624 cmd2.init(_globalZOrder, blend);
625 cmd2.setBeforeCallback(CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawSprite, this, i));
626 Vec2 vertices2[] = {
627 Vec2::ZERO,
628 Vec2(winPoint.x, 0.0f),
629 winPoint,
630 Vec2(0.0f, winPoint.y)
631 };
632 cmd2.createVertexBuffer(sizeof(Vec2), 4, backend::BufferUsage::STATIC);
633 cmd2.updateVertexBuffer(vertices2, sizeof(vertices2));
634 cmd2.createIndexBuffer(backend::IndexFormat::U_SHORT, 6, backend::BufferUsage::STATIC);
635 cmd2.updateIndexBuffer(indices, sizeof(indices));
636 cmd2.getPipelineDescriptor().programState = _programState;
637 }
638}
void onBeforeDrawSprite(int planeIndex)
cocos2d::backend::UniformLocation _locMVPMatrix
void onBeforeDrawClip(int planeIndex)
cocos2d::backend::UniformLocation _locColor

引用了 _disableStencilCallback, _enableStencilCallback, _locColor, _locMVPMatrix, _planeCount, _renderCmds, onBeforeDrawClip() , 以及 onBeforeDrawSprite().

被这些函数引用 setup().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onBeforeDrawClip()

void RawStencilBufferTest::onBeforeDrawClip ( int  planeIndex)
protected

在文件 ClippingNodeTest.cpp680 行定义.

681{
682 this->setupStencilForClippingOnPlane(planeIndex);
683 float color[4] = {1.f, 1.f, 1.f, 1.f};
684 _programState->setUniform(_locColor, color, sizeof(color));
685}
virtual void setupStencilForClippingOnPlane(int plane)

引用了 _locColor , 以及 setupStencilForClippingOnPlane().

被这些函数引用 initCommands().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onBeforeDrawSprite()

void RawStencilBufferTest::onBeforeDrawSprite ( int  planeIndex)
protected

在文件 ClippingNodeTest.cpp687 行定义.

688{
689 this->setupStencilForDrawingOnPlane(planeIndex);
690 auto& color = _planeColor[planeIndex];
691 _programState->setUniform(_locColor, (void*)color, sizeof(color));
692}
static const float _planeColor[][4]
virtual void setupStencilForDrawingOnPlane(int plane)

引用了 _locColor, _planeColor , 以及 setupStencilForDrawingOnPlane().

被这些函数引用 initCommands().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ setup()

void RawStencilBufferTest::setup ( )
overridevirtual

重载 BaseClippingNodeTest .

RawStencilBufferTestAlphaTest , 以及 RawStencilBufferTest6 重载.

在文件 ClippingNodeTest.cpp548 行定义.

549{
550 for(int i = 0; i < _planeCount; ++i)
551 {
552 Sprite* sprite = Sprite::create(s_pathGrossini);
553 sprite->setAnchorPoint( Vec2(0.5, 0) );
554 sprite->setScale( 2.5f );
555 _sprites.pushBack(sprite);
556
557 Sprite* sprite2 = Sprite::create(s_pathGrossini);
558 sprite2->setAnchorPoint( Vec2(0.5, 0) );
559 sprite2->setScale( 2.5f );
560 _spritesStencil.pushBack(sprite2);
561 }
562
563 initCommands();
564}
static const char s_pathGrossini[]
Definition: testResource.h:28

引用了 _planeCount, _sprites, _spritesStencil, initCommands() , 以及 s_pathGrossini.

被这些函数引用 RawStencilBufferTestAlphaTest::setup().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ setupStencilForClippingOnPlane()

void RawStencilBufferTest::setupStencilForClippingOnPlane ( int  plane)
virtual

RawStencilBufferTest2, RawStencilBufferTest3, RawStencilBufferTest4, RawStencilBufferTest5 , 以及 RawStencilBufferTest6 重载.

在文件 ClippingNodeTest.cpp694 行定义.

695{
696 auto renderer = Director::getInstance()->getRenderer();
697 unsigned int planeMask = 0x1 << plane;
698 renderer->setStencilWriteMask(planeMask);
699 renderer->setStencilCompareFunction(backend::CompareFunction::NEVER, planeMask, planeMask);
700 renderer->setStencilOperation(backend::StencilOperation::REPLACE, backend::StencilOperation::KEEP, backend::StencilOperation::KEEP);
701}

被这些函数引用 onBeforeDrawClip(), RawStencilBufferTest2::setupStencilForClippingOnPlane(), RawStencilBufferTest3::setupStencilForClippingOnPlane(), RawStencilBufferTest4::setupStencilForClippingOnPlane() , 以及 RawStencilBufferTest5::setupStencilForClippingOnPlane().

+ 这是这个函数的调用关系图:

◆ setupStencilForDrawingOnPlane()

void RawStencilBufferTest::setupStencilForDrawingOnPlane ( int  plane)
virtual

RawStencilBufferTest2, RawStencilBufferTest3, RawStencilBufferTest4, RawStencilBufferTest5 , 以及 RawStencilBufferTest6 重载.

在文件 ClippingNodeTest.cpp703 行定义.

704{
705 auto renderer = Director::getInstance()->getRenderer();
706 unsigned int planeMask = 0x1 << plane;
707 renderer->setStencilCompareFunction(backend::CompareFunction::EQUAL, planeMask, planeMask);
708 renderer->setStencilOperation(backend::StencilOperation::KEEP, backend::StencilOperation::KEEP, backend::StencilOperation::KEEP);
709}

被这些函数引用 onBeforeDrawSprite(), RawStencilBufferTest2::setupStencilForDrawingOnPlane(), RawStencilBufferTest3::setupStencilForDrawingOnPlane(), RawStencilBufferTest4::setupStencilForDrawingOnPlane(), RawStencilBufferTest5::setupStencilForDrawingOnPlane() , 以及 RawStencilBufferTest6::setupStencilForDrawingOnPlane().

+ 这是这个函数的调用关系图:

◆ subtitle()

std::string RawStencilBufferTest::subtitle ( ) const
overridevirtual

重载 TestCase .

RawStencilBufferTest2, RawStencilBufferTest3, RawStencilBufferTest4, RawStencilBufferTest5 , 以及 RawStencilBufferTest6 重载.

在文件 ClippingNodeTest.cpp543 行定义.

544{
545 return "1:Default";
546}

◆ title()

std::string RawStencilBufferTest::title ( ) const
overridevirtual

重载 BaseClippingNodeTest .

在文件 ClippingNodeTest.cpp538 行定义.

539{
540 return "Raw Stencil Tests";
541}

类成员变量说明

◆ _disableStencilCallback

cocos2d::CallbackCommand RawStencilBufferTest::_disableStencilCallback
protected

在文件 ClippingNodeTest.h190 行定义.

被这些函数引用 draw() , 以及 initCommands().

◆ _enableStencilCallback

cocos2d::CallbackCommand RawStencilBufferTest::_enableStencilCallback
protected

在文件 ClippingNodeTest.h189 行定义.

被这些函数引用 draw() , 以及 initCommands().

◆ _locColor

cocos2d::backend::UniformLocation RawStencilBufferTest::_locColor
protected

在文件 ClippingNodeTest.h193 行定义.

被这些函数引用 initCommands(), onBeforeDrawClip() , 以及 onBeforeDrawSprite().

◆ _locMVPMatrix

cocos2d::backend::UniformLocation RawStencilBufferTest::_locMVPMatrix
protected

在文件 ClippingNodeTest.h194 行定义.

被这些函数引用 initCommands().

◆ _renderCmds

std::vector<cocos2d::CustomCommand> RawStencilBufferTest::_renderCmds
protected

在文件 ClippingNodeTest.h188 行定义.

被这些函数引用 draw() , 以及 initCommands().

◆ _sprites

cocos2d::Vector<cocos2d::Sprite*> RawStencilBufferTest::_sprites
protected

在文件 ClippingNodeTest.h191 行定义.

被这些函数引用 draw() , 以及 setup().

◆ _spritesStencil

cocos2d::Vector<cocos2d::Sprite*> RawStencilBufferTest::_spritesStencil
protected

在文件 ClippingNodeTest.h192 行定义.

被这些函数引用 draw(), setup() , 以及 RawStencilBufferTestAlphaTest::setup().


该类的文档由以下文件生成: