コード例 #1
0
ファイル: GLTexture2D.cs プロジェクト: Wiladams/NewTOAPIA
        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
        /// <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");
            });
        }
コード例 #3
0
ファイル: Texture.cs プロジェクト: RoseLeBlood/libral
        public Texture(string name, byte[] data, TextureDataType type, TextureFormat format,
                       Size pSize, TextureInternalFormat internalFormat)
            : base("tex_" + name, GlHandleType.Texture)
        {
            gl.glBindTexture((uint)GL.TEXTURE_2D, m_iObject[0]);
            gl.glTexImage2D((uint)GL.TEXTURE_2D, 0, (int)internalFormat, pSize.Width, pSize.Height, 0, (uint)format, (uint)type,
                            data);

            gl.glTexParameteri((uint)GL.TEXTURE_2D, (uint)GL.TEXTURE_WRAP_S, (int)GL.CLAMP_TO_EDGE);
            gl.glTexParameteri((uint)GL.TEXTURE_2D, (uint)GL.TEXTURE_WRAP_T, (int)GL.CLAMP_TO_EDGE);
            gl.glTexParameteri((uint)GL.TEXTURE_2D, (uint)GL.TEXTURE_MIN_FILTER, (int)GL.LINEAR_MIPMAP_LINEAR);
            gl.glTexParameteri((uint)GL.TEXTURE_2D, (uint)GL.TEXTURE_MAG_FILTER, (int)GL.LINEAR);

            gl.glGenerateMipmap((uint)GL.TEXTURE_2D);
            m_sDimension = pSize;

            Register(true);
        }
コード例 #4
0
        /// <inheritdoc />
        public override RenderTarget CreateMSAARenderTarget(int samples, Vector2 size, TextureInternalFormat internalFormat = TextureInternalFormat.Rgba, bool attachStencil = false)
        {
            RenderTarget resultTarget = null;

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

            GLThread.ExecuteGLThread(() =>
            {
                // Create the FBO.
                uint newFbo = Gl.GenFramebuffer();
                Gl.BindFramebuffer(FramebufferTarget.Framebuffer, newFbo);

                // Create the texture.
                uint renderTexture = Gl.GenTexture();
                Gl.BindTexture(TextureTarget.Texture2dMultisample, renderTexture);
                Gl.TexImage2DMultisample(TextureTarget.Texture2dMultisample, samples, intFormat, (int)size.X, (int)size.Y, true);

                // Attach the texture to the frame buffer.
                Gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2dMultisample, 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.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, samples, 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($"MSAA Framebuffer creation failed. Error code {status}.", MessageSource.GL);
                }

                // Construct a texture object for it.
                Texture targetTexture = new GLTexture(renderTexture, new Vector2(size.X, size.Y), null, $"MSAA{samples} FBO Texture");

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

                // Clear the target.
                ClearScreen();

                CheckError("creating msaa fbo");

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

            return(resultTarget);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
ファイル: GIInternal.cs プロジェクト: Wiladams/NewTOAPIA
 internal void CopyTexImage2D(Texture2DTarget target, int level, TextureInternalFormat internalFormat, int x, int y, int width, int height, int border)
 {
     gl.glCopyTexImage2D((int)target, level, (int)internalFormat, x, y, width, height, border);
     CheckException();
 }
コード例 #7
0
ファイル: GIInternal.cs プロジェクト: Wiladams/NewTOAPIA
        //internal void ReadPixels(int x, int y, int width, int height, GLPixelFormat format, PixelComponentType type, sbyte[] pixels)
        //{
        //    gl.glReadPixels(x, y, width, height, (int)format, (int)type, pixels);
        //    CheckException();
        //}

        //internal void ReadPixels(int x, int y, int width, int height, GLPixelFormat format, PixelComponentType type, short[] pixels)
        //{
        //    gl.glReadPixels(x, y, width, height, (int)format, (int)type, pixels);
        //    CheckException();
        //}

        //internal void ReadPixels(int x, int y, int width, int height, GLPixelFormat format, PixelComponentType type, ushort[] pixels)
        //{
        //    gl.glReadPixels(x, y, width, height, (int)format, (int)type, pixels);
        //    CheckException();
        //}

        //internal void ReadPixels(int x, int y, int width, int height, GLPixelFormat format, PixelComponentType type, int[] pixels)
        //{
        //    gl.glReadPixels(x, y, width, height, (int)format, (int)type, pixels);
        //    CheckException();
        //}

        //internal void ReadPixels(int x, int y, int width, int height, GLPixelFormat format, PixelComponentType type, uint[] pixels)
        //{
        //    gl.glReadPixels(x, y, width, height, (int)format, (int)type, pixels);
        //    CheckException();
        //}

        //internal void ReadPixels(int x, int y, int width, int height, GLPixelFormat format, PixelComponentType type, float[] pixels)
        //{
        //    gl.glReadPixels(x, y, width, height, (int)format, (int)type, pixels);
        //    CheckException();
        //}

        #endregion

        internal void CopyTexImage1D(int level, TextureInternalFormat internalFormat, int x, int y, int width, int border)
        {
            gl.glCopyTexImage1D((int)Texture1DTarget.Texture1d, level, (int)internalFormat, x, y, width, border);
            CheckException();
        }
コード例 #8
0
ファイル: GL.cs プロジェクト: Wiladams/NewTOAPIA
 public static void CopyTexImage1D(int level, TextureInternalFormat internalFormat, int x, int y, int width, int border)
 {
     gl.glCopyTexImage1D((int)Texture1DTarget.Texture1d, level, (int)internalFormat, x, y, width, border);
 }
コード例 #9
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);
 }
コード例 #10
0
 public void Storage(uint width, uint height, TextureInternalFormat format)
 {
     gl.glBindRenderbuffer((uint)GL.RENDERBUFFER, glObject);
     gl.glRenderbufferStorage((uint)GL.RENDERBUFFER, format, width, height);
 }
コード例 #11
0
 public Renderbuffer(string strName, uint width, uint height, TextureInternalFormat format)
     : base(strName, GlHandleType.Renderbuffer)
 {
     Storage(width, height, format);
 }
コード例 #12
0
ファイル: Texture.cs プロジェクト: RoseLeBlood/libral
 public Texture(Image image, TextureInternalFormat internalFormat = TextureInternalFormat.RGBA8)
     : this(image.Name.Replace("img_", ""), image.ToByteArray(), TextureDataType.UnsignedInt8888Rev, TextureFormat.RGBA, image.Size, internalFormat)
 {
 }
コード例 #13
0
ファイル: GLTexture2D.cs プロジェクト: Wiladams/NewTOAPIA
 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);
 }
コード例 #14
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);
 }
コード例 #15
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);
 }
コード例 #16
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();
 }
コード例 #17
0
 public static extern void glRenderbufferStorage(uint i, TextureInternalFormat format, uint width, uint height);