1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 WEBGL_CONTEXT_UTILS_H_
7 #define WEBGL_CONTEXT_UTILS_H_
8 
9 #include "WebGLStrongTypes.h"
10 #include "WebGLTypes.h"
11 
12 namespace mozilla {
13 
14 // For use with the different texture calls, i.e.
15 //   TexImage2D, CopyTex[Sub]Image2D, ...
16 // that take a "target" parameter. This parameter is not always the same as
17 // the texture binding location, like GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
18 // For example, cube maps would pass GL_TEXTURE_CUBE_MAP_[POS|NEG]_[X|Y|Z]
19 // instead of just GL_TEXTURE_CUBE_MAP.
20 //
21 // This function converts the texture image target to the texture target a.k.a.
22 // binding location. The returned binding location can be used to check that
23 // the currently bound texture is appropriate for this texImageTarget.
24 //
25 // Returns GL_NONE if passed an invalid texture image target
26 TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget);
27 
28 struct GLComponents {
29   unsigned char mComponents;
30 
31   enum Components {
32     Red = (1 << 0),
33     Green = (1 << 1),
34     Blue = (1 << 2),
35     Alpha = (1 << 3),
36     Stencil = (1 << 4),
37     Depth = (1 << 5),
38   };
39 
GLComponentsGLComponents40   GLComponents() : mComponents(0) {}
41 
42   explicit GLComponents(TexInternalFormat format);
43 
44   // Returns true iff other has all (or more) of
45   // the components present in this GLComponents
46   bool IsSubsetOf(const GLComponents& other) const;
47 };
48 
49 /**
50  * Return the displayable name for the texture function that is the
51  * source for validation.
52  */
53 const char* InfoFrom(WebGLTexImageFunc func, WebGLTexDimensions dims);
54 
55 }  // namespace mozilla
56 
57 #endif  // WEBGL_CONTEXT_UTILS_H_
58