コード例 #1
0
ファイル: Mask.cpp プロジェクト: Gabriele91/Easy2D
void MaskSprite::draw()
{
    //draw childs
    Scene*  scene = getScene();
    Object* object = getObject();
    //
    if (object && scene && isVisible())
    {
        Render* render = dynamic_cast<Render*>(scene);
        Camera* camera = render->getCamera();
        //display/view camera
        const Mat4& disViewM4 = RenderContext::getDisplay().mul(camera->getGlobalMatrix());
        const AABox2& viewBox = camera->getBoxViewport();
        /////////////////////////////////////////////////////////////////////////////////////
        //new box pos
        AABox2 modelBox = getBox().applay(disViewM4);
        //culling
        if (!modelBox.isIntersection(viewBox)) return;
        /////////////////////////////////////////////////////////////////////////////////////
        //build queue
        queue->clear();
        //add all childs
        for (auto child : *object)
        queue->append([&](const AABox2& mbox) -> bool
        {
            const AABox2& wbox = mbox.applay(disViewM4);
            return modelBox.isIntersection(wbox);
        }, child);
        //draw filter
        RenderContext::setStencil(STENCIL_REPLACE);
        RenderContext::stencilClear();
        RenderContext::setColorWritable(false, false, false, false);
        RenderContext::setZBufferWritable(false);
        ///////////////////////////////////
        //enable state settings
        enableStates();
        //set uniform
        getShader()->uniform(uAlphaMask,alphaMask);
        //draw mesh
        if (getMesh()) getMesh()->draw();
        ///////////////////////////////////
        //set filter
        RenderContext::setStencil(STENCIL_KEEP);
        RenderContext::setColorWritable(true, true, true, true);
        RenderContext::setZBufferWritable(true);
        //draw queue
        if (render->getBatchingIsEnable())
            queue->draw(render->getBatchingMesh());
        else
            queue->draw();
        //disable filter
        RenderContext::setStencil(STENCIL_NONE);
    }
}
コード例 #2
0
void GroupDrawable::draw(Render& render, const glm::mat4& transformation)
{
	if(!m_canDraw)
		return;

	glm::mat4 mvp = transformation*getMatrix();

	for(std::list<Drawable*>::iterator it = m_drawables.begin(); it != m_drawables.end(); it++)
		if((*it))
			(*it)->draw(render, mvp);

	if(m_material)
		m_material->enableShader();

	if(m_staticToCamera)
		onDraw(render, mvp);
	else
		onDraw(render, render.getCamera().getMatrix() * mvp);

	if(m_material)
		m_material->disableShader();
}