本文整理汇总了C#中OpenGL.GraphicsContext类的典型用法代码示例。如果您正苦于以下问题:C# GraphicsContext类的具体用法?C# GraphicsContext怎么用?C# GraphicsContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphicsContext类属于OpenGL命名空间,在下文中一共展示了GraphicsContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Set
/// <summary>
/// Upload Texture1D data.
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/> used for uploading texture data.
/// </param>
private void Set(GraphicsContext ctx)
{
// Create texture if necessary
Create(ctx);
// Bind this Texture
Bind(ctx);
// Upload texture data
int internalFormat = Pixel.GetGlInternalFormat(PixelLayout, ctx);
PixelFormat format = Pixel.GetGlFormat(mTextureData.PixelLayout);
PixelType type = Pixel.GetPixelType(mTextureData.PixelLayout);
// Set pixel transfer
foreach (int alignment in new int[] { 8, 4, 2, 1 }) {
if (mTextureData.Stride % alignment == 0) {
Gl.PixelStore(PixelStoreParameter.UnpackAlignment, alignment);
break;
}
}
// Upload texture contents
Gl.TexImage1D(TextureTarget.Texture1d, 0, internalFormat, (int)Width, 0, format, type, mTextureData.ImageBuffer);
// Unbind this texture
Unbind(ctx);
// Data no more required
mTextureData = null;
}
示例2: SetUniform
/// <summary>
/// Set uniform state variable (any known object type).
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/> used for operations.
/// </param>
/// <param name="uniformName">
/// A <see cref="String"/> that specify the variable name in the shader source.
/// </param>
/// <param name="value">
/// A <see cref="Object"/> holding the uniform variabile data.
/// </param>
/// <remarks>
/// </remarks>
/// <exception cref="ArgumentNullException">
/// This exception is thrown if the parameter <paramref name="ctx"/> is null.
/// </exception>
/// <exception cref="ArgumentNullException">
/// This exception is thrown if the parameter <paramref name="uniformName"/> is null.
/// </exception>
public void SetUniform(GraphicsContext ctx, string uniformName, object value)
{
if (ctx == null)
throw new ArgumentNullException("ctx");
if (value == null)
throw new ArgumentNullException("value");
MethodInfo setUniformMethod;
if (_SetUniformMethods.TryGetValue(value.GetType(), out setUniformMethod) == false) {
setUniformMethod = typeof(ShaderProgram).GetMethod("SetUniform", new Type[] { typeof(GraphicsContext), typeof(string), value.GetType() });
_SetUniformMethods[value.GetType()] = setUniformMethod;
}
if (setUniformMethod != null) {
// Avoid stack overflow
if (setUniformMethod.GetParameters()[2].ParameterType == typeof(object))
throw new NotSupportedException(value.GetType() + " is not supported");
try {
setUniformMethod.Invoke(this, new object[] { ctx, uniformName, value });
} catch (TargetInvocationException targetInvocationException) {
throw targetInvocationException.InnerException;
}
} else
throw new NotSupportedException(value.GetType() + " is not supported");
}
示例3: Draw
/// <summary>
/// Draw the attributes of this vertex array.
/// </summary>
/// <param name="ctx">
/// The <see cref="GraphicsContext"/> used for rendering.
/// </param>
/// <param name="shader">
/// The <see cref="ShaderProgram"/> used for drawing the vertex arrays.
/// </param>
public virtual void Draw(GraphicsContext ctx, ShaderProgram shader)
{
CheckThisExistence(ctx);
if (shader != null && shader.Exists(ctx) == false)
throw new ArgumentException("not existing", "shader");
// If vertex was modified after creation, don't miss to create array buffers
if (_VertexArrayDirty) CreateObject(ctx);
// Set vertex arrays
SetVertexArrayState(ctx, shader);
// Fixed or programmable pipeline?
if ((shader == null) && (ctx.Caps.GlExtensions.VertexShader_ARB == true))
ShaderProgram.Unbind(ctx);
else if (shader != null)
shader.Bind(ctx);
// Issue rendering using shader
foreach (Element attributeElement in DrawElements) {
if (_FeedbackBuffer != null)
_FeedbackBuffer.Begin(ctx, attributeElement.ElementsMode);
attributeElement.Draw(ctx);
if (_FeedbackBuffer != null)
_FeedbackBuffer.End(ctx);
}
}
示例4: IsPrimitiveRestartSupported
public static bool IsPrimitiveRestartSupported(GraphicsContext ctx)
{
if (ctx == null)
throw new ArgumentNullException("ctx");
return (ctx.Caps.GlExtensions.PrimitiveRestart || ctx.Caps.GlExtensions.PrimitiveRestart_NV);
}
示例5: IsSupported
/// <summary>
/// Check whether one of the extention strings is supported.
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/> that specifies the current OpenGL version to test for extension support. In the case this
/// parameter is null, the test fallback to the current OpenGL version.
/// </param>
public bool IsSupported(GraphicsContext ctx, IDeviceContext deviceContext)
{
if (IsSupportedExtension(ctx, deviceContext, mExtensionString) == true)
return (true);
if (mExtensionAlternatives != null) {
foreach (string ext in mExtensionAlternatives)
if (IsSupportedExtension(ctx, deviceContext, ext) == true)
return (true);
}
return (false);
}
示例6: DisablePrimitiveRestart
public static void DisablePrimitiveRestart(GraphicsContext ctx)
{
if (ctx == null)
throw new ArgumentNullException("ctx");
if (ctx.Caps.GlExtensions.PrimitiveRestart) {
// Enable primitive restart (server state)
Gl.Disable(EnableCap.PrimitiveRestart);
} else if (ctx.Caps.GlExtensions.PrimitiveRestart_NV) {
// Enable primitive restart (client state)
Gl.DisableClientState(EnableCap.PrimitiveRestartNv);
} else
throw new InvalidOperationException("primitive restart not supported");
}
示例7: EnablePrimitiveRestart
public static void EnablePrimitiveRestart(GraphicsContext ctx, DrawElementsType elementType)
{
switch (elementType) {
case DrawElementsType.UnsignedInt:
EnablePrimitiveRestart(ctx, UInt32.MaxValue);
break;
case DrawElementsType.UnsignedShort:
EnablePrimitiveRestart(ctx, UInt16.MaxValue);
break;
case DrawElementsType.UnsignedByte:
EnablePrimitiveRestart(ctx, Byte.MaxValue);
break;
default:
throw new ArgumentException(String.Format("unknown element type {0}", elementType));
}
}
示例8: Query
/// <summary>
/// Query OpenGL implementation extensions.
/// </summary>
/// <param name="ctx"></param>
/// <returns></returns>
public static GraphicsCapabilities Query(GraphicsContext ctx, IDeviceContext deviceContext)
{
GraphicsCapabilities graphicsCapabilities = new GraphicsCapabilities();
FieldInfo[] capsFields = typeof(GraphicsCapabilities).GetFields(BindingFlags.Public | BindingFlags.Instance);
#region Platform Extension Reload
// Since at this point there's a current OpenGL context, it's possible to use
// {glx|wgl}GetExtensionsString to retrieve platform specific extensions
switch (Environment.OSVersion.Platform) {
case PlatformID.Win32NT:
case PlatformID.Win32Windows:
case PlatformID.Win32S:
case PlatformID.WinCE:
Wgl.SyncDelegates();
break;
}
#endregion
// Only boolean fields are considered
FieldInfo[] extsFields = Array.FindAll<FieldInfo>(capsFields, delegate(FieldInfo info) {
return (info.FieldType == typeof(bool));
});
foreach (FieldInfo field in extsFields) {
Attribute[] graphicsExtensionAttributes = Attribute.GetCustomAttributes(field, typeof(GraphicsExtensionAttribute));
GraphicsExtensionDisabledAttribute graphicsExtensionDisabled = (GraphicsExtensionDisabledAttribute)Attribute.GetCustomAttribute(field, typeof(GraphicsExtensionDisabledAttribute));
bool implemented = false;
// Check whether at least one extension is implemented
implemented = Array.Exists(graphicsExtensionAttributes, delegate(Attribute item) {
return ((GraphicsExtensionAttribute)item).IsSupported(ctx, deviceContext);
});
// Check whether the required extensions are artifically disabled
if (graphicsExtensionDisabled != null)
implemented = false;
field.SetValue(graphicsCapabilities, implemented);
}
return (graphicsCapabilities);
}
示例9: Query
/// <summary>
/// Query OpenGL implementation extensions.
/// </summary>
/// <param name="ctx"></param>
/// <returns></returns>
public static GraphicsCapabilities Query(GraphicsContext ctx, IDeviceContext deviceContext)
{
GraphicsCapabilities graphicsCapabilities = new GraphicsCapabilities();
KhronosApi.LogComment("Query OpenGL extensions.");
#region Platform Extension Reload
// Since at this point there's a current OpenGL context, it's possible to use
// {glx|wgl}GetExtensionsString to retrieve platform specific extensions
switch (Environment.OSVersion.Platform) {
case PlatformID.Win32NT:
case PlatformID.Win32Windows:
case PlatformID.Win32S:
case PlatformID.WinCE:
// Wgl.SyncDelegates();
break;
}
#endregion
// OpenGL extensions
graphicsCapabilities._GlExtensions.Query();
// Windows OpenGL extensions
WindowsDeviceContext windowsDeviceContext = deviceContext as WindowsDeviceContext;
if (windowsDeviceContext != null)
graphicsCapabilities._WglExtensions.Query(windowsDeviceContext);
// GLX OpenGL extensions
XServerDeviceContext xserverDeviceContext = deviceContext as XServerDeviceContext;
if (xserverDeviceContext != null)
graphicsCapabilities._GlxExtensions.Query(xserverDeviceContext);
// Query implementation limits
graphicsCapabilities._GraphicsLimits = GraphicsLimits.Query(graphicsCapabilities._GlExtensions);
return (graphicsCapabilities);
}
示例10: CreateName
/// <summary>
/// Create a RenderBuffer name.
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/> used for creating this object name.
/// </param>
/// <returns>
/// It returns a valid object name for this RenderBuffer.
/// </returns>
protected override uint CreateName(GraphicsContext ctx)
{
return (Gl.GenRenderbuffer());
}
示例11: Exists
/// <summary>
/// Determine whether this RenderBuffer really exists for a specific context.
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/> that would have created (or a sharing one) the object. This context shall be current to
/// the calling thread.
/// </param>
/// <returns>
/// It returns a boolean value indicating whether this RenderBuffer exists in the object space of <paramref name="ctx"/>.
/// </returns>
/// <remarks>
/// <para>
/// The object existence is done by checking a valid object by its name <see cref="IGraphicsResource.ObjectName"/>. This routine will test whether
/// <paramref name="ctx"/> has created this RenderBuffer (or is sharing with the creator).
/// </para>
/// </remarks>
/// <exception cref="ArgumentNullException">
/// Exception thrown if <paramref name="ctx"/> is null.
/// </exception>
/// <exception cref="ArgumentException">
/// Exception thrown if <paramref name="ctx"/> is not current to the calling thread.
/// </exception>
public override bool Exists(GraphicsContext ctx)
{
if (ctx == null)
throw new ArgumentNullException("ctx");
if (ctx.IsCurrent == false)
throw new ArgumentException("not current", "ctx");
// Object name space test (and 'ctx' sanity checks)
if (base.Exists(ctx) == false)
return (false);
return (Gl.IsRenderbuffer(ObjectName));
}
示例12: ReadBuffer
/// <summary>
/// Read this GraphicsSurface color buffer.
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/>
/// </param>
/// <param name="rBuffer">
/// A <see cref="ReadBufferMode"/> that specify the read buffer where the colors are read from.
/// </param>
/// <param name="x">
/// A <see cref="Int32"/> that specify the x coordinate of the lower left corder of the rectangle area to read.
/// </param>
/// <param name="y">
/// A <see cref="Int32"/> that specify the y coordinate of the lower left corder of the rectangle area to read.
/// </param>
/// <param name="width">
/// A <see cref="Int32"/> that specify the width of the rectangle area to read.
/// </param>
/// <param name="height">
/// A <see cref="Int32"/> that specify the height of the rectangle area to read.
/// </param>
/// <param name="pType">
/// A <see cref="PixelLayout"/> which determine the pixel storage of the returned image.
/// </param>
/// <returns>
/// It returns an <see cref="Image"/> representing the current read buffer <paramref name="rBuffer"/>.
/// </returns>
protected Image ReadBuffer(GraphicsContext ctx, ReadBufferMode rBuffer, uint x, uint y, uint width, uint height, PixelLayout pType)
{
Image image = null;
if ((x + width > Width) || (y + height > Height))
throw new ArgumentException("specified region lies outside the GraphicsSurface");
// Bind for reading
BindRead(ctx);
// Set for reading
Gl.ReadBuffer(rBuffer);
// Allocate image holding data read
image = new Image();
image.Create(pType, width, height);
// Set pixel transfer
foreach (int alignment in new int[] { 8, 4, 2, 1 }) {
if (image.Stride % alignment == 0) {
Gl.PixelStore(PixelStoreParameter.PackAlignment, alignment);
break;
}
}
// Grab frame buffer pixels
PixelFormat rFormat = Pixel.GetGlFormat(pType);
PixelType rType = Pixel.GetPixelType(pType);
Gl.ReadPixels((int)x, (int)y, (int)width, (int)height, rFormat, rType, image.ImageBuffer);
// Unbind from reading
UnbindRead(ctx);
return (image);
}
示例13: UnbindDraw
/// <summary>
/// Unbind this GraphicsSurface for drawing.
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/> to wich disassociate its rendering result from this GraphicsSurface.
/// </param>
public virtual void UnbindDraw(GraphicsContext ctx) { }
示例14: Clear
/// <summary>
/// Clear surface buffers.
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/> used for clearing buffers.
/// </param>
/// <param name="bufferMask">
/// A <see cref="GraphicsBuffersFormat.BufferType"/> indicating which buffers to clear.
/// </param>
public void Clear(GraphicsContext ctx, GraphicsBuffersFormat.BufferType bufferMask)
{
// Update clear values (only what is necessary)
if ((bufferMask & GraphicsBuffersFormat.BufferType.Color) != 0)
Gl.ClearColor(mClearColor.Red, mClearColor.Green, mClearColor.Blue, mClearColor.Alpha);
if ((bufferMask & GraphicsBuffersFormat.BufferType.Depth) != 0)
Gl.ClearDepth(mClearDepth);
if ((bufferMask & GraphicsBuffersFormat.BufferType.Stencil) != 0)
Gl.ClearStencil(mClearStencil);
// Clear
Gl.Clear(GetClearFlags(bufferMask));
}
示例15: RequiresName
/// <summary>
/// Determine whether this object requires a name bound to a context or not.
/// </summary>
/// <param name="ctx">
/// A <see cref="GraphicsContext"/> used for creating this object name.
/// </param>
/// <returns>
/// <para>
/// This implementation returns always false.
/// </para>
/// </returns>
protected override bool RequiresName(GraphicsContext ctx)
{
return (false);
}