public override DeviceTexture2D CreateTexture(
            int mipLevels,
            int width,
            int height,
            PixelFormat format,
            DeviceTextureCreateOptions createOptions)
        {
            OpenTK.Graphics.OpenGL.PixelFormat pixelFormat = OpenGLFormats.MapPixelFormat(format);
            PixelInternalFormat pixelInternalFormat        = OpenGLFormats.MapPixelInternalFormat(format);

            if (createOptions == DeviceTextureCreateOptions.DepthStencil)
            {
                if (format != PixelFormat.R16_UInt)
                {
                    throw new NotImplementedException("R16_UInt is the only supported depth texture format.");
                }

                pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.DepthComponent;
                pixelInternalFormat = PixelInternalFormat.DepthComponent16;
            }

            return(new OpenGLTexture2D(
                       mipLevels,
                       width,
                       height,
                       format,
                       pixelInternalFormat,
                       pixelFormat,
                       OpenGLFormats.MapPixelType(format)));
        }
        public OpenGLCubemapTexture(
            IntPtr pixelsFront,
            IntPtr pixelsBack,
            IntPtr pixelsLeft,
            IntPtr pixelsRight,
            IntPtr pixelsTop,
            IntPtr pixelsBottom,
            int width,
            int height,
            PixelFormat format)
            : base(TextureTarget.TextureCubeMap, width, height)
        {
            _internalFormat = OpenGLFormats.MapPixelInternalFormat(format);
            _format         = OpenGLFormats.MapPixelFormat(format);
            _type           = OpenGLFormats.MapPixelType(format);

            Bind();
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge);

            SetFacePixels(0, pixelsRight);
            SetFacePixels(1, pixelsLeft);
            SetFacePixels(2, pixelsTop);
            SetFacePixels(3, pixelsBottom);
            SetFacePixels(4, pixelsBack);
            SetFacePixels(5, pixelsFront);
        }
Пример #3
0
        public static OpenGLTexture2D Create <T>(T[] pixelData, int width, int height, int pixelSizeInBytes, PixelFormat format) where T : struct
        {
            var internalFormat = OpenGLFormats.MapPixelInternalFormat(format);
            var pixelFormat    = OpenGLFormats.MapPixelFormat(format);
            var pixelType      = OpenGLFormats.MapPixelType(format);

            OpenGLTexture2D texture = new OpenGLTexture2D(
                width,
                height,
                format,
                internalFormat,
                pixelFormat,
                pixelType);

            texture.Bind();
            GL.TexImage2D(TextureTarget.Texture2D, 0, internalFormat, width, height, 0, pixelFormat, pixelType, pixelData);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            return(texture);
        }
Пример #4
0
 public OpenGLTexture2D(int width, int height, PixelFormat format, IntPtr pixelData)
     : this(1, width, height, format, OpenGLFormats.MapPixelInternalFormat(format), OpenGLFormats.MapPixelFormat(format), OpenGLFormats.MapPixelType(format))
 {
     SetTextureData(1, 0, 0, width, height, pixelData, FormatHelpers.GetPixelSizeInBytes(format) * width * height);
 }
Пример #5
0
 public OpenGLTexture2D(int width, int height, PixelFormat format, IntPtr pixelData)
     : this(width, height, format, OpenGLFormats.MapPixelInternalFormat(format), OpenGLFormats.MapPixelFormat(format), OpenGLFormats.MapPixelType(format), pixelData)
 {
 }