コード例 #1
0
ファイル: CanvasTest.cs プロジェクト: ymoussaba/duality
 private void CreateReferenceImage(string name, int width, int height, Action <Canvas> renderMethod)
 {
     Pixmap.Layer image = this.RenderToTexture(width, height, renderMethod);
     image.SavePixelData(TestHelper.GetEmbeddedResourcePath(name, ".png"));
 }
コード例 #2
0
ファイル: Texture.cs プロジェクト: batbuild/duality
        /// <summary>
        /// Loads the specified <see cref="Duality.Resources.Pixmap">Pixmaps</see> pixel data.
        /// </summary>
        /// <param name="basePixmap">The <see cref="Duality.Resources.Pixmap"/> that is used as pixel data source.</param>
        /// <param name="sizeMode">Specifies behaviour in case the source data has non-power-of-two dimensions.</param>
        public void LoadData(ContentRef <Pixmap> basePixmap, SizeMode sizeMode)
        {
            DualityApp.GuardSingleThreadState();
            if (this.glTexId == 0)
            {
                this.glTexId = GL.GenTexture();
            }
            this.needsReload = false;
            this.basePixmap  = basePixmap;
            this.texSizeMode = sizeMode;

            int lastTexId;

            GL.GetInteger(GetPName.TextureBinding2D, out lastTexId);
            GL.BindTexture(TextureTarget.Texture2D, this.glTexId);

            if (!this.basePixmap.IsExplicitNull)
            {
                Pixmap.Layer pixelData     = null;
                Pixmap       basePixmapRes = this.basePixmap.IsAvailable ? this.basePixmap.Res : null;
                if (basePixmapRes != null)
                {
                    pixelData  = basePixmapRes.ProcessedLayer;
                    this.atlas = basePixmapRes.Atlas != null?basePixmapRes.Atlas.ToArray() : null;
                }

                if (pixelData == null)
                {
                    pixelData = Pixmap.Checkerboard.Res.MainLayer;
                }

                this.AdjustSize(pixelData.Width, pixelData.Height);
                this.SetupOpenGLRes();
                if (this.texSizeMode != SizeMode.NonPowerOfTwo &&
                    (this.pxWidth != this.texWidth || this.pxHeight != this.texHeight))
                {
                    if (this.texSizeMode == SizeMode.Enlarge)
                    {
                        Pixmap.Layer oldData = pixelData;
                        pixelData = oldData.CloneResize(this.texWidth, this.texHeight);
                        // Fill border pixels manually - that's cheaper than ColorTransparentPixels here.
                        oldData.DrawOnto(pixelData, BlendMode.Solid, this.pxWidth, 0, 1, this.pxHeight, this.pxWidth - 1, 0);
                        oldData.DrawOnto(pixelData, BlendMode.Solid, 0, this.pxHeight, this.pxWidth, 1, 0, this.pxHeight - 1);
                    }
                    else
                    {
                        pixelData = pixelData.CloneRescale(this.texWidth, this.texHeight, Pixmap.FilterMethod.Linear);
                    }
                }

                // Load pixel data to video memory
                if (Compressed && pixelData.CompressedData != null)
                {
                    GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.CompressedRgbaS3tcDxt5Ext, pixelData.Width, pixelData.Height, 0,
                                            pixelData.CompressedData.Length, pixelData.CompressedData);
                }
                else
                {
                    GL.TexImage2D(TextureTarget.Texture2D, 0,
                                  this.pixelformat, pixelData.Width, pixelData.Height, 0,
                                  GLPixelFormat.Rgba, PixelType.UnsignedByte,
                                  pixelData.Data);
                }

                // Adjust atlas to represent UV coordinates
                if (this.atlas != null)
                {
                    Vector2 scale;
                    scale.X = this.uvRatio.X / this.pxWidth;
                    scale.Y = this.uvRatio.Y / this.pxHeight;
                    for (int i = 0; i < this.atlas.Length; i++)
                    {
                        this.atlas[i].X *= scale.X;
                        this.atlas[i].W *= scale.X;
                        this.atlas[i].Y *= scale.Y;
                        this.atlas[i].H *= scale.Y;
                    }
                }
            }
            else
            {
                this.atlas = null;
                this.AdjustSize(this.size.X, this.size.Y);
                this.SetupOpenGLRes();
            }

            GL.BindTexture(TextureTarget.Texture2D, lastTexId);
        }
コード例 #3
0
ファイル: CanvasTest.cs プロジェクト: ymoussaba/duality
 private bool AreImagesEqual(Bitmap referenceImage, Action <Canvas> renderMethod)
 {
     Pixmap.Layer image     = this.RenderToTexture(referenceImage.Width, referenceImage.Height, renderMethod);
     Pixmap.Layer reference = new Pixmap.Layer(referenceImage);
     return(this.AreImagesEqual(reference, image));
 }
コード例 #4
0
        protected void UpdateWidget(bool inLimitTextWidth)
        {
            if (_batchInfo == null)
            {
                _batchInfo = new BatchInfo(
                    DrawTechnique.Mask,
                    Colors.White,
                    new ContentRef <Texture>(
                        new Texture(new ContentRef <Pixmap>(new Pixmap()))
                {
                    FilterMin   = TextureMinFilter.NearestMipmapLinear,
                    FilterMag   = TextureMagFilter.Nearest,
                    WrapX       = TextureWrapMode.ClampToEdge,
                    WrapY       = TextureWrapMode.ClampToEdge,
                    TexSizeMode = Texture.SizeMode.Enlarge
                }));
            }

            _isScrollbarRequired = false;

            if (!String.IsNullOrWhiteSpace(_fText.SourceText))
            {
                if (_textFont.Res != null && _fText.Fonts[0] != _textFont)
                {
                    _fText.Fonts[0] = _textFont;
                }

                int textWidth = _visibleWidth;

                if (!inLimitTextWidth)
                {
                    _fText.MaxWidth = ushort.MaxValue;

                    textWidth = (int)Math.Ceiling(_fText.Size.X) + 10;
                }

                _fText.MaxWidth = textWidth;

                _isScrollbarRequired = _fText.Size.Y > _visibleHeight;

                _uvUnit.X = 1f / textWidth;
                _uvUnit.Y = 1;

                if (_scrollbar != null)
                {
                    _scrollbar.Active = _isScrollbarRequired;
                    if (_isScrollbarRequired)
                    {
                        _scrollComponent.Maximum = (int)Math.Ceiling(_fText.Size.Y - _visibleHeight);

                        _uvUnit.X = 1f / textWidth;
                        _uvUnit.Y = 1f / _fText.Size.Y;
                    }
                }

                Pixmap.Layer textLayer = new Pixmap.Layer(_fText.MaxWidth, (int)Math.Max(_visibleHeight, _fText.Size.Y), Colors.Transparent);

                _fText.RenderToBitmap(_fText.SourceText, textLayer);

                Texture tx = _batchInfo.MainTexture.Res;
                tx.BasePixmap.Res.MainLayer = textLayer;
                tx.ReloadData();
            }
        }