2012-10-05 00:35:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; 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/. */
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
#ifndef WEBGL_CONTEXT_UTILS_H_
|
|
|
|
#define WEBGL_CONTEXT_UTILS_H_
|
2012-10-05 00:35:54 +04:00
|
|
|
|
|
|
|
#include "WebGLContext.h"
|
2014-09-19 03:14:22 +04:00
|
|
|
#include "WebGLStrongTypes.h"
|
2012-10-05 00:35:54 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-09-23 21:48:27 +04:00
|
|
|
bool IsGLDepthFormat(TexInternalFormat webGLFormat);
|
|
|
|
bool IsGLDepthStencilFormat(TexInternalFormat webGLFormat);
|
|
|
|
bool FormatHasAlpha(TexInternalFormat webGLFormat);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2014-10-08 03:52:58 +04:00
|
|
|
void
|
|
|
|
DriverFormatsFromEffectiveInternalFormat(gl::GLContext* gl,
|
|
|
|
TexInternalFormat internalformat,
|
2014-11-14 07:03:50 +03:00
|
|
|
GLenum* const out_driverInternalFormat,
|
|
|
|
GLenum* const out_driverFormat,
|
|
|
|
GLenum* const out_driverType);
|
2014-10-08 03:52:58 +04:00
|
|
|
TexInternalFormat
|
|
|
|
EffectiveInternalFormatFromInternalFormatAndType(TexInternalFormat internalformat,
|
|
|
|
TexType type);
|
|
|
|
TexInternalFormat
|
|
|
|
EffectiveInternalFormatFromUnsizedInternalFormatAndType(TexInternalFormat internalformat,
|
|
|
|
TexType type);
|
|
|
|
void
|
|
|
|
UnsizedInternalFormatAndTypeFromEffectiveInternalFormat(TexInternalFormat effectiveinternalformat,
|
2014-11-14 07:03:50 +03:00
|
|
|
TexInternalFormat* const out_internalformat,
|
|
|
|
TexType* const out_type);
|
|
|
|
TexType TypeFromInternalFormat(TexInternalFormat internalformat);
|
|
|
|
|
2014-10-08 03:52:58 +04:00
|
|
|
TexInternalFormat
|
|
|
|
UnsizedInternalFormatFromInternalFormat(TexInternalFormat internalformat);
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2015-01-29 08:29:45 +03:00
|
|
|
void SetLegacyTextureSwizzle(gl::GLContext* gl, GLenum target, GLenum internalformat);
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
size_t GetBitsPerTexel(TexInternalFormat effectiveinternalformat);
|
2014-01-24 07:53:53 +04:00
|
|
|
|
2014-09-03 23:17:18 +04:00
|
|
|
// For use with the different texture calls, i.e.
|
|
|
|
// TexImage2D, CopyTex[Sub]Image2D, ...
|
|
|
|
// that take a "target" parameter. This parameter is not always the same as
|
|
|
|
// the texture binding location, like GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
|
|
|
|
// For example, cube maps would pass GL_TEXTURE_CUBE_MAP_[POS|NEG]_[X|Y|Z]
|
|
|
|
// instead of just GL_TEXTURE_CUBE_MAP.
|
|
|
|
//
|
|
|
|
// This function converts the texture image target to the texture target a.k.a.
|
|
|
|
// binding location. The returned binding location can be used to check that
|
|
|
|
// the currently bound texture is appropriate for this texImageTarget.
|
|
|
|
//
|
|
|
|
// Returns GL_NONE if passed an invalid texture image target
|
2014-09-19 03:14:22 +04:00
|
|
|
TexTarget TexImageTargetToTexTarget(TexImageTarget texImageTarget);
|
2014-09-03 23:17:18 +04:00
|
|
|
|
2015-06-05 06:26:34 +03:00
|
|
|
// Helper function to create a JS::Value from a C string
|
|
|
|
JS::Value StringValue(JSContext* cx, const char* str, ErrorResult& rv);
|
|
|
|
|
2014-08-21 00:38:42 +04:00
|
|
|
struct GLComponents
|
|
|
|
{
|
|
|
|
unsigned char mComponents;
|
|
|
|
|
|
|
|
enum Components {
|
|
|
|
Red = (1 << 0),
|
|
|
|
Green = (1 << 1),
|
|
|
|
Blue = (1 << 2),
|
|
|
|
Alpha = (1 << 3),
|
|
|
|
Stencil = (1 << 4),
|
|
|
|
Depth = (1 << 5),
|
|
|
|
};
|
|
|
|
|
|
|
|
GLComponents()
|
|
|
|
: mComponents(0)
|
2014-11-14 07:03:50 +03:00
|
|
|
{}
|
2014-08-21 00:38:42 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
explicit GLComponents(TexInternalFormat format);
|
2014-08-21 00:38:42 +04:00
|
|
|
|
|
|
|
// Returns true iff other has all (or more) of
|
|
|
|
// the components present in this GLComponents
|
|
|
|
bool IsSubsetOf(const GLComponents& other) const;
|
|
|
|
};
|
|
|
|
|
2012-10-05 00:35:54 +04:00
|
|
|
template <typename WebGLObjectType>
|
|
|
|
JS::Value
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::WebGLObjectAsJSValue(JSContext* cx, const WebGLObjectType* object,
|
|
|
|
ErrorResult& rv) const
|
2012-10-05 00:35:54 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
if (!object)
|
2012-10-05 00:35:54 +04:00
|
|
|
return JS::NullValue();
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2012-10-05 00:35:54 +04:00
|
|
|
MOZ_ASSERT(this == object->Context());
|
2013-04-25 20:29:53 +04:00
|
|
|
JS::Rooted<JS::Value> v(cx);
|
|
|
|
JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
|
2012-10-05 00:35:54 +04:00
|
|
|
JSAutoCompartment ac(cx, wrapper);
|
2014-11-14 07:03:50 +03:00
|
|
|
if (!dom::GetOrCreateDOMReflector(cx, const_cast<WebGLObjectType*>(object), &v)) {
|
2012-10-05 00:35:54 +04:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename WebGLObjectType>
|
|
|
|
JSObject*
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::WebGLObjectAsJSObject(JSContext* cx,
|
|
|
|
const WebGLObjectType* object,
|
|
|
|
ErrorResult& rv) const
|
2012-10-05 00:35:54 +04:00
|
|
|
{
|
|
|
|
JS::Value v = WebGLObjectAsJSValue(cx, object, rv);
|
2014-11-14 07:03:50 +03:00
|
|
|
if (v.isNull())
|
2012-10-05 00:35:54 +04:00
|
|
|
return nullptr;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2012-10-05 00:35:54 +04:00
|
|
|
return &v.toObject();
|
|
|
|
}
|
|
|
|
|
2014-10-14 03:42:15 +04:00
|
|
|
/**
|
|
|
|
* Return the displayable name for the texture function that is the
|
|
|
|
* source for validation.
|
|
|
|
*/
|
2014-11-14 07:03:50 +03:00
|
|
|
const char* InfoFrom(WebGLTexImageFunc func, WebGLTexDimensions dims);
|
2014-10-14 03:42:15 +04:00
|
|
|
|
2012-10-05 00:35:54 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
#endif // WEBGL_CONTEXT_UTILS_H_
|