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); /// /// returns an empty handle /// IntPtr GetEmptyHandle(); /// /// returns an empty uniform handle /// IntPtr GetEmptyUniformHandle(); /// /// 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(string source, 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(string source, bool required); /// /// Creates a complete pipeline from the provided vertex and fragment shader handles /// Pipeline CreatePipeline(VertexLayout vertexLayout, Shader vertexShader, Shader fragmentShader, bool required); /// /// Binds this pipeline as the current used for rendering /// void BindPipeline(Pipeline pipeline); /// /// Sets a uniform sampler to use use the provided texture handle /// void SetPipelineUniformSampler(PipelineUniform uniform, IntPtr texHandle); /// /// 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 VertexLayout /// unsafe void BindArrayData(void* pData); /// /// Draws based on the currently set VertexLayout and ArrayData /// void DrawArrays(PrimitiveType mode, int first, int count); /// /// Frees the provided shader handle /// void FreeShader(IntPtr shader); /// /// frees the provided texture /// void FreeTexture(Texture2d tex); /// /// resolves the texture into a new BitmapBuffer /// BitmapBuffer ResolveTexture2d(Texture2d texture); /// /// frees the provided render target /// void FreeRenderTarget(RenderTarget rt); /// /// Binds this texture as the current texture2d target for parameter-specification /// void BindTexture2d(Texture2d texture); /// /// Sets a 2d texture parameter /// void TexParameter2d(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 /// 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 according to the provided specifications /// void SetViewport(int x, int y, int width, int height); /// /// sets the viewport according to the provided specifications /// void SetViewport(int width, int height); /// /// sets the viewport according to the client area of the provided control /// void SetViewport(swf.Control control); /// /// sets the viewport 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); /// /// 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); /// /// Creates a render target. Includes a color buffer. Pixel format control TBD /// RenderTarget CreateRenderTarget(int w, int h); /// /// Binds a RenderTarget for current rendering /// void BindRenderTarget(RenderTarget rt); IGraphicsControl Internal_CreateGraphicsControl(); /// /// returns a string representing the API employed by this context /// string API { get; } } }