소스 검색

imroving TreeInspector

dmuratshin 9 년 전
부모
커밋
8a63d294f1

+ 1 - 1
oxygine/src/MaskedRenderer.cpp

@@ -5,7 +5,7 @@
 
 
 namespace oxygine
 namespace oxygine
 {
 {
-    MaskedRenderer::MaskedRenderer(spNativeTexture mask, const RectF& srcRect, const RectF& destRect, const Transform& t, bool channelR) : _mask(mask)
+    MaskedRenderer::MaskedRenderer(spNativeTexture mask, const RectF& srcRect, const RectF& destRect, const Transform& t, bool channelR, IVideoDriver *driver) : STDRenderer(driver), _mask(mask)
     {
     {
         _clipUV = ClipUV(
         _clipUV = ClipUV(
                       t.transform(destRect.getLeftTop()),
                       t.transform(destRect.getLeftTop()),

+ 1 - 1
oxygine/src/MaskedRenderer.h

@@ -72,7 +72,7 @@ namespace oxygine
     class MaskedRenderer : public STDRenderer
     class MaskedRenderer : public STDRenderer
     {
     {
     public:
     public:
-        MaskedRenderer(spNativeTexture mask, const RectF& srcRect, const RectF& destRect, const Transform& t, bool channelR);
+        MaskedRenderer(spNativeTexture mask, const RectF& srcRect, const RectF& destRect, const Transform& t, bool channelR, IVideoDriver *);
 
 
         //void draw(const RState *rs, const RectF &destRect) OVERRIDE;
         //void draw(const RState *rs, const RectF &destRect) OVERRIDE;
 
 

+ 1 - 1
oxygine/src/STDMaterial.cpp

@@ -116,7 +116,7 @@ namespace oxygine
 
 
             _renderer->drawBatch();
             _renderer->drawBatch();
 
 
-            MaskedRenderer mr(msk, maskSrc, maskDest, t, rchannel);
+            MaskedRenderer mr(msk, maskSrc, maskDest, t, rchannel, original->getDriver());
             mr.begin(_renderer);
             mr.begin(_renderer);
             _renderer = &mr;
             _renderer = &mr;
             RenderState rs = parentRS;
             RenderState rs = parentRS;

+ 20 - 4
oxygine/src/dev_tools/TreeInspectorLine.cpp

@@ -5,6 +5,8 @@
 #include "TextField.h"
 #include "TextField.h"
 #include "res/ResFont.h"
 #include "res/ResFont.h"
 #include "res/Resources.h"
 #include "res/Resources.h"
+#include "Stage.h"
+#include "DebugActor.h"
 
 
 namespace oxygine
 namespace oxygine
 {
 {
@@ -25,10 +27,13 @@ namespace oxygine
         setCull(true);
         setCull(true);
 
 
         _page = page;
         _page = page;
-        _item = new TreeInspectorPreview(page->getTreeInspector());
-        _item->init(item);
+        _item = new TreeInspectorPreview();
+        _item->init(item, Vector2(50, 50), false);
         addChild(_item);
         addChild(_item);
 
 
+        _itemTree = new TreeInspectorPreview();
+        _itemTree->init(item, getStage()->getSize()/2, true);
+
 
 
         spTextField tb = new TextField();
         spTextField tb = new TextField();
         tb->setTouchEnabled(false);
         tb->setTouchEnabled(false);
@@ -37,7 +42,7 @@ namespace oxygine
         const float minWidth = 300.0f;
         const float minWidth = 300.0f;
 
 
         TextStyle style;
         TextStyle style;
-        style.font = _page->getTreeInspector()->_resSystem->getResFont("system");
+        style.font = DebugActor::resSystem->getResFont("system");
         style.multiline = true;
         style.multiline = true;
         style.vAlign = TextStyle::VALIGN_TOP;
         style.vAlign = TextStyle::VALIGN_TOP;
         tb->setStyle(style);
         tb->setStyle(style);
@@ -60,6 +65,17 @@ namespace oxygine
         addChild(tb);
         addChild(tb);
 
 
         setSize(0, 0);
         setSize(0, 0);
-        setSize(TreeInspector::calcBounds(this).size);
+        Vector2 sz = TreeInspector::calcBounds(this).size;
+        setSize(sz);
+
+        addTouchDownListener([=](Event*) {
+            _itemTree->setPriority(_stage->getLastChild()->getPriority());
+            _itemTree->setPosition(getStage()->getSize() / 4);
+            _stage->addChild(_itemTree);
+        });
+
+        addTouchUpListener([=](Event*) {
+            _itemTree->detach();
+        });
     }
     }
 }
 }

+ 2 - 0
oxygine/src/dev_tools/TreeInspectorLine.h

@@ -21,6 +21,8 @@ namespace oxygine
     private:
     private:
         TreeInspectorPage* _page;
         TreeInspectorPage* _page;
         spTreeInspectorPreview _item;
         spTreeInspectorPreview _item;
+        spTreeInspectorPreview _itemTree;
+
 
 
         void _onMouseOver(bool over);
         void _onMouseOver(bool over);
         void _onPress(bool over);
         void _onPress(bool over);

+ 363 - 29
oxygine/src/dev_tools/TreeInspectorPreview.cpp

@@ -6,18 +6,12 @@
 #include "RenderState.h"
 #include "RenderState.h"
 #include "STDRenderer.h"
 #include "STDRenderer.h"
 #include "STDMaterial.h"
 #include "STDMaterial.h"
+#include "DebugActor.h"
+#include "core/NativeTexture.h"
 
 
 namespace oxygine
 namespace oxygine
 {
 {
-    TreeInspectorPreview::TreeInspectorPreview(TreeInspector* tree): _tree(tree), _prevParent(0), _drawChildren(false)
-    {
-        setTouchEnabled(false);
-    }
-
-    TreeInspectorPreview::~TreeInspectorPreview()
-    {
-
-    }
+    
 
 
     Vector2 fitSize(const Vector2& destSize, const Vector2& src)
     Vector2 fitSize(const Vector2& destSize, const Vector2& src)
     {
     {
@@ -37,26 +31,66 @@ namespace oxygine
         return Vector2(srcSize.x * scale, srcSize.y * scale);
         return Vector2(srcSize.x * scale, srcSize.y * scale);
     }
     }
 
 
-    void TreeInspectorPreview::init(spActor item)
+
+    TreeInspectorPreview::TreeInspectorPreview(): _drawChildren(false)
+    {
+
+        //setTouchEnabled(false);
+        //addEventListener(TouchEvent::TOUCH_DOWN, )
+    }
+
+    TreeInspectorPreview::~TreeInspectorPreview()
+    {
+
+    }
+
+    void TreeInspectorPreview::doUpdate(const UpdateState& us)
     {
     {
-        STDRenderer r_(&_videoCache);
-        STDMaterial mat(&r_);
+        if (getPressed())
+        {
+
+        }
+        else
+        {
+
+        }
+    }
+
+
+    Vector2 TreeInspectorPreview::render2cache(spActor item, const Vector2& size, bool child)
+    {
+        Material::setCurrent(0);
+
+        VideoDriverCache &cache = _videoCache;
+
+        STDRenderer renderer(&cache);
+        renderer.setViewProjTransform(STDRenderer::instance->getViewProjection());
+        STDMaterial mat(&renderer);
 
 
-        STDRenderer& r = r_;
         RenderState rs;
         RenderState rs;
-        rs.transform = item->getTransform();
         rs.material = &mat;
         rs.material = &mat;
-        r.begin(0);
-        //r.setTransform(rs.transform);
-        item->doRender(rs);
-        r.end();
-        r.drawBatch();
+        RectF clip(0,0,getStage()->getWidth(), getStage()->getHeight());
+        rs.clip = &clip;
+        renderer.begin(0);
+        if (child)
+        {
+            bool vis = item->getVisible();
+            item->setVisible(true);
+            item->render(rs);
+            item->setVisible(vis);
+        }
+        else
+            item->doRender(rs);
+
+        renderer.end();
+        renderer.drawBatch();
 
 
         Material::setCurrent(0);
         Material::setCurrent(0);
 
 
+
         //setSize(30, 30);
         //setSize(30, 30);
 
 
-        RectF itemRect = _videoCache._bounds;
+        RectF itemRect = cache._bounds;
         if (itemRect.isEmpty())
         if (itemRect.isEmpty())
         {
         {
             itemRect = item->getDestRect();
             itemRect = item->getDestRect();
@@ -64,23 +98,36 @@ namespace oxygine
                 itemRect.setSize(Vector2(10, 4));
                 itemRect.setSize(Vector2(10, 4));
         }
         }
 
 
-        Vector2 ns = fitSize(Vector2(50.0f, 50.0f), itemRect.size);
+        Vector2 ns = fitSize(size, itemRect.size);
         float scale = ns.x / itemRect.size.x;
         float scale = ns.x / itemRect.size.x;
 
 
-        _cacheTransform.identity();
+        AffineTransform transform;
+        transform.identity();
+        transform.scale(Vector2(scale, scale));
+        transform.translate(-itemRect.pos);
 
 
-        _cacheTransform.scale(Vector2(scale, scale));
-        _cacheTransform.translate(-itemRect.pos);
+        cache.transform(transform);
 
 
+        return ns;
+    }
 
 
+    void TreeInspectorPreview::init(spActor item, const Vector2& size, bool tree)
+    {
+        Vector2 ns = render2cache(item, size, tree);
+
+        AnimationFrame fr = DebugActor::resSystem->getResAnim("checker")->getFrame(0);
 
 
-        AnimationFrame fr = _tree->_resSystem->getResAnim("checker")->getFrame(0, 0);
-        //Point itemSize(30, 30);// = _getItemRect().size;
+        Vector2 uv = ns;
 
 
         RectF srcRect = fr.getSrcRect();
         RectF srcRect = fr.getSrcRect();
+
+        uv.x = std::min(uv.x, fr.getDestRect().getWidth());
+        uv.y = std::min(uv.y, fr.getDestRect().getHeight());
+
         const Diffuse& df = fr.getDiffuse();
         const Diffuse& df = fr.getDiffuse();
-        srcRect.size.x = ns.x / (float)df.base->getWidth();
-        srcRect.size.y = ns.y / (float)df.base->getHeight();
+        srcRect.size.x = uv.x / (float)df.base->getWidth();
+        srcRect.size.y = uv.y / (float)df.base->getHeight();
+
         RectF destRect = fr.getDestRect();
         RectF destRect = fr.getDestRect();
         destRect.size = ns;
         destRect.size = ns;
 
 
@@ -95,8 +142,295 @@ namespace oxygine
         Sprite::doRender(parentRenderState);
         Sprite::doRender(parentRenderState);
 
 
         STDMaterial::instance->getRenderer()->drawBatch();
         STDMaterial::instance->getRenderer()->drawBatch();
-        _videoCache.render(_cacheTransform * parentRenderState.transform);
+        _videoCache.render(parentRenderState.transform);
         STDMaterial::instance->getRenderer()->drawBatch();
         STDMaterial::instance->getRenderer()->drawBatch();
         STDMaterial::instance->getRenderer()->resetSettings();
         STDMaterial::instance->getRenderer()->resetSettings();
     }
     }
+
+    VideoDriverCache::VideoDriverCache() : _bounds(0, 0, 0, 0)
+    {
+        _batches.push_back(cached_batch());
+        rt = new NativeTextureNull;
+    }
+
+    VideoDriverCache::~VideoDriverCache()
+    {
+
+    }
+
+    oxygine::VideoDriverCache::cached_batch& VideoDriverCache::current()
+    {
+        return _batches.back();
+    }
+
+    const oxygine::VideoDriverCache::cached_batch& VideoDriverCache::current() const
+    {
+        return _batches.back();
+    }
+
+    oxygine::spNativeTexture VideoDriverCache::createTexture()
+    {
+        return 0;
+    }
+
+    void VideoDriverCache::begin(const Rect& viewport, const Color* color)
+    {
+
+    }
+
+    const oxygine::VertexDeclaration* VideoDriverCache::getVertexDeclaration(bvertex_format fmt) const
+    {
+        return instance->getVertexDeclaration(fmt);
+    }
+
+    void VideoDriverCache::setDefaultSettings()
+    {
+
+    }
+
+    void VideoDriverCache::setRenderTarget(spNativeTexture r)
+    {
+        rt = r;
+    }
+
+    oxygine::spNativeTexture VideoDriverCache::getRenderTarget() const
+    {
+        return rt;
+    }
+
+    void VideoDriverCache::setShaderProgram(ShaderProgram* program)
+    {
+        current().program = program;
+    }
+
+    void VideoDriverCache::setTexture(int sampler, spNativeTexture texture)
+    {
+        current().textures[sampler] = texture;
+    }
+
+    void VideoDriverCache::setState(STATE state, unsigned int value)
+    {
+        current().states[state] = value;
+    }
+
+    void VideoDriverCache::addUni(const char *id, cached_batch::uni::type tp, const void* ptr, int sz)
+    {
+        cached_batch::uni uni;
+        uni.id = id;
+        uni.tp = tp;
+        const unsigned char *data = (const unsigned char*)ptr;
+        uni.data.assign(data, data + sz);
+        current().uniforms.push_back(uni);
+    }
+
+    void VideoDriverCache::setUniformInt(const char* id, int v)
+    {
+        addUni(id, cached_batch::uni::uni_int, &v, sizeof(v));
+    }
+
+    void VideoDriverCache::setUniform(const char* id, float v)
+    {
+        addUni(id, cached_batch::uni::uni_float, &v, sizeof(v));
+    }
+
+    void VideoDriverCache::setUniform(const char* id, const Matrix* v)
+    {
+        addUni(id, cached_batch::uni::uni_matrix, v, sizeof(*v));
+    }
+
+    void VideoDriverCache::setUniform(const char* id, const Vector2* v, int num)
+    {
+        addUni(id, cached_batch::uni::uni_vec2, v, sizeof(*v) * num);
+    }
+
+    void VideoDriverCache::setUniform(const char* id, const Vector3* v, int num)
+    {
+        addUni(id, cached_batch::uni::uni_vec3, v, sizeof(*v) * num);
+    }
+
+    void VideoDriverCache::setUniform(const char* id, const Vector4* v, int num)
+    {
+        addUni(id, cached_batch::uni::uni_vec4, v, sizeof(*v) * num);
+    }
+
+    void VideoDriverCache::setBlendFunc(BLEND_TYPE src, BLEND_TYPE dest)
+    {
+        current().blendSrc = src;
+        current().blendDest = dest;
+    }
+
+    void VideoDriverCache::setScissorRect(const Rect* r)
+    {
+        if (r)
+            current().scissor = *r;
+        else
+            current().scissor = EmptyScissor;
+
+    }
+
+    bool VideoDriverCache::getScissorRect(Rect& r) const
+    {
+        if (current().scissor == EmptyScissor)
+            return false;
+        r = current().scissor;
+        return true;
+    }
+
+    void VideoDriverCache::nextBatch()
+    {
+        _batches.push_back(cached_batch());
+        cached_batch &b = _batches.back();
+        b = _batches[_batches.size() - 2];
+        b.indices.clear();
+        b.vertices.clear();
+        b.numIndices = 0;
+        b.numVertices = 0;
+    }
+
+    void VideoDriverCache::draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int numVertices, const unsigned short* indicesData, unsigned int numIndices)
+    {
+        if (!numIndices)
+            return;
+
+        current().vdecl = decl;
+        current().pt = pt;
+        current().numVertices = numVertices;
+        current().numIndices = numIndices;
+        current().vertices.assign((const char*)verticesData, (const char*)verticesData + decl->size * numVertices);
+        current().indices.assign(indicesData, indicesData + numIndices);
+
+        const vertexPCT2* v = (const vertexPCT2*)(&current().vertices.front());
+        if (_batches.size() == 1)
+        {
+            OX_ASSERT(current().vertices.size());
+            _bounds = RectF(v->x, v->y, 0, 0);
+        }
+
+        size_t num = current().vertices.size() / current().vdecl->size;
+
+        for (size_t i = 0; i != num; ++i)
+        {
+            v = (const vertexPCT2*)(&current().vertices.front() + current().vdecl->size * i);
+            RectF f(v->x, v->y, 0, 0);
+            _bounds.unite(f);
+        }
+        nextBatch();
+    }
+
+    void VideoDriverCache::draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int numVertices)
+    {
+        current().vdecl = decl;
+        current().pt = pt;
+        current().numVertices = numVertices;
+        current().vertices.assign((const char*)verticesData, (const char*)verticesData + current().vdecl->size * numVertices);
+        nextBatch();
+    }
+
+    void VideoDriverCache::render(const AffineTransform& transform)
+    {
+        for (batches::iterator i = _batches.begin(); i != _batches.end(); ++i)
+        {
+            const cached_batch& b = *i;
+
+            std::vector<char> modified = b.vertices;
+
+            if (b.vertices.size())
+            {
+                size_t num = b.vertices.size() / b.vdecl->size;
+
+                //if (0)
+                for (size_t i = 0; i != num; ++i)
+                {
+                    vertexPCT2* v = (vertexPCT2*)(&modified.front() + b.vdecl->size * i);
+                    Vector2 np = transform.transform(Vector2(v->x, v->y));
+                    v->x = np.x;
+                    v->y = np.y;
+                }
+            }
+
+            for (int i = 0; i < cached_batch::MAX_TEXTURES; ++i)
+                instance->setTexture(i, b.textures[i]);
+
+            if (b.program)
+                instance->setShaderProgram(b.program);
+            instance->setBlendFunc(b.blendSrc, b.blendDest);
+            for (int i = 0; i < STATE_NUM; ++i)
+                instance->setState((STATE)i, b.states[i]);
+
+            /*
+            if (b.scissor == EmptyScissor)
+                instance->setScissorRect(0);
+            else
+                instance->setScissorRect(&b.scissor);
+
+            */
+            //if(0)
+            for (size_t i = 0; i < b.uniforms.size(); ++i)
+            {
+                const cached_batch::uni &uni = b.uniforms[i];
+                switch (uni.tp)
+                {
+                case cached_batch::uni::uni_float:
+                    instance->setUniform(uni.id.c_str(), *((const float*)&uni.data[0])); break;
+                case cached_batch::uni::uni_int:
+                    instance->setUniformInt(uni.id.c_str(), *((const int*)&uni.data[0])); break;
+                case cached_batch::uni::uni_matrix:
+                    instance->setUniform(uni.id.c_str(), ((const Matrix*)&uni.data[0])); break;
+                case cached_batch::uni::uni_vec2:
+                    instance->setUniform(uni.id.c_str(), ((const Vector2*)&uni.data[0]), uni.data.size() / sizeof(Vector2)); break;
+                case cached_batch::uni::uni_vec3:
+                    instance->setUniform(uni.id.c_str(), ((const Vector3*)&uni.data[0]), uni.data.size() / sizeof(Vector3)); break;
+                case cached_batch::uni::uni_vec4:
+                    instance->setUniform(uni.id.c_str(), ((const Vector4*)&uni.data[0]), uni.data.size() / sizeof(Vector4)); break;
+                default:
+                    break;
+                }
+            }
+
+            if (b.numIndices)
+                instance->draw(b.pt, b.vdecl, &modified.front(), b.numVertices, &b.indices.front(), b.numIndices);
+            else
+            {
+                if (b.numVertices)
+                    instance->draw(b.pt, b.vdecl, &modified.front(), b.numVertices);
+            }
+        }
+    }
+
+    void VideoDriverCache::transform(const AffineTransform& m)
+    {
+        for (batches::iterator i = _batches.begin(); i != _batches.end(); ++i)
+        {
+            cached_batch& b = *i;
+            if (!b.numVertices)
+                continue;
+
+            size_t num = b.vertices.size() / b.vdecl->size;
+
+            std::vector<char> &modified = b.vertices;
+            //if (0)
+            for (size_t i = 0; i != num; ++i)
+            {
+                vertexPCT2* v = (vertexPCT2*)(&modified.front() + b.vdecl->size * i);
+                Vector2 np = m.transform(Vector2(v->x, v->y));
+                v->x = np.x;
+                v->y = np.y;
+            }
+
+            /*
+            if (b.scissor != EmptyScissor)
+            {
+                Vector2 lt = b.scissor.getLeftTop().cast<Vector2>();
+                lt = m.transform(lt);
+
+                Vector2 rb = b.scissor.getRightBottom().cast<Vector2>();
+                rb = m.transform(rb);
+
+                Vector2 size = rb - lt;
+                b.scissor = RectF(lt, size).cast<Rect>();
+            }
+            */
+        }
+    }
+
 }
 }

+ 55 - 113
oxygine/src/dev_tools/TreeInspectorPreview.h

@@ -5,6 +5,8 @@
 
 
 namespace oxygine
 namespace oxygine
 {
 {
+    const Rect EmptyScissor(0, 0, -1, -1);
+
     class TreeInspector;
     class TreeInspector;
 
 
     class VertexDeclarationNull: public VertexDeclaration
     class VertexDeclarationNull: public VertexDeclaration
@@ -22,7 +24,7 @@ namespace oxygine
     public:
     public:
         struct cached_batch
         struct cached_batch
         {
         {
-            cached_batch(): program(0), vdecl(0), numVertices(0), numIndices(0), blendSrc(IVideoDriver::BT_ONE), blendDest(IVideoDriver::BT_ONE)
+            cached_batch(): program(0), vdecl(0), numVertices(0), numIndices(0), blendSrc(IVideoDriver::BT_ONE), blendDest(IVideoDriver::BT_ONE), scissor(EmptyScissor)
             {
             {
                 memset(states, 0, sizeof(states));
                 memset(states, 0, sizeof(states));
             }
             }
@@ -35,10 +37,23 @@ namespace oxygine
             PRIMITIVE_TYPE pt;
             PRIMITIVE_TYPE pt;
             std::vector<char> vertices;
             std::vector<char> vertices;
             std::vector<unsigned short> indices;
             std::vector<unsigned short> indices;
+            
+            struct uni
+            {
+                std::string id;
+                enum type {uni_int, uni_float, uni_vec2, uni_vec3, uni_vec4, uni_matrix};
+                type tp;
+                std::vector<unsigned char> data;
+
+            };
+            std::vector<uni> uniforms;
+
+
             int numVertices;
             int numVertices;
             int numIndices;
             int numIndices;
             unsigned int states[STATE_NUM];
             unsigned int states[STATE_NUM];
             BLEND_TYPE blendSrc, blendDest;
             BLEND_TYPE blendSrc, blendDest;
+            Rect scissor;
         };
         };
 
 
         typedef std::vector<cached_batch> batches;
         typedef std::vector<cached_batch> batches;
@@ -48,156 +63,83 @@ namespace oxygine
         AffineTransform _transform;
         AffineTransform _transform;
         mutable VertexDeclarations<VertexDeclarationNull> _declarations;
         mutable VertexDeclarations<VertexDeclarationNull> _declarations;
 
 
-        VideoDriverCache(): _bounds(0, 0, 0, 0)
-        {
-            _batches.push_back(cached_batch());
-        }
+        VideoDriverCache();
+        ~VideoDriverCache();
 
 
-        cached_batch& current()
-        {
-            return _batches.back();
-        }
+        cached_batch& current();
+        const cached_batch& current() const;
 
 
-        spNativeTexture createTexture() {return 0;}
+        spNativeTexture createTexture();
 
 
-        void begin(const Rect& viewport, const Color* color)
-        {
-        }
+        void begin(const Rect& viewport, const Color* color);
 
 
-        const VertexDeclaration* getVertexDeclaration(bvertex_format fmt) const
-        {
-            return instance->getVertexDeclaration(fmt);
-        }
+        const VertexDeclaration* getVertexDeclaration(bvertex_format fmt) const;
 
 
-        void setDefaultSettings()
-        {
+        void setDefaultSettings();
 
 
-        }
+        void setRenderTarget(spNativeTexture);
 
 
-        void setRenderTarget(spNativeTexture)
-        {
+        spNativeTexture getRenderTarget() const OVERRIDE;
 
 
-        }
+        void setShaderProgram(ShaderProgram* program);
 
 
-        void setShaderProgram(ShaderProgram* program)
-        {
-            current().program = program;
-        }
+        void setTexture(int sampler, spNativeTexture texture);
 
 
-        void setTexture(int sampler, spNativeTexture texture)
-        {
-            current().textures[sampler] = texture;
-        }
+        void setState(STATE state, unsigned int value);
 
 
-        void setState(STATE state, unsigned int value)
-        {
-            current().states[state] = value;
-        }
+        void addUni(const char *id, cached_batch::uni::type tp, const void* ptr, int sz);
 
 
-        void setBlendFunc(BLEND_TYPE src, BLEND_TYPE dest)
-        {
-            current().blendSrc = src;
-            current().blendDest = dest;
-        }
+        void setUniformInt(const char* id, int v);
 
 
-        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData,  unsigned int numVertices)
-        {
-            current().vdecl = decl;
-            current().pt = pt;
-            current().numVertices = numVertices;
-            current().vertices.assign((const char*)verticesData, (const char*)verticesData + current().vdecl->size * numVertices);
-            _batches.push_back(cached_batch());
+        void setUniform(const char* id, const Vector4* v, int num);
 
 
-        }
+        void setUniform(const char* id, const Vector3* v, int num);
 
 
-        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData,  unsigned int numVertices, const unsigned short* indicesData, unsigned int numIndices)
-        {
-            current().vdecl = decl;
-            current().pt = pt;
-            current().numVertices = numVertices;
-            current().numIndices = numIndices;
-            current().vertices.assign((const char*)verticesData, (const char*)verticesData + decl->size * numVertices);
-            current().indices.assign(indicesData, indicesData + numIndices);
-
-            const vertexPCT2* v = (const vertexPCT2*)(&current().vertices.front());
-            if (_batches.size() == 1)
-            {
-                OX_ASSERT(current().vertices.size());
-                _bounds = RectF(v->x, v->y, 0, 0);
-            }
+        void setUniform(const char* id, const Vector2* v, int num);
 
 
-            size_t num = current().vertices.size() / current().vdecl->size;
+        void setUniform(const char* id, const Matrix* v);
 
 
-            for (size_t i = 0; i != num; ++i)
-            {
-                v = (const vertexPCT2*)(&current().vertices.front() + current().vdecl->size * i);
-                RectF f(v->x, v->y, 0, 0);
-                _bounds.unite(f);
-            }
+        void setUniform(const char* id, float v);
 
 
+        void setBlendFunc(BLEND_TYPE src, BLEND_TYPE dest);
 
 
-            _batches.push_back(cached_batch());
-        }
+        void setScissorRect(const Rect*);
+        bool getScissorRect(Rect&) const OVERRIDE;
 
 
-        void render(const AffineTransform& transform)
-        {
-            for (batches::iterator i = _batches.begin(); i != _batches.end(); ++i)
-            {
-                const cached_batch& b = *i;
-                if (!b.program)
-                    break;
-                if (!b.vdecl)
-                    break;
-
-                size_t num = b.vertices.size() / b.vdecl->size;
-
-                std::vector<char> modified = b.vertices;
-                for (size_t i = 0; i != num; ++i)
-                {
-                    vertexPCT2* v = (vertexPCT2*)(&modified.front() + b.vdecl->size * i);
-                    Vector2 np = transform.transform(Vector2(v->x, v->y));
-                    v->x = np.x;
-                    v->y = np.y;
-                }
-
-                for (int i = 0; i < cached_batch::MAX_TEXTURES; ++i)
-                    instance->setTexture(i, b.textures[i]);
-
-                instance->setShaderProgram(b.program);
-                instance->setBlendFunc(b.blendSrc, b.blendDest);
-                for (int i = 0; i < STATE_NUM; ++i)
-                    instance->setState((STATE)i, b.states[i]);
-                if (b.numIndices)
-                    instance->draw(b.pt, b.vdecl, &modified.front(), b.numVertices, &b.indices.front(), b.numIndices);
-                else
-                    instance->draw(b.pt, b.vdecl, &modified.front(), b.numVertices);
-            }
-        }
+        void nextBatch();
+
+        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData,  unsigned int numVertices);
+
+        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData,  unsigned int numVertices, const unsigned short* indicesData, unsigned int numIndices);
+
+        void render(const AffineTransform& m);
+        void transform(const AffineTransform& m);
+
+        spNativeTexture rt;
     };
     };
 
 
 
 
     class TreeInspectorPreview: public Sprite
     class TreeInspectorPreview: public Sprite
     {
     {
     public:
     public:
-        TreeInspectorPreview(TreeInspector* tree);
+        TreeInspectorPreview();
         ~TreeInspectorPreview();
         ~TreeInspectorPreview();
 
 
-        void init(spActor item);
+        void init(spActor item, const Vector2& size, bool tree);
 
 
         void doRender(RenderState const& parentRenderState);
         void doRender(RenderState const& parentRenderState);
 
 
     private:
     private:
+        void doUpdate(const UpdateState& us);
         friend class TreeInspector;
         friend class TreeInspector;
         //bool _onEvent(const EventState &es);
         //bool _onEvent(const EventState &es);
 
 
-        VideoDriverCache _videoCache;
-        AffineTransform _cacheTransform;
+        Vector2 render2cache(spActor item, const Vector2& size,  bool child);
 
 
-        Rect _getItemRect();
+        VideoDriverCache _videoCache;
 
 
-        Actor* _prevParent;
 
 
-        TreeInspector* _tree;
+        Rect _getItemRect();
         bool _drawChildren;
         bool _drawChildren;
     };
     };
 }
 }