Skip to content

Commit de05ff3

Browse files
author
Joseph Hager
committed
Added implementation and documentation for most other methods
1 parent 7514906 commit de05ff3

File tree

1 file changed

+145
-33
lines changed

1 file changed

+145
-33
lines changed

webgl.go

Lines changed: 145 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,6 @@ func (c *Context) GetContextAttributes() ContextAttributes {
352352
}
353353
}
354354

355-
func (c *Context) IsContextLost() bool {
356-
return c.Call("isContextLost").Bool()
357-
}
358-
359355
// Specifies the active texture unit.
360356
func (c *Context) ActiveTexture(texture int) {
361357
c.Call("activeTexture", texture)
@@ -772,32 +768,92 @@ func (c *Context) GetVertexAttribOffset(index, pname int) int {
772768
}
773769

774770
// public function hint(target:GLenum, mode:GLenum) : Void;
775-
// public function isBuffer(buffer:WebGLBuffer) : GLboolean;
776-
// public function isEnabled(cap:GLenum) : GLboolean;
777-
// public function isFramebuffer(framebuffer:WebGLFramebuffer) : GLboolean;
778-
// public function isProgram(program:WebGLProgram) : GLboolean;
779-
// public function isRenderbuffer(renderbuffer:WebGLRenderbuffer) : GLboolean;
780-
// public function isShader(shader:WebGLShader) : GLboolean;
781-
// public function isTexture(texture:WebGLTexture) : GLboolean;
782771

772+
// Returns true if buffer is valid, false otherwise.
773+
func (c *Context) IsBuffer(buffer js.Object) bool {
774+
return c.Call("isBuffer", buffer).Bool()
775+
}
776+
777+
// Returns whether the WebGL context has been lost.
778+
func (c *Context) IsContextLost() bool {
779+
return c.Call("isContextLost").Bool()
780+
}
781+
782+
// Returns true if buffer is valid, false otherwise.
783+
func (c *Context) IsFramebuffer(framebuffer js.Object) bool {
784+
return c.Call("isFramebuffer", framebuffer).Bool()
785+
}
786+
787+
// Returns true if program object is valid, false otherwise.
788+
func (c *Context) IsProgram(program js.Object) bool {
789+
return c.Call("isProgram", program).Bool()
790+
}
791+
792+
// Returns true if buffer is valid, false otherwise.
793+
func (c *Context) IsRenderbuffer(renderbuffer js.Object) bool {
794+
return c.Call("isRenderbuffer", renderbuffer).Bool()
795+
}
796+
797+
// Returns true if shader is valid, false otherwise.
798+
func (c *Context) IsShader(shader js.Object) bool {
799+
return c.Call("isShader", shader).Bool()
800+
}
801+
802+
// Returns true if texture is valid, false otherwise.
803+
func (c *Context) IsTexture(texture js.Object) bool {
804+
return c.Call("isTexture", texture).Bool()
805+
}
806+
807+
// Returns whether or not a WebGL capability is enabled for this context.
808+
func (c *Context) IsEnabled(capability int) bool {
809+
return c.Call("isEnabled", capability).Bool()
810+
}
811+
812+
// Sets the width of lines in WebGL.
783813
func (c *Context) LineWidth(width float64) {
784814
c.Call("lineWidth", width)
785815
}
786816

817+
// Links an attached vertex shader and an attached fragment shader
818+
// to a program so it can be used by the graphics processing unit (GPU).
787819
func (c *Context) LinkProgram(program js.Object) {
788820
c.Call("linkProgram", program)
789821
}
790822

823+
// Sets pixel storage modes for readPixels and unpacking of textures
824+
// with texImage2D and texSubImage2D.
791825
func (c *Context) PixelStorei(pname, param int) {
792826
c.Call("pixelStorei", pname, param)
793827
}
794828

795-
// public function polygonOffset(factor:GLfloat, units:GLfloat) : Void;
796-
// public function readPixels(x:GLint, y:GLint, width:GLsizei, height:GLsizei, format:GLenum, type:GLenum, pixels:ArrayBufferView) : Void;
797-
// public function renderbufferStorage(target:GLenum, internalformat:GLenum, width:GLsizei, height:GLsizei) : Void;
798-
// public function sampleCoverage(value:GLclampf, invert:GLboolean) : Void;
799-
// public function scissor(x:GLint, y:GLint, width:GLsizei, height:GLsizei) : Void;
829+
// Sets the implementation-specific units and scale factor
830+
// used to calculate fragment depth values.
831+
func (c *Context) PolygonOffset(factor, units float64) {
832+
c.Call("polygonOffset", factor, units)
833+
}
834+
835+
// TODO: Figure out if pixels should be a slice.
836+
// Reads pixel data into an ArrayBufferView object from a
837+
// rectangular area in the color buffer of the active frame buffer.
838+
func (c *Context) ReadPixels(x, y, width, height, format, typ int, pixels js.Object) {
839+
c.Call("readPixels", x, y, width, height, format, typ, pixels)
840+
}
841+
842+
// Creates or replaces the data store for the currently bound WebGLRenderbuffer object.
843+
func (c *Context) RenderbufferStorage(target, internalFormat, width, height int) {
844+
c.Call("renderbufferStorage", target, internalFormat, width, height)
845+
}
846+
847+
//func (c *Context) SampleCoverage(value float64, invert bool) {
848+
// c.Call("sampleCoverage", value, invert)
849+
//}
800850

851+
// Sets the dimensions of the scissor box.
852+
func (c *Context) Scissor(x, y, width, height int) {
853+
c.Call("scissor", x, y, width, height)
854+
}
855+
856+
// Sets and replaces shader source code in a shader object.
801857
func (c *Context) ShaderSource(shader js.Object, source string) {
802858
c.Call("shaderSource", shader, source)
803859
}
@@ -809,23 +865,61 @@ func (c *Context) ShaderSource(shader js.Object, source string) {
809865
// public function stencilOp(fail:GLenum, zfail:GLenum, zpass:GLenum) : Void;
810866
// public function stencilOpSeparate(face:GLenum, fail:GLenum, zfail:GLenum, zpass:GLenum) : Void;
811867

868+
// Loads the supplied pixel data into a texture.
812869
func (c *Context) TexImage2D(target, level, internalFormat, format, kind int, image js.Object) {
813870
c.Call("texImage2D", target, level, internalFormat, format, kind, image)
814871
}
815872

873+
// Sets texture parameters for the current texture unit.
816874
func (c *Context) TexParameteri(target int, pname int, param int) {
817875
c.Call("texParameteri", target, pname, param)
818876
}
819877

820-
// public function texSubImage2D(target:GLenum, level:GLint, xoffset:GLint , yoffset:GLint, format:GLenum, type:GLenum, video:HTMLVideoElement) : Void;
821-
// public function uniform1f(location:WebGLUniformLocation, x:GLfloat) : Void;
822-
// public function uniform1i(location:WebGLUniformLocation, x:GLint) : Void;
823-
// public function uniform2f(location:WebGLUniformLocation, x:GLfloat, y:GLfloat) : Void;
824-
// public function uniform2i(location:WebGLUniformLocation, x:GLint, y:GLint) : Void;
825-
// public function uniform3f(location:WebGLUniformLocation, x:GLfloat, y:GLfloat, z:GLfloat) : Void;
826-
// public function uniform3i(location:WebGLUniformLocation, x:GLint, y:GLint, z:GLint) : Void;
827-
// public function uniform4f(location:WebGLUniformLocation, x:GLfloat, y:GLfloat, z:GLfloat, w:GLfloat) : Void;
828-
// public function uniform4i(location:WebGLUniformLocation, x:GLint, y:GLint, z:GLint, w:GLint) : Void;
878+
// Replaces a portion of an existing 2D texture image with all of another image.
879+
func (c *Context) TexSubImage2D(target, level, xoffset, yoffset, format, typ int, image js.Object) {
880+
c.Call("texSubImage2D", target, level, xoffset, yoffset, format, typ, image)
881+
}
882+
883+
// Assigns a floating point value to a uniform variable for the current program object.
884+
func (c *Context) Uniform1f(location js.Object, x float32) {
885+
c.Call("uniform1f", location, x)
886+
}
887+
888+
// Assigns a integer value to a uniform variable for the current program object.
889+
func (c *Context) Uniform1i(location js.Object, x int) {
890+
c.Call("uniform1i", location, x)
891+
}
892+
893+
// Assigns 2 floating point values to a uniform variable for the current program object.
894+
func (c *Context) Uniform2f(location js.Object, x, y float32) {
895+
c.Call("uniform2f", location, x, y)
896+
}
897+
898+
// Assigns 2 integer values to a uniform variable for the current program object.
899+
func (c *Context) Uniform2i(location js.Object, x, y int) {
900+
c.Call("uniform2i", location, x, y)
901+
}
902+
903+
// Assigns 3 floating point values to a uniform variable for the current program object.
904+
func (c *Context) Uniform3f(location js.Object, x, y, z float32) {
905+
c.Call("uniform3f", location, x, y, z)
906+
}
907+
908+
// Assigns 3 integer values to a uniform variable for the current program object.
909+
func (c *Context) Uniform3i(location js.Object, x, y, z int) {
910+
c.Call("uniform3i", location, x, y, z)
911+
}
912+
913+
// Assigns 4 floating point values to a uniform variable for the current program object.
914+
func (c *Context) Uniform4f(location js.Object, x, y, z, w float32) {
915+
c.Call("uniform4f", location, x, y, z, w)
916+
}
917+
918+
// Assigns 4 integer values to a uniform variable for the current program object.
919+
func (c *Context) Uniform4i(location js.Object, x, y, z, w int) {
920+
c.Call("uniform4i", location, x, y, z, w)
921+
}
922+
829923
// public function uniform1fv(location:WebGLUniformLocation, v:ArrayAccess<Float>) : Void;
830924
// public function uniform1iv(location:WebGLUniformLocation, v:ArrayAccess<Long>) : Void;
831925
// public function uniform2fv(location:WebGLUniformLocation, v:ArrayAccess<Float>) : Void;
@@ -834,32 +928,50 @@ func (c *Context) TexParameteri(target int, pname int, param int) {
834928
// public function uniform3iv(location:WebGLUniformLocation, v:ArrayAccess<Long>) : Void;
835929
// public function uniform4fv(location:WebGLUniformLocation, v:ArrayAccess<Float>) : Void;
836930
// public function uniform4iv(location:WebGLUniformLocation, v:ArrayAccess<Long>) : Void;
837-
// public function uniformMatrix2fv(location:WebGLUniformLocation, transpose:GLboolean, value:ArrayAccess<Float>) : Void;
838-
// public function uniformMatrix3fv(location:WebGLUniformLocation, transpose:GLboolean, value:ArrayAccess<Float>) : Void;
839931

932+
// Sets values for a 2x2 floating point vector matrix into a
933+
// uniform location as a matrix or a matrix array.
934+
func (c *Context) UniformMatrix2fv(location js.Object, transpose bool, value []float32) {
935+
c.Call("uniformMatrix2fv", location, transpose, value)
936+
}
937+
938+
// Sets values for a 3x3 floating point vector matrix into a
939+
// uniform location as a matrix or a matrix array.
940+
func (c *Context) UniformMatrix3fv(location js.Object, transpose bool, value []float32) {
941+
c.Call("uniformMatrix3fv", location, transpose, value)
942+
}
943+
944+
// Sets values for a 4x4 floating point vector matrix into a
945+
// uniform location as a matrix or a matrix array.
840946
func (c *Context) UniformMatrix4fv(location js.Object, transpose bool, value []float32) {
841947
c.Call("uniformMatrix4fv", location, transpose, value)
842948
}
843949

950+
// Set the program object to use for rendering.
844951
func (c *Context) UseProgram(program js.Object) {
845952
c.Call("useProgram", program)
846953
}
847954

955+
// Returns whether a given program can run in the current WebGL state.
848956
func (c *Context) ValidateProgram(program js.Object) {
849957
c.Call("validateProgram", program)
850958
}
851959

852-
// public function vertexAttrib1f(indx:GLuint, x:GLfloat) : Void;
853-
// public function vertexAttrib2f(indx:GLuint, x:GLfloat, y:GLfloat) : Void;
854-
// public function vertexAttrib3f(indx:GLuint, x:GLfloat, y:GLfloat, z:GLfloat) : Void;
855-
// public function vertexAttrib4f(indx:GLuint, x:GLfloat, y:GLfloat, z:GLfloat, w:GLfloat) : Void;
856-
857960
func (c *Context) VertexAttribPointer(index, size, typ int, normal bool, stride int, offset int) {
858961
c.Call("vertexAttribPointer", index, size, typ, normal, stride, offset)
859962
}
860963

964+
// public function vertexAttrib1f(indx:GLuint, x:GLfloat) : Void;
965+
// public function vertexAttrib2f(indx:GLuint, x:GLfloat, y:GLfloat) : Void;
966+
// public function vertexAttrib3f(indx:GLuint, x:GLfloat, y:GLfloat, z:GLfloat) : Void;
967+
// public function vertexAttrib4f(indx:GLuint, x:GLfloat, y:GLfloat, z:GLfloat, w:GLfloat) : Void;
861968
// public function vertexAttrib1fv(indx:GLuint, values:ArrayAccess<Float>) : Void;
862969
// public function vertexAttrib2fv(indx:GLuint, values:ArrayAccess<Float>) : Void;
863970
// public function vertexAttrib3fv(indx:GLuint, values:ArrayAccess<Float>) : Void;
864971
// public function vertexAttrib4fv(indx:GLuint, values:ArrayAccess<Float>) : Void;
865-
// public function viewport(x:GLint, y:GLint, width:GLsizei, height:GLsizei) : Void;
972+
973+
// Represents a rectangular viewable area that contains
974+
// the rendering results of the drawing buffer.
975+
func (c *Context) Viewport(x, y, width, height int) {
976+
c.Call("viewport", x, y, width, height)
977+
}

0 commit comments

Comments
 (0)