Exemplo n.º 1
0
        public long CreateHandle(int textureId, int samplerId)
        {
            long texHandle = GL.Arb.GetTextureSamplerHandle(textureId, samplerId);

            mErrHandler.LogGLError(nameof(CreateHandle));
            return(texHandle);
        }
Exemplo n.º 2
0
 public void SetLineWidth(float width)
 {
     if (width > 0f)
     {
         GL.Enable(EnableCap.LineSmooth);
         GL.LineWidth(width);
         mErrHandler.LogGLError("SetLineWidth.Enable");
     }
     else
     {
         GL.Disable(EnableCap.LineSmooth);
         mErrHandler.LogGLError("SetLineWidth.Disable");
     }
 }
Exemplo n.º 3
0
        public GLDeviceMemory(MgMemoryAllocateInfo pAllocateInfo, IGLErrorHandler errHandler)
        {
            mErrHandler   = errHandler;
            mBufferType   = (GLMemoryBufferType)pAllocateInfo.MemoryTypeIndex;
            mIsHostCached = (mBufferType == GLMemoryBufferType.INDIRECT || mBufferType == GLMemoryBufferType.IMAGE);

            if (pAllocateInfo.AllocationSize > (ulong)int.MaxValue)
            {
                throw new ArgumentOutOfRangeException("pAllocateInfo.AllocationSize > int.MaxValue");
            }

            mBufferSize = (int)pAllocateInfo.AllocationSize;

            if (mBufferType != GLMemoryBufferType.IMAGE)
            {
                mBufferTarget = GetBufferTarget(mBufferType);
            }

            if (mIsHostCached || pAllocateInfo.MemoryTypeIndex == (uint)GLMemoryBufferType.IMAGE)
            {
                mHandle = Marshal.AllocHGlobal(mBufferSize);
            }
            else
            {
                if (mBufferTarget.HasValue)
                {
                    var buffers = new uint[1];
                    // ARB_direct_state_access
                    // Allows buffer objects to be initialised without binding them
                    GL.CreateBuffers(1, buffers);

                    mErrHandler.LogGLError("GL.CreateBuffers");
                    mBufferId = buffers[0];

                    // TODO : update flags based on buffer request
                    BufferStorageFlags flags = BufferStorageFlags.MapWriteBit | BufferStorageFlags.MapPersistentBit | BufferStorageFlags.MapCoherentBit;
                    GL.NamedBufferStorage(mBufferId, mBufferSize, IntPtr.Zero, flags);
                    mErrHandler.LogGLError("GL.NamedBufferStorage");

                    //					BufferAccessMask rangeFlags = BufferAccessMask.MapWriteBit | BufferAccessMask.MapPersistentBit | BufferAccessMask.MapCoherentBit;
                    //					Handle = GL.MapNamedBufferRange (buffers[0], (IntPtr)0, BufferSize, rangeFlags);
                }
            }
        }
Exemplo n.º 4
0
        public Result MapMemory(IMgDevice device, ulong offset, ulong size, uint flags, out IntPtr ppData)
        {
            if (mIsHostCached)
            {
                if (offset > (ulong)Int32.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("offset >= Int32.MaxValue");
                }

                var handleOffset = (Int32)offset;
                ppData    = IntPtr.Add(mHandle, handleOffset);
                mIsMapped = true;
                return(Result.SUCCESS);
            }
            else
            {
                if (offset >= (ulong)Int64.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("offset >= Int64.MaxValue");
                }

                if (size >= (ulong)int.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("size >= Int64.MaxValue");
                }

                var handleOffset = (IntPtr)((Int64)offset);
                var handleSize   = (int)size;

                // TODO: flags translate
                BufferAccessMask rangeFlags = BufferAccessMask.MapWriteBit | BufferAccessMask.MapPersistentBit | BufferAccessMask.MapCoherentBit;
                ppData = GL.MapNamedBufferRange(mBufferId, IntPtr.Zero, handleSize, rangeFlags);

                mErrHandler.LogGLError("GL.MapNamedBufferRange");

                //ppData = GL.Ext.MapNamedBufferRange(BufferId, handleOffset, handleSize, BufferAccessMask.MapWriteBit | BufferAccessMask.MapCoherentBit);


                mIsMapped = true;
                return(Result.SUCCESS);
            }
        }
Exemplo n.º 5
0
        public int CreateImageView(IGLImage image, MgImageViewCreateInfo pCreateInfo)
        {
            var internalFormat = mImgFormat.GetGLFormat(pCreateInfo.Format, true);

            var textureTarget = GetGLTextureTarget(pCreateInfo.ViewType);

            int textureId = GL.GenTexture();

            mErrHandler.LogGLError("GL.CreateTextures (AFTER)");

            GL.TextureView​(
                textureId,
                textureTarget,
                image.OriginalTextureId,
                (PixelInternalFormat)internalFormat.InternalFormat,
                (int)pCreateInfo.SubresourceRange.BaseMipLevel,
                (int)pCreateInfo.SubresourceRange.LevelCount,
                (int)pCreateInfo.SubresourceRange.BaseArrayLayer​,
                (int)pCreateInfo.SubresourceRange.LayerCount​);

            mErrHandler.LogGLError("GL.TextureView (AFTER)");

            return(textureId);
        }
Exemplo n.º 6
0
 public void ApplyScissors(GLCmdScissorParameter scissors)
 {
     GL.ScissorArray(scissors.Parameters.First, scissors.Parameters.Count, scissors.Parameters.Values);
     mErrHandler.LogGLError("ApplyScissors");
 }
Exemplo n.º 7
0
 public void BindIndexBuffer(uint vbo, uint bufferId)
 {
     GL.VertexArrayElementBuffer(vbo, bufferId);
     mErrHandler.LogGLError(nameof(BindIndexBuffer));
 }
Exemplo n.º 8
0
 public void SetTextureWrapS(int samplerId, MgSamplerAddressMode addressModeU)
 {
     GL.SamplerParameter(samplerId, SamplerParameterName.TextureWrapS, (int)GetAddressMode(addressModeU));
     mErrHandler.LogGLError("SamplerParameter (TextureWrapS)");
 }