static bool cmp(const spNativeTexture& t2, const spNativeTexture& t1)
 {
     if (t1->getFormat() > t2->getFormat())
         return true;
     if (t1->getWidth() > t2->getWidth())
         return true;
     return t1->getHeight() > t2->getHeight();
 }
 AnimationFrame::AnimationFrame(spNativeTexture t)
 {
     _row = _column = 0;
     _resAnim = 0;
     _diffuse.base = t;
     _diffuse.premultiplied = true;
     _srcRect = RectF(0, 0, 1, 1);
     _destRect = RectF(0, 0, (float)t->getWidth(), (float)t->getHeight());
     _frameSize = Vector2((float)t->getWidth(), (float)t->getHeight());
 }
        TextureLine(spNativeTexture t)
        {
            setVerticalMode(Box9Sprite::TILING_FULL);
            setHorizontalMode(Box9Sprite::TILING_FULL);
            Sprite::setResAnim(DebugActor::resSystem->getResAnim("checker"));

            AnimationFrame f;
            Vector2 s = fitSize(itemSize, Vector2((float)t->getWidth(), (float)t->getHeight()));

            setSize(s);

            Diffuse df;
            df.base = t;

            f.init(0, df, RectF(0, 0, 1.0f, 1.0f), RectF(0, 0, s.x, s.y), s);
            spSprite image = initActor(new Sprite,
                                       arg_blend = blend_disabled,
                                       arg_resAnim = f);
            addChild(image);

            spColorRectSprite rect = initActor(new ColorRectSprite,
                                               arg_color = Color(Color::White, 255),
                                               arg_attachTo = this);

            rect->addTween(Sprite::TweenColor(Color(Color::White, 0)), 4000, -1, true);

            char path[255];
            path::normalize(t->getName().c_str(), path);

            char txt[255];
            safe_sprintf(txt, "%s\n<div c=\"FF0000\">%s</div>-<div c=\"0000ff\">%dx%d</div>\nid: %d",
                         path,
                         textureFormat2String(t->getFormat()),
                         t->getWidth(), t->getHeight(), t->getObjectID());

            spTextField text = initActor(new TextField,
                                         arg_color = Color::Black,
                                         arg_w = (float)itemSize.x,
                                         arg_vAlign = TextStyle::VALIGN_TOP,
                                         arg_hAlign = TextStyle::HALIGN_LEFT,
                                         arg_multiline = true,
                                         arg_attachTo = rect,
                                         arg_htmlText = txt
                                        );

            text->setBreakLongWords(true);

            rect->setSize(text->getTextRect().size.cast<Vector2>() + Vector2(2, 2));
            rect->setY((itemSize.y - rect->getHeight()) / 2.0f);
        }
    void pass(spNativeTexture srcTexture, const Rect& srcRect, spNativeTexture destTexture, const Rect& destRect, const Color& color)
    {
        IVideoDriver* driver = IVideoDriver::instance;

        const VertexDeclarationGL* decl = static_cast<const VertexDeclarationGL*>(driver->getVertexDeclaration(vertexPCT2::FORMAT));
        driver->setRenderTarget(destTexture);
        driver->clear(0);

        driver->setViewport(destRect);

        driver->setTexture(0, srcTexture);


        vertexPCT2 v[4];


        RectF dst = srcRect.cast<RectF>() / Vector2((float)srcTexture->getWidth(), (float)srcTexture->getHeight());
        fillQuadT(v,
                  dst,
                  RectF(-1, -1, 2, 2),
                  AffineTransform::getIdentity(), color.rgba());


        driver->draw(IVideoDriver::PT_TRIANGLE_STRIP, decl, v, sizeof(v));
        driver->setTexture(0, 0);
    }
 bool operator()(const spNativeTexture& t1, const spNativeTexture& t2) const
 {
     if (t1->getFormat() < _tf)
         return true;
     if (t1->getWidth() < _w)
         return true;
     return t1->getHeight() < _h;
 }
    bool RenderTargetsManager::isGood(const spNativeTexture& t, int w, int h, TextureFormat tf) const
    {
        if (!t)
            return false;

        if (!t->getHandle())
            return false;

        if (t->getFormat() == tf &&
                t->getWidth() >= w && t->getHeight() >= h &&
                t->getWidth() <= (w + ALIGN_SIZE) && t->getHeight() <= (h + ALIGN_SIZE))
            return true;
        return false;
    }
	MaskedRenderer::MaskedRenderer(spNativeTexture mask, const RectF &srcRect, const RectF &destRect, const transform &t, bool channelR) :_mask(mask)
	{
		_clipUV = ClipUV(
			t.transform(destRect.getLeftTop()),
			t.transform(destRect.getRightTop()),
			t.transform(destRect.getLeftBottom()),
			srcRect.getLeftTop(),
			srcRect.getRightTop(),
			srcRect.getLeftBottom());

		_clipMask = srcRect;
		Vector2 v(1.0f / mask->getWidth(), 1.0f / mask->getHeight());
		_clipMask.expand(v, v);

		_shaderFlags |= UberShaderProgram::MASK;
		if (channelR)
			_shaderFlags |= UberShaderProgram::MASK_R_CHANNEL;
	}
    void ResAnim::init(spNativeTexture texture, const Point& originalSize, int columns, int rows, float scaleFactor)
    {
        _scaleFactor = scaleFactor;
        if (!texture)
            return;

        int frame_width = originalSize.x / columns;
        int frame_height = originalSize.y / rows;

        animationFrames frames;
        int frames_count = rows * columns;
        frames.reserve(frames_count);

        Vector2 frameSize((float)frame_width, (float)frame_height);
        for (int y = 0; y < rows; ++y)
        {
            for (int x = 0; x < columns; ++x)
            {
                Rect src;
                src.pos = Point(x * frame_width, y * frame_height);
                src.size = Point(frame_width, frame_height);

                float iw = 1.0f / texture->getWidth();
                float ih = 1.0f / texture->getHeight();
                RectF srcRect(src.pos.x * iw, src.pos.y * ih, src.size.x * iw, src.size.y * ih);

                RectF destRect(Vector2(0, 0), frameSize * scaleFactor);
                AnimationFrame frame;
                Diffuse df;
                df.base = texture;
                frame.init(this, df, srcRect, destRect, destRect.size);
                frames.push_back(frame);
            }
        }

        init(frames, columns, scaleFactor);
    }