ocsigen / js_of_ocaml

Compiler from OCaml to Javascript.
http://ocsigen.org/js_of_ocaml/
Other
958 stars 187 forks source link

Addition of web GL2 [FEATURE REQUEST] #1226

Open craff opened 2 years ago

craff commented 2 years ago

webGL2 is now pretty standard and js_of_ocaml only supports webGL1 and a few extension.

I actually started working on that... But there are a lot of valid combinations of internal format / format / type in function like texImage2D.

This raises two questions:

hhugo commented 2 years ago

I'm not very familiar with the Webgl api and the difference between GL1 and Gl2. Would you be able to provide more information and maybe concrete examples covering your two points above.

dbuenzli commented 2 years ago

Just in case you want something right now® I'd just mention that brr has bindings to webgl2 here (hello triangle here) . Regarding the larger question of whether you want to type the GL APIs I'd say it's more trouble than benefits.

craff commented 2 years ago

On 22-01-18 06:07:03, hhugo wrote:

I'm not very familiar with the Webgl api and the difference between GL1 and Gl2. Would you be able to provide more information and maybe concrete examples covering your two points above.

The main differences are:

Look for instance at

https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/texImage2D

The number of possible values for internalformat and format exploses.

Some of these values are very usefull for shadow mapping, fine tunning of performance and other modern techniques in GL.

Moreover, webGL1, is more or less deprecated in practice.

I have a version of js_of_ocaml working with webGL2 and only the extension I need currently. To finish the port I need to take a decision regarding the webGL type

dataType / pixelType / pixelFormat.

with webGL2, type and pixelType have many more common values in webGL there was only method _UNSIGNED_BYTE_DT : dataType readonly_prop method _UNSIGNEDBYTE : pixelType readonly_prop

in webGL there was no distinction between format and internalFormat (both represented as pixelFormat).

I think these should be moved to parametric types

'a dataType and 'a pixelFormat

using a phantom type to distinguish the various usages.

for instance this would give:

method texImage2D_new :
     texTarget
  -> int
  -> [`TexImageInternal] pixelFormat
  -> sizei
  -> sizei
  -> int
  -> [`TexImage] pixelFormat
  -> [`TexImage] dataType
  -> void opt
  -> unit meth

An option to go further would be to add more parameter to the types to handle the coherence between the 3 arguments with something like:

method texImage2D_new :
     texTarget
  -> int
  -> ([`TexImageInternal],'a,'b) pixelFormat
  -> sizei
  -> sizei
  -> int
  -> ([`TexImage],'a) pixelFormat
  -> ([`TexImage],'b) dataType
  -> void opt
  -> unit meth

But this requires a lot of investigations ... and probably auto generation.

Cheers, Christophe

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.*Message ID: <ocsigen/ @.***>

-- Christophe Raffalli tél: +689 87 23 11 48 web: http://raffalli.eu