internal override void Init() { GL = Platform.WebGL2Context; if (GL == null) { throw new CKGLException("Couldn't create WebGL 2.0 context"); } // Debug Output.WriteLine("GraphicsBackend - WebGL 2.0 Initialized"); var attributes = GL.getContextAttributes(); Output.WriteLine($"WebGL Context - Attributes: alpha[{attributes.alpha}] premultipliedAlpha[{attributes.premultipliedAlpha}] depth[{attributes.depth}] stencil[{attributes.stencil}] antialias[{attributes.antialias}] preserveDrawingBuffer[{attributes.preserveDrawingBuffer}] failIfMajorPerformanceCaveat[{attributes.failIfMajorPerformanceCaveat}]"); Output.WriteLine($"WebGL Context - GLSL Version: {GL.getParameter(SHADING_LANGUAGE_VERSION)}"); Output.WriteLine($"WebGL Context - VERSION: {GL.getParameter(VERSION)}"); Output.WriteLine($"WebGL Context - VENDOR: {GL.getParameter(VENDOR)}"); Output.WriteLine($"WebGL Context - RENDERER: {GL.getParameter(RENDERER)}"); try { Output.WriteLine($"WebGL Context - WEBGL_debug_renderer_info.UNMASKED_VENDOR_WEBGL: {GL.getParameter(Extensions.WEBGL_debug_renderer_info.UNMASKED_VENDOR_WEBGL)}"); Output.WriteLine($"WebGL Context - WEBGL_debug_renderer_info.UNMASKED_RENDERER_WEBGL: {GL.getParameter(Extensions.WEBGL_debug_renderer_info.UNMASKED_RENDERER_WEBGL)}"); } catch { } Output.WriteLine($"WebGL Context - MaxColourAttachments: {GL.getParameter(MAX_COLOR_ATTACHMENTS_Static)}"); Output.WriteLine($"WebGL Context - MaxCubeMapTextureSize: {GL.getParameter(MAX_CUBE_MAP_TEXTURE_SIZE)}"); Output.WriteLine($"WebGL Context - MaxDrawBuffers: {GL.getParameter(MAX_DRAW_BUFFERS_Static)}"); Output.WriteLine($"WebGL Context - MaxElementIndices: {GL.getParameter(MAX_ELEMENTS_INDICES_Static)}"); Output.WriteLine($"WebGL Context - MaxElementVertices: {GL.getParameter(MAX_ELEMENTS_VERTICES_Static)}"); Output.WriteLine($"WebGL Context - MaxRenderbufferSize: {GL.getParameter(MAX_RENDERBUFFER_SIZE)}"); Output.WriteLine($"WebGL Context - MaxSamples: {GL.getParameter(MAX_SAMPLES_Static)}"); Output.WriteLine($"WebGL Context - MaxTextureImageUnits: {GL.getParameter(MAX_TEXTURE_IMAGE_UNITS)}"); Output.WriteLine($"WebGL Context - MaxTextureSize: {GL.getParameter(MAX_TEXTURE_SIZE)}"); //Output.WriteLine($"WebGL - Extensions: \n{string.Join("\n", GL.GetSupportedExtensions())}"); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150718/webgl2 //https://wiki.mozilla.org/Platform/GFX/WebGL2 // https://twitter.com/etribz/status/359954523789328387 // 2years since? // https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext // cannot find any example. retry later var c = new WebGL2RenderingContext(); new IHTMLPre { new { c } }.AttachToDocument(); // {{ c = null }} // https://github.com/dotnet/corefx/blob/master/src/System.Numerics.Vectors/src/System/Numerics/Matrix4x4.cs // --enable-unsafe-es3-apis. // https://groups.google.com/forum/#!topic/webgl-dev-list/8P9Sk47K5hg // http://www.marmoset.co/viewer/gallery // http://lmv.rocks/ // "C:\Users\Arvo\AppData\Local\Google\Chrome SxS\Application\chrome.exe - es3.lnk" // GL_VERSION OpenGL ES 2.0 (ANGLE 2.1.0.02df796f466c) // GL_VERSION OpenGL ES 3.0 (ANGLE 2.1.0.02df796f466c) ///* Uniform Buffer Objects and Transform Feedback Buffers */ //421 void bindBufferBase(GLenum target, GLuint index, WebGLBuffer? buffer); //422 void bindBufferRange(GLenum target, GLuint index, WebGLBuffer? buffer, GLintptr offset, GLsizeiptr size); // void drawElementsInstanced(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei instanceCount); }
public void Run() { InitContextAttributes(); gl = new WebGL2RenderingContext(canvas, contextAttributes); var vertexShaderCode = @"#version 300 es in vec4 aPos; void main(void) { gl_PointSize = 20.; gl_Position = vec4(-aPos.x, aPos.yzw); } "; var fragmentShaderCode = @"#version 300 es precision highp float; out vec4 fragColor; void main(void) { fragColor = vec4(1., 0., 0., 1. ); } "; var vertexShader = GLExtensions.GetShader( gl, vertexShaderCode, WebGLRenderingContextBase.VERTEX_SHADER); var fragmentShader = GLExtensions.GetShader( gl, fragmentShaderCode, WebGLRenderingContextBase.FRAGMENT_SHADER); var shaderProgram = gl.CreateProgram(); gl.AttachShader(shaderProgram, vertexShader); gl.AttachShader(shaderProgram, fragmentShader); gl.TransformFeedbackVaryings( shaderProgram, new string[] { "gl_Position" }, WebGL2RenderingContextBase.SEPARATE_ATTRIBS); gl.LinkProgram(shaderProgram); gl.UseProgram(shaderProgram); aPosLoc = (uint)gl.GetAttribLocation(shaderProgram, "aPos"); gl.EnableVertexAttribArray(aPosLoc); var bufAData = new float[] { 0.8f, 0, 0, 1 }; bufA = gl.CreateArrayBufferWithUsage(bufAData, WebGL2RenderingContextBase.DYNAMIC_COPY); var bufBData = new float[4 * 4]; bufB = gl.CreateArrayBufferWithUsage(bufBData, WebGL2RenderingContextBase.DYNAMIC_COPY); var transformFeedback = gl.CreateTransformFeedback(); gl.BindTransformFeedback(WebGL2RenderingContextBase.TRANSFORM_FEEDBACK, transformFeedback); }
public WebGL2Tests(JSObject canvas) { if (!WebGL2RenderingContextBase.IsSupported) { throw new InconclusiveException("WebGL 2 is not supported"); } gl = new WebGL2RenderingContext(canvas); pixels = new byte[TextureWidthOrHeight * 2 * BytesPerPixel]; pixelsHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned); texture = gl.CreateTexture(); }