Example #1
0
        /// <summary>
        /// tess and read result as triangle list index array (for GLES draw element)
        /// </summary>
        /// <param name="tessTool"></param>
        /// <param name="vertex2dCoords"></param>
        /// <param name="contourEndPoints"></param>
        /// <param name="outputCoords"></param>
        /// <param name="vertexCount"></param>
        /// <returns></returns>
        internal static void TessAndAddToMultiPartResult(this TessTool tessTool,
                                                         float[] vertex2dCoords,
                                                         int[] contourEndPoints,
                                                         MultiPartTessResult multipartTessResult,
                                                         out int vertexCount)
        {
            if (!tessTool.TessPolygon(vertex2dCoords, contourEndPoints))
            {
                vertexCount = 0;
                return;
            }
            //-----------------------------
            //results
            //1.
            List <ushort> indexList = tessTool.TessIndexList;
            //2.
            List <TessTempVertex> tempVertexList = tessTool.TempVertexList;

            //3.
            vertexCount = indexList.Count;
            //-----------------------------
            multipartTessResult.BeginPart();
            multipartTessResult.AddTessCoords(vertex2dCoords);
            //append with newly create vertex(from tempVertList)
            int tempVertListCount = tempVertexList.Count;

            for (int i = 0; i < tempVertListCount; ++i)
            {
                TessTempVertex v = tempVertexList[i];
                multipartTessResult.AddTessCoord((float)v.m_X, (float)v.m_Y);
            }
            multipartTessResult.AddVertexIndexList(indexList);
            multipartTessResult.EndPart();
        }
Example #2
0
 public float[] GetAreaTess(ref TessTool tess)
 {
     if (areaTess == null)
     {
         List <Vertex> vertextList = tess.TessPolygon(coordXYs);
         if (vertextList == null)
         {
             tessAreaTriangleCount = 0;
             return(null);
         }
         //-----------------------------
         //switch how to fill polygon
         int     j   = vertextList.Count;
         float[] vtx = new float[j * 2];
         int     n   = 0;
         for (int p = 0; p < j; ++p)
         {
             var v = vertextList[p];
             vtx[n]     = (float)v.m_X;
             vtx[n + 1] = (float)v.m_Y;
             n         += 2;
         }
         //triangle list
         tessAreaTriangleCount = j;
         //-------------------------------------
         return(this.areaTess = vtx);
     }
     return(areaTess);
 }
        internal GLRenderSurface(int width, int height)
        {
            //-------------
            //y axis points upward (like other OpenGL)
            //x axis points to right.
            //please NOTE: left lower corner of the canvas is (0,0)
            //-------------

            this._width  = width;
            this._height = height;
            //setup viewport size,
            //we need W:H ratio= 1:1 , square viewport
            int max = Math.Max(width, height);

            orthoView = MyMat4.ortho(0, max, 0, max, 0, 1); //this make our viewport W:H =1:1

            flipVerticalView = MyMat4.scale(1, -1) * MyMat4.translate(new OpenTK.Vector3(0, -height, 0));
            orthoAndFlip     = orthoView * flipVerticalView;
            //-----------------------------------------------------------------------
            _shareRes           = new ShaderSharedResource();
            _shareRes.OrthoView = orthoView;
            //-----------------------------------------------------------------------
            basicFillShader     = new BasicFillShader(_shareRes);
            smoothLineShader    = new SmoothLineShader(_shareRes);
            rectFillShader      = new RectFillShader(_shareRes);
            gdiImgTextureShader = new GdiImageTextureShader(_shareRes);
            gdiImgTextureWithWhiteTransparentShader = new GdiImageTextureWithWhiteTransparentShader(_shareRes);
            glyphStencilShader        = new GlyphImageStecilShader(_shareRes);
            textureSubPixRendering    = new ImageTextureWithSubPixelRenderingShader(_shareRes);
            blurShader                = new BlurShader(_shareRes);
            glesTextureShader         = new OpenGLESTextureShader(_shareRes);
            invertAlphaFragmentShader = new InvertAlphaLineSmoothShader(_shareRes); //used with stencil  ***

            conv3x3TextureShader        = new Conv3x3TextureShader(_shareRes);
            msdfShader                  = new DrawingGL.MultiChannelSdf(_shareRes);
            msdfSubPixelRenderingShader = new DrawingGL.MultiChannelSubPixelRenderingSdf(_shareRes);
            sdfShader = new DrawingGL.SingleChannelSdf(_shareRes);
            //-----------------------------------------------------------------------
            //tools

            tessTool = new TessTool();
            //-----------------------------------------------------------------------


            //GL.Enable(EnableCap.CullFace);
            //GL.FrontFace(FrontFaceDirection.Cw);
            //GL.CullFace(CullFaceMode.Back);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);//original **

            //GL.BlendFunc(BlendingFactorSrc.SrcColor, BlendingFactorDest.One);// not apply alpha to src
            //GL.BlendFuncSeparate(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcAlpha,
            //                     BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            //GL.BlendFuncSeparate(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcColor, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.Zero);

            GL.ClearColor(1, 1, 1, 1);
            //-------------------------------------------------------------------------------
            GL.Viewport(0, 0, width, height);
        }
Example #4
0
        public float[] GetAreaTess(TessTool tess, TessTriangleTechnique tech)
        {
#if DEBUG
            if (this.TessTriangleTech == 0)
            {
            }
#endif

            if (TessTriangleTech != tech)
            {
                //re tess again
                this.TessTriangleTech = tech;
                //***
                if (this.TessTriangleTech == TessTriangleTechnique.DrawArray)
                {
                    return(_areaTess ??
                           (_areaTess = tess.TessAsTriVertexArray(coordXYs, null, out _tessAreaVertexCount)));
                }
                else
                {
                    _indexListArray = tess.TessAsTriIndexArray(coordXYs,
                                                               null,
                                                               out _areaTess,
                                                               out _tessAreaVertexCount);
                    return(_areaTess);
                }
            }
            else
            {
                //if equal
                return(_areaTess);
            }
        }
Example #5
0
 public float[] GetAreaTess(TessTool tess)
 {
     if (areaTess == null)
     {
         //triangle list
         return(areaTess = tess.TessAsTriVertexArray(coordXYs, null, out this._tessAreaVertexCount));
     }
     return(areaTess);
 }
Example #6
0
        FrameBuffer _currentFrameBuffer;//default = null, system provide frame buffer


        internal CanvasGL2d(int canvasW, int canvasH)
        {
            this.canvasW = canvasW;
            this.canvasH = canvasH;
            ////setup viewport size
            int max = Math.Max(canvasW, canvasH);

            ////square viewport
            orthoView        = MyMat4.ortho(0, max, 0, max, 0, 1);
            flipVerticalView = MyMat4.scale(1, -1) * MyMat4.translate(new OpenTK.Vector3(0, -max, 0));
            orthoAndFlip     = orthoView * flipVerticalView;
            //-----------------------------------------------------------------------
            shaderRes           = new CanvasToShaderSharedResource();
            shaderRes.OrthoView = orthoView;
            //-----------------------------------------------------------------------
            basicFillShader     = new BasicFillShader(shaderRes);
            smoothLineShader    = new SmoothLineShader(shaderRes);
            rectFillShader      = new RectFillShader(shaderRes);
            gdiImgTextureShader = new GdiImageTextureShader(shaderRes);
            gdiImgTextureWithWhiteTransparentShader = new GdiImageTextureWithWhiteTransparentShader(shaderRes);
            textureSubPixRendering    = new ImageTextureWithSubPixelRenderingShader(shaderRes);
            blurShader                = new BlurShader(shaderRes);
            glesTextureShader         = new OpenGLESTextureShader(shaderRes);
            invertAlphaFragmentShader = new InvertAlphaLineSmoothShader(shaderRes); //used with stencil  ***
            // tessListener.Connect(tess,
            //Tesselate.Tesselator.WindingRuleType.Odd, true);
            conv3x3TextureShader = new Conv3x3TextureShader(shaderRes);
            msdfShader           = new DrawingGL.MultiChannelSdf(shaderRes);


            msdfSubPixelRenderingShader = new DrawingGL.MultiChannelSubPixelRenderingSdf(shaderRes);
            sdfShader = new DrawingGL.SingleChannelSdf(shaderRes);
            //----
            Tesselator tess = new Tesselator();

            tess.WindingRule = Tesselator.WindingRuleType.Odd;
            tessTool         = new TessTool(tess);
            //-----------------------------------------------------------------------


            //GL.Enable(EnableCap.CullFace);
            //GL.FrontFace(FrontFaceDirection.Cw);
            //GL.CullFace(CullFaceMode.Back);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);//original **

            //GL.BlendFunc(BlendingFactorSrc.SrcColor, BlendingFactorDest.One);// not apply alpha to src
            //GL.BlendFuncSeparate(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcAlpha,
            //                     BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            //GL.BlendFuncSeparate(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcColor, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.Zero);

            GL.ClearColor(1, 1, 1, 1);
            //-------------------------------------------------------------------------------
            GL.Viewport(0, 0, canvasW, canvasH);
        }
Example #7
0
        public float[] GetAreaTess(TessTool tess, Tesselate.Tesselator.WindingRuleType windingRuleType, TessTriangleTechnique tessTechnique)
        {
#if DEBUG
            if (this.TessTriangleTech == 0)
            {
            }
#endif

            if (TessTriangleTech != tessTechnique)
            {
                //re tess again
                this.TessTriangleTech = tessTechnique;
                //***
                using (Borrow(out ReusableCoordList resuableCoordList))
                {
                    List <float> coordXYs         = resuableCoordList._coordXYs;
                    List <int>   contourEndPoints = resuableCoordList._contourEndPoints;


                    for (int i = 0; i < _figures.Length; ++i)
                    {
                        Figure figure = _figures[i];
                        coordXYs.AddRange(figure.coordXYs);
                        contourEndPoints.Add(coordXYs.Count - 1);
                    }


                    if (this.TessTriangleTech == TessTriangleTechnique.DrawArray)
                    {
                        tess.WindingRuleType = windingRuleType;
                        return(_areaTess = tess.TessAsTriVertexArray(
                                   coordXYs.ToArray(),
                                   contourEndPoints.ToArray(),
                                   out _tessAreaVertexCount));
                    }
                    else
                    {
                        tess.WindingRuleType = windingRuleType;
                        _areaTessIndexList   = tess.TessAsTriIndexArray(
                            coordXYs.ToArray(),
                            contourEndPoints.ToArray(),
                            out _areaTess,
                            out _tessAreaVertexCount);
                        return(_areaTess);
                    }
                }
            }
            else
            {
                //if equal
                return(_areaTess);
            }
        }
Example #8
0
 /// <summary>
 /// vertex buffer of the solid area part
 /// </summary>
 public VertexBufferObject GetAreaTessAsVBO(TessTool tess)
 {
     if (_vboArea == null)
     {
         //tess
         indexListArray = tess.TessAsTriIndexArray(coordXYs, null,
                                                   out tessXYCoords2, out this._tessAreaVertexCount);
         _vboArea = new VertexBufferObject();
         _vboArea.CreateBuffers(tessXYCoords2, indexListArray, null);
     }
     return(_vboArea);
 }
Example #9
0
        FrameBuffer _currentFrameBuffer;//default = null, system provide frame buffer 


        internal CanvasGL2d(int canvasW, int canvasH)
        {
            this.canvasW = canvasW;
            this.canvasH = canvasH;
            ////setup viewport size
            int max = Math.Max(canvasW, canvasH);
            ////square viewport 
            orthoView = MyMat4.ortho(0, max, 0, max, 0, 1);
            //-----------------------------------------------------------------------
            shaderRes = new CanvasToShaderSharedResource();
            shaderRes.OrthoView = orthoView;
            //-----------------------------------------------------------------------


            basicFillShader = new BasicFillShader(shaderRes);
            smoothLineShader = new SmoothLineShader(shaderRes);
            rectFillShader = new RectFillShader(shaderRes);
            gdiImgTextureShader = new GdiImageTextureShader(shaderRes);
            gdiImgTextureWithWhiteTransparentShader = new GdiImageTextureWithWhiteTransparentShader(shaderRes);
            blurShader = new BlurShader(shaderRes);
            glesTextureShader = new OpenGLESTextureShader(shaderRes);
            invertAlphaFragmentShader = new InvertAlphaLineSmoothShader(shaderRes); //used with stencil  ***
            // tessListener.Connect(tess,          
            //Tesselate.Tesselator.WindingRuleType.Odd, true);
            conv3x3TextureShader = new Conv3x3TextureShader(shaderRes);
            msdfShader = new DrawingGL.MultiChannelSdf(shaderRes);


            msdfSubPixelRenderingShader = new DrawingGL.MultiChannelSubPixelRenderingSdf(shaderRes);
            sdfShader = new DrawingGL.SingleChannelSdf(shaderRes);
            //----
            Tesselator tess = new Tesselator();
            tess.WindingRule = Tesselator.WindingRuleType.Odd;
            tessTool = new TessTool(tess);
            //-----------------------------------------------------------------------


            //GL.Enable(EnableCap.CullFace);
            //GL.FrontFace(FrontFaceDirection.Cw);
            //GL.CullFace(CullFaceMode.Back); 

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(1, 1, 1, 1);
            //-------------------------------------------------------------------------------

            GL.Viewport(0, 0, canvasW, canvasH);
        }
Example #10
0
 internal void CreateAreaTessVBOSegment(VBOStream ownerVBOStream,
                                        TessTool tess,
                                        Tesselate.Tesselator.WindingRuleType windingRuleType)
 {
     //
     float[] tessArea = GetAreaTess(tess, windingRuleType);
     if (tessArea != null)
     {
         _tessAreaVboSeg = ownerVBOStream.CreateSegment(tessArea, TessAreaVertexCount, 2);
     }
     else
     {
         //??
     }
     //
 }
Example #11
0
            internal void CreateGraphicsPathForMultiPartRenderVx(
                MultiPartPolygon multipartPolygon,
                MultiPartTessResult multipartTessResult,
                TessTool tessTool,
                SmoothBorderBuilder borderBuilder)
            {
                //a multipart polygon contains a  list of  expand coord (x,y) set.

                List <float[]> expandCoordsList = multipartPolygon.expandCoordsList;
                List <int[]>   endPointList     = multipartPolygon.contourEndPoints;


                int listCount = expandCoordsList.Count;

                for (int i = 0; i < listCount; ++i)
                {
                    //expand x,y
                    float[] expandCoords = expandCoordsList[i];
                    int[]   endPoints    = endPointList[i];
                    //area
                    int localVertexCount;

                    tessTool.TessAndAddToMultiPartResult(expandCoords,
                                                         endPoints,
                                                         multipartTessResult,
                                                         out localVertexCount);

                    //borders
                    //build smooth border
                    int m = endPoints.Length;
                    int latest_endPoint = 0;
                    multipartTessResult.BeginBorderPart();
                    for (int n = 0; n < m; ++n)
                    {
                        int endPoint = endPoints[n];                     //'x' , not include 'y'
                        int len      = (endPoint - latest_endPoint) + 1; //so len we add +1 for 'y'
                        int borderTriangleStripCount;
                        //expand coords for draw array
                        float[] smoothBorderXYs = borderBuilder.BuildSmoothBorders(expandCoords, latest_endPoint, len, out borderTriangleStripCount);
                        latest_endPoint += len + 2;
                        multipartTessResult.AddSmoothBorders(smoothBorderXYs, borderTriangleStripCount);
                    }
                    multipartTessResult.EndBorderPart();
                }
            }
Example #12
0
        /// <summary>
        /// tess and read result as triangle list index array (for GLES draw element)
        /// </summary>
        /// <param name="tessTool"></param>
        /// <param name="vertex2dCoords"></param>
        /// <param name="contourEndPoints"></param>
        /// <param name="outputCoords"></param>
        /// <param name="vertexCount"></param>
        /// <returns></returns>
        public static ushort[] TessAsTriIndexArray(this TessTool tessTool,
                                                   float[] vertex2dCoords,
                                                   int[] contourEndPoints,
                                                   out float[] outputCoords,
                                                   out int vertexCount)
        {
            if (!tessTool.TessPolygon(vertex2dCoords, contourEndPoints))
            {
                vertexCount  = 0;
                outputCoords = null;
                return(null); //* early exit
            }
            //results
            //1.
            List <ushort> indexList = tessTool.TessIndexList;
            //2.
            List <TessTempVertex> tempVertexList = tessTool.TempVertexList;

            //3.
            vertexCount = indexList.Count;
            //-----------------------------

            //create a new array and append with original and new tempVertex list
            int tempVertListCount = tempVertexList.Count;

            outputCoords = new float[vertex2dCoords.Length + tempVertListCount * 2];
            //1. copy original array
            Array.Copy(vertex2dCoords, outputCoords, vertex2dCoords.Length);
            //2. append with newly create vertex (from tempVertList)
            int endAt = vertex2dCoords.Length + tempVertListCount;
            int p     = 0;
            int q     = vertex2dCoords.Length; //start adding at

            for (int i = vertex2dCoords.Length; i < endAt; ++i)
            {
                TessTempVertex v = tempVertexList[p];
                outputCoords[q]     = (float)v.m_X;
                outputCoords[q + 1] = (float)v.m_Y;
                p++;
                q += 2;
            }

            return(indexList.ToArray());
        }
Example #13
0
        /// <summary>
        /// tess and read result as triangle list vertex array (for GLES draw-array)
        /// </summary>
        /// <param name="tessTool"></param>
        /// <param name="vertex2dCoords"></param>
        /// <param name="contourEndPoints"></param>
        /// <param name="vertexCount"></param>
        /// <returns></returns>
        public static float[] TessAsTriVertexArray(this TessTool tessTool, float[] vertex2dCoords, int[] contourEndPoints, out int vertexCount)
        {
            if (!tessTool.TessPolygon(vertex2dCoords, contourEndPoints))
            {
                vertexCount = 0;
                return(null);
            }
            //results
            //1.
            List <ushort> indexList = tessTool.TessIndexList;
            //2.
            List <TessTempVertex> tempVertexList = tessTool.TempVertexList;

            //3.
            vertexCount = indexList.Count;
            //-----------------------------
            int orgVertexCount = vertex2dCoords.Length / 2;

            float[] vtx = new float[vertexCount * 2];//***
            int     n   = 0;

            for (int p = 0; p < vertexCount; ++p)
            {
                ushort index = indexList[p];
                if (index >= orgVertexCount)
                {
                    //extra coord (newly created)
                    TessTempVertex extraVertex = tempVertexList[index - orgVertexCount];
                    vtx[n]     = (float)extraVertex.m_X;
                    vtx[n + 1] = (float)extraVertex.m_Y;
                }
                else
                {
                    //original corrd
                    vtx[n]     = (float)vertex2dCoords[index * 2];
                    vtx[n + 1] = (float)vertex2dCoords[(index * 2) + 1];
                }
                n += 2;
            }
            //triangle list
            return(vtx);
        }
 public float[] GetAreaTess(ref TessTool tess)
 {
     if (areaTess == null)
     {
         List<Vertex> vertextList = tess.TessPolygon(coordXYs);
         //-----------------------------   
         //switch how to fill polygon
         int j = vertextList.Count;
         float[] vtx = new float[j * 2];
         int n = 0;
         for (int p = 0; p < j; ++p)
         {
             var v = vertextList[p];
             vtx[n] = (float)v.m_X;
             vtx[n + 1] = (float)v.m_Y;
             n += 2;
         }
         //triangle list
         tessAreaTriangleCount = j;
         //-------------------------------------                              
         return this.areaTess = vtx;
     }
     return areaTess;
 }
Example #15
0
 internal float[] GetAreaTess(TessTool tess, Tesselate.Tesselator.WindingRuleType windingRuleType)
 {
     return((_figure != null) ?
            _figure.GetAreaTess(tess, windingRuleType, TessTriangleTechnique.DrawArray) :
            _figures.GetAreaTess(tess, windingRuleType, TessTriangleTechnique.DrawArray));
 }
Example #16
0
 internal float[] GetAreaTess(TessTool tess)
 {
     return((_figure != null) ?
            _figure.GetAreaTess(tess, TessTriangleTechnique.DrawArray) :
            _figures.GetAreaTess(tess, TessTriangleTechnique.DrawArray));
 }