Ejemplo n.º 1
0
        public unsafe override void DrawCommandList(GLCommandList list, Rectangle scissor)
        {
            if (list == null)
            {
                return;
            }

            if (list.HasAnything)
            {
                if (!scissor.IsEmpty)
                {
                    SetScissorRect(scissor.Left, scissor.Top, scissor.Right, scissor.Bottom);
                }

                if (list.HasAnyMeshes)
                {
                    var drawData = list.GetMeshDrawData();

                    GL.EnableClientState(ArrayCap.ColorArray);

                    foreach (var draw in drawData)
                    {
                        if (draw.smooth)
                        {
                            GL.Enable(EnableCap.PolygonSmooth);
                        }
                        GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, draw.colArray);
                        GL.VertexPointer(2, VertexPointerType.Float, 0, draw.vtxArray);
                        GL.DrawElements(PrimitiveType.Triangles, draw.numIndices, DrawElementsType.UnsignedShort, draw.idxArray);
                        if (draw.smooth)
                        {
                            GL.Disable(EnableCap.PolygonSmooth);
                        }
                    }

                    GL.DisableClientState(ArrayCap.ColorArray);
                }

                if (list.HasAnyLines)
                {
                    var drawData = list.GetLineDrawData();

                    GL.PushMatrix();
                    GL.Translate(0.5f, 0.5f, 0.0f);
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, dashedBitmap.Id);
                    GL.EnableClientState(ArrayCap.ColorArray);
                    GL.EnableClientState(ArrayCap.TextureCoordArray);

                    foreach (var draw in drawData)
                    {
                        if (draw.smooth)
                        {
                            GL.Enable(EnableCap.LineSmooth);
                        }
                        GL.LineWidth(draw.lineWidth);
                        GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, draw.texArray);
                        GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, draw.colArray);
                        GL.VertexPointer(2, VertexPointerType.Float, 0, draw.vtxArray);
                        GL.DrawArrays(PrimitiveType.Lines, 0, draw.numVertices);
                        if (draw.smooth)
                        {
                            GL.Disable(EnableCap.LineSmooth);
                        }
                    }

                    GL.DisableClientState(ArrayCap.ColorArray);
                    GL.DisableClientState(ArrayCap.TextureCoordArray);
                    GL.Disable(EnableCap.Texture2D);
                    GL.PopMatrix();
                }

#if FAMISTUDIO_LINUX
                if (list.HasAnyTickLineMeshes)
                {
                    var draw = list.GetThickLineAsPolygonDrawData();

                    /*if (draw.smooth)*/ GL.Enable(EnableCap.PolygonSmooth);
                    GL.EnableClientState(ArrayCap.ColorArray);
                    GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, draw.colArray);
                    GL.VertexPointer(2, VertexPointerType.Float, 0, draw.vtxArray);
                    GL.DrawElements(PrimitiveType.Triangles, draw.numIndices, DrawElementsType.UnsignedShort, draw.idxArray);
                    GL.DisableClientState(ArrayCap.ColorArray);
                    /*if (draw.smooth)*/ GL.Disable(EnableCap.PolygonSmooth);
                }
#endif

                if (list.HasAnyBitmaps)
                {
                    var drawData = list.GetBitmapDrawData(vtxArray, texArray, colArray, out _, out _, out _, out _);

                    GL.Enable(EnableCap.Texture2D);
                    GL.EnableClientState(ArrayCap.ColorArray);
                    GL.EnableClientState(ArrayCap.TextureCoordArray);
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, texArray);
                    GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, colArray);
                    GL.VertexPointer(2, VertexPointerType.Float, 0, vtxArray);

                    fixed(short *ptr = quadIdxArray)
                    {
                        foreach (var draw in drawData)
                        {
                            GL.BindTexture(TextureTarget.Texture2D, draw.textureId);
                            GL.DrawElements(PrimitiveType.Triangles, draw.count, DrawElementsType.UnsignedShort, new IntPtr(ptr + draw.start));
                        }
                    }

                    GL.DisableClientState(ArrayCap.ColorArray);
                    GL.DisableClientState(ArrayCap.TextureCoordArray);
                    GL.Disable(EnableCap.Texture2D);
                }

                if (list.HasAnyTexts)
                {
                    var drawData = list.GetTextDrawData(vtxArray, texArray, colArray, out _, out _, out _, out _);

                    GL.Enable(EnableCap.Texture2D);
                    GL.EnableClientState(ArrayCap.ColorArray);
                    GL.EnableClientState(ArrayCap.TextureCoordArray);
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, texArray);
                    GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, colArray);
                    GL.VertexPointer(2, VertexPointerType.Float, 0, vtxArray);

                    fixed(short *ptr = quadIdxArray)
                    {
                        foreach (var draw in drawData)
                        {
                            GL.BindTexture(TextureTarget.Texture2D, draw.textureId);
                            GL.DrawElements(PrimitiveType.Triangles, draw.count, DrawElementsType.UnsignedShort, new IntPtr(ptr + draw.start));
                        }
                    }

                    GL.DisableClientState(ArrayCap.ColorArray);
                    GL.DisableClientState(ArrayCap.TextureCoordArray);
                    GL.Disable(EnableCap.Texture2D);
                }

                if (!scissor.IsEmpty)
                {
                    ClearScissorRect();
                }
            }

            list.Release();
        }
Ejemplo n.º 2
0
        public override unsafe void DrawCommandList(GLCommandList list, Rectangle scissor)
        {
            if (list == null)
            {
                return;
            }

            if (list.HasAnything)
            {
                if (!scissor.IsEmpty)
                {
                    SetScissorRect(scissor.Left, scissor.Top, scissor.Right, scissor.Bottom);
                }

                if (list.HasAnyMeshes)
                {
                    var drawData = list.GetMeshDrawData();

                    GLES11.GlEnableClientState(GLES11.GlColorArray);

                    foreach (var draw in drawData)
                    {
                        var vb = CopyGetVtxBuffer(draw.vtxArray, draw.vtxArraySize);
                        var cb = CopyGetColBuffer(draw.colArray, draw.colArraySize);
                        var ib = CopyGetIdxBuffer(draw.idxArray, draw.idxArraySize);

                        //if (draw.smooth) GLES11.GlEnable(GLES11.GlPolygonSmooth);
                        GLES11.GlColorPointer(4, GLES11.GlUnsignedByte, 0, cb);
                        GLES11.GlVertexPointer(2, GLES11.GlFloat, 0, vb);
                        GLES11.GlDrawElements(GLES11.GlTriangles, draw.numIndices, GLES11.GlUnsignedShort, ib);
                        //if (draw.smooth) GLES11.GlDisable(GLES11.GlPolygonSmooth);
                    }

                    GLES11.GlDisableClientState(GLES11.GlColorArray);
                }

                if (list.HasAnyLines)
                {
                    var drawData = list.GetLineDrawData();

                    GLES11.GlPushMatrix();
                    GLES11.GlTranslatef(0.5f, 0.5f, 0.0f);
                    GLES11.GlEnable(GLES11.GlTexture2d);
                    GLES11.GlBindTexture(GLES11.GlTexture2d, dashedBitmap.Id);
                    GLES11.GlEnableClientState(GLES11.GlColorArray);
                    GLES11.GlEnableClientState(GLES11.GlTextureCoordArray);

                    foreach (var draw in drawData)
                    {
                        var vb = CopyGetVtxBuffer(draw.vtxArray, draw.vtxArraySize);
                        var cb = CopyGetColBuffer(draw.colArray, draw.colArraySize);
                        var tb = CopyGetVtxBuffer(draw.texArray, draw.texArraySize);

                        if (draw.smooth)
                        {
                            GLES11.GlEnable(GLES11.GlLineSmooth);
                        }
                        GLES11.GlLineWidth(draw.lineWidth);
                        GLES11.GlTexCoordPointer(2, GLES11.GlFloat, 0, tb);
                        GLES11.GlColorPointer(4, GLES11.GlUnsignedByte, 0, cb);
                        GLES11.GlVertexPointer(2, GLES11.GlFloat, 0, vb);
                        GLES11.GlDrawArrays(GLES11.GlLines, 0, draw.numVertices);
                        if (draw.smooth)
                        {
                            GLES11.GlDisable(GLES11.GlLineSmooth);
                        }
                    }

                    GLES11.GlDisableClientState(GLES11.GlColorArray);
                    GLES11.GlDisableClientState(GLES11.GlTextureCoordArray);
                    GLES11.GlDisable(GLES11.GlTexture2d);
                    GLES11.GlPopMatrix();
                }

                if (list.HasAnyBitmaps)
                {
                    var drawData = list.GetBitmapDrawData(vtxArray, texArray, colArray, out var vtxSize, out var texSize, out var colSize, out var idxSize);

                    var vb = CopyGetVtxBuffer(vtxArray, vtxSize);
                    var cb = CopyGetColBuffer(colArray, colSize);
                    var tb = CopyGetVtxBuffer(texArray, texSize);
                    var ib = CopyGetIdxBuffer(quadIdxArray, idxSize);

                    GLES11.GlEnable(GLES11.GlTexture2d);
                    GLES11.GlEnableClientState(GLES11.GlColorArray);
                    GLES11.GlEnableClientState(GLES11.GlTextureCoordArray);
                    GLES11.GlTexCoordPointer(2, GLES11.GlFloat, 0, tb);
                    GLES11.GlColorPointer(4, GLES11.GlUnsignedByte, 0, cb);
                    GLES11.GlVertexPointer(2, GLES11.GlFloat, 0, vb);

                    foreach (var draw in drawData)
                    {
                        ib.Position(draw.start);
                        GLES11.GlBindTexture(GLES11.GlTexture2d, draw.textureId);
                        GLES11.GlDrawElements(GLES11.GlTriangles, draw.count, GLES11.GlUnsignedShort, ib);
                    }

                    GLES11.GlDisableClientState(GLES11.GlColorArray);
                    GLES11.GlDisableClientState(GLES11.GlTextureCoordArray);
                    GLES11.GlDisable(GLES11.GlTexture2d);
                }

                if (list.HasAnyTexts)
                {
                    var drawData = list.GetTextDrawData(vtxArray, texArray, colArray, out var vtxSize, out var texSize, out var colSize, out var idxSize);

                    var vb = CopyGetVtxBuffer(vtxArray, vtxSize);
                    var cb = CopyGetColBuffer(colArray, colSize);
                    var tb = CopyGetVtxBuffer(texArray, texSize);
                    var ib = CopyGetIdxBuffer(quadIdxArray, idxSize);

                    GLES11.GlEnable(GLES11.GlTexture2d);
                    GLES11.GlEnableClientState(GLES11.GlColorArray);
                    GLES11.GlEnableClientState(GLES11.GlTextureCoordArray);
                    GLES11.GlTexCoordPointer(2, GLES11.GlFloat, 0, tb);
                    GLES11.GlColorPointer(4, GLES11.GlUnsignedByte, 0, cb);
                    GLES11.GlVertexPointer(2, GLES11.GlFloat, 0, vb);

                    foreach (var draw in drawData)
                    {
                        ib.Position(draw.start);
                        GLES11.GlBindTexture(GLES11.GlTexture2d, draw.textureId);
                        GLES11.GlDrawElements(GLES11.GlTriangles, draw.count, GLES11.GlUnsignedShort, ib);
                    }

                    GLES11.GlDisableClientState(GLES11.GlColorArray);
                    GLES11.GlDisableClientState(GLES11.GlTextureCoordArray);
                    GLES11.GlDisable(GLES11.GlTexture2d);
                }

                if (!scissor.IsEmpty)
                {
                    ClearScissorRect();
                }
            }

            list.Release();
        }