dmuratshin 8 anos atrás
pai
commit
4f437b9b0c

+ 22 - 36
examples/Demo/src/TestUserShader.h

@@ -1,54 +1,33 @@
 #pragma once
 #include "test.h"
 
-DECLARE_SMART(ShaderSprite, spShaderSprite);
-
-class ShaderSprite: public Sprite
+class MyTestMat : public MaterialTX<STDMatData>
 {
 public:
-    ShaderSprite(): _program(0), _val(0.5f, 0.5f, 0.5f, 0)
-    {
-
-    }
-
-    void setShaderProgram(UberShaderProgram* p)
-    {
-        _program = p;
-    }
-
-    const Vector4& getVal() const
-    {
-        return _val;
-    }
+    Vector4 uniform;
 
-    void setVal(const Vector4& v)
+    void init(size_t& hash)
     {
-        _val = v;
+//        STDMatData::init(hash);
+  //      hash_combine(hash, uniform.x, uniform.y, uniform.z, uniform.w);
     }
 
-    typedef Property<Vector4, const Vector4&, ShaderSprite, &ShaderSprite::getVal, &ShaderSprite::setVal>   TweenVal;
-
-private:
-    Vector4 _val;
-    UberShaderProgram* _program;
-    void setUniforms(IVideoDriver* driver, ShaderProgram* prog)
+    bool isSame(const MyTestMat& other)
     {
-        driver->setUniform("userValue", _val);
+    //    if (!STDMatData::isSame(other))
+      //      return false;
+        return uniform == other.uniform;
     }
 
-    void doRender(const RenderState& rs) override
+    void apply()
     {
-        /* _program->setShaderUniformsCallback(CLOSURE(this, &ShaderSprite::setUniforms));
-         STDRenderer* renderer = safeCast<STDRenderer*>(rs.renderer);
-         renderer->setUberShaderProgram(_program);
-         Sprite::doRender(rs);
-         renderer->setUberShaderProgram(&Renderer::uberShader);
-
-         _program->setShaderUniformsCallback(UberShaderProgram::ShaderUniformsCallback());*/
+        //STDMatData::apply();
+        IVideoDriver::instance->setUniform("userValue", uniform);
     }
 };
 
-class TweenShader: public Tween, public Material
+
+class TweenShader: public Tween//, public Material
 {
 public:
     UberShaderProgram* _program;
@@ -63,7 +42,12 @@ public:
     void _start(Actor& actor) override
     {
         actor.setName("zzz");
-        actor.setMaterial(this);
+        Sprite& spr = (Sprite&)actor;
+
+//        MyTestMat data;
+        //data = spr._mat->_data;
+        //spr._mat = mc().add(data);
+        //actor.setMaterial(this);
     }
 
     void _update(Actor& actor, const UpdateState& us) override
@@ -81,6 +65,7 @@ public:
         driver->setUniform("userValue", _val);
     }
 
+    /*
     void apply(Material* prev) override
     {
         STDRenderer* renderer = STDRenderer::getCurrent();
@@ -98,6 +83,7 @@ public:
         STDRenderer* renderer = STDRenderer::getCurrent();
         renderer->drawBatch();
     }
+    */
 };
 
 

+ 1 - 1
examples/Demo/src/main.cpp

@@ -63,7 +63,7 @@ void run()
 
 
     // Create the stage. Stage is a root node for all updateable and drawable objects
-    Stage::instance = new Stage(true);
+    Stage::instance = new Stage(false);
     Point size = core::getDisplaySize();
     getStage()->setSize(size);
 

+ 22 - 5
oxygine/src/oxygine/MaterialX.cpp

@@ -7,7 +7,7 @@ namespace oxygine
 {
     spMaterialX currentMat;
 
-    bool STDMatData::operator==(const STDMatData& b) const
+    bool STDMatData::isSame(const STDMatData& b) const
     {
         if (_base != b._base)
             return false;
@@ -35,10 +35,27 @@ namespace oxygine
 
     void STDMatData::apply()
     {
-        STDRenderer::getCurrent()->setShaderFlags(_flags);
-        STDRenderer::getCurrent()->setTextureNew(UberShaderProgram::SAMPLER_BASE, _base);
-        STDRenderer::getCurrent()->setTextureNew(UberShaderProgram::SAMPLER_ALPHA, _alpha);
-        STDRenderer::getCurrent()->setBlendMode(_blend);
+        STDRenderer* r = STDRenderer::getCurrent();
+        r->setShaderFlags(_flags);
+        r->setTextureNew(UberShaderProgram::SAMPLER_BASE, _base);
+        r->setTextureNew(UberShaderProgram::SAMPLER_ALPHA, _alpha);
+        r->setBlendMode(_blend);
+    }
+
+    MaterialX::MaterialX(const MaterialX& other)
+    {
+        _hash = other._hash;
+        _compare = other._compare;
+    }
+
+    MaterialX::MaterialX(compare cmp) : _hash(0), _compare(cmp)
+    {
+
+    }
+
+    MaterialX::MaterialX() : _hash(0)
+    {
+
     }
 
 }

+ 11 - 11
oxygine/src/oxygine/MaterialX.h

@@ -11,13 +11,9 @@ namespace oxygine
 
         typedef bool(*compare)(const MaterialX* a, const MaterialX* b);
 
-        MaterialX() {}
-        MaterialX(compare cmp) : _hash(0), _compare(cmp) {}
-        MaterialX(const MaterialX& other)
-        {
-            _hash = other._hash;
-            _compare = other._compare;
-        }
+        MaterialX();
+        MaterialX(compare cmp);
+        MaterialX(const MaterialX& other);
 
         size_t _hash;
         compare _compare;
@@ -30,6 +26,12 @@ namespace oxygine
     typedef intrusive_ptr<MaterialX> spMaterialX;
 
 
+    class STDMaterialX : public MaterialX
+    {
+    public:
+
+    };
+
 
     template<class T>
     class MaterialTX : public MaterialX
@@ -53,7 +55,7 @@ namespace oxygine
         template<class C>
         static bool cmp(const MaterialTX<C>& a, const MaterialTX<C>& b)
         {
-            return a._data == b._data;
+            return a._data.isSame(b._data);
         }
 
         void apply() override
@@ -91,10 +93,8 @@ namespace oxygine
         int             _flags;
 
         void init(size_t& hash);
-
         void apply();
-
-        bool operator == (const STDMatData& b) const;
+        bool isSame(const STDMatData& b) const;
     };
 
     typedef intrusive_ptr< MaterialTX<STDMatData> > spSTDMaterialX;

+ 3 - 4
oxygine/src/oxygine/STDRenderer.cpp

@@ -592,7 +592,7 @@ namespace oxygine
     }
 
 
-    void STDRenderer::setTextureNew(int sampler, spNativeTexture t)
+    void STDRenderer::setTextureNew(int sampler, const spNativeTexture& t)
     {
         if (_textures[sampler] == t)
             return;
@@ -606,10 +606,9 @@ namespace oxygine
         if (_program != sp)
         {
             _driver->setShaderProgram(sp);
+            _driver->setUniform("mat", _vp);
             _program = sp;
         }
-
-        _driver->setUniform("mat", STDRenderer::getCurrent()->getViewProjection());
     }
 
     void STDRenderer::add(const spMaterialX& mat, vertexPCT2 vert[4])
@@ -716,7 +715,7 @@ namespace oxygine
         if (!indices)
             return;
 
-        IVideoDriver::instance->draw(IVideoDriver::PT_TRIANGLES, STDRenderer::getCurrent()->getVertexDeclaration(),
+        IVideoDriver::instance->draw(IVideoDriver::PT_TRIANGLES, _vdecl,
                                      &_vertices.front(), (unsigned int)_vertices.size(),
                                      &STDRenderer::indices16.front(), (unsigned int)indices);
 

+ 1 - 1
oxygine/src/oxygine/STDRenderer.h

@@ -55,7 +55,7 @@ namespace oxygine
         /**Sets World transformation.*/
         void setTransform(const Transform& world);
         void draw(const Color&, const RectF& srcRect, const RectF& destRect);
-        void setTextureNew(int sampler, spNativeTexture t);
+        void setTextureNew(int sampler, const spNativeTexture& t);
 
         /**Draws existing batch immediately.*/
         void drawBatch();

+ 7 - 0
oxygine/src/oxygine/math/Vector4.h

@@ -29,6 +29,7 @@ namespace oxygine
         VectorT4 operator / (T) const;
 
         VectorT3<T> xyz()const;
+        bool operator == (const VectorT4& r) const;
 
         inline T& operator[](int i) {return m[i];}
         inline const T& operator[](int i)const {return m[i];}
@@ -131,6 +132,12 @@ namespace oxygine
         x *= is; y *= is; z *= is; w *= is; return (*this);
     }
 
+    template <class T>
+    bool VectorT4<T>::operator == (const VectorT4& v) const
+    {
+        return x == v.x && y == v.y && z == v.z && w == v.w;
+    }
+
     template <class T>
     VectorT4<T> VectorT4<T>::operator * (T s) const
     {