Пример #1
0
 public static void Init()
 {
     White = new RendererTexture(new Vector3(1, 1, 1), nameof(White));
     Black = new RendererTexture(new Vector3(0, 0, 0), nameof(Black));
     Gray  = new RendererTexture(new Vector3(0.5f, 0.5f, 0.5f), nameof(Gray));
     Red   = new RendererTexture(new Vector3(1, 0, 0), nameof(Red));
     Green = new RendererTexture(new Vector3(0, 1, 0), nameof(Green));
     Blue  = new RendererTexture(new Vector3(0, 0, 1), nameof(Blue));
 }
Пример #2
0
        public static RendererTexture CreateCubeArrayShadowMap(PixelInternalFormat internalformat, int width, int height, int layers, int border, PixelFormat format, PixelType type, IntPtr pixels)
        {
            int handle;

            GL.GenTextures(1, out handle);
            var txt = new RendererTexture(handle, TextureTarget.TextureCubeMapArray, width, height);

            txt.Bind();
            txt.ObjectLabel = "CubeShadowMapArray";
            txt.AddRef();
            GL.TexImage3D(TextureTarget.TextureCubeMapArray, 0, PixelInternalFormat.DepthComponent16, width, height, layers * 6, border, format, type, pixels);

            txt.SetNearestFilter();
            txt.SetClampToEdgeWrap();
            return(txt);
        }
Пример #3
0
        public static unsafe RendererTexture LoadCubeMap(string path)
        {
            //var faces = new string[] { "right", "left", "back", "front", "top", "bottom" };
            //var faces = new string[] { "left", "right", "top", "top", "top", "top" };
            //var faces = new string[] { "top", "top", "top", "top", "left", "top" };
            //var faces = new string[] { "right", "left", "top", "bottom", "back", "front" };
            var faces = new string[] { "right", "left", "top", "bottom", "front", "back" };
            //var faces = new string[] { "right", "left", "front", "back", "top", "bottom" };
            var images = new List <Image>();

            foreach (var face in faces)
            {
                images.Add(LoadBitmap(path.Replace("#", face)));
            }

            var name = Path.GetDirectoryName(path);

            // images[1].RotateFlip(RotateFlipType.Rotate90FlipY);
            // images[3].RotateFlip(RotateFlipType.RotateNoneFlipX);
            // images[2].RotateFlip(RotateFlipType.Rotate180FlipX);
            // images[0].RotateFlip(RotateFlipType.Rotate90FlipX);
            // images[4].RotateFlip(RotateFlipType.RotateNoneFlipY);

            int handle;

            GL.GenTextures(1, out handle);
            var txt = new RendererTexture(handle, TextureTarget.TextureCubeMap, images[0].Width, images[0].Height);

            //txt.ObjectLabel = Path.GetFileName(path);
            txt.Bind();
            txt.ObjectLabel = name;
            txt.AddRef();

            for (var i = 0; i < images.Count; i++)
            {
                images[i].UseData(ptr =>
                {
                    GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, 0, PixelInternalFormat.Rgba, txt.Width, txt.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, ptr);
                });
                images[i].Dispose();
            }
            txt.SetNearestFilter();
            txt.SetClampToEdgeWrap();

            //Console.WriteLine($"Loaded Cubemap #{txt.Handle} {path}");
            return(txt);
        }
Пример #4
0
        public static RendererTexture CreateCubeShadowMap(PixelInternalFormat internalformat, int width, int height, int border, PixelFormat format, PixelType type, IntPtr pixels)
        {
            int handle;

            GL.GenTextures(1, out handle);
            var txt = new RendererTexture(handle, TextureTarget.TextureCubeMap, width, height);

            txt.Bind();
            txt.ObjectLabel = "CubeShadowMap";
            txt.AddRef();
            for (var i = 0; i < 6; i++)
            {
                GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, 0, PixelInternalFormat.DepthComponent16, txt.Width, txt.Height, border, format, type, pixels);
            }

            txt.SetNearestFilter();
            txt.SetClampToEdgeWrap();
            return(txt);
        }
Пример #5
0
 internal static void RemoveRef(RendererTexture texture)
 {
     lock (References)
         References.Remove(texture.Handle);
 }
Пример #6
0
 internal static void AddRef(RendererTexture texture)
 {
     lock (References)
         References.Set(texture.Handle, new WeakReference <RendererTexture>(texture));
 }
Пример #7
0
 public GraphicsTexture(int width, int height)
 {
     Image   = new Image <Rgba32>(width, height);
     Texture = new RendererTexture(Image, "GraphicsTexture");
     UpdateTexture();
 }