Wt 3.1.10
Classes | Public Types | Public Member Functions | Private Member Functions
Wt::WGLWidget Class Reference

WebGL support class. More...

#include <Wt/WGLWidget>

Inheritance diagram for Wt::WGLWidget:
Inheritance graph
[legend]

List of all members.

Classes

class  JavaScriptMatrix4x4
 A client-side JavaScript matrix. More...

Public Types

enum  ClientSideRenderer { PAINT_GL = 1, RESIZE_GL = 2, UPDATE_GL = 4 }
 Specifies what WebGL function needs to be updated. More...
enum  GLenum
 The enourmous GLenum. More...

Public Member Functions

 WGLWidget (WContainerWidget *parent)
 Construct a WebGL widget.
 ~WGLWidget ()
 Destructor.
virtual void initializeGL ()
 Initialize the WebGL state when the widget is first shown.
virtual void resizeGL (int width, int height)
 Act on resize events.
virtual void paintGL ()
 Update the client-side painting function.
virtual void updateGL ()
 Update state set in initializeGL()
void repaintGL (WFlags< ClientSideRenderer > which)
 Request invocation of resizeGL, paintGL and/or updateGL.
void resize (const WLength &width, const WLength &height)
 Resizes the widget.
void setClientSideLookAtHandler (const JavaScriptMatrix4x4 &m, double lX, double lY, double lZ, double uX, double uY, double uZ, double pitchRate, double yawRate)
 Add a mouse handler to the widget that looks at a given point.
void setClientSideWalkHandler (const JavaScriptMatrix4x4 &m, double frontStep, double rotStep)
 Add a mouse handler to the widget that allows 'walking' in the scene.
void setAlternativeContent (WWidget *alternative)
 Sets the content to be displayed when WebGL is not available.
JSlotrepaintSlot ()
 A JavaScript slot that repaints the widget when triggered.
WebGL methods

The WebGL methods are mostly 1-on-1 translated to the identical JavaScript call. You can use the WebGL methods in your resizeGL(), paintGL() and updateGL() specializations. Wt takes care that data, arguments, ... are transfered to the client side and that the equivalent JavaScript WebGL funtion is executed.

void debugger ()
 GL function to activate an existing texture.
void activeTexture (GLenum texture)
 GL function to activate an existing texture.
void attachShader (Program program, Shader shader)
 GL function to attach a shader to a program.
void bindAttribLocation (Program program, unsigned index, const std::string &name)
 GL function to bind an attribute to a given location.
void bindBuffer (GLenum target, Buffer buffer)
 GL function to bind a buffer to a target.
void bindTexture (GLenum target, 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 blendEquation (GLenum mode)
 GL function to set the blending equation.
void blendEquationSeparate (GLenum modeRGB, GLenum modeAlpha)
 GL function that sets separate blending functions for RGB and alpha.
void blendFunc (GLenum sfactor, GLenum dfactor)
 GL function to configure the blending function.
void blendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
 GL function that configures the blending function.
template<typename Iterator >
void bufferDatafv (GLenum target, const Iterator begin, const Iterator end, GLenum usage)
 GL function that loads float or double data in a VBO.
template<typename Iterator >
void bufferDataiv (GLenum target, const Iterator begin, const Iterator end, GLenum usage, GLenum type)
 GL function that updates an existing VBO with new integer data.
template<typename Iterator >
void bufferSubDatafv (GLenum target, unsigned offset, const Iterator begin, const Iterator end)
 GL function that updates an existing VBO with new float or double data.
template<typename Iterator >
void bufferSubDataiv (GLenum target, unsigned offset, const Iterator begin, Iterator end, GLenum type)
 GL function that loads integer data in a VBO.
void clear (WFlags< GLenum > mask)
 GL function that clears the given buffers.
void 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 (bool red, bool green, bool blue, bool alpha)
 GL function.
void compileShader (Shader shader)
 GL function to compile a shader.
void copyTexImage2D (GLenum target, int level, GLenum internalformat, int x, int y, unsigned width, unsigned height, int border)
 GL function to copy a texture image.
void copyTexSubImage2D (GLenum target, int level, int xoffset, int yoffset, int x, int y, unsigned width, unsigned height)
 GL function that copies a part of a texture image.
Buffer createBuffer ()
 GL function that creates an empty VBO.
Program createProgram ()
 GL function that creates an empty program.
Shader createShader (GLenum shader)
 GL function that creates an empty shader.
Texture createTexture ()
 GL function that creates an empty texture.
Texture createTextureAndLoad (const std::string &url)
 GL function that creates an image texture.
void cullFace (GLenum mode)
 GL function that configures the backface culling mode.
void deleteBuffer (Buffer buffer)
 GL function that deletes a VBO.
void deleteProgram (Program program)
 GL function that deletes a program.
void deleteShader (Shader shader)
 GL function that depetes a shader.
void deleteTexture (Texture texture)
 GL function that deletes a texture.
void depthFunc (GLenum func)
 GL function to set the depth test function.
void depthMask (bool 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 (Program program, Shader shader)
 GL function that detaches a shader from a program.
void disable (GLenum cap)
 GL function to disable features.
void drawArrays (GLenum mode, int first, unsigned count)
 GL function to draw a VBO.
void drawElements (GLenum mode, unsigned count, GLenum type, unsigned offset)
 GL function to draw indexed VBOs.
void enable (GLenum cap)
 GL function to enable features.
void enableVertexAttribArray (AttribLocation index)
 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 frontFace (GLenum mode)
 GL function that specifies which side of a triangle is the front side.
void generateMipmap (GLenum target)
 GL function that generates a set of mipmaps for a texture object.
AttribLocation getAttribLocation (Program program, const std::string &attrib)
 GL function to retrieve an attribute's location in a Program.
UniformLocation getUniformLocation (Program program, const std::string location)
 GL function to retrieve a Uniform's location in a Program.
void hint (GLenum target, GLenum mode)
 GL function to give hints to the render pipeline.
void lineWidth (double width)
 GL function to set the line width.
void linkProgram (Program program)
 GL function to link a program.
void pixelStorei (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 sampleCoverage (double value, bool invert)
 GL function to set multisample parameters.
void scissor (int x, int y, unsigned width, unsigned height)
 GL function to define the scissor box.
void shaderSource (Shader shader, const std::string &src)
 GL function to set a shader's source code.
void stencilFunc (GLenum func, int ref, unsigned mask)
 GL function to set stencil test parameters.
void stencilFuncSeparate (GLenum face, GLenum func, int ref, unsigned mask)
 GL function to set stencil test parameters for front and/or back stencils.
void stencilMask (unsigned mask)
 GL function to control which bits are to be written in the stencil buffer.
void stencilMaskSeparate (GLenum face, unsigned mask)
 GL function to control which bits are written to the front and/or back stencil buffers.
void stencilOp (GLenum fail, GLenum zfail, GLenum zpass)
 GL function to set stencil test actions.
void stencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
 GL function to set front and/or back stencil test actions separately.
void texImage2D (GLenum target, int level, GLenum internalformat, GLenum format, GLenum type, WImage *image)
 GL function to load a 2D texture from a WImage.
void texImage2D (GLenum target, int level, GLenum internalformat, GLenum format, GLenum type, WHTML5Video *video)
 GL function to load a 2D texture from a HTML5Video object.
void texImage2D (GLenum target, int level, GLenum internalformat, GLenum format, GLenum type, Texture texture)
 GL function to load a 2D texture loaded with createTextureAndLoad()
void texParameteri (GLenum target, GLenum pname, GLenum param)
 GL function to set texture parameters.
void uniform1f (const UniformLocation &location, double x)
 GL function to set the value of a uniform variable of the current program.
template<typename Array >
void uniform1fv (const UniformLocation &location, const Array *value)
 GL function to set the value of a uniform variable of the current program.
void uniform1i (const UniformLocation &location, int x)
 GL function to set the value of a uniform variable of the current program.
template<typename Array >
void uniform1iv (const UniformLocation &location, const Array *value)
 GL function to set the value of a uniform variable of the current program.
void uniform2f (const UniformLocation &location, double x, double y)
 GL function to set the value of a uniform variable of the current program.
template<typename Array >
void uniform2fv (const UniformLocation &location, const Array *value)
 GL function to set the value of a uniform variable of the current program.
void uniform2i (const UniformLocation &location, int x, int y)
 GL function to set the value of a uniform variable of the current program.
template<typename Array >
void uniform2iv (const UniformLocation &location, const Array *value)
 GL function to set the value of a uniform variable of the current program.
void uniform3f (const UniformLocation &location, double x, double y, double z)
 GL function to set the value of a uniform variable of the current program.
template<typename Array >
void uniform3fv (const UniformLocation &location, const Array *value)
 GL function to set the value of a uniform variable of the current program.
void uniform3i (const UniformLocation &location, int x, int y, int z)
 GL function to set the value of a uniform variable of the current program.
template<typename Array >
void uniform3iv (const UniformLocation &location, const Array *value)
 GL function to set the value of a uniform variable of the current program.
void uniform4f (const UniformLocation &location, double x, double y, double z, double w)
 GL function to set the value of a uniform variable of the current program.
template<typename Array >
void uniform4fv (const UniformLocation &location, const Array *value)
 GL function to set the value of a uniform variable of the current program.
void uniform4i (const UniformLocation &location, int x, int y, int z, int w)
 GL function to set the value of a uniform variable of the current program.
template<typename Array >
void uniform4iv (const UniformLocation &location, const Array *value)
 GL function to set the value of a uniform variable of the current program.
template<typename MatrixType >
void uniformMatrix2fv (const UniformLocation &location, bool transpose, const MatrixType *value)
 GL function to set the value of a uniform matrix of the current program.
template<typename T >
void uniformMatrix2 (const UniformLocation &location, const WGenericMatrix< T, 2, 2 > &m)
 GL function to set the value of a uniform matrix of the current program.
template<typename MatrixType >
void uniformMatrix3fv (const UniformLocation &location, bool transpose, const MatrixType *value)
 GL function to set the value of a uniform matrix of the current program.
template<typename T >
void uniformMatrix3 (const UniformLocation &location, const WGenericMatrix< T, 3, 3 > &m)
 GL function to set the value of a uniform matrix of the current program.
template<typename MatrixType >
void uniformMatrix4fv (const UniformLocation &location, bool transpose, const MatrixType *value)
 GL function to set the value of a uniform matrix of the current program.
template<typename T >
void uniformMatrix4 (const UniformLocation &location, const WGenericMatrix< T, 4, 4 > &m)
 GL function to set the value of a uniform matrix of the current program.
void uniformMatrix4 (const UniformLocation &location, const JavaScriptMatrix4x4 &m)
 GL function to set the value of a uniform matrix of the current program.
void useProgram (Program program)
 GL function to set the current active shader program.
void validateProgram (Program program)
 GL function to validate a program.
void vertexAttrib1f (AttribLocation location, double x)
 GL function to set the value of an attribute of the current program.
template<typename Array >
void vertexAttrib1fv (AttribLocation location, const Array *values)
 GL function to set the value of an attribute of the current program.
void vertexAttrib2f (AttribLocation location, double x, double y)
 GL function to set the value of an attribute of the current program.
template<typename Array >
void vertexAttrib2fv (AttribLocation location, const Array *values)
 GL function to set the value of an attribute of the current program.
void vertexAttrib3f (AttribLocation location, double x, double y, double z)
 GL function to set the value of an attribute of the current program.
template<typename Array >
void vertexAttrib3fv (AttribLocation location, const Array *values)
 GL function to set the value of an attribute of the current program.
void vertexAttrib4f (AttribLocation location, double x, double y, double z, double w)
 GL function to set the value of an attribute of the current program.
template<typename Array >
void vertexAttrib4fv (AttribLocation location, const Array *values)
 GL function to set the value of an attribute of the current program.
void vertexAttribPointer (AttribLocation location, int size, GLenum type, bool normalized, unsigned stride, unsigned offset)
 GL function to bind a VBO to an attribute.
void viewport (int x, int y, unsigned width, unsigned height)
 GL function to set the viewport.
Additional WebGL methods

These methods are used to render WebGL content, but have no equivalent in WebGL.

Like the WebGL methods, you can use the WebGL methods in your resizeGL(), paintGL() and updateGL() specializations. It makes no sense to call these methods outside those functions.

JavaScriptMatrix4x4 createJavaScriptMatrix4 ()
 Create a matrix that can be manipulated in client-side JavaScript.
template<typename T >
void setJavaScriptMatrix4 (const JavaScriptMatrix4x4 &jsm, const WGenericMatrix< T, 4, 4 > &m)
 Set the value of a client-side JavaScript matrix created by createJavaScriptMatrix4x4()

Private Member Functions

void layoutSizeChanged (int width, int height)
 Virtual method that indicates a size change.

Detailed Description

WebGL support class.

The WGLWidget class is an interface to the HTML5 WebGL infrastructure. Its implementation started based on the working drafts of the Khronos group, and will be updated as the standard stabilizes. 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: https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/WebGL-spec.html

This widget is work in progress. The API may change in the future because of new features, reorganizations or changes in the WebGL draft.

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, Wt records the JavaScript calls that have to be invoked in the browser.

The WebGL 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.

Client side matrices.

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.

Note: the client side matrices are currently not yet communicated back to the server, but that is an implementation idea for the future.


Member Enumeration Documentation

Specifies what WebGL function needs to be updated.

Enumerator:
PAINT_GL 

refresh paintGL()

RESIZE_GL 

refresh resizeGL()

UPDATE_GL 

refresh updateGL()

The enourmous GLenum.

This enum contains all numeric constants defined by the WebGL standard.


Constructor & Destructor Documentation

WGLWidget::WGLWidget ( WContainerWidget parent)

Construct a WebGL widget.

Before the first rendering, you must apply a size to the WGLWidget.

/code /endcode


Member Function Documentation

void WGLWidget::activeTexture ( GLenum  texture)

GL function to activate an existing texture.

glActiveTexture() OpenGL ES manpage

void WGLWidget::attachShader ( Program  program,
Shader  shader 
)

GL function to attach a shader to a program.

glAttachShader() OpenGL ES manpage

void WGLWidget::bindAttribLocation ( Program  program,
unsigned  index,
const std::string &  name 
)

GL function to bind an attribute to a given location.

glBindAttribLocation() OpenGL ES manpage

void WGLWidget::bindBuffer ( GLenum  target,
Buffer  buffer 
)

GL function to bind a buffer to a target.

glBindBuffer() OpenGL ES manpage

void WGLWidget::bindTexture ( GLenum  target,
Texture  texture 
)

GL function to bind a texture to a target.

glBindTexture() OpenGL ES manpage

void WGLWidget::blendColor ( double  red,
double  green,
double  blue,
double  alpha 
)

GL function to set the blending color.

glBlendColor() OpenGL ES manpage

void WGLWidget::blendEquation ( GLenum  mode)

GL function to set the blending equation.

glBlendEquation() OpenGL ES manpage

void WGLWidget::blendEquationSeparate ( GLenum  modeRGB,
GLenum  modeAlpha 
)

GL function that sets separate blending functions for RGB and alpha.

glBlendEquationSeparate() OpenGL ES manpage

void WGLWidget::blendFunc ( GLenum  sfactor,
GLenum  dfactor 
)

GL function to configure the blending function.

glBlendFunc() OpenGL ES manpage

void WGLWidget::blendFuncSeparate ( GLenum  srcRGB,
GLenum  dstRGB,
GLenum  srcAlpha,
GLenum  dstAlpha 
)

GL function that configures the blending function.

glBlendFuncSeparate() OpenGL ES manpage

template<typename Iterator >
void Wt::WGLWidget::bufferDatafv ( GLenum  target,
const Iterator  begin,
const Iterator  end,
GLenum  usage 
)

GL function that loads float or double data in a VBO.

Unlike the C version, we can't accept a void * here. We must be able to interpret the buffer's data in order to transmit it to the JS side.

Later we may also want versions with strides and offsets to cope with more complex buffer layouts that we typically see on desktop WebGL apps; suggestions to improve this are welcome

glBufferData() OpenGL ES manpage

template<typename Iterator >
void Wt::WGLWidget::bufferDataiv ( GLenum  target,
const Iterator  begin,
const Iterator  end,
GLenum  usage,
GLenum  type 
)

GL function that updates an existing VBO with new integer data.

glBufferData() OpenGL ES manpage

template<typename Iterator >
void Wt::WGLWidget::bufferSubDatafv ( GLenum  target,
unsigned  offset,
const Iterator  begin,
const Iterator  end 
)

GL function that updates an existing VBO with new float or double data.

glBufferSubData() OpenGL ES manpage

template<typename Iterator >
void Wt::WGLWidget::bufferSubDataiv ( GLenum  target,
unsigned  offset,
const Iterator  begin,
Iterator  end,
GLenum  type 
)

GL function that loads integer data in a VBO.

glBufferSubData() OpenGL ES manpage

void WGLWidget::clear ( WFlags< GLenum mask)

GL function that clears the given buffers.

glClear() OpenGL ES manpage

void WGLWidget::clearColor ( double  r,
double  g,
double  b,
double  a 
)

GL function that sets the clear color of the color buffer.

glClearColor() OpenGL ES manpage

void WGLWidget::clearDepth ( double  depth)

GL function that configures the depth to be set when the depth buffer is cleared.

glClearDepthf() OpenGL ES manpage

void WGLWidget::clearStencil ( int  s)
void WGLWidget::colorMask ( bool  red,
bool  green,
bool  blue,
bool  alpha 
)
void WGLWidget::compileShader ( Shader  shader)

GL function to compile a shader.

glCompileShader() OpenGL ES manpage

void WGLWidget::copyTexImage2D ( GLenum  target,
int  level,
GLenum  internalformat,
int  x,
int  y,
unsigned  width,
unsigned  height,
int  border 
)

GL function to copy a texture image.

glCopyTexImage2D() OpenGL ES manpage

void WGLWidget::copyTexSubImage2D ( GLenum  target,
int  level,
int  xoffset,
int  yoffset,
int  x,
int  y,
unsigned  width,
unsigned  height 
)

GL function that copies a part of a texture image.

glCopyTexSubImage2D() OpenGL ES manpage

WGLWidget::Buffer WGLWidget::createBuffer ( )

GL function that creates an empty VBO.

glGenBuffers() OpenGL ES manpage

WGLWidget::Program WGLWidget::createProgram ( )

GL function that creates an empty program.

glCreateProgram() OpenGL ES manpage

WGLWidget::Shader WGLWidget::createShader ( GLenum  shader)

GL function that creates an empty shader.

glCreateShader() OpenGL ES manpage

WGLWidget::Texture WGLWidget::createTexture ( )

GL function that creates an empty texture.

glGenTextures() OpenGL ES manpage

WGLWidget::Texture WGLWidget::createTextureAndLoad ( const std::string &  url)

GL function that creates an image texture.

glGenTextures() OpenGL ES manpage

void WGLWidget::cullFace ( GLenum  mode)

GL function that configures the backface culling mode.

glCullFace() OpenGL ES manpage

void WGLWidget::debugger ( )

GL function to activate an existing texture.

glActiveTexture() OpenGL ES manpage

void WGLWidget::deleteBuffer ( Buffer  buffer)

GL function that deletes a VBO.

glDeleteBuffers() OpenGL ES manpage

void WGLWidget::deleteProgram ( Program  program)

GL function that deletes a program.

glDeleteProgram() OpenGL ES manpage

void WGLWidget::deleteShader ( Shader  shader)

GL function that depetes a shader.

glDeleteShader() OpenGL ES manpage

void WGLWidget::deleteTexture ( Texture  texture)

GL function that deletes a texture.

glDeleteTextures() OpenGL ES manpage

void WGLWidget::depthFunc ( GLenum  func)

GL function to set the depth test function.

glDepthFunc() OpenGL ES manpage

void WGLWidget::depthMask ( bool  flag)

GL function that enables or disables writing to the depth buffer.

glDepthMask() OpenGL ES manpage

void WGLWidget::depthRange ( double  zNear,
double  zFar 
)

GL function that specifies to what range the normalized [-1,1] z values should match.

glDepthRangef() OpenGL ES manpage

void WGLWidget::detachShader ( Program  program,
Shader  shader 
)

GL function that detaches a shader from a program.

glDetachShader() OpenGL ES manpage

void WGLWidget::disable ( GLenum  cap)

GL function to disable features.

glDisable() OpenGL ES manpage

void WGLWidget::drawArrays ( GLenum  mode,
int  first,
unsigned  count 
)

GL function to draw a VBO.

glDrawArrays() OpenGL ES manpage

void WGLWidget::drawElements ( GLenum  mode,
unsigned  count,
GLenum  type,
unsigned  offset 
)

GL function to draw indexed VBOs.

glDrawElements() OpenGL ES manpage

void WGLWidget::enable ( GLenum  cap)

GL function to enable features.

glEnable() OpenGL ES manpage

void WGLWidget::enableVertexAttribArray ( AttribLocation  index)

GL function to enable the vertex attribute array.

glEnableVertexAttribArray() OpenGL ES manpage

void WGLWidget::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.

glFinish() OpenGL ES manpage

void WGLWidget::flush ( )

GL function to force execution of GL commands in finite time.

glFlush() OpenGL ES manpage

void WGLWidget::frontFace ( GLenum  mode)

GL function that specifies which side of a triangle is the front side.

glFrontFace() OpenGL ES manpage

void WGLWidget::generateMipmap ( GLenum  target)

GL function that generates a set of mipmaps for a texture object.

glGenerateMipmap() OpenGL ES manpage

WGLWidget::AttribLocation WGLWidget::getAttribLocation ( Program  program,
const std::string &  attrib 
)

GL function to retrieve an attribute's location in a Program.

glGetAttribLocation() OpenGL ES manpage

WGLWidget::UniformLocation WGLWidget::getUniformLocation ( Program  program,
const std::string  location 
)

GL function to retrieve a Uniform's location in a Program.

glGetUniformLocation() OpenGL ES manpage

void WGLWidget::hint ( GLenum  target,
GLenum  mode 
)

GL function to give hints to the render pipeline.

glHint() OpenGL ES manpage

void WGLWidget::initializeGL ( ) [virtual]

Initialize the WebGL state when the widget is first shown.

initializeGL() is called once, when the widget is first rendered. It usually creates most of the WebGL 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.

Note: in a future version, this method will probably also be invoked on contextrestore events.

void WGLWidget::layoutSizeChanged ( int  width,
int  height 
) [private, virtual]

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.

See also:
setLayoutSizeAware()

Reimplemented from Wt::WWidget.

void WGLWidget::lineWidth ( double  width)

GL function to set the line width.

glLineWidth() OpenGL ES manpage

void WGLWidget::linkProgram ( Program  program)

GL function to link a program.

glLinkProgram() OpenGL ES manpage

void WGLWidget::paintGL ( ) [virtual]

Update the client-side painting function.

This method is invoked client-side when a repaint is required, i.e. when the repaintSlot() (a JavaScript-side JSlot) 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 WebGL 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 repaintSlot(). There are a few mechanisms that may be employed to change what is rendered without updating the paintGL() cache:

  • Client-side matrices may be used to change camera viewpoints, manipilate separate object's model transformation matrices, ...
  • 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 the paintGL() code only draws the VBOs. Of course, if you have to draw many separate objects, the paintGL() JS code may become large and updating is more expensive.

In order to update the paintGL() cache, call repaintGL() with the PAINT_GL parameter, which will cause the invocation of this method.

void WGLWidget::pixelStorei ( GLenum  pname,
int  param 
)

GL function to set the pixel storage mode.

glPixelStorei() OpenGL ES manpage

void WGLWidget::polygonOffset ( double  factor,
double  units 
)

GL function to apply modifications to Z values.

glPolygonOffset() OpenGL ES manpage

void WGLWidget::repaintGL ( WFlags< ClientSideRenderer which)

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().

JSlot& Wt::WGLWidget::repaintSlot ( )

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.

void WGLWidget::resize ( const WLength width,
const WLength height 
) [virtual]

Resizes the widget.

Specify a new size for this widget, by specifying width and height. By default a widget has automatic width and height, see WLength::isAuto().

This applies to CSS-based layout, and only block widgets can be given a size reliably.

When inserted in a layout manager, the widget may be informed about its current size using setLayoutSizeAware(). If you have defined a "wtResize()" JavaScript method for the widget, then this method will also be called. operation.

See also:
width(), height()

Reimplemented from Wt::WWebWidget.

void WGLWidget::resizeGL ( int  width,
int  height 
) [virtual]

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.

void WGLWidget::sampleCoverage ( double  value,
bool  invert 
)

GL function to set multisample parameters.

glSampleCoverage() OpenGL ES manpage

void WGLWidget::scissor ( int  x,
int  y,
unsigned  width,
unsigned  height 
)

GL function to define the scissor box.

glScissor() OpenGL ES manpage

void WGLWidget::setAlternativeContent ( WWidget alternative)

Sets the content to be displayed when WebGL is not available.

If Wt 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.

void WGLWidget::setClientSideLookAtHandler ( const JavaScriptMatrix4x4 m,
double  lX,
double  lY,
double  lZ,
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).

void WGLWidget::setClientSideWalkHandler ( const 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.

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).

void WGLWidget::shaderSource ( Shader  shader,
const std::string &  src 
)

GL function to set a shader's source code.

glShaderSource() OpenGL ES manpage

void WGLWidget::stencilFunc ( GLenum  func,
int  ref,
unsigned  mask 
)

GL function to set stencil test parameters.

glStencilFunc() OpenGL ES manpage

void WGLWidget::stencilFuncSeparate ( GLenum  face,
GLenum  func,
int  ref,
unsigned  mask 
)

GL function to set stencil test parameters for front and/or back stencils.

glStencilFuncSeparate() OpenGL ES manpage

void WGLWidget::stencilMask ( unsigned  mask)

GL function to control which bits are to be written in the stencil buffer.

glStencilMask() OpenGL ES manpage

void WGLWidget::stencilMaskSeparate ( GLenum  face,
unsigned  mask 
)

GL function to control which bits are written to the front and/or back stencil buffers.

glStencilMaskSeparate() OpenGL ES manpage

void WGLWidget::stencilOp ( GLenum  fail,
GLenum  zfail,
GLenum  zpass 
)

GL function to set stencil test actions.

glStencilOp() OpenGL ES manpage

void WGLWidget::stencilOpSeparate ( GLenum  face,
GLenum  fail,
GLenum  zfail,
GLenum  zpass 
)

GL function to set front and/or back stencil test actions separately.

glStencilOpSeparate() OpenGL ES manpage

void WGLWidget::texImage2D ( GLenum  target,
int  level,
GLenum  internalformat,
GLenum  format,
GLenum  type,
WHTML5Video video 
)

GL function to load a 2D texture from a HTML5Video object.

Note: the video must be loaded prior to calling this function. The current frame is used as texture image.

glTexImage2D() OpenGL ES manpage

void WGLWidget::texImage2D ( GLenum  target,
int  level,
GLenum  internalformat,
GLenum  format,
GLenum  type,
WImage image 
)

GL function to load a 2D texture from a WImage.

Note: WImage must be loaded before this function is executed.

glTexImage2D() OpenGL ES manpage

void WGLWidget::texImage2D ( GLenum  target,
int  level,
GLenum  internalformat,
GLenum  format,
GLenum  type,
Texture  texture 
)

GL function to load a 2D texture loaded with createTextureAndLoad()

This function must only be used for textures created with createTextureAndLoad()

Note: the WGLWidget implementation will delay rendering until all textures created with createTextureAndLoad() are loaded in the browser.

glTexImage2D() OpenGL ES manpage

void WGLWidget::texParameteri ( GLenum  target,
GLenum  pname,
GLenum  param 
)

GL function to set texture parameters.

glTexParameter() OpenGL ES manpage

void Wt::WGLWidget::uniform1f ( const UniformLocation &  location,
double  x 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::uniform1fv ( const UniformLocation &  location,
const Array *  value 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

void Wt::WGLWidget::uniform1i ( const UniformLocation &  location,
int  x 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::uniform1iv ( const UniformLocation &  location,
const Array *  value 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

void Wt::WGLWidget::uniform2f ( const UniformLocation &  location,
double  x,
double  y 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::uniform2fv ( const UniformLocation &  location,
const Array *  value 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

void Wt::WGLWidget::uniform2i ( const UniformLocation &  location,
int  x,
int  y 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::uniform2iv ( const UniformLocation &  location,
const Array *  value 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

void Wt::WGLWidget::uniform3f ( const UniformLocation &  location,
double  x,
double  y,
double  z 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::uniform3fv ( const UniformLocation &  location,
const Array *  value 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

void Wt::WGLWidget::uniform3i ( const UniformLocation &  location,
int  x,
int  y,
int  z 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::uniform3iv ( const UniformLocation &  location,
const Array *  value 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

void Wt::WGLWidget::uniform4f ( const UniformLocation &  location,
double  x,
double  y,
double  z,
double  w 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::uniform4fv ( const UniformLocation &  location,
const Array *  value 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

void Wt::WGLWidget::uniform4i ( const UniformLocation &  location,
int  x,
int  y,
int  z,
int  w 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::uniform4iv ( const UniformLocation &  location,
const Array *  value 
)

GL function to set the value of a uniform variable of the current program.

glUniform() OpenGL ES manpage

template<typename T >
void Wt::WGLWidget::uniformMatrix2 ( const UniformLocation &  location,
const WGenericMatrix< T, 2, 2 > &  m 
)

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.

glUniform() OpenGL ES manpage

template<typename MatrixType >
void Wt::WGLWidget::uniformMatrix2fv ( const UniformLocation &  location,
bool  transpose,
const MatrixType *  value 
)

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.

glUniform() OpenGL ES manpage

template<typename T >
void Wt::WGLWidget::uniformMatrix3 ( const UniformLocation &  location,
const WGenericMatrix< T, 3, 3 > &  m 
)

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.

glUniform() OpenGL ES manpage

template<typename MatrixType >
void Wt::WGLWidget::uniformMatrix3fv ( const UniformLocation &  location,
bool  transpose,
const MatrixType *  value 
)

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.

glUniform() OpenGL ES manpage

template<typename T >
void Wt::WGLWidget::uniformMatrix4 ( const UniformLocation &  location,
const WGenericMatrix< T, 4, 4 > &  m 
)

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.

glUniform() OpenGL ES manpage

void Wt::WGLWidget::uniformMatrix4 ( const UniformLocation &  location,
const JavaScriptMatrix4x4 m 
)

GL function to set the value of a uniform matrix of the current program.

glUniform() OpenGL ES manpage

template<typename MatrixType >
void Wt::WGLWidget::uniformMatrix4fv ( const UniformLocation &  location,
bool  transpose,
const MatrixType *  value 
)

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.

glUniform() OpenGL ES manpage

void WGLWidget::updateGL ( ) [virtual]

Update state set in initializeGL()

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.

void WGLWidget::useProgram ( Program  program)

GL function to set the current active shader program.

glUseProgram() OpenGL ES manpage

void WGLWidget::validateProgram ( Program  program)

GL function to validate a program.

implementation note: there is currently not yet a method to read out the validation result.

glValidateProgram() OpenGL ES manpage

void Wt::WGLWidget::vertexAttrib1f ( AttribLocation  location,
double  x 
)

GL function to set the value of an attribute of the current program.

glVertexAttrib() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::vertexAttrib1fv ( AttribLocation  location,
const Array *  values 
)

GL function to set the value of an attribute of the current program.

glVertexAttrib() OpenGL ES manpage

void Wt::WGLWidget::vertexAttrib2f ( AttribLocation  location,
double  x,
double  y 
)

GL function to set the value of an attribute of the current program.

glVertexAttrib() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::vertexAttrib2fv ( AttribLocation  location,
const Array *  values 
)

GL function to set the value of an attribute of the current program.

glVertexAttrib() OpenGL ES manpage

void Wt::WGLWidget::vertexAttrib3f ( AttribLocation  location,
double  x,
double  y,
double  z 
)

GL function to set the value of an attribute of the current program.

glVertexAttrib() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::vertexAttrib3fv ( AttribLocation  location,
const Array *  values 
)

GL function to set the value of an attribute of the current program.

glVertexAttrib() OpenGL ES manpage

void Wt::WGLWidget::vertexAttrib4f ( AttribLocation  location,
double  x,
double  y,
double  z,
double  w 
)

GL function to set the value of an attribute of the current program.

glVertexAttrib() OpenGL ES manpage

template<typename Array >
void Wt::WGLWidget::vertexAttrib4fv ( AttribLocation  location,
const Array *  values 
)

GL function to set the value of an attribute of the current program.

glVertexAttrib() OpenGL ES manpage

void WGLWidget::vertexAttribPointer ( AttribLocation  location,
int  size,
GLenum  type,
bool  normalized,
unsigned  stride,
unsigned  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.

glVertexAttribPointer() OpenGL ES manpage

void WGLWidget::viewport ( int  x,
int  y,
unsigned  width,
unsigned  height 
)

GL function to set the viewport.

glViewport() OpenGL ES manpage

 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Wed Jul 27 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.4