using System; using System.IO; using System.Drawing; using swf=System.Windows.Forms; using OpenTK; using OpenTK.Graphics.OpenGL; namespace BizHawk.Bizware.BizwareGL { /// /// This is a wrapper over hopefully any OpenGL bindings.. /// And possibly, quite possibly, Direct3d.. even though none of your shaders would work. (could use nvidia CG, native dlls in necessary since this would only be for windows) /// TODO - This really needs to be split up into an internal and a user interface. so many of the functions are made to support the smart wrappers /// Maybe make a method that returns an interface used for advanced methods (and IGL_TK could implement that as well and just "return this:") /// /// NOTE: THIS SHOULD NOT BE ASSUMED TO BE THREAD SAFE! Make a new IGL if you want to use it in a new thread. I hope that will work... /// public interface IGL : IDisposable { /// /// Clears the specified buffer parts /// void Clear(ClearBufferMask mask); /// /// Sets the current clear color /// void SetClearColor(Color color); /// /// compile a fragment shader. This is the simplified method. A more complex method may be added later which will accept multiple sources and preprocessor definitions independently /// Shader CreateFragmentShader(bool cg, string source, string entry, bool required); /// /// compile a vertex shader. This is the simplified method. A more complex method may be added later which will accept multiple sources and preprocessor definitions independently /// Shader CreateVertexShader(bool cg, string source, string entry, bool required); /// /// Creates a complete pipeline from the provided vertex and fragment shader handles /// Pipeline CreatePipeline(VertexLayout vertexLayout, Shader vertexShader, Shader fragmentShader, bool required, string memo); /// /// Binds this pipeline as the current used for rendering /// void BindPipeline(Pipeline pipeline); /// /// Sets a uniform sampler to use use the provided texture /// void SetPipelineUniformSampler(PipelineUniform uniform, Texture2d tex); /// /// Sets a uniform value /// void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose); /// /// Sets a uniform value /// void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose); /// /// sets a uniform value /// void SetPipelineUniform(PipelineUniform uniform, Vector4 value); /// /// sets a uniform value /// void SetPipelineUniform(PipelineUniform uniform, Vector2 value); /// /// sets a uniform value /// void SetPipelineUniform(PipelineUniform uniform, float value); /// /// sets uniform values /// void SetPipelineUniform(PipelineUniform uniform, Vector4[] values); /// /// sets a uniform value /// void SetPipelineUniform(PipelineUniform uniform, bool value); /// /// Binds array data for use with the currently-bound pipeline's VertexLayout /// unsafe void BindArrayData(void* pData); /// /// Begins a rendering scene; use before doing any draw calls, as per normal /// void BeginScene(); /// /// Indicates end of scene rendering; use after alldraw calls as per normal /// void EndScene(); /// /// Draws based on the currently set pipeline, VertexLayout and ArrayData. /// Count is the VERT COUNT not the primitive count /// void DrawArrays(PrimitiveType mode, int first, int count); /// /// resolves the texture into a new BitmapBuffer /// BitmapBuffer ResolveTexture2d(Texture2d texture); /// /// Sets a 2d texture parameter /// void TexParameter2d(Texture2d texture, TextureParameterName pname, int param); /// /// creates a vertex layout resource /// VertexLayout CreateVertexLayout(); /// /// Creates a blending state object /// IBlendState CreateBlendState(BlendingFactorSrc colorSource, BlendEquationMode colorEquation, BlendingFactorDest colorDest, BlendingFactorSrc alphaSource, BlendEquationMode alphaEquation, BlendingFactorDest alphaDest); /// /// retrieves a blend state for opaque rendering /// Alpha values are copied from the source fragment. /// IBlendState BlendNoneCopy { get; } /// /// retrieves a blend state for opaque rendering /// Alpha values are written as opaque /// IBlendState BlendNoneOpaque { get; } /// /// retrieves a blend state for normal (non-premultiplied) alpha blending. /// Alpha values are copied from the source fragment. /// IBlendState BlendNormal { get; } /// /// Sets the current blending state object /// void SetBlendState(IBlendState rsBlend); /// /// Creates a texture with the specified dimensions /// TODO - pass in specifications somehow /// Texture2d CreateTexture(int width, int height); /// /// In case you already have the texture ID (from an opengl emulator gpu core) you can get a Texture2d with it this way. /// Otherwise, if this isn't an OpenGL frontend implementation, I guess... try reading the texturedata out of it and making a new texture? /// Texture2d WrapGLTexture2d(IntPtr glTexId, int width, int height); /// /// Sets the clamp mode (for both uv) for the Texture2d. /// The default is clamped=true. /// void SetTextureWrapMode(Texture2d tex, bool clamp); /// /// Loads the texture with new data. This isnt supposed to be especially versatile, it just blasts a bitmap buffer into the texture /// void LoadTextureData(Texture2d tex, BitmapBuffer bmp); /// /// Loads a texture from disk /// Texture2d LoadTexture(string path); /// /// Loads a texture from the stream /// Texture2d LoadTexture(Stream stream); /// /// Loads a texture from the BitmapBuffer /// Texture2d LoadTexture(BitmapBuffer buffer); /// /// Loads a texture from the System.Drawing.Bitmap /// Texture2d LoadTexture(Bitmap bitmap); /// /// sets the viewport (and scissor) according to the provided specifications /// void SetViewport(int x, int y, int width, int height); /// /// sets the viewport (and scissor) according to the provided specifications /// void SetViewport(int width, int height); /// /// sets the viewport (and scissor) according to the client area of the provided control /// void SetViewport(swf.Control control); /// /// sets the viewport (and scissor) according to the provided specifications /// void SetViewport(Size size); /// /// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI /// Matrix4 CreateGuiProjectionMatrix(int w, int h); /// /// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI /// Matrix4 CreateGuiProjectionMatrix(Size dims); /// /// generates a proper view transform for a standard 2d ortho projection, including half-pixel jitter if necessary and /// re-establishing of a normal 2d graphics top-left origin. suitable for use in a GUI /// Matrix4 CreateGuiViewMatrix(int w, int h, bool autoflip = true); /// /// generates a proper view transform for a standard 2d ortho projection, including half-pixel jitter if necessary and /// re-establishing of a normal 2d graphics top-left origin. suitable for use in a GUI /// Matrix4 CreateGuiViewMatrix(Size dims, bool autoflip = true); /// /// Creates a render target. Only includes a color buffer. Pixel format control TBD /// RenderTarget CreateRenderTarget(int w, int h); /// /// Binds a RenderTarget for current rendering /// void BindRenderTarget(RenderTarget rt); /// /// returns a string representing the API employed by this context /// string API { get; } /// /// frees the provided render target. Same as disposing the resource. /// void FreeRenderTarget(RenderTarget rt); /// /// frees the provided texture. Same as disposing the resource. /// void FreeTexture(Texture2d tex); /// /// Frees the provided pipeline. Same as disposing the resource. /// void FreePipeline(Pipeline pipeline); /// /// Frees the provided texture. For internal use only. /// void Internal_FreeShader(Shader shader); IGraphicsControl Internal_CreateGraphicsControl(); } }