content/canvas/src/WebGLTypes.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/WebGLTypes.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,176 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef WEBGLTYPES_H_
    1.10 +#define WEBGLTYPES_H_
    1.11 +
    1.12 +#include "mozilla/TypedEnum.h"
    1.13 +
    1.14 +// Most WebIDL typedefs are identical to their OpenGL counterparts.
    1.15 +#include "GLTypes.h"
    1.16 +
    1.17 +// Manual reflection of WebIDL typedefs that are different from their
    1.18 +// OpenGL counterparts.
    1.19 +typedef int64_t WebGLsizeiptr;
    1.20 +typedef int64_t WebGLintptr;
    1.21 +typedef bool WebGLboolean;
    1.22 +
    1.23 +namespace mozilla {
    1.24 +
    1.25 +/*
    1.26 + * WebGLContextFakeBlackStatus and WebGLTextureFakeBlackStatus are enums to
    1.27 + * track what needs to use a dummy 1x1 black texture, which we refer to as a
    1.28 + * 'fake black' texture.
    1.29 + *
    1.30 + * There are generally two things that can cause us to use such 'fake black'
    1.31 + * textures:
    1.32 + *
    1.33 + *   (1) OpenGL ES rules on sampling incomplete textures specify that they
    1.34 + *       must be sampled as RGBA(0, 0, 0, 1) (opaque black). We have to implement these rules
    1.35 + *       ourselves, if only because we do not always run on OpenGL ES, and also
    1.36 + *       because this is dangerously close to the kind of case where we don't
    1.37 + *       want to trust the driver with corner cases of texture memory accesses.
    1.38 + *
    1.39 + *   (2) OpenGL has cases where a renderbuffer, or a texture image, can contain
    1.40 + *       uninitialized image data. See below the comment about WebGLImageDataStatus.
    1.41 + *       WebGL must never have access to uninitialized image data. The WebGL 1 spec,
    1.42 + *       section 4.1 'Resource Restrictions', specifies that in any such case, the
    1.43 + *       uninitialized image data must be exposed to WebGL as if it were filled
    1.44 + *       with zero bytes, which means it's either opaque or transparent black
    1.45 + *       depending on whether the image format has alpha.
    1.46 + *
    1.47 + * Why are there _two_ separate enums there, WebGLContextFakeBlackStatus
    1.48 + * and WebGLTextureFakeBlackStatus? That's because each texture must know the precise
    1.49 + * reason why it needs to be faked (incomplete texture vs. uninitialized image data),
    1.50 + * whereas the WebGL context can only know whether _any_ faking is currently needed at all.
    1.51 + */
    1.52 +MOZ_BEGIN_ENUM_CLASS(WebGLContextFakeBlackStatus, int)
    1.53 +  Unknown,
    1.54 +  NotNeeded,
    1.55 +  Needed
    1.56 +MOZ_END_ENUM_CLASS(WebGLContextFakeBlackStatus)
    1.57 +
    1.58 +MOZ_BEGIN_ENUM_CLASS(WebGLTextureFakeBlackStatus, int)
    1.59 +  Unknown,
    1.60 +  NotNeeded,
    1.61 +  IncompleteTexture,
    1.62 +  UninitializedImageData
    1.63 +MOZ_END_ENUM_CLASS(WebGLTextureFakeBlackStatus)
    1.64 +
    1.65 +/*
    1.66 + * Implementing WebGL (or OpenGL ES 2.0) on top of desktop OpenGL requires
    1.67 + * emulating the vertex attrib 0 array when it's not enabled. Indeed,
    1.68 + * OpenGL ES 2.0 allows drawing without vertex attrib 0 array enabled, but
    1.69 + * desktop OpenGL does not allow that.
    1.70 + */
    1.71 +MOZ_BEGIN_ENUM_CLASS(WebGLVertexAttrib0Status, int)
    1.72 +    Default, // default status - no emulation needed
    1.73 +    EmulatedUninitializedArray, // need an artificial attrib 0 array, but contents may be left uninitialized
    1.74 +    EmulatedInitializedArray // need an artificial attrib 0 array, and contents must be initialized
    1.75 +MOZ_END_ENUM_CLASS(WebGLVertexAttrib0Status)
    1.76 +
    1.77 +/*
    1.78 + * Enum to track the status of image data (renderbuffer or texture image) presence
    1.79 + * and initialization.
    1.80 + *
    1.81 + * - NoImageData is the initial state before any image data is allocated.
    1.82 + * - InitializedImageData is the state after image data is allocated and initialized.
    1.83 + * - UninitializedImageData is an intermediate state where data is allocated but not
    1.84 + *   initialized. It is the state that renderbuffers are in after a renderbufferStorage call,
    1.85 + *   and it is the state that texture images are in after a texImage2D call with null data.
    1.86 + */
    1.87 +MOZ_BEGIN_ENUM_CLASS(WebGLImageDataStatus, int)
    1.88 +    NoImageData,
    1.89 +    UninitializedImageData,
    1.90 +    InitializedImageData
    1.91 +MOZ_END_ENUM_CLASS(WebGLImageDataStatus)
    1.92 +
    1.93 +/*
    1.94 + * The formats that may participate, either as source or destination formats,
    1.95 + * in WebGL texture conversions. This includes:
    1.96 + *  - all the formats accepted by WebGL.texImage2D, e.g. RGBA4444
    1.97 + *  - additional formats provided by extensions, e.g. RGB32F
    1.98 + *  - additional source formats, depending on browser details, used when uploading
    1.99 + *    textures from DOM elements. See gfxImageSurface::Format().
   1.100 + */
   1.101 +MOZ_BEGIN_ENUM_CLASS(WebGLTexelFormat, int)
   1.102 +    // returned by SurfaceFromElementResultToImageSurface to indicate absence of image data
   1.103 +    None,
   1.104 +    // dummy error code returned by GetWebGLTexelFormat in error cases,
   1.105 +    // after assertion failure (so this never happens in debug builds)
   1.106 +    BadFormat,
   1.107 +    // dummy pseudo-format meaning "use the other format".
   1.108 +    // For example, if SrcFormat=Auto and DstFormat=RGB8, then the source
   1.109 +    // is implicitly treated as being RGB8 itself.
   1.110 +    Auto,
   1.111 +    // 1-channel formats
   1.112 +    R8,
   1.113 +    A8,
   1.114 +    D16, // WEBGL_depth_texture
   1.115 +    D32, // WEBGL_depth_texture
   1.116 +    R16F, // OES_texture_half_float
   1.117 +    A16F, // OES_texture_half_float
   1.118 +    R32F, // OES_texture_float
   1.119 +    A32F, // OES_texture_float
   1.120 +    // 2-channel formats
   1.121 +    RA8,
   1.122 +    RA16F, // OES_texture_half_float
   1.123 +    RA32F, // OES_texture_float
   1.124 +    D24S8, // WEBGL_depth_texture
   1.125 +    // 3-channel formats
   1.126 +    RGB8,
   1.127 +    BGRX8, // used for DOM elements. Source format only.
   1.128 +    RGB565,
   1.129 +    RGB16F, // OES_texture_half_float
   1.130 +    RGB32F, // OES_texture_float
   1.131 +    // 4-channel formats
   1.132 +    RGBA8,
   1.133 +    BGRA8, // used for DOM elements
   1.134 +    RGBA5551,
   1.135 +    RGBA4444,
   1.136 +    RGBA16F, // OES_texture_half_float
   1.137 +    RGBA32F // OES_texture_float
   1.138 +MOZ_END_ENUM_CLASS(WebGLTexelFormat)
   1.139 +
   1.140 +MOZ_BEGIN_ENUM_CLASS(WebGLTexImageFunc, int)
   1.141 +    TexImage,
   1.142 +    TexSubImage,
   1.143 +    CopyTexImage,
   1.144 +    CopyTexSubImage,
   1.145 +    CompTexImage,
   1.146 +    CompTexSubImage,
   1.147 +MOZ_END_ENUM_CLASS(WebGLTexImageFunc)
   1.148 +
   1.149 +// Please keep extensions in alphabetic order.
   1.150 +MOZ_BEGIN_ENUM_CLASS(WebGLExtensionID, uint8_t)
   1.151 +    ANGLE_instanced_arrays,
   1.152 +    EXT_color_buffer_half_float,
   1.153 +    EXT_frag_depth,
   1.154 +    EXT_sRGB,
   1.155 +    EXT_texture_filter_anisotropic,
   1.156 +    OES_element_index_uint,
   1.157 +    OES_standard_derivatives,
   1.158 +    OES_texture_float,
   1.159 +    OES_texture_float_linear,
   1.160 +    OES_texture_half_float,
   1.161 +    OES_texture_half_float_linear,
   1.162 +    OES_vertex_array_object,
   1.163 +    WEBGL_color_buffer_float,
   1.164 +    WEBGL_compressed_texture_atc,
   1.165 +    WEBGL_compressed_texture_etc1,
   1.166 +    WEBGL_compressed_texture_pvrtc,
   1.167 +    WEBGL_compressed_texture_s3tc,
   1.168 +    WEBGL_debug_renderer_info,
   1.169 +    WEBGL_debug_shaders,
   1.170 +    WEBGL_depth_texture,
   1.171 +    WEBGL_draw_buffers,
   1.172 +    WEBGL_lose_context,
   1.173 +    Max,
   1.174 +    Unknown
   1.175 +MOZ_END_ENUM_CLASS(WebGLExtensionID)
   1.176 +
   1.177 +} // namespace mozilla
   1.178 +
   1.179 +#endif

mercurial