Browse Source

removing SDF from oxygine -> moved to Demo

dmuratshin 8 years ago
parent
commit
ffbc9cafc8

+ 70 - 7
examples/Demo/src/TestSignedDistanceFont.h

@@ -1,6 +1,66 @@
 #pragma once
 #include "test.h"
 
+DECLARE_SMART(SDFMaterial, spSDFMaterial);
+class SDFMaterial : public STDMaterialX
+{
+public:
+    MATX(SDFMaterial);
+
+
+    Color outlineColor = Color(255, 255, 255, 255);
+    float offset = 0.5f;
+    float outline = 0.4f;
+
+
+    static void initMaterial()
+    {
+
+    }
+
+    static void freeMaterial()
+    {
+
+    }
+
+    void init() override 
+    {
+        _flags = UberShaderProgram::SDF;
+        //if (outlineOffset < offset)
+        _flags |= UberShaderProgram::SDF_OUTLINE;
+    }
+
+
+    void rehash(size_t& hash) const override
+    {
+        hash_combine(hash, this);
+    }
+
+    static bool cmp(const SDFMaterial& a, const SDFMaterial& b)
+    {
+        if (!STDMaterialX::cmp(a, b))
+            return false;
+
+        return a.outlineColor == b.outlineColor && a.offset == b.offset && a.outline == b.outline;
+    }
+
+    void xapply() override 
+    {
+        STDMaterialX::xapply();
+
+        const AffineTransform &tr = STDRenderer::getCurrent()->getTransform();
+        float scale = sqrt(tr.a *tr.a + tr.c * tr.c);
+        float contrast = 3.0f + scale * 8.0f;
+
+        Vector4 sdfParams(offset, contrast, outline, contrast);
+        IVideoDriver::instance->setUniform("sdf_params", sdfParams);
+
+        Vector4 color = outlineColor.toVector();
+        IVideoDriver::instance->setUniform("sdf_outline_color", color);
+        
+    }
+};
+
 class TestSignedDistanceFont : public Test
 {
 public:
@@ -43,15 +103,13 @@ public:
 
         st.multiline = true;
 
-        st.outlineColor = Color::White;
-        st.outline = 0.1f;
-
         txt->setStyle(st);
         txt->setColor(Color::CornflowerBlue);
         txt->setText("The quick brown fox jumps over the lazy dog. 1234567890.");
         txt->setPosition(getStage()->getSize() / 2);
         txt->setWidth(getStage()->getWidth() / 2);
         txt->setAnchor(0.5f, 0.5f);
+        txt->addTween(Actor::TweenRotationDegrees(360), 10000, -1);
 
         SDFMaterial sdf;
 
@@ -74,10 +132,12 @@ public:
 
     void clicked(string id)
     {
+        spSDFMaterial mat = safeSpCast<SDFMaterial>(_txt->_mat);
+
         if (id == "outline+")
-            _txt->setOutline(_txt->getOutline() + 0.01f);
+            mat->outline += 0.01f;
         if (id == "outline-")
-            _txt->setOutline(_txt->getOutline() - 0.01f);
+            mat->outline -= 0.01f;
 
         if (id == "scale+")
             _txt->addTween(TweenScale(_txt->getScale() * 1.5f), 300);
@@ -85,9 +145,12 @@ public:
             _txt->addTween(TweenScale(_txt->getScale() / 1.5f), 300);
 
         if (id == "weight+")
-            _txt->setWeight(_txt->getWeight() - 0.01f);
+            mat->offset += 0.01f;
         if (id == "weight-")
-            _txt->setWeight(_txt->getWeight() + 0.01f);
+            mat->offset -= 0.01f;
+
+        _txt->setMat(mat);
+
     }
 
     void toggleClicked(string id, const toggle* data)

+ 0 - 5
oxygine/src/oxygine/Font.cpp

@@ -95,9 +95,4 @@ namespace oxygine
     {
         return _scale;
     }
-
-    bool Font::isSDF() const
-    {
-        return _sdf;
-    }
 }

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

@@ -61,7 +61,6 @@ namespace oxygine
         int             getBaselineDistance() const;
         int             getSize() const;
         float           getScale() const;
-        bool            isSDF() const;
 
     protected:
         const glyph* findGlyph(int code, const glyphOptions& opt) const;

+ 1 - 20
oxygine/src/oxygine/STDMaterial.cpp

@@ -165,26 +165,7 @@ namespace oxygine
 
         //renderer->setBlendMode(tf->getBlendMode());
         renderer->setTransform(rs.transform);
-
-        int sdfSize;
-        if (tf->getFont()->isSDF(sdfSize))
-        {
-            if (tf->getFontSize())
-                scale = scale * tf->getFontSize() / sdfSize;
-
-            float contrast = 3.0f + scale * 8.0f;
-            float offset = tf->getWeight();
-            float outline = tf->getWeight() - tf->getOutline();
-
-            renderer->applySDF(contrast, offset, tf->getOutlineColor(), outline);
-            root->draw(dc);
-            renderer->endSDF();
-        }
-        else
-        {
-            renderer->applySimpleMode(true);
-            root->draw(dc);
-        }
+        root->draw(dc);
     }
 
     void STDMaterial::doRender(ColorRectSprite* sprite, const RenderState& rs)

+ 0 - 78
oxygine/src/oxygine/STDRenderer.cpp

@@ -757,46 +757,6 @@ namespace oxygine
         _uberShader = pr;
     }
 
-    void STDRenderer::applySDF(float contrast, float offset, const Color& outlineColor, float outlineOffset)
-    {
-        if (_alpha)
-        {
-            drawBatch();
-            _shaderFlags &= ~UberShaderProgram::SEPARATE_ALPHA;
-            _alpha = 0;
-        }
-
-        unsigned int shaderFlags = _shaderFlags;
-        shaderFlags |= UberShaderProgram::SDF;
-
-        if (outlineOffset < offset)
-            shaderFlags |= UberShaderProgram::SDF_OUTLINE;
-
-        if (_shaderFlags != shaderFlags)
-        {
-            drawBatch();
-        }
-
-        _shaderFlags = shaderFlags;
-
-        ShaderProgram* prog = _uberShader->getShaderProgram(_shaderFlags);
-        setShader(prog);
-
-        Vector4 c = outlineColor.toVector();
-        _driver->setUniform("sdf_outline_color", c);
-
-        c = Vector4(offset, contrast, outlineOffset, contrast);
-        _driver->setUniform("sdf_params", c);
-    }
-
-    void STDRenderer::endSDF()
-    {
-        drawBatch();
-        _shaderFlags &= ~(UberShaderProgram::SDF | UberShaderProgram::SDF_OUTLINE);
-
-        ShaderProgram* prog = _uberShader->getShaderProgram(_shaderFlags);
-        setShader(prog);
-    }
 
     void STDRenderer::applySimpleMode(bool basePremultiplied)
     {
@@ -832,42 +792,4 @@ namespace oxygine
         fillQuadT(v, src, dest, _transform, color);
         addVertices(v, sizeof(v));
     }
-
-
-    void SDFMaterial::init()
-    {
-        _flags = UberShaderProgram::SDF;
-        //if (outlineOffset < offset)
-        _flags |= UberShaderProgram::SDF_OUTLINE;
-        outlineParams = Vector4(0.25f, 6.25f, 0.15f, 12.5f);
-        outlineColor = Vector4(1, 1, 1, 1);
-    }
-
-    void SDFMaterial::rehash(size_t& hash) const
-    {
-        STDMaterialX::rehash(hash);
-        hash_combine(hash, outlineColor.x, outlineColor.y, outlineColor.z, outlineColor.w);
-        hash_combine(hash, outlineParams.x, outlineParams.y, outlineParams.z, outlineParams.w);
-    }
-
-    bool SDFMaterial::cmp(const SDFMaterial& a, const SDFMaterial& b)
-    {
-        if (!STDMaterialX::cmp(a, b))
-            return false;
-
-        return a.outlineColor == b.outlineColor && a.outlineParams == b.outlineParams;
-    }
-
-    void SDFMaterial::xapply()
-    {
-        STDMaterialX::xapply();
-        IVideoDriver::instance->setUniform("sdf_outline_color", outlineColor);
-        IVideoDriver::instance->setUniform("sdf_params", outlineParams);
-    }
-
-    void SDFMaterial::render(const Color& c, const RectF& src, const RectF& dest)
-    {
-        STDRenderer::getCurrent()->draw(c, src, dest);
-    }
-
 }

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

@@ -5,25 +5,6 @@
 
 namespace oxygine
 {
-    class SDFMaterial : public STDMaterialX
-    {
-    public:
-        MATX(SDFMaterial);
-
-        void init() override;
-
-        Vector4 outlineColor = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
-        Vector4 outlineParams = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
-
-
-        void rehash(size_t& hash) const override;
-
-        static bool cmp(const SDFMaterial& a, const SDFMaterial& b);
-
-        void xapply() override;
-        void render(const Color& c, const RectF& src, const RectF& dest) override;
-    };
-
     class STDRenderer : public IElementRenderer
     {
     public:
@@ -61,6 +42,7 @@ namespace oxygine
         const Matrix&   getViewProjection() const;
         IVideoDriver*   getDriver();
         unsigned int    getShaderFlags() const;
+        const AffineTransform&  getTransform() const { return _transform; }
         const VertexDeclaration* getVertexDeclaration() const { return _vdecl; }
 
         void setShaderFlags(int);
@@ -81,9 +63,6 @@ namespace oxygine
         void drawBatch();
 
 
-        void applySDF(float contrast, float offset, const Color& outlineColor, float outlineOffset);
-        void endSDF();
-
         void applySimpleMode(bool basePremultiplied);
         /**used in pair with applySimpleMode/applySDF, fast, don't have excess checks*/
         void draw(const spNativeTexture& texture, unsigned int color, const RectF& src, const RectF& dest) override;

+ 0 - 55
oxygine/src/oxygine/TextField.cpp

@@ -133,21 +133,6 @@ namespace oxygine
         needRebuild();
     }
 
-    void TextField::setOutlineColor(const Color& c)
-    {
-        _style.outlineColor = c;
-    }
-
-    void TextField::setOutline(float v)
-    {
-        _style.outline = v;
-    }
-
-    void TextField::setWeight(float v)
-    {
-        _style.weight = v;
-    }
-
     void TextField::setHAlign(TextStyle::HorizontalAlign align)
     {
         _style.hAlign = align;
@@ -265,26 +250,11 @@ namespace oxygine
         return _style.kerning;
     }
 
-    const Color& TextField::getOutlineColor() const
-    {
-        return _style.outlineColor;
-    }
-
-    float TextField::getOutline() const
-    {
-        return _style.outline;
-    }
-
     const oxygine::Color& TextField::getStyleColor() const
     {
         return _style.color;
     }
 
-    float TextField::getWeight() const
-    {
-        return _style.weight;
-    }
-
     float TextField::getBaselineScale() const
     {
         return _style.baselineScale;
@@ -350,29 +320,6 @@ namespace oxygine
 
             _textRect = rd.bounds;
         }
-        else
-        {
-            int sdfSize;
-            if (_style.font && _style.font->isSDF(sdfSize))
-            {
-                SDFMaterial *sdf = safeCast<SDFMaterial*>(_mat.get());
-                static float lastGS = 0;
-                if (lastGS != globalScale)
-                {
-                    if (getFontSize())
-                        scale = scale * getFontSize() / sdfSize;
-
-                    float contrast = 3.0f + scale * 8.0f;
-                    float offset = getWeight();
-                    float outline = getWeight() - getOutline();
-
-                    Vector4 vvv(offset, contrast, outline, contrast);
-                    sdf->outlineParams = vvv;
-                    matChanged();
-                }
-                lastGS = globalScale;
-            }
-        }
 
         return _root;
     }
@@ -430,8 +377,6 @@ namespace oxygine
             stream << " linesOffset=" << s.linesOffset;
         if (!onlydiff || def.fontSize != s.fontSize)
             stream << " fontSize=" << s.fontSize;
-        if (!onlydiff || def.outline != s.outline)
-            stream << " outline=" << s.outline;
         if (s.font)
         {
             stream << " font='" << s.font->getName() << "'";

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

@@ -71,14 +71,7 @@ namespace oxygine
 
         /**Overwrites TextStyle font.*/
         void setFont(const ResFont* rs);
-
-        /**Overwrites TextStyle outlineColor. works only with SD font*/
-        void setOutlineColor(const Color&);
-        /**Overwrites TextStyle outline. works only with SD font*/
-        void setOutline(float v);
-        /**Overwrites TextStyle outline. works only with SD font*/
-        void setWeight(float w);
-
+        
         void setStyle(const TextStyle& st);
         /**Changes text utf-8 string*/
         void setText(const std::string& str);
@@ -96,9 +89,6 @@ namespace oxygine
         bool isOn(const Vector2& localPosition, float localScale = 1.0f) override;
 
 
-        typedef Property<Color, const Color&, TextField, &TextField::getOutlineColor, &TextField::setOutlineColor>  TweenOutlineColor;
-
-
     public:
 
         std::string dump(const dumpOptions& options) const override;

+ 0 - 13
oxygine/src/oxygine/TextStyle.h

@@ -34,9 +34,6 @@ namespace oxygine
             multiline(false),
             fontSize(0),
             breakLongWords(false),
-            outline(0.0f),
-            outlineColor(Color::Black),
-            weight(0.5f),
             baselineScale(1.0f),
             options(0) {}
 
@@ -52,14 +49,7 @@ namespace oxygine
         bool breakLongWords;//works with multiline flag. breakLongWords = false doesn't allow to break too long words
         Color color;
 
-
-
         int fontSize;
-
-
-        float outline;//works only with SD fonts, disabled by default = 0.0f, 0.5 - max outline
-        Color outlineColor;//works only with SD fonts
-        float weight;//works only with SD fonts, font weight, default = 0.5f,  0.0 - bold, 1.0 - thin
         float baselineScale;//baseline distance multiplier
 
 
@@ -86,9 +76,6 @@ namespace oxygine
 
         TextStyle withFontSize(int size) const { TextStyle st = *this; st.fontSize = size; return st; }
 
-        TextStyle withOutline(float outline) const { TextStyle st = *this; st.outline = outline; return st; }
-        TextStyle withOutlineColor(const Color& color) const { TextStyle st = *this; st.outlineColor = color; return st; }
-        TextStyle withWeight(float weight) const { TextStyle st = *this; st.weight = weight; return st; }
         TextStyle withOptions(unsigned int opt) const { TextStyle st = *this; st.options = opt; return st; }
     };
 

+ 0 - 1
oxygine/src/oxygine/res/ResFont.h

@@ -12,7 +12,6 @@ namespace oxygine
         ResFont(): _size(0) {}
 
         virtual const Font* getFont(const char* name = 0, int size = 0) const = 0;
-        virtual bool isSDF(int& size) const { size = 0; return false; }
         int getSize() const { return _size; }
 
         virtual const Font* getClosestFont(float worldScale, int styleFontSize, float& resScale) const;

+ 1 - 8
oxygine/src/oxygine/res/ResFontBM.cpp

@@ -64,14 +64,7 @@ namespace oxygine
     {
         cleanup();
     }
-
-
-    bool ResFontBM::isSDF(int& size) const
-    {
-        size = _font->getSize();
-        return _sdf;
-    }
-
+    
     const oxygine::Font* ResFontBM::getClosestFont(float worldScale, int styleFontSize, float& resScale) const
     {
         if (!styleFontSize)

+ 0 - 3
oxygine/src/oxygine/res/ResFontBM.h

@@ -23,9 +23,6 @@ namespace oxygine
         void cleanup();
 
         const Font* getFont(const char* name = 0, int size = 0) const override;
-
-        bool isSDF(int& size) const override;
-
         const Font* getClosestFont(float worldScale, int styleFontSize, float& resScale) const override;
 
     private:

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

@@ -24,7 +24,7 @@ namespace oxygine
             int code;
             glyph gl;
             RectF destRect;
-            spMaterialX mat;
+            spSTDMaterialX mat;
         };
 
         class Aligner

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

@@ -185,8 +185,9 @@ namespace oxygine
                     Symbol& s = _data[i];
 
                     spSTDMaterialX m = mat.clone();
+                    m->_base = s.mat->_base;
 
-                    s.mat = mc().cache(mat);
+                    s.mat = mc().cache(*m.get());
                 }
             }
         }