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 thewebglcontextrestoredsignal 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
Nested ClassesModifier and TypeClassDescriptionstatic classReference to a javascript ArrayBuffer class.static classReference to a shader attribute location.static classReference to a WebGLBuffer class.static classReference to a WebGLFramebuffer class.static enumThe enormous GLenum.static classAbstract base class for all GL objects.static classA client-side JavaScript matrix.static classA client-side JavaScript vector.static classReference to a WebGLProgram class.static classReference to a WebGLRenderbuffer class.static classReference to a WebGLShader class.static classReference to a WebGLTexture class.static classReference 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_, noDefault -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a GL widget.WGLWidget(WContainerWidget parentContainer) Construct a GL widget. -
Method Summary
Modifier and TypeMethodDescriptionvoidactiveTexture(WGLWidget.GLenum texture) GL function to activate an existing texture.voidRegister a matrix with thisWGLWidget.voidRegister a vector with thisWGLWidget.voidattachShader(WGLWidget.Program program, WGLWidget.Shader shader) GL function to attach a shader to a program.voidbindAttribLocation(WGLWidget.Program program, int index, String name) GL function to bind an attribute to a given location.voidbindBuffer(WGLWidget.GLenum target, WGLWidget.Buffer buffer) GL function to bind a buffer to a target.voidbindFramebuffer(WGLWidget.GLenum target, WGLWidget.Framebuffer buffer) GL function to bind a frame buffer to a target.voidbindRenderbuffer(WGLWidget.GLenum target, WGLWidget.Renderbuffer buffer) GL function to bind a render buffer to a target.voidbindTexture(WGLWidget.GLenum target, WGLWidget.Texture texture) GL function to bind a texture to a target.voidblendColor(double red, double green, double blue, double alpha) GL function to set the blending color.voidGL function to set the blending equation.voidblendEquationSeparate(WGLWidget.GLenum modeRGB, WGLWidget.GLenum modeAlpha) GL function that sets separate blending functions for RGB and alpha.voidblendFunc(WGLWidget.GLenum sfactor, WGLWidget.GLenum dfactor) GL function to configure the blending function.voidblendFuncSeparate(WGLWidget.GLenum srcRGB, WGLWidget.GLenum dstRGB, WGLWidget.GLenum srcAlpha, WGLWidget.GLenum dstAlpha) GL function that configures the blending function.voidbufferData(WGLWidget.GLenum target, int size, WGLWidget.GLenum usage) glBufferData - create and initialize a buffer object's data storevoidbufferData(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.ArrayBuffervoidbufferData(WGLWidget.GLenum target, WGLWidget.ArrayBuffer res, WGLWidget.GLenum usage) glBufferData - create and initialize a buffer object's data store from anWGLWidget.ArrayBufferfinal voidbufferDatafv(WGLWidget.GLenum target, ByteBuffer buffer, WGLWidget.GLenum usage) GL function that loads float or double data in a VBO.voidbufferDatafv(WGLWidget.GLenum target, ByteBuffer buffer, WGLWidget.GLenum usage, boolean binary) GL function that loads float or double data in a VBO.voidbufferDatafv(WGLWidget.GLenum target, FloatBuffer buffer, WGLWidget.GLenum usage) voidbufferDataiv(WGLWidget.GLenum target, IntBuffer buffer, WGLWidget.GLenum usage, WGLWidget.GLenum type) GL function that updates an existing VBO with new integer data.voidbufferSubData(WGLWidget.GLenum target, int offset, WGLWidget.ArrayBuffer res) Initialize a buffer object's data store from anWGLWidget.ArrayBuffer.voidbufferSubData(WGLWidget.GLenum target, int offset, WGLWidget.ArrayBuffer res, int bufferResourceOffset, int bufferResourceSize) Initialize a buffer object's data store from anWGLWidget.ArrayBuffer.final voidbufferSubDatafv(WGLWidget.GLenum target, int offset, ByteBuffer buffer) GL function that updates an existing VBO with new float data.voidbufferSubDatafv(WGLWidget.GLenum target, int offset, ByteBuffer buffer, boolean binary) GL function that updates an existing VBO with new float data.voidbufferSubDatafv(WGLWidget.GLenum target, int offset, FloatBuffer buffer) voidbufferSubDataiv(WGLWidget.GLenum target, int offset, IntBuffer buffer, WGLWidget.GLenum type) GL function that loads integer data in a VBO.final voidclear(WGLWidget.GLenum mas, WGLWidget.GLenum... mask) GL function that clears the given buffers.voidclear(EnumSet<WGLWidget.GLenum> mask) GL function that clears the given buffers.voidremove all binary buffer resourcesvoidclearColor(double r, double g, double b, double a) GL function that sets the clear color of the color buffer.voidclearDepth(double depth) GL function that configures the depth to be set when the depth buffer is cleared.voidclearStencil(int s) GL function.voidcolorMask(boolean red, boolean green, boolean blue, boolean alpha) GL function.voidcompileShader(WGLWidget.Shader shader) GL function to compile a shader.protected voidvoidcopyTexImage2D(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.voidcopyTexSubImage2D(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 DomElementCreate 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.voidcullFace(WGLWidget.GLenum mode) GL function that configures the backface culling mode.voiddebugger()voiddeleteBuffer(WGLWidget.Buffer buffer) GL function that deletes a VBO.voidGL function that deletes a frame buffer.voiddeleteProgram(WGLWidget.Program program) GL function that deletes a program.voidGL function that deletes a render buffer.voiddeleteShader(WGLWidget.Shader shader) GL function that depetes a shader.voiddeleteTexture(WGLWidget.Texture texture) GL function that deletes a texture.voiddepthFunc(WGLWidget.GLenum func) GL function to set the depth test function.voiddepthMask(boolean flag) GL function that enables or disables writing to the depth buffer.voiddepthRange(double zNear, double zFar) GL function that specifies to what range the normalized [-1,1] z values should match.voiddetachShader(WGLWidget.Program program, WGLWidget.Shader shader) GL function that detaches a shader from a program.voiddisable(WGLWidget.GLenum cap) GL function to disable features.voidGL function to disable the vertex attribute array.voiddrawArrays(WGLWidget.GLenum mode, int first, int count) GL function to draw a VBO.voiddrawElements(WGLWidget.GLenum mode, int count, WGLWidget.GLenum type, int offset) GL function to draw indexed VBOs.voidenable(WGLWidget.GLenum cap) GL function to enable features.final voidenable client-side error messages (read detailed doc!)voidenableClientErrorChecks(boolean enable) enable client-side error messages (read detailed doc!)voidGL function to enable the vertex attribute array.voidfinish()GL function to wait until given commands are executed.voidflush()GL function to force execution of GL commands in finite time.voidframebufferRenderbuffer(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.voidframebufferTexture2D(WGLWidget.GLenum target, WGLWidget.GLenum attachment, WGLWidget.GLenum textarget, WGLWidget.Texture texture, int level) GL function to render directly into a texture image.voidfrontFace(WGLWidget.GLenum mode) GL function that specifies which side of a triangle is the front side.voidgenerateMipmap(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 voidgetDomChanges(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.voidhint(WGLWidget.GLenum target, WGLWidget.GLenum mode) GL function to give hints to the render pipeline.protected voidInitialize the GL state when the widget is first shown.voidInitialize the client-side JavaScript for the givenWGLWidget.JavaScriptMatrix4x4.voidInitialize the client-side JavaScript for the givenWGLWidget.JavaScriptVector.voidInject JavaScript into the current js-stream.booleanReturns whether a lost context is in the process of being restored.protected voidlayoutSizeChanged(int width, int height) Virtual method that indicates a size change.voidlineWidth(double width) GL function to set the line width.voidlinkProgram(WGLWidget.Program program) GL function to link a program.protected voidpaintGL()Update the client-side painting function.voidpixelStorei(WGLWidget.GLenum pname, int param) GL function to set the pixel storage mode.voidpolygonOffset(double factor, double units) GL function to apply modifications to Z values.voidremove()Destructor.protected voidrender(EnumSet<RenderFlag> flags) Renders the widget.voidrenderbufferStorage(WGLWidget.GLenum target, WGLWidget.GLenum internalformat, int width, int height) GL function to allocate the appropriate amount of memory for a render buffer.final voidrepaintGL(GLClientSideRenderer whic, GLClientSideRenderer... which) Request invocation of resizeGL, paintGL and/or updateGL.voidrepaintGL(EnumSet<GLClientSideRenderer> which) Request invocation of resizeGL, paintGL and/or updateGL.voidResizes the widget.protected voidresizeGL(int width, int height) Act on resize events.voidsampleCoverage(double value, boolean invert) GL function to set multisample parameters.voidscissor(int x, int y, int width, int height) GL function to define the scissor box.voidsetAlternativeContent(WWidget alternative) Sets the content to be displayed when WebGL is not available.voidsetClientSideLookAtHandler(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.voidsetClientSideMouseHandler(String handlerCode) Set a custom mouse handler based on the given JavaScript code.voidsetClientSideWalkHandler(WGLWidget.JavaScriptMatrix4x4 m, double frontStep, double rotStep) Add a mouse handler to the widget that allows 'walking' in the scene.protected voidsetFormData(WObject.FormData formData) voidsetJavaScriptMatrix4(WGLWidget.JavaScriptMatrix4x4 jsm, javax.vecmath.Matrix4f m) Set the value of a client-side JavaScript matrix created by createJavaScriptMatrix4x4()voidSet the value of a client-side JavaScript vector created bycreateJavaScriptVector()final voidsetRenderOptions(GLRenderOption option, GLRenderOption... options) Sets the rendering option.voidsetRenderOptions(EnumSet<GLRenderOption> options) Sets the rendering option.voidshaderSource(WGLWidget.Shader shader, String src) GL function to set a shader's source code.voidstencilFunc(WGLWidget.GLenum func, int ref, int mask) GL function to set stencil test parameters.voidstencilFuncSeparate(WGLWidget.GLenum face, WGLWidget.GLenum func, int ref, int mask) GL function to set stencil test parameters for front and/or back stencils.voidstencilMask(int mask) GL function to control which bits are to be written in the stencil buffer.voidstencilMaskSeparate(WGLWidget.GLenum face, int mask) GL function to control which bits are written to the front and/or back stencil buffers.voidstencilOp(WGLWidget.GLenum fail, WGLWidget.GLenum zfail, WGLWidget.GLenum zpass) GL function to set stencil test actions.voidstencilOpSeparate(WGLWidget.GLenum face, WGLWidget.GLenum fail, WGLWidget.GLenum zfail, WGLWidget.GLenum zpass) GL function to set front and/or back stencil test actions separately.voidtexImage2D(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.voidtexImage2D(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()voidtexImage2D(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.voidtexImage2D(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.voidtexImage2D(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.voidtexImage2D(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.voidtexParameteri(WGLWidget.GLenum target, WGLWidget.GLenum pname, WGLWidget.GLenum param) GL function to set texture parameters.voiduniform1f(WGLWidget.UniformLocation location, double x) GL function to set the value of a uniform variable of the current program.voiduniform1fv(WGLWidget.UniformLocation location, float[] value) GL function to set the value of a uniform variable of the current program.voidGL function to set the value of a uniform variable of the current program.voiduniform1i(WGLWidget.UniformLocation location, int x) GL function to set the value of a uniform variable of the current program.voiduniform1iv(WGLWidget.UniformLocation location, int[] value) GL function to set the value of a uniform variable of the current program.voiduniform2f(WGLWidget.UniformLocation location, double x, double y) GL function to set the value of a uniform variable of the current program.voiduniform2fv(WGLWidget.UniformLocation location, float[] value) GL function to set the value of a uniform variable of the current program.voidGL function to set the value of a uniform variable of the current program.voiduniform2i(WGLWidget.UniformLocation location, int x, int y) GL function to set the value of a uniform variable of the current program.voiduniform2iv(WGLWidget.UniformLocation location, int[] value) GL function to set the value of a uniform variable of the current program.voiduniform3f(WGLWidget.UniformLocation location, double x, double y, double z) GL function to set the value of a uniform variable of the current program.voiduniform3fv(WGLWidget.UniformLocation location, float[] value) GL function to set the value of a uniform variable of the current program.voidGL function to set the value of a uniform variable of the current program.voiduniform3i(WGLWidget.UniformLocation location, int x, int y, int z) GL function to set the value of a uniform variable of the current program.voiduniform3iv(WGLWidget.UniformLocation location, int[] value) GL function to set the value of a uniform variable of the current program.voiduniform4f(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.voiduniform4fv(WGLWidget.UniformLocation location, float[] value) GL function to set the value of a uniform variable of the current program.voidGL function to set the value of a uniform variable of the current program.voiduniform4i(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.voiduniform4iv(WGLWidget.UniformLocation location, int[] value) GL function to set the value of a uniform variable of the current program.voiduniformMatrix2(WGLWidget.UniformLocation location, Matrix2f m) GL function to set the value of a uniform matrix of the current program.voiduniformMatrix2fv(WGLWidget.UniformLocation location, boolean transpose, double[] value) GL function to set the value of a uniform matrix of the current program.voiduniformMatrix3(WGLWidget.UniformLocation location, javax.vecmath.Matrix3f m) GL function to set the value of a uniform matrix of the current program.voiduniformMatrix3fv(WGLWidget.UniformLocation location, boolean transpose, double[] value) GL function to set the value of a uniform matrix of the current program.voiduniformMatrix4(WGLWidget.UniformLocation location, WGLWidget.JavaScriptMatrix4x4 jsm) GL function to set the value of a uniform matrix of the current program.voiduniformMatrix4(WGLWidget.UniformLocation location, javax.vecmath.Matrix4f m) GL function to set the value of a uniform matrix of the current program.voiduniformMatrix4fv(WGLWidget.UniformLocation location, boolean transpose, double[] value) GL function to set the value of a uniform matrix of the current program.protected voidupdateGL()Update state set ininitializeGL()voiduseProgram(WGLWidget.Program program) GL function to set the current active shader program.voidvalidateProgram(WGLWidget.Program program) GL function to validate a program.voidvertexAttrib1f(WGLWidget.AttribLocation location, double x) GL function to set the value of an attribute of the current program.voidvertexAttrib2f(WGLWidget.AttribLocation location, double x, double y) GL function to set the value of an attribute of the current program.voidvertexAttrib2fv(WGLWidget.AttribLocation location, float[] values) GL function to set the value of an attribute of the current program.voidvertexAttrib3f(WGLWidget.AttribLocation location, double x, double y, double z) GL function to set the value of an attribute of the current program.voidvertexAttrib3fv(WGLWidget.AttribLocation location, float[] values) GL function to set the value of an attribute of the current program.voidvertexAttrib4f(WGLWidget.AttribLocation location, double x, double y, double z, double w) GL function to set the value of an attribute of the current program.voidvertexAttrib4fv(WGLWidget.AttribLocation location, float[] values) GL function to set the value of an attribute of the current program.voidvertexAttribPointer(WGLWidget.AttribLocation location, int size, WGLWidget.GLenum type, boolean normalized, int stride, int offset) GL function to bind a VBO to an attribute.voidviewport(int x, int y, int width, int height) GL function to set the viewport.voidMethods 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, unsetDraggableMethods 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, hideToolTip, 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, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemovedMethods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, trMethods 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:
removein 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.Shadersources 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:WWidgetResizes the widget.Specifies a fixed size for this widget, setting CSS
widthandheightproperties. 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 the 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:
resizein 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.ArrayBufferSet 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.ArrayBufferrefers 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.ArrayBufferSet the size of the currently bound WebGLBuffer object to arrayBufferSize, and copy the contents of the
WGLWidget.ArrayBufferto 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
WGLWidgetimplementation 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 aWGLWidgetwith 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.JavaScriptMatrix4x4is 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 thisWGLWidgetshould 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 aWGLWidgetwith 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.JavaScriptVectoris 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 thisWGLWidgetshould 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
mousedownevent.ois the<canvas>(client-side rendering) or<img>(server-side rendering) element corresponding to thisWGLWidget.eventis theMouseEvent. - mouseUp(o, event): To handle the
mouseupevent.ois the<canvas>(client-side rendering) or<img>(server-side rendering) element corresponding to thisWGLWidget.eventis theMouseEvent. - mouseDrag(o, event): Called when the mouse is dragged.
ois the<canvas>(client-side rendering) or<img>(server-side rendering) element corresponding to thisWGLWidget.eventis theMouseEvent. - mouseMove(o, event): Called when the mouse is moved.
ois the<canvas>(client-side rendering) or<img>(server-side rendering) element corresponding to thisWGLWidget.eventis theMouseEvent. - mouseWheel(o, event): Called when the mouse wheel is used.
ois the<canvas>(client-side rendering) or<img>(server-side rendering) element corresponding to thisWGLWidget.eventis theMouseEvent. - touchStart(o, event): To handle the
touchstartevent.ois the<canvas>(client-side rendering) or<img>(server-side rendering) element corresponding to thisWGLWidget.eventis theTouchEvent. - touchEnd(o, event): To handle the
touchendevent.ois this<canvas>(client-side rendering) or<img>(server-side rendering) element corresponding to thisWGLWidget.eventis theTouchEvent. - touchMoved(o, event): To handle the
touchmoveevent.ois this<canvas>(client-side rendering) or<img>(server-side rendering) element corresponding to thisWGLWidget.eventis theTouchEvent.
For example, if we wanted to scale some object when we scroll, we could create a
WGLWidget.JavaScriptMatrix4x4calledtransform_: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 matrixThen, 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:WWebWidgetCreate DOM element for widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
createDomElementin classWWebWidget
-
getDomChanges
Description copied from class:WWebWidgetGet DOM changes for this widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
getDomChangesin classWWebWidget
-
render
Description copied from class:WWidgetRenders 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:
renderin classWInteractWidget
-
layoutSizeChanged
protected void layoutSizeChanged(int width, int height) Description copied from class:WWidgetVirtual 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:
layoutSizeChangedin classWWidget- See Also:
-
setFormData
- Overrides:
setFormDatain classWObject
-
contextRestored
protected void contextRestored()
-