2013-08-02 14:30:58 -07: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/. */
|
|
|
|
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
|
|
|
const size_t kMAX_EXTENSION_GROUP_SIZE = 5;
|
|
|
|
|
2013-08-15 12:58:20 -07:00
|
|
|
// ARB_ES2_compatibility is natively supported in OpenGL 4.1.
|
|
|
|
static const unsigned int kGLCoreVersionForES2Compat = 410;
|
|
|
|
|
|
|
|
// ARB_ES3_compatibility is natively supported in OpenGL 4.3.
|
|
|
|
static const unsigned int kGLCoreVersionForES3Compat = 430;
|
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
struct FeatureInfo
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
|
|
|
const char* mName;
|
|
|
|
unsigned int mOpenGLVersion;
|
|
|
|
unsigned int mOpenGLESVersion;
|
|
|
|
GLContext::GLExtensions mExtensions[kMAX_EXTENSION_GROUP_SIZE];
|
|
|
|
};
|
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
static const FeatureInfo sFeatureInfoArr[] = {
|
2013-08-20 08:36:20 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"bind_buffer_offset",
|
2013-08-20 08:36:20 -07:00
|
|
|
0, // OpenGL version
|
|
|
|
0, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::EXT_transform_feedback,
|
|
|
|
GLContext::NV_transform_feedback,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-26 14:12:54 -07:00
|
|
|
{
|
|
|
|
"blend_minmax",
|
|
|
|
200, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::EXT_blend_minmax,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-15 12:58:20 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"depth_texture",
|
2013-08-15 12:58:20 -07:00
|
|
|
200, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_depth_texture,
|
|
|
|
GLContext::OES_depth_texture,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"draw_buffers",
|
2013-08-02 14:30:58 -07:00
|
|
|
200, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_draw_buffers,
|
|
|
|
GLContext::EXT_draw_buffers,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"draw_instanced",
|
2013-08-02 14:30:58 -07:00
|
|
|
310, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_draw_instanced,
|
|
|
|
GLContext::EXT_draw_instanced,
|
|
|
|
GLContext::NV_draw_instanced,
|
2013-08-06 17:05:51 -07:00
|
|
|
GLContext::ANGLE_instanced_arrays,
|
2013-08-02 14:30:58 -07:00
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-15 12:58:20 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"element_index_uint",
|
2013-08-15 12:58:20 -07:00
|
|
|
200, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::OES_element_index_uint,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"ES2_compatibility",
|
2013-08-15 12:58:20 -07:00
|
|
|
kGLCoreVersionForES2Compat,
|
|
|
|
200, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_ES2_compatibility,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"ES3_compatibility",
|
2013-08-15 12:58:20 -07:00
|
|
|
kGLCoreVersionForES3Compat,
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_ES3_compatibility,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"framebuffer_blit",
|
2013-08-02 14:30:58 -07:00
|
|
|
300, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::EXT_framebuffer_blit,
|
|
|
|
GLContext::ANGLE_framebuffer_blit,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"framebuffer_multisample",
|
2013-08-02 14:30:58 -07:00
|
|
|
300, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::EXT_framebuffer_multisample,
|
|
|
|
GLContext::ANGLE_framebuffer_multisample,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"framebuffer_object",
|
2013-08-02 14:30:58 -07:00
|
|
|
300, // OpenGL version
|
|
|
|
200, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_framebuffer_object,
|
|
|
|
GLContext::EXT_framebuffer_object,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-15 12:58:20 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"get_query_object_iv",
|
2013-08-15 12:58:20 -07:00
|
|
|
200, // OpenGL version
|
|
|
|
0, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX_get_query_object_iv only provide GetQueryObjectiv provided by
|
|
|
|
* ARB_occlusion_query (added by OpenGL 2.0).
|
|
|
|
*/
|
|
|
|
},
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"instanced_arrays",
|
2013-08-06 17:05:51 -07:00
|
|
|
330, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_instanced_arrays,
|
|
|
|
GLContext::NV_instanced_arrays,
|
|
|
|
GLContext::ANGLE_instanced_arrays,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-15 12:58:20 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"occlusion_query",
|
2013-08-15 12:58:20 -07:00
|
|
|
200, // OpenGL version
|
|
|
|
0, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
// XXX_occlusion_query depend on ARB_occlusion_query (added in OpenGL 2.0)
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"occlusion_query_boolean",
|
2013-08-15 12:58:20 -07:00
|
|
|
kGLCoreVersionForES3Compat,
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_ES3_compatibility,
|
|
|
|
GLContext::EXT_occlusion_query_boolean,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX_occlusion_query_boolean provide ANY_SAMPLES_PASSED_CONSERVATIVE,
|
|
|
|
* but EXT_occlusion_query_boolean is only a OpenGL ES extension. But
|
|
|
|
* it is supported on desktop if ARB_ES3_compatibility because
|
|
|
|
* EXT_occlusion_query_boolean (added in OpenGL ES 3.0).
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"occlusion_query2",
|
2013-08-15 12:58:20 -07:00
|
|
|
330, // = min(330, kGLCoreVersionForES3Compat),
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_occlusion_query2,
|
|
|
|
GLContext::ARB_ES3_compatibility,
|
|
|
|
GLContext::EXT_occlusion_query_boolean,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX_occlusion_query2 (add in OpenGL 3.3) provide ANY_SAMPLES_PASSED,
|
|
|
|
* which is provided by ARB_occlusion_query2, EXT_occlusion_query_boolean
|
|
|
|
* (added in OpenGL ES 3.0) and ARB_ES3_compatibility
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"packed_depth_stencil",
|
2013-08-15 12:58:20 -07:00
|
|
|
300, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::EXT_packed_depth_stencil,
|
|
|
|
GLContext::OES_packed_depth_stencil,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"query_objects",
|
2013-08-15 12:58:20 -07:00
|
|
|
200, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::EXT_occlusion_query_boolean,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX_query_objects only provide entry points commonly supported by
|
|
|
|
* ARB_occlusion_query (added in OpenGL 2.0) and EXT_occlusion_query_boolean
|
|
|
|
* (added in OpenGL ES 3.0)
|
|
|
|
*/
|
|
|
|
},
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"robustness",
|
2013-08-02 14:30:58 -07:00
|
|
|
0, // OpenGL version
|
|
|
|
0, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_robustness,
|
|
|
|
GLContext::EXT_robustness,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-15 12:58:20 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"standard_derivatives",
|
2013-08-15 12:58:20 -07:00
|
|
|
200, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::OES_standard_derivatives,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"texture_float",
|
2013-08-02 14:30:58 -07:00
|
|
|
310, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_texture_float,
|
|
|
|
GLContext::OES_texture_float,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-15 12:58:20 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"texture_float_linear",
|
2013-08-15 12:58:20 -07:00
|
|
|
310, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_texture_float,
|
|
|
|
GLContext::OES_texture_float_linear,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"texture_non_power_of_two",
|
2013-08-02 14:30:58 -07:00
|
|
|
200, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_texture_non_power_of_two,
|
|
|
|
GLContext::OES_texture_npot,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-15 17:43:47 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"transform_feedback",
|
2013-08-15 17:43:47 -07:00
|
|
|
300, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::EXT_transform_feedback,
|
|
|
|
GLContext::NV_transform_feedback,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
},
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:05 -07:00
|
|
|
"vertex_array_object",
|
2013-08-02 14:30:58 -07:00
|
|
|
300, // OpenGL version
|
|
|
|
300, // OpenGL ES version
|
|
|
|
{
|
|
|
|
GLContext::ARB_vertex_array_object,
|
|
|
|
GLContext::OES_vertex_array_object,
|
|
|
|
GLContext::APPLE_vertex_array_object,
|
|
|
|
GLContext::Extensions_End
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
static inline const FeatureInfo&
|
|
|
|
GetFeatureInfo(GLFeature::Enum feature)
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:04 -07:00
|
|
|
static_assert(MOZ_ARRAY_LENGTH(sFeatureInfoArr) == size_t(GLFeature::EnumMax),
|
|
|
|
"Mismatched lengths for sFeatureInfoInfos and GLFeature enums");
|
2013-08-02 14:30:58 -07:00
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
MOZ_ASSERT(feature < GLFeature::EnumMax,
|
|
|
|
"GLContext::GetFeatureInfoInfo : unknown <feature>");
|
2013-08-02 14:30:58 -07:00
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
return sFeatureInfoArr[feature];
|
2013-08-02 14:30:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t
|
2013-08-22 10:42:04 -07:00
|
|
|
ProfileVersionForFeature(GLFeature::Enum feature, ContextProfile profile)
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(profile != ContextProfile::Unknown,
|
2013-08-22 10:42:04 -07:00
|
|
|
"GLContext::ProfileVersionForFeature : unknown <profile>");
|
2013-08-02 14:30:58 -07:00
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
const FeatureInfo& featureInfo = GetFeatureInfo(feature);
|
2013-08-02 14:30:58 -07:00
|
|
|
|
|
|
|
if (profile == ContextProfile::OpenGLES) {
|
2013-08-22 10:42:04 -07:00
|
|
|
return featureInfo.mOpenGLESVersion;
|
2013-08-02 14:30:58 -07:00
|
|
|
}
|
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
return featureInfo.mOpenGLVersion;
|
2013-08-02 14:30:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2013-08-22 10:42:04 -07:00
|
|
|
IsFeatureIsPartOfProfileVersion(GLFeature::Enum feature,
|
|
|
|
ContextProfile profile, unsigned int version)
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:04 -07:00
|
|
|
unsigned int profileVersion = ProfileVersionForFeature(feature, profile);
|
2013-08-02 14:30:58 -07:00
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
/**
|
|
|
|
* if `profileVersion` is zero, it means that no version of the profile
|
|
|
|
* added support for the feature.
|
|
|
|
*/
|
2013-08-02 14:30:58 -07:00
|
|
|
return profileVersion && version >= profileVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
2013-08-22 10:42:04 -07:00
|
|
|
GLContext::GetFeatureName(GLFeature::Enum feature)
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-22 10:42:04 -07:00
|
|
|
return GetFeatureInfo(feature).mName;
|
2013-08-02 14:30:58 -07:00
|
|
|
}
|
|
|
|
|
2013-08-23 16:33:42 -07:00
|
|
|
void
|
|
|
|
GLContext::InitFeatures()
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-23 16:33:42 -07:00
|
|
|
for (size_t i = 0; i < GLFeature::EnumMax; i++)
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-23 16:33:42 -07:00
|
|
|
GLFeature::Enum feature = GLFeature::Enum(i);
|
2013-08-02 14:30:58 -07:00
|
|
|
|
2013-08-23 16:33:42 -07:00
|
|
|
if (IsFeatureIsPartOfProfileVersion(feature, mProfile, mVersion)) {
|
|
|
|
mAvailableFeatures[feature] = true;
|
|
|
|
continue;
|
2013-08-02 14:30:58 -07:00
|
|
|
}
|
|
|
|
|
2013-08-23 16:33:42 -07:00
|
|
|
mAvailableFeatures[feature] = false;
|
|
|
|
|
|
|
|
const FeatureInfo& featureInfo = GetFeatureInfo(feature);
|
|
|
|
|
|
|
|
for (size_t j = 0; true; j++)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(j < kMAX_EXTENSION_GROUP_SIZE, "kMAX_EXTENSION_GROUP_SIZE too small");
|
|
|
|
|
|
|
|
if (featureInfo.mExtensions[j] == GLContext::Extensions_End) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsExtensionSupported(featureInfo.mExtensions[j])) {
|
|
|
|
mAvailableFeatures[feature] = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-02 14:30:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 16:33:42 -07:00
|
|
|
void
|
2013-08-22 10:42:04 -07:00
|
|
|
GLContext::MarkUnsupported(GLFeature::Enum feature)
|
2013-08-02 14:30:58 -07:00
|
|
|
{
|
2013-08-23 16:33:42 -07:00
|
|
|
mAvailableFeatures[feature] = false;
|
2013-08-02 14:30:58 -07:00
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
const FeatureInfo& featureInfo = GetFeatureInfo(feature);
|
2013-08-02 14:30:58 -07:00
|
|
|
|
|
|
|
for (size_t i = 0; true; i++)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(i < kMAX_EXTENSION_GROUP_SIZE, "kMAX_EXTENSION_GROUP_SIZE too small");
|
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
if (featureInfo.mExtensions[i] == GLContext::Extensions_End) {
|
2013-08-02 14:30:58 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
MarkExtensionUnsupported(featureInfo.mExtensions[i]);
|
2013-08-02 14:30:58 -07:00
|
|
|
}
|
|
|
|
|
2013-08-23 16:33:42 -07:00
|
|
|
MOZ_ASSERT(!IsSupported(feature), "GLContext::MarkUnsupported has failed!");
|
2013-08-02 14:30:58 -07:00
|
|
|
|
2013-08-22 10:42:04 -07:00
|
|
|
NS_WARNING(nsPrintfCString("%s marked as unsupported", GetFeatureName(feature)).get());
|
2013-08-02 14:30:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|