WebGLRenderingContext.h [plain text]
#ifndef WebGLRenderingContext_h
#define WebGLRenderingContext_h
#include "CanvasRenderingContext.h"
#include "ExceptionCode.h"
#include "Float32Array.h"
#include "WebGLGetInfo.h"
#include "Int32Array.h"
#include "Uint8Array.h"
#include "GraphicsContext3D.h"
#include "PlatformString.h"
namespace WebCore {
class WebGLActiveInfo;
class WebGLBuffer;
class WebGLContextAttributes;
class WebGLFramebuffer;
class CanvasObject;
class WebGLProgram;
class WebGLRenderbuffer;
class WebGLShader;
class WebGLTexture;
class WebGLUniformLocation;
class HTMLImageElement;
class HTMLVideoElement;
class ImageData;
class WebKitCSSMatrix;
class WebGLRenderingContext : public CanvasRenderingContext {
public:
static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*);
virtual ~WebGLRenderingContext();
virtual bool is3d() const { return true; }
int sizeInBytes(int type, ExceptionCode& ec);
void activeTexture(unsigned long texture, ExceptionCode& ec);
void attachShader(WebGLProgram*, WebGLShader*, ExceptionCode& ec);
void bindAttribLocation(WebGLProgram*, unsigned long index, const String& name, ExceptionCode& ec);
void bindBuffer(unsigned long target, WebGLBuffer*, ExceptionCode& ec);
void bindFramebuffer(unsigned long target, WebGLFramebuffer*, ExceptionCode& ec);
void bindRenderbuffer(unsigned long target, WebGLRenderbuffer*, ExceptionCode& ec);
void bindTexture(unsigned long target, WebGLTexture*, ExceptionCode& ec);
void blendColor(double red, double green, double blue, double alpha);
void blendEquation(unsigned long mode);
void blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha);
void blendFunc(unsigned long sfactor, unsigned long dfactor);
void blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha);
void bufferData(unsigned long target, int size, unsigned long usage, ExceptionCode&);
void bufferData(unsigned long target, ArrayBufferView* data, unsigned long usage, ExceptionCode&);
void bufferSubData(unsigned long target, long offset, ArrayBufferView* data, ExceptionCode&);
unsigned long checkFramebufferStatus(unsigned long target);
void clear(unsigned long mask);
void clearColor(double red, double green, double blue, double alpha);
void clearDepth(double);
void clearStencil(long);
void colorMask(bool red, bool green, bool blue, bool alpha);
void compileShader(WebGLShader*, ExceptionCode& ec);
void copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border);
void copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height);
PassRefPtr<WebGLBuffer> createBuffer();
PassRefPtr<WebGLFramebuffer> createFramebuffer();
PassRefPtr<WebGLProgram> createProgram();
PassRefPtr<WebGLRenderbuffer> createRenderbuffer();
PassRefPtr<WebGLShader> createShader(unsigned long type, ExceptionCode&);
PassRefPtr<WebGLTexture> createTexture();
void cullFace(unsigned long mode);
void deleteBuffer(WebGLBuffer*);
void deleteFramebuffer(WebGLFramebuffer*);
void deleteProgram(WebGLProgram*);
void deleteRenderbuffer(WebGLRenderbuffer*);
void deleteShader(WebGLShader*);
void deleteTexture(WebGLTexture*);
void depthFunc(unsigned long);
void depthMask(bool);
void depthRange(double zNear, double zFar);
void detachShader(WebGLProgram*, WebGLShader*, ExceptionCode&);
void disable(unsigned long cap);
void disableVertexAttribArray(unsigned long index, ExceptionCode&);
void drawArrays(unsigned long mode, long first, long count, ExceptionCode&);
void drawElements(unsigned long mode, long count, unsigned long type, long offset, ExceptionCode&);
void enable(unsigned long cap);
void enableVertexAttribArray(unsigned long index, ExceptionCode&);
void finish();
void flush();
void framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, WebGLRenderbuffer*, ExceptionCode& ec);
void framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, WebGLTexture*, long level, ExceptionCode& ec);
void frontFace(unsigned long mode);
void generateMipmap(unsigned long target);
PassRefPtr<WebGLActiveInfo> getActiveAttrib(WebGLProgram*, unsigned long index, ExceptionCode&);
PassRefPtr<WebGLActiveInfo> getActiveUniform(WebGLProgram*, unsigned long index, ExceptionCode&);
int getAttribLocation(WebGLProgram*, const String& name);
WebGLGetInfo getBufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
PassRefPtr<WebGLContextAttributes> getContextAttributes();
unsigned long getError();
WebGLGetInfo getFramebufferAttachmentParameter(unsigned long target, unsigned long attachment, unsigned long pname, ExceptionCode&);
WebGLGetInfo getParameter(unsigned long pname, ExceptionCode&);
WebGLGetInfo getProgramParameter(WebGLProgram*, unsigned long pname, ExceptionCode&);
String getProgramInfoLog(WebGLProgram*, ExceptionCode& ec);
WebGLGetInfo getRenderbufferParameter(unsigned long target, unsigned long pname, ExceptionCode&);
WebGLGetInfo getShaderParameter(WebGLShader*, unsigned long pname, ExceptionCode& ec);
String getShaderInfoLog(WebGLShader*, ExceptionCode& ec);
String getShaderSource(WebGLShader*, ExceptionCode&);
String getString(unsigned long name);
WebGLGetInfo getTexParameter(unsigned long target, unsigned long pname, ExceptionCode&);
WebGLGetInfo getUniform(WebGLProgram*, const WebGLUniformLocation*, ExceptionCode&);
PassRefPtr<WebGLUniformLocation> getUniformLocation(WebGLProgram*, const String&, ExceptionCode&);
WebGLGetInfo getVertexAttrib(unsigned long index, unsigned long pname, ExceptionCode&);
long getVertexAttribOffset(unsigned long index, unsigned long pname);
void hint(unsigned long target, unsigned long mode);
bool isBuffer(WebGLBuffer*);
bool isEnabled(unsigned long cap);
bool isFramebuffer(WebGLFramebuffer*);
bool isProgram(WebGLProgram*);
bool isRenderbuffer(WebGLRenderbuffer*);
bool isShader(WebGLShader*);
bool isTexture(WebGLTexture*);
void lineWidth(double);
void linkProgram(WebGLProgram*, ExceptionCode&);
void pixelStorei(unsigned long pname, long param);
void polygonOffset(double factor, double units);
PassRefPtr<ArrayBufferView> readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type);
void releaseShaderCompiler();
void renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height);
void sampleCoverage(double value, bool invert);
void scissor(long x, long y, unsigned long width, unsigned long height);
void shaderSource(WebGLShader*, const String&, ExceptionCode&);
void stencilFunc(unsigned long func, long ref, unsigned long mask);
void stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask);
void stencilMask(unsigned long);
void stencilMaskSeparate(unsigned long face, unsigned long mask);
void stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass);
void stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass);
void texImage2D(unsigned target, unsigned level, unsigned internalformat,
unsigned width, unsigned height, unsigned border,
unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, unsigned internalformat,
unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, unsigned internalformat,
unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, unsigned internalformat,
unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, unsigned internalformat,
unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, ImageData* pixels, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, ExceptionCode&);
void texImage2D(unsigned target, unsigned level, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void texParameterf(unsigned target, unsigned pname, float param);
void texParameteri(unsigned target, unsigned pname, int param);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
unsigned width, unsigned height,
unsigned format, unsigned type, ArrayBufferView* pixels, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
unsigned format, unsigned type, ImageData* pixels, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
unsigned format, unsigned type, HTMLImageElement* image, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
unsigned format, unsigned type, HTMLCanvasElement* canvas, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
unsigned format, unsigned type, HTMLVideoElement* video, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, ImageData* pixels, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLImageElement* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLCanvasElement* canvas, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, ExceptionCode&);
void texSubImage2D(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset, HTMLVideoElement* video, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void uniform1f(const WebGLUniformLocation* location, float x, ExceptionCode&);
void uniform1fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
void uniform1fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
void uniform1i(const WebGLUniformLocation* location, int x, ExceptionCode&);
void uniform1iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
void uniform1iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
void uniform2f(const WebGLUniformLocation* location, float x, float y, ExceptionCode&);
void uniform2fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
void uniform2fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
void uniform2i(const WebGLUniformLocation* location, int x, int y, ExceptionCode&);
void uniform2iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
void uniform2iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
void uniform3f(const WebGLUniformLocation* location, float x, float y, float z, ExceptionCode&);
void uniform3fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
void uniform3fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
void uniform3i(const WebGLUniformLocation* location, int x, int y, int z, ExceptionCode&);
void uniform3iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
void uniform3iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
void uniform4f(const WebGLUniformLocation* location, float x, float y, float z, float w, ExceptionCode&);
void uniform4fv(const WebGLUniformLocation* location, Float32Array* v, ExceptionCode&);
void uniform4fv(const WebGLUniformLocation* location, float* v, int size, ExceptionCode&);
void uniform4i(const WebGLUniformLocation* location, int x, int y, int z, int w, ExceptionCode&);
void uniform4iv(const WebGLUniformLocation* location, Int32Array* v, ExceptionCode&);
void uniform4iv(const WebGLUniformLocation* location, int* v, int size, ExceptionCode&);
void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
void uniformMatrix2fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
void uniformMatrix3fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, Float32Array* value, ExceptionCode&);
void uniformMatrix4fv(const WebGLUniformLocation* location, bool transpose, float* value, int size, ExceptionCode&);
void useProgram(WebGLProgram*, ExceptionCode&);
void validateProgram(WebGLProgram*, ExceptionCode&);
void vertexAttrib1f(unsigned long indx, float x);
void vertexAttrib1fv(unsigned long indx, Float32Array* values);
void vertexAttrib1fv(unsigned long indx, float* values, int size);
void vertexAttrib2f(unsigned long indx, float x, float y);
void vertexAttrib2fv(unsigned long indx, Float32Array* values);
void vertexAttrib2fv(unsigned long indx, float* values, int size);
void vertexAttrib3f(unsigned long indx, float x, float y, float z);
void vertexAttrib3fv(unsigned long indx, Float32Array* values);
void vertexAttrib3fv(unsigned long indx, float* values, int size);
void vertexAttrib4f(unsigned long indx, float x, float y, float z, float w);
void vertexAttrib4fv(unsigned long indx, Float32Array* values);
void vertexAttrib4fv(unsigned long indx, float* values, int size);
void vertexAttribPointer(unsigned long indx, long size, unsigned long type, bool normalized,
unsigned long stride, unsigned long offset, ExceptionCode&);
void viewport(long x, long y, unsigned long width, unsigned long height);
GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
void reshape(int width, int height);
void beginPaint();
void endPaint();
void removeObject(CanvasObject*);
private:
friend class CanvasObject;
WebGLRenderingContext(HTMLCanvasElement*, PassOwnPtr<GraphicsContext3D>);
void addObject(CanvasObject*);
void detachAndRemoveAllObjects();
WebGLTexture* findTexture(Platform3DObject);
WebGLRenderbuffer* findRenderbuffer(Platform3DObject);
WebGLBuffer* findBuffer(Platform3DObject);
void markContextChanged();
void cleanupAfterGraphicsCall(bool changed)
{
if (changed)
markContextChanged();
}
bool isGLES2Compliant();
bool validateElementArraySize(unsigned long count, unsigned long type, long offset);
bool validateIndexArrayConservative(unsigned long type, long& numElementsRequired);
bool validateIndexArrayPrecise(unsigned long count, unsigned long type, long offset, long& numElementsRequired);
bool validateRenderingState(long numElements);
bool validateWebGLObject(CanvasObject* object);
OwnPtr<GraphicsContext3D> m_context;
bool m_needsUpdate;
bool m_markedCanvasDirty;
HashSet<RefPtr<CanvasObject> > m_canvasObjects;
RefPtr<WebGLBuffer> m_boundArrayBuffer;
RefPtr<WebGLBuffer> m_boundElementArrayBuffer;
class VertexAttribState {
public:
VertexAttribState() : enabled(false), bytesPerElement(0), stride(0), offset(0) { }
bool enabled;
RefPtr<WebGLBuffer> bufferBinding;
long bytesPerElement;
unsigned long stride;
unsigned long offset;
};
Vector<VertexAttribState> m_vertexAttribState;
unsigned m_maxVertexAttribs;
RefPtr<WebGLProgram> m_currentProgram;
RefPtr<WebGLFramebuffer> m_framebufferBinding;
RefPtr<WebGLRenderbuffer> m_renderbufferBinding;
class TextureUnitState {
public:
RefPtr<WebGLTexture> m_texture2DBinding;
RefPtr<WebGLTexture> m_textureCubeMapBinding;
};
Vector<TextureUnitState> m_textureUnits;
unsigned long m_activeTextureUnit;
RefPtr<WebGLTexture> m_blackTexture2D;
RefPtr<WebGLTexture> m_blackTextureCubeMap;
long m_maxTextureSize;
long m_maxCubeMapTextureSize;
int m_packAlignment;
int m_unpackAlignment;
unsigned long m_implementationColorReadFormat;
unsigned long m_implementationColorReadType;
bool m_unpackFlipY;
bool m_unpackPremultiplyAlpha;
WebGLGetInfo getBooleanParameter(unsigned long pname);
WebGLGetInfo getBooleanArrayParameter(unsigned long pname);
WebGLGetInfo getFloatParameter(unsigned long pname);
WebGLGetInfo getIntParameter(unsigned long pname);
WebGLGetInfo getLongParameter(unsigned long pname);
WebGLGetInfo getUnsignedLongParameter(unsigned long pname);
WebGLGetInfo getWebGLFloatArrayParameter(unsigned long pname);
WebGLGetInfo getWebGLIntArrayParameter(unsigned long pname);
void texImage2DBase(unsigned target, unsigned level, unsigned internalformat,
unsigned width, unsigned height, unsigned border,
unsigned format, unsigned type, void* pixels, ExceptionCode&);
void texImage2DImpl(unsigned target, unsigned level, unsigned internalformat,
unsigned format, unsigned type, Image* image,
bool flipY, bool premultiplyAlpha, ExceptionCode&);
void texSubImage2DBase(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
unsigned width, unsigned height,
unsigned format, unsigned type, void* pixels, ExceptionCode&);
void texSubImage2DImpl(unsigned target, unsigned level, unsigned xoffset, unsigned yoffset,
unsigned format, unsigned type,
Image* image, bool flipY, bool premultiplyAlpha, ExceptionCode&);
void handleNPOTTextures(bool prepareToDraw);
void createFallbackBlackTextures1x1();
bool isTexInternalFormatColorBufferCombinationValid(unsigned long texInternalFormat,
unsigned long colorBufferFormat);
WebGLTexture* getTextureBinding(unsigned long target);
bool validateTexFuncFormatAndType(unsigned long format, unsigned long type);
bool validateTexFuncParameters(unsigned long target, long level,
unsigned long internalformat,
long width, long height, long border,
unsigned long format, unsigned long type);
bool validateTexFuncData(long width, long height,
unsigned long format, unsigned long type,
ArrayBufferView* pixels);
bool validateDrawMode(unsigned long);
void texParameter(unsigned long target, unsigned long pname, float parami, int paramf, bool isFloat);
void printWarningToConsole(const String& message);
bool validateFramebufferFuncParameters(unsigned long target, unsigned long attachment);
bool validateBlendEquation(unsigned long);
bool validateCapability(unsigned long);
friend class WebGLStateRestorer;
};
}
#endif