2013-06-11 00:00:35 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef WEBGLTYPES_H_
|
|
|
|
#define WEBGLTYPES_H_
|
|
|
|
|
2013-09-04 16:14:44 +04:00
|
|
|
// Most WebIDL typedefs are identical to their OpenGL counterparts.
|
|
|
|
#include "GLTypes.h"
|
|
|
|
|
|
|
|
// Manual reflection of WebIDL typedefs that are different from their
|
|
|
|
// OpenGL counterparts.
|
2013-06-11 00:00:35 +04:00
|
|
|
typedef int64_t WebGLsizeiptr;
|
|
|
|
typedef int64_t WebGLintptr;
|
|
|
|
typedef bool WebGLboolean;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2016-07-22 09:25:41 +03:00
|
|
|
namespace gl {
|
|
|
|
class GLContext; // This is going to be needed a lot.
|
|
|
|
} // namespace gl
|
2013-06-11 00:00:35 +04:00
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
/*
|
2015-11-25 07:15:29 +03:00
|
|
|
* WebGLTextureFakeBlackStatus is an enum to track what needs to use a dummy 1x1 black
|
|
|
|
* texture, which we refer to as a 'fake black' texture.
|
2013-10-11 17:16:43 +04:00
|
|
|
*
|
2015-11-25 07:15:29 +03:00
|
|
|
* There are two things that can cause us to use such 'fake black' textures:
|
2013-10-11 17:16:43 +04:00
|
|
|
*
|
|
|
|
* (1) OpenGL ES rules on sampling incomplete textures specify that they
|
|
|
|
* must be sampled as RGBA(0, 0, 0, 1) (opaque black). We have to implement these rules
|
|
|
|
* ourselves, if only because we do not always run on OpenGL ES, and also
|
|
|
|
* because this is dangerously close to the kind of case where we don't
|
|
|
|
* want to trust the driver with corner cases of texture memory accesses.
|
|
|
|
*
|
|
|
|
* (2) OpenGL has cases where a renderbuffer, or a texture image, can contain
|
|
|
|
* uninitialized image data. See below the comment about WebGLImageDataStatus.
|
|
|
|
* WebGL must never have access to uninitialized image data. The WebGL 1 spec,
|
|
|
|
* section 4.1 'Resource Restrictions', specifies that in any such case, the
|
|
|
|
* uninitialized image data must be exposed to WebGL as if it were filled
|
|
|
|
* with zero bytes, which means it's either opaque or transparent black
|
|
|
|
* depending on whether the image format has alpha.
|
|
|
|
*/
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
enum class FakeBlackType : uint8_t {
|
|
|
|
None,
|
|
|
|
RGBA0001, // Incomplete textures and uninitialized no-alpha color textures.
|
|
|
|
RGBA0000, // Uninitialized with-alpha color textures.
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2013-06-11 00:00:35 +04:00
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
/*
|
|
|
|
* Implementing WebGL (or OpenGL ES 2.0) on top of desktop OpenGL requires
|
|
|
|
* emulating the vertex attrib 0 array when it's not enabled. Indeed,
|
|
|
|
* OpenGL ES 2.0 allows drawing without vertex attrib 0 array enabled, but
|
|
|
|
* desktop OpenGL does not allow that.
|
|
|
|
*/
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLVertexAttrib0Status : uint8_t {
|
2013-10-11 17:16:43 +04:00
|
|
|
Default, // default status - no emulation needed
|
|
|
|
EmulatedUninitializedArray, // need an artificial attrib 0 array, but contents may be left uninitialized
|
|
|
|
EmulatedInitializedArray // need an artificial attrib 0 array, and contents must be initialized
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2013-06-11 00:00:35 +04:00
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
/*
|
|
|
|
* Enum to track the status of image data (renderbuffer or texture image) presence
|
|
|
|
* and initialization.
|
|
|
|
*
|
|
|
|
* - NoImageData is the initial state before any image data is allocated.
|
|
|
|
* - InitializedImageData is the state after image data is allocated and initialized.
|
|
|
|
* - UninitializedImageData is an intermediate state where data is allocated but not
|
|
|
|
* initialized. It is the state that renderbuffers are in after a renderbufferStorage call,
|
|
|
|
* and it is the state that texture images are in after a texImage2D call with null data.
|
|
|
|
*/
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLImageDataStatus : uint8_t {
|
2013-10-11 17:16:43 +04:00
|
|
|
NoImageData,
|
|
|
|
UninitializedImageData,
|
|
|
|
InitializedImageData
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2013-10-11 17:16:43 +04:00
|
|
|
|
2013-06-11 00:00:35 +04:00
|
|
|
/*
|
|
|
|
* The formats that may participate, either as source or destination formats,
|
|
|
|
* in WebGL texture conversions. This includes:
|
|
|
|
* - all the formats accepted by WebGL.texImage2D, e.g. RGBA4444
|
|
|
|
* - additional formats provided by extensions, e.g. RGB32F
|
|
|
|
* - additional source formats, depending on browser details, used when uploading
|
|
|
|
* textures from DOM elements. See gfxImageSurface::Format().
|
|
|
|
*/
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLTexelFormat : uint8_t {
|
2013-11-24 06:20:48 +04:00
|
|
|
// returned by SurfaceFromElementResultToImageSurface to indicate absence of image data
|
|
|
|
None,
|
2014-10-10 00:07:07 +04:00
|
|
|
// common value for formats for which format conversions are not supported
|
|
|
|
FormatNotSupportingAnyConversion,
|
2013-06-11 00:00:35 +04:00
|
|
|
// dummy pseudo-format meaning "use the other format".
|
|
|
|
// For example, if SrcFormat=Auto and DstFormat=RGB8, then the source
|
|
|
|
// is implicitly treated as being RGB8 itself.
|
|
|
|
Auto,
|
|
|
|
// 1-channel formats
|
|
|
|
A8,
|
2014-01-24 01:47:37 +04:00
|
|
|
A16F, // OES_texture_half_float
|
|
|
|
A32F, // OES_texture_float
|
2015-12-22 21:59:00 +03:00
|
|
|
R8,
|
|
|
|
R16F, // OES_texture_half_float
|
|
|
|
R32F, // OES_texture_float
|
2013-06-11 00:00:35 +04:00
|
|
|
// 2-channel formats
|
|
|
|
RA8,
|
2014-01-24 01:47:37 +04:00
|
|
|
RA16F, // OES_texture_half_float
|
|
|
|
RA32F, // OES_texture_float
|
2015-12-22 23:56:00 +03:00
|
|
|
RG8,
|
2015-12-22 23:57:00 +03:00
|
|
|
RG16F,
|
2015-12-23 00:01:00 +03:00
|
|
|
RG32F,
|
2013-06-11 00:00:35 +04:00
|
|
|
// 3-channel formats
|
|
|
|
RGB8,
|
|
|
|
RGB565,
|
2015-12-23 00:02:00 +03:00
|
|
|
RGB11F11F10F,
|
2014-01-24 01:47:37 +04:00
|
|
|
RGB16F, // OES_texture_half_float
|
|
|
|
RGB32F, // OES_texture_float
|
2013-06-11 00:00:35 +04:00
|
|
|
// 4-channel formats
|
|
|
|
RGBA8,
|
|
|
|
RGBA5551,
|
|
|
|
RGBA4444,
|
2014-01-24 01:47:37 +04:00
|
|
|
RGBA16F, // OES_texture_half_float
|
2015-12-22 21:59:00 +03:00
|
|
|
RGBA32F, // OES_texture_float
|
|
|
|
// DOM element source only formats.
|
|
|
|
RGBX8,
|
|
|
|
BGRX8,
|
|
|
|
BGRA8
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2013-06-11 00:00:35 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLTexImageFunc : uint8_t {
|
2014-02-21 05:20:28 +04:00
|
|
|
TexImage,
|
|
|
|
TexSubImage,
|
|
|
|
CopyTexImage,
|
|
|
|
CopyTexSubImage,
|
|
|
|
CompTexImage,
|
|
|
|
CompTexSubImage,
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-02-21 05:20:28 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLTexDimensions : uint8_t {
|
2014-10-14 03:42:15 +04:00
|
|
|
Tex2D,
|
|
|
|
Tex3D
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-10-14 03:42:15 +04:00
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
// Please keep extensions in alphabetic order.
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLExtensionID : uint8_t {
|
2014-04-26 06:34:07 +04:00
|
|
|
ANGLE_instanced_arrays,
|
2014-06-14 20:07:53 +04:00
|
|
|
EXT_blend_minmax,
|
2016-05-05 02:39:02 +03:00
|
|
|
EXT_color_buffer_float,
|
2014-04-26 06:34:07 +04:00
|
|
|
EXT_color_buffer_half_float,
|
|
|
|
EXT_frag_depth,
|
|
|
|
EXT_sRGB,
|
2014-07-24 19:58:43 +04:00
|
|
|
EXT_shader_texture_lod,
|
2014-04-26 06:34:07 +04:00
|
|
|
EXT_texture_filter_anisotropic,
|
2015-05-27 14:12:00 +03:00
|
|
|
EXT_disjoint_timer_query,
|
2017-04-11 11:50:59 +03:00
|
|
|
MOZ_debug,
|
2014-04-26 06:34:07 +04:00
|
|
|
OES_element_index_uint,
|
|
|
|
OES_standard_derivatives,
|
|
|
|
OES_texture_float,
|
|
|
|
OES_texture_float_linear,
|
|
|
|
OES_texture_half_float,
|
|
|
|
OES_texture_half_float_linear,
|
|
|
|
OES_vertex_array_object,
|
|
|
|
WEBGL_color_buffer_float,
|
2016-11-23 05:59:35 +03:00
|
|
|
WEBGL_compressed_texture_astc,
|
2014-04-26 06:34:07 +04:00
|
|
|
WEBGL_compressed_texture_atc,
|
2016-11-11 03:37:03 +03:00
|
|
|
WEBGL_compressed_texture_etc,
|
2014-04-26 06:34:07 +04:00
|
|
|
WEBGL_compressed_texture_etc1,
|
|
|
|
WEBGL_compressed_texture_pvrtc,
|
|
|
|
WEBGL_compressed_texture_s3tc,
|
2017-05-30 18:21:33 +03:00
|
|
|
WEBGL_compressed_texture_s3tc_srgb,
|
2014-04-26 06:34:07 +04:00
|
|
|
WEBGL_debug_renderer_info,
|
|
|
|
WEBGL_debug_shaders,
|
|
|
|
WEBGL_depth_texture,
|
|
|
|
WEBGL_draw_buffers,
|
|
|
|
WEBGL_lose_context,
|
|
|
|
Max,
|
|
|
|
Unknown
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-04-26 06:34:07 +04:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
class UniqueBuffer
|
|
|
|
{
|
|
|
|
// Like UniquePtr<>, but for void* and malloc/calloc/free.
|
|
|
|
void* mBuffer;
|
|
|
|
|
|
|
|
public:
|
|
|
|
UniqueBuffer()
|
|
|
|
: mBuffer(nullptr)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
MOZ_IMPLICIT UniqueBuffer(void* buffer)
|
|
|
|
: mBuffer(buffer)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~UniqueBuffer() {
|
|
|
|
free(mBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
UniqueBuffer(UniqueBuffer&& other) {
|
|
|
|
this->mBuffer = other.mBuffer;
|
|
|
|
other.mBuffer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniqueBuffer& operator =(UniqueBuffer&& other) {
|
|
|
|
free(this->mBuffer);
|
|
|
|
this->mBuffer = other.mBuffer;
|
|
|
|
other.mBuffer = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniqueBuffer& operator =(void* newBuffer) {
|
|
|
|
free(this->mBuffer);
|
|
|
|
this->mBuffer = newBuffer;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit operator bool() const { return bool(mBuffer); }
|
|
|
|
|
|
|
|
void* get() const { return mBuffer; }
|
|
|
|
|
|
|
|
UniqueBuffer(const UniqueBuffer& other) = delete; // construct using Move()!
|
|
|
|
void operator =(const UniqueBuffer& other) = delete; // assign using Move()!
|
|
|
|
};
|
|
|
|
|
2013-06-11 00:00:35 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|