content/canvas/src/WebGLTypes.h

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:2eaef29871f1
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/. */
5
6 #ifndef WEBGLTYPES_H_
7 #define WEBGLTYPES_H_
8
9 #include "mozilla/TypedEnum.h"
10
11 // Most WebIDL typedefs are identical to their OpenGL counterparts.
12 #include "GLTypes.h"
13
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;
19
20 namespace mozilla {
21
22 /*
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.
26 *
27 * There are generally two things that can cause us to use such 'fake black'
28 * textures:
29 *
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.
35 *
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.
43 *
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.
48 */
49 MOZ_BEGIN_ENUM_CLASS(WebGLContextFakeBlackStatus, int)
50 Unknown,
51 NotNeeded,
52 Needed
53 MOZ_END_ENUM_CLASS(WebGLContextFakeBlackStatus)
54
55 MOZ_BEGIN_ENUM_CLASS(WebGLTextureFakeBlackStatus, int)
56 Unknown,
57 NotNeeded,
58 IncompleteTexture,
59 UninitializedImageData
60 MOZ_END_ENUM_CLASS(WebGLTextureFakeBlackStatus)
61
62 /*
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.
67 */
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)
73
74 /*
75 * Enum to track the status of image data (renderbuffer or texture image) presence
76 * and initialization.
77 *
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.
83 */
84 MOZ_BEGIN_ENUM_CLASS(WebGLImageDataStatus, int)
85 NoImageData,
86 UninitializedImageData,
87 InitializedImageData
88 MOZ_END_ENUM_CLASS(WebGLImageDataStatus)
89
90 /*
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().
97 */
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
109 R8,
110 A8,
111 D16, // WEBGL_depth_texture
112 D32, // WEBGL_depth_texture
113 R16F, // OES_texture_half_float
114 A16F, // OES_texture_half_float
115 R32F, // OES_texture_float
116 A32F, // OES_texture_float
117 // 2-channel formats
118 RA8,
119 RA16F, // OES_texture_half_float
120 RA32F, // OES_texture_float
121 D24S8, // WEBGL_depth_texture
122 // 3-channel formats
123 RGB8,
124 BGRX8, // used for DOM elements. Source format only.
125 RGB565,
126 RGB16F, // OES_texture_half_float
127 RGB32F, // OES_texture_float
128 // 4-channel formats
129 RGBA8,
130 BGRA8, // used for DOM elements
131 RGBA5551,
132 RGBA4444,
133 RGBA16F, // OES_texture_half_float
134 RGBA32F // OES_texture_float
135 MOZ_END_ENUM_CLASS(WebGLTexelFormat)
136
137 MOZ_BEGIN_ENUM_CLASS(WebGLTexImageFunc, int)
138 TexImage,
139 TexSubImage,
140 CopyTexImage,
141 CopyTexSubImage,
142 CompTexImage,
143 CompTexSubImage,
144 MOZ_END_ENUM_CLASS(WebGLTexImageFunc)
145
146 // Please keep extensions in alphabetic order.
147 MOZ_BEGIN_ENUM_CLASS(WebGLExtensionID, uint8_t)
148 ANGLE_instanced_arrays,
149 EXT_color_buffer_half_float,
150 EXT_frag_depth,
151 EXT_sRGB,
152 EXT_texture_filter_anisotropic,
153 OES_element_index_uint,
154 OES_standard_derivatives,
155 OES_texture_float,
156 OES_texture_float_linear,
157 OES_texture_half_float,
158 OES_texture_half_float_linear,
159 OES_vertex_array_object,
160 WEBGL_color_buffer_float,
161 WEBGL_compressed_texture_atc,
162 WEBGL_compressed_texture_etc1,
163 WEBGL_compressed_texture_pvrtc,
164 WEBGL_compressed_texture_s3tc,
165 WEBGL_debug_renderer_info,
166 WEBGL_debug_shaders,
167 WEBGL_depth_texture,
168 WEBGL_draw_buffers,
169 WEBGL_lose_context,
170 Max,
171 Unknown
172 MOZ_END_ENUM_CLASS(WebGLExtensionID)
173
174 } // namespace mozilla
175
176 #endif

mercurial