Files
stgsharp/源代码/StgSharp/Graphics/IglFunc.cs
T

240 lines
10 KiB
C#

using StgSharp.Math;
using System;
namespace StgSharp.Graphics
{
public interface IglFunc
{
/// <summary>
/// Align a sets of code to frame update of a <see cref="Form"/>.
/// Usually, a call of <see cref="AfterAlign(Form,Action)"/> is required.
/// This method is used as sigle thread method. If more than one
/// alignment is requested, a <see cref="InvalidOperationException"/> will throw.
/// </summary>
/// <param name="form">The form used as frame update benchmark.</param>
/// <exception cref="InvalidOperationException">More than one alingment attached to one form timer</exception>
void AlignFrame(Form form);
/// <summary>
/// Operation after alignment by calling <see cref="AlignFrame(Form)"/>.
/// No calling of this method is acceptable, but it will bring the risk
/// of that relevant code will not run if it is interrupted by frame overtime.
/// Please call this method immediately after calling <see cref="AlignFrame(Form)"/>,
/// too early or sonner may cause <see cref="InvalidOperationException"/>.
/// </summary>
/// <param name="form">The form used as frame update benchmark.</param>
/// <param name="action">Operation after frame update alignment.</param>
/// <exception cref="InvalidOperationException">The action binded to a wrong alignment.</exception>
void AfterAlign(Form form, Action action);
/// <summary>
/// Same function as OpenGL api glActiveTexture
/// </summary>
/// <param name="type">type of texture to activate</param>
void ActiveTexture(uint type);
/// <summary>
/// Same fucntion as OpenGL api glAttachShader
/// </summary>
/// <param name="program">Shader program to be attachec</param>
/// <param name="shader">A shader part to attach</param>
void AttachShader(uint program, uint shader);
/// <summary>
/// Bind the indexed buffer object to certain type of buffer
/// </summary>
/// <param name="bufferType"></param>
/// <param name="index"></param>
void BindBuffer(BufferType bufferType, uint index);
/// <summary>
/// Same function as OpenGL api, glBindTexture.
/// </summary>
/// <param name="type">Type of texture to bind</param>
/// <param name="texture">Sign of texture</param>
void BindTexture(uint type, uint texture);
/// <summary>
/// Same function as OpenGL api, glBindVertexArray
/// </summary>
/// <param name="index"></param>
void BindVertexArray(uint index);
/// <summary>
/// Clear buffers to preset values
/// </summary>
/// <param name="mask"></param>
void Clear(MaskBufferBit mask);
/// <summary>
/// Call apiClearColor in OpenGL
/// specifies the red, green, blue, and alpha values used by apiClear to clear the color buffers.
/// Values specified by apiClearColor are clamped to the range [0,1]
/// </summary>
/// <param name="R">Specify the red values used when the color buffers are cleared.</param>
/// <param name="G">Specify the red values used when the color buffers are cleared.</param>
/// <param name="B">Specify the red values used when the color buffers are cleared.</param>
/// <param name="A">Specify the red values used when the color buffers are cleared.</param>
void ClearColor(float R, float G, float B, float A);
void ClearGraphicError();
/// <summary>
/// Conpile the provided shader code in string form.
/// </summary>
/// <param name="shaderCode">A string represent the shader's code</param>
/// <param name="shaderType">An <see cref="ShaderType"/> enum represent the type of the shader to
/// conpile, including vertex shader and fragment shader.</param>
/// <returns>An uint value as the only mark of conpiled shader</returns>
uint CompileShader(string shaderCode, ShaderType shaderType);
/// <summary>
/// Same function as OpenGL api, glCreateProgram
/// </summary>
/// <returns></returns>
uint CreateProgram();
/// <summary>
/// Creates a form and its associated
/// </summary>
/// <param name="width">Required width</param>
/// <param name="height">Required width</param>
/// <param name="tittle">Tittle of the window </param>
/// <param name="monitor"></param>
/// <param name="share"></param>
/// <returns>The instance of created form</returns>
/// <exception cref="Exception"></exception>
IntPtr CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share);
uint CreatGraphicProgram();
/// <summary>
/// Same function as OpenGL api, glDeleteBuffer.
/// </summary>
/// <param name="count">Amount of bufferd to be deleted</param>
/// <param name="ptr">Pointer of buffer to be deleted</param>
unsafe void DeleteBuffers(int count, uint* ptr);
/// <summary>
/// Same function as OpenGL api, glDeleteVertexArrays
/// </summary>
/// <param name="count">Amount of vao to be deleted</param>
/// <param name="ptr">pointer of vao sign array</param>
unsafe void DeleteVertexArrays(int count, uint* ptr);
void DrawElements(GepmetryType mode, int count, Type type, IntPtr ptr);
/// <summary>
/// Same fucntion as the OpenGL api glGenBuffers
/// </summary>
/// <param name="count"></param>
/// <param name="ptr"></param>
unsafe void GenBuffers(int count, uint* ptr);
/// <summary>
/// Same fucnction as OpenGL api glGenTextures.
/// </summary>
/// <param name="count">amount of textures to generate</param>
/// <param name="ptr">pointer to texture signs' array</param>
unsafe void GenTextures(int count, uint* ptr);
/// <summary>
/// Same fucntion as OpenGL api, glGenVertexArray
/// </summary>
/// <param name="count">Amount of vao to be generated</param>
/// <param name="ptr">Pointer of vao sign array</param>
unsafe void GenVertexArrays(int count, uint* ptr);
void GetGraphicError();
/// <summary>
/// Same fucntion as OpenGL api, glGetUniformLocation
/// </summary>
/// <param name="program">Shader program to find the uniform</param>
/// <param name="ptr">Pointer to byte array of name <see cref="string"/> of the uniform </param>
/// <returns></returns>
unsafe int GetUniformLocation(uint program, byte* ptr);
bool GetWindowShouldClose(Form form);
/// <summary>
/// Make the OpenGL context of a vertain <see cref="Form"/> as the activated OpenGL context.
/// </summary>
/// <param name="form"></param>
void MakeContexCurrent(Form form);
void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage) where T : IMat;
void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible;
/// <summary>
/// sets the framebuffer resize callback of the specified <see cref="Form"/>,
///which is called when the framebuffer of the specified <see cref="Form"/> is resized.
/// </summary>
/// <param name="id">The only signiture stands for the <see cref="Form"/> to be controlled</param>
/// <param name="handler">Method hadler </param>
void SetFrameBufferSizeCallback(IntPtr id, FrameBufferSizeHandler handler);
void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3);
void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec);
void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2);
void SetValue(Uniform<float, float> uniform, float v0, float v1);
void SetValue(Uniform<float> uniform, float v0);
void SetValue(Uniform<int> uniform, int i0);
void SetValue(Uniform<Vec4d> uniform, Vec4d vec);
/// <summary>
/// Set how a shader parameter read data from a VBO.
/// </summary>
/// <param name="index">Serial number of the parameter</param>
/// <param name="size">Amount of data each elements contains</param>
/// <param name="t">Type of data read by shader</param>
/// <param name="normalized"></param>
/// <param name="stride">Pixels stride of each sets of data</param>
/// <param name="pointer"></param>
void SetVertexAttribute(uint index, int size, Type t, bool normalized, int stride, int pointer);
void SwapBuffers(Form form);
/// <summary>
/// Same function as OpenGL api glTexImage2d
/// </summary>
/// <param name="target">texture target to load image in</param>
/// <param name="level">level of mipmap, 0 if default</param>
/// <param name="internalformat">OpenGL's internal color channel format</param>
/// <param name="width">width of image</param>
/// <param name="height">height of image</param>
/// <param name="format">color channels of this image</param>
/// <param name="type">how this image express each pixel</param>
/// <param name="pixels">pointer to data array of pixels</param>
unsafe void TextureImage2d(uint target, int level, uint internalformat, int width, int height, uint format, uint type, void* pixels);
/// <summary>
/// Same fucntion as OpenGL api glTexParameteri
/// </summary>
/// <param name="target">texture target to set parameters</param>
/// <param name="pname">name of parameter</param>
/// <param name="param">value of parameter</param>
void TextureParameter(uint target, uint pname, int param);
/// <summary>
/// Same fucntion as OpenGL api glUseShader.
/// </summary>
/// <param name="program">Sign of program to be used</param>
void UseProgram(uint program);
/// <summary>
/// Same function as the OpenGL api, glViewPort
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="width"></param>
/// <param name="height"></param>
void Viewport(int x, int y, int width, int height);
}
}