Exemplo n.º 1
0
        internal WebGLTexture(byte[] data, TextureType type,
                              int width, int height, int depth,
                              TextureFormat format,
                              TextureFilter minFilter, TextureFilter magFilter,
                              TextureWrap wrapX, TextureWrap wrapY)
        {
            Type   = type;
            Width  = width;
            Height = height;
            Depth  = depth;
            Format = format;
            id     = GL.createTexture();
            switch (Type)
            {
            case TextureType.Texture2D:
                TextureTarget = GL.TEXTURE_2D;
                break;

            //case TextureType.Texture2DArray: // Not available in WebGL 1.0
            //	TextureTarget = GL.TEXTURE_2D_ARRAY;
            //	break;
            //case TextureType.Texture3D: // Not available in WebGL 1.0
            //	TextureTarget = GL.TEXTURE_3D;
            //	break;
            default:
                throw new IllegalValueException(typeof(TextureType), Type);
            }
            MinFilter = minFilter;
            MagFilter = magFilter;
            WrapX     = wrapX;
            WrapY     = wrapY;

            SetData(data);
        }
Exemplo n.º 2
0
 public override void Destroy()
 {
     if (id != null)
     {
         GL.deleteTexture(id);
         id = null;
     }
 }
Exemplo n.º 3
0
        internal WebGLTexture(string file, TextureType type,
                              TextureFormat format,
                              TextureFilter minFilter, TextureFilter magFilter,
                              TextureWrap wrapX, TextureWrap wrapY)
        {
            Type   = type;
            Width  = 1;
            Height = 1;
            Depth  = 1;
            Format = format;
            id     = GL.createTexture();
            switch (Type)
            {
            case TextureType.Texture2D:
                TextureTarget = GL.TEXTURE_2D;
                break;

            //case TextureType.Texture2DArray: // Not available in WebGL 1.0
            //	TextureTarget = GL.TEXTURE_2D_ARRAY;
            //	break;
            //case TextureType.Texture3D: // Not available in WebGL 1.0
            //	TextureTarget = GL.TEXTURE_3D;
            //	break;
            default:
                throw new IllegalValueException(typeof(TextureType), Type);
            }
            MinFilter = minFilter;
            MagFilter = magFilter;
            WrapX     = wrapX;
            WrapY     = wrapY;

            //SetData(new byte[] { 255, 20, 147, 255 }); // Debug Pink
            SetData(new byte[] { 255, 255, 255, 255 });

            // Load image async
            HTMLImageElement image = new HTMLImageElement();

            image.crossOrigin = "";
            image.onload      = (ev) => { HandleLoadedTexture(image); };
            image.src         = file;
        }