Gorgon
Show / Hide Table of Contents

Class GorgonShader

The base shader object.

Inheritance
object
GorgonNamedObject
GorgonShader
GorgonComputeShader
GorgonDomainShader
GorgonGeometryShader
GorgonHullShader
GorgonPixelShader
GorgonVertexShader
Implements
IGorgonNamedObject
IDisposable
IGorgonGraphicsObject
Inherited Members
GorgonNamedObject.GetHashCode()
GorgonNamedObject.ToString()
GorgonNamedObject.Name
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Graphics.Core
Assembly: Gorgon.Graphics.Core.dll
Syntax
public abstract class GorgonShader : GorgonNamedObject, IGorgonNamedObject, IDisposable, IGorgonGraphicsObject
Remarks

Shaders are used to modify data on the GPU via a program uploaded to the GPU. This allows for a wide range of effects on GPU data. For example, a gaussian blur algorithm can be written using a pixel shader to blur an image.

In Gorgon, shaders can be compiled from a string containing source code via the GorgonShaderFactory, or loaded from a Stream or file for quicker access. The GorgonShaderFactory is required to compile or read shaders, they cannot be created via the new keyword.

All shaders in Gorgon will inherit from this type.

Properties

| Edit this page View Source

Graphics

Property to return the graphics interface that built this object.

Declaration
public GorgonGraphics Graphics { get; }
Property Value
Type Description
GorgonGraphics
| Edit this page View Source

ID

Property to return the ID for the shader.

Declaration
public long ID { get; }
Property Value
Type Description
long
| Edit this page View Source

IsDebug

Property to set or return whether to include debug information in the shader or not.

Declaration
public bool IsDebug { get; }
Property Value
Type Description
bool
| Edit this page View Source

ShaderType

Property to return the type of shader.

Declaration
public abstract ShaderType ShaderType { get; }
Property Value
Type Description
ShaderType

Methods

| Edit this page View Source

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public virtual void Dispose()
| Edit this page View Source

Save(Stream)

Function to persist the shader data to a stream as a GorgonChunkFile<T>.

Declaration
public void Save(Stream stream)
Parameters
Type Name Description
Stream stream

The stream to write the data into.

Remarks

This will write the shader data as GorgonChunkFile<T> formatted data into the supplied stream. Shaders may take some time to compile, saving them to a binary format in a stream will help cut down on the time it takes to initialize an application.

This makes use of the Gorgon GorgonChunkFile<T> format to allow flexible storage of data. The Gorgon shader format is broken into 2 chunks, both of which are available in the BinaryShaderMetaData, and BinaryShaderByteCode constants. The file header for the format is stored in the BinaryShaderFileHeader constant.

The file format is as follows:

  • BinaryShaderFileHeaderThis describes the type of file, and the version.
  • BinaryShaderMetaDataShader metadata, such as the ShaderType (int), debug flag (bool), and the entry point name (string) is stored here.
  • BinaryShaderByteCodeThe compiled shader byte code is stored here and is loaded as a byte array.
Exceptions
Type Condition
ArgumentNullException

Thrown when the stream parameter is null.

ArgumentException

Thrown when the stream is read only.

See Also
GorgonChunkFile<T>
GorgonChunkFileReader
GorgonChunkFileWriter
| Edit this page View Source

Save(string)

Function to persist the shader data to a file as a GorgonChunkFile<T>.

Declaration
public void Save(string path)
Parameters
Type Name Description
string path

The path to the file where the shader data will eb written.

Remarks

This will write the shader data as GorgonChunkFile<T> formatted data into the file. Shaders may take some time to compile, saving them to a binary format in a stream will help cut down on the time it takes to initialize an application.

This makes use of the Gorgon GorgonChunkFile<T> format to allow flexible storage of data. The Gorgon shader format is broken into 2 chunks, both of which are available in the BinaryShaderMetaData, and BinaryShaderByteCode constants. The file header for the format is stored in the BinaryShaderFileHeader constant.

The file format is as follows:

  • BinaryShaderFileHeaderThis describes the type of file, and the version.
  • BinaryShaderMetaDataShader metadata, such as the ShaderType (int), debug flag (bool), and the entry point name (string) is stored here.
  • BinaryShaderByteCodeThe compiled shader byte code is stored here and is loaded as a byte array.
Exceptions
Type Condition
ArgumentNullException

Thrown when the path parameter is null.

ArgumentException

Thrown when path parameter is empty.

See Also
GorgonChunkFile<T>
GorgonChunkFileReader
GorgonChunkFileWriter
| Edit this page View Source

SaveToFile(string)

Function to persist the shader data to a file as a GorgonChunkFile<T>.

Declaration
[Obsolete("Use Save(string) instead.")]
public void SaveToFile(string path)
Parameters
Type Name Description
string path

The path to the file where the shader data will eb written.

Remarks

This will write the shader data as GorgonChunkFile<T> formatted data into the file. Shaders may take some time to compile, saving them to a binary format in a stream will help cut down on the time it takes to initialize an application.

This makes use of the Gorgon GorgonChunkFile<T> format to allow flexible storage of data. The Gorgon shader format is broken into 2 chunks, both of which are available in the BinaryShaderMetaData, and BinaryShaderByteCode constants. The file header for the format is stored in the BinaryShaderFileHeader constant.

The file format is as follows:

  • BinaryShaderFileHeaderThis describes the type of file, and the version.
  • BinaryShaderMetaDataShader metadata, such as the ShaderType (int), debug flag (bool), and the entry point name (string) is stored here.
  • BinaryShaderByteCodeThe compiled shader byte code is stored here and is loaded as a byte array.
Exceptions
Type Condition
ArgumentNullException

Thrown when the path parameter is null.

ArgumentException

Thrown when path parameter is empty.

See Also
GorgonChunkFile<T>
GorgonChunkFileReader
GorgonChunkFileWriter
| Edit this page View Source

SaveToStream(Stream)

Function to persist the shader data to a stream as a GorgonChunkFile<T>.

Declaration
[Obsolete("Use Save(Stream) instead.")]
public void SaveToStream(Stream stream)
Parameters
Type Name Description
Stream stream

The stream to write the data into.

Remarks

This will write the shader data as GorgonChunkFile<T> formatted data into the supplied stream. Shaders may take some time to compile, saving them to a binary format in a stream will help cut down on the time it takes to initialize an application.

This makes use of the Gorgon GorgonChunkFile<T> format to allow flexible storage of data. The Gorgon shader format is broken into 2 chunks, both of which are available in the BinaryShaderMetaData, and BinaryShaderByteCode constants. The file header for the format is stored in the BinaryShaderFileHeader constant.

The file format is as follows:

  • BinaryShaderFileHeaderThis describes the type of file, and the version.
  • BinaryShaderMetaDataShader metadata, such as the ShaderType (int), debug flag (bool), and the entry point name (string) is stored here.
  • BinaryShaderByteCodeThe compiled shader byte code is stored here and is loaded as a byte array.
Exceptions
Type Condition
ArgumentNullException

Thrown when the stream parameter is null.

ArgumentException

Thrown when the stream is read only.

See Also
GorgonChunkFile<T>
GorgonChunkFileReader
GorgonChunkFileWriter

Implements

IGorgonNamedObject
IDisposable
IGorgonGraphicsObject

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author