Ver Fonte

improved material

dm há 7 anos atrás
pai
commit
ea1a6e381b

+ 7 - 0
oxygine/src/oxygine/Material.cpp

@@ -81,6 +81,13 @@ namespace oxygine
     }
     }
 
 
 
 
+    spSTDMaterial STDMaterial::cloneDefaultShader() const
+    {
+        STDMaterial mat(*this);
+        mat._uberShader = &STDRenderer::uberShader;
+        return mc().cache(mat);
+    }
+
     Material::Material(const Material& other)
     Material::Material(const Material& other)
     {
     {
         _hash = other._hash;
         _hash = other._hash;

+ 5 - 2
oxygine/src/oxygine/Material.h

@@ -15,6 +15,7 @@ namespace oxygine
         init();\
         init();\
     }\
     }\
     void copyTo(cl &d) const{d = *this;}\
     void copyTo(cl &d) const{d = *this;}\
+    void copyFrom(const cl &d) {*this = d;}\
     cl* clone() const override {return new cl(*this);}\
     cl* clone() const override {return new cl(*this);}\
     void update(size_t &hash, compare &cm) const override {\
     void update(size_t &hash, compare &cm) const override {\
         typedef bool (*fn)(const cl&a, const cl&b);\
         typedef bool (*fn)(const cl&a, const cl&b);\
@@ -80,6 +81,7 @@ namespace oxygine
         void rehash(size_t& hash) const override {}
         void rehash(size_t& hash) const override {}
     };
     };
 
 
+    DECLARE_SMART(STDMaterial, spSTDMaterial);
     class STDMaterial: public Material
     class STDMaterial: public Material
     {
     {
     public:
     public:
@@ -102,7 +104,8 @@ namespace oxygine
 
 
         void render(const AffineTransform& tr, const Color& c, const RectF& src, const RectF& dest) override;
         void render(const AffineTransform& tr, const Color& c, const RectF& src, const RectF& dest) override;
         void render(const Color& c, const RectF& src, const RectF& dest) override;
         void render(const Color& c, const RectF& src, const RectF& dest) override;
-    };
 
 
-    DECLARE_SMART(STDMaterial, spSTDMaterial);
+        spSTDMaterial cloneDefaultShader() const;
+    };
+    
 }
 }

+ 6 - 0
oxygine/src/oxygine/VisualStyle.cpp

@@ -131,4 +131,10 @@ namespace oxygine
         _mat = mat;
         _mat = mat;
         matChanged();
         matChanged();
     }
     }
+
+    void VStyleActor::resetMaterial()
+    {
+        setMaterial(_mat->cloneDefaultShader());
+    }
+
 }
 }

+ 1 - 0
oxygine/src/oxygine/VisualStyle.h

@@ -51,6 +51,7 @@ namespace oxygine
         typedef Property<Color, const Color&, VStyleActor, &VStyleActor::getAddColor, &VStyleActor::setAddColor> TweenAddColor;
         typedef Property<Color, const Color&, VStyleActor, &VStyleActor::getAddColor, &VStyleActor::setAddColor> TweenAddColor;
 
 
         void                    setMaterial(spSTDMaterial mat);
         void                    setMaterial(spSTDMaterial mat);
+        void                    resetMaterial();
         spSTDMaterial _mat;
         spSTDMaterial _mat;
 
 
     protected:
     protected: