Exemple #1
0
        public MultisampleTarget(int width, int height, int samples)
        {
            Width  = width;
            Height = height;
            texID  = GL.GenTexture();
            GLBind.BindTexture(0, GL.GL_TEXTURE_2D_MULTISAMPLE, texID);
            if (GL.GLES)
            {
                GL.TexStorage2DMultisample(GL.GL_TEXTURE_2D_MULTISAMPLE, samples, GL.GL_RGBA8, width, height, true);
            }
            else
            {
                GL.TexImage2DMultisample(GL.GL_TEXTURE_2D_MULTISAMPLE, samples, GL.GL_RGBA, width, height, true);
            }
            depthID = GL.GenRenderbuffer();
            GL.BindRenderbuffer(GL.GL_RENDERBUFFER, depthID);
            GL.RenderbufferStorageMultisample(GL.GL_RENDERBUFFER, samples, GL.GL_DEPTH_COMPONENT24, width, height);
            GL.BindRenderbuffer(GL.GL_RENDERBUFFER, 0);
            fbo = GL.GenFramebuffer();
            GL.BindFramebuffer(GL.GL_FRAMEBUFFER, fbo);
            GL.FramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D_MULTISAMPLE, texID, 0);
            GL.FramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
                                       GL.GL_DEPTH_ATTACHMENT,
                                       GL.GL_RENDERBUFFER, depthID);
            int status = GL.CheckFramebufferStatus(GL.GL_FRAMEBUFFER);

            GL.BindFramebuffer(GL.GL_FRAMEBUFFER, 0);
        }
Exemple #2
0
 public override void BindTo(int unit)
 {
     GLBind.BindTexture(unit, GL.GL_TEXTURE_CUBE_MAP, ID);
     if (unit != 4 && LevelCount > 1 && maxLevel != currentLevels)
     {
         currentLevels = maxLevel;
         GL.TexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_MAX_LEVEL, maxLevel);
     }
 }
 public override void BindTo(int unit)
 {
     GLBind.BindTexture(unit, GL.GL_TEXTURE_2D, ID);
     //Unit 4 is for creation, don't call it a trillion times
     if (unit != 4 && LevelCount > 1 && maxLevel != currentLevels)
     {
         currentLevels = maxLevel;
         GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_LEVEL, maxLevel);
     }
 }
Exemple #4
0
        public Texture2D(int width, int height, bool hasMipMaps, SurfaceFormat format) : this(true)
        {
            Width  = width;
            Height = height;
            Format = format;
            Format.GetGLFormat(out glInternalFormat, out glFormat, out glType);
            LevelCount    = hasMipMaps ? CalculateMipLevels(width, height) : 1;
            currentLevels = hasMipMaps ? (LevelCount - 1) : 0;
            //Bind the new TextureD
            GLBind.Trash();
            GLBind.BindTexture(4, GL.GL_TEXTURE_2D, ID);
            //initialise the texture data
            var imageSize = 0;
            Dxt1 = format == SurfaceFormat.Dxt1;
            if (glFormat == GL.GL_NUM_COMPRESSED_TEXTURE_FORMATS)
            {
                if (GLExtensions.S3TC)
                {
                    switch (Format)
                    {
                    case SurfaceFormat.Dxt1:
                    case SurfaceFormat.Dxt3:
                    case SurfaceFormat.Dxt5:
                        imageSize = ((Width + 3) / 4) * ((Height + 3) / 4) * format.GetSize();
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                    GL.CompressedTexImage2D(GL.GL_TEXTURE_2D, 0, glInternalFormat,
                                            Width, Height, 0,
                                            imageSize, IntPtr.Zero);
                }
                else
                {
                    GL.TexImage2D(GL.GL_TEXTURE_2D, 0,
                                  GL.GL_RGBA,
                                  Width, Height, 0,
                                  GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, IntPtr.Zero);
                }
            }
            else
            {
                GL.TexImage2D(GL.GL_TEXTURE_2D, 0,
                              glInternalFormat,
                              Width, Height, 0,
                              glFormat, glType, IntPtr.Zero);
            }
            //enable filtering
            GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
            GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
        }
Exemple #5
0
 public override void BindTo(int unit)
 {
     if (IsDisposed)
     {
         throw new ObjectDisposedException("Texture2D");
     }
     GLBind.BindTexture(unit, GL.GL_TEXTURE_2D, ID);
     //Unit 4 is for creation, don't call it a trillion times
     if (unit != 4 && LevelCount > 1 && maxLevel != currentLevels)
     {
         currentLevels = maxLevel;
         GL.TexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_LEVEL, maxLevel);
     }
 }
Exemple #6
0
 public override void BindTo(int unit)
 {
     GLBind.BindTexture(unit, GL.GL_TEXTURE_2D, ID);
 }