HLSF use long as aloloc size
This commit is contained in:
@@ -1,40 +1,40 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IImageProvider"
|
||||
// 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.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IImageProvider
|
||||
{
|
||||
|
||||
Image ProvideImage();
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IImageProvider"
|
||||
// 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.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IImageProvider
|
||||
{
|
||||
|
||||
Image ProvideImage();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ImageHelper"
|
||||
// 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.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class ImageHelper
|
||||
{
|
||||
|
||||
public static void Resize(Image i, int width, int height, ImageMovement move)
|
||||
{
|
||||
if (i == null) {
|
||||
throw new ArgumentNullException(nameof(i));
|
||||
}
|
||||
if (i.Size == (width, height)) {
|
||||
return;
|
||||
}
|
||||
if (!Enum.IsDefined(typeof(ImageMovement), move)) {
|
||||
throw new InvalidEnumArgumentException(nameof(move));
|
||||
}
|
||||
byte[] oldData = i.Data;
|
||||
i.Data = new byte[width * height * i.PixelSize];
|
||||
i.Height = height;
|
||||
i.Width = width;
|
||||
i.PixelUpdateCount++;
|
||||
switch (move)
|
||||
{
|
||||
case ImageMovement.Discard:
|
||||
break;
|
||||
case ImageMovement.Top:
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ImageMovement
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
Discard = 0,
|
||||
#pragma warning restore CA1008
|
||||
Top = 1,
|
||||
Bottom = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
TopLeft = Top | Left,
|
||||
BottomLeft = Bottom | Left,
|
||||
TopRight = Top | Right,
|
||||
BottomRight = Bottom | Right,
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ImageHelper"
|
||||
// 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.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class ImageHelper
|
||||
{
|
||||
|
||||
public static void Resize(Image i, int width, int height, ImageMovement move)
|
||||
{
|
||||
if (i == null) {
|
||||
throw new ArgumentNullException(nameof(i));
|
||||
}
|
||||
if (i.Size == (width, height)) {
|
||||
return;
|
||||
}
|
||||
if (!Enum.IsDefined(typeof(ImageMovement), move)) {
|
||||
throw new InvalidEnumArgumentException(nameof(move));
|
||||
}
|
||||
byte[] oldData = i.Data;
|
||||
i.Data = new byte[width * height * i.PixelSize];
|
||||
i.Height = height;
|
||||
i.Width = width;
|
||||
i.PixelUpdateCount++;
|
||||
switch (move)
|
||||
{
|
||||
case ImageMovement.Discard:
|
||||
break;
|
||||
case ImageMovement.Top:
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ImageMovement
|
||||
{
|
||||
#pragma warning disable CA1008
|
||||
Discard = 0,
|
||||
#pragma warning restore CA1008
|
||||
Top = 1,
|
||||
Bottom = 2,
|
||||
Left = 4,
|
||||
Right = 8,
|
||||
TopLeft = Top | Left,
|
||||
BottomLeft = Bottom | Left,
|
||||
TopRight = Top | Right,
|
||||
BottomRight = Bottom | Right,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="BufferObjectBase"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL BufferHandle objects
|
||||
/// </summary>
|
||||
public abstract class BufferObjectBase : IDisposable
|
||||
{
|
||||
|
||||
protected GlHandle[] _bufferHandle;
|
||||
protected RenderStream binding;
|
||||
|
||||
/// <summary>
|
||||
/// Get the only handle to one of the Object instance
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public GlHandle this[int index] => _bufferHandle[index];
|
||||
|
||||
/// <summary>
|
||||
/// Bind a BufferHandle instance to OpenGL
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
/// Index of handle of the object in this instance to be bind
|
||||
/// </param>
|
||||
public abstract void Bind(int index);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}.";
|
||||
}
|
||||
|
||||
protected abstract void Dispose(bool disposing);
|
||||
|
||||
~BufferObjectBase()
|
||||
{
|
||||
Dispose(disposing:false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="BufferObjectBase"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface of all kinds OpenGL BufferHandle objects
|
||||
/// </summary>
|
||||
public abstract class BufferObjectBase : IDisposable
|
||||
{
|
||||
|
||||
protected GlHandle[] _bufferHandle;
|
||||
protected RenderStream binding;
|
||||
|
||||
/// <summary>
|
||||
/// Get the only handle to one of the Object instance
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public GlHandle this[int index] => _bufferHandle[index];
|
||||
|
||||
/// <summary>
|
||||
/// Bind a BufferHandle instance to OpenGL
|
||||
/// </summary>
|
||||
/// <param _label="index">
|
||||
/// Index of handle of the object in this instance to be bind
|
||||
/// </param>
|
||||
public abstract void Bind(int index);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing:true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"This is a {GetType().FullName}, containing {_bufferHandle.Length} buffer handles: {_bufferHandle.ToString()}.";
|
||||
}
|
||||
|
||||
protected abstract void Dispose(bool disposing);
|
||||
|
||||
~BufferObjectBase()
|
||||
{
|
||||
Dispose(disposing:false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,336 +1,336 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="FrameworkConstant"
|
||||
// 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.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class FrameworkConstant
|
||||
{
|
||||
|
||||
#region glfw
|
||||
|
||||
public const int VERSION_MAJOR = 3;
|
||||
public const int VERSION_MINOR = 3;
|
||||
public const int VERSION_REVISION = 8;
|
||||
public const int TRUE = 1;
|
||||
public const int FALSE = 0;
|
||||
public const int RELEASE = 0;
|
||||
public const int PRESS = 1;
|
||||
public const int REPEAT = 2;
|
||||
public const int HAT_CENTERED = 0;
|
||||
public const int HAT_UP = 1;
|
||||
public const int HAT_RIGHT = 2;
|
||||
public const int HAT_DOWN = 4;
|
||||
public const int HAT_LEFT = 8;
|
||||
public const int HAT_RIGHT_UP = HAT_RIGHT | HAT_UP;
|
||||
public const int HAT_RIGHT_DOWN = HAT_RIGHT | HAT_DOWN;
|
||||
public const int HAT_LEFT_UP = HAT_LEFT | HAT_UP;
|
||||
public const int HAT_LEFT_DOWN = HAT_LEFT | HAT_DOWN;
|
||||
public const int KEY_UNKNOWN = -1;
|
||||
public const int KEY_SPACE = 32;
|
||||
public const int KEY_APOSTROPHE = 39;
|
||||
public const int KEY_COMMA = 44;
|
||||
public const int KEY_MINUS = 45;
|
||||
public const int KEY_PERIOD = 46;
|
||||
public const int KEY_SLASH = 47;
|
||||
public const int KEY_0 = 48;
|
||||
public const int KEY_1 = 49;
|
||||
public const int KEY_2 = 50;
|
||||
public const int KEY_3 = 51;
|
||||
public const int KEY_4 = 52;
|
||||
public const int KEY_5 = 53;
|
||||
public const int KEY_6 = 54;
|
||||
public const int KEY_7 = 55;
|
||||
public const int KEY_8 = 56;
|
||||
public const int KEY_9 = 57;
|
||||
public const int KEY_SEMICOLON = 59;
|
||||
public const int KEY_EQUAL = 61;
|
||||
public const int KEY_A = 65;
|
||||
public const int KEY_B = 66;
|
||||
public const int KEY_C = 67;
|
||||
public const int KEY_D = 68;
|
||||
public const int KEY_E = 69;
|
||||
public const int KEY_F = 70;
|
||||
public const int KEY_G = 71;
|
||||
public const int KEY_H = 72;
|
||||
public const int KEY_I = 73;
|
||||
public const int KEY_J = 74;
|
||||
public const int KEY_K = 75;
|
||||
public const int KEY_L = 76;
|
||||
public const int KEY_M = 77;
|
||||
public const int KEY_N = 78;
|
||||
public const int KEY_O = 79;
|
||||
public const int KEY_P = 80;
|
||||
public const int KEY_Q = 81;
|
||||
public const int KEY_R = 82;
|
||||
public const int KEY_S = 83;
|
||||
public const int KEY_T = 84;
|
||||
public const int KEY_U = 85;
|
||||
public const int KEY_V = 86;
|
||||
public const int KEY_W = 87;
|
||||
public const int KEY_X = 88;
|
||||
public const int KEY_Y = 89;
|
||||
public const int KEY_Z = 90;
|
||||
public const int KEY_LEFT_BRACKET = 91;
|
||||
public const int KEY_BACKSLASH = 92;
|
||||
public const int KEY_RIGHT_BRACKET = 93;
|
||||
public const int KEY_GRAVE_ACCENT = 96;
|
||||
public const int KEY_WORLD_1 = 161;
|
||||
public const int KEY_WORLD_2 = 162;
|
||||
public const int KEY_ESCAPE = 256;
|
||||
public const int KEY_ENTER = 257;
|
||||
public const int KEY_TAB = 258;
|
||||
public const int KEY_BACKSPACE = 259;
|
||||
public const int KEY_INSERT = 260;
|
||||
public const int KEY_DELETE = 261;
|
||||
public const int KEY_RIGHT = 262;
|
||||
public const int KEY_LEFT = 263;
|
||||
public const int KEY_DOWN = 264;
|
||||
public const int KEY_UP = 265;
|
||||
public const int KEY_PAGE_UP = 266;
|
||||
public const int KEY_PAGE_DOWN = 267;
|
||||
public const int KEY_HOME = 268;
|
||||
public const int KEY_END = 269;
|
||||
public const int KEY_CAPS_LOCK = 280;
|
||||
public const int KEY_SCROLL_LOCK = 281;
|
||||
public const int KEY_NUM_LOCK = 282;
|
||||
public const int KEY_PRINT_SCREEN = 283;
|
||||
public const int KEY_PAUSE = 284;
|
||||
public const int KEY_F1 = 290;
|
||||
public const int KEY_F2 = 291;
|
||||
public const int KEY_F3 = 292;
|
||||
public const int KEY_F4 = 293;
|
||||
public const int KEY_F5 = 294;
|
||||
public const int KEY_F6 = 295;
|
||||
public const int KEY_F7 = 296;
|
||||
public const int KEY_F8 = 297;
|
||||
public const int KEY_F9 = 298;
|
||||
public const int KEY_F10 = 299;
|
||||
public const int KEY_F11 = 300;
|
||||
public const int KEY_F12 = 301;
|
||||
public const int KEY_F13 = 302;
|
||||
public const int KEY_F14 = 303;
|
||||
public const int KEY_F15 = 304;
|
||||
public const int KEY_F16 = 305;
|
||||
public const int KEY_F17 = 306;
|
||||
public const int KEY_F18 = 307;
|
||||
public const int KEY_F19 = 308;
|
||||
public const int KEY_F20 = 309;
|
||||
public const int KEY_F21 = 310;
|
||||
public const int KEY_F22 = 311;
|
||||
public const int KEY_F23 = 312;
|
||||
public const int KEY_F24 = 313;
|
||||
public const int KEY_F25 = 314;
|
||||
public const int KEY_KP_0 = 320;
|
||||
public const int KEY_KP_1 = 321;
|
||||
public const int KEY_KP_2 = 322;
|
||||
public const int KEY_KP_3 = 323;
|
||||
public const int KEY_KP_4 = 324;
|
||||
public const int KEY_KP_5 = 325;
|
||||
public const int KEY_KP_6 = 326;
|
||||
public const int KEY_KP_7 = 327;
|
||||
public const int KEY_KP_8 = 328;
|
||||
public const int KEY_KP_9 = 329;
|
||||
public const int KEY_KP_DECIMAL = 330;
|
||||
public const int KEY_KP_DIVIDE = 331;
|
||||
public const int KEY_KP_MULTIPLY = 332;
|
||||
public const int KEY_KP_SUBTRACT = 333;
|
||||
public const int KEY_KP_ADD = 334;
|
||||
public const int KEY_KP_ENTER = 335;
|
||||
public const int KEY_KP_EQUAL = 336;
|
||||
public const int KEY_LEFT_SHIFT = 340;
|
||||
public const int KEY_LEFT_CONTROL = 341;
|
||||
public const int KEY_LEFT_ALT = 342;
|
||||
public const int KEY_LEFT_SUPER = 343;
|
||||
public const int KEY_RIGHT_SHIFT = 344;
|
||||
public const int KEY_RIGHT_CONTROL = 345;
|
||||
public const int KEY_RIGHT_ALT = 346;
|
||||
public const int KEY_RIGHT_SUPER = 347;
|
||||
public const int KEY_MENU = 348;
|
||||
public const int KEY_LAST = KEY_MENU;
|
||||
public const int MOD_SHIFT = 0x0001;
|
||||
public const int MOD_CONTROL = 0x0002;
|
||||
public const int MOD_ALT = 0x0004;
|
||||
public const int MOD_SUPER = 0x0008;
|
||||
public const int MOD_CAPS_LOCK = 0x0010;
|
||||
public const int MOD_NUM_LOCK = 0x0020;
|
||||
public const int MOUSE_BUTTON_1 = 0;
|
||||
public const int MOUSE_BUTTON_2 = 1;
|
||||
public const int MOUSE_BUTTON_3 = 2;
|
||||
public const int MOUSE_BUTTON_4 = 3;
|
||||
public const int MOUSE_BUTTON_5 = 4;
|
||||
public const int MOUSE_BUTTON_6 = 5;
|
||||
public const int MOUSE_BUTTON_7 = 6;
|
||||
public const int MOUSE_BUTTON_8 = 7;
|
||||
public const int MOUSE_BUTTON_LAST = MOUSE_BUTTON_8;
|
||||
public const int MOUSE_BUTTON_LEFT = MOUSE_BUTTON_1;
|
||||
public const int MOUSE_BUTTON_RIGHT = MOUSE_BUTTON_2;
|
||||
public const int MOUSE_BUTTON_MIDDLE = MOUSE_BUTTON_3;
|
||||
public const int JOYSTICK_1 = 0;
|
||||
public const int JOYSTICK_2 = 1;
|
||||
public const int JOYSTICK_3 = 2;
|
||||
public const int JOYSTICK_4 = 3;
|
||||
public const int JOYSTICK_5 = 4;
|
||||
public const int JOYSTICK_6 = 5;
|
||||
public const int JOYSTICK_7 = 6;
|
||||
public const int JOYSTICK_8 = 7;
|
||||
public const int JOYSTICK_9 = 8;
|
||||
public const int JOYSTICK_10 = 9;
|
||||
public const int JOYSTICK_11 = 10;
|
||||
public const int JOYSTICK_12 = 11;
|
||||
public const int JOYSTICK_13 = 12;
|
||||
public const int JOYSTICK_14 = 13;
|
||||
public const int JOYSTICK_15 = 14;
|
||||
public const int JOYSTICK_16 = 15;
|
||||
public const int JOYSTICK_LAST = JOYSTICK_16;
|
||||
public const int GAMEPAD_BUTTON_A = 0;
|
||||
public const int GAMEPAD_BUTTON_B = 1;
|
||||
public const int GAMEPAD_BUTTON_X = 2;
|
||||
public const int GAMEPAD_BUTTON_Y = 3;
|
||||
public const int GAMEPAD_BUTTON_LEFT_BUMPER = 4;
|
||||
public const int GAMEPAD_BUTTON_RIGHT_BUMPER = 5;
|
||||
public const int GAMEPAD_BUTTON_BACK = 6;
|
||||
public const int GAMEPAD_BUTTON_START = 7;
|
||||
public const int GAMEPAD_BUTTON_GUIDE = 8;
|
||||
public const int GAMEPAD_BUTTON_LEFT_THUMB = 9;
|
||||
public const int GAMEPAD_BUTTON_RIGHT_THUMB = 10;
|
||||
public const int GAMEPAD_BUTTON_DPAD_UP = 11;
|
||||
public const int GAMEPAD_BUTTON_DPAD_RIGHT = 12;
|
||||
public const int GAMEPAD_BUTTON_DPAD_DOWN = 13;
|
||||
public const int GAMEPAD_BUTTON_DPAD_LEFT = 14;
|
||||
public const int GAMEPAD_BUTTON_LAST = GAMEPAD_BUTTON_DPAD_LEFT;
|
||||
public const int GAMEPAD_BUTTON_CROSS = GAMEPAD_BUTTON_A;
|
||||
public const int GAMEPAD_BUTTON_CIRCLE = GAMEPAD_BUTTON_B;
|
||||
public const int GAMEPAD_BUTTON_SQUARE = GAMEPAD_BUTTON_X;
|
||||
public const int GAMEPAD_BUTTON_TRIANGLE = GAMEPAD_BUTTON_Y;
|
||||
public const int GAMEPAD_AXIS_LEFT_X = 0;
|
||||
public const int GAMEPAD_AXIS_LEFT_Y = 1;
|
||||
public const int GAMEPAD_AXIS_RIGHT_X = 2;
|
||||
public const int GAMEPAD_AXIS_RIGHT_Y = 3;
|
||||
public const int GAMEPAD_AXIS_LEFT_TRIGGER = 4;
|
||||
public const int GAMEPAD_AXIS_RIGHT_TRIGGER = 5;
|
||||
public const int GAMEPAD_AXIS_LAST = GAMEPAD_AXIS_RIGHT_TRIGGER;
|
||||
public const int NO_ERROR = 0;
|
||||
public const int NOT_INITIALIZED = 0x00010001;
|
||||
public const int NO_CURRENT_CONTEXT = 0x00010002;
|
||||
public const int INVALID_ENUM = 0x00010003;
|
||||
public const int INVALID_VALUE = 0x00010004;
|
||||
public const int OUT_OF_MEMORY = 0x00010005;
|
||||
public const int API_UNAVAILABLE = 0x00010006;
|
||||
public const int VERSION_UNAVAILABLE = 0x00010007;
|
||||
public const int PLATFORM_ERROR = 0x00010008;
|
||||
public const int FORMAT_UNAVAILABLE = 0x00010009;
|
||||
public const int NO_WINDOW_CONTEXT = 0x0001000A;
|
||||
public const int FOCUSED = 0x00020001;
|
||||
public const int ICONIFIED = 0x00020002;
|
||||
public const int RESIZABLE = 0x00020003;
|
||||
public const int VISIBLE = 0x00020004;
|
||||
public const int DECORATED = 0x00020005;
|
||||
public const int AUTO_ICONIFY = 0x00020006;
|
||||
public const int FLOATING = 0x00020007;
|
||||
public const int MAXIMIZED = 0x00020008;
|
||||
public const int CENTER_CURSOR = 0x00020009;
|
||||
public const int TRANSPARENT_FRAMEBUFFER = 0x0002000A;
|
||||
public const int HOVERED = 0x0002000B;
|
||||
public const int FOCUS_ON_SHOW = 0x0002000C;
|
||||
public const int RED_BITS = 0x00021001;
|
||||
public const int GREEN_BITS = 0x00021002;
|
||||
public const int BLUE_BITS = 0x00021003;
|
||||
public const int ALPHA_BITS = 0x00021004;
|
||||
public const int DEPTH_BITS = 0x00021005;
|
||||
public const int STENCIL_BITS = 0x00021006;
|
||||
public const int ACCUM_RED_BITS = 0x00021007;
|
||||
public const int ACCUM_GREEN_BITS = 0x00021008;
|
||||
public const int ACCUM_BLUE_BITS = 0x00021009;
|
||||
public const int ACCUM_ALPHA_BITS = 0x0002100A;
|
||||
public const int AUX_BUFFERS = 0x0002100B;
|
||||
public const int STEREO = 0x0002100C;
|
||||
public const int SAMPLES = 0x0002100D;
|
||||
public const int SRGB_CAPABLE = 0x0002100E;
|
||||
public const int REFRESH_RATE = 0x0002100F;
|
||||
public const int DOUBLEBUFFER = 0x00021010;
|
||||
public const int CLIENT_API = 0x00022001;
|
||||
public const int CONTEXT_VERSION_MAJOR = 0x00022002;
|
||||
public const int CONTEXT_VERSION_MINOR = 0x00022003;
|
||||
public const int CONTEXT_REVISION = 0x00022004;
|
||||
public const int CONTEXT_ROBUSTNESS = 0x00022005;
|
||||
public const int OPENGL_FORWARD_COMPAT = 0x00022006;
|
||||
public const int OPENGL_DEBUG_CONTEXT = 0x00022007;
|
||||
public const int OPENGL_PROFILE = 0x00022008;
|
||||
public const int CONTEXT_RELEASE_BEHAVIOR = 0x00022009;
|
||||
public const int CONTEXT_NO_ERROR = 0x0002200A;
|
||||
public const int CONTEXT_CREATION_API = 0x0002200B;
|
||||
public const int SCALE_TO_MONITOR = 0x0002200C;
|
||||
public const int COCOA_RETINA_FRAMEBUFFER = 0x00023001;
|
||||
public const int COCOA_FRAME_NAME = 0x00023002;
|
||||
public const int COCOA_GRAPHICS_SWITCHING = 0x00023003;
|
||||
public const int X11_CLASS_NAME = 0x00024001;
|
||||
public const int X11_INSTANCE_NAME = 0x00024002;
|
||||
public const int NO_API = 0;
|
||||
public const int OPENGL_API = 0x00030001;
|
||||
public const int OPENGL_ES_API = 0x00030002;
|
||||
public const int NO_ROBUSTNESS = 0;
|
||||
public const int NO_RESET_NOTIFICATION = 0x00031001;
|
||||
public const int LOSE_CONTEXT_ON_RESET = 0x00031002;
|
||||
public const int OPENGL_ANY_PROFILE = 0;
|
||||
public const int OPENGL_CORE_PROFILE = 0x00032001;
|
||||
public const int OPENGL_COMPAT_PROFILE = 0x00032002;
|
||||
public const int CURSOR = 0x00033001;
|
||||
public const int STICKY_KEYS = 0x00033002;
|
||||
public const int STICKY_MOUSE_BUTTONS = 0x00033003;
|
||||
public const int LOCK_KEY_MODS = 0x00033004;
|
||||
public const int RAW_MOUSE_MOTION = 0x00033005;
|
||||
public const int CURSOR_NORMAL = 0x00034001;
|
||||
public const int CURSOR_HIDDEN = 0x00034002;
|
||||
public const int CURSOR_DISABLED = 0x00034003;
|
||||
public const int ANY_RELEASE_BEHAVIOR = 0;
|
||||
public const int RELEASE_BEHAVIOR_FLUSH = 0x00035001;
|
||||
public const int RELEASE_BEHAVIOR_NONE = 0x00035002;
|
||||
public const int NATIVE_CONTEXT_API = 0x00036001;
|
||||
public const int EGL_CONTEXT_API = 0x00036002;
|
||||
public const int OSMESA_CONTEXT_API = 0x00036003;
|
||||
public const int ARROW_CURSOR = 0x00036001;
|
||||
public const int IBEAM_CURSOR = 0x00036002;
|
||||
public const int CROSSHAIR_CURSOR = 0x00036003;
|
||||
public const int HAND_CURSOR = 0x00036004;
|
||||
public const int HRESIZE_CURSOR = 0x00036005;
|
||||
public const int VRESIZE_CURSOR = 0x00036006;
|
||||
public const int CONNECTED = 0x00040001;
|
||||
public const int DISCONNECTED = 0x00040002;
|
||||
public const int JOYSTICK_HAT_BUTTONS = 0x00050001;
|
||||
public const int COCOA_CHDIR_RESOURCES = 0x00051001;
|
||||
public const int COCOA_MENUBAR = 0x00051002;
|
||||
public const int DONT_CARE = -1;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="FrameworkConstant"
|
||||
// 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.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public static class FrameworkConstant
|
||||
{
|
||||
|
||||
#region glfw
|
||||
|
||||
public const int VERSION_MAJOR = 3;
|
||||
public const int VERSION_MINOR = 3;
|
||||
public const int VERSION_REVISION = 8;
|
||||
public const int TRUE = 1;
|
||||
public const int FALSE = 0;
|
||||
public const int RELEASE = 0;
|
||||
public const int PRESS = 1;
|
||||
public const int REPEAT = 2;
|
||||
public const int HAT_CENTERED = 0;
|
||||
public const int HAT_UP = 1;
|
||||
public const int HAT_RIGHT = 2;
|
||||
public const int HAT_DOWN = 4;
|
||||
public const int HAT_LEFT = 8;
|
||||
public const int HAT_RIGHT_UP = HAT_RIGHT | HAT_UP;
|
||||
public const int HAT_RIGHT_DOWN = HAT_RIGHT | HAT_DOWN;
|
||||
public const int HAT_LEFT_UP = HAT_LEFT | HAT_UP;
|
||||
public const int HAT_LEFT_DOWN = HAT_LEFT | HAT_DOWN;
|
||||
public const int KEY_UNKNOWN = -1;
|
||||
public const int KEY_SPACE = 32;
|
||||
public const int KEY_APOSTROPHE = 39;
|
||||
public const int KEY_COMMA = 44;
|
||||
public const int KEY_MINUS = 45;
|
||||
public const int KEY_PERIOD = 46;
|
||||
public const int KEY_SLASH = 47;
|
||||
public const int KEY_0 = 48;
|
||||
public const int KEY_1 = 49;
|
||||
public const int KEY_2 = 50;
|
||||
public const int KEY_3 = 51;
|
||||
public const int KEY_4 = 52;
|
||||
public const int KEY_5 = 53;
|
||||
public const int KEY_6 = 54;
|
||||
public const int KEY_7 = 55;
|
||||
public const int KEY_8 = 56;
|
||||
public const int KEY_9 = 57;
|
||||
public const int KEY_SEMICOLON = 59;
|
||||
public const int KEY_EQUAL = 61;
|
||||
public const int KEY_A = 65;
|
||||
public const int KEY_B = 66;
|
||||
public const int KEY_C = 67;
|
||||
public const int KEY_D = 68;
|
||||
public const int KEY_E = 69;
|
||||
public const int KEY_F = 70;
|
||||
public const int KEY_G = 71;
|
||||
public const int KEY_H = 72;
|
||||
public const int KEY_I = 73;
|
||||
public const int KEY_J = 74;
|
||||
public const int KEY_K = 75;
|
||||
public const int KEY_L = 76;
|
||||
public const int KEY_M = 77;
|
||||
public const int KEY_N = 78;
|
||||
public const int KEY_O = 79;
|
||||
public const int KEY_P = 80;
|
||||
public const int KEY_Q = 81;
|
||||
public const int KEY_R = 82;
|
||||
public const int KEY_S = 83;
|
||||
public const int KEY_T = 84;
|
||||
public const int KEY_U = 85;
|
||||
public const int KEY_V = 86;
|
||||
public const int KEY_W = 87;
|
||||
public const int KEY_X = 88;
|
||||
public const int KEY_Y = 89;
|
||||
public const int KEY_Z = 90;
|
||||
public const int KEY_LEFT_BRACKET = 91;
|
||||
public const int KEY_BACKSLASH = 92;
|
||||
public const int KEY_RIGHT_BRACKET = 93;
|
||||
public const int KEY_GRAVE_ACCENT = 96;
|
||||
public const int KEY_WORLD_1 = 161;
|
||||
public const int KEY_WORLD_2 = 162;
|
||||
public const int KEY_ESCAPE = 256;
|
||||
public const int KEY_ENTER = 257;
|
||||
public const int KEY_TAB = 258;
|
||||
public const int KEY_BACKSPACE = 259;
|
||||
public const int KEY_INSERT = 260;
|
||||
public const int KEY_DELETE = 261;
|
||||
public const int KEY_RIGHT = 262;
|
||||
public const int KEY_LEFT = 263;
|
||||
public const int KEY_DOWN = 264;
|
||||
public const int KEY_UP = 265;
|
||||
public const int KEY_PAGE_UP = 266;
|
||||
public const int KEY_PAGE_DOWN = 267;
|
||||
public const int KEY_HOME = 268;
|
||||
public const int KEY_END = 269;
|
||||
public const int KEY_CAPS_LOCK = 280;
|
||||
public const int KEY_SCROLL_LOCK = 281;
|
||||
public const int KEY_NUM_LOCK = 282;
|
||||
public const int KEY_PRINT_SCREEN = 283;
|
||||
public const int KEY_PAUSE = 284;
|
||||
public const int KEY_F1 = 290;
|
||||
public const int KEY_F2 = 291;
|
||||
public const int KEY_F3 = 292;
|
||||
public const int KEY_F4 = 293;
|
||||
public const int KEY_F5 = 294;
|
||||
public const int KEY_F6 = 295;
|
||||
public const int KEY_F7 = 296;
|
||||
public const int KEY_F8 = 297;
|
||||
public const int KEY_F9 = 298;
|
||||
public const int KEY_F10 = 299;
|
||||
public const int KEY_F11 = 300;
|
||||
public const int KEY_F12 = 301;
|
||||
public const int KEY_F13 = 302;
|
||||
public const int KEY_F14 = 303;
|
||||
public const int KEY_F15 = 304;
|
||||
public const int KEY_F16 = 305;
|
||||
public const int KEY_F17 = 306;
|
||||
public const int KEY_F18 = 307;
|
||||
public const int KEY_F19 = 308;
|
||||
public const int KEY_F20 = 309;
|
||||
public const int KEY_F21 = 310;
|
||||
public const int KEY_F22 = 311;
|
||||
public const int KEY_F23 = 312;
|
||||
public const int KEY_F24 = 313;
|
||||
public const int KEY_F25 = 314;
|
||||
public const int KEY_KP_0 = 320;
|
||||
public const int KEY_KP_1 = 321;
|
||||
public const int KEY_KP_2 = 322;
|
||||
public const int KEY_KP_3 = 323;
|
||||
public const int KEY_KP_4 = 324;
|
||||
public const int KEY_KP_5 = 325;
|
||||
public const int KEY_KP_6 = 326;
|
||||
public const int KEY_KP_7 = 327;
|
||||
public const int KEY_KP_8 = 328;
|
||||
public const int KEY_KP_9 = 329;
|
||||
public const int KEY_KP_DECIMAL = 330;
|
||||
public const int KEY_KP_DIVIDE = 331;
|
||||
public const int KEY_KP_MULTIPLY = 332;
|
||||
public const int KEY_KP_SUBTRACT = 333;
|
||||
public const int KEY_KP_ADD = 334;
|
||||
public const int KEY_KP_ENTER = 335;
|
||||
public const int KEY_KP_EQUAL = 336;
|
||||
public const int KEY_LEFT_SHIFT = 340;
|
||||
public const int KEY_LEFT_CONTROL = 341;
|
||||
public const int KEY_LEFT_ALT = 342;
|
||||
public const int KEY_LEFT_SUPER = 343;
|
||||
public const int KEY_RIGHT_SHIFT = 344;
|
||||
public const int KEY_RIGHT_CONTROL = 345;
|
||||
public const int KEY_RIGHT_ALT = 346;
|
||||
public const int KEY_RIGHT_SUPER = 347;
|
||||
public const int KEY_MENU = 348;
|
||||
public const int KEY_LAST = KEY_MENU;
|
||||
public const int MOD_SHIFT = 0x0001;
|
||||
public const int MOD_CONTROL = 0x0002;
|
||||
public const int MOD_ALT = 0x0004;
|
||||
public const int MOD_SUPER = 0x0008;
|
||||
public const int MOD_CAPS_LOCK = 0x0010;
|
||||
public const int MOD_NUM_LOCK = 0x0020;
|
||||
public const int MOUSE_BUTTON_1 = 0;
|
||||
public const int MOUSE_BUTTON_2 = 1;
|
||||
public const int MOUSE_BUTTON_3 = 2;
|
||||
public const int MOUSE_BUTTON_4 = 3;
|
||||
public const int MOUSE_BUTTON_5 = 4;
|
||||
public const int MOUSE_BUTTON_6 = 5;
|
||||
public const int MOUSE_BUTTON_7 = 6;
|
||||
public const int MOUSE_BUTTON_8 = 7;
|
||||
public const int MOUSE_BUTTON_LAST = MOUSE_BUTTON_8;
|
||||
public const int MOUSE_BUTTON_LEFT = MOUSE_BUTTON_1;
|
||||
public const int MOUSE_BUTTON_RIGHT = MOUSE_BUTTON_2;
|
||||
public const int MOUSE_BUTTON_MIDDLE = MOUSE_BUTTON_3;
|
||||
public const int JOYSTICK_1 = 0;
|
||||
public const int JOYSTICK_2 = 1;
|
||||
public const int JOYSTICK_3 = 2;
|
||||
public const int JOYSTICK_4 = 3;
|
||||
public const int JOYSTICK_5 = 4;
|
||||
public const int JOYSTICK_6 = 5;
|
||||
public const int JOYSTICK_7 = 6;
|
||||
public const int JOYSTICK_8 = 7;
|
||||
public const int JOYSTICK_9 = 8;
|
||||
public const int JOYSTICK_10 = 9;
|
||||
public const int JOYSTICK_11 = 10;
|
||||
public const int JOYSTICK_12 = 11;
|
||||
public const int JOYSTICK_13 = 12;
|
||||
public const int JOYSTICK_14 = 13;
|
||||
public const int JOYSTICK_15 = 14;
|
||||
public const int JOYSTICK_16 = 15;
|
||||
public const int JOYSTICK_LAST = JOYSTICK_16;
|
||||
public const int GAMEPAD_BUTTON_A = 0;
|
||||
public const int GAMEPAD_BUTTON_B = 1;
|
||||
public const int GAMEPAD_BUTTON_X = 2;
|
||||
public const int GAMEPAD_BUTTON_Y = 3;
|
||||
public const int GAMEPAD_BUTTON_LEFT_BUMPER = 4;
|
||||
public const int GAMEPAD_BUTTON_RIGHT_BUMPER = 5;
|
||||
public const int GAMEPAD_BUTTON_BACK = 6;
|
||||
public const int GAMEPAD_BUTTON_START = 7;
|
||||
public const int GAMEPAD_BUTTON_GUIDE = 8;
|
||||
public const int GAMEPAD_BUTTON_LEFT_THUMB = 9;
|
||||
public const int GAMEPAD_BUTTON_RIGHT_THUMB = 10;
|
||||
public const int GAMEPAD_BUTTON_DPAD_UP = 11;
|
||||
public const int GAMEPAD_BUTTON_DPAD_RIGHT = 12;
|
||||
public const int GAMEPAD_BUTTON_DPAD_DOWN = 13;
|
||||
public const int GAMEPAD_BUTTON_DPAD_LEFT = 14;
|
||||
public const int GAMEPAD_BUTTON_LAST = GAMEPAD_BUTTON_DPAD_LEFT;
|
||||
public const int GAMEPAD_BUTTON_CROSS = GAMEPAD_BUTTON_A;
|
||||
public const int GAMEPAD_BUTTON_CIRCLE = GAMEPAD_BUTTON_B;
|
||||
public const int GAMEPAD_BUTTON_SQUARE = GAMEPAD_BUTTON_X;
|
||||
public const int GAMEPAD_BUTTON_TRIANGLE = GAMEPAD_BUTTON_Y;
|
||||
public const int GAMEPAD_AXIS_LEFT_X = 0;
|
||||
public const int GAMEPAD_AXIS_LEFT_Y = 1;
|
||||
public const int GAMEPAD_AXIS_RIGHT_X = 2;
|
||||
public const int GAMEPAD_AXIS_RIGHT_Y = 3;
|
||||
public const int GAMEPAD_AXIS_LEFT_TRIGGER = 4;
|
||||
public const int GAMEPAD_AXIS_RIGHT_TRIGGER = 5;
|
||||
public const int GAMEPAD_AXIS_LAST = GAMEPAD_AXIS_RIGHT_TRIGGER;
|
||||
public const int NO_ERROR = 0;
|
||||
public const int NOT_INITIALIZED = 0x00010001;
|
||||
public const int NO_CURRENT_CONTEXT = 0x00010002;
|
||||
public const int INVALID_ENUM = 0x00010003;
|
||||
public const int INVALID_VALUE = 0x00010004;
|
||||
public const int OUT_OF_MEMORY = 0x00010005;
|
||||
public const int API_UNAVAILABLE = 0x00010006;
|
||||
public const int VERSION_UNAVAILABLE = 0x00010007;
|
||||
public const int PLATFORM_ERROR = 0x00010008;
|
||||
public const int FORMAT_UNAVAILABLE = 0x00010009;
|
||||
public const int NO_WINDOW_CONTEXT = 0x0001000A;
|
||||
public const int FOCUSED = 0x00020001;
|
||||
public const int ICONIFIED = 0x00020002;
|
||||
public const int RESIZABLE = 0x00020003;
|
||||
public const int VISIBLE = 0x00020004;
|
||||
public const int DECORATED = 0x00020005;
|
||||
public const int AUTO_ICONIFY = 0x00020006;
|
||||
public const int FLOATING = 0x00020007;
|
||||
public const int MAXIMIZED = 0x00020008;
|
||||
public const int CENTER_CURSOR = 0x00020009;
|
||||
public const int TRANSPARENT_FRAMEBUFFER = 0x0002000A;
|
||||
public const int HOVERED = 0x0002000B;
|
||||
public const int FOCUS_ON_SHOW = 0x0002000C;
|
||||
public const int RED_BITS = 0x00021001;
|
||||
public const int GREEN_BITS = 0x00021002;
|
||||
public const int BLUE_BITS = 0x00021003;
|
||||
public const int ALPHA_BITS = 0x00021004;
|
||||
public const int DEPTH_BITS = 0x00021005;
|
||||
public const int STENCIL_BITS = 0x00021006;
|
||||
public const int ACCUM_RED_BITS = 0x00021007;
|
||||
public const int ACCUM_GREEN_BITS = 0x00021008;
|
||||
public const int ACCUM_BLUE_BITS = 0x00021009;
|
||||
public const int ACCUM_ALPHA_BITS = 0x0002100A;
|
||||
public const int AUX_BUFFERS = 0x0002100B;
|
||||
public const int STEREO = 0x0002100C;
|
||||
public const int SAMPLES = 0x0002100D;
|
||||
public const int SRGB_CAPABLE = 0x0002100E;
|
||||
public const int REFRESH_RATE = 0x0002100F;
|
||||
public const int DOUBLEBUFFER = 0x00021010;
|
||||
public const int CLIENT_API = 0x00022001;
|
||||
public const int CONTEXT_VERSION_MAJOR = 0x00022002;
|
||||
public const int CONTEXT_VERSION_MINOR = 0x00022003;
|
||||
public const int CONTEXT_REVISION = 0x00022004;
|
||||
public const int CONTEXT_ROBUSTNESS = 0x00022005;
|
||||
public const int OPENGL_FORWARD_COMPAT = 0x00022006;
|
||||
public const int OPENGL_DEBUG_CONTEXT = 0x00022007;
|
||||
public const int OPENGL_PROFILE = 0x00022008;
|
||||
public const int CONTEXT_RELEASE_BEHAVIOR = 0x00022009;
|
||||
public const int CONTEXT_NO_ERROR = 0x0002200A;
|
||||
public const int CONTEXT_CREATION_API = 0x0002200B;
|
||||
public const int SCALE_TO_MONITOR = 0x0002200C;
|
||||
public const int COCOA_RETINA_FRAMEBUFFER = 0x00023001;
|
||||
public const int COCOA_FRAME_NAME = 0x00023002;
|
||||
public const int COCOA_GRAPHICS_SWITCHING = 0x00023003;
|
||||
public const int X11_CLASS_NAME = 0x00024001;
|
||||
public const int X11_INSTANCE_NAME = 0x00024002;
|
||||
public const int NO_API = 0;
|
||||
public const int OPENGL_API = 0x00030001;
|
||||
public const int OPENGL_ES_API = 0x00030002;
|
||||
public const int NO_ROBUSTNESS = 0;
|
||||
public const int NO_RESET_NOTIFICATION = 0x00031001;
|
||||
public const int LOSE_CONTEXT_ON_RESET = 0x00031002;
|
||||
public const int OPENGL_ANY_PROFILE = 0;
|
||||
public const int OPENGL_CORE_PROFILE = 0x00032001;
|
||||
public const int OPENGL_COMPAT_PROFILE = 0x00032002;
|
||||
public const int CURSOR = 0x00033001;
|
||||
public const int STICKY_KEYS = 0x00033002;
|
||||
public const int STICKY_MOUSE_BUTTONS = 0x00033003;
|
||||
public const int LOCK_KEY_MODS = 0x00033004;
|
||||
public const int RAW_MOUSE_MOTION = 0x00033005;
|
||||
public const int CURSOR_NORMAL = 0x00034001;
|
||||
public const int CURSOR_HIDDEN = 0x00034002;
|
||||
public const int CURSOR_DISABLED = 0x00034003;
|
||||
public const int ANY_RELEASE_BEHAVIOR = 0;
|
||||
public const int RELEASE_BEHAVIOR_FLUSH = 0x00035001;
|
||||
public const int RELEASE_BEHAVIOR_NONE = 0x00035002;
|
||||
public const int NATIVE_CONTEXT_API = 0x00036001;
|
||||
public const int EGL_CONTEXT_API = 0x00036002;
|
||||
public const int OSMESA_CONTEXT_API = 0x00036003;
|
||||
public const int ARROW_CURSOR = 0x00036001;
|
||||
public const int IBEAM_CURSOR = 0x00036002;
|
||||
public const int CROSSHAIR_CURSOR = 0x00036003;
|
||||
public const int HAND_CURSOR = 0x00036004;
|
||||
public const int HRESIZE_CURSOR = 0x00036005;
|
||||
public const int VRESIZE_CURSOR = 0x00036006;
|
||||
public const int CONNECTED = 0x00040001;
|
||||
public const int DISCONNECTED = 0x00040002;
|
||||
public const int JOYSTICK_HAT_BUTTONS = 0x00050001;
|
||||
public const int COCOA_CHDIR_RESOURCES = 0x00051001;
|
||||
public const int COCOA_MENUBAR = 0x00051002;
|
||||
public const int DONT_CARE = -1;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IGraphicAPIs"
|
||||
// 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.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IGraphicAPIs
|
||||
{
|
||||
|
||||
public IntPtr GraphicApiPackageHandle { get; }
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IGraphicAPIs"
|
||||
// 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.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IGraphicAPIs
|
||||
{
|
||||
|
||||
public IntPtr GraphicApiPackageHandle { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+190
-190
@@ -1,191 +1,191 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Image"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : ISSDSerializable, IImageProvider
|
||||
{
|
||||
|
||||
private byte[] _data;
|
||||
private ImageInfo _rawInfo;
|
||||
private int _pixelUpdateCount = 0;
|
||||
|
||||
internal unsafe Image()
|
||||
{
|
||||
_rawInfo = new ImageInfo();
|
||||
}
|
||||
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
_rawInfo = information;
|
||||
_data = [];
|
||||
|
||||
// int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
|
||||
}
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (_rawInfo.Width, _rawInfo.Height);
|
||||
}
|
||||
|
||||
public byte[] PixelBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((_data.Length == 0) || (_data == null))
|
||||
{
|
||||
GetBytes();
|
||||
return _data!;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
public ImageChannel Channel => _rawInfo.Channel;
|
||||
|
||||
/// <summary>
|
||||
/// Hash code of time pixels updated last time.
|
||||
/// </summary>
|
||||
public int PixelUpdateCount
|
||||
{
|
||||
get => _pixelUpdateCount;
|
||||
internal set => _pixelUpdateCount = value;
|
||||
}
|
||||
|
||||
public int ChannelCount => _rawInfo.ChannelCount;
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => _rawInfo.Height;
|
||||
internal set => _rawInfo.Height = value;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => _rawInfo.Width;
|
||||
internal set => _rawInfo.Width = value;
|
||||
}
|
||||
|
||||
public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel);
|
||||
|
||||
public PixelChannelLayout PixelLayout
|
||||
{
|
||||
get => _rawInfo.pixelLayout;
|
||||
private set => _rawInfo.pixelLayout = value;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
|
||||
internal ref byte[] Data => ref _data;
|
||||
|
||||
public void FromBytes(byte[] stream) { }
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
{
|
||||
Image ret = new Image();
|
||||
fixed (ImageInfo* iptr = &ret._rawInfo) {
|
||||
GraphicFramework.InternalLoadImage(route, iptr, loader);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = PixelChannelLayout.Byte;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory(
|
||||
(int width, int height) size,
|
||||
ImageChannel channel,
|
||||
PixelChannelLayout layout,
|
||||
byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = layout;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
if (_data.Length == 0)
|
||||
{
|
||||
int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel);
|
||||
_data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray();
|
||||
fixed (ImageInfo* pptr = &_rawInfo) {
|
||||
GraphicFramework.InternalUnloadImage(pptr);
|
||||
}
|
||||
_rawInfo.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount)
|
||||
{
|
||||
return new Image
|
||||
{
|
||||
_rawInfo = info,
|
||||
_data = data,
|
||||
_pixelUpdateCount = operationCount
|
||||
};
|
||||
}
|
||||
|
||||
byte[] ISSDSerializable.GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Image"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : ISSDSerializable, IImageProvider
|
||||
{
|
||||
|
||||
private byte[] _data;
|
||||
private ImageInfo _rawInfo;
|
||||
private int _pixelUpdateCount = 0;
|
||||
|
||||
internal unsafe Image()
|
||||
{
|
||||
_rawInfo = new ImageInfo();
|
||||
}
|
||||
|
||||
internal Image(ImageInfo information)
|
||||
{
|
||||
_rawInfo = information;
|
||||
_data = [];
|
||||
|
||||
// int length = _rawInfo.width * _rawInfo.height * _rawInfo.channel;
|
||||
}
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (_rawInfo.Width, _rawInfo.Height);
|
||||
}
|
||||
|
||||
public byte[] PixelBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((_data.Length == 0) || (_data == null))
|
||||
{
|
||||
GetBytes();
|
||||
return _data!;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
public ImageChannel Channel => _rawInfo.Channel;
|
||||
|
||||
/// <summary>
|
||||
/// Hash code of time pixels updated last time.
|
||||
/// </summary>
|
||||
public int PixelUpdateCount
|
||||
{
|
||||
get => _pixelUpdateCount;
|
||||
internal set => _pixelUpdateCount = value;
|
||||
}
|
||||
|
||||
public int ChannelCount => _rawInfo.ChannelCount;
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => _rawInfo.Height;
|
||||
internal set => _rawInfo.Height = value;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => _rawInfo.Width;
|
||||
internal set => _rawInfo.Width = value;
|
||||
}
|
||||
|
||||
public int PixelSize => ImageInfo.GetPixelSize(_rawInfo.pixelLayout, _rawInfo.Channel);
|
||||
|
||||
public PixelChannelLayout PixelLayout
|
||||
{
|
||||
get => _rawInfo.pixelLayout;
|
||||
private set => _rawInfo.pixelLayout = value;
|
||||
}
|
||||
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
|
||||
internal ref byte[] Data => ref _data;
|
||||
|
||||
public void FromBytes(byte[] stream) { }
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
{
|
||||
Image ret = new Image();
|
||||
fixed (ImageInfo* iptr = &ret._rawInfo) {
|
||||
GraphicFramework.InternalLoadImage(route, iptr, loader);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory((int width, int height) size, ImageChannel channel, byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = PixelChannelLayout.Byte;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Image FromMemory(
|
||||
(int width, int height) size,
|
||||
ImageChannel channel,
|
||||
PixelChannelLayout layout,
|
||||
byte[] stream)
|
||||
{
|
||||
ImageInfo _info = new ImageInfo
|
||||
{
|
||||
Height = size.height,
|
||||
Width = size.width,
|
||||
Channel = channel,
|
||||
StreamPtr = IntPtr.Zero
|
||||
};
|
||||
Image ret = new Image(_info);
|
||||
ret.PixelLayout = layout;
|
||||
ret._data = stream;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
if (_data.Length == 0)
|
||||
{
|
||||
int size = Width * Height * ImageInfo.GetPixelSize(PixelLayout, Channel);
|
||||
_data = new Span<byte>((byte*)_rawInfo.StreamPtr, size).ToArray();
|
||||
fixed (ImageInfo* pptr = &_rawInfo) {
|
||||
GraphicFramework.InternalUnloadImage(pptr);
|
||||
}
|
||||
_rawInfo.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
return _data;
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
internal static Image FromMemory(ImageInfo info, byte[] data, int operationCount)
|
||||
{
|
||||
return new Image
|
||||
{
|
||||
_rawInfo = info,
|
||||
_data = data,
|
||||
_pixelUpdateCount = operationCount
|
||||
};
|
||||
}
|
||||
|
||||
byte[] ISSDSerializable.GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,162 +1,162 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ImageInfo"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public delegate IntPtr ImageLoader(
|
||||
string name,
|
||||
ref int width,
|
||||
ref int height,
|
||||
ref int definedChannel,
|
||||
int desiredChannel);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ImageInfo
|
||||
{
|
||||
|
||||
private ImageChannel channel;
|
||||
private int height;
|
||||
private int width;
|
||||
private IntPtr pixelPtr;
|
||||
internal PixelChannelLayout pixelLayout;
|
||||
|
||||
public ImageChannel Channel
|
||||
{
|
||||
get => channel;
|
||||
set { channel = value; }
|
||||
}
|
||||
|
||||
public int ChannelCount
|
||||
{
|
||||
get => GetChannelCount(channel);
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
public int StreamSize
|
||||
{
|
||||
get => width * height * GetPixelSize(
|
||||
pixelLayout, channel);
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = (hash * 17) + width;
|
||||
hash = (hash * 17) + height;
|
||||
hash = (hash * 17) + (int)channel;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
internal static int GetChannelCount(ImageChannel channel)
|
||||
{
|
||||
return channel switch
|
||||
{
|
||||
ImageChannel.SingleColor => 1,
|
||||
ImageChannel.DoubleColor => 2,
|
||||
ImageChannel.TripleColor => 3,
|
||||
ImageChannel.WithAlphaChannel => 4,
|
||||
_ => throw new InvalidCastException(
|
||||
"Unknown color channel decoding setting.")
|
||||
};
|
||||
}
|
||||
|
||||
internal static int GetPixelSize(PixelChannelLayout layout, ImageChannel channel)
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.UByte => sizeof(byte) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Byte => sizeof(byte) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UShort => sizeof(short) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Short => sizeof(short) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UInt => sizeof(int) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Int => sizeof(int) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Float => sizeof(float) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UByte332 => sizeof(byte),
|
||||
PixelChannelLayout.UByte233Rev => sizeof(byte),
|
||||
PixelChannelLayout.UShort565 => sizeof(short),
|
||||
PixelChannelLayout.UShort565Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort4444 => sizeof(short),
|
||||
PixelChannelLayout.UShort4444Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort5551 => sizeof(short),
|
||||
PixelChannelLayout.UShort1555Rev => sizeof(short),
|
||||
PixelChannelLayout.UInt8888 => sizeof(int),
|
||||
PixelChannelLayout.UInt8888Rev => sizeof(int),
|
||||
PixelChannelLayout.UInt1010102 => sizeof(int),
|
||||
PixelChannelLayout.UInt2101010Rev => sizeof(int),
|
||||
_ => throw new ArgumentException("Unknown layout type"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
{
|
||||
|
||||
SingleColor = glConst.RED,
|
||||
DoubleColor = glConst.RG,
|
||||
TripleColor = glConst.RGB,
|
||||
WithAlphaChannel = glConst.RGBA,
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ImageInfo"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
public delegate IntPtr ImageLoader(
|
||||
string name,
|
||||
ref int width,
|
||||
ref int height,
|
||||
ref int definedChannel,
|
||||
int desiredChannel);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ImageInfo
|
||||
{
|
||||
|
||||
private ImageChannel channel;
|
||||
private int height;
|
||||
private int width;
|
||||
private IntPtr pixelPtr;
|
||||
internal PixelChannelLayout pixelLayout;
|
||||
|
||||
public ImageChannel Channel
|
||||
{
|
||||
get => channel;
|
||||
set { channel = value; }
|
||||
}
|
||||
|
||||
public int ChannelCount
|
||||
{
|
||||
get => GetChannelCount(channel);
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => height;
|
||||
set => height = value;
|
||||
}
|
||||
|
||||
public int StreamSize
|
||||
{
|
||||
get => width * height * GetPixelSize(
|
||||
pixelLayout, channel);
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => width;
|
||||
set => width = value;
|
||||
}
|
||||
|
||||
public IntPtr StreamPtr
|
||||
{
|
||||
get => pixelPtr;
|
||||
internal set => pixelPtr = value;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 17;
|
||||
hash = (hash * 17) + width;
|
||||
hash = (hash * 17) + height;
|
||||
hash = (hash * 17) + (int)channel;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
|
||||
}
|
||||
|
||||
internal static int GetChannelCount(ImageChannel channel)
|
||||
{
|
||||
return channel switch
|
||||
{
|
||||
ImageChannel.SingleColor => 1,
|
||||
ImageChannel.DoubleColor => 2,
|
||||
ImageChannel.TripleColor => 3,
|
||||
ImageChannel.WithAlphaChannel => 4,
|
||||
_ => throw new InvalidCastException(
|
||||
"Unknown color channel decoding setting.")
|
||||
};
|
||||
}
|
||||
|
||||
internal static int GetPixelSize(PixelChannelLayout layout, ImageChannel channel)
|
||||
{
|
||||
return layout switch
|
||||
{
|
||||
PixelChannelLayout.UByte => sizeof(byte) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Byte => sizeof(byte) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UShort => sizeof(short) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Short => sizeof(short) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UInt => sizeof(int) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Int => sizeof(int) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.Float => sizeof(float) * GetChannelCount(
|
||||
channel),
|
||||
PixelChannelLayout.UByte332 => sizeof(byte),
|
||||
PixelChannelLayout.UByte233Rev => sizeof(byte),
|
||||
PixelChannelLayout.UShort565 => sizeof(short),
|
||||
PixelChannelLayout.UShort565Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort4444 => sizeof(short),
|
||||
PixelChannelLayout.UShort4444Rev => sizeof(short),
|
||||
PixelChannelLayout.UShort5551 => sizeof(short),
|
||||
PixelChannelLayout.UShort1555Rev => sizeof(short),
|
||||
PixelChannelLayout.UInt8888 => sizeof(int),
|
||||
PixelChannelLayout.UInt8888Rev => sizeof(int),
|
||||
PixelChannelLayout.UInt1010102 => sizeof(int),
|
||||
PixelChannelLayout.UInt2101010Rev => sizeof(int),
|
||||
_ => throw new ArgumentException("Unknown layout type"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ImageChannel : uint
|
||||
{
|
||||
|
||||
SingleColor = glConst.RED,
|
||||
DoubleColor = glConst.RG,
|
||||
TripleColor = glConst.RGB,
|
||||
WithAlphaChannel = glConst.RGBA,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,160 +1,160 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="AutoTexture"
|
||||
// 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 StgSharp.Collections;
|
||||
using StgSharp.Graphics;
|
||||
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 BufferHandle. 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="AutoTexture"
|
||||
// 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 StgSharp.Collections;
|
||||
using StgSharp.Graphics;
|
||||
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 BufferHandle. 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,81 +1,81 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="EBO"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
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 BufferHandle Object in OpenglFunc. Each <see
|
||||
/// langword="uint" /> value indexed from instance of this class this is the only handle to
|
||||
/// one Element BufferHandle Object.
|
||||
/// </summary>
|
||||
public sealed unsafe class ElementBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal ElementBuffer(int n, glRender binding)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage) where T: unmanaged, 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: unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData<T>(BufferType.ElementArrayBuffer, bufferSpan, usage);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="EBO"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
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 BufferHandle Object in OpenglFunc. Each <see
|
||||
/// langword="uint" /> value indexed from instance of this class this is the only handle to
|
||||
/// one Element BufferHandle Object.
|
||||
/// </summary>
|
||||
public sealed unsafe class ElementBuffer : GlBufferObjectBase
|
||||
{
|
||||
|
||||
internal ElementBuffer(int n, glRender binding)
|
||||
: base(binding)
|
||||
{
|
||||
_bufferHandle = GL.GenBuffers(n);
|
||||
}
|
||||
|
||||
public sealed override void Bind(int index)
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
}
|
||||
|
||||
public void SetValue<T>(int index, T[] bufferArray, BufferUsage usage) where T: unmanaged, 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: unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ElementArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData<T>(BufferType.ElementArrayBuffer, bufferSpan, usage);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,115 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="FBO"
|
||||
// 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 StgSharp.Graphics;
|
||||
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 = new GlHandle[count];
|
||||
GL.GenFrameBuffers(_bufferHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame BufferHandle object with _label frame BufferHandle to the frame
|
||||
/// BufferHandle 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 BufferHandle object with _label frame BufferHandle to the frame
|
||||
/// BufferHandle target specified by target. Target of this frame BufferHandle should be
|
||||
/// set manually.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// The frame BufferHandle 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="FBO"
|
||||
// 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 StgSharp.Graphics;
|
||||
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 = new GlHandle[count];
|
||||
GL.GenFrameBuffers(_bufferHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind the frame BufferHandle object with _label frame BufferHandle to the frame
|
||||
/// BufferHandle 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 BufferHandle object with _label frame BufferHandle to the frame
|
||||
/// BufferHandle target specified by target. Target of this frame BufferHandle should be
|
||||
/// set manually.
|
||||
/// </summary>
|
||||
/// <param _label="target">
|
||||
/// The frame BufferHandle 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,50 +1,50 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GLBufferObjectBase"
|
||||
// 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 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;
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="GLBufferObjectBase"
|
||||
// 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 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,67 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RBO"
|
||||
// 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 StgSharp.Graphics;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RBO"
|
||||
// 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 StgSharp.Graphics;
|
||||
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,311 +1,311 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TextureGL"
|
||||
// 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 StgSharp.Graphics;
|
||||
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, i.Width, 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,
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TextureGL"
|
||||
// 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 StgSharp.Graphics;
|
||||
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, i.Width, 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,86 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="VAO"
|
||||
// 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 StgSharp.Graphics;
|
||||
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 sealed override 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,
|
||||
int stride,
|
||||
int pointer
|
||||
)
|
||||
{
|
||||
GL.SetVertexAttribute(attributeIndex, vertexLength, dataType, isNomalized, stride,
|
||||
pointer);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteVertexArrays(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="VAO"
|
||||
// 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 StgSharp.Graphics;
|
||||
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 sealed override 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,
|
||||
int stride,
|
||||
int pointer
|
||||
)
|
||||
{
|
||||
GL.SetVertexAttribute(attributeIndex, vertexLength, dataType, isNomalized, stride,
|
||||
pointer);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteVertexArrays(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,181 +1,181 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="VBO"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
|
||||
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 sealed override 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 BufferHandle 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 : unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle 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 : unmanaged,INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex BufferHandle 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 : unmanaged, IUnmanagedVector<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle 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 : unmanaged, IUnmanagedVector<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="VBO"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
|
||||
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 sealed override 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 BufferHandle 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 : unmanaged, INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, bufferArray, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle 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 : unmanaged,INumber<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferData(BufferType.ArrayBuffer, scalerSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set data to current vertex BufferHandle 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 : unmanaged, IUnmanagedVector<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorSpan, usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set _data to current vertex BufferHandle 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 : unmanaged, IUnmanagedVector<T>
|
||||
{
|
||||
GL.BindBuffer(BufferType.ArrayBuffer, _bufferHandle[index]);
|
||||
GL.SetBufferVectorData(BufferType.ArrayBuffer, vectorArray, usage);
|
||||
}
|
||||
|
||||
protected sealed override void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (disposing) {
|
||||
GL.DeleteBuffers(_bufferHandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,65 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IglConvertable"
|
||||
// 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 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();
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="IglConvertable"
|
||||
// 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 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,318 +1,318 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Shader"
|
||||
// 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 StgSharp;
|
||||
using StgSharp.Graphics;
|
||||
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 sealed override ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override 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 : unmanaged
|
||||
{
|
||||
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 : unmanaged 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 : unmanaged 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 : unmanaged 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 (GraphicFramework.InternalLinkShaderProgram(
|
||||
(OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
|
||||
{
|
||||
IntPtr logPtr = GraphicFramework.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);
|
||||
DefaultLog.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DefaultLog.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();
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Shader"
|
||||
// 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 StgSharp;
|
||||
using StgSharp.Graphics;
|
||||
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 sealed override ShaderProgram CreateShaderProgram()
|
||||
{
|
||||
return new ShaderProgram(this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override 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 : unmanaged
|
||||
{
|
||||
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 : unmanaged 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 : unmanaged 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 : unmanaged 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 (GraphicFramework.InternalLinkShaderProgram(
|
||||
(OpenglContext*)this.GL.ContextHandle, handle.Value) == 0)
|
||||
{
|
||||
IntPtr logPtr = GraphicFramework.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);
|
||||
DefaultLog.InternalWriteLog(log, LogType.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DefaultLog.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,225 +1,225 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Uniform"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
|
||||
internal GlHandle id;
|
||||
|
||||
public GlHandle Handle => id;
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform where T : unmanaged
|
||||
{
|
||||
|
||||
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 : unmanaged 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 : unmanaged 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 : unmanaged 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
|
||||
)
|
||||
{
|
||||
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, (byte)0, (float*)&mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<float, float, float, float> uniform,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, (float*)&vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<Vec4> uniform,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, (float*)&vec);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Uniform"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public class Uniform
|
||||
{
|
||||
|
||||
internal GlHandle id;
|
||||
|
||||
public GlHandle Handle => id;
|
||||
|
||||
}
|
||||
|
||||
public sealed class Uniform<T> : Uniform where T : unmanaged
|
||||
{
|
||||
|
||||
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 : unmanaged 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 : unmanaged 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 : unmanaged 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
|
||||
)
|
||||
{
|
||||
Context.glUniformMatrix4fv(uniform.id.SignedValue, 1, (byte)0, (float*)&mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<float, float, float, float> uniform,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, (float*)&vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetUniformValue(
|
||||
[NotNull]Uniform<Vec4> uniform,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Context.glUniform1fv(uniform.id.SignedValue, 4, (float*)&vec);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+4563
-4563
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,224 +1,224 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glEnum"
|
||||
// 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.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
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glEnum"
|
||||
// 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.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,98 +1,98 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glException"
|
||||
// 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.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,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glException"
|
||||
// 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.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,92 +1,92 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFucntionSourceManager"
|
||||
// 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 StgSharp;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private readonly int textureUnitCountGetter;
|
||||
|
||||
public int TextureUnitCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => textureUnitCountGetter;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> UnusedTextureImageUint
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = [];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFucntionSourceManager"
|
||||
// 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 StgSharp;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public partial class OpenGLFunction
|
||||
{
|
||||
|
||||
private readonly int textureUnitCountGetter;
|
||||
|
||||
public int TextureUnitCount
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => textureUnitCountGetter;
|
||||
}
|
||||
|
||||
private ConcurrentQueue<TextureUnit> UnusedTextureImageUint
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = [];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,190 +1,190 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFunction.v4_2"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindImageTexture(
|
||||
uint unit,
|
||||
GlHandle texture,
|
||||
int level,
|
||||
byte layered,
|
||||
int layer,
|
||||
uint access,
|
||||
uint format
|
||||
)
|
||||
{
|
||||
_context->glBindImageTexture(unit, texture.Value, level, layered, layer, access,
|
||||
format);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawArraysInstancedBaseInstance(
|
||||
uint mode,
|
||||
int first,
|
||||
int count,
|
||||
int instancecount,
|
||||
uint baseinstance
|
||||
)
|
||||
{
|
||||
_context->glDrawArraysInstancedBaseInstance(mode, first, count, instancecount,
|
||||
baseinstance);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawElementsInstancedBaseInstance(
|
||||
uint mode,
|
||||
int count,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> indices,
|
||||
int instancecount,
|
||||
uint baseinstance
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* indicesPtr = indices) {
|
||||
_context->glDrawElementsInstancedBaseInstance(mode, count, (uint)type, indicesPtr,
|
||||
instancecount, baseinstance);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawElementsInstancedBaseVertexBaseInstance(
|
||||
uint mode,
|
||||
int count,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> indices,
|
||||
int instancecount,
|
||||
int basevertex,
|
||||
uint baseinstance
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* indicesPtr = indices) {
|
||||
_context->glDrawElementsInstancedBaseVertexBaseInstance(mode, count, (uint)type,
|
||||
indicesPtr, instancecount,
|
||||
basevertex, baseinstance);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawTransformFeedbackInstanced(
|
||||
uint mode,
|
||||
uint id,
|
||||
int instancecount
|
||||
)
|
||||
{
|
||||
_context->glDrawTransformFeedbackInstanced(mode, id, instancecount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawTransformFeedbackStreamInstanced(
|
||||
uint mode,
|
||||
uint id,
|
||||
uint stream,
|
||||
int instancecount
|
||||
)
|
||||
{
|
||||
_context->glDrawTransformFeedbackStreamInstanced(mode, id, stream, instancecount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void GetActiveAtomicCounterBufferiv(
|
||||
GlHandle program,
|
||||
GlHandle bufferIndex,
|
||||
uint pname,
|
||||
int* @params
|
||||
)
|
||||
{
|
||||
_context->glGetActiveAtomicCounterBufferiv(program.Value, bufferIndex.Value, pname,
|
||||
@params);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void GetInternalformativ(
|
||||
uint target,
|
||||
uint internalformat,
|
||||
uint pname,
|
||||
int count,
|
||||
int* @params
|
||||
)
|
||||
{
|
||||
_context->glGetInternalformativ(target, internalformat, pname, count, @params);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MemoryBarrier(
|
||||
uint barriers
|
||||
)
|
||||
{
|
||||
_context->glMemoryBarrier(barriers);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TexStorage1D(
|
||||
uint target,
|
||||
int levels,
|
||||
uint internalformat,
|
||||
int width
|
||||
)
|
||||
{
|
||||
_context->glTexStorage1D(target, levels, internalformat, width);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TexStorage2D(
|
||||
uint target,
|
||||
int levels,
|
||||
uint internalformat,
|
||||
int width,
|
||||
int height
|
||||
)
|
||||
{
|
||||
_context->glTexStorage2D(target, levels, internalformat, width, height);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TexStorage3D(
|
||||
uint target,
|
||||
int levels,
|
||||
uint internalformat,
|
||||
int width,
|
||||
int height,
|
||||
int depth
|
||||
)
|
||||
{
|
||||
_context->glTexStorage3D(target, levels, internalformat, width, height, depth);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFunction.v4_2"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindImageTexture(
|
||||
uint unit,
|
||||
GlHandle texture,
|
||||
int level,
|
||||
byte layered,
|
||||
int layer,
|
||||
uint access,
|
||||
uint format
|
||||
)
|
||||
{
|
||||
_context->glBindImageTexture(unit, texture.Value, level, layered, layer, access,
|
||||
format);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawArraysInstancedBaseInstance(
|
||||
uint mode,
|
||||
int first,
|
||||
int count,
|
||||
int instancecount,
|
||||
uint baseinstance
|
||||
)
|
||||
{
|
||||
_context->glDrawArraysInstancedBaseInstance(mode, first, count, instancecount,
|
||||
baseinstance);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawElementsInstancedBaseInstance(
|
||||
uint mode,
|
||||
int count,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> indices,
|
||||
int instancecount,
|
||||
uint baseinstance
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* indicesPtr = indices) {
|
||||
_context->glDrawElementsInstancedBaseInstance(mode, count, (uint)type, indicesPtr,
|
||||
instancecount, baseinstance);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawElementsInstancedBaseVertexBaseInstance(
|
||||
uint mode,
|
||||
int count,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> indices,
|
||||
int instancecount,
|
||||
int basevertex,
|
||||
uint baseinstance
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* indicesPtr = indices) {
|
||||
_context->glDrawElementsInstancedBaseVertexBaseInstance(mode, count, (uint)type,
|
||||
indicesPtr, instancecount,
|
||||
basevertex, baseinstance);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawTransformFeedbackInstanced(
|
||||
uint mode,
|
||||
uint id,
|
||||
int instancecount
|
||||
)
|
||||
{
|
||||
_context->glDrawTransformFeedbackInstanced(mode, id, instancecount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void DrawTransformFeedbackStreamInstanced(
|
||||
uint mode,
|
||||
uint id,
|
||||
uint stream,
|
||||
int instancecount
|
||||
)
|
||||
{
|
||||
_context->glDrawTransformFeedbackStreamInstanced(mode, id, stream, instancecount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void GetActiveAtomicCounterBufferiv(
|
||||
GlHandle program,
|
||||
GlHandle bufferIndex,
|
||||
uint pname,
|
||||
int* @params
|
||||
)
|
||||
{
|
||||
_context->glGetActiveAtomicCounterBufferiv(program.Value, bufferIndex.Value, pname,
|
||||
@params);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void GetInternalformativ(
|
||||
uint target,
|
||||
uint internalformat,
|
||||
uint pname,
|
||||
int count,
|
||||
int* @params
|
||||
)
|
||||
{
|
||||
_context->glGetInternalformativ(target, internalformat, pname, count, @params);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MemoryBarrier(
|
||||
uint barriers
|
||||
)
|
||||
{
|
||||
_context->glMemoryBarrier(barriers);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TexStorage1D(
|
||||
uint target,
|
||||
int levels,
|
||||
uint internalformat,
|
||||
int width
|
||||
)
|
||||
{
|
||||
_context->glTexStorage1D(target, levels, internalformat, width);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TexStorage2D(
|
||||
uint target,
|
||||
int levels,
|
||||
uint internalformat,
|
||||
int width,
|
||||
int height
|
||||
)
|
||||
{
|
||||
_context->glTexStorage2D(target, levels, internalformat, width, height);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void TexStorage3D(
|
||||
uint target,
|
||||
int levels,
|
||||
uint internalformat,
|
||||
int width,
|
||||
int height,
|
||||
int depth
|
||||
)
|
||||
{
|
||||
_context->glTexStorage3D(target, levels, internalformat, width, height, depth);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,179 +1,179 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFunction.v4_4"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindBuffersBase(
|
||||
uint target,
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> buffers
|
||||
)
|
||||
{
|
||||
fixed (uint* buffersPtr = buffers) {
|
||||
_context->glBindBuffersBase(target, first, count, buffersPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindBuffersRange(
|
||||
uint target,
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> buffers,
|
||||
ReadOnlySpan<nint> offsets,
|
||||
ReadOnlySpan<nuint> sizes
|
||||
)
|
||||
{
|
||||
fixed (uint* buffersPtr = buffers)
|
||||
{
|
||||
fixed (nint* offsetsPtr = offsets)
|
||||
{
|
||||
fixed (nuint* sizesPtr = sizes) {
|
||||
_context->glBindBuffersRange(target, first, count, buffersPtr, offsetsPtr,
|
||||
sizesPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindImageTextures(
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> textures
|
||||
)
|
||||
{
|
||||
fixed (uint* texturesPtr = textures) {
|
||||
_context->glBindImageTextures(first, count, texturesPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindSamplers(
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> samplers
|
||||
)
|
||||
{
|
||||
fixed (uint* samplersPtr = samplers) {
|
||||
_context->glBindSamplers(first, count, samplersPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindTextures(
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> textures
|
||||
)
|
||||
{
|
||||
fixed (uint* texturesPtr = textures) {
|
||||
_context->glBindTextures(first, count, texturesPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindVertexBuffers(
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> buffers,
|
||||
ReadOnlySpan<nint> offsets,
|
||||
ReadOnlySpan<int> strides
|
||||
)
|
||||
{
|
||||
fixed (uint* buffersPtr = buffers)
|
||||
{
|
||||
fixed (nint* offsetsPtr = offsets)
|
||||
{
|
||||
fixed (int* stridesPtr = strides) {
|
||||
_context->glBindVertexBuffers(first, count, buffersPtr, offsetsPtr,
|
||||
stridesPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BufferStorage(
|
||||
uint target,
|
||||
nuint size,
|
||||
ReadOnlySpan<IntPtr> data,
|
||||
uint flags
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* dataPtr = data) {
|
||||
_context->glBufferStorage(target, size, dataPtr, flags);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ClearTexImage(
|
||||
GlHandle texture,
|
||||
int level,
|
||||
uint format,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> data
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* dataPtr = data) {
|
||||
_context->glClearTexImage(texture.Value, level, format, (uint)type, dataPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ClearTexSubImage(
|
||||
GlHandle texture,
|
||||
int level,
|
||||
int xoffset,
|
||||
int yoffset,
|
||||
int zoffset,
|
||||
int width,
|
||||
int height,
|
||||
int depth,
|
||||
uint format,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> data
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* dataPtr = data) {
|
||||
_context->glClearTexSubImage(texture.Value, level, xoffset, yoffset, zoffset, width,
|
||||
height, depth, format, (uint)type, dataPtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFunction.v4_4"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindBuffersBase(
|
||||
uint target,
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> buffers
|
||||
)
|
||||
{
|
||||
fixed (uint* buffersPtr = buffers) {
|
||||
_context->glBindBuffersBase(target, first, count, buffersPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindBuffersRange(
|
||||
uint target,
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> buffers,
|
||||
ReadOnlySpan<nint> offsets,
|
||||
ReadOnlySpan<nuint> sizes
|
||||
)
|
||||
{
|
||||
fixed (uint* buffersPtr = buffers)
|
||||
{
|
||||
fixed (nint* offsetsPtr = offsets)
|
||||
{
|
||||
fixed (nuint* sizesPtr = sizes) {
|
||||
_context->glBindBuffersRange(target, first, count, buffersPtr, offsetsPtr,
|
||||
sizesPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindImageTextures(
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> textures
|
||||
)
|
||||
{
|
||||
fixed (uint* texturesPtr = textures) {
|
||||
_context->glBindImageTextures(first, count, texturesPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindSamplers(
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> samplers
|
||||
)
|
||||
{
|
||||
fixed (uint* samplersPtr = samplers) {
|
||||
_context->glBindSamplers(first, count, samplersPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindTextures(
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> textures
|
||||
)
|
||||
{
|
||||
fixed (uint* texturesPtr = textures) {
|
||||
_context->glBindTextures(first, count, texturesPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BindVertexBuffers(
|
||||
uint first,
|
||||
int count,
|
||||
ReadOnlySpan<uint> buffers,
|
||||
ReadOnlySpan<nint> offsets,
|
||||
ReadOnlySpan<int> strides
|
||||
)
|
||||
{
|
||||
fixed (uint* buffersPtr = buffers)
|
||||
{
|
||||
fixed (nint* offsetsPtr = offsets)
|
||||
{
|
||||
fixed (int* stridesPtr = strides) {
|
||||
_context->glBindVertexBuffers(first, count, buffersPtr, offsetsPtr,
|
||||
stridesPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void BufferStorage(
|
||||
uint target,
|
||||
nuint size,
|
||||
ReadOnlySpan<IntPtr> data,
|
||||
uint flags
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* dataPtr = data) {
|
||||
_context->glBufferStorage(target, size, dataPtr, flags);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ClearTexImage(
|
||||
GlHandle texture,
|
||||
int level,
|
||||
uint format,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> data
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* dataPtr = data) {
|
||||
_context->glClearTexImage(texture.Value, level, format, (uint)type, dataPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ClearTexSubImage(
|
||||
GlHandle texture,
|
||||
int level,
|
||||
int xoffset,
|
||||
int yoffset,
|
||||
int zoffset,
|
||||
int width,
|
||||
int height,
|
||||
int depth,
|
||||
uint format,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> data
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* dataPtr = data) {
|
||||
_context->glClearTexSubImage(texture.Value, level, xoffset, yoffset, zoffset, width,
|
||||
height, depth, format, (uint)type, dataPtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,102 +1,102 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFunction.v4_6"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MultiDrawArraysIndirectCount(
|
||||
uint mode,
|
||||
ReadOnlySpan<IntPtr> indirect,
|
||||
nint drawcount,
|
||||
int maxdrawcount,
|
||||
int stride
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* indirectPtr = indirect) {
|
||||
_context->glMultiDrawArraysIndirectCount(mode, indirectPtr, drawcount, maxdrawcount,
|
||||
stride);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MultiDrawElementsIndirectCount(
|
||||
uint mode,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> indirect,
|
||||
nint drawcount,
|
||||
int maxdrawcount,
|
||||
int stride
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* indirectPtr = indirect) {
|
||||
_context->glMultiDrawElementsIndirectCount(mode, (uint)type, indirectPtr, drawcount,
|
||||
maxdrawcount, stride);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void PolygonOffsetClamp(
|
||||
float factor,
|
||||
float units,
|
||||
float clamp
|
||||
)
|
||||
{
|
||||
_context->glPolygonOffsetClamp(factor, units, clamp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SpecializeShader(
|
||||
GlHandle shader,
|
||||
ReadOnlySpan<byte> pEntryPoint,
|
||||
uint numSpecializationConstants,
|
||||
ReadOnlySpan<uint> pConstantIndex,
|
||||
ReadOnlySpan<uint> pConstantValue
|
||||
)
|
||||
{
|
||||
fixed (byte* pEntryPointPtr = pEntryPoint)
|
||||
{
|
||||
fixed (uint* pConstantIndexPtr = pConstantIndex)
|
||||
{
|
||||
fixed (uint* pConstantValuePtr = pConstantValue) {
|
||||
_context->glSpecializeShader(shader.Value, pEntryPointPtr,
|
||||
numSpecializationConstants, pConstantIndexPtr,
|
||||
pConstantValuePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glFunction.v4_6"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
public unsafe partial class OpenGLFunction
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MultiDrawArraysIndirectCount(
|
||||
uint mode,
|
||||
ReadOnlySpan<IntPtr> indirect,
|
||||
nint drawcount,
|
||||
int maxdrawcount,
|
||||
int stride
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* indirectPtr = indirect) {
|
||||
_context->glMultiDrawArraysIndirectCount(mode, indirectPtr, drawcount, maxdrawcount,
|
||||
stride);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void MultiDrawElementsIndirectCount(
|
||||
uint mode,
|
||||
ShaderType type,
|
||||
ReadOnlySpan<IntPtr> indirect,
|
||||
nint drawcount,
|
||||
int maxdrawcount,
|
||||
int stride
|
||||
)
|
||||
{
|
||||
fixed (IntPtr* indirectPtr = indirect) {
|
||||
_context->glMultiDrawElementsIndirectCount(mode, (uint)type, indirectPtr, drawcount,
|
||||
maxdrawcount, stride);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void PolygonOffsetClamp(
|
||||
float factor,
|
||||
float units,
|
||||
float clamp
|
||||
)
|
||||
{
|
||||
_context->glPolygonOffsetClamp(factor, units, clamp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SpecializeShader(
|
||||
GlHandle shader,
|
||||
ReadOnlySpan<byte> pEntryPoint,
|
||||
uint numSpecializationConstants,
|
||||
ReadOnlySpan<uint> pConstantIndex,
|
||||
ReadOnlySpan<uint> pConstantValue
|
||||
)
|
||||
{
|
||||
fixed (byte* pEntryPointPtr = pEntryPoint)
|
||||
{
|
||||
fixed (uint* pConstantIndexPtr = pConstantIndex)
|
||||
{
|
||||
fixed (uint* pConstantValuePtr = pConstantValue) {
|
||||
_context->glSpecializeShader(shader.Value, pEntryPointPtr,
|
||||
numSpecializationConstants, pConstantIndexPtr,
|
||||
pConstantValuePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +1,84 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glHandle"
|
||||
// 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.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 GlHandle()
|
||||
{
|
||||
Unsafe.SkipInit(out Value);
|
||||
Unsafe.SkipInit(out SignedValue);
|
||||
Unsafe.SkipInit(out this);
|
||||
}
|
||||
|
||||
public static GlHandle Zero
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new GlHandle
|
||||
{
|
||||
Value = 0
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlHandle Create(uint value)
|
||||
{
|
||||
return new GlHandle
|
||||
{
|
||||
Value = value
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlHandle CreateSigned(int value)
|
||||
{
|
||||
return new GlHandle
|
||||
{
|
||||
SignedValue = value
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glHandle"
|
||||
// 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.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 GlHandle()
|
||||
{
|
||||
Unsafe.SkipInit(out Value);
|
||||
Unsafe.SkipInit(out SignedValue);
|
||||
Unsafe.SkipInit(out this);
|
||||
}
|
||||
|
||||
public static GlHandle Zero
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new GlHandle
|
||||
{
|
||||
Value = 0
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlHandle Create(uint value)
|
||||
{
|
||||
return new GlHandle
|
||||
{
|
||||
Value = value
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlHandle CreateSigned(int value)
|
||||
{
|
||||
return new GlHandle
|
||||
{
|
||||
SignedValue = value
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,120 +1,120 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glRenderObjectGenrator"
|
||||
// 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.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);
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glRenderObjectGenrator"
|
||||
// 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.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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,46 +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;
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// 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,197 +1,197 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glRenderStream"
|
||||
// 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 StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
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<OpenglContext>());
|
||||
OpenglContext* contextID = (OpenglContext*)ContextHandle;
|
||||
contextID->glGetString = (delegate*<uint,byte*>)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()
|
||||
{
|
||||
GraphicFramework.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;
|
||||
GraphicFramework.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
|
||||
)
|
||||
{
|
||||
GraphicFramework.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight,
|
||||
maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal sealed override void PlatformSpecifiedInitialize()
|
||||
{
|
||||
InitializeContext();
|
||||
MakeAsCurrentContext();
|
||||
glManager.LoadOpenGLApiTo(BindedViewPortContext.GraphicHandle);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal sealed override void Terminate()
|
||||
{
|
||||
CustomizeDeinit();
|
||||
}
|
||||
|
||||
protected sealed override Uniform<Matrix44> NativeCameraUniform(
|
||||
ShaderProgram source,
|
||||
string name
|
||||
)
|
||||
{
|
||||
NativeCamera.GainAllUniforms(source, name);
|
||||
return NativeCamera.convertedUniform;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override void NativeCameraViewRange(
|
||||
Radius fieldOfRange,
|
||||
Vec2 offset,
|
||||
(float frontDepth, float backDepth) viewDepth
|
||||
)
|
||||
{
|
||||
NativeCamera.SetViewRange(fieldOfRange, this.Size, offset, viewDepth);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override void NativeCameraViewTarget(
|
||||
Vec3 position,
|
||||
Vec3 direction,
|
||||
Vec3 up
|
||||
)
|
||||
{
|
||||
NativeCamera.SetViewDirection(position, direction, up);
|
||||
}
|
||||
|
||||
#region Key Control
|
||||
|
||||
protected KeyStatus CheckKey(
|
||||
KeyboardKey key
|
||||
)
|
||||
{
|
||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(
|
||||
Mouse key
|
||||
)
|
||||
{
|
||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(
|
||||
Joystick key
|
||||
)
|
||||
{
|
||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glRenderStream"
|
||||
// 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 StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
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<OpenglContext>());
|
||||
OpenglContext* contextID = (OpenglContext*)ContextHandle;
|
||||
contextID->glGetString = (delegate*<uint,byte*>)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()
|
||||
{
|
||||
GraphicFramework.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;
|
||||
GraphicFramework.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
|
||||
)
|
||||
{
|
||||
GraphicFramework.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight,
|
||||
maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal sealed override void PlatformSpecifiedInitialize()
|
||||
{
|
||||
InitializeContext();
|
||||
MakeAsCurrentContext();
|
||||
glManager.LoadOpenGLApiTo(BindedViewPortContext.GraphicHandle);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal sealed override void Terminate()
|
||||
{
|
||||
CustomizeDeinit();
|
||||
}
|
||||
|
||||
protected sealed override Uniform<Matrix44> NativeCameraUniform(
|
||||
ShaderProgram source,
|
||||
string name
|
||||
)
|
||||
{
|
||||
NativeCamera.GainAllUniforms(source, name);
|
||||
return NativeCamera.convertedUniform;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override void NativeCameraViewRange(
|
||||
Radius fieldOfRange,
|
||||
Vec2 offset,
|
||||
(float frontDepth, float backDepth) viewDepth
|
||||
)
|
||||
{
|
||||
NativeCamera.SetViewRange(fieldOfRange, this.Size, offset, viewDepth);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected sealed override void NativeCameraViewTarget(
|
||||
Vec3 position,
|
||||
Vec3 direction,
|
||||
Vec3 up
|
||||
)
|
||||
{
|
||||
NativeCamera.SetViewDirection(position, direction, up);
|
||||
}
|
||||
|
||||
#region Key Control
|
||||
|
||||
protected KeyStatus CheckKey(
|
||||
KeyboardKey key
|
||||
)
|
||||
{
|
||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(
|
||||
Mouse key
|
||||
)
|
||||
{
|
||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(
|
||||
Joystick key
|
||||
)
|
||||
{
|
||||
return GraphicFramework.glfwGetKey(this.CanvasHandle, (int)key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,111 +1,111 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glType"
|
||||
// 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.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
internal delegate void GLVULKANPROCNV();
|
||||
|
||||
public unsafe struct glHandleARB(
|
||||
IntPtr value
|
||||
) { }
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct glHalfNv(
|
||||
Half bin
|
||||
)
|
||||
{
|
||||
|
||||
[FieldOffset(0)] public Half binary = bin;
|
||||
|
||||
public float ToSingle()
|
||||
{
|
||||
return (float)binary;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct glSync
|
||||
{
|
||||
|
||||
public IntPtr Handle;
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 8)]
|
||||
public struct GlFixed
|
||||
{
|
||||
|
||||
[FieldOffset(0)] public int All;
|
||||
[FieldOffset(0)] public short Decimals;
|
||||
[FieldOffset(4)] public short Integer;
|
||||
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="glType"
|
||||
// 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.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.OpenGL
|
||||
{
|
||||
internal delegate void GLVULKANPROCNV();
|
||||
|
||||
public unsafe struct glHandleARB(
|
||||
IntPtr value
|
||||
) { }
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct glHalfNv(
|
||||
Half bin
|
||||
)
|
||||
{
|
||||
|
||||
[FieldOffset(0)] public Half binary = bin;
|
||||
|
||||
public float ToSingle()
|
||||
{
|
||||
return (float)binary;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct glSync
|
||||
{
|
||||
|
||||
public IntPtr Handle;
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 8)]
|
||||
public struct GlFixed
|
||||
{
|
||||
|
||||
[FieldOffset(0)] public int All;
|
||||
[FieldOffset(0)] public short Decimals;
|
||||
[FieldOffset(4)] public short Integer;
|
||||
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,83 +1,83 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Pixels"
|
||||
// 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.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IPixel
|
||||
{
|
||||
|
||||
public float Red { get; set; }
|
||||
|
||||
public float Green { get; set; }
|
||||
|
||||
public float Blue { get; set; }
|
||||
|
||||
public float Alpha { get; set; }
|
||||
|
||||
internal int Size { get; }
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32)]
|
||||
public unsafe struct Pixel32RGBA : IPixel
|
||||
{
|
||||
|
||||
[FieldOffset(0)] private unsafe fixed byte data[4];
|
||||
|
||||
public int Size => 4;
|
||||
|
||||
float IPixel.Alpha
|
||||
{
|
||||
get => data[3] / 256 ;
|
||||
set => data[3] = (byte)(value * 256);
|
||||
}
|
||||
|
||||
float IPixel.Blue
|
||||
{
|
||||
get => data[2] / 256 ;
|
||||
set => data[2] = (byte)(value * 256);
|
||||
}
|
||||
|
||||
float IPixel.Green
|
||||
{
|
||||
get => data[1] / 256 ;
|
||||
set => data[1] = (byte)(value * 256);
|
||||
}
|
||||
|
||||
float IPixel.Red
|
||||
{
|
||||
get => data[0] / 256 ;
|
||||
set => data[0] = (byte)(value * 256);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Pixels"
|
||||
// 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.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public interface IPixel
|
||||
{
|
||||
|
||||
public float Red { get; set; }
|
||||
|
||||
public float Green { get; set; }
|
||||
|
||||
public float Blue { get; set; }
|
||||
|
||||
public float Alpha { get; set; }
|
||||
|
||||
internal int Size { get; }
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32)]
|
||||
public unsafe struct Pixel32RGBA : IPixel
|
||||
{
|
||||
|
||||
[FieldOffset(0)] private unsafe fixed byte data[4];
|
||||
|
||||
public int Size => 4;
|
||||
|
||||
float IPixel.Alpha
|
||||
{
|
||||
get => data[3] / 256 ;
|
||||
set => data[3] = (byte)(value * 256);
|
||||
}
|
||||
|
||||
float IPixel.Blue
|
||||
{
|
||||
get => data[2] / 256 ;
|
||||
set => data[2] = (byte)(value * 256);
|
||||
}
|
||||
|
||||
float IPixel.Green
|
||||
{
|
||||
get => data[1] / 256 ;
|
||||
set => data[1] = (byte)(value * 256);
|
||||
}
|
||||
|
||||
float IPixel.Red
|
||||
{
|
||||
get => data[0] / 256 ;
|
||||
set => data[0] = (byte)(value * 256);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PlainGeometryMesh"
|
||||
// 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 StgSharp.Geometries;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class PlainGeometryMesh
|
||||
{
|
||||
|
||||
private PlainGeometry _shape;
|
||||
private TextureProvider _texture;
|
||||
|
||||
public PlainGeometryMesh([NotNull] PlainGeometry shape, [NotNull] TextureProvider texture)
|
||||
{
|
||||
if (shape.VertexCount > texture.TextureCoordinate.Length) {
|
||||
throw new ArgumentException(
|
||||
paramName:nameof(texture),
|
||||
message:"Amount of texture coordination is too less");
|
||||
}
|
||||
_texture = texture;
|
||||
_shape = shape;
|
||||
}
|
||||
|
||||
// private Image _texture;
|
||||
|
||||
public PlainGeometryMesh(PlainGeometry shape, Image texture, Vec2[] texCoord)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(shape);
|
||||
ArgumentNullException.ThrowIfNull(texCoord);
|
||||
|
||||
if (shape.VertexCount > texCoord.Length) {
|
||||
throw new ArgumentException(
|
||||
paramName:nameof(texCoord),
|
||||
message:"Amount of texture coordination is too less");
|
||||
}
|
||||
_texture = new TextureProvider(texture, texCoord);
|
||||
}
|
||||
|
||||
public Vec4[] VertexArray => _shape.VertexStream;
|
||||
|
||||
public Image TextureImage
|
||||
{
|
||||
get => _texture.ProvideImage();
|
||||
internal set => _texture.ReadImage(value);
|
||||
}
|
||||
|
||||
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureCoord => MemoryMarshal.Cast<Vec2, Vec4>(
|
||||
_texture.TextureCoordinate);
|
||||
|
||||
public PlainGeometryMesh Resize(PlainGeometry newShape)
|
||||
{
|
||||
return new PlainGeometryMesh(newShape, _texture);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="PlainGeometryMesh"
|
||||
// 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 StgSharp.Geometries;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class PlainGeometryMesh
|
||||
{
|
||||
|
||||
private PlainGeometry _shape;
|
||||
private TextureProvider _texture;
|
||||
|
||||
public PlainGeometryMesh([NotNull] PlainGeometry shape, [NotNull] TextureProvider texture)
|
||||
{
|
||||
if (shape.VertexCount > texture.TextureCoordinate.Length) {
|
||||
throw new ArgumentException(
|
||||
paramName:nameof(texture),
|
||||
message:"Amount of texture coordination is too less");
|
||||
}
|
||||
_texture = texture;
|
||||
_shape = shape;
|
||||
}
|
||||
|
||||
// private Image _texture;
|
||||
|
||||
public PlainGeometryMesh(PlainGeometry shape, Image texture, Vec2[] texCoord)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(shape);
|
||||
ArgumentNullException.ThrowIfNull(texCoord);
|
||||
|
||||
if (shape.VertexCount > texCoord.Length) {
|
||||
throw new ArgumentException(
|
||||
paramName:nameof(texCoord),
|
||||
message:"Amount of texture coordination is too less");
|
||||
}
|
||||
_texture = new TextureProvider(texture, texCoord);
|
||||
}
|
||||
|
||||
public Vec4[] VertexArray => _shape.VertexStream;
|
||||
|
||||
public Image TextureImage
|
||||
{
|
||||
get => _texture.ProvideImage();
|
||||
internal set => _texture.ReadImage(value);
|
||||
}
|
||||
|
||||
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
|
||||
|
||||
public ReadOnlySpan<Vec4> TextureCoord => MemoryMarshal.Cast<Vec2, Vec4>(
|
||||
_texture.TextureCoordinate);
|
||||
|
||||
public PlainGeometryMesh Resize(PlainGeometry newShape)
|
||||
{
|
||||
return new PlainGeometryMesh(newShape, _texture);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,249 +1,249 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RenderStream"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.MVVM;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract class RenderStream
|
||||
{
|
||||
|
||||
private Camera nativeCamera;
|
||||
|
||||
private protected ViewPort primeArgs;
|
||||
internal TimeSpanProvider _timeProvider;
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (Width, Height);
|
||||
}
|
||||
|
||||
public abstract bool IsContextSharable { get; }
|
||||
|
||||
public int Height
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => primeArgs.Height;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => primeArgs.Width;
|
||||
}
|
||||
|
||||
public IntPtr Monitor
|
||||
{
|
||||
get => primeArgs.Monitor;
|
||||
internal set => primeArgs.Monitor = value;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => primeArgs.Name;
|
||||
}
|
||||
|
||||
public ViewPort BindedViewPortContext
|
||||
{
|
||||
get => primeArgs;
|
||||
internal set => primeArgs = value;
|
||||
}
|
||||
|
||||
internal IntPtr CanvasHandle
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => primeArgs.ViewPortHandle;
|
||||
}
|
||||
|
||||
internal IntPtr ContextHandle
|
||||
{
|
||||
get => primeArgs.GraphicHandle;
|
||||
private protected set => primeArgs.GraphicHandle = value;
|
||||
}
|
||||
|
||||
protected internal Camera NativeCamera
|
||||
{
|
||||
get => nativeCamera;
|
||||
internal set => nativeCamera = value;
|
||||
}
|
||||
|
||||
protected float FramePassed
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
protected int PassedFrames
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
protected float TimePassed
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (float)_timeProvider.CurrentSecond;
|
||||
}
|
||||
|
||||
protected TimeSpanProvider TimeProvider
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the Size limit of current form
|
||||
/// </summary>
|
||||
/// <param _label="minWidth">
|
||||
/// Minimum width of current form
|
||||
/// </param>
|
||||
/// <param _label="minHeight">
|
||||
/// Minimum height of current form
|
||||
/// </param>
|
||||
/// <param _label="maxWidth">
|
||||
/// Maximum width of current form
|
||||
/// </param>
|
||||
/// <param _label="maxHeight">
|
||||
/// Maximum height of current form
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public abstract void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight);
|
||||
|
||||
public static TTarget ShareContextFrom<TSource, TTarget>([NotNull]TSource source) where TSource : RenderStream
|
||||
where TTarget : RenderStream, new()
|
||||
{
|
||||
TTarget target = new TTarget();
|
||||
target.Initialize(source.BindedViewPortContext, source._timeProvider);
|
||||
return target;
|
||||
}
|
||||
|
||||
/**/
|
||||
protected internal static void PollEvents()
|
||||
{
|
||||
GraphicFramework.glfwPollEvents();
|
||||
}
|
||||
|
||||
private protected void SwapBuffers()
|
||||
{
|
||||
GraphicFramework.glfwSwapBuffers(CanvasHandle);
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
#region native camera operation
|
||||
|
||||
protected abstract void NativeCameraViewRange(
|
||||
Radius fieldOfRange,
|
||||
Vec2 offset,
|
||||
(float frontDepth, float backDepth) viewDepth);
|
||||
|
||||
protected abstract void NativeCameraViewTarget(Vec3 position, Vec3 direction, Vec3 up);
|
||||
|
||||
/// <summary>
|
||||
/// Get <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) uniform from a shader.
|
||||
/// This uniform will be used as projection matrix of this camera. Additionally, for
|
||||
/// multi- shader rendering, each shader requires a uniform, so do not ignore return
|
||||
/// value of this method.
|
||||
/// </summary>
|
||||
/// <param _label="source">
|
||||
/// Shader using this camera
|
||||
/// </param>
|
||||
/// <param _label="name">
|
||||
/// ContextName of projection camera named in shader
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) representing projection
|
||||
/// matrix in shader program.
|
||||
/// </returns>
|
||||
protected abstract Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name);
|
||||
|
||||
#endregion
|
||||
|
||||
#region internal operation
|
||||
|
||||
public void Initialize(ViewPort v, TimeSpanProvider timeProvider)
|
||||
{
|
||||
if (v == null) {
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
primeArgs = v;
|
||||
this._timeProvider = timeProvider;
|
||||
nativeCamera = new Camera();
|
||||
PlatformSpecifiedInitialize();
|
||||
CustomizeInit();
|
||||
GraphicFramework.glfwMakeContextCurrent(IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal abstract void PlatformSpecifiedInitialize();
|
||||
|
||||
internal abstract void Terminate();
|
||||
|
||||
#endregion
|
||||
|
||||
#region public operation
|
||||
|
||||
protected abstract void CustomizeDeinit();
|
||||
|
||||
protected abstract void CustomizeInit();
|
||||
|
||||
/// <summary>
|
||||
/// Marking the start of current render operations, and set this renser context as
|
||||
/// current.
|
||||
/// </summary>
|
||||
public abstract void RenderStart();
|
||||
|
||||
/// <summary>
|
||||
/// Marking the end of current render operations, and release the binding of this renser
|
||||
/// context to current, making it available for another thread as current.
|
||||
/// </summary>
|
||||
public abstract void RenderEnd();
|
||||
|
||||
#endregion
|
||||
|
||||
#region public resource generator
|
||||
|
||||
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
|
||||
|
||||
protected abstract ShaderProgram CreateShaderProgram();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="RenderStream"
|
||||
// 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 StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Graphic;
|
||||
using StgSharp.MVVM;
|
||||
using StgSharp.Timing;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract class RenderStream
|
||||
{
|
||||
|
||||
private Camera nativeCamera;
|
||||
|
||||
private protected ViewPort primeArgs;
|
||||
internal TimeSpanProvider _timeProvider;
|
||||
|
||||
public (int width, int height) Size
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (Width, Height);
|
||||
}
|
||||
|
||||
public abstract bool IsContextSharable { get; }
|
||||
|
||||
public int Height
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => primeArgs.Height;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => primeArgs.Width;
|
||||
}
|
||||
|
||||
public IntPtr Monitor
|
||||
{
|
||||
get => primeArgs.Monitor;
|
||||
internal set => primeArgs.Monitor = value;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => primeArgs.Name;
|
||||
}
|
||||
|
||||
public ViewPort BindedViewPortContext
|
||||
{
|
||||
get => primeArgs;
|
||||
internal set => primeArgs = value;
|
||||
}
|
||||
|
||||
internal IntPtr CanvasHandle
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => primeArgs.ViewPortHandle;
|
||||
}
|
||||
|
||||
internal IntPtr ContextHandle
|
||||
{
|
||||
get => primeArgs.GraphicHandle;
|
||||
private protected set => primeArgs.GraphicHandle = value;
|
||||
}
|
||||
|
||||
protected internal Camera NativeCamera
|
||||
{
|
||||
get => nativeCamera;
|
||||
internal set => nativeCamera = value;
|
||||
}
|
||||
|
||||
protected float FramePassed
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
protected int PassedFrames
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider.CurrentSpan;
|
||||
}
|
||||
|
||||
protected float TimePassed
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (float)_timeProvider.CurrentSecond;
|
||||
}
|
||||
|
||||
protected TimeSpanProvider TimeProvider
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _timeProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the Size limit of current form
|
||||
/// </summary>
|
||||
/// <param _label="minWidth">
|
||||
/// Minimum width of current form
|
||||
/// </param>
|
||||
/// <param _label="minHeight">
|
||||
/// Minimum height of current form
|
||||
/// </param>
|
||||
/// <param _label="maxWidth">
|
||||
/// Maximum width of current form
|
||||
/// </param>
|
||||
/// <param _label="maxHeight">
|
||||
/// Maximum height of current form
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public abstract void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight);
|
||||
|
||||
public static TTarget ShareContextFrom<TSource, TTarget>([NotNull]TSource source) where TSource : RenderStream
|
||||
where TTarget : RenderStream, new()
|
||||
{
|
||||
TTarget target = new TTarget();
|
||||
target.Initialize(source.BindedViewPortContext, source._timeProvider);
|
||||
return target;
|
||||
}
|
||||
|
||||
/**/
|
||||
protected internal static void PollEvents()
|
||||
{
|
||||
GraphicFramework.glfwPollEvents();
|
||||
}
|
||||
|
||||
private protected void SwapBuffers()
|
||||
{
|
||||
GraphicFramework.glfwSwapBuffers(CanvasHandle);
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
#region native camera operation
|
||||
|
||||
protected abstract void NativeCameraViewRange(
|
||||
Radius fieldOfRange,
|
||||
Vec2 offset,
|
||||
(float frontDepth, float backDepth) viewDepth);
|
||||
|
||||
protected abstract void NativeCameraViewTarget(Vec3 position, Vec3 direction, Vec3 up);
|
||||
|
||||
/// <summary>
|
||||
/// Get <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) uniform from a shader.
|
||||
/// This uniform will be used as projection matrix of this camera. Additionally, for
|
||||
/// multi- shader rendering, each shader requires a uniform, so do not ignore return
|
||||
/// value of this method.
|
||||
/// </summary>
|
||||
/// <param _label="source">
|
||||
/// Shader using this camera
|
||||
/// </param>
|
||||
/// <param _label="name">
|
||||
/// ContextName of projection camera named in shader
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see cref="Uniform{T}" />(TView is <see cref="Matrix44" />) representing projection
|
||||
/// matrix in shader program.
|
||||
/// </returns>
|
||||
protected abstract Uniform<Matrix44> NativeCameraUniform(ShaderProgram source, string name);
|
||||
|
||||
#endregion
|
||||
|
||||
#region internal operation
|
||||
|
||||
public void Initialize(ViewPort v, TimeSpanProvider timeProvider)
|
||||
{
|
||||
if (v == null) {
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
primeArgs = v;
|
||||
this._timeProvider = timeProvider;
|
||||
nativeCamera = new Camera();
|
||||
PlatformSpecifiedInitialize();
|
||||
CustomizeInit();
|
||||
GraphicFramework.glfwMakeContextCurrent(IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal abstract void PlatformSpecifiedInitialize();
|
||||
|
||||
internal abstract void Terminate();
|
||||
|
||||
#endregion
|
||||
|
||||
#region public operation
|
||||
|
||||
protected abstract void CustomizeDeinit();
|
||||
|
||||
protected abstract void CustomizeInit();
|
||||
|
||||
/// <summary>
|
||||
/// Marking the start of current render operations, and set this renser context as
|
||||
/// current.
|
||||
/// </summary>
|
||||
public abstract void RenderStart();
|
||||
|
||||
/// <summary>
|
||||
/// Marking the end of current render operations, and release the binding of this renser
|
||||
/// context to current, making it available for another thread as current.
|
||||
/// </summary>
|
||||
public abstract void RenderEnd();
|
||||
|
||||
#endregion
|
||||
|
||||
#region public resource generator
|
||||
|
||||
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
|
||||
|
||||
protected abstract ShaderProgram CreateShaderProgram();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,203 +1,203 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ShaderGenerator"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public class ShaderGenerator
|
||||
{
|
||||
|
||||
private Dictionary<int, ShaderParameter> uniformDefine;
|
||||
private List<string> codeList;
|
||||
private List<ShaderFunction> usedShaderFunctions;
|
||||
|
||||
public Uniform<T> DefineUniform<T>(string name, int index) where T: unmanaged
|
||||
{
|
||||
ShaderParameter p = new ShaderParameter(name, ShaderParameter.TypeMarshal<T>());
|
||||
uniformDefine.Add(index, p);
|
||||
|
||||
// return new Uniform<TView>();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ShaderFunction
|
||||
{
|
||||
|
||||
private List<string> codeList;
|
||||
private List<ShaderParameter> inputList;
|
||||
private ShaderParameter outPut;
|
||||
private string name;
|
||||
|
||||
public int ParameterCount => inputList.Count;
|
||||
|
||||
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
|
||||
{
|
||||
if (inputParams.Length != function.ParameterCount)
|
||||
{
|
||||
// Param list length not equal
|
||||
throw new ArgumentException(
|
||||
"Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
if (!ShaderParameter.IsSameType(outPut, function.outPut))
|
||||
{
|
||||
// Type of returning value not equal
|
||||
throw new ArgumentException(
|
||||
"Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
for (int i = 0; i < inputParams.Length; i++)
|
||||
{
|
||||
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
|
||||
{
|
||||
// Input type not match
|
||||
throw new InvalidCastException(
|
||||
"Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
}
|
||||
string codeLine = string.Empty; // adding a line like " outvalue = Func(input1, input2,...); "
|
||||
if (outPut != ShaderParameter.Void) {
|
||||
codeLine += $"{outPut.name} = ";
|
||||
}
|
||||
codeLine += $"{function.name}(";
|
||||
foreach (ShaderParameter inputParam in inputParams) {
|
||||
codeLine += inputParam.name;
|
||||
}
|
||||
codeLine += ");\n";
|
||||
codeList.Add(codeLine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ShaderParameter
|
||||
{
|
||||
|
||||
public static readonly ShaderParameter Void = new ShaderParameter(
|
||||
string.Empty, InternalShaderType.Void);
|
||||
internal readonly bool isReadOnly;
|
||||
internal readonly InternalShaderType type;
|
||||
internal readonly string name;
|
||||
|
||||
public ShaderParameter(string name, InternalShaderType type)
|
||||
{
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
isReadOnly = false;
|
||||
}
|
||||
|
||||
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
|
||||
{
|
||||
if (param1.type != InternalShaderType.Struct)
|
||||
{
|
||||
return param1.type == param2.type;
|
||||
} else
|
||||
{
|
||||
throw new Exception("Struct is currently not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public static InternalShaderType TypeMarshal<T>() where T: unmanaged
|
||||
{
|
||||
switch (Type.GetTypeCode(typeof(T)))
|
||||
{
|
||||
case TypeCode.Single:
|
||||
return InternalShaderType.Float;
|
||||
case TypeCode.Double:
|
||||
return InternalShaderType.Double;
|
||||
case TypeCode.Int32:
|
||||
return InternalShaderType.Int;
|
||||
case TypeCode.UInt32:
|
||||
return InternalShaderType.UInt;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (typeof(T).Name)
|
||||
{
|
||||
case "vec4d":
|
||||
return InternalShaderType.Vector4;
|
||||
case "Matrix2x2":
|
||||
return InternalShaderType.Matrix2x2;
|
||||
case "Matrix2x3":
|
||||
return InternalShaderType.Matrix2x3;
|
||||
case "Matrix2x4":
|
||||
return InternalShaderType.Matrix2x4;
|
||||
case "Matrix3x2":
|
||||
return InternalShaderType.Matrix3x2;
|
||||
case "Matrix3x3":
|
||||
return InternalShaderType.Matrix3x3;
|
||||
case "Matrix3x4":
|
||||
return InternalShaderType.Matrix3x4;
|
||||
case "Matrix4x2":
|
||||
return InternalShaderType.Matrix4x2;
|
||||
case "Matrix4x3":
|
||||
return InternalShaderType.Matrix4x3;
|
||||
case "Matrix4x4":
|
||||
return InternalShaderType.Matrix4x4;
|
||||
default:
|
||||
throw new ArgumentException("Not supported shader data type.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum InternalShaderType
|
||||
{
|
||||
#pragma warning disable CS1591
|
||||
Struct,
|
||||
Void,
|
||||
Int,
|
||||
UInt,
|
||||
Float,
|
||||
Double,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
VectorD2,
|
||||
VectorD3,
|
||||
VectorD4,
|
||||
Matrix2x2,
|
||||
Matrix2x3,
|
||||
Matrix2x4,
|
||||
Matrix3x2,
|
||||
Matrix3x3,
|
||||
Matrix3x4,
|
||||
Matrix4x2,
|
||||
Matrix4x3,
|
||||
Matrix4x4,
|
||||
#pragma warning restore CS1591
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ShaderGenerator"
|
||||
// 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 StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Mathematics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.ShaderEdit
|
||||
{
|
||||
public class ShaderGenerator
|
||||
{
|
||||
|
||||
private Dictionary<int, ShaderParameter> uniformDefine;
|
||||
private List<string> codeList;
|
||||
private List<ShaderFunction> usedShaderFunctions;
|
||||
|
||||
public Uniform<T> DefineUniform<T>(string name, int index) where T: unmanaged
|
||||
{
|
||||
ShaderParameter p = new ShaderParameter(name, ShaderParameter.TypeMarshal<T>());
|
||||
uniformDefine.Add(index, p);
|
||||
|
||||
// return new Uniform<TView>();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ShaderFunction
|
||||
{
|
||||
|
||||
private List<string> codeList;
|
||||
private List<ShaderParameter> inputList;
|
||||
private ShaderParameter outPut;
|
||||
private string name;
|
||||
|
||||
public int ParameterCount => inputList.Count;
|
||||
|
||||
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
|
||||
{
|
||||
if (inputParams.Length != function.ParameterCount)
|
||||
{
|
||||
// Param list length not equal
|
||||
throw new ArgumentException(
|
||||
"Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
if (!ShaderParameter.IsSameType(outPut, function.outPut))
|
||||
{
|
||||
// Type of returning value not equal
|
||||
throw new ArgumentException(
|
||||
"Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
for (int i = 0; i < inputParams.Length; i++)
|
||||
{
|
||||
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
|
||||
{
|
||||
// Input type not match
|
||||
throw new InvalidCastException(
|
||||
"Provided parameters does not match function's parameter list.");
|
||||
}
|
||||
}
|
||||
string codeLine = string.Empty; // adding a line like " outvalue = Func(input1, input2,...); "
|
||||
if (outPut != ShaderParameter.Void) {
|
||||
codeLine += $"{outPut.name} = ";
|
||||
}
|
||||
codeLine += $"{function.name}(";
|
||||
foreach (ShaderParameter inputParam in inputParams) {
|
||||
codeLine += inputParam.name;
|
||||
}
|
||||
codeLine += ");\n";
|
||||
codeList.Add(codeLine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ShaderParameter
|
||||
{
|
||||
|
||||
public static readonly ShaderParameter Void = new ShaderParameter(
|
||||
string.Empty, InternalShaderType.Void);
|
||||
internal readonly bool isReadOnly;
|
||||
internal readonly InternalShaderType type;
|
||||
internal readonly string name;
|
||||
|
||||
public ShaderParameter(string name, InternalShaderType type)
|
||||
{
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
isReadOnly = false;
|
||||
}
|
||||
|
||||
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
|
||||
{
|
||||
if (param1.type != InternalShaderType.Struct)
|
||||
{
|
||||
return param1.type == param2.type;
|
||||
} else
|
||||
{
|
||||
throw new Exception("Struct is currently not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public static InternalShaderType TypeMarshal<T>() where T: unmanaged
|
||||
{
|
||||
switch (Type.GetTypeCode(typeof(T)))
|
||||
{
|
||||
case TypeCode.Single:
|
||||
return InternalShaderType.Float;
|
||||
case TypeCode.Double:
|
||||
return InternalShaderType.Double;
|
||||
case TypeCode.Int32:
|
||||
return InternalShaderType.Int;
|
||||
case TypeCode.UInt32:
|
||||
return InternalShaderType.UInt;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (typeof(T).Name)
|
||||
{
|
||||
case "vec4d":
|
||||
return InternalShaderType.Vector4;
|
||||
case "Matrix2x2":
|
||||
return InternalShaderType.Matrix2x2;
|
||||
case "Matrix2x3":
|
||||
return InternalShaderType.Matrix2x3;
|
||||
case "Matrix2x4":
|
||||
return InternalShaderType.Matrix2x4;
|
||||
case "Matrix3x2":
|
||||
return InternalShaderType.Matrix3x2;
|
||||
case "Matrix3x3":
|
||||
return InternalShaderType.Matrix3x3;
|
||||
case "Matrix3x4":
|
||||
return InternalShaderType.Matrix3x4;
|
||||
case "Matrix4x2":
|
||||
return InternalShaderType.Matrix4x2;
|
||||
case "Matrix4x3":
|
||||
return InternalShaderType.Matrix4x3;
|
||||
case "Matrix4x4":
|
||||
return InternalShaderType.Matrix4x4;
|
||||
default:
|
||||
throw new ArgumentException("Not supported shader data type.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum InternalShaderType
|
||||
{
|
||||
#pragma warning disable CS1591
|
||||
Struct,
|
||||
Void,
|
||||
Int,
|
||||
UInt,
|
||||
Float,
|
||||
Double,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
VectorD2,
|
||||
VectorD3,
|
||||
VectorD4,
|
||||
Matrix2x2,
|
||||
Matrix2x3,
|
||||
Matrix2x4,
|
||||
Matrix3x2,
|
||||
Matrix3x3,
|
||||
Matrix3x4,
|
||||
Matrix4x2,
|
||||
Matrix4x3,
|
||||
Matrix4x4,
|
||||
#pragma warning restore CS1591
|
||||
}
|
||||
}
|
||||
@@ -1,96 +1,96 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ShaderStruct"
|
||||
// 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 StgSharp.Graphics;
|
||||
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 class ShaderStructMember
|
||||
{
|
||||
|
||||
internal InternalShaderType type;
|
||||
internal object value;
|
||||
|
||||
}
|
||||
|
||||
public class ShaderStruct
|
||||
{
|
||||
|
||||
internal Dictionary<GlHandle, ShaderStructMember> uniformPair;
|
||||
|
||||
internal ShaderStruct() { }
|
||||
|
||||
public ShaderStruct(params (GlHandle, ShaderStructMember)[] uniformPairs)
|
||||
{
|
||||
uniformPair = new Dictionary<GlHandle, ShaderStructMember>();
|
||||
if (uniformPairs.Length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ((GlHandle, ShaderStructMember) item in uniformPairs) {
|
||||
uniformPair.Add(item.Item1, item.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
OpenglContext* gl = (OpenglContext*)OpenGL.OpenGLFunction.CurrentGL.ContextHandle;
|
||||
foreach (KeyValuePair<GlHandle, ShaderStructMember> uniform in uniformPair)
|
||||
{
|
||||
int id = uniform.Key.SignedValue;
|
||||
ShaderStructMember s = uniform.Value;
|
||||
switch (s.type)
|
||||
{
|
||||
case InternalShaderType.Struct:
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Struct\" defined in this self define type");
|
||||
case InternalShaderType.Void:
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Void\" defined in this self define type");
|
||||
case InternalShaderType.Float:
|
||||
gl->glUniform1f(id, (float)s.value);
|
||||
break;
|
||||
case InternalShaderType.Int:
|
||||
gl->glUniform1f(id, (int)s.value);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Unknown\" defined in this self define type");
|
||||
}
|
||||
}
|
||||
}//------------------------------------ End of Class ---------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ShaderStruct"
|
||||
// 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 StgSharp.Graphics;
|
||||
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 class ShaderStructMember
|
||||
{
|
||||
|
||||
internal InternalShaderType type;
|
||||
internal object value;
|
||||
|
||||
}
|
||||
|
||||
public class ShaderStruct
|
||||
{
|
||||
|
||||
internal Dictionary<GlHandle, ShaderStructMember> uniformPair;
|
||||
|
||||
internal ShaderStruct() { }
|
||||
|
||||
public ShaderStruct(params (GlHandle, ShaderStructMember)[] uniformPairs)
|
||||
{
|
||||
uniformPair = new Dictionary<GlHandle, ShaderStructMember>();
|
||||
if (uniformPairs.Length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ((GlHandle, ShaderStructMember) item in uniformPairs) {
|
||||
uniformPair.Add(item.Item1, item.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
OpenglContext* gl = (OpenglContext*)OpenGL.OpenGLFunction.CurrentGL.ContextHandle;
|
||||
foreach (KeyValuePair<GlHandle, ShaderStructMember> uniform in uniformPair)
|
||||
{
|
||||
int id = uniform.Key.SignedValue;
|
||||
ShaderStructMember s = uniform.Value;
|
||||
switch (s.type)
|
||||
{
|
||||
case InternalShaderType.Struct:
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Struct\" defined in this self define type");
|
||||
case InternalShaderType.Void:
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Void\" defined in this self define type");
|
||||
case InternalShaderType.Float:
|
||||
gl->glUniform1f(id, (float)s.value);
|
||||
break;
|
||||
case InternalShaderType.Int:
|
||||
gl->glUniform1f(id, (int)s.value);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
throw new ArgumentException(
|
||||
"Incorrect type \"Unknown\" defined in this self define type");
|
||||
}
|
||||
}
|
||||
}//------------------------------------ End of Class ---------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TexturePipeline"
|
||||
// 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 StgSharp.PipeLine;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class TexturePipeline : IPipeLineConnectionPayload
|
||||
{
|
||||
|
||||
private Image _value;
|
||||
|
||||
public TexturePipeline(Image i)
|
||||
{
|
||||
_value = i;
|
||||
}
|
||||
|
||||
public object? ValueDefault => null;
|
||||
|
||||
public object Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
if (value is not Image image) {
|
||||
throw new ArgumentException("Value must be of type Image");
|
||||
}
|
||||
_value = image;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TexturePipeline"
|
||||
// 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 StgSharp.PipeLine;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class TexturePipeline : IPipeLineConnectionPayload
|
||||
{
|
||||
|
||||
private Image _value;
|
||||
|
||||
public TexturePipeline(Image i)
|
||||
{
|
||||
_value = i;
|
||||
}
|
||||
|
||||
public object? ValueDefault => null;
|
||||
|
||||
public object Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(value);
|
||||
if (value is not Image image) {
|
||||
throw new ArgumentException("Value must be of type Image");
|
||||
}
|
||||
_value = image;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TextureProvider"
|
||||
// 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 StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class TextureProvider : IImageProvider
|
||||
{
|
||||
|
||||
private Vec2[] _texCoord;
|
||||
private Image _tex;
|
||||
|
||||
public TextureProvider(Image image, Vec2[] coord)
|
||||
{
|
||||
_tex = image;
|
||||
_texCoord = coord;
|
||||
}
|
||||
|
||||
public ref Vec2 this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref _texCoord[index];
|
||||
}
|
||||
|
||||
public Span<Vec2> TextureCoordinate
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new Span<Vec2>(_texCoord);
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
{
|
||||
return _tex;
|
||||
}
|
||||
|
||||
public void ReadImage(IImageProvider provider)
|
||||
{
|
||||
_tex = provider.ProvideImage();
|
||||
}
|
||||
|
||||
public void UpdateFromImage([NotNull]Image i)
|
||||
{
|
||||
if (i == _tex) {
|
||||
return;
|
||||
}
|
||||
if (i.Size == _tex.Size)
|
||||
{
|
||||
_tex = i;
|
||||
} else
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Size of {nameof(i)} does not equals to current image.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="TextureProvider"
|
||||
// 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 StgSharp.Mathematics.Graphic;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class TextureProvider : IImageProvider
|
||||
{
|
||||
|
||||
private Vec2[] _texCoord;
|
||||
private Image _tex;
|
||||
|
||||
public TextureProvider(Image image, Vec2[] coord)
|
||||
{
|
||||
_tex = image;
|
||||
_texCoord = coord;
|
||||
}
|
||||
|
||||
public ref Vec2 this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref _texCoord[index];
|
||||
}
|
||||
|
||||
public Span<Vec2> TextureCoordinate
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new Span<Vec2>(_texCoord);
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
{
|
||||
return _tex;
|
||||
}
|
||||
|
||||
public void ReadImage(IImageProvider provider)
|
||||
{
|
||||
_tex = provider.ProvideImage();
|
||||
}
|
||||
|
||||
public void UpdateFromImage([NotNull]Image i)
|
||||
{
|
||||
if (i == _tex) {
|
||||
return;
|
||||
}
|
||||
if (i.Size == _tex.Size)
|
||||
{
|
||||
_tex = i;
|
||||
} else
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Size of {nameof(i)} does not equals to current image.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="vkEnum"
|
||||
// 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.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.Vulkan
|
||||
{
|
||||
internal enum VkStructureType : uint
|
||||
{
|
||||
|
||||
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
|
||||
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
|
||||
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
|
||||
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
|
||||
VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
|
||||
VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
|
||||
VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
|
||||
|
||||
}
|
||||
|
||||
internal enum VkResult
|
||||
{
|
||||
|
||||
VK_SUCCESS = 0,
|
||||
VK_NOT_READY = 1,
|
||||
VK_TIMEOUT = 2,
|
||||
VK_EVENT_SET = 3,
|
||||
VK_EVENT_RESET = 4,
|
||||
VK_INCOMPLETE = 5,
|
||||
VK_ERROR_OUT_OF_HOST_MEMORY = -1,
|
||||
VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
|
||||
VK_ERROR_INITIALIZATION_FAILED = -3,
|
||||
VK_ERROR_DEVICE_LOST = -4,
|
||||
VK_ERROR_MEMORY_MAP_FAILED = -5,
|
||||
VK_ERROR_LAYER_NOT_PRESENT = -6,
|
||||
VK_ERROR_EXTENSION_NOT_PRESENT = -7,
|
||||
VK_ERROR_FEATURE_NOT_PRESENT = -8,
|
||||
VK_ERROR_INCOMPATIBLE_DRIVER = -9,
|
||||
VK_ERROR_TOO_MANY_OBJECTS = -10,
|
||||
VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
|
||||
VK_ERROR_SURFACE_LOST_KHR = -1000000000,
|
||||
VK_SUBOPTIMAL_KHR = 1000001003,
|
||||
VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
|
||||
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
|
||||
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
|
||||
VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
|
||||
VK_RESULT_MAX_ENUM = 0x7FFFFFFF
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="vkEnum"
|
||||
// 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.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics.Vulkan
|
||||
{
|
||||
internal enum VkStructureType : uint
|
||||
{
|
||||
|
||||
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
|
||||
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
|
||||
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
|
||||
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
|
||||
VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
|
||||
VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
|
||||
VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
|
||||
|
||||
}
|
||||
|
||||
internal enum VkResult
|
||||
{
|
||||
|
||||
VK_SUCCESS = 0,
|
||||
VK_NOT_READY = 1,
|
||||
VK_TIMEOUT = 2,
|
||||
VK_EVENT_SET = 3,
|
||||
VK_EVENT_RESET = 4,
|
||||
VK_INCOMPLETE = 5,
|
||||
VK_ERROR_OUT_OF_HOST_MEMORY = -1,
|
||||
VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
|
||||
VK_ERROR_INITIALIZATION_FAILED = -3,
|
||||
VK_ERROR_DEVICE_LOST = -4,
|
||||
VK_ERROR_MEMORY_MAP_FAILED = -5,
|
||||
VK_ERROR_LAYER_NOT_PRESENT = -6,
|
||||
VK_ERROR_EXTENSION_NOT_PRESENT = -7,
|
||||
VK_ERROR_FEATURE_NOT_PRESENT = -8,
|
||||
VK_ERROR_INCOMPATIBLE_DRIVER = -9,
|
||||
VK_ERROR_TOO_MANY_OBJECTS = -10,
|
||||
VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
|
||||
VK_ERROR_SURFACE_LOST_KHR = -1000000000,
|
||||
VK_SUBOPTIMAL_KHR = 1000001003,
|
||||
VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
|
||||
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
|
||||
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
|
||||
VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
|
||||
VK_RESULT_MAX_ENUM = 0x7FFFFFFF
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="vkHandle"
|
||||
// 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.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.Vulkan
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 8)]
|
||||
public struct vkHandle
|
||||
{
|
||||
|
||||
[FieldOffset(0)] public int SignedHalfValue;
|
||||
[FieldOffset(0)] public IntPtr Handle;
|
||||
[FieldOffset(0)] public IntPtr UnsignedHandle;
|
||||
[FieldOffset(0)] public uint HalfValue;
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="vkHandle"
|
||||
// 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.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics.Vulkan
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 8)]
|
||||
public struct vkHandle
|
||||
{
|
||||
|
||||
[FieldOffset(0)] public int SignedHalfValue;
|
||||
[FieldOffset(0)] public IntPtr Handle;
|
||||
[FieldOffset(0)] public IntPtr UnsignedHandle;
|
||||
[FieldOffset(0)] public uint HalfValue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="framework"
|
||||
// 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.Runtime.InteropServices;
|
||||
|
||||
#if Windows
|
||||
// using Windows.Win32;
|
||||
#endif
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Function handler to load an opengl function by searching its _label.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// the _label of the Opengl function
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// An Intptr value representing the pointer to the function
|
||||
/// </returns>
|
||||
public delegate IntPtr glLoader(
|
||||
string name
|
||||
);
|
||||
|
||||
#region StgSharpDele
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate void FrameBufferSizeHandler(
|
||||
IntPtr window,
|
||||
int width,
|
||||
int height
|
||||
);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate void FramePositionHandler(
|
||||
IntPtr window,
|
||||
float width,
|
||||
float height
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region glDEBUG
|
||||
|
||||
internal unsafe delegate void GLDEBUGPROC(
|
||||
int source,
|
||||
int type,
|
||||
uint id,
|
||||
int severity,
|
||||
int length,
|
||||
sbyte* message,
|
||||
void* userParam
|
||||
);
|
||||
internal unsafe delegate void GLDEBUGPROCARB(
|
||||
int source,
|
||||
int type,
|
||||
uint id,
|
||||
int severity,
|
||||
int length,
|
||||
sbyte* message,
|
||||
void* userParam
|
||||
);
|
||||
internal unsafe delegate void GLDEBUGPROCKHR(
|
||||
int source,
|
||||
int type,
|
||||
uint id,
|
||||
int severity,
|
||||
int length,
|
||||
sbyte* message,
|
||||
void* userParam
|
||||
);
|
||||
internal unsafe delegate void GLDEBUGPROCAMD(
|
||||
uint id,
|
||||
int category,
|
||||
int severity,
|
||||
int length,
|
||||
sbyte* message,
|
||||
void* userParam
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="framework"
|
||||
// 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.Runtime.InteropServices;
|
||||
|
||||
#if Windows
|
||||
// using Windows.Win32;
|
||||
#endif
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Function handler to load an opengl function by searching its _label.
|
||||
/// </summary>
|
||||
/// <param _label="name">
|
||||
/// the _label of the Opengl function
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// An Intptr value representing the pointer to the function
|
||||
/// </returns>
|
||||
public delegate IntPtr glLoader(
|
||||
string name
|
||||
);
|
||||
|
||||
#region StgSharpDele
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate void FrameBufferSizeHandler(
|
||||
IntPtr window,
|
||||
int width,
|
||||
int height
|
||||
);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate void FramePositionHandler(
|
||||
IntPtr window,
|
||||
float width,
|
||||
float height
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region glDEBUG
|
||||
|
||||
internal unsafe delegate void GLDEBUGPROC(
|
||||
int source,
|
||||
int type,
|
||||
uint id,
|
||||
int severity,
|
||||
int length,
|
||||
sbyte* message,
|
||||
void* userParam
|
||||
);
|
||||
internal unsafe delegate void GLDEBUGPROCARB(
|
||||
int source,
|
||||
int type,
|
||||
uint id,
|
||||
int severity,
|
||||
int length,
|
||||
sbyte* message,
|
||||
void* userParam
|
||||
);
|
||||
internal unsafe delegate void GLDEBUGPROCKHR(
|
||||
int source,
|
||||
int type,
|
||||
uint id,
|
||||
int severity,
|
||||
int length,
|
||||
sbyte* message,
|
||||
void* userParam
|
||||
);
|
||||
internal unsafe delegate void GLDEBUGPROCAMD(
|
||||
uint id,
|
||||
int category,
|
||||
int severity,
|
||||
int length,
|
||||
sbyte* message,
|
||||
void* userParam
|
||||
);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="frameworkSyncContext"
|
||||
// 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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Threading
|
||||
{
|
||||
public class FrameworkSyncContext : SynchronizationContext
|
||||
{
|
||||
|
||||
private readonly BlockingCollection<SendOrPostCallback> _syncContexts = [];
|
||||
private readonly Thread _mainThread = Thread.CurrentThread;
|
||||
|
||||
public FrameworkSyncContext()
|
||||
{
|
||||
_mainThread = Thread.CurrentThread;
|
||||
}
|
||||
|
||||
public static FrameworkSyncContext MainThreadContext
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = new FrameworkSyncContext();
|
||||
|
||||
public override void Post(SendOrPostCallback d, object state)
|
||||
{
|
||||
_syncContexts.Add(d);
|
||||
}
|
||||
|
||||
public override void Send(SendOrPostCallback d, object state)
|
||||
{
|
||||
if (Thread.CurrentThread == _mainThread)
|
||||
{
|
||||
d(state);
|
||||
} else
|
||||
{
|
||||
Post(d, state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="frameworkSyncContext"
|
||||
// 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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Threading
|
||||
{
|
||||
public class FrameworkSyncContext : SynchronizationContext
|
||||
{
|
||||
|
||||
private readonly BlockingCollection<SendOrPostCallback> _syncContexts = [];
|
||||
private readonly Thread _mainThread = Thread.CurrentThread;
|
||||
|
||||
public FrameworkSyncContext()
|
||||
{
|
||||
_mainThread = Thread.CurrentThread;
|
||||
}
|
||||
|
||||
public static FrameworkSyncContext MainThreadContext
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get;
|
||||
} = new FrameworkSyncContext();
|
||||
|
||||
public override void Post(SendOrPostCallback d, object state)
|
||||
{
|
||||
_syncContexts.Add(d);
|
||||
}
|
||||
|
||||
public override void Send(SendOrPostCallback d, object state)
|
||||
{
|
||||
if (Thread.CurrentThread == _mainThread)
|
||||
{
|
||||
d(state);
|
||||
} else
|
||||
{
|
||||
Post(d, state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user