Beispiel #1
0
        private void SetScissorRect(int x0, int y0, int x1, int y1)
        {
            var scissor = new Rectangle(controlRect.X + x0, controlRect.Y + y0, x1 - x0, y1 - y0);

            scissor = FlipRectangleY(scissor);
            GLES11.GlScissor(scissor.Left, scissor.Top, scissor.Width, scissor.Height);
        }
Beispiel #2
0
        public void UpdateBitmap(GLBitmap bmp, int x, int y, int width, int height, int[] data)
        {
            var buffer = ByteBuffer.AllocateDirect(width * height * sizeof(int)).Order(ByteOrder.NativeOrder()).AsIntBuffer();

            buffer.Put(data);
            buffer.Position(0);

            GLES11.GlBindTexture(GLES11.GlTexture2d, bmp.Id);
            GLES11.GlTexSubImage2D(GLES11.GlTexture2d, 0, x, y, width, height, GLES11.GlRgba, GLES11.GlUnsignedByte, buffer);
        }
Beispiel #3
0
        public override void Dispose()
        {
            if (texture != 0)
            {
                GLES11.GlDeleteTextures(1, new[] { texture }, 0);
            }
            if (fbo != 0)
            {
                GLES11Ext.GlDeleteFramebuffersOES(1, new[] { fbo }, 0);
            }

            base.Dispose();
        }
Beispiel #4
0
        protected override int CreateTexture(Bitmap bmp, bool filter)
        {
            var id = new int[1];

            GLES11.GlGenTextures(1, id, 0);
            GLES11.GlBindTexture(GLES11.GlTexture2d, id[0]);
            GLUtils.TexImage2D(GLES11.GlTexture2d, 0, bmp, 0);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureMinFilter, filter ? GLES11.GlLinear : GLES11.GlNearest);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureMagFilter, filter ? GLES11.GlLinear : GLES11.GlNearest);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureWrapS, GLES11.GlClampToEdge);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureWrapT, GLES11.GlClampToEdge);
            bmp.Recycle();

            return(id[0]);
        }
Beispiel #5
0
        public GLBitmapAtlas CreateBitmapAtlasFromResources(string[] names)
        {
            var bitmaps      = new Bitmap[names.Length];
            var elementSizeX = 0;
            var elementSizeY = 0;

            for (int i = 0; i < names.Length; i++)
            {
                var bmp = LoadBitmapFromResourceWithScaling(names[i]);

                elementSizeX = Math.Max(elementSizeX, bmp.Width);
                elementSizeY = Math.Max(elementSizeY, bmp.Height);

                bitmaps[i] = bmp;
            }

            var elementsPerRow = MaxAtlasResolution / elementSizeX;
            var numRows        = Utils.DivideAndRoundUp(names.Length, elementsPerRow);
            var atlasSizeX     = elementsPerRow * elementSizeX;
            var atlasSizeY     = numRows * elementSizeY;
            var textureId      = CreateEmptyTexture(atlasSizeX, atlasSizeY, true);
            var elementRects   = new Rectangle[names.Length];

            GLES11.GlBindTexture(GLES11.GlTexture2d, textureId);

            for (int i = 0; i < names.Length; i++)
            {
                var bmp = bitmaps[i];

                var row = i / elementsPerRow;
                var col = i % elementsPerRow;

                elementRects[i] = new Rectangle(
                    col * elementSizeX,
                    row * elementSizeY,
                    bmp.Width,
                    bmp.Height);

                GLUtils.TexSubImage2D(GLES11.GlTexture2d, 0, elementRects[i].X, elementRects[i].Y, bmp);
                bmp.Recycle();
            }

            return(new GLBitmapAtlas(textureId, atlasSizeX, atlasSizeY, elementRects, true, true));
        }
Beispiel #6
0
        public override void BeginDrawControl(Rectangle unflippedControlRect, int windowSizeY)
        {
            base.BeginDrawControl(unflippedControlRect, windowSizeY);

            GLES11.GlHint(GLES11.GlLineSmoothHint, GLES11.GlNicest);
            GLES11.GlViewport(controlRectFlip.Left, controlRectFlip.Top, controlRectFlip.Width, controlRectFlip.Height);
            GLES11.GlMatrixMode(GLES11.GlProjection);
            GLES11.GlLoadIdentity();
            GLES11.GlOrthof(0, unflippedControlRect.Width, unflippedControlRect.Height, 0, -1, 1);
            GLES11.GlDisable((int)2884); // Cull face?
            GLES11.GlMatrixMode(GLES11.GlModelview);
            GLES11.GlLoadIdentity();
            GLES11.GlBlendFunc(GLES11.GlSrcAlpha, GLES11.GlOneMinusSrcAlpha);
            GLES11.GlEnable(GLES11.GlBlend);
            GLES11.GlDisable(GLES11.GlDepthTest);
            GLES11.GlDisable(GLES11.GlStencilTest);
            GLES11.GlEnable(GLES11.GlScissorTest);
            GLES11.GlScissor(controlRectFlip.Left, controlRectFlip.Top, controlRectFlip.Width, controlRectFlip.Height);
            GLES11.GlEnableClientState(GLES11.GlVertexArray);
        }
Beispiel #7
0
        protected override int CreateEmptyTexture(int width, int height, bool filter = false)
        {
            var id = new int[1];

            GLES11.GlGenTextures(1, id, 0);
            GLES11.GlBindTexture(GLES11.GlTexture2d, id[0]);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureMinFilter, filter ? GLES11.GlLinear : GLES11.GlNearest);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureMagFilter, filter ? GLES11.GlLinear : GLES11.GlNearest);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureWrapS, GLES11.GlClampToEdge);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureWrapT, GLES11.GlClampToEdge);

            var buffer = ByteBuffer.AllocateDirect(width * height * sizeof(int)).Order(ByteOrder.NativeOrder()).AsIntBuffer();

            buffer.Put(new int[width * height]);
            buffer.Position(0);

            GLES11.GlTexImage2D(GLES11.GlTexture2d, 0, GLES11.GlRgba, width, height, 0, GLES11.GlRgba, GLES11.GlUnsignedByte, buffer);

            return(id[0]);
        }
Beispiel #8
0
        public static GLOffscreenGraphics Create(int imageSizeX, int imageSizeY, bool allowReadback)
        {
#if !DEBUG
            try
#endif
            {
                var extentions = GLES11.GlGetString(GLES11.GlExtensions);

                if (extentions.ToUpper().Contains("GL_OES_FRAMEBUFFER_OBJECT"))
                {
                    return(new GLOffscreenGraphics(imageSizeX, imageSizeY, allowReadback));
                }
            }
#if !DEBUG
            catch
            {
            }
#endif

            return(null);
        }
Beispiel #9
0
        public GLGraphics(float mainScale, float baseScale) : base(mainScale, baseScale)
        {
            dashedBitmap = CreateBitmapFromResource("Dash");
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureWrapS, GLES11.GlRepeat);
            GLES11.GlTexParameterx(GLES11.GlTexture2d, GLES11.GlTextureWrapT, GLES11.GlRepeat);

            for (int i = 0; i < NumBufferSizes; i++)
            {
                freeVtxBuffers[i] = new List <FloatBuffer>();
                freeColBuffers[i] = new List <IntBuffer>();
                freeIdxBuffers[i] = new List <ShortBuffer>();
                usedVtxBuffers[i] = new List <FloatBuffer>();
                usedColBuffers[i] = new List <IntBuffer>();
                usedIdxBuffers[i] = new List <ShortBuffer>();
            }

            var smoothLineWidths = new int[2];

            GLES11.GlGetIntegerv(GLES11.GlSmoothLineWidthRange, smoothLineWidths, 0);
            maxSmoothLineWidth = smoothLineWidths[1];
        }
Beispiel #10
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();
        }
Beispiel #11
0
 public void Clear(Color color)
 {
     GLES11.GlClearColor(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
     GLES11.GlClear(GLES11.GlColorBufferBit);
 }
Beispiel #12
0
 public void SetViewport(int x, int y, int width, int height)
 {
     GLES11.GlViewport(x, y, width, height);
 }
Beispiel #13
0
 private void ClearScissorRect()
 {
     GLES11.GlScissor(controlRectFlip.Left, controlRectFlip.Top, controlRectFlip.Width, controlRectFlip.Height);
 }