예제 #1
0
 public void SetTileMode(bool tileX, bool tileY)
 {
     GPUStateMachine.BindTexture(0, texTarget, id);
     GL.TexParameter(texTarget, TextureParameterName.TextureWrapS, tileX ? (int)TextureWrapMode.Repeat : (int)TextureWrapMode.ClampToEdge);
     GL.TexParameter(texTarget, TextureParameterName.TextureWrapT, tileY ? (int)TextureWrapMode.Repeat : (int)TextureWrapMode.ClampToEdge);
     GPUStateMachine.UnbindTexture(0, texTarget);
 }
예제 #2
0
 public void SetEnableLinearFilter(bool linear)
 {
     GPUStateMachine.BindTexture(0, texTarget, id);
     GL.TexParameter(texTarget, TextureParameterName.TextureMagFilter, linear ? (int)TextureMagFilter.Linear : (int)TextureMagFilter.Nearest);
     GL.TexParameter(texTarget, TextureParameterName.TextureMinFilter, linear ? (int)TextureMinFilter.Linear : (int)TextureMinFilter.Nearest);
     GPUStateMachine.UnbindTexture(0, texTarget);
 }
예제 #3
0
        public void SetData(ITextureSource src)
        {
            GPUStateMachine.BindTexture(0, src.GetTextureTarget(), id);
            switch (src.GetDimensions())
            {
            case 1:
                GL.TexImage1D(src.GetTextureTarget(), src.GetLevels(), src.GetInternalFormat(), src.GetWidth(), 0, src.GetFormat(), src.GetType(), src.GetPixelData());
                break;

            case 2:
                GL.TexImage2D(src.GetTextureTarget(), src.GetLevels(), src.GetInternalFormat(), src.GetWidth(), src.GetHeight(), 0, src.GetFormat(), src.GetType(), src.GetPixelData());
                break;

            case 3:
                GL.TexImage3D(src.GetTextureTarget(), src.GetLevels(), src.GetInternalFormat(), src.GetWidth(), src.GetHeight(), src.GetDepth(), 0, src.GetFormat(), src.GetType(), src.GetPixelData());
                break;
            }

            GL.GenerateMipmap((GenerateMipmapTarget)src.GetTextureTarget());
            GPUStateMachine.UnbindTexture(0, src.GetTextureTarget());

            this.Width      = src.GetWidth();
            this.Height     = src.GetHeight();
            this.Depth      = src.GetDepth();
            this.LevelCount = src.GetLevels();

            this.format         = src.GetFormat();
            this.internalformat = src.GetInternalFormat();
            this.texTarget      = src.GetTextureTarget();
        }
예제 #4
0
 public static void SetBufferTexture(int slot, BufferTexture b)
 {
     if (b != null)
     {
         GPUStateMachine.BindTexture(slot, TextureTarget.TextureBuffer, b.id);
     }
     else
     {
         GPUStateMachine.BindTexture(slot, TextureTarget.TextureBuffer, 0);
     }
 }
예제 #5
0
        public static void SaveTexture(Texture t, string file)
        {
#if DEBUG
            Bitmap bmp = new Bitmap(t.Width, t.Height);
            System.Drawing.Imaging.BitmapData bmpData;

            bmpData = bmp.LockBits(new Rectangle(0, 0, t.Width, t.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            GPUStateMachine.BindTexture(0, t.texTarget, t.id);
            GL.GetTexImage(t.texTarget, 0, PixelFormat.Bgra, PixelType.UnsignedInt8888Reversed, bmpData.Scan0);
            GPUStateMachine.UnbindTexture(0, t.texTarget);
            bmp.UnlockBits(bmpData);

            bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
            bmp.Save(file);
            bmp.Dispose();
#endif
        }
예제 #6
0
 public void SetAnisotropicFilter(float taps)
 {
     GPUStateMachine.BindTexture(0, texTarget, id);
     GL.TexParameter(texTarget, (TextureParameterName)All.TextureMaxAnisotropyExt, taps);
     GPUStateMachine.UnbindTexture(0, texTarget);
 }
 public void SetStorage(GPUBuffer storage, SizedInternalFormat internalFormat)
 {
     GPUStateMachine.BindTexture(0, TextureTarget.TextureBuffer, id);
     GL.TexBuffer(TextureBufferTarget.TextureBuffer, internalFormat, storage.id);
     GPUStateMachine.UnbindTexture(0, TextureTarget.TextureBuffer);
 }
예제 #8
0
        public static void Draw(PrimitiveType type, int first, int count)
        {
            if (count == 0)
            {
                return;
            }

            if (curVarray == null)
            {
                return;
            }
            if (curProg == null)
            {
                return;
            }
            if (curFramebuffer == null)
            {
                return;
            }


            for (int i = 0; i < textures.Count; i++)
            {
                GPUStateMachine.BindTexture(i, textures[i].texTarget, textures[i].id);
            }
            for (int i = 0; i < feedbackBufs.Count; i++)
            {
                GPUStateMachine.BindBuffer(BufferTarget.TransformFeedbackBuffer, feedbackBufs[i].Item1.id, i, (IntPtr)feedbackBufs[i].Item2, (IntPtr)feedbackBufs[i].Item3);
            }



            GPUStateMachine.BindFramebuffer(curFramebuffer.id);
            if (feedbackBufs.Count > 0)
            {
                GL.BeginTransformFeedback((TransformFeedbackPrimitiveType)feedbackPrimitive);
            }

            GL.UseProgram(curProg.id);
            GPUStateMachine.BindVertexArray(curVarray.id);
            if (curIndices != null)
            {
                GPUStateMachine.BindBuffer(BufferTarget.ElementArrayBuffer, curIndices.id);
            }

            if (curIndices != null)
            {
                GL.DrawElements(type, count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            }
            else
            {
                GL.DrawArrays(type, first, count);
            }

            if (feedbackBufs.Count > 0)
            {
                GL.EndTransformFeedback();
            }

            for (int i = 0; i < feedbackBufs.Count; i++)
            {
                GPUStateMachine.UnbindBuffer(BufferTarget.TransformFeedbackBuffer, i);
            }
            for (int i = 0; i < textures.Count; i++)
            {
                GPUStateMachine.UnbindTexture(i, textures[i].texTarget);
            }

            textures.Clear();
            feedbackBufs.Clear();
        }