Exemplo n.º 1
0
        /// <summary>
        /// Maps a texture
        /// </summary>
        /// <param name="texture">Texture to map</param>
        /// <param name="access">Access mode</param>
        /// <returns></returns>
        public bool MapTexture(Texture2D texture, BufferAccess access)
        {
            if (texture == null || IsLocked || Handle == 0)
            {
                return(false);
            }

            Texture   = texture;
            Rectangle = texture.Bounds;
            IsLocked  = true;

            // Bind PBO
            TK.GL.BindBuffer(TK.BufferTarget.PixelUnpackBuffer, Handle);

            // Copy the texture to the PBO
            TK.GL.TexSubImage2D(TK.TextureTarget.Texture2D, 0, 0, 0, Texture.Size.Width, Texture.Size.Height, TK.PixelFormat.Bgra, TK.PixelType.UnsignedByte, IntPtr.Zero);

            //	if (Data == null || Data.Length != Size.Width * Size.Height * 4)
            //		Data = new byte[Size.Width * Size.Height * 4];

            // Map PBO to client memory
            IntPtr ptr = TK.GL.MapBuffer(TK.BufferTarget.PixelUnpackBuffer, (TK.BufferAccess)BufferAccess.ReadWrite);



            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Maps the current frame buffer
        /// </summary>
        /// <param name="rectangle">Rectangle</param>
        /// <param name="access">Access mode</param>
        /// <returns></returns>
        public bool MapFrameBuffer(Rectangle rectangle, BufferAccess access)
        {
            Texture   = null;
            Rectangle = Rectangle.Empty;

            // No buffer available
            if (Handle == 0 || IsLocked)
            {
                return(false);
            }

            // Reserve enough space
            Rectangle = rectangle;
            if (Data == null || Data.Length != Size.Width * Size.Height * 4)
            {
                Data = new byte[Size.Width * Size.Height * 4];
            }

            Access   = access;
            IsLocked = true;

            // Write only, no need to get the content
            if (Access == BufferAccess.WriteOnly)
            {
                return(true);
            }

            // Read the frame buffer
            TK.GL.MapBuffer(TK.BufferTarget.PixelPackBuffer, (TK.BufferAccess)access);
            TK.GL.ReadPixels(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, TK.PixelFormat.Bgra, TK.PixelType.UnsignedByte, IntPtr.Zero);

            TK.GL.BindBuffer(TK.BufferTarget.PixelPackBuffer, 0);
            return(true);
        }
Exemplo n.º 3
0
 public IntPtr Map(BufferAccess access)
 {
     EnsureLoaded();
     var ptr = GL.MapBuffer(Target, access);
     IsMapped = true;
     return ptr;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Map the buffer to program memory for writing/reading
        /// </summary>
        /// <param name="bufferAccess"></param>
        public unsafe IntPtr Map(BufferAccess bufferAccess)
        {
            this.Assert();

            Bind(BufferTarget.ArrayBuffer);
            return(GL.MapBuffer(BufferTarget.ArrayBuffer, bufferAccess));
        }
Exemplo n.º 5
0
 public GLBufferLockedBytes(GLBufferObject buffer, BufferTarget target, BufferAccess access, IntPtr pointer, int offset, int size)
 {
     fTarget = target;
     fBuffer = buffer;
     fOffset = offset;
     fSize = size;
     fAccess = access;
     fLockingThread = Thread.CurrentThread;
     fData = pointer;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new <see cref="BufferMapping"/>.
        /// </summary>
        /// <param name="buffer">The <see cref="IBuffer"/> to map.</param>
        /// <param name="access">The <see cref="BufferAccess"/>.</param>
        /// <param name="mapImmediately"><c>true</c> if the <paramref name="buffer"/> shall be mapped directly, otherwise <c>false</c>.</param>
        public BufferMapping(IBuffer buffer, BufferAccess access, bool mapImmediately = true)
            : this()
        {
            Contract.Requires<ArgumentNullException>(buffer != null);

            this.access = access;
            this.buffer = buffer;
            if (mapImmediately)
            {
                this.Map();
            }
        }
Exemplo n.º 7
0
        public IntPtr Map(BufferAccess access)
        {
            if (!this.Loaded)
            {
                var s = string.Format("VBO.MapBuffer ({0}): buffer not loaded", this.Name);
                log.Error(s);
                throw new InvalidOperationException(s);
            }

            var ptr = GL.MapBuffer(this.Target, access);

            this.Mapped = true;
            return(ptr);
        }
Exemplo n.º 8
0
            public Mapper(GraphicsContext ctx, Buffer thisBuffer, BufferAccess mask)
            {
                CheckCurrentContext(ctx);
                CheckThatExistence(ctx, thisBuffer);

                _Context = ctx;
                _Buffer  = thisBuffer;

                // Leave unmapped if not mapped yet
                _UnmapOnDispose = thisBuffer.MappedBuffer == IntPtr.Zero;

                if (_UnmapOnDispose)
                {
                    _Buffer.Map(_Context, mask);
                }
            }
Exemplo n.º 9
0
        /// <summary>
        /// Map the GPU buffer allocated by this Buffer.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> required for mapping this Buffer.
        /// </param>
        /// <param name="mask">
        /// A <see cref="BufferAccess"/> that specify the map access.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown if this Buffer is already mapped.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown if this Buffer does not exist for <paramref name="ctx"/>.
        /// </exception>
        /// <remarks>
        /// <para>
        /// After being mapped, the mapped buffer is accessible via <see cref="MapGet{T}(GraphicsContext, long)"/> or
        /// <see cref="MapSet{T}(GraphicsContext, T, long)"/>, or via <see cref="MappedBuffer"/> as raw pointer.
        /// </para>
        /// </remarks>
        public void Map(GraphicsContext ctx, BufferAccess mask)
        {
            CheckThisExistence(ctx);

            Debug.Assert(ctx.Extensions.VertexBufferObject_ARB || ctx.Version.IsCompatible(Gl.Version_200_ES) || _GpuBuffer != null);
            if (ctx.Extensions.VertexBufferObject_ARB || ctx.Version.IsCompatible(Gl.Version_200_ES))
            {
                BindCore(ctx);

                _MappedBuffer = Gl.MapBuffer(Target, mask);
            }
            else
            {
                _MappedBuffer = _GpuBuffer.AlignedBuffer;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Map the GPU buffer allocated by this Buffer.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> required for mapping this Buffer.
        /// </param>
        /// <param name="mask">
        /// A <see cref="BufferAccess"/> that specify the map access.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown if this Buffer is already mapped.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown if this Buffer does not exist for <paramref name="ctx"/>.
        /// </exception>
        public void Map(GraphicsContext ctx, BufferAccess mask)
        {
            CheckThisExistence(ctx);

            if (IsMapSupported(ctx))
            {
#if !MONODROID
                if (ctx.Extensions.DirectStateAccess_ARB || ctx.Version.IsCompatible(Gl.Version_450))
                {
                    if ((MappedBuffer = Gl.MapNamedBuffer(ObjectName, mask)) == IntPtr.Zero)
                    {
                        Gl.CheckErrors();
                    }
                }
                else
                {
#endif
                ctx.Bind(this);

                if ((MappedBuffer = Gl.MapBuffer(Target, mask)) == IntPtr.Zero)
                {
                    Gl.CheckErrors();
                }
#if !MONODROID
            }
#endif
            }
            else
            {
                if (GpuBuffer == null)
                {
                    throw new GlException(ErrorCode.InvalidOperation);
                }
                if ((MappedBuffer = GpuBuffer.AlignedBuffer) == IntPtr.Zero)
                {
                    throw new GlException(ErrorCode.InvalidOperation);
                }
            }

            Debug.Assert(MappedBuffer != IntPtr.Zero);

            MapOffset = IntPtr.Zero;
            MapSize   = Size;
            _Access   = mask;
        }
Exemplo n.º 11
0
        public MDLBlock(BinaryReader reader, BlockHeader header) : base(header)
        {
            InertiaTensor  = reader.ReadVector3();
            BoundingRadius = reader.ReadSingle();
            if (header.Signature != BlockHeader.MAGIC_MODEL0)
            {
                AllowDistanceFade   = reader.ReadUInt32() > 0;
                IncludesBoundingBox = reader.ReadUInt32() > 0;
                if (IncludesBoundingBox)
                {
                    AABBMin    = reader.ReadVector3();
                    AABBMax    = reader.ReadVector3();
                    AABBCenter = reader.ReadVector3();
                    AABBYaw    = reader.ReadSingle();
                }
                UseUniqueMaterials      = reader.ReadUInt32();
                UseUniqueTextures       = reader.ReadUInt32();
                UseGenericGeometry      = reader.ReadUInt32();
                VertexBufferAccessFlags = (BufferAccess)reader.ReadUInt32();
                reader.ReadBytes(12 * 4);
            }
            else
            {
                AllowDistanceFade = false;
            }

            int textureReferenceCount = reader.ReadInt32();

            for (int i = 0; i < textureReferenceCount; i++)
            {
                TextureReferences.Add(new TextureReference(reader));
            }

            int materialCount = reader.ReadInt32();

            for (int i = 0; i < materialCount; i++)
            {
                Materials.Add(new MaterialProps(reader));
            }
        }
Exemplo n.º 12
0
 static extern IntPtr glitz_buffer_map(IntPtr buffer, BufferAccess access);
Exemplo n.º 13
0
 public IBufferLock Lock(long startOffset, long length, BufferAccess requestedAccess) =>
 base.innerRefT.Lock(startOffset, length, requestedAccess);
Exemplo n.º 14
0
 public static void BindImageTexture(uint unit, uint texture, uint level, bool layered, uint layer, BufferAccess access, PixelInternalFormat format)
 => bindImageTexture(unit, texture, level, layered, layer, access, format);
Exemplo n.º 15
0
 /// <summary>
 /// Maps GPU data into the cpu and return an IntPtr pointing to that data, use (<typeparamref name="T"/>*)Map(...) for speed xD
 /// </summary>
 /// <param name="bufferAccess"></param>
 /// <returns></returns>
 public IntPtr Map(BufferAccess bufferAccess)
 {
     Bind();
     return(GL.MapBuffer(bufferType, bufferAccess));
 }
Exemplo n.º 16
0
 public IntPtr MapBuffer(BufferTarget target, BufferAccess access)
 {
     IntPtr retValue = glMapBufferARB((int)target, (int)access);
     return retValue;
 }
Exemplo n.º 17
0
		public Status Unmap (BufferAccess access)
		{
			return GlitzAPI.glitz_buffer_unmap (Handle);
		}
 public static void BindImageTextureEXT(UInt32 index, UInt32 texture, Int32 level, bool layered, Int32 layer, BufferAccess access, InternalFormat format)
 {
     Debug.Assert(Delegates.pglBindImageTextureEXT != null, "pglBindImageTextureEXT not implemented");
     Delegates.pglBindImageTextureEXT(index, texture, level, layered, layer, (Int32)access, (Int32)format);
     LogCommand("glBindImageTextureEXT", null, index, texture, level, layered, layer, access, format);
     DebugCheckErrors(null);
 }
Exemplo n.º 19
0
 public IDisposable CreateMapGuard(GraphicsContext ctx, BufferAccess mask)
 {
     return(new Mapper(ctx, this, mask));
 }
Exemplo n.º 20
0
        public IntPtr MapBuffer(BufferAccess access)
        {
            // If it's already mapped, return the pointer that already
            // exists for the mapping.
            if (IsMapped)
                return GetMappedPointer();

            // If it's not already mapped, then map it and return the pointer.
            IntPtr mappedPointer = GI.MapBuffer(fBufferTarget, access);

            return mappedPointer;
        }
Exemplo n.º 21
0
 public Status Unmap(BufferAccess access)
 {
     return(GlitzAPI.glitz_buffer_unmap(Handle));
 }
Exemplo n.º 22
0
 public IntPtr Map(BufferAccess access)
 {
     return(GlitzAPI.glitz_buffer_map(Handle, access));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Map buffer into application's address space.
 /// </summary>
 /// <param name="access">An enumerant indicating the operations the client may perform on the data store through the pointer while the buffer data is mapped.</param>
 /// <returns>Returns a pointer through which the application can read or write the buffer's data store.</returns>
 public IntPtr Map(BufferAccess access)
 {
     return NativeMethods.cgMapBuffer(this.Handle, access);
 }
Exemplo n.º 24
0
 public IntPtr MapRange(uint offset, uint length, BufferAccess access)
 => Gl.MapBufferRange(BufferTarget, new IntPtr(offset), length, (uint)access);
Exemplo n.º 25
0
 /// <summary>
 /// Initializes a new <see cref="BufferMapping"/>.
 /// </summary>
 /// <param name="buffer">The <see cref="IBuffer"/> to map.</param>
 /// <param name="access">The <see cref="BufferAccess"/>.</param>
 public BufferMapping(IBuffer buffer, BufferAccess access)
     : this(buffer, access, true)
 {
     Contract.Requires<ArgumentNullException>(buffer != null);
 }
Exemplo n.º 26
0
		static extern IntPtr glitz_buffer_map (IntPtr buffer, BufferAccess access);
Exemplo n.º 27
0
 public IntPtr Map(BufferAccess access)
 {
     return(IGL.Primary.MapBuffer((int)BufferTarget.ShaderStorageBuffer, (int)access));
 }
Exemplo n.º 28
0
		public IntPtr Map (BufferAccess access)
		{
			return GlitzAPI.glitz_buffer_map (Handle, access);
		}
Exemplo n.º 29
0
 public static extern IntPtr cgMapBuffer(IntPtr buffer, BufferAccess access);
Exemplo n.º 30
0
 public IntPtr Map(BufferAccess access)
 => Gl.MapBuffer(BufferTarget, access);
Exemplo n.º 31
0
 public IntPtr MapBuffer(BufferAccess access)
 {
     Bind();
     return(GL.MapBuffer(bufferTarget, access));
 }
Exemplo n.º 32
0
		public static IntPtr MapBuffer(BufferTarget target, BufferAccess access)
		{
			glMapBuffer deleg = BaseGraphicsContext.Current.Loader.Get<glMapBuffer>();
			if (deleg != null)
				return deleg(target, access);
			return default(IntPtr);
		}
Exemplo n.º 33
0
 public IntPtr Map(BufferAccess access = BufferAccess.WriteOnly)
 {
     return(GL.MapBuffer(target, access));
 }