Exemplo n.º 1
0
        public CubismAvaloniaTexture(GlInterfaceEx gl, Bitmap _bitmap)
        {
            this.gl = gl;
            var InternalFormat = gl.ContextInfo.Version.Type == GlProfileType.OpenGLES ? GL_RGBA : GL_RGBA8;

            var arr = new int[2];

            gl.GenTextures(1, arr);
            TextureId = arr[0];

            var impl  = _bitmap.PlatformImpl.Item;
            var field = impl.GetType().GetField("_image", BindingFlags.NonPublic | BindingFlags.Instance);
            int w     = _bitmap.PixelSize.Width;
            int h     = _bitmap.PixelSize.Height;
            var img   = (SKImage)field.GetValue(impl);
            var info  = new SKImageInfo(w, h, SKColorType.Bgra8888);

            byte[] buf = new byte[w * h * 4];
            fixed(byte *p = buf)
            {
                img.ReadPixels(info, (IntPtr)p);
                gl.BindTexture(GL_TEXTURE_2D, TextureId);
                gl.PixelStorei(GL_UNPACK_ALIGNMENT, 4);
                gl.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
                // TODO restore pixel store mode
                gl.TexImage2D(GL_TEXTURE_2D, 0, InternalFormat, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (IntPtr)p);
                SetupParameters(GL_LINEAR, GL_CLAMP_TO_EDGE);
                gl.BindTexture(GL_TEXTURE_2D, 0);
            }
        }
Exemplo n.º 2
0
        public CubismAvaloniaRenderer(GlInterfaceEx gl)
        {
            this.gl       = gl;
            State         = new CubismAvaloniaState(gl);
            ShaderManager = new CubismAvaloniaShaderManager(gl);

            // create some buffer objects
            m_maskVertexBuf = gl.GenBuffer();
            m_maskUvBuf     = gl.GenBuffer();
            m_meshVertexBuf = gl.GenBuffer();
            m_meshUvBuf     = gl.GenBuffer();
        }
Exemplo n.º 3
0
        public CubismAvaloniaClippingMask(GlInterfaceEx gl, int width, int height)
        {
            this.gl = gl;
            Texture = new CubismAvaloniaTexture(gl, width, height);

            int[] fbos = new int[1];
            this.gl.GenFramebuffers(1, fbos);
            FrameBufferId = fbos[0];
            this.gl.BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId);
            this.gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0);
            this.gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
        }
Exemplo n.º 4
0
        public CubismAvaloniaTexture(GlInterfaceEx gl, int width, int height)
        {
            this.gl = gl;
            var InternalFormat = gl.ContextInfo.Version.Type == GlProfileType.OpenGLES ? GL_RGBA : GL_RGBA8;

            Width  = width;
            Height = height;
            var arr = new int[2];

            gl.GenTextures(1, arr);
            TextureId = arr[0];
            gl.BindTexture(GL_TEXTURE_2D, TextureId);
            gl.TexImage2D(GL_TEXTURE_2D, 0, InternalFormat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, IntPtr.Zero);
            SetupParameters(GL_LINEAR, GL_CLAMP_TO_EDGE);
            gl.BindTexture(GL_TEXTURE_2D, 0);
        }
Exemplo n.º 5
0
 public CubismAvaloniaState(GlInterfaceEx gl)
 {
     this.gl = gl;
 }