daily update on 2024.03.18 by itload youmu
This commit is contained in:
@@ -1,4 +1,34 @@
|
||||
using StgSharp.Logic;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GLonRender.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -12,23 +42,15 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
internal unsafe partial class GLonRender : IglFunc
|
||||
{
|
||||
internal GLcontext* api;
|
||||
|
||||
private FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
|
||||
internal GLcontext* api;
|
||||
|
||||
internal GLonRender(GLcontext* context)
|
||||
{
|
||||
api = context;
|
||||
}
|
||||
|
||||
GLcontext* IglFunc.Context
|
||||
{
|
||||
get => api;
|
||||
}
|
||||
|
||||
void IglFunc.SwitchContext()
|
||||
{
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.ActiveTexture(uint type)
|
||||
{
|
||||
@@ -87,35 +109,6 @@ namespace StgSharp.Graphics
|
||||
while (api->glGetError() != 0) { }
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
|
||||
{
|
||||
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
|
||||
fixed (byte* streamPtr = stream)
|
||||
{
|
||||
api->glShaderSource(shaderHandle.DirectValue, 1, &streamPtr, (void*)0);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
glHandleSet IglFunc.CreateShaderSet(int count, ShaderType type)
|
||||
{
|
||||
glHandleSet ret = new glHandleSet(count);
|
||||
uint t = (uint)type;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
uint id = api->glCreateShader(t);
|
||||
if (id == 0)
|
||||
{
|
||||
uint error = api->glGetError();
|
||||
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
|
||||
throw new Exception();
|
||||
}
|
||||
ret.SetValue(i, id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.CompileShader(glHandle shaderhandle)
|
||||
{
|
||||
@@ -139,6 +132,25 @@ namespace StgSharp.Graphics
|
||||
return h;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
glHandleSet IglFunc.CreateShaderSet(int count, ShaderType type)
|
||||
{
|
||||
glHandleSet ret = new glHandleSet(count);
|
||||
uint t = (uint)type;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
uint id = api->glCreateShader(t);
|
||||
if (id == 0)
|
||||
{
|
||||
uint error = api->glGetError();
|
||||
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
|
||||
throw new Exception();
|
||||
}
|
||||
ret.SetValue(i, id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsafe IntPtr IglFunc.CreateWindowHandle(
|
||||
int width, int height, string tittle, IntPtr monitor, Form share)
|
||||
{
|
||||
@@ -147,15 +159,15 @@ namespace StgSharp.Graphics
|
||||
if (share == null)
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(
|
||||
width, height, tittleBytes, monitor, IntPtr.Zero);
|
||||
width, height, tittleBytes, monitor, (GLFWwindow*)IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
windowPtr = InternalIO.glfwCreateWindow(
|
||||
width, height, tittleBytes, monitor, share.windowID);
|
||||
width, height, tittleBytes, monitor, share.id);
|
||||
}
|
||||
|
||||
if ((long)windowPtr == -1 || (long)windowPtr == -2)
|
||||
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
|
||||
{
|
||||
throw new Exception("Cannot create window instance!");
|
||||
}
|
||||
@@ -180,14 +192,14 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
|
||||
{
|
||||
api->glDeleteBuffers((uint)handle.length, (uint*)handle.handle);
|
||||
api->glDeleteBuffers((uint)handle.length, handle.handle);
|
||||
handle.Free();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays)
|
||||
{
|
||||
api->glDeleteVertexArrays((uint)arrays.length, (uint*)arrays.handle);
|
||||
api->glDeleteVertexArrays((uint)arrays.length, arrays.handle);
|
||||
arrays.Free();
|
||||
}
|
||||
|
||||
@@ -211,18 +223,22 @@ namespace StgSharp.Graphics
|
||||
|
||||
default:
|
||||
InternalIO.InternalWriteLog(
|
||||
$"Parameter error in parameter {nameof(type)} method DrawElements. " +
|
||||
$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are suporrted.",
|
||||
$"{($"Parameter error in parameter {nameof(type)} method DrawElements. ")}{($"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are suporrted.")}",
|
||||
LogType.Error);
|
||||
return;
|
||||
}
|
||||
api->glDrawElements((uint)mode, count, a, (void*)ptr);
|
||||
}
|
||||
|
||||
void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params M128[] param)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe glHandleSet IglFunc.GenBuffers(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet((int)count);
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
api->glGenBuffers((uint)count, h.handle);
|
||||
return h;
|
||||
}
|
||||
@@ -230,7 +246,7 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe glHandleSet IglFunc.GenTextures(int count)
|
||||
{
|
||||
glHandleSet h = new glHandleSet((int)count);
|
||||
glHandleSet h = new glHandleSet(count);
|
||||
api->glGenTextures((uint)count, h.handle);
|
||||
return h;
|
||||
}
|
||||
@@ -256,18 +272,28 @@ namespace StgSharp.Graphics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe bool IglFunc.GetWindowShouldClose(Form form)
|
||||
{
|
||||
return InternalIO.glfwWindowShouldClose(form.windowID) == 0;
|
||||
return InternalIO.glfwWindowShouldClose(form.id) == 0;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
|
||||
{
|
||||
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
|
||||
fixed (byte* streamPtr = stream)
|
||||
{
|
||||
api->glShaderSource(shaderHandle.DirectValue, 1, &streamPtr, (void*)0);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void IglFunc.MakeContexCurrent(Form form)
|
||||
{
|
||||
if (form.windowID == IntPtr.Zero)
|
||||
if (form.WindowID == IntPtr.Zero)
|
||||
{
|
||||
InternalIO.InternalWriteLog($"From {nameof(form)} is not initted.", LogType.Warning);
|
||||
return;
|
||||
}
|
||||
InternalIO.glfwMakeContextCurrent(form.windowID);
|
||||
InternalIO.glfwMakeContextCurrent(form.id);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -290,11 +316,13 @@ namespace StgSharp.Graphics
|
||||
return;
|
||||
}
|
||||
fixed (void* bufferPtr = bufferArray)
|
||||
{
|
||||
api->glBufferData(
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
(uint)bufferType,
|
||||
(IntPtr)size,
|
||||
(IntPtr)bufferPtr,
|
||||
(uint)usage);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -305,6 +333,10 @@ namespace StgSharp.Graphics
|
||||
api->glEnableVertexAttribArray(index);
|
||||
}
|
||||
|
||||
void IglFunc.SwitchContext()
|
||||
{
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IglFunc.TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
|
||||
{
|
||||
@@ -331,9 +363,8 @@ namespace StgSharp.Graphics
|
||||
api->glViewport(x, y, width, height);
|
||||
}
|
||||
|
||||
void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params M128[] param)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
GLcontext* IglFunc.Context
|
||||
=> api;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user