dmuratshin 9 years ago
parent
commit
8ac8a678fc

+ 16 - 22
examples/Demo/src/TestColorFont.h

@@ -8,14 +8,12 @@ public:
     MATX(ColoredShaderMat);
     MATX(ColoredShaderMat);
 
 
     Vector4 uniformBlack = Vector4(0.0f, 0.0f, 0.0f, 1.0f);
     Vector4 uniformBlack = Vector4(0.0f, 0.0f, 0.0f, 1.0f);
-    Vector4 uniformWhite = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
 
 
 
 
     void rehash(size_t& hash) const override
     void rehash(size_t& hash) const override
     {
     {
         data.init(hash);
         data.init(hash);
         hash_combine(hash, uniformBlack.x, uniformBlack.y, uniformBlack.z, uniformBlack.w);
         hash_combine(hash, uniformBlack.x, uniformBlack.y, uniformBlack.z, uniformBlack.w);
-        hash_combine(hash, uniformWhite.x, uniformWhite.y, uniformWhite.z, uniformWhite.w);
     }
     }
 
 
     static bool cmp(const ColoredShaderMat& a, const ColoredShaderMat& b)
     static bool cmp(const ColoredShaderMat& a, const ColoredShaderMat& b)
@@ -23,14 +21,13 @@ public:
         if (!MaterialTX<STDMatData>::cmp(a, b))
         if (!MaterialTX<STDMatData>::cmp(a, b))
             return false;
             return false;
 
 
-        return a.uniformWhite == b.uniformWhite && a.uniformBlack == b.uniformBlack;
+        return a.uniformBlack == b.uniformBlack;
     }
     }
 
 
-    void apply()
+    void apply() override
     {
     {
         MaterialTX<STDMatData>::apply();
         MaterialTX<STDMatData>::apply();
         IVideoDriver::instance->setUniform("_black", uniformBlack);
         IVideoDriver::instance->setUniform("_black", uniformBlack);
-        IVideoDriver::instance->setUniform("_white", uniformWhite);
     }
     }
 };
 };
 
 
@@ -41,18 +38,20 @@ public:
     static void init()
     static void init()
     {
     {
         shader = new UberShaderProgram();
         shader = new UberShaderProgram();
-        shader->init(STDRenderer::uberShaderBody, R"(
+        shader->init(STDRenderer::uberShaderBody,
+                     R"(
                      #define MODIFY_BASE
                      #define MODIFY_BASE
-                     #define DONT_MULT_BY_RESULT_COLOR
+                     #define DONT_MULT_BY_RESULT_COLOR)",
+                     R"(
                      uniform lowp vec4 _black;
                      uniform lowp vec4 _black;
                      uniform lowp vec4 _white;
                      uniform lowp vec4 _white;
                      lowp vec4 modify_base(lowp vec4 base)
                      lowp vec4 modify_base(lowp vec4 base)
                      {
                      {
-                         lowp vec4 black = vec4(_black.rgb, 1.0);
-                         lowp vec4 white = vec4(_white.rgb, 1.0);
-                         return mix(_white, _black, base.r) * base.a;
+                         lowp vec4 black = vec4(_black.rgb, result_color.a);
+                         lowp vec4 white = result_color;
+                         return mix(white, black, base.r) * base.a;
                      }
                      }
-        )");
+            )");
     }
     }
 
 
     static void free()
     static void free()
@@ -65,6 +64,7 @@ public:
     ShaderTextField() : _outer(Color::White)
     ShaderTextField() : _outer(Color::White)
     {
     {
         mat.data._uberShader = shader;
         mat.data._uberShader = shader;
+        mat.uniformBlack = _outer.toVector();
         _mat = mc().cache(mat);
         _mat = mc().cache(mat);
     }
     }
 
 
@@ -76,22 +76,15 @@ public:
     void setOuterColor(const Color& v)
     void setOuterColor(const Color& v)
     {
     {
         _outer = v;
         _outer = v;
+        mat.uniformBlack = _outer.toVector();
+
+        setMat(mc().cache(mat));
     }
     }
 
 
     typedef Property<Color, const Color&, ShaderTextField, &ShaderTextField::getOuterColor, &ShaderTextField::setOuterColor>   TweenOuterColor;
     typedef Property<Color, const Color&, ShaderTextField, &ShaderTextField::getOuterColor, &ShaderTextField::setOuterColor>   TweenOuterColor;
 
 
 private:
 private:
     Color _outer;
     Color _outer;
-    unsigned char _adata;
-
-    void setUniforms(IVideoDriver* driver, ShaderProgram* prog)
-    {
-        Color q(_adata, _adata, _adata, _adata);
-        Vector4 c = (_outer * q).toVector();
-        driver->setUniform("_black", c);
-        c = (getColor() * _style.color * q).toVector();
-        driver->setUniform("_white", c);
-    }
 };
 };
 
 
 DECLARE_SMART(ShaderTextField, spShaderTextField);
 DECLARE_SMART(ShaderTextField, spShaderTextField);
@@ -123,8 +116,9 @@ public:
         txt->setText("1234567890");
         txt->setText("1234567890");
         txt->setPosition(getStage()->getSize() / 2);
         txt->setPosition(getStage()->getSize() / 2);
         txt->setOuterColor(Color::White);
         txt->setOuterColor(Color::White);
+        txt->setKerning(5);
         txt->addTween(ShaderTextField::TweenOuterColor(Color::Black), 4000, -1, true, 2000);
         txt->addTween(ShaderTextField::TweenOuterColor(Color::Black), 4000, -1, true, 2000);
-        txt->addTween(TextField::TweenColor(Color::Magenta), 5000, -1, true);
+        txt->addTween(ShaderTextField::TweenColor(Color::Magenta), 5000, -1, true);
     }
     }
 
 
     ~TestColorFont()
     ~TestColorFont()

+ 2 - 2
examples/Demo/src/TestUserShader.h

@@ -39,10 +39,10 @@ public:
 
 
     void _start(Actor& actor) override
     void _start(Actor& actor) override
     {
     {
-        upd(actor, Vector4(0,0,0,0));
+        upd(actor, Vector4(0, 0, 0, 0));
     }
     }
 
 
-    void upd(Actor& actor, const Vector4 &val)
+    void upd(Actor& actor, const Vector4& val)
     {
     {
         Sprite& spr = (Sprite&)actor;
         Sprite& spr = (Sprite&)actor;
 
 

+ 7 - 1
oxygine/src/oxygine/TextField.cpp

@@ -188,6 +188,12 @@ namespace oxygine
         needRebuild();
         needRebuild();
     }
     }
 
 
+    void TextField::matChanged()
+    {
+        log::warning("not optimal");
+        needRebuild();
+    }
+
     void TextField::setText(const std::string& str)
     void TextField::setText(const std::string& str)
     {
     {
         _flags &= ~flag_html;
         _flags &= ~flag_html;
@@ -328,7 +334,7 @@ namespace oxygine
                 _root = new text::TextNode(_text.c_str());
                 _root = new text::TextNode(_text.c_str());
             }
             }
 
 
-            text::Aligner rd(_style, _mat->data , font, scale, getSize());
+            text::Aligner rd(_style, _mat, font, scale, getSize());
             rd.begin();
             rd.begin();
             _root->resize(rd);
             _root->resize(rd);
             rd.end();
             rd.end();

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

@@ -122,6 +122,7 @@ namespace oxygine
 
 
         void needRebuild();
         void needRebuild();
         void sizeChanged(const Vector2& size) override;
         void sizeChanged(const Vector2& size) override;
+        void matChanged() override;
     };
     };
 }
 }
 
 

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

@@ -94,8 +94,12 @@ namespace oxygine
         _mat = _mat->clone();
         _mat = _mat->clone();
         _mat->data._blend = mode;
         _mat->data._blend = mode;
         _mat = mc().cache(*_mat.get());
         _mat = mc().cache(*_mat.get());
-
-        blendModeChanged(mode);
+        matChanged();
     }
     }
 
 
+    void VStyleActor::setMat(spSTDMaterialX mat)
+    {
+        _mat = mat;
+        matChanged();
+    }
 }
 }

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

@@ -47,10 +47,11 @@ namespace oxygine
 
 
         bool getBounds(RectF& b) const  override { b = getDestRect();  return true; }
         bool getBounds(RectF& b) const  override { b = getDestRect();  return true; }
 
 
+        void                    setMat(spSTDMaterialX mat);
         spSTDMaterialX _mat;
         spSTDMaterialX _mat;
 
 
     protected:
     protected:
-        virtual void blendModeChanged(blend_mode) {}
+        virtual void matChanged() {}
         VisualStyle _vstyle;
         VisualStyle _vstyle;
 
 
 
 

File diff suppressed because it is too large
+ 0 - 1
oxygine/src/oxygine/core/system_data.cpp


+ 2 - 1
oxygine/src/oxygine/text_utils/Aligner.cpp

@@ -8,7 +8,8 @@ namespace oxygine
     {
     {
 #define GSCALE 1
 #define GSCALE 1
 
 
-        Aligner::Aligner(const TextStyle& Style, const STDMatData& md, const Font* font, float gscale, const Vector2& size): width((int)size.x), height((int)size.y), _x(0), _y(0), _lineWidth(0), bounds(0, 0, 0, 0), style(Style), _scale(gscale), _font(font), data(md)
+        Aligner::Aligner(const TextStyle& Style, spSTDMaterialX mt, const Font* font, float gscale, const Vector2& size): width((int)size.x), height((int)size.y), _x(0), _y(0), _lineWidth(0),
+            bounds(0, 0, 0, 0), style(Style), _scale(gscale), _font(font), mat(mt)
         {
         {
             //log::messageln("gscale %f, adjScale %f globscale %f, %d %f", gscale, _globalScale, _fontSize, fs);
             //log::messageln("gscale %f, adjScale %f globscale %f, %d %f", gscale, _globalScale, _fontSize, fs);
             _line.reserve(50);
             _line.reserve(50);

+ 2 - 2
oxygine/src/oxygine/text_utils/Aligner.h

@@ -30,7 +30,7 @@ namespace oxygine
         class Aligner
         class Aligner
         {
         {
         public:
         public:
-            Aligner(const TextStyle& style, const STDMatData& md, const Font* font, float gscale, const Vector2& size);
+            Aligner(const TextStyle& style, spSTDMaterialX mat, const Font* font, float gscale, const Vector2& size);
             ~Aligner();
             ~Aligner();
 
 
 
 
@@ -50,7 +50,7 @@ namespace oxygine
             int height;
             int height;
             int options;
             int options;
 
 
-            const STDMatData& data;
+            spSTDMaterialX mat;
 
 
             const Font* _font;
             const Font* _font;
 
 

+ 5 - 4
oxygine/src/oxygine/text_utils/Node.cpp

@@ -5,6 +5,7 @@
 #include "../RenderState.h"
 #include "../RenderState.h"
 #include "../AnimationFrame.h"
 #include "../AnimationFrame.h"
 #include "../res/ResFont.h"
 #include "../res/ResFont.h"
+#include "STDMaterial.h"
 
 
 namespace oxygine
 namespace oxygine
 {
 {
@@ -199,12 +200,12 @@ namespace oxygine
                             }
                             }
                         }
                         }
 
 
-                        MaterialTX<STDMatData> mat;
-                        mat.data = rd.data;
-                        mat.data._base = gl->texture;
+                        spSTDMaterialX mat = rd.mat->clone();
 
 
+                        mat->data._base = gl->texture;
 
 
-                        s.materialX = mc().cache(mat);
+
+                        s.materialX = mc().cache(*mat.get());
                     }
                     }
                     ++i;
                     ++i;
                     if (i < 0)
                     if (i < 0)

Some files were not shown because too many files changed in this diff