示例#1
0
        protected virtual void SetupTexture2D(GraphicsInterface gi, int width, int height, TextureInternalFormat internalFormat, TexturePixelFormat pixelFormat, PixelComponentType pixelType, IntPtr pixelData, bool createMipMaps)
        {
            fWidth = width;
            fHeight = height;

            fInternalFormat = internalFormat;
            fPixelFormat = pixelFormat;
            fPixelType = pixelType;

            // Setup the alignment
            fGI.PixelStore(PixelStore.UnpackAlignment, 1);

            // Allocate storage for the texture
            // We do this once at the beginning to allocate space for the texture object
            fGI.TexImage2D(0, internalFormat, fWidth, fHeight, 0, pixelFormat, pixelType, pixelData);

            // Setup default filters and wrapping
            SetupFiltering();
            SetupWrapping();

            if (createMipMaps)
            {
                // Make call to generate MipMap
                //fGI.GenerateMipmap();
                
                // Alter the min filter to use the mipmap
                fGI.TexParameter(TextureParameterTarget.Texture2d, TextureParameterName.TextureMinFilter, TextureMinFilter.LinearMipmapLinear);
            }

        }
示例#2
0
        private static RenderbufferInternalFormat TexFormatToRboFormat(TexturePixelFormat format)
        {
            switch (format)
            {
            case TexturePixelFormat.Single: return(RenderbufferInternalFormat.R8);

            case TexturePixelFormat.Dual: return(RenderbufferInternalFormat.Rg8);

            case TexturePixelFormat.Rgb: return(RenderbufferInternalFormat.Rgb8);

            default:
            case TexturePixelFormat.Rgba: return(RenderbufferInternalFormat.Rgba8);

            case TexturePixelFormat.FloatSingle: return /*RenderbufferInternalFormat.R16f*/ ((RenderbufferInternalFormat)33325);

            case TexturePixelFormat.FloatDual: return /*RenderbufferInternalFormat.Rg16f*/ ((RenderbufferInternalFormat)33327);

            case TexturePixelFormat.FloatRgb: return /*RenderbufferInternalFormat.Rgb16f*/ ((RenderbufferInternalFormat)34843);

            case TexturePixelFormat.FloatRgba: return /*RenderbufferInternalFormat.Rgba16f*/ ((RenderbufferInternalFormat)34842);

            case TexturePixelFormat.CompressedSingle: return(RenderbufferInternalFormat.R8);

            case TexturePixelFormat.CompressedDual: return(RenderbufferInternalFormat.Rg8);

            case TexturePixelFormat.CompressedRgb: return(RenderbufferInternalFormat.Rgb8);

            case TexturePixelFormat.CompressedRgba: return(RenderbufferInternalFormat.Rgba8);
            }
        }
示例#3
0
 public TextureData(IntPtr data, TexturePixelFormat pixelFormat, int width, int height)
 {
     Data        = data;
     PixelFormat = pixelFormat;
     Width       = width;
     Height      = height;
 }
示例#4
0
        private static RenderbufferStorage TexFormatToRboFormat(TexturePixelFormat format)
        {
            switch (format)
            {
            case TexturePixelFormat.Single: return(RenderbufferStorage.R8);

            case TexturePixelFormat.Dual: return(RenderbufferStorage.Rg8);

            case TexturePixelFormat.Rgb: return(RenderbufferStorage.Rgb8);

            case TexturePixelFormat.Rgba: return(RenderbufferStorage.Rgba8);

            case TexturePixelFormat.FloatSingle: return(RenderbufferStorage.R16f);

            case TexturePixelFormat.FloatDual: return(RenderbufferStorage.Rg16f);

            case TexturePixelFormat.FloatRgb: return(RenderbufferStorage.Rgb16f);

            case TexturePixelFormat.FloatRgba: return(RenderbufferStorage.Rgba16f);

            case TexturePixelFormat.CompressedSingle: return(RenderbufferStorage.R8);

            case TexturePixelFormat.CompressedDual: return(RenderbufferStorage.Rg8);

            case TexturePixelFormat.CompressedRgb: return(RenderbufferStorage.Rgb8);

            case TexturePixelFormat.CompressedRgba: return(RenderbufferStorage.Rgba8);
            }

            return(RenderbufferStorage.Rgba8);
        }
示例#5
0
        private static GLPixelFormat ToOpenTKPixelFormat(TexturePixelFormat format)
        {
            switch (format)
            {
            case TexturePixelFormat.Single: return(GLPixelFormat.Red);

            case TexturePixelFormat.Dual: return(GLPixelFormat.Rg);

            case TexturePixelFormat.Rgb: return(GLPixelFormat.Rgb);

            default:
            case TexturePixelFormat.Rgba: return(GLPixelFormat.Rgba);

            case TexturePixelFormat.FloatSingle: return(GLPixelFormat.Red);

            case TexturePixelFormat.FloatDual: return(GLPixelFormat.Rg);

            case TexturePixelFormat.FloatRgb: return(GLPixelFormat.Rgb);

            case TexturePixelFormat.FloatRgba: return(GLPixelFormat.Rgba);

                // Compressed formats are not supported in OpenGL ES
                //case TexturePixelFormat.CompressedSingle: return (PixelInternalFormat)TextureComponentCount.CompressedRed;
                //case TexturePixelFormat.CompressedDual: return (PixelInternalFormat)TextureComponentCount.CompressedRg;
                //case TexturePixelFormat.CompressedRgb: return (PixelInternalFormat)TextureComponentCount.CompressedRgb;
                //case TexturePixelFormat.CompressedRgba: return (PixelInternalFormat)TextureComponentCount.CompressedRgba;
            }
        }
示例#6
0
        public FieldTexturePS3(TexturePixelFormat format, byte mipMapCount, short width, short height, byte[] data)
        {
            Field00 = 0x020200FF;
            Field08 = 0x00000001;
            Field0C = 0x00000000;
            Flags   = FieldTextureFlags.Flag2 | FieldTextureFlags.Flag4 | FieldTextureFlags.Flag80;

            if (format == TexturePixelFormat.BC2)
            {
                Flags |= FieldTextureFlags.DXT3;
            }
            else if (format == TexturePixelFormat.BC3)
            {
                Flags |= FieldTextureFlags.DXT5;
            }

            MipMapCount = mipMapCount;
            Field1A     = 2;
            Field1B     = 0;
            Field1C     = 0xAAE4;
            Width       = width;
            Height      = height;
            Field24     = 1;
            Data        = data;
        }
示例#7
0
        private static PixelInternalFormat ToOpenTKPixelFormat(TexturePixelFormat format)
        {
            switch (format)
            {
            case TexturePixelFormat.Single: return(PixelInternalFormat.R8);

            case TexturePixelFormat.Dual: return(PixelInternalFormat.Rg8);

            case TexturePixelFormat.Rgb: return(PixelInternalFormat.Rgb);

            case TexturePixelFormat.Rgba: return(PixelInternalFormat.Rgba);

            case TexturePixelFormat.FloatSingle: return(PixelInternalFormat.R16f);

            case TexturePixelFormat.FloatDual: return(PixelInternalFormat.Rg16f);

            case TexturePixelFormat.FloatRgb: return(PixelInternalFormat.Rgb16f);

            case TexturePixelFormat.FloatRgba: return(PixelInternalFormat.Rgba16f);

            case TexturePixelFormat.CompressedSingle: return(PixelInternalFormat.CompressedRed);

            case TexturePixelFormat.CompressedDual: return(PixelInternalFormat.CompressedRg);

            case TexturePixelFormat.CompressedRgb: return(PixelInternalFormat.CompressedRgb);

            case TexturePixelFormat.CompressedRgba: return(PixelInternalFormat.CompressedRgba);
            }

            return(PixelInternalFormat.Rgba);
        }
示例#8
0
        private static uint ToOpenTKPixelFormat(TexturePixelFormat format)
        {
            switch (format)
            {
            case TexturePixelFormat.Single: return(WebGL2RenderingContextBase.RED);

            case TexturePixelFormat.Dual: return(WebGL2RenderingContextBase.RG);

            case TexturePixelFormat.Rgb: return(WebGL2RenderingContextBase.RGB);

            default:
            case TexturePixelFormat.Rgba: return(WebGL2RenderingContextBase.RGBA);

            case TexturePixelFormat.FloatSingle: return(WebGL2RenderingContextBase.RED);

            case TexturePixelFormat.FloatDual: return(WebGL2RenderingContextBase.RG);

            case TexturePixelFormat.FloatRgb: return(WebGL2RenderingContextBase.RGB);

            case TexturePixelFormat.FloatRgba: return(WebGL2RenderingContextBase.RGBA);

                // Compressed formats are not supported in OpenGL ES
                //case TexturePixelFormat.CompressedSingle: return (PixelInternalFormat)TextureComponentCount.CompressedRed;
                //case TexturePixelFormat.CompressedDual: return (PixelInternalFormat)TextureComponentCount.CompressedRg;
                //case TexturePixelFormat.CompressedRgb: return (PixelInternalFormat)TextureComponentCount.CompressedRgb;
                //case TexturePixelFormat.CompressedRgba: return (PixelInternalFormat)TextureComponentCount.CompressedRgba;
            }
        }
        /// <inheritdoc />
        public override RenderTarget CreateRenderTarget(Vector2 size, bool smooth      = false, TextureInternalFormat internalFormat = TextureInternalFormat.Rgba,
                                                        TexturePixelFormat pixelFormat = TexturePixelFormat.Rgba, bool attachStencil = false)
        {
            RenderTarget resultTarget = null;

            InternalFormat intFormat = (InternalFormat)Enum.Parse(typeof(InternalFormat), internalFormat.ToString());
            PixelFormat    glFormat  = (PixelFormat)Enum.Parse(typeof(PixelFormat), pixelFormat.ToString());

            GLThread.ExecuteGLThread(() =>
            {
                // Create the FBO which rendering will be done to.
                uint newFbo = Gl.GenFramebuffer();
                Gl.BindFramebuffer(FramebufferTarget.Framebuffer, newFbo);

                // Create the texture.
                uint renderTexture = Gl.GenTexture();
                Gl.BindTexture(TextureTarget.Texture2d, renderTexture);
                Gl.TexImage2D(TextureTarget.Texture2d, 0, intFormat, (int)size.X, (int)size.Y, 0, glFormat,
                              PixelType.UnsignedByte, IntPtr.Zero);
                Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMinFilter, smooth ? Gl.LINEAR : Gl.NEAREST);
                Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMagFilter, smooth ? Gl.LINEAR : Gl.NEAREST);

                // Attach the texture to the frame buffer.
                Gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2d, renderTexture, 0);

                // Attach color components.
                int[] modes = { Gl.COLOR_ATTACHMENT0 };
                Gl.DrawBuffers(modes);

                // Create render buffer.
                uint depthBuffer = Gl.GenRenderbuffer();
                Gl.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBuffer);
                Gl.RenderbufferStorage(RenderbufferTarget.Renderbuffer, InternalFormat.Depth24Stencil8, (int)size.X,
                                       (int)size.Y);
                Gl.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, attachStencil ? FramebufferAttachment.DepthStencilAttachment : FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, depthBuffer);

                // Check status.
                FramebufferStatus status = Gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
                if (status != FramebufferStatus.FramebufferComplete)
                {
                    Engine.Log.Warning($"Framebuffer creation failed. Error code {status}.", MessageSource.GL);
                }

                // Create the texture object.
                Texture targetTexture = new GLTexture(renderTexture, new Vector2(size.X, size.Y), null, $"FBO {newFbo} Texture");

                // Create the render target object.
                resultTarget = new GlRenderTarget(newFbo, size, targetTexture);

                // Clear the target.
                ClearScreen();

                CheckError("creating scale fbo");

                // Restore bindings and so on.
                Engine.Renderer?.EnsureRenderTarget();
            });

            return(resultTarget);
        }
示例#10
0
 internal TextureInfo(Texture texture, int width, int height, int mipMapCount, TexturePixelFormat format)
 {
     Texture     = texture;
     Name        = texture.Name;
     Width       = width;
     Height      = height;
     PixelFormat = format;
     MipMapCount = mipMapCount;
 }
示例#11
0
 public TextureFileFormat()
 {
     MipmapLevels    = new List <MipmapLevel>();
     BaseWidth       = 1;
     BaseHeight      = 1;
     BaseDepth       = 1;
     FrameCount      = 1;
     FramesPerSecond = 0;
     Type            = TextureType.Texture2D;
     Format          = TexturePixelFormat.BGRA;
 }
示例#12
0
        void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps)
        {
            // Removed thread guards because of performance
            //DefaultOpenTKBackendPlugin.GuardSingleThreadState();

            if (width == 0 || height == 0)
            {
                return;
            }

            int lastTexId;

            GL.GetInteger(GetPName.TextureBinding2D, out lastTexId);
            if (lastTexId != this.handle)
            {
                GL.BindTexture(TextureTarget.Texture2D, this.handle);
            }

            // Set texture parameters
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)ToOpenTKTextureMinFilter(minFilter));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)ToOpenTKTextureMagFilter(magFilter));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)ToOpenTKTextureWrapMode(wrapX));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)ToOpenTKTextureWrapMode(wrapY));

            // Anisotropic filtering
            // ToDo: Add similar code for OpenGL ES
            //if (anisoLevel > 0) {
            //    GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, (float)anisoLevel);
            //}

            // If needed, care for Mipmaps
            // ToDo: Why are mipmaps disabled here?
            //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, mipmaps ? 1 : 0);

            // Setup pixel format
            GL.TexImage2D(TextureTarget2d.Texture2D, 0,
                          ToOpenTKPixelInternalFormat(format), width, height, 0,
                          ToOpenTKPixelFormat(format), PixelType.UnsignedByte, IntPtr.Zero);

            //GL.GenerateMipmap(TextureTarget.Texture2D);

            this.width   = width;
            this.height  = height;
            this.format  = format;
            this.mipmaps = mipmaps;

            if (lastTexId != this.handle)
            {
                GL.BindTexture(TextureTarget.Texture2D, lastTexId);
            }
        }
示例#13
0
 /// <summary>
 /// Creates a new Texture based on a <see cref="Duality.Resources.Pixmap"/>.
 /// </summary>
 /// <param name="basePixmap">The <see cref="Duality.Resources.Pixmap"/> to use as source for pixel data.</param>
 /// <param name="sizeMode">Specifies behaviour in case the source data has non-power-of-two dimensions.</param>
 /// <param name="filterMag">The OpenGL filter mode for drawing the Texture bigger than it is.</param>
 /// <param name="filterMin">The OpenGL fitler mode for drawing the Texture smaller than it is.</param>
 /// <param name="wrapX">The OpenGL wrap mode on the texel x axis.</param>
 /// <param name="wrapY">The OpenGL wrap mode on the texel y axis.</param>
 /// <param name="format">The format in which OpenGL stores the pixel data.</param>
 public Texture(ContentRef <Pixmap> basePixmap,
                TextureSizeMode sizeMode   = TextureSizeMode.Default,
                TextureMagFilter filterMag = TextureMagFilter.Linear,
                TextureMinFilter filterMin = TextureMinFilter.LinearMipmapLinear,
                TextureWrapMode wrapX      = TextureWrapMode.Clamp,
                TextureWrapMode wrapY      = TextureWrapMode.Clamp,
                TexturePixelFormat format  = TexturePixelFormat.Rgba)
 {
     this.filterMag   = filterMag;
     this.filterMin   = filterMin;
     this.wrapX       = wrapX;
     this.wrapY       = wrapY;
     this.pixelformat = format;
     this.LoadData(basePixmap, sizeMode);
 }
示例#14
0
 /// <summary>
 /// Creates a new empty Texture with the specified size.
 /// </summary>
 /// <param name="width">The Textures width.</param>
 /// <param name="height">The Textures height</param>
 /// <param name="sizeMode">Specifies behaviour in case the specified size has non-power-of-two dimensions.</param>
 /// <param name="filterMag">The OpenGL filter mode for drawing the Texture bigger than it is.</param>
 /// <param name="filterMin">The OpenGL fitler mode for drawing the Texture smaller than it is.</param>
 /// <param name="wrapX">The OpenGL wrap mode on the texel x axis.</param>
 /// <param name="wrapY">The OpenGL wrap mode on the texel y axis.</param>
 /// <param name="format">The format in which OpenGL stores the pixel data.</param>
 public Texture(int width, int height,
                TextureSizeMode sizeMode   = TextureSizeMode.Default,
                TextureMagFilter filterMag = TextureMagFilter.Linear,
                TextureMinFilter filterMin = TextureMinFilter.LinearMipmapLinear,
                TextureWrapMode wrapX      = TextureWrapMode.Clamp,
                TextureWrapMode wrapY      = TextureWrapMode.Clamp,
                TexturePixelFormat format  = TexturePixelFormat.Rgba)
 {
     this.filterMag   = filterMag;
     this.filterMin   = filterMin;
     this.wrapX       = wrapX;
     this.wrapY       = wrapY;
     this.pixelformat = format;
     this.texSizeMode = sizeMode;
     this.AdjustSize(width, height);
     this.SetupNativeRes();
 }
示例#15
0
        void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps)
        {
            // Removed thread guards because of performance
            //DefaultOpenTKBackendPlugin.GuardSingleThreadState();

            WebGLTexture lastTexId = (WebGLTexture)GraphicsBackend.GL.GetParameter(WebGLRenderingContextBase.TEXTURE_BINDING_2D);

            if (lastTexId != this.handle)
            {
                GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, this.handle);
            }

            // Set texture parameters
            GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_MIN_FILTER, (int)ToOpenTKTextureMinFilter(minFilter));
            GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_MAG_FILTER, (int)ToOpenTKTextureMagFilter(magFilter));
            GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_WRAP_S, (int)ToOpenTKTextureWrapMode(wrapX));
            GraphicsBackend.GL.TexParameteri(WebGLRenderingContextBase.TEXTURE_2D, WebGLRenderingContextBase.TEXTURE_WRAP_T, (int)ToOpenTKTextureWrapMode(wrapY));

            // Anisotropic filtering
            // ToDo: Add similar code for OpenGL ES
            //if (anisoLevel > 0) {
            //    GraphicsBackend.GL.TexParameter(WebGLRenderingContextBase.TEXTURE_2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, (float)anisoLevel);
            //}

            // If needed, care for Mipmaps
            // ToDo: Why are mipmaps disabled here?
            //GraphicsBackend.GL.TexParameter(WebGLRenderingContextBase.TEXTURE_2D, TextureParameterName.GenerateMipmap, mipmaps ? 1 : 0);

            // Setup pixel format
            GraphicsBackend.GL.TexImage2D(WebGLRenderingContextBase.TEXTURE_2D, 0,
                                          ToOpenTKPixelInternalFormat(format), width, height, 0,
                                          ToOpenTKPixelFormat(format), WebGLRenderingContextBase.UNSIGNED_BYTE, null);

            //GraphicsBackend.GL.GenerateMipmap(WebGLRenderingContextBase.TEXTURE_2D);

            this.width   = width;
            this.height  = height;
            this.format  = format;
            this.mipmaps = mipmaps;

            if (lastTexId != this.handle)
            {
                GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, lastTexId);
            }
        }
示例#16
0
 /// <summary>
 /// Uploads the specified pixel data in RGBA format to video memory. A call to <see cref="INativeTexture.SetupEmpty"/>
 /// is to be considered required for this.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="texture"></param>
 /// <param name="format">The textures internal format.</param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="data">The block of pixel data to transfer.</param>
 /// <param name="dataLayout">The color layout of the specified data block.</param>
 /// <param name="dataElementType">The color element type of the specified data block.</param>
 public static void LoadData <T>(
     this INativeTexture texture,
     TexturePixelFormat format,
     int width, int height,
     T[] data,
     ColorDataLayout dataLayout,
     ColorDataElementType dataElementType) where T : struct
 {
     using (PinnedArrayHandle pinned = new PinnedArrayHandle(data))
     {
         texture.LoadData(
             format,
             width,
             height,
             pinned.Address,
             dataLayout,
             dataElementType);
     }
 }
示例#17
0
        void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps)
        {
            DefaultOpenTKBackendPlugin.GuardSingleThreadState();

            int lastTexId;

            GL.GetInteger(GetPName.TextureBinding2D, out lastTexId);
            if (lastTexId != this.handle)
            {
                GL.BindTexture(TextureTarget.Texture2D, this.handle);
            }

            // Set texture parameters
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)ToOpenTKTextureMinFilter(minFilter));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)ToOpenTKTextureMagFilter(magFilter));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)ToOpenTKTextureWrapMode(wrapX));
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)ToOpenTKTextureWrapMode(wrapY));

            // Anisotropic filtering
            if (anisoLevel > 0)
            {
                GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, (float)anisoLevel);
            }

            // If needed, care for Mipmaps
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, mipmaps ? 1 : 0);

            // Setup pixel format
            GL.TexImage2D(TextureTarget.Texture2D, 0,
                          ToOpenTKPixelFormat(format), width, height, 0,
                          GLPixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

            this.width   = width;
            this.height  = height;
            this.format  = format;
            this.mipmaps = mipmaps;

            if (lastTexId != this.handle)
            {
                GL.BindTexture(TextureTarget.Texture2D, lastTexId);
            }
        }
示例#18
0
        void INativeTexture.LoadData(TexturePixelFormat format, int width, int height, IntPtr data, ColorDataLayout dataLayout, ColorDataElementType dataElementType)
        {
            DefaultOpenTKBackendPlugin.GuardSingleThreadState();

            int lastTexId;

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

            // Load pixel data to video memory
            GL.TexImage2D(TextureTarget.Texture2D, 0,
                          ToOpenTKPixelFormat(format), width, height, 0,
                          dataLayout.ToOpenTK(), dataElementType.ToOpenTK(),
                          data);

            this.width  = width;
            this.height = height;
            this.format = format;

            GL.BindTexture(TextureTarget.Texture2D, lastTexId);
        }
示例#19
0
        private static TextureComponentCount ToOpenTKPixelInternalFormat(TexturePixelFormat format)
        {
            switch (format)
            {
            // ToDo
            //case TexturePixelFormat.Single: return TextureComponentCount./*R8Ext*/Rgb;
            //case TexturePixelFormat.Dual: return TextureComponentCount./*Rg8Ext*/Rgb;
            //case TexturePixelFormat.Rgb: return TextureComponentCount.Rgb;
            default:
            case TexturePixelFormat.Rgba: return(TextureComponentCount.Rgba);

                //case TexturePixelFormat.FloatSingle: return TextureComponentCount.R16fExt;
                //case TexturePixelFormat.FloatDual: return TextureComponentCount.Rg16fExt;
                //case TexturePixelFormat.FloatRgb: return TextureComponentCount.Rgb16fExt;
                //case TexturePixelFormat.FloatRgba: return TextureComponentCount.Rgba16fExt;

                // Compressed formats are not supported in OpenGL ES
                //case TexturePixelFormat.CompressedSingle: return (PixelInternalFormat)TextureComponentCount.CompressedRed;
                //case TexturePixelFormat.CompressedDual: return (PixelInternalFormat)TextureComponentCount.CompressedRg;
                //case TexturePixelFormat.CompressedRgb: return (PixelInternalFormat)TextureComponentCount.CompressedRgb;
                //case TexturePixelFormat.CompressedRgba: return (PixelInternalFormat)TextureComponentCount.CompressedRgba;
            }
        }
示例#20
0
        unsafe void INativeTexture.LoadData(TexturePixelFormat format, int width, int height, IntPtr data, ColorDataLayout dataLayout, ColorDataElementType dataElementType)
        {
            // Removed thread guards because of performance
            //DefaultOpenTKBackendPlugin.GuardSingleThreadState();

            WebGLTexture lastTexId = (WebGLTexture)GraphicsBackend.GL.GetParameter(WebGLRenderingContextBase.TEXTURE_BINDING_2D);

            GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, this.handle);

            // Load pixel data to video memory
            GraphicsBackend.GL.TexImage2D(WebGLRenderingContextBase.TEXTURE_2D, 0,
                                          ToOpenTKPixelInternalFormat(format), width, height, 0,
                                          dataLayout.ToOpenTK(), dataElementType.ToOpenTK(),
                                          TypedArray <Uint8ClampedArray, byte> .From(new Span <byte>(data.ToPointer(), /*ToDo*/ (width * height * 4))));

            GraphicsBackend.GL.GenerateMipmap(WebGLRenderingContextBase.TEXTURE_2D);

            this.width  = width;
            this.height = height;
            this.format = format;

            GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, lastTexId);
        }
示例#21
0
        void INativeTexture.LoadData <T>(TexturePixelFormat format, int width, int height, T[] data, ColorDataLayout dataLayout, ColorDataElementType dataElementType)
        {
            // Removed thread guards because of performance
            //DefaultOpenTKBackendPlugin.GuardSingleThreadState();

            int lastTexId;

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

            // Load pixel data to video memory
            GL.TexImage2D(TextureTarget.Texture2D, 0,
                          ToOpenTKPixelInternalFormat(format), width, height, 0,
                          dataLayout.ToOpenTK(), dataElementType.ToOpenTK(),
                          data);

            GL.GenerateMipmap(TextureTarget.Texture2D);

            this.width  = width;
            this.height = height;
            this.format = format;

            GL.BindTexture(TextureTarget.Texture2D, lastTexId);
        }
示例#22
0
文件: GL.cs 项目: Wiladams/NewTOAPIA
 public static void TexImage1D(int level, TextureInternalFormat internalformat, int width, int border, TexturePixelFormat format, PixelComponentType type, IntPtr pixels)
 {
     gl.glTexImage1D((int)Texture1DTarget.Texture1d, level, (int)internalformat, width, border, (int)format, (int)type, pixels);
 }
示例#23
0
 public static PixelFormat ConvertYakToVeldrid(TexturePixelFormat pixelFormat)
 {
     return((PixelFormat)pixelFormat);
 }
示例#24
0
        public void SetPixelFormatAndCreateStagingTextureAndDataArray(uint stagingTextureWidth, uint stagingTextureHeight, TexturePixelFormat pixelFormat)
        {
            _pixelFormat = TexturePixelFormatConverter.ConvertYakToVeldrid(pixelFormat);

            _stagingTextureWidth  = stagingTextureWidth;
            _stagingTextureHeight = stagingTextureHeight;

            if (StagingTextureId != 0UL)
            {
                _surfaceManager.DestroySurface(StagingTextureId);
            }

            StagingTextureId = _surfaceManager.CreateGpuCpuStagingSurface(_stagingTextureWidth,
                                                                          _stagingTextureHeight,
                                                                          _pixelFormat).Id;

            _data = new byte[4 * _stagingTextureWidth * _stagingTextureHeight];
        }
示例#25
0
 public void TexSubImage2D(Texture2DTarget target, int level, int xoffset, int yoffset, int width, int height, TexturePixelFormat format, PixelComponentType type, byte[] pixels)
 {
     gl.glTexSubImage2D((int)target, level, xoffset, yoffset, width, height, (int)format, (int)type, pixels);
 }
示例#26
0
        public void TexSubImage2D(Texture2DTarget target, int level, int xoffset, int yoffset, int width, int height, TexturePixelFormat format, PixelComponentType type, IntPtr pixels)
        {
            if (null == pixels || pixels == IntPtr.Zero)
                return;

            gl.glTexSubImage2D((int)target, level, xoffset, yoffset, width, height, (int)format, (int)type, pixels);
        }
示例#27
0
 public void TexSubImage1D(int level, int xoffset, int width, TexturePixelFormat format, PixelComponentType type, object[] pixels)
 {
     gl.glTexSubImage1D((int)Texture1DTarget.Texture1d, level, xoffset, width, (int)format, (int)type, pixels);
 }
示例#28
0
 public GLTexture2D(GraphicsInterface gi, int width, int height, TextureInternalFormat internalFormat, TexturePixelFormat pixelFormat, PixelComponentType pixelType, IntPtr pixelData, bool createMipMaps)
     : base(gi, TextureBindTarget.Texture2d)
 {
     SetupTexture2D(gi, width, height, internalFormat, pixelFormat, pixelType, pixelData, createMipMaps);
 }
示例#29
0
 void INativeTexture.SetupEmpty(TexturePixelFormat format, int width, int height, TextureMinFilter minFilter, TextureMagFilter magFilter, TextureWrapMode wrapX, TextureWrapMode wrapY, int anisoLevel, bool mipmaps)
 {
 }
 private static bool HasAlpha(TexturePixelFormat pixelFormat)
 {
     return(pixelFormat == TexturePixelFormat.DXT3 || pixelFormat == TexturePixelFormat.DXT5);
 }
示例#31
0
 private static bool HasAlpha(TexturePixelFormat pixelFormat)
 {
     return(pixelFormat == TexturePixelFormat.BC2 || pixelFormat == TexturePixelFormat.BC3);
 }
示例#32
0
        /// <inheritdoc />
        public override void UploadToTexture(IntPtr data, Vector2 size, TextureInternalFormat internalFormat, TexturePixelFormat pixelFormat)
        {
            InternalFormat intFormat = (InternalFormat)Enum.Parse(typeof(InternalFormat), internalFormat.ToString());
            PixelFormat    glFormat  = (PixelFormat)Enum.Parse(typeof(PixelFormat), pixelFormat.ToString());

            GLThread.ExecuteGLThread(() =>
            {
                // Set scaling to pixel perfect.
                Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMinFilter, Gl.NEAREST);
                Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMagFilter, Gl.NEAREST);

                Gl.TexImage2D(TextureTarget.Texture2d, 0, intFormat, (int)size.X, (int)size.Y, 0, glFormat, PixelType.UnsignedByte, data);
                Gl.GenerateMipmap(TextureTarget.Texture2d);

                CheckError("after uploading texture");
            });
        }
示例#33
0
 void INativeTexture.LoadData(TexturePixelFormat format, int width, int height, IntPtr data, ColorDataLayout dataLayout, ColorDataElementType dataElementType)
 {
 }
示例#34
0
 public void TexImage1D(Texture1DTarget target, int level, TextureInternalFormat internalformat, int width, int border, TexturePixelFormat format, PixelComponentType type, object pixels)
 {
     gl.glTexImage1D((int)target, level, (int)internalformat, width, border, (int)format, (int)type, pixels);
 }
示例#35
0
 public void TexImage2D(Texture2DTarget target, int level, TextureInternalFormat internalformat, int width, int height, int border, TexturePixelFormat format, PixelComponentType type, object pixels)
 {
     gl.glTexImage2D((int)target, level, (int)internalformat, width, height, border, (int)format, (int)type, pixels);
     CheckException();
 }
示例#36
0
 public GLTextureRectangle(GraphicsInterface gi, int width, int height, TextureInternalFormat internalFormat, TexturePixelFormat pixelFormat, PixelComponentType pixelType)
     : base(gi, TextureBindTarget.Rectangle)
 {
     gi.Enable(GLOption.TextureRectangle);
     SetupTexture2D(gi, width, height, internalFormat, pixelFormat, pixelType, IntPtr.Zero, false);
 }