Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WebGL2 #838

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
962 changes: 962 additions & 0 deletions api-reports/2_12.txt

Large diffs are not rendered by default.

962 changes: 962 additions & 0 deletions api-reports/2_13.txt

Large diffs are not rendered by default.

9,999 changes: 9,999 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/WebGL2RenderingContext.scala

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/WebGLQuery.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2014 Matt Seddon. This source is donated in full to the scala-js-dom project.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, who is Matt Seddon? What is the origin and license of this code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this file and and several others by copying WebGLBuffer.scala and changing only the class name and comment. I didn't feel good about copying the code without the copyright statement. Did I err?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It looks like these contributions originated in #14. Thanks for bringing this to my attention.

To be clear, the issue is not the (C) 2014 Matt Seddon. The issue is that "donated in full" is not a well-known license. I don't know what that means. For example, does "donated in full" allow you to copy and modify the code like you just did in this PR?

@mseddon would you be able to clarify the license that this code is under?

Copy link
Contributor

@mseddon mseddon Jun 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, that is me, it appears to have crept in from a template I had years ago- please remove this and any comment like it, it is unnecessary. All code committed here is property of the scala-js-dom project. You have complete ownership of it, and I relinquish any perceived claims of ownership. I'm happy to merge. Apologies delaying this PR, and thank you @tsnee for contributing this much needed feature!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@armanbilge Confirming via ping since there hasn't been much movement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mseddon Thanks for the ping, I had missed this (although haven't had much time recently for sjs-dom maintenance). I appreciate the clarification! In retrospect, it should have been obvious that mseddon is Matt Seddon 😅

*
* Based on https://www.khronos.org/registry/webgl/specs/1.0/
*/

package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** An opaque type that provides ways to asynchronously query for information. By default, occlusion queries and
* primitive queries are available.
*/
@js.native
@JSGlobal
class WebGLQuery private[this] () extends js.Object
15 changes: 15 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/WebGLSampler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (C) 2014 Matt Seddon. This source is donated in full to the scala-js-dom project.
*
* Based on https://www.khronos.org/registry/webgl/specs/1.0/
*/

package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** An opaque type that stores sampling parameters for WebGLTexture access inside of a shader. */
@js.native
@JSGlobal
class WebGLSampler private[this] () extends js.Object
15 changes: 15 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/WebGLSync.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (C) 2014 Matt Seddon. This source is donated in full to the scala-js-dom project.
*
* Based on https://www.khronos.org/registry/webgl/specs/1.0/
*/

package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** An opaque type that is used to synchronize activities between the GPU and the application. */
@js.native
@JSGlobal
class WebGLSync private[this] () extends js.Object
18 changes: 18 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/WebGLTransformFeedback.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (C) 2014 Matt Seddon. This source is donated in full to the scala-js-dom project.
*
* Based on https://www.khronos.org/registry/webgl/specs/1.0/
*/

package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** An opaque type that enables transform feedback, which is the process of capturing primitives generated by vertex
* processing. It allows to preserve the post-transform rendering state of an object and resubmit this data multiple
* times.
*/
@js.native
@JSGlobal
class WebGLTransformFeedback private[this] () extends js.Object
15 changes: 15 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/WebGLVertexArrayObject.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (C) 2014 Matt Seddon. This source is donated in full to the scala-js-dom project.
*
* Based on https://www.khronos.org/registry/webgl/specs/1.0/
*/

package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** An opaque type representing a WebGL Vertex Array Object (VAO). */
@js.native
@JSGlobal
class WebGLVertexArrayObject private[this] () extends js.Object
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.scalajs.dom.webgl.extensions

import scala.scalajs.js

/** The EXT_texture_compression_bptc extension is part of the WebGL API and exposes 4 BPTC compressed texture formats.
* These compression formats are called BC7 and BC6H in Microsoft's DirectX API.
*
* WebGL extensions are available using the [[org.scalajs.dom.WebGLRenderingContext.getExtension]] and
* [[org.scalajs.dom.WebGL2RenderingContext.getExtension]] methods.
*
* Note: Support depends on the system's graphics driver. There is no support on Windows.
*
* Note: This extension is available to both WebGL1 and WebGL2 contexts.
*
* The compressed texture formats are exposed by four constants and can be used in the
* WebGL2RenderingContext.compressedTexImage2D and WebGL2RenderingContext.compressedTexSubImage2D functions.
*
* @see
* https://www.khronos.org/registry/webgl/extensions/EXT_texture_compression_bptc/
* @see
* https://docs.microsoft.com/windows/win32/direct3d11/bc7-format
* @see
* https://docs.microsoft.com/windows/win32/direct3d11/bc6h-format
* @example
* {{{
* val ext = gl.getExtension("EXT_texture_compression_bptc")
*
* val texture = gl.createTexture()
* gl.bindTexture(WebGLRenderingContext.TEXTURE_2D, texture)
*
* gl.compressedTexImage2D(
* WebGLRenderingContext.TEXTURE_2D,
* 0,
* ext.COMPRESSED_RGBA_BPTC_UNORM_EXT,
* 128,
* 128,
* 0,
* textureData
* )
* }}}
*/
@js.native
trait EXTTextureCompressionBPTC extends js.Object {

/** Compresses 8-bit fixed-point data. Each 4x4 block of texels consists of 128 bits of RGBA or image data. See also
* BC7 format.
*/
val COMPRESSED_RGBA_BPTC_UNORM_EXT: Int = js.native

/** Compresses 8-bit fixed-point data. Each 4x4 block of texels consists of 128 bits of SRGB_ALPHA or image data. See
* also BC7 format.
*/
val COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: Int = js.native

/** Compresses high dynamic range signed floating point values. Each 4x4 block of texels consists of 128 bits of RGB
* data. It only contains RGB data, so the returned alpha value is 1.0. See also BC6H format.
*/
val COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: Int = js.native

/** Compresses high dynamic range unsigned floating point values. Each 4x4 block of texels consists of 128 bits of RGB
* data. It only contains RGB data, so the returned alpha value is 1.0. See also BC6H format.
*/
val COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: Int = js.native
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.scalajs.dom.webgl.extensions

import scala.scalajs.js

/** The EXT_texture_compression_rgtc extension is part of the WebGL API and exposes 4 RGTC compressed texture formats.
* RGTC is a block-based texture compression format suited for unsigned and signed red and red-green textures
* (Red-Green Texture Compression).
*
* WebGL extensions are available using the [[org.scalajs.dom.WebGLRenderingContext.getExtension]] and
* [[org.scalajs.dom.WebGL2RenderingContext.getExtension]] methods.
*
* Note: Support depends on the system's graphics driver. There is no support on Windows.
*
* Note: This extension is available to both WebGL1 and WebGL2 contexts.
*
* The compressed texture formats are exposed by four constants and can be used in the
* WebGL2RenderingContext.compressedTexImage2D and WebGL2RenderingContext.compressedTexSubImage2D functions.
*
* @see
* https://www.khronos.org/registry/webgl/extensions/EXT_texture_compression_rgtc/
* @see
* https://docs.microsoft.com/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-block-compression#bc4
* @see
* https://docs.microsoft.com/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-block-compression#bc5
* @example
* {{{
* val ext = gl.getExtension("EXT_texture_compression_rgtc")
*
* val texture = gl.createTexture()
* gl.bindTexture(WebGLRenderingContext.TEXTURE_2D, texture)
*
* gl.compressedTexImage2D(
* WebGLRenderingContext.TEXTURE_2D,
* 0,
* ext.COMPRESSED_RED_RGTC1_EXT,
* 128,
* 128,
* 0,
* textureData
* )
* }}}
*/
@js.native
trait EXTTextureCompressionRGTC extends js.Object {

/** Each 4x4 block of texels consists of 64 bits of unsigned red image data. See also BC4 unsigned. */
val COMPRESSED_RED_RGTC1_EXT: Int = js.native

/** Each 4x4 block of texels consists of 64 bits of signed red image data. See also BC4 signed. */
val COMPRESSED_SIGNED_RED_RGTC1_EXT: Int = js.native

/** Each 4x4 block of texels consists of 64 bits of compressed unsigned red image data followed by 64 bits of
* compressed unsigned green image data. See also BC5 unsigned.
*/
val COMPRESSED_RED_GREEN_RGTC2_EXT: Int = js.native

/** Each 4x4 block of texels consists of 64 bits of compressed signed red image data followed by 64 bits of compressed
* signed green image data. See also BC5 signed.
*/
val COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: Int = js.native
}
Loading
Loading