Backed out changeset 58dbd2146e24 (bug 944961) for bustage.
[gecko.git] / content / canvas / src / WebGLTypes.h
bloba8fac662ea340845ba0af71efe31b043db2c7ea5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WEBGLTYPES_H_
7 #define WEBGLTYPES_H_
9 #include "mozilla/TypedEnum.h"
11 // Most WebIDL typedefs are identical to their OpenGL counterparts.
12 #include "GLTypes.h"
14 // Manual reflection of WebIDL typedefs that are different from their
15 // OpenGL counterparts.
16 typedef int64_t WebGLsizeiptr;
17 typedef int64_t WebGLintptr;
18 typedef bool WebGLboolean;
20 namespace mozilla {
23 * WebGLContextFakeBlackStatus and WebGLTextureFakeBlackStatus are enums to
24 * track what needs to use a dummy 1x1 black texture, which we refer to as a
25 * 'fake black' texture.
27 * There are generally two things that can cause us to use such 'fake black'
28 * textures:
30 * (1) OpenGL ES rules on sampling incomplete textures specify that they
31 * must be sampled as RGBA(0, 0, 0, 1) (opaque black). We have to implement these rules
32 * ourselves, if only because we do not always run on OpenGL ES, and also
33 * because this is dangerously close to the kind of case where we don't
34 * want to trust the driver with corner cases of texture memory accesses.
36 * (2) OpenGL has cases where a renderbuffer, or a texture image, can contain
37 * uninitialized image data. See below the comment about WebGLImageDataStatus.
38 * WebGL must never have access to uninitialized image data. The WebGL 1 spec,
39 * section 4.1 'Resource Restrictions', specifies that in any such case, the
40 * uninitialized image data must be exposed to WebGL as if it were filled
41 * with zero bytes, which means it's either opaque or transparent black
42 * depending on whether the image format has alpha.
44 * Why are there _two_ separate enums there, WebGLContextFakeBlackStatus
45 * and WebGLTextureFakeBlackStatus? That's because each texture must know the precise
46 * reason why it needs to be faked (incomplete texture vs. uninitialized image data),
47 * whereas the WebGL context can only know whether _any_ faking is currently needed at all.
49 MOZ_BEGIN_ENUM_CLASS(WebGLContextFakeBlackStatus, int)
50 Unknown,
51 NotNeeded,
52 Needed
53 MOZ_END_ENUM_CLASS(WebGLContextFakeBlackStatus)
55 MOZ_BEGIN_ENUM_CLASS(WebGLTextureFakeBlackStatus, int)
56 Unknown,
57 NotNeeded,
58 IncompleteTexture,
59 UninitializedImageData
60 MOZ_END_ENUM_CLASS(WebGLTextureFakeBlackStatus)
63 * Implementing WebGL (or OpenGL ES 2.0) on top of desktop OpenGL requires
64 * emulating the vertex attrib 0 array when it's not enabled. Indeed,
65 * OpenGL ES 2.0 allows drawing without vertex attrib 0 array enabled, but
66 * desktop OpenGL does not allow that.
68 MOZ_BEGIN_ENUM_CLASS(WebGLVertexAttrib0Status, int)
69 Default, // default status - no emulation needed
70 EmulatedUninitializedArray, // need an artificial attrib 0 array, but contents may be left uninitialized
71 EmulatedInitializedArray // need an artificial attrib 0 array, and contents must be initialized
72 MOZ_END_ENUM_CLASS(WebGLVertexAttrib0Status)
75 * Enum to track the status of image data (renderbuffer or texture image) presence
76 * and initialization.
78 * - NoImageData is the initial state before any image data is allocated.
79 * - InitializedImageData is the state after image data is allocated and initialized.
80 * - UninitializedImageData is an intermediate state where data is allocated but not
81 * initialized. It is the state that renderbuffers are in after a renderbufferStorage call,
82 * and it is the state that texture images are in after a texImage2D call with null data.
84 MOZ_BEGIN_ENUM_CLASS(WebGLImageDataStatus, int)
85 NoImageData,
86 UninitializedImageData,
87 InitializedImageData
88 MOZ_END_ENUM_CLASS(WebGLImageDataStatus)
91 * The formats that may participate, either as source or destination formats,
92 * in WebGL texture conversions. This includes:
93 * - all the formats accepted by WebGL.texImage2D, e.g. RGBA4444
94 * - additional formats provided by extensions, e.g. RGB32F
95 * - additional source formats, depending on browser details, used when uploading
96 * textures from DOM elements. See gfxImageSurface::Format().
98 MOZ_BEGIN_ENUM_CLASS(WebGLTexelFormat, int)
99 // returned by SurfaceFromElementResultToImageSurface to indicate absence of image data
100 None,
101 // dummy error code returned by GetWebGLTexelFormat in error cases,
102 // after assertion failure (so this never happens in debug builds)
103 BadFormat,
104 // dummy pseudo-format meaning "use the other format".
105 // For example, if SrcFormat=Auto and DstFormat=RGB8, then the source
106 // is implicitly treated as being RGB8 itself.
107 Auto,
108 // 1-channel formats
111 D16, // used for WEBGL_depth_texture extension
112 D32, // used for WEBGL_depth_texture extension
113 R32F, // used for OES_texture_float extension
114 A32F, // used for OES_texture_float extension
115 // 2-channel formats
116 RA8,
117 RA32F,
118 D24S8, // used for WEBGL_depth_texture extension
119 // 3-channel formats
120 RGB8,
121 BGRX8, // used for DOM elements. Source format only.
122 RGB565,
123 RGB32F, // used for OES_texture_float extension
124 // 4-channel formats
125 RGBA8,
126 BGRA8, // used for DOM elements
127 RGBA5551,
128 RGBA4444,
129 RGBA32F // used for OES_texture_float extension
130 MOZ_END_ENUM_CLASS(WebGLTexelFormat)
132 } // namespace mozilla
134 #endif