using StgSharp.Logic; using StgSharp.Math; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace StgSharp.Graphics { internal unsafe partial class GLonUpdate : IglFunc { internal IntPtr ActiveTexturePtr = (IntPtr)(delegate*)&InternalActiveTexture; internal IntPtr AttachShaderPtr = (IntPtr)(delegate*)&InternalAttachShader; internal IntPtr BindBufferPtr = (IntPtr)(delegate*)&InternalBindBuffer; internal IntPtr ClearColorPtr = (IntPtr)(delegate*)&InternalClearColor; internal IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*)&InternalClearGraphicError; internal IntPtr CompileShaderPtr = (IntPtr)(delegate*)&InternalCompileShader; IntPtr BindTexturePtr = (IntPtr)(delegate*)&InternalBindTexture; IntPtr BindVertexArrayPtr = (IntPtr)(delegate*)&InternalBindVertexArray; private IntPtr ClearPtr = (IntPtr)(delegate*)&InternalClear; private static void InternalActiveTexture() { uint t; paramQueue.TryDequeue(out t); paramQueue.context->glActiveTexture(t); } private static void InternalAttachShader() { uint p, s; paramQueue.TryDequeue(out p, out s); paramQueue.context->glAttachShader(p, s); } private static void InternalBindBuffer() { M128 m = default; paramQueue.TryDequeue(out m); paramQueue.context->glBindBuffer(m.UInt32[0], *(uint*)m.IntPtr1); } private static void InternalBindTexture() { uint t, te; paramQueue.TryDequeue(out t, out te); paramQueue.context->glBindTexture(t, te); } private static void InternalBindVertexArray() { IntPtr i; paramQueue.TryDequeue(out i); paramQueue.context->glBindVertexArray(*(uint*)i); } private static void InternalClear() { uint mt; paramQueue.TryDequeue(out mt); paramQueue.context->glClear(mt); } private static void InternalClearColor() { float r, g, b, a; paramQueue.TryDequeue(out r, out g, out b, out a); paramQueue.context->glClearColor(r, g, b, a); } private static void InternalClearGraphicError() { while (paramQueue.context->glGetError() != 0) { } } private static void InternalCompileShader() { IntPtr shaderHandle, codeHandle; int count, type; paramQueue.TryDequeue(out type, out count); for (int i = 0; i < count; i++) { paramQueue.TryDequeue(out shaderHandle, out codeHandle); *(uint*)shaderHandle = InternalIO.InternalLoadShaderCode((byte*)codeHandle, type); if (*(uint*)shaderHandle == 0) { IntPtr logPtr = InternalIO.InternalReadLog(); string log; try { byte[] logByte = new byte[512]; Marshal.Copy(logPtr, logByte, 0, 512); log = Encoding.UTF8.GetString(logByte); log = log.Replace("\0", ""); bool isUseful = false; foreach (char item in log) { if (!char.IsControl(item)) { isUseful = true; break; } } if (!isUseful) { throw new Exception(); } } catch (Exception) { log = "Failed to compile shader.\nFailed to get GLSL compiler log"; } InternalIO.InternalWriteLog(log, LogType.Error); } GCHandle.FromIntPtr(codeHandle).Free(); } } private void InternalAfterAlign(Form form, Action action) { throw new NotImplementedException(); } private void InternalAlignFrame(Form form) { throw new NotImplementedException(); } IntPtr CreateProgramPtr = (IntPtr)(delegate*)&InternalCreateProgram; private static void InternalCreateProgram() { IntPtr programHandle = default; paramQueue.TryDequeue(out programHandle); *(uint*)programHandle = paramQueue.context->glCreateProgram(); } IntPtr CreateProgramSetPtr = (IntPtr)(delegate*)&InternalCreateProgramSet; private static void InternalCreateProgramSet() { IntPtr programHandle; M128 m = default; paramQueue.TryDequeue(out m); programHandle = m.IntPtr0; for (int i = 0; i < m.Int32[2]; i++) { *((uint*)programHandle + i) = paramQueue.context->glCreateProgram(); } } internal IntPtr DeleBufferPtr = (IntPtr)(delegate*)&InternalDeleteBuffer; private static void InternalDeleteBuffer() { M128 m = default; paramQueue.TryDequeue(out m); paramQueue.context->glDeleteBuffers(m.UInt32[2], (uint*)m.IntPtr0); } private void InternalDeleteVertexArrays(glHandleSet arrays) { throw new NotImplementedException(); } private void InternalDrawElements(GepmetryType mode, uint count, Type type, IntPtr ptr) { throw new NotImplementedException(); } private void InternalGenBuffers(uint count, glHandleSet ptr) { throw new NotImplementedException(); } private void InternalGenTextures(uint count, glHandleSet ptr) { throw new NotImplementedException(); } private void InternalGenVertexArrays(uint count, glHandleSet ptr) { throw new NotImplementedException(); } private void InternalGetGraphicError() { throw new NotImplementedException(); } private int InternalGetUniformLocation(uint program, byte* ptr) { throw new NotImplementedException(); } private bool InternalGetWindowShouldClose(Form form) { throw new NotImplementedException(); } private void InternalMakeContexCurrent(Form form) { throw new NotImplementedException(); } private void InternalSetBufferData(BufferType bufferType, T bufferData, BufferUsage usage) { throw new NotImplementedException(); } private void InternalSetBufferData(BufferType bufferType, T[] bufferArray, BufferUsage usage) { throw new NotImplementedException(); } private void InternalSetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler) { throw new NotImplementedException(); } private void InternalSetValue(Uniform uniform, float v0, float v1, float v2, float v3) { throw new NotImplementedException(); } private void InternalSetValue(Uniform uniform, Vec4d vec) { throw new NotImplementedException(); } private void InternalSetValue(Uniform uniform, float v0, float v1, float v2) { throw new NotImplementedException(); } private void InternalSetValue(Uniform uniform, float v0, float v1) { throw new NotImplementedException(); } private void InternalSetValue(Uniform uniform, float v0) { throw new NotImplementedException(); } private void InternalSetValue(Uniform uniform, int i0) { throw new NotImplementedException(); } private void InternalSetValue(Uniform uniform, Vec4d vec) { throw new NotImplementedException(); } private void InternalSetVertexAttribute(uint index, int size, Type t, bool normalized, uint stride, int pointer) { throw new NotImplementedException(); } private void InternalSetWindowShouldClose(Form form, bool mark) { throw new NotImplementedException(); } private void InternalSwapBuffers(Form form) { throw new NotImplementedException(); } private void InternalSwitchContext() { throw new NotImplementedException(); } private void InternalTextureImage2d(uint target, int level, uint internalformat, uint width, uint height, uint format, uint type, void* pixels) { throw new NotImplementedException(); } private void InternalTextureParameter(uint target, uint pname, int param) { throw new NotImplementedException(); } private void InternalUseProgram(uint program) { throw new NotImplementedException(); } private void InternalViewport(int x, int y, uint width, uint height) { throw new NotImplementedException(); } } }