예제 #1
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
            });
        }
예제 #2
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="context">A graphics context to use when updating the buffer.</param>
        /// <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 void OnUpdate(GorgonDataStream stream, int offset, int size, GorgonGraphics context)
        {
            GorgonDebug.AssertNull(stream, "stream");

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

            context.Context.UpdateSubresource(
                new DX.DataBox
            {
                DataPointer = stream.PositionPointer,
                RowPitch    = size
            },
                D3DResource,
                0,
                new D3D11.ResourceRegion
            {
                Left   = offset,
                Right  = offset + size,
                Top    = 0,
                Bottom = 1,
                Front  = 0,
                Back   = 1
            });
        }
예제 #3
0
        /// <summary>
        /// Function to set an animation playing.
        /// </summary>
        /// <param name="animatedObject">The object to apply the animation onto.</param>
        /// <param name="animation">Animation to play.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="animation"/> or <paramref name="animatedObject"/> parameters are NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException">Thrown when the animation could not be found in the collection.</exception>
        public void Play(T animatedObject, GorgonAnimation <T> animation)
        {
            GorgonDebug.AssertNull(animation, "animation");
            GorgonDebug.AssertNull(animatedObject, "animatedObject");

#if DEBUG
            if (!Contains(animation))
            {
                throw new KeyNotFoundException(string.Format(Resources.GORANM_ANIMATION_DOES_NOT_EXIST, animation.Name));
            }
#endif

            // This animation is already playing.
            if (animation == CurrentAnimation)
            {
                return;
            }

            // Stop the current animation.
            if (CurrentAnimation != null)
            {
                Stop();
            }

            AnimatedObject   = animatedObject;
            CurrentAnimation = animation;

            // Update to the first frame.
            CurrentAnimation.UpdateObject();
        }
예제 #4
0
        /// <summary>
        /// Function to save the animation to a stream.
        /// </summary>
        /// <param name="stream">Stream to write the animation into.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        public void Save(Stream stream)
        {
            GorgonDebug.AssertNull(stream, "stream");

            using (var chunk = new GorgonChunkWriter(stream))
            {
                chunk.Begin(GorgonAnimationController <T> .AnimationVersion);

                // Write out animation header data.
                chunk.Begin("ANIMDATA");
                chunk.WriteString(AnimationController.AnimatedObjectType.FullName);
                chunk.WriteString(Name);
                chunk.WriteFloat(Length);
                chunk.WriteBoolean(IsLooped);
                chunk.End();

                // Put out the tracks with the most keys first.
                var activeTracks = from GorgonAnimationTrack <T> track in Tracks
                                   where track.KeyFrames.Count > 0
                                   orderby track.KeyFrames.Count
                                   select track;

                foreach (var track in activeTracks)
                {
                    if (track.KeyFrames.Count <= 0)
                    {
                        continue;
                    }

                    chunk.Begin("TRCKDATA");
                    track.ToChunk(chunk);
                    chunk.End();
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Function to save the shader to a stream.
        /// </summary>
        /// <param name="stream">Stream to write into.</param>
        /// <param name="binary">[Optional] TRUE to save the binary version of the shader, FALSE to save the source.</param>
        /// <param name="saveDebug">[Optional] TRUE to save the debug information, FALSE to exclude it.</param>
        /// <remarks>The <paramref name="saveDebug"/> parameter is only applicable when the <paramref name="binary"/> parameter is set to TRUE.</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the shader is being saved as source code and the <see cref="GorgonLibrary.Graphics.GorgonShader.SourceCode">SourceCode</see> parameter is NULL (Nothing in VB.Net) or empty.</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the shader fails to compile.</exception>
        public void Save(Stream stream, bool binary = false, bool saveDebug = false)
        {
            Shaders.ShaderBytecode compiledShader = null;
            GorgonDebug.AssertNull(stream, "stream");

            if ((!binary) && (string.IsNullOrEmpty(SourceCode)))
            {
                throw new ArgumentException(Resources.GORGFX_SHADER_NO_CODE, "binary");
            }

            if (!binary)
            {
                byte[] shaderSource = Encoding.UTF8.GetBytes(SourceCode);
                stream.Write(shaderSource, 0, shaderSource.Length);

                return;
            }

            try
            {
                compiledShader = CompileFromSource(saveDebug);
                byte[] header = Encoding.UTF8.GetBytes(GorgonShaderBinding.BinaryShaderHeader);
                stream.Write(header, 0, header.Length);
                compiledShader.Save(stream);
            }
            finally
            {
                if (compiledShader != null)
                {
                    compiledShader.Dispose();
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Function to copy the contents of the specified buffer to this buffer.
        /// </summary>
        /// <param name="buffer">Buffer to copy.</param>
        /// <param name="sourceOffset">Starting byte index to start copying from.</param>
        /// <param name="byteCount">The number of bytes to copy.</param>
        /// <param name="destOffset">The offset within the destination buffer.</param>
        /// <remarks>This is used to copy data from one GPU buffer to another.</remarks>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="sourceOffset"/> is less than 0 or larger than the size of the source <paramref name="buffer"/>.
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="byteCount"/> + sourceStartIndex is greater than the size of the source buffer, or less than 0.</para>
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="destOffset"/> + byteCount is greater than the size of this buffer, or less than 0.</para>
        /// </exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when this buffer has a usage of Immutable.</exception>
        public void Copy(GorgonBaseBuffer buffer, int sourceOffset, int byteCount, int destOffset)
        {
            int sourceByteIndex = sourceOffset + byteCount;
            int destByteIndex   = destOffset + byteCount;

            GorgonDebug.AssertNull(buffer, "buffer");
            GorgonDebug.AssertParamRange(sourceOffset, 0, buffer.SizeInBytes, "sourceOffset");
            GorgonDebug.AssertParamRange(sourceByteIndex, 0, buffer.SizeInBytes, "sourceOffset");
            GorgonDebug.AssertParamRange(destOffset, 0, SizeInBytes, "destOffset");
            GorgonDebug.AssertParamRange(destByteIndex, 0, buffer.SizeInBytes, "destOffset");

#if DEBUG
            if (Settings.Usage == BufferUsage.Immutable)
            {
                throw new GorgonException(GorgonResult.AccessDenied, Resources.GORGFX_BUFFER_IMMUTABLE);
            }
#endif
            Graphics.Context.CopySubresourceRegion(buffer.D3DResource, 0, new D3D.ResourceRegion
            {
                Top    = 0,
                Bottom = 1,
                Left   = sourceOffset,
                Right  = sourceByteIndex,
                Front  = 0,
                Back   = 1
            }, D3DResource, 0, destOffset);
        }
예제 #7
0
        /// <summary>
        /// Function to load an animation from a stream.
        /// </summary>
        /// <param name="stream">Stream to load from.</param>
        /// <returns>The animation in the stream.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the stream parameter does not contain a Gorgon animation file.
        /// <para>-or-</para>
        /// <para>Thrown when the name of the animation is already present in the controller animation collection.</para>
        /// <para>-or-</para>
        /// <para>Thrown when a track type cannot be associated with a property on the object type that the controller was declared with.</para>
        /// </exception>
        /// <exception cref="System.InvalidCastException">Thrown when the animation being loaded is for a different type than the controller was declared with.</exception>
        public GorgonAnimation <T> FromStream(Stream stream)
        {
            GorgonAnimation <T> animation;

            GorgonDebug.AssertNull(stream, "stream");

            using (var chunk = new GorgonChunkReader(stream))
            {
                // Get the header.
                chunk.Begin(AnimationVersion);

                chunk.Begin("ANIMDATA");
                // Get the type data.
                string typeString = chunk.ReadString();

                if (typeString != AnimatedObjectType.FullName)
                {
                    throw new InvalidCastException(string.Format(Resources.GORANM_ANIMATION_TYPE_MISMATCH, typeString,
                                                                 AnimatedObjectType.FullName));
                }

                // Get the name.
                string animationName = chunk.ReadString();
                if (Contains(animationName))
                {
                    throw new ArgumentException(string.Format(Resources.GORANM_ANIMATION_ALREADY_EXISTS, animationName),
                                                "stream");
                }

                animation = new GorgonAnimation <T>(this, animationName, chunk.ReadFloat())
                {
                    IsLooped = chunk.ReadBoolean()
                };

                chunk.End();

                // Get all the tracks.
                while (chunk.HasChunk("TRCKDATA"))
                {
                    chunk.Begin("TRCKDATA");

                    string trackName = chunk.ReadString();                                      // Get the name of the track.

                    if (!animation.Tracks.Contains(trackName))
                    {
                        throw new ArgumentException(
                                  string.Format(Resources.GORANM_TRACK_TYPE_DOES_NOT_EXIST, trackName, AnimatedObjectType.FullName), "stream");
                    }

                    animation.Tracks[trackName].FromChunk(chunk);

                    chunk.End();
                }
            }

            Add(animation);

            return(animation);
        }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonAnimatedProperty" /> struct.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="propertyInfo"/> parameter is NULL (Nothing in VB.Net).</exception>
        public GorgonAnimatedProperty(PropertyInfo propertyInfo)
        {
            GorgonDebug.AssertNull(propertyInfo, "propertyInfo");

            Property    = propertyInfo;
            DisplayName = propertyInfo.Name;
            DataType    = propertyInfo.PropertyType;
        }
예제 #9
0
        /// <summary>
        /// Function to retrieve the list of plug-ins associated with a specific assembly.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly to filter.</param>
        /// <returns>A read-only list of plug-ins.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="assemblyName"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <remarks>Unlike the overload of this method, this method only enumerates plug-ins from assemblies that are already loaded into memory.</remarks>
        public GorgonNamedObjectReadOnlyCollection <GorgonPlugIn> EnumeratePlugIns(AssemblyName assemblyName)
        {
            GorgonDebug.AssertNull(assemblyName, "assemblyName");

            var plugIns = this.Where(item => AssemblyName.ReferenceMatchesDefinition(item.Assembly, assemblyName));

            return(new GorgonNamedObjectReadOnlyCollection <GorgonPlugIn>(false, plugIns));
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonAnimatedProperty" /> struct.
        /// </summary>
        /// <param name="displayName">The display name used to override the property name.</param>
        /// <param name="propertyInfo">The property info.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="displayName"/> or <paramref name="propertyInfo"/> parameters are NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the displayName parameter is an empty string.</exception>
        public GorgonAnimatedProperty(string displayName, PropertyInfo propertyInfo)
        {
            GorgonDebug.AssertParamString(displayName, "displayName");
            GorgonDebug.AssertNull(propertyInfo, "propertyInfo");

            DisplayName = displayName;
            DataType    = propertyInfo.PropertyType;
            Property    = propertyInfo;
        }
        /// <summary>
        /// Function to add a track to the collection.
        /// </summary>
        /// <param name="track">Track to add.</param>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="track"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the track parameter already exists in the collection.</exception>
        public void Add(GorgonAnimationTrack <T> track)
        {
            GorgonDebug.AssertNull(track, "track");

            if (Contains(track.Name))
            {
                throw new ArgumentException(string.Format(Resources.GORANM_TRACK_ALREADY_EXISTS, track.Name), "track");
            }

            AddItem(track);
        }
예제 #12
0
        /// <summary>
        /// Function to clear the unordered access value with the specified values.
        /// </summary>
        /// <param name="values">Values used to clear.</param>
        /// <remarks>This method works on any unordered access view that does not require format conversion.  Unordered access views for raw/structured buffers only use the first value in the array.</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="values"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="values"/> parameter does not contain exactly 4 elements in the array.</exception>
        public void Clear(float[] values)
        {
            GorgonDebug.AssertNull(values, "values");

            if (values.Length != 4)
            {
                throw new ArgumentException(Resources.GORGFX_VIEW_UNORDERED_CLEAR_NEED_4_VALUES, "values");
            }

            Resource.Graphics.Context.ClearUnorderedAccessView(D3DView, new DX.Vector4(values));
        }
예제 #13
0
        /// <summary>
        /// Function to remove an animation from the collection.
        /// </summary>
        /// <param name="animation">Animation to remove.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="animation"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException">Thrown when the animation was not found in the collection.</exception>
        public void Remove(GorgonAnimation <T> animation)
        {
            GorgonDebug.AssertNull(animation, "animation");
#if DEBUG
            if (!Contains(animation))
            {
                throw new KeyNotFoundException(string.Format(Resources.GORANM_ANIMATION_DOES_NOT_EXIST, animation.Name));
            }
#endif

            RemoveItem(animation);
        }
예제 #14
0
        /// <summary>
        /// Function to add an animation to the collection.
        /// </summary>
        /// <param name="value">Animation to add.</param>
        protected override void AddItem(GorgonAnimation <T> value)
        {
            GorgonDebug.AssertNull(value, "value");

            if ((value.AnimationController != null) && (value.AnimationController != this) &&
                (value.AnimationController.Contains(value)))
            {
                value.AnimationController.Remove(value);
                value.AnimationController = this;
            }

            base.AddItem(value);
        }
예제 #15
0
        /// <summary>
        /// Function to add an animation to the collection.
        /// </summary>
        /// <param name="animation">Animation to add to the collection.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="animation"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the animation already exists in this collection.</exception>
        public void Add(GorgonAnimation <T> animation)
        {
            GorgonDebug.AssertNull(animation, "animation");

#if DEBUG
            if (Contains(animation.Name))
            {
                throw new ArgumentException(string.Format(Resources.GORANM_ANIMATION_ALREADY_EXISTS, animation.Name), "animation");
            }
#endif

            AddItem(animation);
        }
예제 #16
0
        /// <summary>
        /// Function to add a list of animations to the collection.
        /// </summary>
        /// <param name="animations">Animations to add.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="animations"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when an animation in the list already exists in this collection.</exception>
        public void AddRange(IEnumerable <GorgonAnimation <T> > animations)
        {
            var animationList = animations.ToArray();

            GorgonDebug.AssertNull(animationList, "animations");

            if (animationList.Length == 0)
            {
                return;
            }

            AddItems(animationList);
        }
예제 #17
0
        /// <summary>
        /// Function to execute rendering commands from a deferred context.
        /// </summary>
        /// <param name="commands">Commands to execute.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="commands"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.NotSupportedException">Thrown when the current context is a deferred context.
        /// <para>-or-</para>
        /// <para>Thrown if the current video device does not have a feature level of SM5 or better.</para>
        /// </exception>
        /// <remarks>
        /// Use this method to execute previously recorded rendering commands on the immediate context.  This method must be called from the immediate context.
        /// </remarks>
        public void ExecuteDeferred(GorgonRenderCommands commands)
        {
            GorgonDebug.AssertNull(commands, "commands");

#if DEBUG
            if (IsDeferred)
            {
                throw new NotSupportedException(Resources.GORGFX_CANNOT_USE_DEFERRED_CONTEXT);
            }
#endif

            Context.ExecuteCommandList(commands.D3DCommands, true);
        }
예제 #18
0
        /// <summary>
        /// Function to execute the current compute shader using an indirect argument buffer.
        /// </summary>
        /// <param name="indirectArgsBuffer">The indirect argument buffer to use.</param>
        /// <param name="alignedOffset">The byte aligned offset into the buffer to start at.</param>
        /// <remarks>Call dispatch to execute the commands in the compute shader.  A compute shader can be run on multiple threads in parallel within a threading group.  Use a particular threading group
        /// within the shader by using a 3D vector (float3).
        /// <para>The <paramref name="indirectArgsBuffer"/> must be loaded with data that matches the argument list of <see cref="Dispatch(int, int, int)"/>.</para></remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="indirectArgsBuffer"/> was NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="alignedOffset"/> parameter is less than 0 or not less than the number of bytes in the buffer.</exception>
        /// <exception cref="System.ArgumentException">Thrown when the buffer passed in through <paramref name="indirectArgsBuffer"/> was not created as an indirect argument buffer.</exception>
        public void Dispatch(GorgonBuffer indirectArgsBuffer, int alignedOffset)
        {
            GorgonDebug.AssertNull(indirectArgsBuffer, "indirectArgsBuffer");
            GorgonDebug.AssertParamRange(alignedOffset, 0, indirectArgsBuffer.SizeInBytes, "alignedOffset");

#if DEBUG
            if (!indirectArgsBuffer.Settings.AllowIndirectArguments)
            {
                throw new ArgumentException(Properties.Resources.GORGFX_BUFFER_NOT_INDIRECT, "indirectArgsBuffer");
            }
#endif
            Graphics.Context.DispatchIndirect(indirectArgsBuffer.D3DBuffer, alignedOffset);
        }
        /// <summary>
        /// Function to copy data from this view into a buffer.
        /// </summary>
        /// <param name="buffer">Buffer that will receive the data.</param>
        /// <param name="offset">DWORD aligned offset within the buffer to start writing at.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="buffer"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="offset"/> parameter is less than 0, or larger than the size of the buffer minus 4 bytes.</exception>
        /// <remarks>This will copy the contents of a structured buffer into any other type of buffer.  The view must have been created using a ViewType of Counter or Append, otherwise an exception will be thrown.</remarks>
        public void CopyTo(GorgonBaseBuffer buffer, int offset)
        {
            GorgonDebug.AssertNull(buffer, "buffer");
            GorgonDebug.AssertParamRange(offset, 0, buffer.SizeInBytes - 4, "index");

#if DEBUG
            if (ViewType == UnorderedAccessViewType.Standard)
            {
                throw new GorgonException(GorgonResult.CannotRead, Resources.GORGFX_VIEW_UNORDERED_TYPE_NOT_VALID_FOR_COPY);
            }
#endif
            Resource.Graphics.Context.CopyStructureCount(buffer.D3DBuffer, offset, D3DView);
        }
예제 #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonRenderable"/> class.
        /// </summary>
        /// <param name="gorgon2D">Gorgon 2D interface.</param>
        /// <param name="name">The name.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="gorgon2D"/> parameter is NULL.</para>
        /// </exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is an empty string.</exception>
        protected GorgonRenderable(Gorgon2D gorgon2D, string name)
            : base(name)
        {
            GorgonDebug.AssertNull(gorgon2D, "gorgon2D");

            Gorgon2D    = gorgon2D;
            CullingMode = CullingMode.Back;

            AlphaTestValues = GorgonRangeF.Empty;
            DepthStencil    = new DepthStencilStates();
            Blending        = new BlendState();
            TextureSampler  = new TextureSamplerState();
            BaseVertexCount = 0;
        }
예제 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonGlyph"/> class.
        /// </summary>
        /// <param name="character">The character that the glyph represents.</param>
        /// <param name="texture">The texture that the glyph can be found on.</param>
        /// <param name="glyphCoordinates">Coordinates on the texture to indicate where the glyph is stored.</param>
        /// <param name="offset">The <see cref="Offset"/> of the glyph.</param>
        /// <param name="advance">Advancement width for the glyph.</param>
        /// <remarks>The <paramref name="glyphCoordinates"/> parameter is in pixel coordinates (i.e. 0 .. Width/Height).</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="texture"/> parameter is NULL (Nothing in VB.Net).
        /// </exception>
        public GorgonGlyph(char character, GorgonTexture2D texture, Rectangle glyphCoordinates, Point offset, int advance)
        {
            GorgonDebug.AssertNull(texture, "texture");

            Character          = character;
            GlyphCoordinates   = glyphCoordinates;
            TextureCoordinates = RectangleF.FromLTRB(glyphCoordinates.Left / (float)texture.Settings.Width,
                                                     glyphCoordinates.Top / (float)texture.Settings.Height,
                                                     glyphCoordinates.Right / (float)texture.Settings.Width,
                                                     glyphCoordinates.Bottom / (float)texture.Settings.Height);
            Texture           = texture;
            Offset            = offset;
            Advance           = advance;
            IsExternalTexture = true;
        }
예제 #22
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);
        }
예제 #23
0
        /// <summary>
        /// Function to write an array of value types 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 values 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>
        public override void Update <T>(T[] data, GorgonGraphics deferred = null)
        {
            GorgonDebug.AssertNull(data, "data");

#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(data, D3DResource, 0, DirectAccess.SizeOf <T>() * data.Length);
        }
예제 #24
0
        /// <summary>
        /// Function to draw a string.
        /// </summary>
        /// <param name="font">Font to use.</param>
        /// <param name="text">Text to draw.</param>
        /// <param name="position">Position of the text.</param>
        /// <param name="color">Color of the text.</param>
        /// <param name="useShadow">TRUE to use a shadow, FALSE to display normally.</param>
        /// <param name="shadowOffset">Offset of the shadow, in pixels.</param>
        /// <param name="shadowOpacity">Opacity of the shadow.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="font"/> parameter is NULL (Nothing in VB.Net).</exception>
        public void DrawString(GorgonFont font, string text, Vector2 position, GorgonColor color, bool useShadow, Vector2 shadowOffset, float shadowOpacity)
        {
            GorgonDebug.AssertNull(font, "font");

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            SetStates(_string);

            _string.Position      = position;
            _string.Font          = font;
            _string.Text          = text;
            _string.Color         = color;
            _string.ShadowEnabled = useShadow;
            _string.ShadowOffset  = shadowOffset;
            _string.ShadowOpacity = shadowOpacity;
            _string.Draw();
        }
예제 #25
0
        /// <summary>
        /// Function to write an array of value types 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 values 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="System.ArgumentNullException">Thrown when the <paramref name="data"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the buffer does not have a usage of Default.</exception>
        public virtual void Update <T>(T[] data, GorgonGraphics deferred = null)
            where T : struct
        {
            GorgonDebug.AssertNull(data, "data");

#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(data, D3DResource, 0, DirectAccess.SizeOf <T>() * data.Length, 0,
                                               new D3D.ResourceRegion(0, 0, 0, SizeInBytes, 1, 1));
        }
예제 #26
0
        /// <summary>
        /// Function to set a value for a property.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="value">Value to assign to the property.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="propertyName"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the propertyName parameter is an empty string.</exception>
        protected void SetData(string propertyName, object value)
        {
            GorgonDebug.AssertParamString(propertyName, "propertyName");
            GorgonDebug.AssertNull(Data[propertyName], "propertyName");

            GorgonCustomHIDProperty property;

            if (Data.TryGetValue(propertyName, out property))
            {
                property.SetValue(value);
            }
            else
            {
                Data.Add(new GorgonCustomHIDProperty(propertyName, value));
            }

            if (DataChanged != null)
            {
                DataChanged(this, new GorgonCustomHIDDataChangedEventArgs(Data[propertyName]));
            }
        }
예제 #27
0
 /// <summary>
 /// Function to blit a texture to the current render target.
 /// </summary>
 /// <param name="texture">Texture to blit to the current render target.</param>
 /// <param name="blitRegion">The position, and size of the blitted region.</param>
 /// <param name="textureRegion">The region of the texture to blit.</param>
 /// <remarks>This is for very quickly copying a texture to a render target.  If more control is required, then use a <see cref="GorgonLibrary.Renderers.GorgonSprite">Sprite</see>.</remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="texture"/> parameter is NULL (Nothing in VB.Net).</exception>
 public void Blit(GorgonTexture2D texture, RectangleF blitRegion, RectangleF textureRegion)
 {
     GorgonDebug.AssertNull(texture, "texture");
     FilledRectangle(blitRegion, Color.White, texture, textureRegion);
 }