Class WGLWidget
- Direct Known Subclasses:
WCartesian3DChart
The WGLWidget
class is an interface to the HTML5 WebGL infrastructure for client-side
rendering, and OpenGL for server-side rendering. Its API is based on the WebGL API. To fully
understand WebGL, it is recommended to read the WebGL standard in addition to this documentation.
The most recent version of the WebGL specification can be found here: http://www.khronos.org/registry/webgl/specs/latest/1.0/
The goal of the WGLWidget
class is to provide a method to render 3D structures in the
browser, where rendering and rerendering is normally done at the client side in JavaScript
without interaction from the server, in order to obtain a smooth user interaction. Unless the
scene requires server-side updates, there is no communication with the server.
The rendering interface resembles to OpenGL ES, the same standard as WebGL is based on. This is a stripped down version of the normal OpenGL as we usually find them on desktops. Many stateful OpenGL features are not present in OpenGL ES: no modelview and camera transformation stacks, no default lighting models, no support for other rendering methods than through VBOs, ... Therefore much existing example code for OpenGL applications and shaders will not work on WebGL without modifications. The 'learning webgl' web site at http://learningwebgl.com/ is a good starting point to get familiar with WebGL.
To use a WGLWidget, you must derive from it and reimplement the painter methods. Usually, you
will always need to implement initializeGL()
and paintGL()
. Optionally, you may choose to implement resizeGL()
(if your widget does not have a fixed
size), and updateGL()
. If you need to modify the painting methods, a
repaint is triggered by calling the repaintGL()
method. The default behaviour for any of these four painting functions is to do nothing.
The four painter methods (initializeGL()
, resizeGL()
, paintGL()
and
updateGL()
) all record JavaScript which is sent to the browser. The
JavaScript code of paintGL()
is cached client-side, and may be
executed many times, e.g. to repaint a scene from different viewpoints. The JavaScript code of
initializeGL()
, resizeGL()
and updateGL()
are intended for OpenGL state updates,
and is therefore only executed once on the client and is then discarded.
There are four painting methods that you may implement in a specialization of this class. The purpose of these functions is to register what JavaScript code has to be executed to render a scene. Through invocations of the WebGL functions documented below, JWt records the JavaScript calls that have to be invoked in the browser.
initializeGL()
: this function is executed after the GL context has been initialized. It is also executed when thewebglcontextrestored
signal is fired. You can distinguish between the first initialization and restoration of context usingisRestoringContext()
. This is the ideal location to compose shader programs, send VBO's to the client, extract uniform and attribute locations, ... Due to the presence of VBO's, this function may generate a large amount of data to the client.resizeGL()
: this function is executed whenever the canvas dimensions change. A change in canvas size will require you to invoke theviewport()
function again, as well as recalculate the projection matrices (especially when the aspect ratio has changed). TheresizeGL()
function is therefore the ideal location to set those properties. TheresizeGL()
function is invoked automatically on every resize, and after the firstinitializeGL()
invocation. Additional invocations may be triggered by calling repaint() with the RESIZE_GL flag.paintGL()
: this is the main scene drawing function. Through its execution, JWt records what has to be done to render a scene, and it is executed every time that the scene is to be redrawn. You can use the VBO's and shaders prepared in theinitializeGL()
phase. Usually, this function sets uniforms and attributes, links attributes to VBO's, applies textures, and draws primitives. You may also create local programs, buffers, ... Remember that this function is executed a lot of times, so every buffer/program created in this function should also be destroyed to avoid memory leaks. This function is transmitted once to the client, and is executed when the scene needs to be redrawn. Redraws may be triggered from mouse events, timer triggers, events on e.g. a video element, or whatever other event. ThepaintGL()
function can be updated through invokingrepaintGL()
with the PAINT_GL flag.updateGL()
: VBO's, programs, uniforms, GL properties, or anything else set during intializeGL() are not necessarily immutable. If you want to change, add, remove or reconfigure those properties, the execution of anupdateGL()
function can be triggered by invokingrepaintGL()
with the UPDATE_GL flag. This signals thatupdateGL()
needs to be evaluated - just once. It is possible that thepaintGL()
function also requires updates as consequence of the changes in theupdateGL()
function; in this case, you should also set the PAINT_GL flag ofrepaintGL()
.
The GL functions are intended to be used exclusively from within the invocation of the four
callback functions mentioned above. In order to manually trigger the execution of these function,
use the repaintGL()
.
A WGLWidget
must be given a size explicitly, or must be put inside a layout manager
that manages its width and height. The behaviour of a WGLWidget
that was not given a size
is undefined.
Binary buffer transfers
In bufferDatafv()
, there is an additional boolean argument
where you can indicate that you want the data to be transferred to the client in binary form. A
WMemoryResource
is created for each of these buffers. If you know all previous resources
are not required in the client anymore, you can free memory with the method clearBinaryResources()
(the memory is also managed, so this is
not neccesary). If you want to manage these resources entirely by yourself, the following method
can be used.
Using createAndLoadArrayBuffer(), you can load an array buffer in binary format from an URL.
This will cause the client to fetch the given URL, and make the contents of the file available in
an WGLWidget.ArrayBuffer
, which can then be used by BufferData() to bind them to an OpenGL buffer.
This is ideal to load VBO buffers in a faster way, as it avoids converting floats to text strings
on the server and then back to floats on the client. You can combine this with the use of WResource
(e.g. WMemoryResource
) to send an std::vector of vertices to the client. Note
that using WGLWidget.ArrayBuffer
is not possible when you want a fall-back in the form of
server-side rendering.
Client side matrices and vectors.
The WGLWidget
provides the WGLWidget.JavaScriptMatrix4x4
class as a mechanism to use
client-side modifiable matrices in the render functions. These matrices can be used identically
to the 'constant', with the advantage that there is no need to have a roundtrip to the
server to redraw the scene when they are changed. As such, they are ideal for mouse-based camera
manipulations, timer triggered animations, or object manipulations.
There's also support for client-side modifiable vectors, with WGLWidget.JavaScriptVector
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Reference to a javascript ArrayBuffer class.static class
Reference to a shader attribute location.static class
Reference to a WebGLBuffer class.static class
Reference to a WebGLFramebuffer class.static enum
The enormous GLenum.static class
Abstract base class for all GL objects.static class
A client-side JavaScript matrix.static class
A client-side JavaScript vector.static class
Reference to a WebGLProgram class.static class
Reference to a WebGLRenderbuffer class.static class
Reference to a WebGLShader class.static class
Reference to a WebGLTexture class.static class
Reference to a WebGLUniformLocation class.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_
-
Constructor Summary
ConstructorDescriptionConstruct a GL widget.WGLWidget
(WContainerWidget parentContainer) Construct a GL widget. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activeTexture
(WGLWidget.GLenum texture) GL function to activate an existing texture.void
Register a matrix with thisWGLWidget
.void
Register a vector with thisWGLWidget
.void
attachShader
(WGLWidget.Program program, WGLWidget.Shader shader) GL function to attach a shader to a program.void
bindAttribLocation
(WGLWidget.Program program, int index, String name) GL function to bind an attribute to a given location.void
bindBuffer
(WGLWidget.GLenum target, WGLWidget.Buffer buffer) GL function to bind a buffer to a target.void
bindFramebuffer
(WGLWidget.GLenum target, WGLWidget.Framebuffer buffer) GL function to bind a frame buffer to a target.void
bindRenderbuffer
(WGLWidget.GLenum target, WGLWidget.Renderbuffer buffer) GL function to bind a render buffer to a target.void
bindTexture
(WGLWidget.GLenum target, WGLWidget.Texture texture) GL function to bind a texture to a target.void
blendColor
(double red, double green, double blue, double alpha) GL function to set the blending color.void
GL function to set the blending equation.void
blendEquationSeparate
(WGLWidget.GLenum modeRGB, WGLWidget.GLenum modeAlpha) GL function that sets separate blending functions for RGB and alpha.void
blendFunc
(WGLWidget.GLenum sfactor, WGLWidget.GLenum dfactor) GL function to configure the blending function.void
blendFuncSeparate
(WGLWidget.GLenum srcRGB, WGLWidget.GLenum dstRGB, WGLWidget.GLenum srcAlpha, WGLWidget.GLenum dstAlpha) GL function that configures the blending function.void
bufferData
(WGLWidget.GLenum target, int size, WGLWidget.GLenum usage) glBufferData - create and initialize a buffer object's data storevoid
bufferData
(WGLWidget.GLenum target, WGLWidget.ArrayBuffer res, int bufferResourceOffset, int bufferResourceSize, WGLWidget.GLenum usage) glBufferData - create and initialize a buffer object's data store from anWGLWidget.ArrayBuffer
void
bufferData
(WGLWidget.GLenum target, WGLWidget.ArrayBuffer res, WGLWidget.GLenum usage) glBufferData - create and initialize a buffer object's data store from anWGLWidget.ArrayBuffer
final void
bufferDatafv
(WGLWidget.GLenum target, ByteBuffer buffer, WGLWidget.GLenum usage) GL function that loads float or double data in a VBO.void
bufferDatafv
(WGLWidget.GLenum target, ByteBuffer buffer, WGLWidget.GLenum usage, boolean binary) GL function that loads float or double data in a VBO.void
bufferDatafv
(WGLWidget.GLenum target, FloatBuffer buffer, WGLWidget.GLenum usage) void
bufferDataiv
(WGLWidget.GLenum target, IntBuffer buffer, WGLWidget.GLenum usage, WGLWidget.GLenum type) GL function that updates an existing VBO with new integer data.void
bufferSubData
(WGLWidget.GLenum target, int offset, WGLWidget.ArrayBuffer res) Initialize a buffer object's data store from anWGLWidget.ArrayBuffer
.void
bufferSubData
(WGLWidget.GLenum target, int offset, WGLWidget.ArrayBuffer res, int bufferResourceOffset, int bufferResourceSize) Initialize a buffer object's data store from anWGLWidget.ArrayBuffer
.final void
bufferSubDatafv
(WGLWidget.GLenum target, int offset, ByteBuffer buffer) GL function that updates an existing VBO with new float data.void
bufferSubDatafv
(WGLWidget.GLenum target, int offset, ByteBuffer buffer, boolean binary) GL function that updates an existing VBO with new float data.void
bufferSubDatafv
(WGLWidget.GLenum target, int offset, FloatBuffer buffer) void
bufferSubDataiv
(WGLWidget.GLenum target, int offset, IntBuffer buffer, WGLWidget.GLenum type) GL function that loads integer data in a VBO.final void
clear
(WGLWidget.GLenum mas, WGLWidget.GLenum... mask) GL function that clears the given buffers.void
clear
(EnumSet<WGLWidget.GLenum> mask) GL function that clears the given buffers.void
remove all binary buffer resourcesvoid
clearColor
(double r, double g, double b, double a) GL function that sets the clear color of the color buffer.void
clearDepth
(double depth) GL function that configures the depth to be set when the depth buffer is cleared.void
clearStencil
(int s) GL function.void
colorMask
(boolean red, boolean green, boolean blue, boolean alpha) GL function.void
compileShader
(WGLWidget.Shader shader) GL function to compile a shader.protected void
void
copyTexImage2D
(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalFormat, int x, int y, int width, int height, int border) GL function to copy a texture image.void
copyTexSubImage2D
(WGLWidget.GLenum target, int level, int xoffset, int yoffset, int x, int y, int width, int height) GL function that copies a part of a texture image.GL function that creates an empty VBO.protected DomElement
Create DOM element for widget.Create a matrix that can be manipulated in client-side JavaScript.createJavaScriptVector
(int length) Create a vector of a certain length that can be manipulated in client-side JavaScript.createPaintDevice
(WLength width, WLength height) returns an paintdevice that can be used to paint a GL textureGL function that creates an empty program.createShader
(WGLWidget.GLenum shader) GL function that creates an empty shader.GL function that creates an empty texture.GL function that creates an image texture.void
cullFace
(WGLWidget.GLenum mode) GL function that configures the backface culling mode.void
debugger()
void
deleteBuffer
(WGLWidget.Buffer buffer) GL function that deletes a VBO.void
GL function that deletes a frame buffer.void
deleteProgram
(WGLWidget.Program program) GL function that deletes a program.void
GL function that deletes a render buffer.void
deleteShader
(WGLWidget.Shader shader) GL function that depetes a shader.void
deleteTexture
(WGLWidget.Texture texture) GL function that deletes a texture.void
depthFunc
(WGLWidget.GLenum func) GL function to set the depth test function.void
depthMask
(boolean flag) GL function that enables or disables writing to the depth buffer.void
depthRange
(double zNear, double zFar) GL function that specifies to what range the normalized [-1,1] z values should match.void
detachShader
(WGLWidget.Program program, WGLWidget.Shader shader) GL function that detaches a shader from a program.void
disable
(WGLWidget.GLenum cap) GL function to disable features.void
GL function to disable the vertex attribute array.void
drawArrays
(WGLWidget.GLenum mode, int first, int count) GL function to draw a VBO.void
drawElements
(WGLWidget.GLenum mode, int count, WGLWidget.GLenum type, int offset) GL function to draw indexed VBOs.void
enable
(WGLWidget.GLenum cap) GL function to enable features.final void
enable client-side error messages (read detailed doc!)void
enableClientErrorChecks
(boolean enable) enable client-side error messages (read detailed doc!)void
GL function to enable the vertex attribute array.void
finish()
GL function to wait until given commands are executed.void
flush()
GL function to force execution of GL commands in finite time.void
framebufferRenderbuffer
(WGLWidget.GLenum target, WGLWidget.GLenum attachment, WGLWidget.GLenum renderbuffertarget, WGLWidget.Renderbuffer renderbuffer) GL function to attach the given renderbuffer to the currently bound frame buffer.void
framebufferTexture2D
(WGLWidget.GLenum target, WGLWidget.GLenum attachment, WGLWidget.GLenum textarget, WGLWidget.Texture texture, int level) GL function to render directly into a texture image.void
frontFace
(WGLWidget.GLenum mode) GL function that specifies which side of a triangle is the front side.void
generateMipmap
(WGLWidget.GLenum target) GL function that generates a set of mipmaps for a texture object.getAttribLocation
(WGLWidget.Program program, String attrib) GL function to retrieve an attribute's location in aWGLWidget.Program
.GL function that creates a frame buffer object.GL function that creates a render buffer object.protected void
getDomChanges
(List<DomElement> result, WApplication app) Get DOM changes for this widget.A JavaScript slot that repaints the widget when triggered.getUniformLocation
(WGLWidget.Program program, String location) GL function to retrieve a Uniform's location in aWGLWidget.Program
.void
hint
(WGLWidget.GLenum target, WGLWidget.GLenum mode) GL function to give hints to the render pipeline.protected void
Initialize the GL state when the widget is first shown.void
Initialize the client-side JavaScript for the givenWGLWidget.JavaScriptMatrix4x4
.void
Initialize the client-side JavaScript for the givenWGLWidget.JavaScriptVector
.void
Inject JavaScript into the current js-stream.boolean
Returns whether a lost context is in the process of being restored.protected void
layoutSizeChanged
(int width, int height) Virtual method that indicates a size change.void
lineWidth
(double width) GL function to set the line width.void
linkProgram
(WGLWidget.Program program) GL function to link a program.protected void
paintGL()
Update the client-side painting function.void
pixelStorei
(WGLWidget.GLenum pname, int param) GL function to set the pixel storage mode.void
polygonOffset
(double factor, double units) GL function to apply modifications to Z values.void
remove()
Destructor.protected void
render
(EnumSet<RenderFlag> flags) Renders the widget.void
renderbufferStorage
(WGLWidget.GLenum target, WGLWidget.GLenum internalformat, int width, int height) GL function to allocate the appropriate amount of memory for a render buffer.final void
repaintGL
(GLClientSideRenderer whic, GLClientSideRenderer... which) Request invocation of resizeGL, paintGL and/or updateGL.void
repaintGL
(EnumSet<GLClientSideRenderer> which) Request invocation of resizeGL, paintGL and/or updateGL.void
Resizes the widget.protected void
resizeGL
(int width, int height) Act on resize events.void
sampleCoverage
(double value, boolean invert) GL function to set multisample parameters.void
scissor
(int x, int y, int width, int height) GL function to define the scissor box.void
setAlternativeContent
(WWidget alternative) Sets the content to be displayed when WebGL is not available.void
setClientSideLookAtHandler
(WGLWidget.JavaScriptMatrix4x4 m, double centerX, double centerY, double centerZ, double uX, double uY, double uZ, double pitchRate, double yawRate) Add a mouse handler to the widget that looks at a given point.void
setClientSideMouseHandler
(String handlerCode) Set a custom mouse handler based on the given JavaScript code.void
setClientSideWalkHandler
(WGLWidget.JavaScriptMatrix4x4 m, double frontStep, double rotStep) Add a mouse handler to the widget that allows 'walking' in the scene.protected void
setFormData
(WObject.FormData formData) void
setJavaScriptMatrix4
(WGLWidget.JavaScriptMatrix4x4 jsm, javax.vecmath.Matrix4f m) Set the value of a client-side JavaScript matrix created by createJavaScriptMatrix4x4()void
Set the value of a client-side JavaScript vector created bycreateJavaScriptVector()
final void
setRenderOptions
(GLRenderOption option, GLRenderOption... options) Sets the rendering option.void
setRenderOptions
(EnumSet<GLRenderOption> options) Sets the rendering option.void
shaderSource
(WGLWidget.Shader shader, String src) GL function to set a shader's source code.void
stencilFunc
(WGLWidget.GLenum func, int ref, int mask) GL function to set stencil test parameters.void
stencilFuncSeparate
(WGLWidget.GLenum face, WGLWidget.GLenum func, int ref, int mask) GL function to set stencil test parameters for front and/or back stencils.void
stencilMask
(int mask) GL function to control which bits are to be written in the stencil buffer.void
stencilMaskSeparate
(WGLWidget.GLenum face, int mask) GL function to control which bits are written to the front and/or back stencil buffers.void
stencilOp
(WGLWidget.GLenum fail, WGLWidget.GLenum zfail, WGLWidget.GLenum zpass) GL function to set stencil test actions.void
stencilOpSeparate
(WGLWidget.GLenum face, WGLWidget.GLenum fail, WGLWidget.GLenum zfail, WGLWidget.GLenum zpass) GL function to set front and/or back stencil test actions separately.void
texImage2D
(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, int width, int height, int border, WGLWidget.GLenum format) GL function to reserve space for a 2D texture, without specifying its contents.void
texImage2D
(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, WGLWidget.Texture texture) GL function to load a 2D texture loaded withcreateTextureAndLoad()
void
texImage2D
(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, WImage image) GL function to load a 2D texture from aWImage
.void
texImage2D
(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, WPaintDevice paintdevice) GL function to load a 2D texture from aWPaintDevice
.void
texImage2D
(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, WVideo video) GL function to load a 2D texture from aWVideo
.void
texImage2D
(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, String imgFilename) GL function to load a 2D texture from a file.void
texParameteri
(WGLWidget.GLenum target, WGLWidget.GLenum pname, WGLWidget.GLenum param) GL function to set texture parameters.void
uniform1f
(WGLWidget.UniformLocation location, double x) GL function to set the value of a uniform variable of the current program.void
uniform1fv
(WGLWidget.UniformLocation location, float[] value) GL function to set the value of a uniform variable of the current program.void
GL function to set the value of a uniform variable of the current program.void
uniform1i
(WGLWidget.UniformLocation location, int x) GL function to set the value of a uniform variable of the current program.void
uniform1iv
(WGLWidget.UniformLocation location, int[] value) GL function to set the value of a uniform variable of the current program.void
uniform2f
(WGLWidget.UniformLocation location, double x, double y) GL function to set the value of a uniform variable of the current program.void
uniform2fv
(WGLWidget.UniformLocation location, float[] value) GL function to set the value of a uniform variable of the current program.void
GL function to set the value of a uniform variable of the current program.void
uniform2i
(WGLWidget.UniformLocation location, int x, int y) GL function to set the value of a uniform variable of the current program.void
uniform2iv
(WGLWidget.UniformLocation location, int[] value) GL function to set the value of a uniform variable of the current program.void
uniform3f
(WGLWidget.UniformLocation location, double x, double y, double z) GL function to set the value of a uniform variable of the current program.void
uniform3fv
(WGLWidget.UniformLocation location, float[] value) GL function to set the value of a uniform variable of the current program.void
GL function to set the value of a uniform variable of the current program.void
uniform3i
(WGLWidget.UniformLocation location, int x, int y, int z) GL function to set the value of a uniform variable of the current program.void
uniform3iv
(WGLWidget.UniformLocation location, int[] value) GL function to set the value of a uniform variable of the current program.void
uniform4f
(WGLWidget.UniformLocation location, double x, double y, double z, double w) GL function to set the value of a uniform variable of the current program.void
uniform4fv
(WGLWidget.UniformLocation location, float[] value) GL function to set the value of a uniform variable of the current program.void
GL function to set the value of a uniform variable of the current program.void
uniform4i
(WGLWidget.UniformLocation location, int x, int y, int z, int w) GL function to set the value of a uniform variable of the current program.void
uniform4iv
(WGLWidget.UniformLocation location, int[] value) GL function to set the value of a uniform variable of the current program.void
uniformMatrix2
(WGLWidget.UniformLocation location, Matrix2f m) GL function to set the value of a uniform matrix of the current program.void
uniformMatrix2fv
(WGLWidget.UniformLocation location, boolean transpose, double[] value) GL function to set the value of a uniform matrix of the current program.void
uniformMatrix3
(WGLWidget.UniformLocation location, javax.vecmath.Matrix3f m) GL function to set the value of a uniform matrix of the current program.void
uniformMatrix3fv
(WGLWidget.UniformLocation location, boolean transpose, double[] value) GL function to set the value of a uniform matrix of the current program.void
uniformMatrix4
(WGLWidget.UniformLocation location, WGLWidget.JavaScriptMatrix4x4 jsm) GL function to set the value of a uniform matrix of the current program.void
uniformMatrix4
(WGLWidget.UniformLocation location, javax.vecmath.Matrix4f m) GL function to set the value of a uniform matrix of the current program.void
uniformMatrix4fv
(WGLWidget.UniformLocation location, boolean transpose, double[] value) GL function to set the value of a uniform matrix of the current program.protected void
updateGL()
Update state set ininitializeGL()
void
useProgram
(WGLWidget.Program program) GL function to set the current active shader program.void
validateProgram
(WGLWidget.Program program) GL function to validate a program.void
vertexAttrib1f
(WGLWidget.AttribLocation location, double x) GL function to set the value of an attribute of the current program.void
vertexAttrib2f
(WGLWidget.AttribLocation location, double x, double y) GL function to set the value of an attribute of the current program.void
vertexAttrib2fv
(WGLWidget.AttribLocation location, float[] values) GL function to set the value of an attribute of the current program.void
vertexAttrib3f
(WGLWidget.AttribLocation location, double x, double y, double z) GL function to set the value of an attribute of the current program.void
vertexAttrib3fv
(WGLWidget.AttribLocation location, float[] values) GL function to set the value of an attribute of the current program.void
vertexAttrib4f
(WGLWidget.AttribLocation location, double x, double y, double z, double w) GL function to set the value of an attribute of the current program.void
vertexAttrib4fv
(WGLWidget.AttribLocation location, float[] values) GL function to set the value of an attribute of the current program.void
vertexAttribPointer
(WGLWidget.AttribLocation location, int size, WGLWidget.GLenum type, boolean normalized, int stride, int offset) GL function to bind a VBO to an attribute.void
viewport
(int x, int y, int width, int height) GL function to set the viewport.void
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, doJavaScript, enableAjax, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, iterateChildren, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, refresh, removeScript, removeStyleClass, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, needsRerender, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
Constructor Details
-
WGLWidget
Construct a GL widget.Before the first rendering, you must apply a size to the
WGLWidget
. -
WGLWidget
public WGLWidget()Construct a GL widget.
-
-
Method Details
-
remove
public void remove()Destructor.- Overrides:
remove
in classWInteractWidget
- See Also:
-
setRenderOptions
Sets the rendering option.Use this method to configure whether client-side and/or server-side rendering can be used, and whether anti-aliasing should be enabled. The actual choice is also based on availability (respectively client-side or server-side).
The default value is to try both ClientSide or ServerSide rendering, and to enable anti-aliasing if available.
Note: Options must be set before the widget is being rendered.
-
setRenderOptions
Sets the rendering option. -
initializeGL
protected void initializeGL()Initialize the GL state when the widget is first shown.initializeGL()
is called when the widget is first rendered, and when the webglcontextrestored signal is fired. You can distinguish between the first initialization and context restoration usingisRestoringContext()
. It usually creates most of the GL related state: shaders, VBOs, uniform locations, ...If this state is to be updated during the lifetime of the widget, you should specialize the
updateGL()
to accomodate for this. -
resizeGL
protected void resizeGL(int width, int height) Act on resize events.Usually, this method only contains functions to set the viewport and the projection matrix (as this is aspect ration dependent).
resizeGL()
is rendered after initializeGL, and whenever widget is resized. After this method finishes, the widget is repainted with the cached client-side paint function. -
paintGL
protected void paintGL()Update the client-side painting function.This method is invoked client-side when a repaint is required, i.e. when the
getRepaintSlot()
(a JavaScript-sideJSlot
) is triggered. Typical examples are: after mouse-based camera movements, after a timed update of a camera or an object's position, after a resize event (resizeGL()
will also be called then), after an animation event, ... In many cases, this function will be executed client-side many many times.Using the GL functions from this class, you construct a scene. The implementation tracks all JavaScript calls that need to be performed to draw the scenes, and will replay them verbatim on every trigger of the
getRepaintSlot()
. There are a few mechanisms that may be employed to change what is rendered without updating thepaintGL()
cache:- Client-side matrices may be used to change camera viewpoints, manipilate separate object's model transformation matrices, ...
WGLWidget.Shader
sources can be updated without requiring the paint function to be renewed
Updating the
paintGL()
cache is usually not too expensive; the VBOs, which are large in many cases, are already at the client side, while thepaintGL()
code only draws the VBOs. Of course, if you have to draw many separate objects, thepaintGL()
JS code may become large and updating is more expensive.In order to update the
paintGL()
cache, callrepaintGL()
with the PAINT_GL parameter, which will cause the invocation of this method. -
updateGL
protected void updateGL()Update state set ininitializeGL()
Invoked when repaint is called with the UPDATE_GL call.
This is intended to be executed when you want to change programs, 'constant' uniforms, or even VBO's, ... without resending already initialized data. It is a mechanism to make changes to what you've set in intializeGL(). For every server-side invocation of this method, the result will be rendered client-side exactly once.
-
repaintGL
Request invocation of resizeGL, paintGL and/or updateGL.If invoked with PAINT_GL, the client-side cached paint function is updated. If invoked with RESIZE_GL or UPDATE_GL, the code will be executed once.
If invoked with multiple flags set, the order of execution will be
updateGL()
,resizeGL()
,paintGL()
. -
repaintGL
Request invocation of resizeGL, paintGL and/or updateGL. -
isRestoringContext
public boolean isRestoringContext()Returns whether a lost context is in the process of being restored.You can check for this in
initializeGL()
, to handle the first initialization and restoration of context differently. -
resize
Description copied from class:WWidget
Resizes the widget.Specifies a fixed size for this widget, setting CSS
width
andheight
properties. By default a widget has automatic width and height, which sets a size for the widget following CSS rules.When the widget is not managed by a layout manager, the automatic (natural) size of a widget depends on whether they widget is a block or inline widget:
- a block widget takes by default the width of the parent, and the height that it needs based on its contents
- an inline widget takes the width and height that it needs based on its contents (possibly wrapping over multiple lines). The width and height of an inline widget cannot be changed (by the letter of CSS, although most browsers will react to it in varying ways).
When inserted in a layout manager, the size set will be used as a widget's preferred size, but the widget may be given a different size by the layout manager based on available space and stretch factors. The actual size given by a layout manager may be retrieved by making the widget "layout size aware", using
setLayoutSizeAware()
. If you have defined a"wtResize()"
JavaScript method for the widget, then this method will also be called.The default width and height of a widget is
WLength.Auto
.- Overrides:
resize
in classWWebWidget
- See Also:
-
debugger
public void debugger() -
activeTexture
GL function to activate an existing texture. -
attachShader
GL function to attach a shader to a program. -
bindAttribLocation
GL function to bind an attribute to a given location. -
bindBuffer
GL function to bind a buffer to a target. -
bindFramebuffer
GL function to bind a frame buffer to a target. -
bindRenderbuffer
GL function to bind a render buffer to a target. -
bindTexture
GL function to bind a texture to a target. -
blendColor
public void blendColor(double red, double green, double blue, double alpha) GL function to set the blending color. -
blendEquation
GL function to set the blending equation. -
blendEquationSeparate
GL function that sets separate blending functions for RGB and alpha. -
blendFunc
GL function to configure the blending function. -
blendFuncSeparate
public void blendFuncSeparate(WGLWidget.GLenum srcRGB, WGLWidget.GLenum dstRGB, WGLWidget.GLenum srcAlpha, WGLWidget.GLenum dstAlpha) GL function that configures the blending function. -
bufferData
glBufferData - create and initialize a buffer object's data storeSet the size of the currently bound WebGLBuffer object for the passed target. The buffer is initialized to 0.
-
bufferData
glBufferData - create and initialize a buffer object's data store from anWGLWidget.ArrayBuffer
Set the size and contents of the currently bound WebGLBuffer object to be a copy of the given
WGLWidget.ArrayBuffer
.glBufferData() OpenGL ES manpage
Note: an
WGLWidget.ArrayBuffer
refers to a javascript object, which cannot be used for server-side rendering. If a server-side fallback will be used, thenbufferDatafv()
should be used with the additional boolean argument to indicate binary transfer of the data in case of client-side rendering. -
bufferData
public void bufferData(WGLWidget.GLenum target, WGLWidget.ArrayBuffer res, int bufferResourceOffset, int bufferResourceSize, WGLWidget.GLenum usage) glBufferData - create and initialize a buffer object's data store from anWGLWidget.ArrayBuffer
Set the size of the currently bound WebGLBuffer object to arrayBufferSize, and copy the contents of the
WGLWidget.ArrayBuffer
to the buffer, starting at the given offset.glBufferData() OpenGL ES manpage
Note: not functional for a server-side fall-back (see
bufferData()
for more info) -
bufferSubData
Initialize a buffer object's data store from anWGLWidget.ArrayBuffer
.Load the data of the currently bound WebGLBuffer object from the given
WGLWidget.ArrayBuffer
. The first byte of the resource data will be written at the given offset of the currently bound buffer.glBufferSubData() OpenGL ES manpage
Note: not functional for a server-side fall-back (see
bufferData()
for more info) -
bufferSubData
public void bufferSubData(WGLWidget.GLenum target, int offset, WGLWidget.ArrayBuffer res, int bufferResourceOffset, int bufferResourceSize) Initialize a buffer object's data store from anWGLWidget.ArrayBuffer
.Load the data of the currently bound WebGLBuffer object from the given
WGLWidget.ArrayBuffer
. The byte at position arrayBufferOffset will be written to the currently bound buffer at position offset.glBufferSubData() OpenGL ES manpage
Note: not functional for a server-side fall-back (see
bufferData()
for more info) -
bufferDatafv
public void bufferDatafv(WGLWidget.GLenum target, ByteBuffer buffer, WGLWidget.GLenum usage, boolean binary) GL function that loads float or double data in a VBO. -
bufferDatafv
GL function that loads float or double data in a VBO. -
bufferDatafv
-
clearBinaryResources
public void clearBinaryResources()remove all binary buffer resourcesRemoves all WMemoryResources that were allocated when calling bufferDatafv with binary=true. This is not required, since the resources are also managed, but if you are sure they will not be used anymore in the client, this can help free some memory.
-
bufferDataiv
public void bufferDataiv(WGLWidget.GLenum target, IntBuffer buffer, WGLWidget.GLenum usage, WGLWidget.GLenum type) GL function that updates an existing VBO with new integer data. -
bufferSubDatafv
GL function that updates an existing VBO with new float data. -
bufferSubDatafv
GL function that updates an existing VBO with new float data. -
bufferSubDatafv
-
bufferSubDataiv
public void bufferSubDataiv(WGLWidget.GLenum target, int offset, IntBuffer buffer, WGLWidget.GLenum type) GL function that loads integer data in a VBO. -
clear
GL function that clears the given buffers. -
clear
GL function that clears the given buffers. -
clearColor
public void clearColor(double r, double g, double b, double a) GL function that sets the clear color of the color buffer. -
clearDepth
public void clearDepth(double depth) GL function that configures the depth to be set when the depth buffer is cleared. -
clearStencil
public void clearStencil(int s) GL function. -
colorMask
public void colorMask(boolean red, boolean green, boolean blue, boolean alpha) GL function. -
compileShader
GL function to compile a shader. -
copyTexImage2D
public void copyTexImage2D(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalFormat, int x, int y, int width, int height, int border) GL function to copy a texture image. -
copyTexSubImage2D
public void copyTexSubImage2D(WGLWidget.GLenum target, int level, int xoffset, int yoffset, int x, int y, int width, int height) GL function that copies a part of a texture image. -
createBuffer
GL function that creates an empty VBO. -
getCreateFramebuffer
GL function that creates a frame buffer object. -
createProgram
GL function that creates an empty program. -
getCreateRenderbuffer
GL function that creates a render buffer object. -
createShader
GL function that creates an empty shader. -
createTexture
GL function that creates an empty texture. -
createTextureAndLoad
GL function that creates an image texture. -
createPaintDevice
returns an paintdevice that can be used to paint a GL textureIf the client has a webGL enabled browser this function returns a
WCanvasPaintDevice
.If server-side rendering is used as fallback then this function returns a WRasterPaintDevice.
-
cullFace
GL function that configures the backface culling mode. -
deleteBuffer
GL function that deletes a VBO. -
deleteFramebuffer
GL function that deletes a frame buffer. -
deleteProgram
GL function that deletes a program. -
deleteRenderbuffer
GL function that deletes a render buffer. -
deleteShader
GL function that depetes a shader. -
deleteTexture
GL function that deletes a texture. -
depthFunc
GL function to set the depth test function. -
depthMask
public void depthMask(boolean flag) GL function that enables or disables writing to the depth buffer. -
depthRange
public void depthRange(double zNear, double zFar) GL function that specifies to what range the normalized [-1,1] z values should match. -
detachShader
GL function that detaches a shader from a program. -
disable
GL function to disable features. -
disableVertexAttribArray
GL function to disable the vertex attribute array. -
drawArrays
GL function to draw a VBO. -
drawElements
GL function to draw indexed VBOs. -
enable
GL function to enable features. -
enableVertexAttribArray
GL function to enable the vertex attribute array. -
finish
public void finish()GL function to wait until given commands are executed.This call is transfered to JS, but the server will never wait on this call.
-
flush
public void flush()GL function to force execution of GL commands in finite time. -
framebufferRenderbuffer
public void framebufferRenderbuffer(WGLWidget.GLenum target, WGLWidget.GLenum attachment, WGLWidget.GLenum renderbuffertarget, WGLWidget.Renderbuffer renderbuffer) GL function to attach the given renderbuffer to the currently bound frame buffer. -
framebufferTexture2D
public void framebufferTexture2D(WGLWidget.GLenum target, WGLWidget.GLenum attachment, WGLWidget.GLenum textarget, WGLWidget.Texture texture, int level) GL function to render directly into a texture image. -
frontFace
GL function that specifies which side of a triangle is the front side. -
generateMipmap
GL function that generates a set of mipmaps for a texture object. -
getAttribLocation
GL function to retrieve an attribute's location in aWGLWidget.Program
. -
getUniformLocation
GL function to retrieve a Uniform's location in aWGLWidget.Program
. -
hint
GL function to give hints to the render pipeline. -
lineWidth
public void lineWidth(double width) GL function to set the line width. -
linkProgram
GL function to link a program. -
pixelStorei
GL function to set the pixel storage mode. -
polygonOffset
public void polygonOffset(double factor, double units) GL function to apply modifications to Z values. -
renderbufferStorage
public void renderbufferStorage(WGLWidget.GLenum target, WGLWidget.GLenum internalformat, int width, int height) GL function to allocate the appropriate amount of memory for a render buffer. -
sampleCoverage
public void sampleCoverage(double value, boolean invert) GL function to set multisample parameters. -
scissor
public void scissor(int x, int y, int width, int height) GL function to define the scissor box. -
shaderSource
GL function to set a shader's source code. -
stencilFunc
GL function to set stencil test parameters. -
stencilFuncSeparate
GL function to set stencil test parameters for front and/or back stencils. -
stencilMask
public void stencilMask(int mask) GL function to control which bits are to be written in the stencil buffer. -
stencilMaskSeparate
GL function to control which bits are written to the front and/or back stencil buffers. -
stencilOp
GL function to set stencil test actions. -
stencilOpSeparate
public void stencilOpSeparate(WGLWidget.GLenum face, WGLWidget.GLenum fail, WGLWidget.GLenum zfail, WGLWidget.GLenum zpass) GL function to set front and/or back stencil test actions separately. -
texImage2D
public void texImage2D(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, int width, int height, int border, WGLWidget.GLenum format) GL function to reserve space for a 2D texture, without specifying its contents.This corresponds to calling the WebGL function void texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView pixels) with null as last parameters. The value of 'type' is then of no importance and is therefore omitted from this function.
-
texImage2D
public void texImage2D(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, WImage image) -
texImage2D
public void texImage2D(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, WVideo video) GL function to load a 2D texture from aWVideo
.Note: the video must be loaded prior to calling this function. The current frame is used as texture image.
-
texImage2D
public void texImage2D(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, String imgFilename) GL function to load a 2D texture from a file. -
texImage2D
public void texImage2D(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, WPaintDevice paintdevice) GL function to load a 2D texture from aWPaintDevice
. -
texImage2D
public void texImage2D(WGLWidget.GLenum target, int level, WGLWidget.GLenum internalformat, WGLWidget.GLenum format, WGLWidget.GLenum type, WGLWidget.Texture texture) GL function to load a 2D texture loaded withcreateTextureAndLoad()
This function must only be used for textures created with
createTextureAndLoad()
Note: the
WGLWidget
implementation will delay rendering until all textures created withcreateTextureAndLoad()
are loaded in the browser. -
texParameteri
GL function to set texture parameters. -
uniform1f
GL function to set the value of a uniform variable of the current program. -
uniform1fv
GL function to set the value of a uniform variable of the current program. -
uniform1fv
GL function to set the value of a uniform variable of the current program. -
uniform1i
GL function to set the value of a uniform variable of the current program. -
uniform1iv
GL function to set the value of a uniform variable of the current program. -
uniform2f
GL function to set the value of a uniform variable of the current program. -
uniform2fv
GL function to set the value of a uniform variable of the current program. -
uniform2fv
GL function to set the value of a uniform variable of the current program. -
uniform2i
GL function to set the value of a uniform variable of the current program. -
uniform2iv
GL function to set the value of a uniform variable of the current program. -
uniform3f
GL function to set the value of a uniform variable of the current program. -
uniform3fv
GL function to set the value of a uniform variable of the current program. -
uniform3fv
GL function to set the value of a uniform variable of the current program. -
uniform3i
GL function to set the value of a uniform variable of the current program. -
uniform3iv
GL function to set the value of a uniform variable of the current program. -
uniform4f
GL function to set the value of a uniform variable of the current program. -
uniform4fv
GL function to set the value of a uniform variable of the current program. -
uniform4fv
GL function to set the value of a uniform variable of the current program. -
uniform4i
GL function to set the value of a uniform variable of the current program. -
uniform4iv
GL function to set the value of a uniform variable of the current program. -
uniformMatrix2fv
GL function to set the value of a uniform matrix of the current program.Attention: The OpenGL ES specification states that transpose MUST be false.
-
uniformMatrix2
GL function to set the value of a uniform matrix of the current program.This function renders the matrix in the proper row/column order.
-
uniformMatrix3fv
GL function to set the value of a uniform matrix of the current program.Attention: The OpenGL ES specification states that transpose MUST be false.
-
uniformMatrix3
GL function to set the value of a uniform matrix of the current program.This function renders the matrix in the proper row/column order.
-
uniformMatrix4fv
GL function to set the value of a uniform matrix of the current program.Attention: The OpenGL ES specification states that transpose MUST be false.
-
uniformMatrix4
GL function to set the value of a uniform matrix of the current program.This function renders the matrix in the proper row/column order.
-
uniformMatrix4
GL function to set the value of a uniform matrix of the current program. -
useProgram
GL function to set the current active shader program. -
validateProgram
GL function to validate a program.implementation note: there is currently not yet a method to read out the validation result.
-
vertexAttrib1f
GL function to set the value of an attribute of the current program. -
vertexAttrib2f
GL function to set the value of an attribute of the current program. -
vertexAttrib2fv
GL function to set the value of an attribute of the current program. -
vertexAttrib3f
GL function to set the value of an attribute of the current program. -
vertexAttrib3fv
GL function to set the value of an attribute of the current program. -
vertexAttrib4f
public void vertexAttrib4f(WGLWidget.AttribLocation location, double x, double y, double z, double w) GL function to set the value of an attribute of the current program. -
vertexAttrib4fv
GL function to set the value of an attribute of the current program. -
vertexAttribPointer
public void vertexAttribPointer(WGLWidget.AttribLocation location, int size, WGLWidget.GLenum type, boolean normalized, int stride, int offset) GL function to bind a VBO to an attribute.This function links the given attribute to the VBO currently bound to the ARRAY_BUFFER target.
The size parameter specifies the number of components per attribute (1 to 4). The type parameter is also used to determine the size of each component.
The size of a float is 8 bytes.
In
WGLWidget
, the size of an int is 4 bytes.The stride is in bytes.
The maximum stride is 255.
-
viewport
public void viewport(int x, int y, int width, int height) GL function to set the viewport. -
createJavaScriptMatrix4
Create a matrix that can be manipulated in client-side JavaScript.This is a shorthand for creating a
WGLWidget.JavaScriptMatrix4x4
, then adding it to aWGLWidget
with addJavaScriptMatrix4, and initializing it with initJavaScriptMatrix4.This method should only be called in
initializeGL()
,updateGL()
orresizeGL()
. -
addJavaScriptMatrix4
Register a matrix with thisWGLWidget
.You can call this outside of
resizeGL()
,paintGL()
,updateGL()
orinitializeGL()
methods. After aWGLWidget.JavaScriptMatrix4x4
is added to aWGLWidget
, itsWWidget.getJsRef()
becomes valid, and can be used in aJSlot
, for example. -
initJavaScriptMatrix4
Initialize the client-side JavaScript for the givenWGLWidget.JavaScriptMatrix4x4
.If the given matrix is not associated with a widget yet, it will be added to this widget.
If the given matrix has already been added to a
WGLWidget
, then thisWGLWidget
should be the same as the one you call initJavaScriptMatrix4 on.This method should only be called in
initializeGL()
,updateGL()
orresizeGL()
. -
setJavaScriptMatrix4
Set the value of a client-side JavaScript matrix created by createJavaScriptMatrix4x4()This method should only be called in
initializeGL()
,updateGL()
orresizeGL()
. -
createJavaScriptVector
Create a vector of a certain length that can be manipulated in client-side JavaScript.This is a shorthand for creating a
WGLWidget.JavaScriptVector
, then adding it to aWGLWidget
with addJavaScriptVector, and initializing it with initJavaScriptVector.This method should only be called in
initializeGL()
,updateGL()
orresizeGL()
. -
addJavaScriptVector
Register a vector with thisWGLWidget
.You can call this outside of
resizeGL()
,paintGL()
,updateGL()
orinitializeGL()
methods. After aWGLWidget.JavaScriptVector
is added to aWGLWidget
, itsWWidget.getJsRef()
becomes valid, and can be used in aJSlot
, for example. -
initJavaScriptVector
Initialize the client-side JavaScript for the givenWGLWidget.JavaScriptVector
.If the given vector is not associated with a widget yet, it will be added to this widget.
If the given vector has already been added to a
WGLWidget
, then thisWGLWidget
should be the same as the one you call initJavaScriptVector on.This method should only be called in
initializeGL()
,updateGL()
orresizeGL()
. -
setJavaScriptVector
Set the value of a client-side JavaScript vector created bycreateJavaScriptVector()
This method should only be called in
initializeGL()
,updateGL()
orresizeGL()
. -
setClientSideMouseHandler
Set a custom mouse handler based on the given JavaScript code.The handler code should be JavaScript code that produces an object when evaluated.
A mouse handler is an object that can implement one or more of the following functions:
- setTarget(target): This is called immediately when the mouse handler is added with
an object that uniquely identifies the
WGLWidget
, and apaintGL()
method. - mouseDown(o, event): To handle the
mousedown
event.o
is the<canvas>
(client-side rendering) or<img>
(server-side rendering) element corresponding to thisWGLWidget
.event
is theMouseEvent
. - mouseUp(o, event): To handle the
mouseup
event.o
is the<canvas>
(client-side rendering) or<img>
(server-side rendering) element corresponding to thisWGLWidget
.event
is theMouseEvent
. - mouseDrag(o, event): Called when the mouse is dragged.
o
is the<canvas>
(client-side rendering) or<img>
(server-side rendering) element corresponding to thisWGLWidget
.event
is theMouseEvent
. - mouseMove(o, event): Called when the mouse is moved.
o
is the<canvas>
(client-side rendering) or<img>
(server-side rendering) element corresponding to thisWGLWidget
.event
is theMouseEvent
. - mouseWheel(o, event): Called when the mouse wheel is used.
o
is the<canvas>
(client-side rendering) or<img>
(server-side rendering) element corresponding to thisWGLWidget
.event
is theMouseEvent
. - touchStart(o, event): To handle the
touchstart
event.o
is the<canvas>
(client-side rendering) or<img>
(server-side rendering) element corresponding to thisWGLWidget
.event
is theTouchEvent
. - touchEnd(o, event): To handle the
touchend
event.o
is this<canvas>
(client-side rendering) or<img>
(server-side rendering) element corresponding to thisWGLWidget
.event
is theTouchEvent
. - touchMoved(o, event): To handle the
touchmove
event.o
is this<canvas>
(client-side rendering) or<img>
(server-side rendering) element corresponding to thisWGLWidget
.event
is theTouchEvent
.
For example, if we wanted to scale some object when we scroll, we could create a
WGLWidget.JavaScriptMatrix4x4
calledtransform_:
private JavaScriptMatrix4x4 transform_;
We can add this in the constructor:
transform_ = new JavaScriptMatrix4x4(); addJavaScriptMatrix4(transform_);
Then, in
initializeGL()
, we can initialize it and set the value:initJavaScriptMatrix4(transform_); setJavaScriptMatrix4(transform_, new WMatrix4x4()); // Set to identity matrix
Then, still in
initializeGL()
, we can set a mouse handler as such:setClientSideMouseHandler("(function(){") + "var MouseHandler = function(transform) {" + "var target = null;" + "this.setTarget = function(newTarget) {" + "target = newTarget;" + "};" + "this.mouseWheel = function(o, event) {" + "var fix = jQuery.event.fix(event);" + "fix.preventDefault();" + "fix.stopPropagation();" + "var d = wheelDelta(event);" + "var s = Math.pow(1.2, d);" + "transform[0] *= s;" + // Scale X "transform[5] *= s;" + // Scale Y "transform[10] *= s;" + // Scale Z "target.paintGL();" + // Repaint "};" + "function wheelDelta(e) {" + "var delta = 0;" + "if (e.wheelDelta) {" + "delta = e.wheelDelta > 0 ? 1 : -1;" + "} else if (e.detail) {" + "delta = e.detail < 0 ? 1 : -1;" + "}" + "return delta;" + "}" + "};" + "return new MouseHandler(" + transform_.jsRef() + ");" + "})()");
All that's left to do then is to use this transform somewhere as a uniform variable, see
getUniformLocation()
anduniformMatrix4()
. - setTarget(target): This is called immediately when the mouse handler is added with
an object that uniquely identifies the
-
setClientSideLookAtHandler
public void setClientSideLookAtHandler(WGLWidget.JavaScriptMatrix4x4 m, double centerX, double centerY, double centerZ, double uX, double uY, double uZ, double pitchRate, double yawRate) Add a mouse handler to the widget that looks at a given point.This will allow a user to change client-side matrix m with the mouse. M is a model transformation matrix, representing the viewpoint of the camera.
Through mouse operations, the camera can be changed by the user, but (lX, lY, lZ) will always be at the center of the display, (uX, uY, uZ) is considered to be the up direction, and the distance of the camera to (lX, lY, lZ) will never change.
Pressing the left mouse button and moving the mouse left/right will rotate the camera around the up (uX, uY, uZ) direction. Moving up/down will tilt the camera (causing it to move up/down to keep the lookpoint centered). The scroll wheel simulates zooming by scaling the scene.
pitchRate and yawRate control how much the camera will move per mouse pixel.
Usually this method is called after setting a camera transformation with a client-side matrix in
initializeGL()
. However, this function may also be called from outside the intializeGL()/paintGL()/updateGL() methods (but not before m was initialized). -
setClientSideWalkHandler
public void setClientSideWalkHandler(WGLWidget.JavaScriptMatrix4x4 m, double frontStep, double rotStep) Add a mouse handler to the widget that allows 'walking' in the scene.This will allow a user to change client-side matrix m with the mouse. M is a model transformation matrix, representing the viewpoint of the camera.
Through mouse operations, the camera can be changed by the user, as if he is walking around on a plane.
Pressing the left mouse button and moving the mouse left/right will rotate the camera around Y axis. Moving the mouse up/down will move the camera in the Z direction (walking forward/backward). centered).
frontStep and rotStep control how much the camera will move per mouse pixel.
-
setAlternativeContent
Sets the content to be displayed when WebGL is not available.If JWt cannot create a working WebGL context, this content will be shown to the user. This may be a text explanation, or a pre-rendered image, or a video, a flash movie, ...
The default is a widget that explains to the user that he has no WebGL support.
-
getRepaintSlot
A JavaScript slot that repaints the widget when triggered.This is useful for client-side initiated repaints. You may e.g. use this if you write your own client-side mouse handler, or if you updated a texture, or if you're playing a video texture.
-
enableClientErrorChecks
public void enableClientErrorChecks(boolean enable) enable client-side error messages (read detailed doc!)This option will add client-side code to check the result of every WebGL call, and will popup an error dialog if a WebGL call returned an error. The JavaScript then invokes the client-side debugger. This code is intended to test your application, and should not be used in production.
-
enableClientErrorChecks
public final void enableClientErrorChecks()enable client-side error messages (read detailed doc!) -
injectJS
Inject JavaScript into the current js-stream.Careful: this method directly puts the given jsString into the JavaScript stream, whatever state it current has. For example, if called in initGL(), it will put the jsString into the client-side initGL() code.
-
webglNotAvailable
public void webglNotAvailable() -
createDomElement
Description copied from class:WWebWidget
Create DOM element for widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
createDomElement
in classWWebWidget
-
getDomChanges
Description copied from class:WWebWidget
Get DOM changes for this widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
getDomChanges
in classWWebWidget
-
render
Description copied from class:WWidget
Renders the widget.This function renders the widget (or an update for the widget), after this has been scheduled using
scheduleRender()
.The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
- Overrides:
render
in classWWebWidget
-
layoutSizeChanged
protected void layoutSizeChanged(int width, int height) Description copied from class:WWidget
Virtual method that indicates a size change.This method propagates the client-side width and height of the widget when the widget is contained by a layout manager and setLayoutSizeAware(true) was called.
- Overrides:
layoutSizeChanged
in classWWidget
- See Also:
-
setFormData
- Overrides:
setFormData
in classWObject
-
contextRestored
protected void contextRestored()
-