void IDualityBackend.Init() { activeInstance = this; using (var app = (JSObject)Runtime.GetGlobalObject("App")) { cachedCanvasSize.X = (int)app.GetObjectProperty("defaultWidth"); cachedCanvasSize.Y = (int)app.GetObjectProperty("defaultHeight"); } htmlCanvas = HtmlHelper.AddCanvas("game", cachedCanvasSize.X, cachedCanvasSize.Y); if (!WebGLRenderingContext.IsSupported) { using (var app = (JSObject)Runtime.GetGlobalObject("App")) { app.Invoke("webglNotSupported"); } throw new NotSupportedException("This browser does not support WebGL 1"); } // ToDo: Use WebGLContextAttributes instead using (JSObject contextAttributes = new JSObject()) { contextAttributes.SetObjectProperty("premultipliedAlpha", false); GL = new WebGLRenderingContext(htmlCanvas); } GraphicsBackend.LogOpenGLSpecs(); }
public static WebGLBuffer CreateArrayBufferWithUsage(this WebGLRenderingContextBase gl, Array items, uint usage) { var arrayBuffer = gl.CreateBuffer(); gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, arrayBuffer); gl.BufferData(WebGLRenderingContextBase.ARRAY_BUFFER, items, usage); return(arrayBuffer); }
public static WebGLBuffer CreateElementArrayBuffer(this WebGLRenderingContextBase gl, Array items) { var elementArrayBuffer = gl.CreateBuffer(); gl.BindBuffer(WebGLRenderingContextBase.ELEMENT_ARRAY_BUFFER, elementArrayBuffer); gl.BufferData(WebGLRenderingContextBase.ELEMENT_ARRAY_BUFFER, items, WebGLRenderingContextBase.STATIC_DRAW); gl.BindBuffer(WebGLRenderingContextBase.ELEMENT_ARRAY_BUFFER, null); return(elementArrayBuffer); }
public static WebGLBuffer CreateArrayBuffer(this WebGLRenderingContextBase gl, Array items) { var arrayBuffer = gl.CreateBuffer(); gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, arrayBuffer); gl.BufferData(WebGLRenderingContextBase.ARRAY_BUFFER, items, WebGLRenderingContextBase.STATIC_DRAW); gl.BindBuffer(WebGLRenderingContextBase.ARRAY_BUFFER, null); return(arrayBuffer); }
public virtual Task InitAsync(JSObject canvas, Vector4 clearColor) { this.clearColor = clearColor; this.canvas = canvas; canvasWidth = (int)canvas.GetObjectProperty("width"); canvasHeight = (int)canvas.GetObjectProperty("height"); gl = new WebGL2RenderingContext(canvas); return Task.CompletedTask; }
public virtual Task InitAsync(JSObject canvas, Vector4 clearColor) { this.clearColor = clearColor; this.canvas = canvas; canvasWidth = (int)canvas.GetObjectProperty("width"); canvasHeight = (int)canvas.GetObjectProperty("height"); var contextAttributes = new WebGLContextAttributes { Stencil = true }; gl = new WebGL2RenderingContext(canvas, contextAttributes); return(Task.CompletedTask); }
public static WebGLShader GetShader(this WebGLRenderingContextBase gl, string shaderSource, uint type) { var shader = gl.CreateShader(type); gl.ShaderSource(shader, shaderSource); gl.CompileShader(shader); var message = gl.GetShaderInfoLog(shader); if (message.Length > 0) { var msg = $"Shader Error: {message}"; throw new Exception(msg); } return(shader); }
public static WebGLProgram InitializeShaders( this WebGLRenderingContextBase gl, string vertexShaderCode, string fragmentShaderCode) { var shaderProgram = gl.CreateProgram(); var vertexShader = GetShader(gl, vertexShaderCode, WebGLRenderingContextBase.VERTEX_SHADER); var fragmentShader = GetShader(gl, fragmentShaderCode, WebGLRenderingContextBase.FRAGMENT_SHADER); gl.AttachShader(shaderProgram, vertexShader); gl.AttachShader(shaderProgram, fragmentShader); gl.LinkProgram(shaderProgram); gl.UseProgram(shaderProgram); return(shaderProgram); }
protected WebGLProgram SetUpProgram( WebGLRenderingContextBase gl, string vertexShaderSource = "void main() {}", string fragmentShaderSource = "void main() {}") { var vertexShader = gl.CreateShader(WebGLRenderingContextBase.VERTEX_SHADER); gl.ShaderSource(vertexShader, vertexShaderSource); gl.CompileShader(vertexShader); var fragmentShader = gl.CreateShader(WebGLRenderingContextBase.FRAGMENT_SHADER); gl.ShaderSource(fragmentShader, fragmentShaderSource); gl.CompileShader(fragmentShader); var program = gl.CreateProgram(); gl.AttachShader(program, vertexShader); gl.AttachShader(program, fragmentShader); gl.LinkProgram(program); return(program); }