dmuratshin 8 years ago
parent
commit
708417f378
2 changed files with 67 additions and 7 deletions
  1. 42 6
      examples/Demo/src/TestUserShader.h
  2. 25 1
      oxygine/src/oxygine/MaterialX.h

+ 42 - 6
examples/Demo/src/TestUserShader.h

@@ -1,27 +1,59 @@
 #pragma once
 #include "test.h"
 
+template <class T>
+class IsSame
+{
+public:
+    static bool isSame(const T& a, const T &b)
+    {
+        return a.isSame(b);
+    }
+};
+template <class T>
+bool isSameF(const T &a, const T & b)
+{
+    return a.isSame(b);
+}
+
 class MyTestMat : public MaterialTX<STDMatData>
 {
 public:
     Vector4 uniform;
 
-    void init(size_t& hash)
+    //MyTestMat():MaterialTX<STDMatData>( {}
+    MyTestMat() {}
+    MyTestMat(const MyTestMat &other)
     {
-//        STDMatData::init(hash);
+        _data = other._data;
+        _data.init(_hash);
+
+        typedef bool(*fcmp)(const MyTestMat& a, const MyTestMat& b);
+        fcmp fn = &IsSame<MyTestMat>::isSame;
+        _compare = (compare)(fn);
+
+        hash_combine(_hash, _compare);
+
   //      hash_combine(hash, uniform.x, uniform.y, uniform.z, uniform.w);
     }
 
-    bool isSame(const MyTestMat& other)
+    bool isSame(const MyTestMat& other) const
     {
-    //    if (!STDMatData::isSame(other))
-      //      return false;
+        if (MaterialTX<STDMatData>::cmp(*this, other))
+            return false;
+
         return uniform == other.uniform;
     }
 
+    MyTestMat* clone() const override
+    {
+        return new MyTestMat(*this);
+    }
+    
+
     void apply()
     {
-        //STDMatData::apply();
+        MaterialTX<STDMatData>::apply();
         IVideoDriver::instance->setUniform("userValue", uniform);
     }
 };
@@ -44,6 +76,10 @@ public:
         actor.setName("zzz");
         Sprite& spr = (Sprite&)actor;
 
+        MyTestMat my;
+        my._data = spr._mat->_data;
+
+        spr._mat = mc().add2(my);
 //        MyTestMat data;
         //data = spr._mat->_data;
         //spr._mat = mc().add(data);

+ 25 - 1
oxygine/src/oxygine/MaterialX.h

@@ -19,18 +19,40 @@ namespace oxygine
         compare _compare;
 
         virtual void apply() = 0;
-
+        //virtual void init(size_t &);
         virtual MaterialX* clone() const = 0;
     };
 
     typedef intrusive_ptr<MaterialX> spMaterialX;
 
 
+    /*
     class STDMaterialX : public MaterialX
     {
     public:
+        spNativeTexture _base;
+        spNativeTexture _alpha;
+        blend_mode      _blend;
+        int             _flags;
+
+        void init(size_t& hash) override
+        {
+            hash_combine(hash, _base.get());
+            hash_combine(hash, _alpha.get());
+            hash_combine(hash, (int)_blend);
+            hash_combine(hash, _flags);
+        }
 
+        void apply() override
+        {
+            STDRenderer* r = STDRenderer::getCurrent();
+            r->setShaderFlags(_flags);
+            r->setTextureNew(UberShaderProgram::SAMPLER_BASE, _base);
+            r->setTextureNew(UberShaderProgram::SAMPLER_ALPHA, _alpha);
+            r->setBlendMode(_blend);
+        }
     };
+    */
 
 
     template<class T>
@@ -42,6 +64,8 @@ namespace oxygine
 
         T _data;
 
+        MaterialTX() {}
+
         MaterialTX(const T& data) : _data(data)
         {
             _data.init(_hash);