chunquedong avatar chunquedong committed af7d757 Draft

JS WebGlContext reflection

Comments (0)

Files changed (7)

fan3d/fgfx3d/build.fan

   {
     podName  = "fgfx3d"
     summary  = "Fantom 3D lib"
-    depends  = ["sys 1.0", "fwt 1.0", "fgfxArray 1.0", "fgfxOpenGl 1.0", "fgfxMath 1.0", "compiler 1.0"]
+    depends  = ["sys 1.0", "fwt 1.0", "fgfxArray 1.0", "fgfxOpenGl 1.0", "fgfxMath 1.0"]
     srcDirs  = [`fan/`]
 
-    index = ["compiler.dsl.fgfx3d::Shader": "fgfx3d::ShaderDslPlugin"]
+    //index = ["compiler.dsl.fgfx3d::Shader": "fgfx3d::ShaderDslPlugin"]
   }
 }

fan3d/fgfx3d/fan/Shader.fan

 {
   Str src
 
-  private new make(Str s) { src = s }
-
-  static Shader fromStr(Str s) { Shader.make(s) }
+  new make(Str s) { src = s }
 }

fan3d/fgfx3d/fan/ShaderDslPlugin.fan

-//
-// Copyright (c) 2012, chunquedong
-// Licensed under the Academic Free License version 3.0
-//
-// History:
-//   2012-02-24  Jed Young  Creation
-//
-
-using compiler
-
-@Js
-class ShaderDslPlugin : DslPlugin
-{
-  new make(Compiler c) : super(c) {}
-
-  override Expr compile(DslExpr dsl)
-  {
-    regexType := ns.resolveType(Shader#.qname)
-    fromStr := regexType.method("fromStr")
-    args := [Expr.makeForLiteral(dsl.loc, ns, dsl.src)]
-    return CallExpr.makeWithMethod(dsl.loc, null, fromStr, args)
-  }
-}

fan3d/openGl/fan/WebGlContext.fan

+//
+// Copyright (c) 2011, chunquedong
+// Licensed under the Academic Free License version 3.0
+//
+// History:
+//   2011-5-29  Jed Young  Creation
+//
+
+using fgfxArray
+
+**
+** Stub for native implementation of GlContext
+**
+@Js
+internal native class WebGlContext : GlContext
+{
+  override native Void bindTexture(GlEnum target, GlTexture? texture)
+  override native Void bufferData(GlEnum target, ArrayBuffer data, GlEnum usage)
+  override native Int getProgramParameter(GlProgram program, GlEnum pname)
+  override native Int getShaderParameter(GlShader shader, GlEnum pname)
+  override native Str getShaderInfoLog(GlShader shader)
+  override native Void uniformMatrix4fv(GlUniformLocation location, Bool transpose, ArrayBuffer value)
+  override native Void texImage2DBuffer(GlEnum target, Int level, GlEnum internalformat, Int width, Int height, Int border, GlEnum format, GlEnum type, ArrayBuffer pixels)
+  override native Void texImage2D(GlEnum target, Int level, GlEnum internalformat, GlEnum format, GlEnum type, GlImage image)
+
+
+//////////////////////////////////////////////////////////////////////////
+// special
+//////////////////////////////////////////////////////////////////////////
+
+//  override native null getContextAttributes()
+//  override native Bool isContextLost()
+//  override native Str[] getSupportedExtensions()
+//  override native null getExtension(Str name)
+//  override native Void bindTexture(GlEnum target, GlTexture texture)
+//  override native Void bufferData(GlEnum target, Int size, GlEnum usage)
+//  override native Void bufferData(GlEnum target, ArrayBuffer data, GlEnum usage)
+//  override native Void bufferData(GlEnum target, ArrayBuffer data, GlEnum usage)
+//  override native Void bufferSubData(GlEnum target, Int offset, ArrayBuffer data)
+//  override native Void bufferSubData(GlEnum target, Int offset, ArrayBuffer data)
+//  override native GlEnum checkFramebufferStatus(GlEnum target)
+//  override native GlActiveInfo getActiveAttrib(GlProgram program, Int index)
+//  override native GlActiveInfo getActiveUniform(GlProgram program, Int index)
+//  override native GlShader[] getAttachedShaders(GlProgram program)
+//  override native null getParameter(GlEnum pname)
+//  override native null getBufferParameter(GlEnum target, GlEnum pname)
+//  override native GlEnum getError()
+//  override native null getFramebufferAttachmentParameter(GlEnum target, GlEnum attachment, GlEnum pname)
+//  override native null getProgramParameter(GlProgram program, GlEnum pname)
+//  override native Str getProgramInfoLog(GlProgram program)
+//  override native null getRenderbufferParameter(GlEnum target, GlEnum pname)
+//  override native null getShaderParameter(GlShader shader, GlEnum pname)
+//  override native Str getShaderInfoLog(GlShader shader)
+//  override native Str getShaderSource(GlShader shader)
+//  override native null getTexParameter(GlEnum target, GlEnum pname)
+//  override native null getUniform(GlProgram program, GlUniformLocation location)
+//  override native null getVertexAttrib(Int index, GlEnum pname)
+//  override native Int getVertexAttribOffset(Int index, GlEnum pname)
+//  override native Void readPixels(Int x, Int y, Int width, Int height, GlEnum format, GlEnum type, ArrayBuffer pixels)
+//  override native Void texImage2D(GlEnum target, Int level, GlEnum internalformat, Int width, Int height, Int border, GlEnum format, GlEnum type, ArrayBuffer pixels)
+//  override native Void texImage2D(GlEnum target, Int level, GlEnum internalformat, GlEnum format, GlEnum type, null pixels)
+//  override native Void texImage2D(GlEnum target, Int level, GlEnum internalformat, GlEnum format, GlEnum type, Image image)
+//  override native Void texImage2D(GlEnum target, Int level, GlEnum internalformat, GlEnum format, GlEnum type, null canvas)
+//  override native Void texImage2D(GlEnum target, Int level, GlEnum internalformat, GlEnum format, GlEnum type, null video)
+//  override native Void texSubImage2D(GlEnum target, Int level, Int xoffset, Int yoffset, Int width, Int height, GlEnum format, GlEnum type, ArrayBuffer pixels)
+//  override native Void texSubImage2D(GlEnum target, Int level, Int xoffset, Int yoffset, GlEnum format, GlEnum type, null pixels)
+//  override native Void texSubImage2D(GlEnum target, Int level, Int xoffset, Int yoffset, GlEnum format, GlEnum type, Image image)
+//  override native Void texSubImage2D(GlEnum target, Int level, Int xoffset, Int yoffset, GlEnum format, GlEnum type, null canvas)
+//  override native Void texSubImage2D(GlEnum target, Int level, Int xoffset, Int yoffset, GlEnum format, GlEnum type, null video)
+//  override native Void uniform1fv(GlUniformLocation location, ArrayBuffer v)
+//  override native Void uniform1fv(GlUniformLocation location, Float[] v)
+//  override native Void uniform1iv(GlUniformLocation location, ArrayBuffer v)
+//  override native Void uniform1iv(GlUniformLocation location, Int[] v)
+//  override native Void uniform2fv(GlUniformLocation location, ArrayBuffer v)
+//  override native Void uniform2fv(GlUniformLocation location, Float[] v)
+//  override native Void uniform2iv(GlUniformLocation location, ArrayBuffer v)
+//  override native Void uniform2iv(GlUniformLocation location, Int[] v)
+//  override native Void uniform3fv(GlUniformLocation location, ArrayBuffer v)
+//  override native Void uniform3fv(GlUniformLocation location, Float[] v)
+//  override native Void uniform3iv(GlUniformLocation location, ArrayBuffer v)
+//  override native Void uniform3iv(GlUniformLocation location, Int[] v)
+//  override native Void uniform4fv(GlUniformLocation location, ArrayBuffer v)
+//  override native Void uniform4fv(GlUniformLocation location, Float[] v)
+//  override native Void uniform4iv(GlUniformLocation location, ArrayBuffer v)
+//  override native Void uniform4iv(GlUniformLocation location, Int[] v)
+//  override native Void uniformMatrix2fv(GlUniformLocation location, Bool transpose, ArrayBuffer value)
+//  override native Void uniformMatrix2fv(GlUniformLocation location, Bool transpose, Float[] value)
+//  override native Void uniformMatrix3fv(GlUniformLocation location, Bool transpose, ArrayBuffer value)
+//  override native Void uniformMatrix3fv(GlUniformLocation location, Bool transpose, Float[] value)
+//  override native Void uniformMatrix4fv(GlUniformLocation location, Bool transpose, ArrayBuffer value)
+//  override native Void uniformMatrix4fv(GlUniformLocation location, Bool transpose, Float[] value)
+//  override native Void vertexAttrib1fv(Int indx, ArrayBuffer values)
+//  override native Void vertexAttrib1fv(Int indx, Float[] values)
+//  override native Void vertexAttrib2fv(Int indx, ArrayBuffer values)
+//  override native Void vertexAttrib2fv(Int indx, Float[] values)
+//  override native Void vertexAttrib3fv(Int indx, ArrayBuffer values)
+//  override native Void vertexAttrib3fv(Int indx, Float[] values)
+//  override native Void vertexAttrib4fv(Int indx, ArrayBuffer values)
+//  override native Void vertexAttrib4fv(Int indx, Float[] values)
+
+//////////////////////////////////////////////////////////////////////////
+// Gen
+//////////////////////////////////////////////////////////////////////////
+
+  override native Void activeTexture(GlEnum texture)
+  override native Void attachShader(GlProgram program, GlShader shader)
+  override native Void bindAttribLocation(GlProgram program, Int index, Str name)
+  override native Void bindBuffer(GlEnum target, GlBuffer buffer)
+  override native Void bindFramebuffer(GlEnum target, GlFramebuffer framebuffer)
+  override native Void bindRenderbuffer(GlEnum target, GlRenderbuffer renderbuffer)
+  override native Void blendColor(Float red, Float green, Float blue, Float alpha)
+  override native Void blendEquation(GlEnum mode)
+  override native Void blendEquationSeparate(GlEnum modeRGB, GlEnum modeAlpha)
+  override native Void blendFunc(GlEnum sfactor, GlEnum dfactor)
+  override native Void blendFuncSeparate(GlEnum srcRGB, GlEnum dstRGB, GlEnum srcAlpha, GlEnum dstAlpha)
+  override native Void clear(GlEnum mask)
+  override native Void clearColor(Float red, Float green, Float blue, Float alpha)
+  override native Void clearDepth(Float depth)
+  override native Void clearStencil(Int s)
+  override native Void colorMask(Bool red, Bool green, Bool blue, Bool alpha)
+  override native Void compileShader(GlShader shader)
+  override native Void copyTexImage2D(GlEnum target, Int level, GlEnum internalformat, Int x, Int y, Int width, Int height, Int border)
+  override native Void copyTexSubImage2D(GlEnum target, Int level, Int xoffset, Int yoffset, Int x, Int y, Int width, Int height)
+  override native GlBuffer createBuffer()
+  override native GlFramebuffer createFramebuffer()
+  override native GlProgram createProgram()
+  override native GlRenderbuffer createRenderbuffer()
+  override native GlShader createShader(GlEnum type)
+  override native GlTexture createTexture()
+  override native Void cullFace(GlEnum mode)
+  override native Void deleteBuffer(GlBuffer buffer)
+  override native Void deleteFramebuffer(GlFramebuffer framebuffer)
+  override native Void deleteProgram(GlProgram program)
+  override native Void deleteRenderbuffer(GlRenderbuffer renderbuffer)
+  override native Void deleteShader(GlShader shader)
+  override native Void deleteTexture(GlTexture texture)
+  override native Void depthFunc(GlEnum func)
+  override native Void depthMask(Bool flag)
+  override native Void depthRange(Float zNear, Float zFar)
+  override native Void detachShader(GlProgram program, GlShader shader)
+  override native Void disable(GlEnum cap)
+  override native Void disableVertexAttribArray(Int index)
+  override native Void drawArrays(GlEnum mode, Int first, Int count)
+  override native Void drawElements(GlEnum mode, Int count, GlEnum type, Int offset)
+  override native Void enable(GlEnum cap)
+  override native Void enableVertexAttribArray(Int index)
+  override native Void finish()
+  override native Void flush()
+  override native Void framebufferRenderbuffer(GlEnum target, GlEnum attachment, GlEnum renderbuffertarget, GlRenderbuffer renderbuffer)
+  override native Void framebufferTexture2D(GlEnum target, GlEnum attachment, GlEnum textarget, GlTexture texture, Int level)
+  override native Void frontFace(GlEnum mode)
+  override native Void generateMipmap(GlEnum target)
+  override native Int getAttribLocation(GlProgram program, Str name)
+  override native GlUniformLocation getUniformLocation(GlProgram program, Str name)
+  override native Void hint(GlEnum target, GlEnum mode)
+  override native Bool isBuffer(GlBuffer buffer)
+  override native Bool isEnabled(GlEnum cap)
+  override native Bool isFramebuffer(GlFramebuffer framebuffer)
+  override native Bool isProgram(GlProgram program)
+  override native Bool isRenderbuffer(GlRenderbuffer renderbuffer)
+  override native Bool isShader(GlShader shader)
+  override native Bool isTexture(GlTexture texture)
+  override native Void lineWidth(Float width)
+  override native Void linkProgram(GlProgram program)
+  override native Void pixelStorei(GlEnum pname, Int param)
+  override native Void polygonOffset(Float factor, Float units)
+  override native Void renderbufferStorage(GlEnum target, GlEnum internalformat, Int width, Int height)
+  override native Void sampleCoverage(Float value, Bool invert)
+  override native Void scissor(Int x, Int y, Int width, Int height)
+  override native Void shaderSource(GlShader shader, Str source)
+  override native Void stencilFunc(GlEnum func, Int ref, Int mask)
+  override native Void stencilFuncSeparate(GlEnum face, GlEnum func, Int ref, Int mask)
+  override native Void stencilMask(Int mask)
+  override native Void stencilMaskSeparate(GlEnum face, Int mask)
+  override native Void stencilOp(GlEnum fail, GlEnum zfail, GlEnum zpass)
+  override native Void stencilOpSeparate(GlEnum face, GlEnum fail, GlEnum zfail, GlEnum zpass)
+  override native Void texParameterf(GlEnum target, GlEnum pname, Float param)
+  override native Void texParameteri(GlEnum target, GlEnum pname, Int param)
+  override native Void uniform1f(GlUniformLocation location, Float x)
+  override native Void uniform1i(GlUniformLocation location, Int x)
+  override native Void uniform2f(GlUniformLocation location, Float x, Float y)
+  override native Void uniform2i(GlUniformLocation location, Int x, Int y)
+  override native Void uniform3f(GlUniformLocation location, Float x, Float y, Float z)
+  override native Void uniform3i(GlUniformLocation location, Int x, Int y, Int z)
+  override native Void uniform4f(GlUniformLocation location, Float x, Float y, Float z, Float w)
+  override native Void uniform4i(GlUniformLocation location, Int x, Int y, Int z, Int w)
+  override native Void useProgram(GlProgram program)
+  override native Void validateProgram(GlProgram program)
+  override native Void vertexAttrib1f(Int indx, Float x)
+  override native Void vertexAttrib2f(Int indx, Float x, Float y)
+  override native Void vertexAttrib3f(Int indx, Float x, Float y, Float z)
+  override native Void vertexAttrib4f(Int indx, Float x, Float y, Float z, Float w)
+  override native Void vertexAttribPointer(Int indx, Int size, GlEnum type, Bool normalized, Int stride, Int offset)
+  override native Void viewport(Int x, Int y, Int width, Int height)
+}

fan3d/openGl/js/WebGlContext.js

 fan.fgfxOpenGl.WebGlContext.prototype.$ctor = function(self) {}
 fan.fgfxOpenGl.WebGlContext.prototype.gl = null;
 
+fan.fgfxOpenGl.WebGlContext.prototype.$typeof = function() { return fan.fgfxOpenGl.WebGlContext.$type; }
+
 //////////////////////////////////////////////////////////////////////////
 // special
 //////////////////////////////////////////////////////////////////////////

fan3d/test/fan/jsfan/Fan3dMain.fan

 
   Void main()
   {
-
     prog := Program
     (
-        Shader<|varying vec4 vertColor;
-                 attribute vec3 aVertexPosition;
+       Shader(Str<|varying vec4 vertColor;
+                   attribute vec3 aVertexPosition;
 
-                 uniform mat4 uMVMatrix;
-                 uniform mat4 uPMatrix;
+                   uniform mat4 uMVMatrix;
+                   uniform mat4 uPMatrix;
 
-                 void main(void) {
-                    gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
-                    vertColor = vec4(0.8, 0.3, 0.9, 1.0);
-                 }
-                 |>
+                   void main(void) {
+                      gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
+                      vertColor = vec4(0.8, 0.3, 0.9, 1.0);
+                   }
+                   |>)
         ,
-        Shader<|
-                 #ifdef GL_ES
-                 precision highp float;
-                 #endif
+       Shader(Str<|
+                   #ifdef GL_ES
+                   precision highp float;
+                   #endif
 
-                 varying vec4 vertColor;
+                   varying vec4 vertColor;
 
-                 void main(void) {
-                    gl_FragColor = vertColor;
-                 }
-                 |>
+                   void main(void) {
+                      gl_FragColor = vertColor;
+                   }
+                   |>)
     )
 
     obj := Object
   {
     scene.paint(gl)
   }
-}
+}
+

fan3d/test/startup.bat

-fan idraft -appHome file:/E:/Hg/fan3d/openGL/fan3dTest/ fgfx3dTest::RootMod
+fan idraft -appHome file:/E:/Hg/fan3d/fan3d/test/ fgfx3dTest::RootMod
 #fan idraft -appHome file:/home/jed/yjd/code/fgfx/fan3d/test/ fgfx3dTest::RootMod
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.