Пример #1
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();
        }
Пример #2
0
        public void BufferData <T>(int offset, T[] data, BufferUsageHint hint) where T : struct
        {
            //if (data.Length < 1) throw new Exception("Buffer is empty!");
            //if (data.Length == 0) return;

            dataLen = data.Length;

            if (data.Length != 0)
            {
                size = (Marshal.SizeOf(data[0]) * data.Length);
            }

            if (addr == IntPtr.Zero)
            {
                GPUStateMachine.BindBuffer(target, id);

                GL.BufferData(target, (IntPtr)size, data, hint);

                GPUStateMachine.UnbindBuffer(target);
            }
            else
            {
                throw new Exception("This buffer is mapped!");
            }
        }
Пример #3
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);
 }
Пример #4
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);
 }
Пример #5
0
        public Texture this[FramebufferAttachment attachment]
        {
            set
            {
                bindings[attachment] = value;
                GPUStateMachine.BindFramebuffer(id);
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachment, value.texTarget, value.id, 0);

                GL.DrawBuffers(bindings.Keys.Count,
                               bindings.Keys.OrderByDescending((a) => (int)a).Reverse().Cast <DrawBuffersEnum>().ToArray());

                if (GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete)
                {
                    throw new Exception("Incomplete Framebuffer!");
                }

                GPUStateMachine.UnbindFramebuffer();
            }
            get
            {
                if (bindings.ContainsKey(attachment))
                {
                    return(bindings[attachment]);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #6
0
 public static void SetFramebuffer(Framebuffer framebuf)
 {
     if (curFramebuffer != null && curFramebuffer.id != framebuf.id)
     {
         GPUStateMachine.UnbindFramebuffer();
     }
     curFramebuffer = framebuf;
 }
Пример #7
0
 public static void SetVertexArray(VertexArray varray)
 {
     if (curVarray != null && varray.id != curVarray.id)
     {
         GPUStateMachine.UnbindVertexArray();
     }
     curVarray = varray;
 }
Пример #8
0
        public static void SetUniformBuffer(GPUBuffer buf, int bufIndex, int baseOff, int size)
        {
            if (buf.target != BufferTarget.UniformBuffer)
            {
                throw new ArgumentException("Argument must be a uniform buffer!");
            }

            GPUStateMachine.BindBuffer(BufferTarget.UniformBuffer, buf.id, bufIndex, (IntPtr)baseOff, (IntPtr)size);
        }
Пример #9
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);
     }
 }
Пример #10
0
        public void SetBufferObject(int index, GPUBuffer buffer, int elementCount, VertexAttribPointerType type)
        {
            GPUStateMachine.BindVertexArray(id);

            GL.EnableVertexAttribArray(index);
            GPUStateMachine.BindBuffer(buffer.target, buffer.id);
            GL.VertexAttribPointer(index, elementCount, type, false, 0, 0);
            GPUStateMachine.UnbindBuffer(buffer.target);

            GPUStateMachine.UnbindVertexArray();
        }
Пример #11
0
        public static void SetIndexBuffer(GPUBuffer indices)
        {
            if (indices.target != BufferTarget.ElementArrayBuffer)
            {
                throw new ArgumentException("Argument must be an index buffer!");
            }

            if (curIndices != null && indices.id != curIndices.id)
            {
                GPUStateMachine.UnbindBuffer(BufferTarget.ElementArrayBuffer);
            }
            curIndices = indices;
        }
Пример #12
0
        public GPUBuffer(BufferTarget target, int size, bool read)
        {
            id          = GL.GenBuffer();
            this.target = target;

            this.size = size;

            GPUStateMachine.BindBuffer(target, id);
            GL.BufferStorage(target, (IntPtr)size, IntPtr.Zero, BufferStorageFlags.MapPersistentBit | BufferStorageFlags.MapWriteBit | (read ? BufferStorageFlags.MapReadBit : 0));

            addr = GL.MapBufferRange(target, IntPtr.Zero, (IntPtr)size, BufferAccessMask.MapPersistentBit | BufferAccessMask.MapUnsynchronizedBit | BufferAccessMask.MapInvalidateBufferBit | BufferAccessMask.MapFlushExplicitBit | BufferAccessMask.MapWriteBit | (read ? BufferAccessMask.MapReadBit : 0));
            GPUStateMachine.UnbindBuffer(target);
        }
Пример #13
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
        }
Пример #14
0
 public void SetAnisotropicFilter(float taps)
 {
     GPUStateMachine.BindTexture(0, texTarget, id);
     GL.TexParameter(texTarget, (TextureParameterName)All.TextureMaxAnisotropyExt, taps);
     GPUStateMachine.UnbindTexture(0, texTarget);
 }
Пример #15
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();
        }
Пример #16
0
 private static void Window_Resize(object sender, EventArgs e)
 {
     GPUStateMachine.SetViewport(0, 0, game.Width, game.Height);
     InputLL.SetWinXY(game.Location.X, game.Location.Y, game.ClientSize.Width, game.ClientSize.Height);
 }
Пример #17
0
 public void UnMapBuffer()
 {
     GPUStateMachine.BindBuffer(target, id);
     GL.UnmapBuffer(target);
     GPUStateMachine.UnbindBuffer(target);
 }
Пример #18
0
 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);
 }
Пример #19
0
 public void MapBuffer(bool read, int offset, int size)
 {
     GPUStateMachine.BindBuffer(target, id);
     addr = GL.MapBufferRange(target, (IntPtr)offset, (IntPtr)size, BufferAccessMask.MapPersistentBit | BufferAccessMask.MapUnsynchronizedBit | BufferAccessMask.MapFlushExplicitBit | BufferAccessMask.MapInvalidateBufferBit | BufferAccessMask.MapWriteBit | (read ? BufferAccessMask.MapReadBit : 0));
     GPUStateMachine.UnbindBuffer(target);
 }