CCClippingRectangleNode,CCClippingNode源码解析

来源:互联网 发布:mac app store打不开 编辑:程序博客网 时间:2024/05/28 16:23

源码:

/** *  @addtogroup _2d *  @{ *//** ClippingNode is a subclass of Node. * It draws its content (childs) clipped using a stencil. * The stencil is an other Node that will not be drawn. * The clipping is done using the alpha part of the stencil (adjusted with an alphaThreshold). */ /// 裁剪节点是节点的一个子类 // 他通过一个模板来裁剪其子节点 /// 这个模板是另一个将被绘制的节点 /// 使用模板的alpha通道裁剪class CC_DLL ClippingNode : public Node{public:    /** Creates and initializes a clipping node without a stencil.     *     * @return An autorelease ClippingNode.     */ /// 创建一个裁剪节点    static ClippingNode* create();        /** Creates and initializes a clipping node with an other node as its stencil.     * The stencil node will be retained.     * @param stencil The stencil node.     */ /// 通过一个模板创建一个裁剪节点    static ClippingNode* create(Node *stencil);    /** The Node to use as a stencil to do the clipping.     * The stencil node will be retained.     * This default to nil.     *     * @return The stencil node.     */ /// 得到模板    Node* getStencil() const;        /** Set the Node to use as a stencil to do the clipping.     *     * @param stencil The Node to use as a stencil to do the clipping.     */ /// 设置模板    void setStencil(Node *stencil);    /** If stencil has no childre it will not be drawn.     * If you have custom stencil-based node with stencil drawing mechanics other then children-based,     * then this method should return true every time you wish stencil to be visited.     * By default returns true if has any children attached.     *     * @return If you have custom stencil-based node with stencil drawing mechanics other then children-based,     *         then this method should return true every time you wish stencil to be visited.     *         By default returns true if has any children attached.     * @js NA     */ /// 是否有子节点    virtual bool hasContent() const;    /** The alpha threshold.     * The content is drawn only where the stencil have pixel with alpha greater than the alphaThreshold.     * Should be a float between 0 and 1.     * This default to 1 (so alpha test is disabled).     *     * @return The alpha threshold value,Should be a float between 0 and 1.     */ /// 得到alpha通道的入口    GLfloat getAlphaThreshold() const;        /** Set the alpha threshold.      *      * @param alphaThreshold The alpha threshold.     */ /// 设置alpha通道的入口    void setAlphaThreshold(GLfloat alphaThreshold);        /** Inverted. If this is set to true,     * the stencil is inverted, so the content is drawn where the stencil is NOT drawn.     * This default to false.     *     * @return If the clippingNode is Inverted, it will be return true.     */ /// 是否反向 /// 真:显示的是模板没有绘制的部分 /// 否:显示的是模板绘制的部分    bool isInverted() const;        /** Set the ClippingNode whether or not invert.     *     * @param inverted A bool Type,to set the ClippingNode whether or not invert.     */ /// 设置是否反向    void setInverted(bool inverted);    // Overrides    /**     * @lua NA     */    virtual void onEnter() override;    /**     * @lua NA     */    virtual void onEnterTransitionDidFinish() override;    /**     * @lua NA     */    virtual void onExitTransitionDidStart() override;    /**     * @lua NA     */    virtual void onExit() override;    virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;        virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override;    CC_CONSTRUCTOR_ACCESS:    ClippingNode();        /**     * @js NA     * @lua NA     */    virtual ~ClippingNode();    /** Initializes a clipping node without a stencil.     */ /// 初始化    virtual bool init() override;        /** Initializes a clipping node with an other node as its stencil.     The stencil node will be retained, and its parent will be set to this clipping node.     */    virtual bool init(Node *stencil);protected:    /**draw fullscreen quad to clear stencil bits    */    void drawFullScreenQuadClearStencil();    Node* _stencil;    GLfloat _alphaThreshold;    bool    _inverted;    //renderData and callback    void onBeforeVisit();    void onAfterDrawStencil();    void onAfterVisit();    GLboolean _currentStencilEnabled;    GLuint _currentStencilWriteMask;    GLenum _currentStencilFunc;    GLint _currentStencilRef;    GLuint _currentStencilValueMask;    GLenum _currentStencilFail;    GLenum _currentStencilPassDepthFail;    GLenum _currentStencilPassDepthPass;    GLboolean _currentDepthWriteMask;    GLboolean _currentAlphaTestEnabled;    GLenum _currentAlphaTestFunc;    GLclampf _currentAlphaTestRef;    GLint _mask_layer_le;        GroupCommand _groupCommand;    CustomCommand _beforeVisitCmd;    CustomCommand _afterDrawStencilCmd;    CustomCommand _afterVisitCmd;private:    CC_DISALLOW_COPY_AND_ASSIGN(ClippingNode);};/** @} */NS_CC_END


源码:

/**@brief Clipping Rectangle Node.@details A node that clipped with specified rectangle.@js NA*//// 矩形裁剪节点/// 一个指定裁剪矩形的节点class CC_DLL ClippingRectangleNode : public Node{    public:    /**    @brief Create node with specified clipping region.    @param clippingRegion Specify the clipping rectangle.    @return If the creation success, return a pointer of ClippingRectangleNode; otherwise return nil.    *//// 创建一个矩形裁剪节点/// 通过指定的裁剪区域创建节点/// clippingRegion 指定的裁剪区域    static ClippingRectangleNode* create(const Rect& clippingRegion);    /**    @brief Create a clipping rectangle node.    @return If the creation success, return a pointer of ClippingRectangleNode; otherwise return nil.    *//// 创建一个矩形裁剪区域    static ClippingRectangleNode* create();        /**    @brief Get the clipping rectangle.    @return The clipping rectangle.    *//// 得到裁剪区域    const Rect& getClippingRegion() const {        return _clippingRegion;    }    /**    @brief Set the clipping rectangle.    @param clippingRegion Specify the clipping rectangle.    *//// 设置裁剪区域    void setClippingRegion(const Rect& clippingRegion);        /**    @brief Get whether the clipping is enabled or not.    @return Whether the clipping is enabled or not. Default is true.    *//// 是否能够裁剪    const bool isClippingEnabled() const {        return _clippingEnabled;    }    /**    @brief Enable/Disable the clipping.    @param enabled Pass true to enable clipping. Pass false to disable clipping.    *//// 设置是否能够裁剪    void setClippingEnabled(bool enabled) {        _clippingEnabled = enabled;    }    //virtual void draw(Renderer* renderer, const Mat4 &transform, uint32_t flags) override;    virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;protected:    ClippingRectangleNode()    : _clippingEnabled(true)    {    }    /// 裁剪之前    void onBeforeVisitScissor();    /// 裁剪之后void onAfterVisitScissor();        Rect _clippingRegion;    bool _clippingEnabled;        CustomCommand _beforeVisitCmdScissor;    CustomCommand _afterVisitCmdScissor;};


0 0