MulAvailable
This commit is contained in:
@@ -1,162 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="AutoTexture.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Commom.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of a sets of OpenGL textures. The collection can automatically select one of
|
||||
/// the texture with minimum costs to upgrade pixels to Buffer. Usually <see
|
||||
/// cref="AutoTextureGL" /> is used for <see cref="IImageProvider" /> loading, but not for
|
||||
/// target of <see cref="OpenGLFunction.FrameBufferTexture2d(FrameBufferTarget, uint,
|
||||
/// Texture2DTarget, GlHandle, int)" />.
|
||||
/// </summary>
|
||||
public sealed class AutoTextureGL
|
||||
{
|
||||
|
||||
private TextureProperty[] propertyCache;
|
||||
private BidirectionalDictionary<Image, int> imageIndexMap = new BidirectionalDictionary<Image, int>(
|
||||
);
|
||||
private Dictionary<Image, int> imageUpdateIndex = new Dictionary<Image, int>();
|
||||
|
||||
private int _size, _currentIndex;
|
||||
private LinkedList<int> usedTextureIndex;
|
||||
private Queue<int> unusedTextureUnitIndex;
|
||||
private TextureGL texturePackage;
|
||||
|
||||
private TextureProperty _textureProperty;
|
||||
|
||||
private AutoTextureGL( TextureGL texture )
|
||||
{
|
||||
texturePackage = texture;
|
||||
_size = texture.Count;
|
||||
imageIndexMap = new BidirectionalDictionary<Image, int>();
|
||||
unusedTextureUnitIndex = new Queue<int>( Enumerable.Range( 0, _size ) );
|
||||
usedTextureIndex = new LinkedList<int>();
|
||||
propertyCache = new TextureProperty[_size];
|
||||
}
|
||||
|
||||
public AutoTextureGL( int textureObjectSize, [NotNull]glRender binding )
|
||||
{
|
||||
this._size = textureObjectSize;
|
||||
imageIndexMap = new BidirectionalDictionary<Image, int>();
|
||||
texturePackage = new TextureGL( textureObjectSize, binding );
|
||||
unusedTextureUnitIndex = new Queue<int>( Enumerable.Range( 0, _size ) );
|
||||
usedTextureIndex = new LinkedList<int>();
|
||||
propertyCache = new TextureProperty[_size];
|
||||
}
|
||||
|
||||
public TextureProperty DefaultTextureProperty
|
||||
{
|
||||
get => _textureProperty;
|
||||
set => _textureProperty = value;
|
||||
}
|
||||
|
||||
private OpenGLFunction GL
|
||||
{
|
||||
get => texturePackage.GL;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SelectTextureAndBind( Image i )
|
||||
{
|
||||
TextureProperty property = _textureProperty;
|
||||
|
||||
SelectTextureAndBind( i, property );
|
||||
}
|
||||
|
||||
public void SelectTextureAndBind( [NotNull]Image i, TextureProperty property )
|
||||
{
|
||||
//usable texture with image match
|
||||
if( imageIndexMap.TryGetValue( i, out int index ) )
|
||||
{
|
||||
//prop setting match
|
||||
if( propertyCache[ index ] == property )
|
||||
{
|
||||
_currentIndex = index; //GL.Assert(true);
|
||||
texturePackage.Bind2D( index ); //GL.Assert(true);
|
||||
if( i.PixelUpdateCount != imageUpdateIndex[ i ] )
|
||||
{
|
||||
texturePackage.LoadTexture( index, i ); //GL.Assert(true);
|
||||
}
|
||||
} else
|
||||
{
|
||||
_currentIndex = index; //GL.Assert(true);
|
||||
texturePackage.Bind2D( index ); //GL.Assert(true);
|
||||
texturePackage.Set2dProperty( index, property ); //GL.Assert(true);
|
||||
if( i.PixelUpdateCount != imageUpdateIndex[ i ] )
|
||||
{
|
||||
texturePackage.LoadTexture( index, i ); //GL.Assert(true);
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if( unusedTextureUnitIndex.TryDequeue( out int newIndex ) )
|
||||
{
|
||||
//has extra unused texture object
|
||||
imageIndexMap.Add( i, index );
|
||||
texturePackage.Bind2D( index );
|
||||
texturePackage.Set2dProperty( index, property );
|
||||
texturePackage.LoadTexture( index, i );
|
||||
usedTextureIndex.AddLast( newIndex );
|
||||
propertyCache[ newIndex ] = property;
|
||||
imageUpdateIndex[ i ] = i.PixelUpdateCount;
|
||||
} else
|
||||
{
|
||||
//recycle from current
|
||||
int reusedIndex = usedTextureIndex.First!.Value;
|
||||
usedTextureIndex.RemoveFirst();
|
||||
usedTextureIndex.AddLast( reusedIndex );
|
||||
imageIndexMap[ i ] = reusedIndex;
|
||||
propertyCache[ newIndex ] = property;
|
||||
imageUpdateIndex[ i ] = i.PixelUpdateCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static AutoTextureGL ToAuto( [NotNull]TextureGL texture )
|
||||
{
|
||||
if( texture.IndexOfCurrentTexture != -1 ) {
|
||||
throw new InvalidOperationException( "Texture to be converted has been editted." );
|
||||
}
|
||||
return new AutoTextureGL( texture );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="EBO.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Internal.OpenGL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of handle to Element Buffer Object in OpenglFunc. Each <see langword="uint"
|
||||
/// /> value indexed from instance of this class this is the only handle to one Element Buffer
|
||||
/// Object.
|
||||
/// </summary>
|
||||
public sealed unsafe class ElementBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal ElementBuffer( int n, glRender binding )
|
||||
: base( binding )
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers( n );
|
||||
}
|
||||
|
||||
public override sealed void Bind( int index )
|
||||
{
|
||||
GL.BindBuffer( BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
|
||||
}
|
||||
|
||||
public void SetValue<T>( int index, T[] bufferArray, BufferUsage usage )
|
||||
where T: struct, INumber<T>
|
||||
{
|
||||
GL.BindBuffer( BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
|
||||
GL.SetBufferData<T>( BufferType.ElementArrayBuffer, bufferArray, usage );
|
||||
}
|
||||
|
||||
public void SetValue<T>( int index, ReadOnlySpan<T> bufferSpan, BufferUsage usage )
|
||||
where T: struct, INumber<T>
|
||||
{
|
||||
GL.BindBuffer( BufferType.ElementArrayBuffer, _bufferHandle[ index ] );
|
||||
GL.SetBufferData<T>( BufferType.ElementArrayBuffer, bufferSpan, usage );
|
||||
}
|
||||
|
||||
protected override sealed void Dispose( bool disposing )
|
||||
{
|
||||
if( disposing ) {
|
||||
GL.DeleteBuffers( _bufferHandle );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="FBO.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
#pragma warning disable CA1028
|
||||
public enum FrameBufferTarget : uint
|
||||
#pragma warning restore CA1028
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Read = glConst.READ_FRAMEBUFFER,
|
||||
All = glConst.FRAMEBUFFER,
|
||||
Draw = glConst.DRAW_FRAMEBUFFER,
|
||||
|
||||
}
|
||||
|
||||
public sealed class FrameBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal unsafe FrameBuffer( int count, glRender binding )
|
||||
: base( binding )
|
||||
{
|
||||
_bufferHandle = GL.GenFrameBuffers( count );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame Buffer object with _label frame Buffer to the frame Buffer target
|
||||
/// specified by target. <see langword="FrameBufferTarget.All" /> will be set as default
|
||||
/// target.
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
/// Index of object to be binded in handle set
|
||||
/// </param>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public override unsafe void Bind( int index )
|
||||
{
|
||||
GL.BindFrameBuffer( FrameBufferTarget.All, _bufferHandle[ index ] );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame Buffer object with _label frame Buffer to the frame Buffer target
|
||||
/// specified by target. Target of this frame Buffer should be set manually.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// The frame Buffer target of the binding operation.
|
||||
/// </param>
|
||||
/// <param _label="index">
|
||||
/// Index of object to be binded in handle set
|
||||
/// </param>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void Bind( FrameBufferTarget target, int index )
|
||||
{
|
||||
GL.BindFrameBuffer( target, _bufferHandle[ index ] );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static void BindNull()
|
||||
{
|
||||
OpenGLFunction.CurrentGL.BindFrameBuffer( FrameBufferTarget.All, GlHandle.Zero );
|
||||
}
|
||||
|
||||
protected override void Dispose( bool disposing )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLBufferObjectBase.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract class GlBufferObjectBase : BufferObjectBase
|
||||
{
|
||||
|
||||
private readonly glRender _contextBinding;
|
||||
|
||||
protected GlBufferObjectBase( glRender contextBinding )
|
||||
{
|
||||
binding = contextBinding;
|
||||
_contextBinding = contextBinding;
|
||||
}
|
||||
|
||||
protected OpenGLFunction GL => _contextBinding.GL;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="RBO.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class RenderBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
public RenderBuffer( int count, glRender binding )
|
||||
: base( binding )
|
||||
{
|
||||
_bufferHandle = GL.GenRenderBuffer( count );
|
||||
}
|
||||
|
||||
public override void Bind( int index )
|
||||
{
|
||||
GL.BindRenderBuffer( this[ index ] );
|
||||
}
|
||||
|
||||
public void Store( RenderBufferInternalFormat format, (int width, int height) size )
|
||||
{
|
||||
if( ( size.width > binding.Width ) || ( size.height > binding.Height ) ) {
|
||||
World.LogWarning( "FrameBuffer is larger than current canvas binding" );
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose( bool disposing )
|
||||
{
|
||||
foreach( GlHandle item in _bufferHandle )
|
||||
{
|
||||
Console.WriteLine( "removing a render buffer" );
|
||||
GL.DeleteRenderBuffer( item );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TextureGL.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class TextureGL
|
||||
{
|
||||
|
||||
private int currentEditingTextureIndex;
|
||||
|
||||
private OpenGLFunction _gl;
|
||||
internal GlHandle[] _textureHandle;
|
||||
|
||||
internal TextureGL( int count, glRender binding )
|
||||
{
|
||||
//sourceList = new Image[count];
|
||||
this._gl = binding.GL;
|
||||
_textureHandle = _gl.GenTextures( count );
|
||||
}
|
||||
|
||||
public GlHandle this[ int index ]
|
||||
{
|
||||
get => _textureHandle[ index ];
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get => _textureHandle.Length;
|
||||
}
|
||||
|
||||
//internal Image[] sourceList;
|
||||
|
||||
public int IndexOfCurrentTexture
|
||||
{
|
||||
get => currentEditingTextureIndex;
|
||||
}
|
||||
|
||||
internal OpenGLFunction GL => _gl;
|
||||
|
||||
public void ActivateAs( TextureUnit unit )
|
||||
{
|
||||
_gl.ActiveTextureUnit( ( uint )unit );
|
||||
}
|
||||
|
||||
public void Bind2D( int index )
|
||||
{
|
||||
currentEditingTextureIndex = index;
|
||||
_gl.BindTexture( glConst.TEXTURE_2D, _textureHandle[ index ] );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an <see cref="Image" /> to certain texture.
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
///
|
||||
/// </param>
|
||||
/// <param _label="i">
|
||||
///
|
||||
/// </param>
|
||||
public unsafe void LoadTexture( int index, Image i )
|
||||
{
|
||||
byte[] handle = i.PixelBuffer;
|
||||
_gl.TextureImage2d(
|
||||
Texture2DTarget.Texture2D, 0, i.Channel, ( uint )i.Width, ( uint )i.Height,
|
||||
i.Channel, i.PixelLayout, pixels: handle );
|
||||
_gl.GenerateMipmap( Texture2DTarget.Texture2D );
|
||||
}
|
||||
|
||||
#region texture setting
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Set2dFilterProperty(
|
||||
int index,
|
||||
TextureFilter onMinify,
|
||||
TextureFilter onMagnify )
|
||||
{
|
||||
#if DEBUG
|
||||
if( index != currentEditingTextureIndex )
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Texture to be editted is not the one being activated." );
|
||||
}
|
||||
#endif
|
||||
_gl.TextureParameter( glConst.TEXTURE_2D, glConst.TEXTURE_MIN_FILTER, ( int )onMinify );
|
||||
_gl.TextureParameter( glConst.TEXTURE_2D, glConst.TEXTURE_MAG_FILTER,
|
||||
( int )onMagnify );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Set2dWrapProperty(
|
||||
int index,
|
||||
TextureWrap onHorizontial,
|
||||
TextureWrap onVertical )
|
||||
{
|
||||
#if DEBUG
|
||||
if( index != currentEditingTextureIndex )
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Texture to be editted is not the one being activated." );
|
||||
}
|
||||
#endif
|
||||
_gl.TextureParameter( glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_S,
|
||||
( int )onHorizontial );
|
||||
_gl.TextureParameter( glConst.TEXTURE_2D, glConst.TEXTURE_WRAP_T, ( int )onVertical );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Set2dProperty( int index, TextureProperty property )
|
||||
{
|
||||
Set2dFilterProperty( index, property.FilterOnMinify, property.FilterOnMagnify );
|
||||
Set2dWrapProperty( index, property.WrapOnHorizontial, property.WrapOnVertical );
|
||||
}
|
||||
|
||||
#endregion texture setting
|
||||
}
|
||||
|
||||
[StructLayout( LayoutKind.Explicit )]
|
||||
public struct TextureProperty
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] private M128 mask;
|
||||
[FieldOffset( 0 )] private TextureFilter mag;
|
||||
[FieldOffset( 4 )] private TextureFilter min;
|
||||
|
||||
[FieldOffset( 8 )] private TextureWrap hori;
|
||||
[FieldOffset( 12 )] private TextureWrap vert;
|
||||
|
||||
public TextureProperty(
|
||||
TextureFilter onMagnify,
|
||||
TextureFilter onMinify,
|
||||
TextureWrap onHorizontial,
|
||||
TextureWrap onVertical )
|
||||
{
|
||||
FilterOnMagnify = onMagnify;
|
||||
FilterOnMinify = onMinify;
|
||||
WrapOnHorizontial = onHorizontial;
|
||||
WrapOnVertical = onVertical;
|
||||
}
|
||||
|
||||
public TextureFilter FilterOnMagnify
|
||||
{
|
||||
get => mag;
|
||||
set => mag = value;
|
||||
}
|
||||
|
||||
public TextureFilter FilterOnMinify
|
||||
{
|
||||
get => min;
|
||||
set => min = value;
|
||||
}
|
||||
|
||||
public TextureWrap WrapOnHorizontial
|
||||
{
|
||||
get => hori;
|
||||
set => hori = value;
|
||||
}
|
||||
|
||||
public TextureWrap WrapOnVertical
|
||||
{
|
||||
get => vert;
|
||||
set => vert = value;
|
||||
}
|
||||
|
||||
public override bool Equals( [NotNullWhen( true )] object obj )
|
||||
{
|
||||
return base.Equals( obj );
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
FilterOnMagnify, FilterOnMagnify, WrapOnHorizontial, WrapOnVertical );
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"FilterOnMagnify:{FilterOnMagnify}, " + $"FilterOnMagnify:{FilterOnMagnify}, " + $"WrapOnHorizontial:{WrapOnHorizontial}, " + $"WrapOnVertical:{WrapOnVertical}";
|
||||
}
|
||||
|
||||
public static bool operator !=( TextureProperty left, TextureProperty right )
|
||||
{
|
||||
return left.mask != right.mask;
|
||||
}
|
||||
|
||||
public static bool operator ==( TextureProperty left, TextureProperty right )
|
||||
{
|
||||
return left.mask == right.mask;
|
||||
}
|
||||
|
||||
public static implicit operator TextureProperty(
|
||||
(
|
||||
TextureFilter onMagnify, TextureFilter onMinify,
|
||||
TextureWrap onHorizontial, TextureWrap onVertical
|
||||
) propertyValueTuple )
|
||||
{
|
||||
return new TextureProperty(
|
||||
propertyValueTuple.onMagnify, propertyValueTuple.onMinify,
|
||||
propertyValueTuple.onHorizontial, propertyValueTuple.onVertical );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureFilter
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Nearest = glConst.NEAREST,
|
||||
Linear = glConst.LINEAR,
|
||||
NearestLinearMipmap = glConst.NEAREST_MIPMAP_LINEAR,
|
||||
LinearLinearMipmap = glConst.LINEAR_MIPMAP_LINEAR,
|
||||
NearestNearestMipmap = glConst.NEAREST_MIPMAP_NEAREST,
|
||||
LinearNearestMipmap = glConst.LINEAR_MIPMAP_NEAREST,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureUnit
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Unit0 = glConst.TEXTURE0,
|
||||
Unit1 = glConst.TEXTURE1,
|
||||
Unit2 = glConst.TEXTURE2,
|
||||
Unit3 = glConst.TEXTURE3,
|
||||
Unit4 = glConst.TEXTURE4,
|
||||
Unit5 = glConst.TEXTURE5,
|
||||
Unit6 = glConst.TEXTURE6,
|
||||
Unit7 = glConst.TEXTURE7,
|
||||
Unit8 = glConst.TEXTURE8,
|
||||
Unit9 = glConst.TEXTURE9,
|
||||
Unit10 = glConst.TEXTURE10,
|
||||
Unit11 = glConst.TEXTURE11,
|
||||
Unit12 = glConst.TEXTURE12,
|
||||
Unit13 = glConst.TEXTURE13,
|
||||
Unit14 = glConst.TEXTURE14,
|
||||
Unit15 = glConst.TEXTURE15,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum TextureWrap
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Repeat = glConst.REPEAT,
|
||||
MirroredRepeat = glConst.MIRRORED_REPEAT,
|
||||
ClampToEdge = glConst.CLAMP_TO_EDGE,
|
||||
ClampToBorder = glConst.CLAMP_TO_BORDER,
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="VAO.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class VertexArray : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexArray( int n, glRender binding )
|
||||
: base( binding )
|
||||
{
|
||||
_bufferHandle = GL.GenVertexArrays( n );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public override sealed void Bind( int index )
|
||||
{
|
||||
GL.BindVertexArray( _bufferHandle[ index ] );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static void BindNull()
|
||||
{
|
||||
OpenGLFunction.CurrentGL.BindVertexArray( GlHandle.Zero );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetVertexAttribute(
|
||||
uint attributeIndex,
|
||||
int vertexLength,
|
||||
TypeCode dataType,
|
||||
bool isNomalized,
|
||||
uint stride,
|
||||
int pointer )
|
||||
{
|
||||
GL.SetVertexAttribute(
|
||||
attributeIndex, vertexLength, dataType, isNomalized, stride, pointer );
|
||||
}
|
||||
|
||||
protected override sealed void Dispose( bool disposing )
|
||||
{
|
||||
if( disposing ) {
|
||||
GL.DeleteVertexArrays( _bufferHandle );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="VBO.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Security;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed unsafe class VertexBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal VertexBuffer( int n, glRender binding )
|
||||
: base( binding )
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers( n );
|
||||
}
|
||||
|
||||
public override sealed void Bind( int index )
|
||||
{
|
||||
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Unbind()
|
||||
{
|
||||
GL.BindBuffer( BufferType.ArrayBuffer, GlHandle.Zero );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex Buffer object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="bufferData">
|
||||
/// Data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteMatrixData<T>( int index, T bufferData, BufferUsage usage )
|
||||
where T: struct, IMatrix<T>
|
||||
{
|
||||
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
|
||||
GL.SetBufferData( BufferType.ArrayBuffer, bufferData, usage );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex Buffer object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="bufferArray">
|
||||
/// Data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteScalerData<T>( int index, T[] bufferArray, BufferUsage usage )
|
||||
where T: struct, INumber<T>
|
||||
{
|
||||
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
|
||||
GL.SetBufferData( BufferType.ArrayBuffer, bufferArray, usage );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex Buffer object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="scalerSpan">
|
||||
/// A <see cref="Span{T}" /> of _data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteScalerData<T>( int index, ReadOnlySpan<T> scalerSpan, BufferUsage usage )
|
||||
where T: struct,INumber<T>
|
||||
{
|
||||
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
|
||||
GL.SetBufferData( BufferType.ArrayBuffer, scalerSpan, usage );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex Buffer object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="vectorSpan">
|
||||
/// A <see cref="Span{T}" /> of data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteVectorData<T>( int index, ReadOnlySpan<T> vectorSpan, BufferUsage usage )
|
||||
where T: struct, IVector<T>
|
||||
{
|
||||
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
|
||||
GL.SetBufferVectorData( BufferType.ArrayBuffer, vectorSpan, usage );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex Buffer object
|
||||
/// </summary>
|
||||
/// <typeparam _label="TItem">
|
||||
/// Type of bufferData
|
||||
/// </typeparam>
|
||||
/// <param _label="index">
|
||||
/// Index to find certain VBO in this instance
|
||||
/// </param>
|
||||
/// <param _label="vectorArray">
|
||||
/// A array of _data to write in
|
||||
/// </param>
|
||||
/// <param _label="usage">
|
||||
/// How OpenGL use these _data, defined by <see cref="BufferUsage" />
|
||||
/// </param>
|
||||
public void WriteVectorData<T>( int index, T[] vectorArray, BufferUsage usage )
|
||||
where T: struct, IVector<T>
|
||||
{
|
||||
GL.BindBuffer( BufferType.ArrayBuffer, _bufferHandle[ index ] );
|
||||
GL.SetBufferVectorData( BufferType.ArrayBuffer, vectorArray, usage );
|
||||
}
|
||||
|
||||
protected override sealed void Dispose( bool disposing )
|
||||
{
|
||||
if( disposing ) {
|
||||
GL.DeleteBuffers( _bufferHandle );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLfixed.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
[StructLayout( LayoutKind.Explicit, Size = 8 )]
|
||||
public struct GLfixed
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] public int All;
|
||||
[FieldOffset( 0 )] public short Decimals;
|
||||
[FieldOffset( 4 )] public short Inertger;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IglConvertable.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public interface IglConvertable
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void DisplayGLtypeDefinition();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void GainAllUniforms( ShaderProgram source, params string[] uniformName );
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public ShaderStruct GetConvertedGLtype();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void SetAllUniforms();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Shader.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp;
|
||||
using StgSharp.Internal;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract partial class glRender : RenderStream
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Create an instance of <see cref="Shader" /> program
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// New instance of <see cref="Shader" /> instance.
|
||||
/// </returns>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected override sealed ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram( this );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected override sealed Shader CreateShaderSegment( ShaderType type, int count )
|
||||
{
|
||||
return new Shader( GL.CreateShaderSet( count, type ), type, this );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Shader : ISSDSerializable
|
||||
{
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle[] handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
internal unsafe Shader( GlHandle[] handle, ShaderType usage, glRender stream )
|
||||
{
|
||||
this.handle = handle;
|
||||
GL = stream.GL;
|
||||
type = usage;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
/// <summary>
|
||||
/// Attach one shader code to a shader program.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// Shader program to attach
|
||||
/// </param>
|
||||
/// <param _label="index">
|
||||
/// Index of shader code in current shader code set.
|
||||
/// </param>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void AttachTo( int index, [NotNull]ShaderProgram target )
|
||||
{
|
||||
GL.AttachShader( target.handle, handle[ index ] );
|
||||
}
|
||||
|
||||
public void CheckStatus( int index, ShaderStatus status )
|
||||
{
|
||||
string log = GL.GetShaderStatus( this, index, ( int )status );
|
||||
if( !string.IsNullOrEmpty( log ) ) {
|
||||
throw new InvalidOperationException( $"{$"Shader Error \t{status}\n"}{log}" );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void Compile( int index, ReadOnlySpan<byte> codeU8Stream )
|
||||
{
|
||||
GL.LoadShaderSource( handle[ index ], codeU8Stream );
|
||||
GL.CompileShader( handle[ index ] );
|
||||
CheckStatus( index, ShaderStatus.CompileStatus );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void Compile( int index, byte[] codeStream )
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( codeStream );
|
||||
GL.LoadShaderSource( handle[ index ], codeStream );
|
||||
GL.CompileShader( handle[ index ] );
|
||||
CheckStatus( index, ShaderStatus.CompileStatus );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void Compile( int index, string codeStream )
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( codeStream );
|
||||
GL.LoadShaderSource( handle[ index ], codeStream.AsSpan() );
|
||||
GL.CompileShader( handle[ index ] );
|
||||
CheckStatus( index, ShaderStatus.CompileStatus );
|
||||
}
|
||||
|
||||
public void FromBytes( byte[] stream )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static byte[] FromCodeFile( string fileRoute )
|
||||
{
|
||||
string str = File.ReadAllText( fileRoute );
|
||||
if( string.IsNullOrEmpty( str ) ) {
|
||||
throw new InvalidOperationException( $"Cannot load and GLSL code from {fileRoute}" );
|
||||
}
|
||||
return Encoding.UTF8.GetBytes( str );
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public byte[] GetBytes( out int length )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ShaderStatus : int
|
||||
{
|
||||
|
||||
CompileStatus = glConst.COMPILE_STATUS,
|
||||
|
||||
}
|
||||
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
private readonly OpenGLFunction GL;
|
||||
internal readonly GlHandle handle;
|
||||
|
||||
/// <summary>
|
||||
/// CustomizeInit a program with no shader attached.
|
||||
/// </summary>
|
||||
internal unsafe ShaderProgram( glRender binding )
|
||||
{
|
||||
GL = binding.GL;
|
||||
handle = GL.CreateProgram();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe Uniform<T> GetUniform<T>( string name ) where T: struct
|
||||
{
|
||||
return new Uniform<T>( GL.GetUniformLocation( this.handle, name ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U> GetUniform<T, U>( string name ) where T: struct where U: struct
|
||||
{
|
||||
return new Uniform<T, U>( GL.GetUniformLocation( this.handle, name ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U, V> GetUniform<T, U, V>( string name ) where T: struct
|
||||
where U: struct
|
||||
where V: struct
|
||||
{
|
||||
return new Uniform<T, U, V>( GL.GetUniformLocation( this.handle, name ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a uniform form current shader, the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// ContextName of the Uniform in shader code
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>( string name ) where T: struct
|
||||
where U: struct
|
||||
where V: struct
|
||||
where W: struct
|
||||
{
|
||||
return new Uniform<T, U, V, W>( GL.GetUniformLocation( this.handle, name ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Link the shader to current viewPortDisplay.
|
||||
/// </summary>
|
||||
public unsafe void Link()
|
||||
{
|
||||
if( InternalIO.InternalLinkShaderProgram(
|
||||
( OpenglContext* )this.GL.ContextHandle, handle.Value ) ==
|
||||
0 )
|
||||
{
|
||||
IntPtr logPtr = InternalIO.InternalReadSSCLog();
|
||||
try
|
||||
{
|
||||
byte[] logByte = new byte[512];
|
||||
Marshal.Copy( logPtr, logByte, 0, 512 );
|
||||
string log = Encoding.UTF8.GetString( logByte );
|
||||
log = log.Replace( "\0", string.Empty );
|
||||
InternalIO.InternalWriteLog( log, LogType.Error );
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
InternalIO.InternalWriteLog( ex.Message, LogType.Error );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Let the current viewPortDisplay use this shader.
|
||||
/// </summary>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void Use()
|
||||
{
|
||||
GL.UseProgram( handle );
|
||||
}
|
||||
|
||||
~ShaderProgram()
|
||||
{
|
||||
//handle.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Uniform.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
|
||||
internal GlHandle id;
|
||||
|
||||
public GlHandle Handle
|
||||
{
|
||||
get => id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform where T: struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform( GlHandle id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T> FromHandle( GlHandle handle )
|
||||
{
|
||||
return new Uniform<T>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U> : Uniform where T: struct where U: struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform( GlHandle id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U> FromHandle( GlHandle handle )
|
||||
{
|
||||
return new Uniform<T, U>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V> : Uniform where T: struct where U: struct where V: struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform( GlHandle id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V> FromHandle( GlHandle handle )
|
||||
{
|
||||
return new Uniform<T, U, V>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T, U, V, W> : Uniform where T: struct where U: struct
|
||||
where V: struct
|
||||
where W: struct
|
||||
{
|
||||
|
||||
internal Uniform() { }
|
||||
|
||||
internal unsafe Uniform( GlHandle id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
internal static Uniform<T, U, V, W> FromHandle( GlHandle handle )
|
||||
{
|
||||
return new Uniform<T, U, V, W>
|
||||
{
|
||||
id = handle
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetUniformValue( [NotNull] Uniform<Matrix44> uniform, Matrix44 mat )
|
||||
{
|
||||
Matrix44 temp = mat;
|
||||
Context.glUniformMatrix4fv( uniform.id.SignedValue, 1, false, ( float* )&temp );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<float, float, float, float> uniform,
|
||||
Vec4 vec )
|
||||
{
|
||||
Vec4 temp = vec;
|
||||
Context.glUniform1fv( uniform.id.SignedValue, 4, &temp.reg );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetUniformValue( [NotNull]Uniform<Vec4> uniform, Vec4 vec )
|
||||
{
|
||||
Vec4 temp = vec;
|
||||
Context.glUniform1fv( uniform.id.SignedValue, 4, &temp.reg );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetUniformValue( [NotNull]Uniform<float> uniform, float v0 )
|
||||
{
|
||||
Context.glUniform1f( uniform.id.SignedValue, v0 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetUniformValue( [NotNull]Uniform<int> uniform, int i0 )
|
||||
{
|
||||
Context.glUniform1i( uniform.id.SignedValue, i0 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetUniformValue( [NotNull] Uniform<float, float> uniform, float v0, float v1 )
|
||||
{
|
||||
Context.glUniform2f( uniform.id.SignedValue, v0, v1 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<float, float, float> uniform,
|
||||
float v0,
|
||||
float v1,
|
||||
float v2 )
|
||||
{
|
||||
Context.glUniform3f( uniform.id.SignedValue, v0, v1, v2 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetUniformValue(
|
||||
[NotNull] Uniform<float, float, float, float> uniform,
|
||||
float v0,
|
||||
float v1,
|
||||
float v2,
|
||||
float v3 )
|
||||
{
|
||||
Context.glUniform4f( uniform.id.SignedValue, v0, v1, v2, v3 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glAPICalling.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
[AttributeUsage( AttributeTargets.Method )]
|
||||
public sealed class OpenGLAPICallingAttribute : Attribute
|
||||
{
|
||||
|
||||
public OpenGLAPICallingAttribute() { }
|
||||
|
||||
}
|
||||
}
|
||||
+24
-27
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glApiManagerConst.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glApiManagerConst"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,92 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glClampf.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// OpenGL numeric type. An IEEE-754 floating-point value, clamped to the range [0,1].
|
||||
/// </summary>
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
public struct GLclampf
|
||||
{
|
||||
|
||||
public float value;
|
||||
|
||||
public GLclampf( float a )
|
||||
{
|
||||
value = a;
|
||||
}
|
||||
|
||||
public static explicit operator float( GLclampf v )
|
||||
{
|
||||
return v.value;
|
||||
}
|
||||
|
||||
public static explicit operator GLclampf( float v )
|
||||
{
|
||||
return new GLclampf( v );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OpenGL numeric type. An IEEE-754 double precision floating-point value, clamped to the
|
||||
/// range [0,1].
|
||||
/// </summary>
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
public struct GLclampd
|
||||
{
|
||||
|
||||
public double value;
|
||||
|
||||
public GLclampd( double a )
|
||||
{
|
||||
value = a;
|
||||
}
|
||||
|
||||
public static explicit operator double( GLclampd v )
|
||||
{
|
||||
return v.value;
|
||||
}
|
||||
|
||||
public static explicit operator GLclampd( double v )
|
||||
{
|
||||
return new GLclampd( v );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,227 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glEnum.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public enum PixelChannelLayout
|
||||
{
|
||||
|
||||
UByte = glConst.UNSIGNED_BYTE,
|
||||
Byte = glConst.BYTE,
|
||||
UShort = glConst.UNSIGNED_SHORT,
|
||||
Short = glConst.SHORT,
|
||||
UInt = glConst.UNSIGNED_INT,
|
||||
Int = glConst.INT,
|
||||
Float = glConst.FLOAT,
|
||||
UByte332 = glConst.UNSIGNED_BYTE_3_3_2,
|
||||
UByte233Rev = glConst.UNSIGNED_BYTE_2_3_3_REV,
|
||||
UShort565 = glConst.UNSIGNED_SHORT_5_6_5,
|
||||
UShort565Rev = glConst.UNSIGNED_SHORT_5_6_5_REV,
|
||||
UShort4444 = glConst.UNSIGNED_SHORT_4_4_4_4,
|
||||
UShort4444Rev = glConst.UNSIGNED_SHORT_4_4_4_4_REV,
|
||||
UShort5551 = glConst.UNSIGNED_SHORT_5_5_5_1,
|
||||
UShort1555Rev = glConst.UNSIGNED_SHORT_1_5_5_5_REV,
|
||||
UInt8888 = glConst.UNSIGNED_INT_8_8_8_8,
|
||||
UInt8888Rev = glConst.UNSIGNED_INT_8_8_8_8_REV,
|
||||
UInt1010102 = glConst.UNSIGNED_INT_10_10_10_2,
|
||||
UInt2101010Rev = glConst.UNSIGNED_INT_2_10_10_10_REV
|
||||
|
||||
}
|
||||
|
||||
public enum FaceMode
|
||||
{
|
||||
|
||||
Point = glConst.POINT,
|
||||
Line = glConst.LINE,
|
||||
Fill = glConst.FILL
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferStatus
|
||||
{
|
||||
|
||||
Complete = glConst.FRAMEBUFFER_COMPLETE, // GL_FRAMEBUFFER_COMPLETE
|
||||
IncompleteAttachment = glConst.FRAMEBUFFER_INCOMPLETE_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
|
||||
IncompleteMissingAttachment = glConst.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT, // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
||||
IncompleteDrawBuffer = glConst.FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
|
||||
IncompleteReadBuffer = glConst.FRAMEBUFFER_INCOMPLETE_READ_BUFFER, // GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
|
||||
Unsupported = glConst.FRAMEBUFFER_UNSUPPORTED, // GL_FRAMEBUFFER_UNSUPPORTED
|
||||
IncompleteMultisample = glConst.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE, // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
|
||||
IncompleteLayerTargets = glConst.FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS // GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferChannel
|
||||
{
|
||||
|
||||
STENCIL_INDEX = glConst.STENCIL_INDEX,
|
||||
DEPTH_COMPONENT = glConst.DEPTH_COMPONENT,
|
||||
DEPTH_STENCIL = glConst.DEPTH_STENCIL,
|
||||
RED = glConst.RED,
|
||||
GREEN = glConst.GREEN,
|
||||
BLUE = glConst.BLUE,
|
||||
RGB = glConst.RGB,
|
||||
BGR = glConst.BGR,
|
||||
RGBA = glConst.RGBA,
|
||||
BGRA = glConst.BGRA
|
||||
|
||||
}
|
||||
|
||||
public enum FrameBufferAttachment
|
||||
{
|
||||
|
||||
Color = glConst.COLOR_ATTACHMENT0,
|
||||
Depth = glConst.DEPTH_ATTACHMENT,
|
||||
Stencil = glConst.STENCIL_ATTACHMENT,
|
||||
DepthAndStencil = glConst.DEPTH_STENCIL_ATTACHMENT,
|
||||
|
||||
}
|
||||
|
||||
public enum Texture2DTarget
|
||||
{
|
||||
|
||||
Texture2D = glConst.TEXTURE_2D,
|
||||
ProxyTexture2D = glConst.PROXY_TEXTURE_2D,
|
||||
Texture1DArray = glConst.TEXTURE_1D_ARRAY,
|
||||
ProxyTexture1DArray = glConst.PROXY_TEXTURE_1D_ARRAY,
|
||||
TextureRectangle = glConst.TEXTURE_RECTANGLE,
|
||||
ProxyTextureRectangle = glConst.PROXY_TEXTURE_RECTANGLE,
|
||||
TextureCubeMapPositiveX = glConst.TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||
TextureCubeMapNegativeX = glConst.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
TextureCubeMapPositiveY = glConst.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||
TextureCubeMapNegativeY = glConst.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
TextureCubeMapPositiveZ = glConst.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||
TextureCubeMapNegativeZ = glConst.TEXTURE_CUBE_MAP_NEGATIVE_Z,
|
||||
ProxyTextureCubeMap = glConst.PROXY_TEXTURE_CUBE_MAP
|
||||
|
||||
}
|
||||
|
||||
public enum RenderBufferInternalFormat : uint
|
||||
{
|
||||
|
||||
RGBA8 = glConst.RGBA8,
|
||||
Depth24_Stencil8 = glConst.DEPTH24_STENCIL8,
|
||||
|
||||
}
|
||||
|
||||
public enum glOperation : uint
|
||||
{
|
||||
|
||||
StencilTest = glConst.STENCIL_TEST,
|
||||
DepthTest = glConst.DEPTH_TEST,
|
||||
PolygonOffsetFill = glConst.POLYGON_OFFSET_FILL,
|
||||
PolygonOffsetLine = glConst.POLYGON_OFFSET_LINE,
|
||||
PolygonOffsetPoint = glConst.POLYGON_OFFSET_POINT,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum ShaderType : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
Fragment = glConst.FRAGMENT_SHADER,
|
||||
Vertex = glConst.VERTEX_SHADER,
|
||||
Compute = glConst.COMPUTE_SHADER,
|
||||
Geometry = glConst.GEOMETRY_SHADER,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum BufferType : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
ArrayBuffer = glConst.ARRAY_BUFFER,
|
||||
ElementArrayBuffer = glConst.ELEMENT_ARRAY_BUFFER,
|
||||
AtomicCounterBuffer = glConst.ATOMIC_COUNTER_BUFFER,
|
||||
CopyHeadBuffer = glConst.COPY_READ_BUFFER,
|
||||
COPY_WRITE_BUFFER = glConst.COPY_WRITE_BUFFER,
|
||||
DISPATCH_INDIRECT_BUFFER = glConst.DISPATCH_INDIRECT_BUFFER,
|
||||
DRAW_INDIRECT_BUFFER = glConst.DRAW_INDIRECT_BUFFER,
|
||||
PIXEL_PACK_BUFFER = glConst.PIXEL_PACK_BUFFER,
|
||||
PIXEL_UNPACK_BUFFER = glConst.PIXEL_UNPACK_BUFFER,
|
||||
QUERY_BUFFER = glConst.QUERY_BUFFER,
|
||||
ShaderStorageBuffer = glConst.SHADER_STORAGE_BUFFER,
|
||||
TEXTURE_BUFFER = glConst.TEXTURE_BUFFER,
|
||||
TRANSFORM_FEEDBACK_BUFFER = glConst.TRANSFORM_FEEDBACK_BUFFER,
|
||||
UNIFORM_BUFFER = glConst.UNIFORM_BUFFER,
|
||||
|
||||
}
|
||||
|
||||
#pragma warning disable CA1008
|
||||
public enum BufferUsage : int
|
||||
#pragma warning restore CA1008
|
||||
{
|
||||
|
||||
StreamDraw = 0x88E0,
|
||||
StreamRead = 0x88E1,
|
||||
StreamCopy = 0x88E2,
|
||||
StaticDraw = 0x88E4,
|
||||
StaticRead = 0x88E5,
|
||||
StaticCopy = 0x88E6,
|
||||
DynamicDraw = 0x88E8,
|
||||
DynamicRead = 0x88E9,
|
||||
DynamicCopy = 0x88EA
|
||||
|
||||
}
|
||||
|
||||
public enum MaskBufferBit
|
||||
{
|
||||
|
||||
COLOR = glConst.COLOR_BUFFER_BIT,
|
||||
DEPTH = glConst.DEPTH_BUFFER_BIT,
|
||||
STENCIL = glConst.STENCIL_BUFFER_BIT,
|
||||
|
||||
}
|
||||
|
||||
public enum GeometryType : uint
|
||||
{
|
||||
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
LINE_LOOP = 0x0002,
|
||||
LINE_STRIP = 0x0003,
|
||||
TRIANGLES = 0x0004,
|
||||
TRIANGLE_STRIP = 0x0005,
|
||||
TRIANGLE_FAN = 0x0006
|
||||
|
||||
}
|
||||
|
||||
public enum TextureFiltering
|
||||
{
|
||||
|
||||
Nearest = 0x2600,
|
||||
Linear = 0x2601
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glException.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public sealed class GlErrorOverflowException : Exception
|
||||
{
|
||||
|
||||
public GlErrorOverflowException( int errorCount, uint errorCode )
|
||||
: base(
|
||||
"Too many opengl error detected at certain position. " + $"The amount of errors exceeds {errorCount}. " + $"Code of the last error is {errorCode}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public sealed class GlExecutionException : Exception
|
||||
{
|
||||
|
||||
public GlExecutionException( uint errorCode )
|
||||
: base( $"Critical OpenGL error: {errorCode}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public sealed class GlArrayFormatException : Exception
|
||||
{
|
||||
|
||||
internal GlArrayFormatException( string message ) : base( message ) { }
|
||||
|
||||
internal GlArrayFormatException( SerializationInfo info, StreamingContext context )
|
||||
: base( info, context ) { }
|
||||
|
||||
internal GlArrayFormatException( string message, Exception innerException )
|
||||
: base( message, innerException ) { }
|
||||
|
||||
public GlArrayFormatException( PixelChannelLayout layout, string arrayname )
|
||||
: base( $"{arrayname} cannot be used as layout of {layout}" ) { }
|
||||
|
||||
}
|
||||
|
||||
public static partial class GlHelper
|
||||
{
|
||||
|
||||
public static bool CheckArrayFormat( this Array array, PixelChannelLayout layout )
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.Byte or PixelChannelLayout.UByte332 or PixelChannelLayout.UByte233Rev => ( array is byte[] ) ||
|
||||
( array is sbyte[] ),
|
||||
PixelChannelLayout.Short => array is short[],
|
||||
PixelChannelLayout.UShort => array is ushort[],
|
||||
PixelChannelLayout.Int => array is int[],
|
||||
PixelChannelLayout.Float => array is float[],
|
||||
PixelChannelLayout.UShort4444 => ( array is ushort[] ) || ( array is byte[] ),
|
||||
PixelChannelLayout.UByte => ( array is byte[] ) || ( array is sbyte[] ),
|
||||
PixelChannelLayout.UInt => array is uint[],
|
||||
PixelChannelLayout.UShort565 or
|
||||
PixelChannelLayout.UShort565Rev or
|
||||
PixelChannelLayout.UShort4444Rev or
|
||||
PixelChannelLayout.UShort5551 or
|
||||
PixelChannelLayout.UShort1555Rev => array is ushort[],
|
||||
PixelChannelLayout.UInt8888Rev or
|
||||
PixelChannelLayout.UInt1010102 or
|
||||
PixelChannelLayout.UInt2101010Rev => array is int[],
|
||||
PixelChannelLayout.UInt8888 => array is uint[] or byte[],
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glFucntionSourceManager.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the ¡°Software¡±), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED ¡°AS IS¡±,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private Lazy<int> textureUnitCountGetter;
|
||||
private Lazy<ConcurrentQueue<TextureUnit>> unusedTextureImageUintInitilizing;
|
||||
|
||||
public int TextureUnitCount
|
||||
{
|
||||
get => textureUnitCountGetter.Value;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> UnusedTextureImageUint
|
||||
{
|
||||
get => unusedTextureImageUintInitilizing.Value;
|
||||
}
|
||||
|
||||
internal void ReturnAvailableUnit( IEnumerable<TextureUnit> source )
|
||||
{
|
||||
int v = glConst.TEXTURE0 + TextureUnitCount;
|
||||
foreach( TextureUnit unit in source )
|
||||
{
|
||||
if( ( int )unit > v ) {
|
||||
throw new InvalidOperationException(
|
||||
"Source contains texture unit beyond context support." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal int TryGetAvailableTextureUnit( int count, out IEnumerable<TextureUnit> result )
|
||||
{
|
||||
result = new Queue<TextureUnit>();
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
if( UnusedTextureImageUint.TryDequeue( out TextureUnit unit ) )
|
||||
{
|
||||
( result as Queue<TextureUnit> )!.Enqueue( unit );
|
||||
} else
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> InitializeUnusedTextureImageUint()
|
||||
{
|
||||
ConcurrentQueue<TextureUnit> result = new ConcurrentQueue<TextureUnit>();
|
||||
for( int index = 0; index < TextureUnitCount; index++ ) {
|
||||
result.Enqueue( ( TextureUnit )( glConst.TEXTURE0 + index ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,838 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glFunction.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Internal;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private static Dictionary<IntPtr, OpenGLFunction> contextToGLMap = new Dictionary<IntPtr, OpenGLFunction>(
|
||||
);
|
||||
private static ThreadLocal<OpenGLFunction> _currentGL = new ThreadLocal<OpenGLFunction>();
|
||||
private OpenglContext* _context;
|
||||
|
||||
private Lazy<int> _attachmentColorRange;
|
||||
|
||||
private OpenGLFunction()
|
||||
{
|
||||
textureUnitCountGetter = new Lazy<int>(
|
||||
() => GetMaskInteger( glConst.MAX_TEXTURE_IMAGE_UNITS ) );
|
||||
unusedTextureImageUintInitilizing = new Lazy<ConcurrentQueue<TextureUnit>>(
|
||||
InitializeUnusedTextureImageUint );
|
||||
_attachmentColorRange = new Lazy<int>(
|
||||
() => {
|
||||
return GetMaskInteger( ( uint )glConst.MAX_COLOR_ATTACHMENTS );
|
||||
} );
|
||||
}
|
||||
|
||||
public int AttachmentColorRange
|
||||
{
|
||||
get => _attachmentColorRange.Value;
|
||||
}
|
||||
|
||||
public static OpenGLFunction CurrentGL
|
||||
{
|
||||
get { return _currentGL.Value; }
|
||||
internal set { _currentGL.Value = value; }
|
||||
}
|
||||
|
||||
internal IntPtr ContextHandle => ( IntPtr )_context;
|
||||
|
||||
protected ref OpenglContext Context
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if( ( IntPtr )_context == IntPtr.Zero )
|
||||
{
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
#endif
|
||||
return ref ( *_context );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void ActiveTextureUnit( uint type )
|
||||
{
|
||||
Context.glActiveTexture( type );
|
||||
}
|
||||
|
||||
[Conditional( "DEBUG" )]
|
||||
public void Assert( bool shouldReportWhenNormal )
|
||||
{
|
||||
uint code = Context.glGetError();
|
||||
if( code != glConst.NO_ERROR ) {
|
||||
throw new GlExecutionException( code );
|
||||
}
|
||||
if( shouldReportWhenNormal ) {
|
||||
Console.WriteLine( "OpenGL runs normally" );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void AttachShader( GlHandle program, GlHandle shader )
|
||||
{
|
||||
Context.glAttachShader( program.Value, shader.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void BindBuffer( BufferType bufferType, GlHandle handle )
|
||||
{
|
||||
Context.glBindBuffer( ( uint )bufferType, handle.Value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind a frame Buffer to a frame Buffer target Same function as <see
|
||||
/// href="https://docs._gl/gl3/glBindFramebuffer"> glBindFramebuffer </see>.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// The frame Buffer target of the binding operation.
|
||||
/// </param>
|
||||
/// <param _label="handle">
|
||||
/// The handle of the frame Buffer object to bind.
|
||||
/// </param>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void BindFrameBuffer( FrameBufferTarget target, GlHandle handle )
|
||||
{
|
||||
Context.glBindFramebuffer( ( uint )target, handle.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void BindRenderBuffer( GlHandle handle )
|
||||
{
|
||||
Context.glBindRenderbuffer( glConst.RENDERBUFFER, handle.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void BindTexture( uint type, GlHandle texture )
|
||||
{
|
||||
Context.glBindTexture( type, texture.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void BindVertexArray( GlHandle handle )
|
||||
{
|
||||
Context.glBindVertexArray( handle.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public FrameBufferStatus CheckFrameBufferStatus( FrameBufferTarget target )
|
||||
{
|
||||
return ( FrameBufferStatus )Context.glCheckFramebufferStatus( ( uint )target );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Clear( MaskBufferBit mask )
|
||||
{
|
||||
Context.glClear( ( uint )mask );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void ClearColor( float R, float G, float B, float A )
|
||||
{
|
||||
Context.glClearColor( R, G, B, A );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void ClearError()
|
||||
{
|
||||
uint code = 0;
|
||||
for( int i = 0; i < 1024; i++ )
|
||||
{
|
||||
code = Context.glGetError();
|
||||
if( code == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Console.WriteLine(code);
|
||||
}
|
||||
foreach( ProcessThread thread in Process.GetCurrentProcess().Threads ) {
|
||||
Debugger.Break();
|
||||
}
|
||||
throw new GlErrorOverflowException( 1024, code );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void ClearGraphicError()
|
||||
{
|
||||
while( Context.glGetError() != 0 ) { }
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void CombineFrameBufferRenderBuffer(
|
||||
FrameBufferAttachment attachment,
|
||||
GlHandle rboHandle )
|
||||
{
|
||||
Context.glFramebufferRenderbuffer(
|
||||
glConst.FRAMEBUFFER, ( uint )attachment, glConst.RENDERBUFFER, rboHandle.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void CompileShader( GlHandle shaderhandle )
|
||||
{
|
||||
Context.glCompileShader( shaderhandle.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe GlHandle CreateGraphicProgram()
|
||||
{
|
||||
return GlHandle.Alloc( Context.glCreateProgram() );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public GlHandle CreateProgram()
|
||||
{
|
||||
return GlHandle.Alloc( Context.glCreateProgram() );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe GlHandle[] CreateProgram( int count )
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
for( int i = 0; i < count; i++ ) {
|
||||
h.SetValue( i, Context.glCreateProgram() );
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public GlHandle[] CreateShaderSet( int count, ShaderType type )
|
||||
{
|
||||
GlHandle[] ret = new GlHandle[count];
|
||||
uint t = ( uint )type;
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
uint id = Context.glCreateShader( t );
|
||||
if( id == 0 )
|
||||
{
|
||||
uint error = Context.glGetError();
|
||||
throw new InvalidOperationException( $"Failed in creating shader: {error}" );
|
||||
}
|
||||
ret[ i ] = GlHandle.Alloc( id );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void DeleteBuffer( GlHandle handle )
|
||||
{
|
||||
Context.glDeleteBuffers( 1, ( uint* )&handle );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void DeleteBuffers( GlHandle[] handle )
|
||||
{
|
||||
if( ( handle == null ) || ( handle.Length == 0 ) ) {
|
||||
throw new ArgumentNullException( nameof( handle ) );
|
||||
}
|
||||
fixed( GlHandle* hptr = handle )
|
||||
{
|
||||
uint* iptr = ( uint* )hptr;
|
||||
for( int i = 0; i < handle.Length; i++ ) {
|
||||
Context.glDeleteBuffers( 1, iptr + i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a render Buffer object Very simlilar function as <see
|
||||
/// href="https://docs.gl/gl3/glDeleteRenderbuffers"> glDeleteRenderbuffers </see>. The
|
||||
/// only deifference is that this mehtod can only delete one renderbuffer at the same
|
||||
/// time.
|
||||
/// </summary>
|
||||
/// <param _label="bufferHandle">
|
||||
/// Handle to Buffer to delete.
|
||||
/// </param>
|
||||
public unsafe void DeleteRenderBuffer( GlHandle bufferHandle )
|
||||
{
|
||||
Context.glDeleteRenderbuffers( 1, &bufferHandle.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void DeleteVertexArrays( GlHandle[] arrays )
|
||||
{
|
||||
fixed( GlHandle* hptr = arrays )
|
||||
{
|
||||
uint* iptr = ( uint* )hptr;
|
||||
for( int i = 0; i < arrays.Length; i++ ) {
|
||||
Context.glDeleteVertexArrays( 1, iptr + i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DepthMaskAccess( bool isWrite )
|
||||
{
|
||||
Context.glDepthMask( isWrite );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Disable( glOperation operation )
|
||||
{
|
||||
Context.glDisable( ( uint )operation );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void DrawArrays( GeometryType mode, int first, uint count )
|
||||
{
|
||||
Context.glDrawArrays( ( uint )mode, first, count );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void DrawElements( GeometryType mode, uint count, TypeCode type, IntPtr ptr )
|
||||
{
|
||||
uint a;
|
||||
a = type switch
|
||||
{
|
||||
TypeCode.UInt32 => glConst.UNSIGNED_INT,
|
||||
TypeCode.UInt16 => glConst.UNSIGNED_SHORT,
|
||||
TypeCode.Byte => glConst.UNSIGNED_BYTE,
|
||||
_ => throw new ArgumentException(
|
||||
$"{$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}"}{$"{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}"}" )
|
||||
};
|
||||
Context.glDrawElements( ( uint )mode, count, a, ( void* )ptr );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void DrawElementsInstanced(
|
||||
GeometryType mode,
|
||||
uint count,
|
||||
TypeCode type,
|
||||
IntPtr ptr,
|
||||
uint amount )
|
||||
{
|
||||
uint a;
|
||||
switch( type )
|
||||
{
|
||||
case TypeCode.UInt32:
|
||||
a = glConst.UNSIGNED_INT;
|
||||
break;
|
||||
|
||||
case TypeCode.UInt16:
|
||||
a = glConst.UNSIGNED_SHORT;
|
||||
break;
|
||||
|
||||
case TypeCode.Byte:
|
||||
a = glConst.UNSIGNED_BYTE;
|
||||
break;
|
||||
default:
|
||||
InternalIO.InternalWriteLog(
|
||||
$"{$"Parameter error in parameter {nameof(type)} method DrawElements. "}{$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are supported."}",
|
||||
LogType.Error );
|
||||
return;
|
||||
}
|
||||
Context.glDrawElementsInstanced( ( uint )mode, count, a, ( void* )ptr, amount );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Enable( glOperation operation )
|
||||
{
|
||||
Context.glEnable( ( uint )operation );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void FrameBufferTexture2d(
|
||||
FrameBufferTarget target,
|
||||
uint attachment,
|
||||
Texture2DTarget texTarget,
|
||||
GlHandle textureHandle,
|
||||
int level )
|
||||
{
|
||||
Context.glFramebufferTexture2D(
|
||||
( uint )target, attachment, ( uint )texTarget, textureHandle.Value, level );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe GlHandle[] GenBuffers( int count )
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed( GlHandle* hptr = h )
|
||||
{
|
||||
for( int i = 0; i < count; i++ ) {
|
||||
Context.glGenBuffers( count, ( ( uint* )hptr ) + i );
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void GenerateMipmap( Texture2DTarget target )
|
||||
{
|
||||
Context.glGenerateMipmap( ( uint )target );
|
||||
}
|
||||
|
||||
public unsafe GlHandle[] GenFrameBuffers( int count )
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed( GlHandle* hptr = h ) {
|
||||
Context.glGenFramebuffers( 1, ( uint* )hptr );
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe GlHandle[] GenRenderBuffer( int count )
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed( GlHandle* hptr = h ) {
|
||||
Context.glGenRenderbuffers( count, ( uint* )hptr );
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe GlHandle[] GenTextures( int count )
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed( GlHandle* hptr = h ) {
|
||||
Context.glGenTextures( count, ( uint* )hptr );
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
public unsafe GlHandle[] GenVertexArrays( int count )
|
||||
{
|
||||
GlHandle[] h = new GlHandle[count];
|
||||
fixed( GlHandle* hptr = h ) {
|
||||
Context.glGenVertexArrays( count, ( uint* )hptr );
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public uint GetError()
|
||||
{
|
||||
return Context.glGetError();
|
||||
}
|
||||
|
||||
public unsafe int GetMaskInteger( uint statusCode )
|
||||
{
|
||||
int ret = 0;
|
||||
Context.glGetIntegerv( statusCode, &ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
public string GetShaderStatus( Shader s, int index, int key )
|
||||
{
|
||||
IntPtr sptr = IntPtr.Zero;
|
||||
if( InternalIO.glCheckShaderStatus(
|
||||
ref Context, s.handle[ index ].Value, key, ref sptr ) ==
|
||||
0 ) {
|
||||
return Marshal.PtrToStringAnsi( sptr );
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void GetTextureImage<T>(
|
||||
Texture2DTarget target,
|
||||
int level,
|
||||
ImageChannel channel,
|
||||
PixelChannelLayout channelLayout,
|
||||
T[] dataStream )
|
||||
where T: struct,INumber<T>
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
fixed( T* tptr = dataStream )
|
||||
{
|
||||
Context.glGetTexImage(
|
||||
( uint )target, level, ( uint )channel, ( uint )channelLayout, tptr );
|
||||
}
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void GetTextureLevelProperty(
|
||||
uint textureTypeMask,
|
||||
int level,
|
||||
uint propertyMask,
|
||||
out int propertyValue )
|
||||
{
|
||||
fixed( int* iptr = &propertyValue ) {
|
||||
Context.glGetTexLevelParameteriv( textureTypeMask, level, propertyMask, iptr );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe GlHandle GetUniformLocation( GlHandle program, string name )
|
||||
{
|
||||
byte[] code = Encoding.UTF8.GetBytes( name );
|
||||
fixed( byte* ptr = code )
|
||||
{
|
||||
int ret = Context.glGetUniformLocation( program.Value, ptr );
|
||||
#if DEBUG
|
||||
if( ( ret == glConst.INVALID_OPERATION ) || ( ret == glConst.INVALID_VALUE ) )
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
if( ret == -1 ) {
|
||||
throw new UniformEmptyReferenceException( nameof( program ), name );
|
||||
}
|
||||
#endif
|
||||
return GlHandle.SignedAlloc( ret );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void LoadShaderSource( GlHandle shaderHandle, byte[] codeStream )
|
||||
{
|
||||
fixed( byte* streamPtr = codeStream ) {
|
||||
Context.glShaderSource( shaderHandle.Value, 1, &streamPtr, ( void* )0 );
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void LoadShaderSource( GlHandle shaderHandle, ReadOnlySpan<char> codeStream )
|
||||
{
|
||||
fixed( char* streamPtr = codeStream )
|
||||
{
|
||||
byte* bptr = ( byte* )streamPtr;
|
||||
Context.glShaderSource( shaderHandle.Value, 1, &bptr, ( void* )0 );
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void LoadShaderSource( GlHandle shaderHandle, ReadOnlySpan<byte> codeStream )
|
||||
{
|
||||
fixed( byte* streamPtr = codeStream )
|
||||
{
|
||||
byte* bptr = streamPtr;
|
||||
Context.glShaderSource( shaderHandle.Value, 1, &bptr, ( void* )0 );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void PolygonMode( FaceMode mode )
|
||||
{
|
||||
Context.glPolygonMode( glConst.FRONT_AND_BACK, ( uint )mode );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void PolygonOffset( float factor, float unit )
|
||||
{
|
||||
Context.glPolygonOffset( factor, unit );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void ReadPixels(
|
||||
(int X, int Y) beginPosition,
|
||||
(int width, int height) size,
|
||||
FrameBufferChannel format,
|
||||
PixelChannelLayout dataType,
|
||||
ref byte[] stream )
|
||||
{
|
||||
fixed( byte* bptr = stream ) {
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y, size.width, size.height, ( uint )format,
|
||||
( uint )dataType, bptr );
|
||||
}
|
||||
}
|
||||
|
||||
public void RereadImage(
|
||||
in Image i,
|
||||
(int X, int Y) beginPosition,
|
||||
FrameBufferChannel format,
|
||||
PixelChannelLayout dataType )
|
||||
{
|
||||
byte[] pixels = i.PixelBuffer;
|
||||
if( !pixels.CheckArrayFormat( dataType ) ) {
|
||||
throw new GlArrayFormatException( dataType, "i.PixelArray" );
|
||||
}
|
||||
fixed( byte* bptr = pixels ) {
|
||||
Context.glReadPixels(
|
||||
beginPosition.X, beginPosition.Y, i.Width, i.Height, ( uint )format,
|
||||
( uint )dataType, bptr );
|
||||
}
|
||||
i.PixelUpdateCount++;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void SetBufferData<T>(
|
||||
BufferType bufferType,
|
||||
T bufferData,
|
||||
BufferUsage usage )
|
||||
where T: struct
|
||||
{
|
||||
int size = Marshal.SizeOf<T>();
|
||||
#pragma warning disable CS8500
|
||||
T* p = &bufferData;
|
||||
#pragma warning restore CS8500
|
||||
Context.glBufferData( ( uint )bufferType, ( IntPtr )size, ( IntPtr )p, ( uint )usage );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void SetBufferData<T>(
|
||||
BufferType bufferType,
|
||||
T[] bufferArray,
|
||||
BufferUsage usage )
|
||||
where T: struct,INumber<T>
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
|
||||
if( bufferArray == null ) {
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed( void* bufferPtr = bufferArray )
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void SetBufferData<T>(
|
||||
BufferType bufferType,
|
||||
ReadOnlySpan<T> bufferSpan,
|
||||
BufferUsage usage )
|
||||
where T: struct,INumber<T>
|
||||
{
|
||||
int size = bufferSpan.Length * Marshal.SizeOf( typeof( T ) );
|
||||
if( bufferSpan == null ) {
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed( void* bufferPtr = bufferSpan )
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void SetBufferData<T>(
|
||||
BufferType bufferType,
|
||||
Span<T> bufferArray,
|
||||
BufferUsage usage )
|
||||
where T: struct, INumber<T>
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
|
||||
if( bufferArray == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
#pragma warning disable CS8500
|
||||
fixed( void* bufferPtr = bufferArray )
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void SetBufferVectorData<T>(
|
||||
BufferType bufferType,
|
||||
ReadOnlySpan<T> bufferSpan,
|
||||
BufferUsage usage )
|
||||
where T: struct, IVector<T>
|
||||
{
|
||||
int size = bufferSpan.Length * Marshal.SizeOf( typeof( T ) );
|
||||
#pragma warning disable CS8500
|
||||
fixed( void* bufferPtr = bufferSpan )
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void SetBufferVectorData<T>(
|
||||
BufferType bufferType,
|
||||
T[] bufferArray,
|
||||
BufferUsage usage )
|
||||
where T: struct, IVector<T>
|
||||
{
|
||||
int size = bufferArray.Length * Marshal.SizeOf( typeof( T ) );
|
||||
if( bufferArray == null ) {
|
||||
return;
|
||||
}
|
||||
#pragma warning disable CS8500
|
||||
fixed( void* bufferPtr = bufferArray )
|
||||
#pragma warning restore CS8500
|
||||
{
|
||||
Context.glBufferData(
|
||||
( uint )bufferType, ( IntPtr )size, ( IntPtr )bufferPtr, ( uint )usage );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void SetRenderBufferStorage(
|
||||
RenderBufferInternalFormat internalFormat,
|
||||
(int width, int height) size )
|
||||
{
|
||||
Context.glRenderbufferStorage(
|
||||
glConst.RENDERBUFFER, ( uint )internalFormat, size.width, size.height );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe void SetRenderBufferStorage(
|
||||
RenderBufferInternalFormat internalFormat,
|
||||
(uint width, uint height) size )
|
||||
{
|
||||
Context.glRenderbufferStorage(
|
||||
glConst.RENDERBUFFER, ( uint )internalFormat, ( int )size.width,
|
||||
( int )size.height );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void SetVertexAttribute(
|
||||
uint index,
|
||||
int size,
|
||||
TypeCode t,
|
||||
bool normalized,
|
||||
uint stride,
|
||||
int pointer )
|
||||
{
|
||||
uint type = InternalIO.GLtype[ t ];
|
||||
Context.glVertexAttribPointer(
|
||||
index, size, type, normalized ? 1 : 0, stride, ( void* )pointer );
|
||||
Context.glEnableVertexAttribArray( index );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void TextureImage2d<T>(
|
||||
Texture2DTarget target,
|
||||
int level,
|
||||
ImageChannel sourceChannel,
|
||||
uint width,
|
||||
uint height,
|
||||
ImageChannel targetChannel,
|
||||
PixelChannelLayout type,
|
||||
T[] pixels )
|
||||
where T: struct, INumber<T>
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
fixed( T* tptr = pixels )
|
||||
{
|
||||
T* ptr = ( ( pixels == null ) || ( pixels.Length == 0 ) ) ? ( T* )IntPtr.Zero : tptr;
|
||||
Context.glTexImage2D(
|
||||
( uint )target, level, ( uint )sourceChannel, width, height, 0,
|
||||
( uint )targetChannel, ( uint )type, tptr );
|
||||
}
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void TextureImage2d<T>(
|
||||
Texture2DTarget target,
|
||||
int level,
|
||||
ImageChannel sourceChannel,
|
||||
uint width,
|
||||
uint height,
|
||||
ImageChannel targetChannel,
|
||||
PixelChannelLayout type,
|
||||
Span<T> pixelSpan )
|
||||
where T: struct, INumber<T>
|
||||
{
|
||||
#pragma warning disable CS8500
|
||||
fixed( T* tptr = pixelSpan )
|
||||
{
|
||||
Context.glTexImage2D(
|
||||
( uint )target, level, ( uint )sourceChannel, width, height, 0,
|
||||
( uint )targetChannel, ( uint )type, tptr );
|
||||
}
|
||||
#pragma warning restore CS8500
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void TextureParameter( int target, uint pname, int param )
|
||||
{
|
||||
Context.glTexParameteri( ( uint )target, pname, param );
|
||||
}
|
||||
|
||||
public static bool TryGetFunctionPackage(
|
||||
IntPtr handle,
|
||||
out OpenGLFunction functionPackage )
|
||||
{
|
||||
return contextToGLMap.TryGetValue( handle, out functionPackage );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void UseProgram( GlHandle program )
|
||||
{
|
||||
Context.glUseProgram( program.Value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void VertexAttributeDivisor( uint layoutIndex, uint divisor )
|
||||
{
|
||||
Context.glVertexAttribDivisor( layoutIndex, divisor );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void Viewport( int x, int y, uint width, uint height )
|
||||
{
|
||||
Context.glViewport( x, y, width, height );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public void WaitAccomplishment()
|
||||
{
|
||||
Context.glFinish();
|
||||
}
|
||||
|
||||
internal static OpenGLFunction BuildGlFunctionPackage( IntPtr handle )
|
||||
{
|
||||
OpenGLFunction pack;
|
||||
if( contextToGLMap.TryGetValue( handle, out pack ) ) {
|
||||
return pack;
|
||||
}
|
||||
pack = new OpenGLFunction
|
||||
{
|
||||
_context = ( OpenglContext* )handle
|
||||
};
|
||||
contextToGLMap.Add( handle, pack );
|
||||
return pack;
|
||||
}
|
||||
|
||||
~OpenGLFunction()
|
||||
{
|
||||
contextToGLMap.Remove( ContextHandle );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glHalfNV.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
[StructLayout( LayoutKind.Explicit, Size = 16 )]
|
||||
public struct glHalfNV
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] public short binary;
|
||||
|
||||
public glHalfNV( short bin )
|
||||
{
|
||||
binary = bin;
|
||||
}
|
||||
|
||||
public static glHalfNV FromInt16( short x )
|
||||
{
|
||||
return new glHalfNV( x );
|
||||
}
|
||||
|
||||
public static short ToInt16( glHalfNV half )
|
||||
{
|
||||
return half.binary;
|
||||
}
|
||||
|
||||
public static explicit operator glHalfNV( short x )
|
||||
{
|
||||
return new glHalfNV( x );
|
||||
}
|
||||
|
||||
public static explicit operator short( glHalfNV x )
|
||||
{
|
||||
return x.binary;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glHandle.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
[StructLayout( LayoutKind.Explicit, Size = 4 )]
|
||||
public struct GlHandle
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] internal int SignedValue;
|
||||
[FieldOffset( 0 )] internal uint Value;
|
||||
|
||||
public static GlHandle Zero
|
||||
{
|
||||
get => new GlHandle
|
||||
{
|
||||
Value = 0
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static GlHandle Alloc( uint value )
|
||||
{
|
||||
return new GlHandle
|
||||
{
|
||||
Value = value
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static GlHandle SignedAlloc( int value )
|
||||
{
|
||||
return new GlHandle
|
||||
{
|
||||
SignedValue = value
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glRenderObjectGenrator.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class glRender
|
||||
{
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected AutoTextureGL CreateAutoTexture( int count )
|
||||
{
|
||||
return new AutoTextureGL( count, this );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="ElementBuffer" />.
|
||||
/// </summary>
|
||||
/// <param _label="count">
|
||||
/// Amount of EBO to be created.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected ElementBuffer CreateElementBuffer( int count )
|
||||
{
|
||||
return new ElementBuffer( count, this );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected FrameBuffer CreateFrameBuffer( int count )
|
||||
{
|
||||
return new FrameBuffer( count, this );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected RenderBuffer CreateRenderBuffer( int count )
|
||||
{
|
||||
return new RenderBuffer( count, this );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a sets of <see cref="TextureGL" />
|
||||
/// </summary>
|
||||
/// <param _label="count">
|
||||
/// Amount of textures to be created.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected TextureGL CreateTexture( int count )
|
||||
{
|
||||
return new TextureGL( count, this );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="VertexArray" />.
|
||||
/// </summary>
|
||||
/// <param _label="count">
|
||||
/// Amount of VAO to be created.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected VertexArray CreateVertexArray( int count )
|
||||
{
|
||||
return new VertexArray( count, this );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a set of <see cref="VertexBuffer" />.
|
||||
/// </summary>
|
||||
/// <param _label="count">
|
||||
/// Amount of Object to be created.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected VertexBuffer CreateVertexBuffer( int count )
|
||||
{
|
||||
return new VertexBuffer( count, this );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glRenderThreadSecurity"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class glRender
|
||||
{
|
||||
|
||||
private static ConcurrentDictionary<Thread, glRender> threadLocalIndex
|
||||
= new();
|
||||
private readonly SynchronizationContext mainThreadContext = SynchronizationContext.Current;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glRenderStream.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
using StgSharp.Threading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public abstract partial class glRender : RenderStream
|
||||
{
|
||||
|
||||
private protected static readonly ConcurrentDictionary<glRender, Thread> renderToThread
|
||||
= new ConcurrentDictionary<glRender, Thread>();
|
||||
|
||||
private OpenGLFunction _context;
|
||||
|
||||
protected internal OpenGLFunction GL
|
||||
{
|
||||
get { return _context; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize an opengl context and load all opengl functions.
|
||||
/// </summary>
|
||||
public unsafe void InitializeContext()
|
||||
{
|
||||
if( ContextHandle == default )
|
||||
{
|
||||
ContextHandle = Marshal.AllocHGlobal( Marshal.SizeOf( typeof( OpenglContext ) ) );
|
||||
OpenglContext* contextID = ( OpenglContext* )ContextHandle;
|
||||
contextID->glGetString = ( delegate*<uint, IntPtr> )IntPtr.Zero;
|
||||
}
|
||||
if( GL == null ) {
|
||||
_context = OpenGLFunction.BuildGlFunctionPackage( ContextHandle );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize an OpenGl viewPortDisplay if current form has not been binded to any
|
||||
/// viewPortDisplay. and set the viewPortDisplay binded to current form as current OpenGL
|
||||
/// viewPortDisplay.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">
|
||||
/// Something goes wrong and World fails in creating a new OpenGL viewPortDisplay.
|
||||
/// </exception>
|
||||
public unsafe void MakeAsCurrentContext()
|
||||
{
|
||||
InternalIO.glfwMakeContextCurrent( CanvasHandle );
|
||||
OpenGLFunction.CurrentGL = this.GL;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void RenderEnd()
|
||||
{
|
||||
if( !renderToThread.TryGetValue( this, out Thread t ) || t != Thread.CurrentThread ) {
|
||||
throw new InvalidOperationException(
|
||||
$"Current render has had been binded to thread {t!.ManagedThreadId}" );
|
||||
}
|
||||
SwapBuffers();
|
||||
renderToThread[ this ] = ThreadHelper.EmptyThread;
|
||||
InternalIO.glfwMakeContextCurrent( IntPtr.Zero );
|
||||
OpenGLFunction.CurrentGL = null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void RenderStart()
|
||||
{
|
||||
Thread current = Thread.CurrentThread;
|
||||
if( !renderToThread.TryGetValue( this, out Thread t ) || t == ThreadHelper.EmptyThread )
|
||||
{
|
||||
renderToThread[ this ] = current;
|
||||
MakeAsCurrentContext();
|
||||
return;
|
||||
}
|
||||
if( t != current ) {
|
||||
throw new InvalidOperationException(
|
||||
$"Current render has had been binded to thread {t!.ManagedThreadId}" );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public override void SetSizeLimit(
|
||||
int minWidth,
|
||||
int minHeight,
|
||||
int maxWidth,
|
||||
int maxHeight )
|
||||
{
|
||||
InternalIO.glfwSetWindowSizeLimits(
|
||||
this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal override sealed void PlatformSpecifiedInitialize()
|
||||
{
|
||||
InitializeContext();
|
||||
MakeAsCurrentContext();
|
||||
glManager.LoadOpenGLApiTo( BindedViewPortContext.GraphicHandle );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal override sealed void Terminate()
|
||||
{
|
||||
CustomizeDeinit();
|
||||
}
|
||||
|
||||
protected override sealed Uniform<Matrix44> NativeCameraUniform(
|
||||
ShaderProgram source,
|
||||
string name )
|
||||
{
|
||||
NativeCamera.GainAllUniforms( source, name );
|
||||
return NativeCamera.convertedUniform;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected override sealed void NativeCameraViewRange(
|
||||
Radius fieldOfRange,
|
||||
Vec2 offset,
|
||||
(float frontDepth, float backDepth) viewDepth )
|
||||
{
|
||||
NativeCamera.SetViewRange( fieldOfRange, this.Size, offset, viewDepth );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
protected override sealed void NativeCameraViewTarget(
|
||||
Vec3 position,
|
||||
Vec3 direction,
|
||||
Vec3 up )
|
||||
{
|
||||
NativeCamera.SetViewDirection( position, direction, up );
|
||||
}
|
||||
|
||||
#region Key Control
|
||||
|
||||
protected KeyStatus CheckKey( KeyboardKey key )
|
||||
{
|
||||
return InternalIO.glfwGetKey( this.CanvasHandle, ( int )key );
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey( Mouse key )
|
||||
{
|
||||
return InternalIO.glfwGetKey( this.CanvasHandle, ( int )key );
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey( Joystick key )
|
||||
{
|
||||
return InternalIO.glfwGetKey( this.CanvasHandle, ( int )key );
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glRenderThreadSecurity.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class glRender
|
||||
{
|
||||
|
||||
private static ConcurrentDictionary<Thread, glRender> threadLocalIndex
|
||||
= new ConcurrentDictionary<Thread, glRender>();
|
||||
private readonly SynchronizationContext mainThreadContext = SynchronizationContext.Current;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="glType.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal.OpenGL
|
||||
{
|
||||
internal delegate void GLVULKANPROCNV();
|
||||
|
||||
public unsafe struct glHandleARB
|
||||
{
|
||||
|
||||
private dynamic value;
|
||||
|
||||
public unsafe glHandleARB( dynamic value )
|
||||
{
|
||||
if( !RuntimeInformation.IsOSPlatform( OSPlatform.OSX ) )
|
||||
{
|
||||
if( value.GetType().Name != "Uint32" )
|
||||
{
|
||||
goto errorlog;
|
||||
}
|
||||
this.value = value;
|
||||
} else
|
||||
{
|
||||
if( value.GetType().Name != "IntPtr" )
|
||||
{
|
||||
goto errorlog;
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
errorlog:
|
||||
{
|
||||
InternalIO.InternalWriteLog(
|
||||
$"{value.GetType().Name} does not match definination of GLhandlARB on OS {Environment.OSVersion.Platform} ",
|
||||
LogType.Error );
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator uint( glHandleARB value )
|
||||
{
|
||||
return ( uint )value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user