Beispiel #1
0
        public void LoadTexture()
        {
            lock (this)
            {
                if (isLoaded)
                {
                    return;
                }
                if (parent != null)
                {
                    textureID = parent.textureID;
                    isLoaded  = parent.isLoaded;
                    parent.LoadTexture();
                    isOpaque = parent.isOpaque;
                    if (width == 0)
                    {
                        width = parent.Width;
                    }
                    if (height == 0)
                    {
                        height = parent.Height;
                    }
                    if (texWidth == 0)
                    {
                        texWidth = width;
                    }
                    if (texHeight == 0)
                    {
                        texHeight = height;
                    }
                    isLoaded = true;
                    return;
                }

                if (!isLoaded)
                {
                    if (isBitmapTexture)
                    {
                        if (format.Equals(null))
                        {
                            tex2d = new Texture2D(GLEx.Device, width, height);
                        }
                        else
                        {
                            tex2d = new Texture2D(GLEx.Device, width, height, false, format);
                        }
                        bool    alpha  = SurfaceFormat.Color.Equals(format);
                        int     size   = width * height;
                        Color[] pixels = new Color[size];
                        for (int i = 0; i < size; i++)
                        {
                            if (alpha)
                            {
                                pixels[i] = new Color(0, 0, 0, 0);
                            }
                            else
                            {
                                pixels[i] = new Color(0, 0, 0, 255);
                            }
                        }
                        tex2d.SetData(pixels);
                    }
                    else
                    {
                        if (!isExt)
                        {
                            if (tex2d == null)
                            {
                                this.tex2d = LFXPlus.Get.Load <Texture2D>(fileName);
                            }
                        }
                        else
                        {
                            if (zoom)
                            {
                                if (tex2d == null)
                                {
                                    tex2d = Texture2D.FromStream(GLEx.Device, ins, width, height, zoom);
                                }
                            }
                            else
                            {
                                if (tex2d == null)
                                {
                                    tex2d = Texture2D.FromStream(GLEx.Device, ins);
                                }
                            }
                        }
                    }
                    this.isLoaded  = true;
                    this.width     = tex2d.Width;
                    this.height    = tex2d.Height;
                    this.texWidth  = width;
                    this.texHeight = height;
                    if (ins != null)
                    {
                        ins.Close();
                        ins = null;
                    }
                    LTextures.LoadTexture(this);
                }
            }

            this.isOpaque    = (BlendState.Opaque == tex2d.GraphicsDevice.BlendState) && !isExt;
            this.widthRatio  = (float)width / (texWidth < 1 ? width : texWidth);
            this.heightRatio = (float)height / (texHeight < 1 ? height : texHeight);
            this.CheckPowerOfTwoSize();
        }