Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonShader"/> class.
        /// </summary>
        /// <param name="graphics">Graphics interface that created this shader.</param>
        /// <param name="name">The name of the shader.</param>
        /// <param name="type">Type of the shader.</param>
        /// <param name="entryPoint">The entry point method for the shader.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is an empty string.</exception>
        protected GorgonShader(GorgonGraphics graphics, string name, ShaderType type, string entryPoint)
            : base(name)
        {
            Graphics = graphics;

#if DEBUG
            IsDebug = true;
#else
            IsDebug = false;
#endif

            ShaderType = type;
            EntryPoint = entryPoint;

            // Determine the version by the supported feature level.
            switch (Graphics.VideoDevice.SupportedFeatureLevel)
            {
            case DeviceFeatureLevel.SM5:
                Version = ShaderVersion.Version5;
                break;

            case DeviceFeatureLevel.SM4_1:
                Version = ShaderVersion.Version4_1;
                break;

            case DeviceFeatureLevel.SM4:
                Version = ShaderVersion.Version4;
                break;

            default:
                Version = ShaderVersion.Version2A_B;
                break;
            }
        }
Example #2
0
 /// <summary>
 /// Function to copy a texture subresource from another texture.
 /// </summary>
 /// <param name="sourceTexture">Source texture to copy.</param>
 /// <param name="sourceRange">[Optional] The dimensions of the source area to copy.</param>
 /// <param name="sourceArrayIndex">[Optional] The array index of the sub resource to copy.</param>
 /// <param name="sourceMipLevel">[Optional] The mip map level of the sub resource to copy.</param>
 /// <param name="destX">[Optional] Horizontal offset into the destination texture to place the copied data.</param>
 /// <param name="destY">[Optional] Vertical offset into the destination texture to place the copied data.</param>
 /// <param name="destArrayIndex">[Optional] The array index of the destination sub resource to copy into.</param>
 /// <param name="destMipLevel">[Optional] The mip map level of the destination sub resource to copy into.</param>
 /// <param name="unsafeCopy">[Optional] TRUE to disable all range checking for coorindates, FALSE to clip coorindates to safe ranges.</param>
 /// <param name="deferred">[Optional] The deferred context to use when copying the sub resource.</param>
 /// <remarks>Use this method to copy a specific sub resource of a texture to another sub resource of another texture, or to a different sub resource of the same texture.  The <paramref name="sourceRange"/>
 /// coordinates must be inside of the destination, if it is not, then the source data will be clipped against the destination region. No stretching or filtering is supported by this method.
 /// <para>For SM_4_1 and SM_5 video devices, texture formats can be converted if they belong to the same format group (e.g. R8G8B8A8, R8G8B8A8_UInt, R8G8B8A8_Int, R8G8B8A8_UIntNormal, etc.. are part of the R8G8B8A8 group).  If the
 /// video device is a SM_4 then no format conversion will be done and an exception will be thrown if format conversion is attempted.</para>
 /// <para>When copying sub resources (e.g. mip-map levels), the mip levels and array indices must be different if copying to the same texture.  If they are not, an exception will be thrown.</para>
 /// <para>Pass NULL (Nothing in VB.Net) to the sourceRange parameter to copy the entire sub resource.</para>
 /// <para>Video devices that have a feature level of SM2_a_b cannot copy sub resource data in a 1D texture if the texture is not a staging texture.</para>
 /// <para>The <paramref name="unsafeCopy"/> parameter is meant to provide a performance increase by skipping any checking of the destination and source coorindates passed in to the function.  When set to TRUE it will
 /// just pass the coordinates without testing and adjusting for clipping.  If your coordinates are outside of the source/destination texture range, then the behaviour will be undefined (i.e. depending on your
 /// video driver, it may clip, or throw an exception or do nothing).  Care must be taken to ensure the coordinates fit within the source and destination if this parameter is set to TRUE.</para>
 /// <para>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net) then the immediate context will be used.  If this method is called from multiple threads, then a deferred context should be passed for each thread that is
 /// accessing the sub resource.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when the texture parameter is NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.ArgumentException">Thrown when the formats cannot be converted because they're not of the same group or the current video device is a SM_4 device.
 /// <para>-or-</para>
 /// <para>Thrown when the subResource and destSubResource are the same and the source texture is the same as this texture.</para>
 /// </exception>
 /// <exception cref="System.InvalidOperationException">Thrown when this texture is an immutable texture.
 /// </exception>
 /// <exception cref="System.NotSupportedException">Thrown when the video device has a feature level of SM2_a_b and this texture or the source texture are not staging textures.</exception>
 public void CopySubResource(GorgonTexture2D sourceTexture,
                             Rectangle?sourceRange   = null,
                             int sourceArrayIndex    = 0,
                             int sourceMipLevel      = 0,
                             int destX               = 0,
                             int destY               = 0,
                             int destArrayIndex      = 0,
                             int destMipLevel        = 0,
                             bool unsafeCopy         = false,
                             GorgonGraphics deferred = null)
 {
     OnCopySubResource(sourceTexture,
                       new GorgonBox
     {
         Front  = 0,
         Depth  = 1,
         Left   = sourceRange != null ? sourceRange.Value.Left : 0,
         Width  = sourceRange != null ? sourceRange.Value.Width : Settings.Width,
         Top    = sourceRange != null ? sourceRange.Value.Top : 0,
         Height = sourceRange != null ? sourceRange.Value.Height : Settings.Height
     },
                       sourceArrayIndex,
                       sourceMipLevel,
                       destX,
                       destY,
                       0,
                       destArrayIndex,
                       destMipLevel,
                       unsafeCopy,
                       deferred);
 }
Example #3
0
 /// <summary>
 /// Function to copy a texture subresource from another texture.
 /// </summary>
 /// <param name="sourceTexture">Source texture to copy.</param>
 /// <param name="sourceRange">[Optional] The dimensions of the source area to copy.</param>
 /// <param name="sourceArrayIndex">[Optional] The array index of the sub resource to copy.</param>
 /// <param name="sourceMipLevel">[Optional] The mip map level of the sub resource to copy.</param>
 /// <param name="destX">[Optional] Horizontal offset into the destination texture to place the copied data.</param>
 /// <param name="destY">[Optional] Vertical offset into the destination texture to place the copied data.</param>
 /// <param name="destZ">[Optional] Depth offset into the destination texture to place the copied data.</param>
 /// <param name="destArrayIndex">[Optional] The array index of the destination sub resource to copy into.</param>
 /// <param name="destMipLevel">[Optional] The mip map level of the destination sub resource to copy into.</param>
 /// <param name="unsafeCopy">[Optional] TRUE to disable all range checking for coorindates, FALSE to clip coorindates to safe ranges.</param>
 /// <param name="deferred">[Optional] The deferred context to use when copying the sub resource.</param>
 /// <remarks>Use this method to copy a specific sub resource of a texture to another sub resource of another texture, or to a different sub resource of the same texture.  The <paramref name="sourceRange"/>
 /// coordinates must be inside of the destination, if it is not, then the source data will be clipped against the destination region. No stretching or filtering is supported by this method.
 /// <para>For SM_4_1 and SM_5 video devices, texture formats can be converted if they belong to the same format group (e.g. R8G8B8A8, R8G8B8A8_UInt, R8G8B8A8_Int, R8G8B8A8_UIntNormal, etc.. are part of the R8G8B8A8 group).  If the
 /// video device is a SM_4 then no format conversion will be done and an exception will be thrown if format conversion is attempted.</para>
 /// <para>When copying sub resources (e.g. mip-map levels), the mip levels and array indices must be different if copying to the same texture.  If they are not, an exception will be thrown.</para>
 /// <para>Pass NULL (Nothing in VB.Net) to the sourceRange parameter to copy the entire sub resource.</para>
 /// <para>Video devices that have a feature level of SM2_a_b cannot copy sub resource data in a 1D texture if the texture is not a staging texture.</para>
 /// <para>The <paramref name="unsafeCopy"/> parameter is meant to provide a performance increase by skipping any checking of the destination and source coorindates passed in to the function.  When set to TRUE it will
 /// just pass the coordinates without testing and adjusting for clipping.  If your coordinates are outside of the source/destination texture range, then the behaviour will be undefined (i.e. depending on your
 /// video driver, it may clip, or throw an exception or do nothing).  Care must be taken to ensure the coordinates fit within the source and destination if this parameter is set to TRUE.</para>
 /// <para>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net) then the immediate context will be used.  If this method is called from multiple threads, then a deferred context should be passed for each thread that is
 /// accessing the sub resource.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when the texture parameter is NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.ArgumentException">Thrown when the formats cannot be converted because they're not of the same group or the current video device is a SM_4 device.
 /// <para>-or-</para>
 /// <para>Thrown when the subResource and destSubResource are the same and the source texture is the same as this texture.</para>
 /// </exception>
 /// <exception cref="System.InvalidOperationException">Thrown when this texture is an immutable texture.
 /// </exception>
 /// <exception cref="System.NotSupportedException">Thrown when the video device has a feature level of SM2_a_b and this texture or the source texture are not staging textures.</exception>
 public void CopySubResource(GorgonTexture3D sourceTexture,
                             GorgonBox?sourceRange   = null,
                             int sourceArrayIndex    = 0,
                             int sourceMipLevel      = 0,
                             int destX               = 0,
                             int destY               = 0,
                             int destZ               = 0,
                             int destArrayIndex      = 0,
                             int destMipLevel        = 0,
                             bool unsafeCopy         = false,
                             GorgonGraphics deferred = null)
 {
     OnCopySubResource(sourceTexture,
                       sourceRange == null ? new GorgonBox
     {
         X      = 0,
         Y      = 0,
         Z      = 0,
         Width  = Settings.Width,
         Height = Settings.Height,
         Depth  = Settings.Depth
     } : sourceRange.Value,
                       sourceArrayIndex,
                       sourceMipLevel,
                       destX,
                       destY,
                       destZ,
                       destArrayIndex,
                       destMipLevel,
                       unsafeCopy,
                       deferred);
 }
Example #4
0
 public override GorgonTextureLockData Lock(BufferLockFlags lockFlags,
                                            int arrayIndex          = 0,
                                            int mipLevel            = 0,
                                            GorgonGraphics deferred = null)
 {
     throw new NotSupportedException(Resources.GORGFX_DEPTH_OPERATION_NOT_SUPPORTED);
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonInputLayout"/> class.
 /// </summary>
 /// <param name="graphics">Graphics interface that created this object.</param>
 /// <param name="name">Name of the object.</param>
 /// <param name="shader">Vertex shader to bind the layout with.</param>
 internal GorgonInputLayout(GorgonGraphics graphics, string name, GorgonShader shader)
     : base(name)
 {
     Graphics = graphics;
     Shader   = shader;
     GorgonRenderStatistics.InputLayoutCount++;
 }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonTextureLockData"/> class.
        /// </summary>
        /// <param name="graphics">The graphics context that owns this lock.</param>
        /// <param name="texture">The texture that owns this lock.</param>
        /// <param name="cache">Lock cache that will contain this lock.</param>
        /// <param name="data">The data returned from the lock.</param>
        /// <param name="mipLevel">The mip level of the sub resource.</param>
        /// <param name="arrayIndex">Array index of the sub resource.</param>
        internal GorgonTextureLockData(GorgonGraphics graphics, GorgonTexture texture, GorgonTextureLockCache cache, DX.DataBox data, int mipLevel, int arrayIndex)
            : base(mipLevel, arrayIndex, 0)
        {
            Graphics = graphics;
            Texture  = texture;
            _cache   = cache;

            Width  = Texture.Settings.Width;
            Height = Texture.Settings.Height;
            Depth  = Texture.Settings.Depth;

            // Calculate the current size at the given mip level.
            for (int mip = 0; mip < mipLevel; ++mip)
            {
                if (Width > 1)
                {
                    Width >>= 1;
                }
                if (Height > 1)
                {
                    Height >>= 1;
                }
                if (Depth > 1)
                {
                    Depth >>= 1;
                }
            }

            PitchInformation = new GorgonFormatPitch(data.RowPitch, data.SlicePitch);
            Data             = new GorgonDataStream(data.DataPointer.ToPointer(), data.SlicePitch);
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonBaseBuffer"/> class.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="name">The name.</param>
        /// <param name="settings">The settings.</param>
        protected GorgonBaseBuffer(GorgonGraphics graphics, string name, IBufferSettings settings)
            : base(graphics, name)
        {
            _viewCache = new GorgonViewCache(this);

            Settings = settings;

            D3DUsage = (D3D.ResourceUsage)settings.Usage;

            // Determine access rights.
            switch (settings.Usage)
            {
            case BufferUsage.Dynamic:
                D3DCPUAccessFlags = D3D.CpuAccessFlags.Write;
                break;

            case BufferUsage.Immutable:
                D3DCPUAccessFlags = D3D.CpuAccessFlags.None;
                break;

            case BufferUsage.Staging:
                D3DCPUAccessFlags = D3D.CpuAccessFlags.Write | D3D.CpuAccessFlags.Read;
                break;

            default:
                D3DCPUAccessFlags = D3D.CpuAccessFlags.None;
                break;
            }
        }
Example #8
0
        /// <summary>
        /// Function to update the buffer with data.
        /// </summary>
        /// <typeparam name="T">Type of data, must be a value type.</typeparam>
        /// <param name="values">Values to write to the buffer.</param>
        /// <param name="offset">Offset in the buffer, in bytes, to write at.</param>
        /// <param name="deferred">[Optional] The deferred context used to update the buffer.</param>
        /// <remarks>This method can only be used with buffers that have Default usage.  Other buffer usages will thrown an exception.
        /// <para>
        /// If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net), the immediate context will be used to update the buffer.  If it is non-NULL, then it
        /// will use the specified deferred context.
        /// <para>If you are using a deferred context, it is necessary to use that context to update the buffer because 2 threads may not access the same resource at the same time.
        /// Passing a separate deferred context will alleviate that.</para>
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="values"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the buffer usage is not set to default.</exception>
        public void Update <T>(T[] values, int offset, GorgonGraphics deferred = null)
            where T : struct
        {
            GorgonDebug.AssertNull(values, "values");

#if DEBUG
            if (Settings.Usage != BufferUsage.Default)
            {
                throw new GorgonException(GorgonResult.AccessDenied, Resources.GORGFX_NOT_DEFAULT_USAGE);
            }
#endif
            if (deferred == null)
            {
                deferred = Graphics;
            }

            deferred.Context.UpdateSubresource(values, D3DResource, 0, 0, 0, new D3D11.ResourceRegion
            {
                Left   = offset,
                Right  = offset + DirectAccess.SizeOf <T>() * values.Length,
                Top    = 0,
                Bottom = 1,
                Front  = 0,
                Back   = 1
            });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonOutputGeometryShader"/> class.
        /// </summary>
        /// <param name="graphics">The graphics interface that owns this object.</param>
        /// <param name="name">The name of the pixel shader.</param>
        /// <param name="entryPoint">The entry point method for the shader.</param>
        /// <param name="rasterizedStream">Stream number to be rasterized.</param>
        /// <param name="outputElements">A list of elements to describe the layout of the data for output.</param>
        /// <param name="bufferStrides">The size of each buffer.</param>
        internal GorgonOutputGeometryShader(GorgonGraphics graphics, string name, string entryPoint, int rasterizedStream, IList <GorgonStreamOutputElement> outputElements, IList <int> bufferStrides)
            : base(graphics, name, entryPoint)
        {
            if (graphics.VideoDevice.SupportedFeatureLevel < DeviceFeatureLevel.SM4)
            {
                throw new GorgonException(GorgonResult.CannotCreate,
                                          string.Format(Resources.GORGFX_REQUIRES_SM, DeviceFeatureLevel.SM4));
            }

            // If the stream to be rasterized is outside of the range for stream output, then set it to no rasterization.
            if ((rasterizedStream < -1) || (rasterizedStream > 3))
            {
                rasterizedStream = -1;
            }

            _elements     = new D3D.StreamOutputElement[outputElements.Count];
            _elementSizes = new int[bufferStrides.Count];
            for (int i = 0; i < _elements.Length; i++)
            {
                _elements[i] = outputElements[i].Convert();
            }

            for (int i = 0; i < bufferStrides.Count; i++)
            {
                _elementSizes[i] = bufferStrides[i];
            }

            RasterizedStream = rasterizedStream;
            Elements         = outputElements;
        }
Example #10
0
 /// <summary>
 /// Function to lock a CPU accessible texture sub resource for reading/writing.
 /// </summary>
 /// <param name="lockFlags">Flags used to lock.</param>
 /// <param name="arrayIndex">[Optional] Array index of the sub resource to lock.</param>
 /// <param name="mipLevel">[Optional] The mip-map level of the sub resource to lock.</param>
 /// <param name="deferred">[Optional] The deferred graphics context used to lock the texture.</param>
 /// <returns>A stream used to write to the texture.</returns>
 /// <remarks>This method is used to lock down a sub resource in the texture for reading/writing. When locking a texture, the entire texture sub resource is locked and returned.  There is no setting to return a portion of the texture subresource.
 /// <para>This method is only available to textures created with a staging or dynamic usage setting.  Otherwise an exception will be raised.</para>
 /// <para>Only the Write, Discard (with the Write flag) and Read flags may be used in the <paramref name="lockFlags"/> parameter.  The Read flag can only be used with staging textures and is mutually exclusive.</para>
 /// <para>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net), then the immediate context is used.  Use a deferred context to allow multiple threads to lock the
 /// texture at the same time.</para>
 /// </remarks>
 /// <returns>This method will return a <see cref="GorgonLibrary.Graphics.GorgonTextureLockData">GorgonTextureLockData</see> object containing information about the locked sub resource as well as
 /// a <see cref="GorgonLibrary.IO.GorgonDataStream">GorgonDataStream</see> that is used to access the locked sub resource data.</returns>
 /// <exception cref="System.ArgumentException">Thrown when the texture is not a dynamic or staging texture.
 /// <para>-or-</para>
 /// <para>Thrown when the texture is not a staging texture and the Read flag has been specified.</para>
 /// <para>-or-</para>
 /// <para>Thrown when the texture is not a dynamic texture and the discard flag has been specified.</para>
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="arrayIndex"/> or the <paramref name="mipLevel"/> parameters are less than 0, or larger than their respective counts in the texture settings.</exception>
 public virtual GorgonTextureLockData Lock(BufferLockFlags lockFlags,
                                           int arrayIndex          = 0,
                                           int mipLevel            = 0,
                                           GorgonGraphics deferred = null)
 {
     return(OnLock(lockFlags, arrayIndex, mipLevel, deferred));
 }
Example #11
0
 public override void UpdateSubResource(GorgonImageBuffer buffer,
                                        Rectangle destRect,
                                        int destArrayIndex      = 0,
                                        int destMipLevel        = 0,
                                        GorgonGraphics deferred = null)
 {
     throw new NotSupportedException(Resources.GORGFX_DEPTH_OPERATION_NOT_SUPPORTED);
 }
Example #12
0
        /// <summary>
        /// Function used to lock the underlying buffer for reading/writing.
        /// </summary>
        /// <param name="lockFlags">Flags used when locking the buffer.</param>
        /// <param name="context">A graphics context to use when locking the buffer.</param>
        /// <returns>
        /// A data stream containing the buffer data.
        /// </returns>
        /// <exception cref="System.ArgumentException">
        /// lockFlags
        /// or
        /// lockFlags
        /// </exception>
        /// <remarks>
        /// Use the <paramref name="context" /> parameter to determine the context in which the buffer should be updated. This is necessary to use that context
        /// to update the buffer because 2 threads may not access the same resource at the same time.
        /// </remarks>
        protected override GorgonDataStream OnLock(BufferLockFlags lockFlags, GorgonGraphics context)
        {
            DX.DataStream lockStream;

            context.Context.MapSubresource(D3DBuffer, GetMapMode(lockFlags), D3D11.MapFlags.None, out lockStream);

            return(new GorgonDataStream(lockStream.DataPointer, (int)lockStream.Length));
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonGeometryShader"/> class.
 /// </summary>
 /// <param name="graphics">The graphics interface that owns this object.</param>
 /// <param name="name">The name of the pixel shader.</param>
 /// <param name="entryPoint">The entry point method for the shader.</param>
 internal GorgonGeometryShader(GorgonGraphics graphics, string name, string entryPoint)
     : base(graphics, name, ShaderType.Geometry, entryPoint)
 {
     if (graphics.VideoDevice.SupportedFeatureLevel < DeviceFeatureLevel.SM4)
     {
         throw new GorgonException(GorgonResult.CannotCreate,
                                   string.Format(Resources.GORGFX_REQUIRES_SM, DeviceFeatureLevel.SM4));
     }
 }
Example #14
0
        /// <summary>
        /// Function to unlock a locked buffer.
        /// </summary>
        /// <param name="deferred">[Optional] The deferred context that was used to lock the buffer.</param>
        /// <remarks>If <paramref name="deferred"/> is NULL (Nothing in VB.Net), then the immediate graphics context will be used to unlock the buffer.  Otherwise, the specified deferred context will be used
        /// to unlock the buffer.
        /// <para>Ensure that the context used to lock the buffer is the same as the one passed to <paramref name="deferred"/>.</para>
        /// </remarks>
        public void Unlock(GorgonGraphics deferred = null)
        {
            if (deferred == null)
            {
                deferred = Graphics;
            }

            deferred.Context.UnmapSubresource(D3DBuffer, 0);
        }
Example #15
0
 /// <summary>
 /// Function to copy a texture subresource from another texture.
 /// </summary>
 /// <param name="sourceTexture">Source texture to copy.</param>
 /// <param name="sourceRange">The dimensions of the source area to copy.</param>
 /// <param name="destX">Horizontal offset into the destination texture to place the copied data.</param>
 /// <param name="destY">Vertical offset into the destination texture to place the copied data.</param>
 /// <param name="unsafeCopy">[Optional] TRUE to disable all range checking for coorindates, FALSE to clip coorindates to safe ranges.</param>
 /// <param name="deferred">[Optional] The deferred context to use when copying the sub resource.</param>
 /// <remarks>Use this method to copy a specific sub resource of a texture to another sub resource of another texture, or to a different sub resource of the same texture.  The <paramref name="sourceRange"/>
 /// coordinates must be inside of the destination, if it is not, then the source data will be clipped against the destination region. No stretching or filtering is supported by this method.
 /// <para>For SM_4_1 and SM_5 video devices, texture formats can be converted if they belong to the same format group (e.g. R8G8B8A8, R8G8B8A8_UInt, R8G8B8A8_Int, R8G8B8A8_UIntNormal, etc.. are part of the R8G8B8A8 group).  If the
 /// video device is a SM_4 then no format conversion will be done and an exception will be thrown if format conversion is attempted.</para>
 /// <para>When copying sub resources (e.g. mip-map levels), the mip levels and array indices must be different if copying to the same texture.  If they are not, an exception will be thrown.</para>
 /// <para>Pass NULL (Nothing in VB.Net) to the sourceRange parameter to copy the entire sub resource.</para>
 /// <para>Video devices that have a feature level of SM2_a_b cannot copy sub resource data in a 1D texture if the texture is not a staging texture.</para>
 /// <para>The <paramref name="unsafeCopy"/> parameter is meant to provide a performance increase by skipping any checking of the destination and source coorindates passed in to the function.  When set to TRUE it will
 /// just pass the coordinates without testing and adjusting for clipping.  If your coordinates are outside of the source/destination texture range, then the behaviour will be undefined (i.e. depending on your
 /// video driver, it may clip, or throw an exception or do nothing).  Care must be taken to ensure the coordinates fit within the source and destination if this parameter is set to TRUE.</para>
 /// <para>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net) then the immediate context will be used.  If this method is called from multiple threads, then a deferred context should be passed for each thread that is
 /// accessing the sub resource.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when the texture parameter is NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.ArgumentException">Thrown when the formats cannot be converted because they're not of the same group or the current video device is a SM_4 device.
 /// <para>-or-</para>
 /// <para>Thrown when the subResource and destSubResource are the same and the source texture is the same as this texture.</para>
 /// </exception>
 /// <exception cref="System.InvalidOperationException">Thrown when this texture is an immutable texture.
 /// </exception>
 /// <exception cref="System.NotSupportedException">Thrown when the video device has a feature level of SM2_a_b and this texture or the source texture are not staging textures.</exception>
 public void CopySubResource(GorgonTexture2D sourceTexture,
                             Rectangle sourceRange,
                             int destX,
                             int destY,
                             bool unsafeCopy         = false,
                             GorgonGraphics deferred = null)
 {
     CopySubResource(sourceTexture, sourceRange, 0, 0, destX, destY, 0, 0, unsafeCopy, deferred);
 }
Example #16
0
        /// <summary>
        /// Function to update the buffer.
        /// </summary>
        /// <param name="stream">Stream containing the data used to update the buffer.</param>
        /// <param name="offset">Offset, in bytes, into the buffer to start writing at.</param>
        /// <param name="size">The number of bytes to write.</param>
        /// <param name="deferred">[Optional] The deferred context used to update the buffer.</param>
        /// <remarks>This method can only be used with buffers that have Default usage.  Other buffer usages will thrown an exception.
        /// <para>Please note that constant buffers don't use the <paramref name="offset"/> and <paramref name="size"/> parameters.</para>
        /// <para>This method will respect the <see cref="GorgonLibrary.IO.GorgonDataStream.Position">Position</see> property of the data stream.
        /// This means that it will start reading from the stream at the current position.  To read from the beginning of the stream, set the position
        /// to 0.</para>
        /// <para>
        /// If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net), the immediate context will be used to update the buffer.  If it is non-NULL, then it
        /// will use the specified deferred context.
        /// <para>If you are using a deferred context, it is necessary to use that context to update the buffer because 2 threads may not access the same resource at the same time.
        /// Passing a separate deferred context will alleviate that.</para>
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the buffer usage is not set to default.</exception>
        public void Update(GorgonDataStream stream, int offset, int size, GorgonGraphics deferred = null)
        {
            if (deferred == null)
            {
                deferred = Graphics;
            }

            OnUpdate(stream, offset, size, deferred);
        }
Example #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VertexBufferBindingList"/> class.
 /// </summary>
 /// <param name="graphics">The graphics.</param>
 internal VertexBufferBindingList(GorgonGraphics graphics)
 {
     _graphics = graphics;
     _bindings = new GorgonVertexBufferBinding[graphics.VideoDevice.SupportedFeatureLevel < DeviceFeatureLevel.SM4_1 ? 16 : 32];
     for (int i = 0; i < _bindings.Length; i++)
     {
         _bindings[i] = GorgonVertexBufferBinding.Empty;
     }
 }
Example #18
0
        /// <summary>
        /// Function to clear the render target view.
        /// </summary>
        /// <param name="color">Color used to clear the render target view.</param>
        /// <param name="deferred">[Optional] A deferred context to use when clearing the depth/stencil buffer.</param>
        /// <remarks>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net), the immediate context will be used to clear the render target.  If it is non-NULL, then it
        /// will use the specified deferred context to clear the render target.
        /// <para>If you are using a deferred context, it is necessary to use that context to clear the render target because 2 threads may not access the same resource at the same time.
        /// Passing a separate deferred context will alleviate that.</para>
        /// </remarks>
        public void Clear(GorgonColor color, GorgonGraphics deferred = null)
        {
            if (deferred != null)
            {
                deferred.Context.ClearRenderTargetView(D3DView, color.SharpDXColor4);
                return;
            }

            Resource.Graphics.Context.ClearRenderTargetView(D3DView, color.SharpDXColor4);
        }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonGlyphTextureBrush"/> class.
 /// </summary>
 /// <param name="graphics">Graphics interface that is managing the texture used by the brush.</param>
 internal GorgonGlyphTextureBrush(GorgonGraphics graphics)
 {
     _graphics        = graphics.ImmediateContext;
     _textureSettings = new GorgonTexture2DSettings
     {
         Format     = BufferFormat.R8G8B8A8_UIntNormal,
         ArrayCount = 1,
         MipCount   = 1
     };
 }
Example #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonResource" /> class.
        /// </summary>
        /// <param name="graphics">The graphics interface that owns this object.</param>
        /// <param name="name">Name of this resource.</param>
        /// <remarks>Names for the resource are required, but do not need to be unique.  Names provide a way to organize the objects and can be ignored.</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is empty.</exception>
        protected GorgonResource(GorgonGraphics graphics, string name)
            : base(name)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }

            Graphics = graphics;
        }
Example #21
0
        /// <summary>
        /// Function to clear the render target and an attached depth/stencil buffer.
        /// </summary>
        /// <param name="color">Color used to clear the render target.</param>
        /// <param name="depthValue">Value used to clear the depth buffer.</param>
        /// <param name="stencilValue">Value used to clear the stencil buffer.</param>
        /// <param name="deferred">[Optional] A deferred context to use when clearing the render target.</param>
        /// <remarks>
        /// This will only clear the default view for the render target.
        /// <para>
        /// If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net), the immediate context will be used to clear the render target.  If it is non-NULL, then it
        /// will use the specified deferred context to clear the render target.
        /// <para>If you are using a deferred context, it is necessary to use that context to clear the render target because 2 threads may not access the same resource at the same time.
        /// Passing a separate deferred context will alleviate that.</para>
        /// </para>
        /// </remarks>
        public void Clear(GorgonColor color, float depthValue, byte stencilValue, GorgonGraphics deferred = null)
        {
            _defaultRenderTargetView.Clear(color, deferred);

            if (DepthStencilBuffer == null)
            {
                return;
            }

            DepthStencilBuffer.Clear(depthValue, stencilValue, deferred);
        }
Example #22
0
 /// <summary>
 /// Function to copy data from the CPU to the texture on the GPU.
 /// </summary>
 /// <param name="buffer">A buffer containing the image data to copy.</param>
 /// <param name="destBox">A 3D box that will specify the region that will receive the data.</param>
 /// <param name="destArrayIndex">[Optional] The array index that will receive the data.</param>
 /// <param name="destMipLevel">[Optional] The mip map level that will receive the data.</param>
 /// <param name="deferred">[Optional] A deferred graphics context used to copy the data.</param>
 /// <exception cref="System.InvalidOperationException">Thrown when the texture is dynamic or immutable.
 /// <para>-or-</para>
 /// <para>Thrown when the texture is multisampled.</para>
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="destArrayIndex"/> or the <paramref name="destMipLevel"/> is less than 0 or greater than/equal to the
 /// number of array indices or mip levels in the texture.</exception>
 /// <remarks>
 /// Use this to copy data into a texture with a usage of staging or default.  If the <paramref name="destBox"/> values are larger than the dimensions of the texture, then the data will be clipped.
 /// <para>Passing NULL (Nothing in VB.Net) to the <paramref name="destArrayIndex"/> and/or the <paramref name="destMipLevel"/> parameters will use the first array index and/or mip map level.</para>
 /// <para>This method will not work with depth/stencil textures or with textures that have multisampling applied.</para>
 /// <para>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net) then the immediate context will be used.  If this method is called from multiple threads, then a deferred context should be passed for each thread that is
 /// accessing the sub resource.</para>
 /// </remarks>
 public void UpdateSubResource(GorgonImageBuffer buffer,
                               GorgonBox destBox,
                               int destArrayIndex      = 0,
                               int destMipLevel        = 0,
                               GorgonGraphics deferred = null)
 {
     OnUpdateSubResource(buffer,
                         destBox,
                         destArrayIndex,
                         destMipLevel,
                         deferred);
 }
Example #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonEffect"/> class.
        /// </summary>
        /// <param name="graphics">The graphics interface that constructed this effect.</param>
        /// <param name="name">The name of the effect.</param>
        /// <param name="passCount">The pass count.</param>
        protected GorgonEffect(GorgonGraphics graphics, string name, int passCount)
            : base(name)
        {
            Graphics           = graphics;
            Passes             = new GorgonEffectPassArray(this, passCount);
            RequiredParameters = new List <string>();
            Parameters         = new Dictionary <string, object>();

            _prevConstantBuffers = new Dictionary <StateKey, GorgonConstantBuffer>();
            _prevSamplers        = new Dictionary <StateKey, GorgonTextureSamplerStates>();
            _prevShaderViews     = new Dictionary <StateKey, GorgonShaderView>();
            _prevShaders         = new Dictionary <ShaderType, GorgonShader>();
        }
Example #24
0
        /// <summary>
        /// Function used to lock the underlying buffer for reading/writing.
        /// </summary>
        /// <param name="lockFlags">Flags used when locking the buffer.</param>
        /// <param name="context">A graphics context to use when locking the buffer.</param>
        /// <returns>A data stream containing the buffer data.</returns>
        /// <remarks>
        /// Use the <paramref name="context"/> parameter to determine the context in which the buffer should be updated. This is necessary to use that context
        /// to update the buffer because 2 threads may not access the same resource at the same time.
        /// </remarks>
        protected virtual GorgonDataStream OnLock(BufferLockFlags lockFlags, GorgonGraphics context)
        {
#if DEBUG
            if ((lockFlags & BufferLockFlags.NoOverwrite) == BufferLockFlags.NoOverwrite)
            {
                throw new ArgumentException(Resources.GORGFX_BUFFER_NO_OVERWRITE_NOT_VALID, "lockFlags");
            }
#endif
            DX.DataStream lockStream;

            context.Context.MapSubresource(D3DBuffer, GetMapMode(lockFlags), D3D.MapFlags.None, out lockStream);

            return(new GorgonDataStream(lockStream.DataPointer, (int)lockStream.Length));
        }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonTexture1D"/> class.
 /// </summary>
 /// <param name="graphics">The graphics interface that owns this texture.</param>
 /// <param name="name">The name of the texture.</param>
 /// <param name="settings">Settings to pass to the texture.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).</exception>
 ///
 /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is an empty string.</exception>
 internal GorgonTexture1D(GorgonGraphics graphics, string name, ITextureSettings settings)
     : base(graphics, name, settings)
 {
     Settings = new GorgonTexture1DSettings
     {
         Width = settings.Width,
         AllowUnorderedAccessViews = settings.AllowUnorderedAccessViews,
         ArrayCount       = settings.ArrayCount,
         Format           = settings.Format,
         MipCount         = settings.MipCount,
         ShaderViewFormat = settings.ShaderViewFormat,
         Usage            = settings.Usage
     };
 }
Example #26
0
        /// <summary>
        /// Function to clear the depth portion of the depth/stencil buffer.
        /// </summary>
        /// <param name="depthValue">Value to fill the depth buffer with.</param>
        /// <param name="deferred">[Optional] A deferred context to use when clearing the depth/stencil buffer.</param>
        /// <remarks>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net), the immediate context will be used to clear the depth/stencil buffer.  If it is non-NULL, then it
        /// will use the specified deferred context to clear the depth/stencil buffer.
        /// <para>If you are using a deferred context, it is necessary to use that context to clear the depth/stencil buffer because 2 threads may not access the same resource at the same time.
        /// Passing a separate deferred context will alleviate that.</para>
        /// </remarks>
        public void ClearDepth(float depthValue, GorgonGraphics deferred = null)
        {
            if (!FormatInformation.HasDepth)
            {
                return;
            }

            if (deferred != null)
            {
                deferred.Context.ClearDepthStencilView(D3DView, D3D.DepthStencilClearFlags.Depth, depthValue, 0);
                return;
            }

            Resource.Graphics.Context.ClearDepthStencilView(D3DView, D3D.DepthStencilClearFlags.Depth, depthValue, 0);
        }
Example #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonShaderBinding"/> class.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        internal GorgonShaderBinding(GorgonGraphics graphics)
        {
            IncludeFiles   = new GorgonShaderIncludeCollection();
            VertexShader   = new GorgonVertexShaderState(graphics);
            PixelShader    = new GorgonPixelShaderState(graphics);
            GeometryShader = new GorgonGeometryShaderState(graphics);

            if (graphics.VideoDevice.SupportedFeatureLevel > DeviceFeatureLevel.SM4_1)
            {
                ComputeShader = new GorgonComputeShaderState(graphics);
                HullShader    = new GorgonHullShaderState(graphics);
                DomainShader  = new GorgonDomainShaderState(graphics);
            }
            _graphics = graphics;
        }
Example #28
0
        /// <summary>
        /// Function to update the buffer.
        /// </summary>
        /// <param name="stream">Stream containing the data used to update the buffer.</param>
        /// <param name="deferred">[Optional] A deferred context to use when updating the buffer.</param>
        /// <remarks>This method can only be used with buffers that have Default usage.  Other buffer usages will thrown an exception.
        /// <para>This method will respect the <see cref="GorgonLibrary.IO.GorgonDataStream.Position">Position</see> property of the data stream.
        /// This means that it will start reading from the stream at the current position.  To read from the beginning of the stream, set the position
        /// to 0.</para>
        /// <para>
        /// If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net), the immediate context will be used to update the buffer.  If it is non-NULL, then it
        /// will use the specified deferred context to clear the render target.
        /// <para>If you are using a deferred context, it is necessary to use that context to update the buffer because 2 threads may not access the same resource at the same time.
        /// Passing a separate deferred context will alleviate that.</para>
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the buffer usage is not set to default.</exception>
        public void Update(GorgonDataStream stream, GorgonGraphics deferred = null)
        {
            GorgonDebug.AssertNull(stream, "stream");

#if DEBUG
            if (Settings.Usage != BufferUsage.Default)
            {
                throw new GorgonException(GorgonResult.AccessDenied, Resources.GORGFX_NOT_DEFAULT_USAGE);
            }
#endif
            if (deferred == null)
            {
                deferred = Graphics;
            }

            OnUpdate(stream, 0, (int)(stream.Length - stream.Position), deferred);
        }
Example #29
0
        /// <summary>
        /// Function to write a single value type to the buffer.
        /// </summary>
        /// <typeparam name="T">Type of value type.</typeparam>
        /// <param name="data">Value type data to write into the buffer.</param>
        /// <param name="deferred">[Optional] A deferred context to use when updating the buffer.</param>
        /// <remarks>
        /// This overload is useful for directly copying a value into the buffer without needing a data stream.  If the type of value is a
        /// struct and contains reference types (arrays, strings, and objects), then these members will not be copied.  Some form of
        /// marshalling will be required in order to copy structures with reference types.
        /// <para>
        /// If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net), the immediate context will be used to update the buffer.  If it is non-NULL, then it
        /// will use the specified deferred context to clear the render target.
        /// <para>If you are using a deferred context, it is necessary to use that context to update the buffer because 2 threads may not access the same resource at the same time.
        /// Passing a separate deferred context will alleviate that.</para>
        /// </para>
        /// <para>This will only work on buffers created with a usage type of [Default].</para>
        /// </remarks>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the buffer does not have a usage of Default.</exception>
        public void Update <T>(ref T data, GorgonGraphics deferred = null)
            where T : struct
        {
#if DEBUG
            if (Settings.Usage != BufferUsage.Default)
            {
                throw new GorgonException(GorgonResult.AccessDenied, Resources.GORGFX_NOT_DEFAULT_USAGE);
            }
#endif

            if (deferred == null)
            {
                deferred = Graphics;
            }

            deferred.Context.UpdateSubresource(ref data, D3DResource, 0, DirectAccess.SizeOf <T>());
        }
Example #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonTexture2D"/> class.
 /// </summary>
 /// <param name="graphics">The graphics interface that owns this texture.</param>
 /// <param name="name">The name of the texture.</param>
 /// <param name="settings">Settings to pass to the texture.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is an empty string.</exception>
 internal GorgonTexture2D(GorgonGraphics graphics, string name, ITextureSettings settings)
     : base(graphics, name, settings)
 {
     Settings = new GorgonTexture2DSettings
     {
         Width  = settings.Width,
         Height = settings.Height,
         AllowUnorderedAccessViews = settings.AllowUnorderedAccessViews,
         ArrayCount       = settings.ArrayCount,
         Format           = settings.Format,
         IsTextureCube    = settings.IsTextureCube,
         MipCount         = settings.MipCount,
         Multisampling    = settings.Multisampling,
         ShaderViewFormat = settings.ShaderViewFormat,
         Usage            = settings.Usage
     };
 }