зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1159117 - Enable support for legacy formats. r=jgilbert
ALPHA, LUMINANCE, and LUMINANCE_ALPHA texture formats are removed in OpenGL core profiles. Emulate these via RED, RG and texture swizzling.
This commit is contained in:
Родитель
4454c8f924
Коммит
e6db7512d2
|
@ -128,6 +128,14 @@ WebGLContext::InitWebGL2()
|
|||
missingList.push_back(kRequiredFeatures[i]);
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
// On OSX, GL core profile is used. This requires texture swizzle
|
||||
// support to emulate legacy texture formats: ALPHA, LUMINANCE,
|
||||
// and LUMINANCE_ALPHA.
|
||||
if (!gl->IsSupported(gl::GLFeature::texture_swizzle))
|
||||
missingList.push_back(gl::GLFeature::texture_swizzle);
|
||||
#endif
|
||||
|
||||
if (missingList.size()) {
|
||||
nsAutoCString exts;
|
||||
for (auto itr = missingList.begin(); itr != missingList.end(); ++itr) {
|
||||
|
|
|
@ -3198,6 +3198,9 @@ GLenum WebGLContext::CheckedTexImage2D(TexImageTarget texImageTarget,
|
|||
|
||||
gl->fTexImage2D(texImageTarget.get(), level, driverInternalFormat, width, height, border, driverFormat, driverType, data);
|
||||
|
||||
if (effectiveInternalFormat != driverInternalFormat)
|
||||
SetLegacyTextureSwizzle(gl, texImageTarget.get(), internalformat.get());
|
||||
|
||||
GLenum error = LOCAL_GL_NO_ERROR;
|
||||
if (sizeMayChange) {
|
||||
error = GetAndFlushUnderlyingGLErrors();
|
||||
|
|
|
@ -249,7 +249,7 @@ DriverFormatsFromEffectiveInternalFormat(gl::GLContext* gl,
|
|||
// in some cases we must pass a different value. On ES, they are equal by definition
|
||||
// as it is an error to pass internalformat!=format.
|
||||
GLenum driverInternalFormat = driverFormat;
|
||||
if (!gl->IsGLES()) {
|
||||
if (gl->IsCompatibilityProfile()) {
|
||||
// Cases where desktop OpenGL requires a tweak to 'format'
|
||||
if (driverFormat == LOCAL_GL_SRGB)
|
||||
driverFormat = LOCAL_GL_RGB;
|
||||
|
@ -284,11 +284,64 @@ DriverFormatsFromEffectiveInternalFormat(gl::GLContext* gl,
|
|||
}
|
||||
}
|
||||
|
||||
// OpenGL core profile removed texture formats ALPHA, LUMINANCE and LUMINANCE_ALPHA
|
||||
if (gl->IsCoreProfile()) {
|
||||
switch (driverFormat) {
|
||||
case LOCAL_GL_ALPHA:
|
||||
case LOCAL_GL_LUMINANCE:
|
||||
driverInternalFormat = driverFormat = LOCAL_GL_RED;
|
||||
break;
|
||||
|
||||
case LOCAL_GL_LUMINANCE_ALPHA:
|
||||
driverInternalFormat = driverFormat = LOCAL_GL_RG;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*out_driverInternalFormat = driverInternalFormat;
|
||||
*out_driverFormat = driverFormat;
|
||||
*out_driverType = driverType;
|
||||
}
|
||||
|
||||
// Map R to A
|
||||
static const GLenum kLegacyAlphaSwizzle[4] = {
|
||||
LOCAL_GL_ZERO, LOCAL_GL_ZERO, LOCAL_GL_ZERO, LOCAL_GL_RED
|
||||
};
|
||||
// Map R to RGB
|
||||
static const GLenum kLegacyLuminanceSwizzle[4] = {
|
||||
LOCAL_GL_RED, LOCAL_GL_RED, LOCAL_GL_RED, LOCAL_GL_ONE
|
||||
};
|
||||
// Map R to RGB, G to A
|
||||
static const GLenum kLegacyLuminanceAlphaSwizzle[4] = {
|
||||
LOCAL_GL_RED, LOCAL_GL_RED, LOCAL_GL_RED, LOCAL_GL_GREEN
|
||||
};
|
||||
|
||||
void
|
||||
SetLegacyTextureSwizzle(gl::GLContext* gl, GLenum target, GLenum internalformat)
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(gl->IsSupported(gl::GLFeature::texture_swizzle));
|
||||
/* Only support swizzling on core profiles. */
|
||||
if (!gl->IsCoreProfile())
|
||||
return;
|
||||
|
||||
switch (internalformat) {
|
||||
case LOCAL_GL_ALPHA:
|
||||
gl->fTexParameteriv(target, LOCAL_GL_TEXTURE_SWIZZLE_RGBA,
|
||||
(GLint*) kLegacyAlphaSwizzle);
|
||||
break;
|
||||
|
||||
case LOCAL_GL_LUMINANCE:
|
||||
gl->fTexParameteriv(target, LOCAL_GL_TEXTURE_SWIZZLE_RGBA,
|
||||
(GLint*) kLegacyLuminanceSwizzle);
|
||||
break;
|
||||
|
||||
case LOCAL_GL_LUMINANCE_ALPHA:
|
||||
gl->fTexParameteriv(target, LOCAL_GL_TEXTURE_SWIZZLE_RGBA,
|
||||
(GLint*) kLegacyLuminanceAlphaSwizzle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bits per texel for format & type combination.
|
||||
* Assumes that format & type are a valid combination as checked with
|
||||
|
|
|
@ -38,6 +38,8 @@ TexType TypeFromInternalFormat(TexInternalFormat internalformat);
|
|||
TexInternalFormat
|
||||
UnsizedInternalFormatFromInternalFormat(TexInternalFormat internalformat);
|
||||
|
||||
void SetLegacyTextureSwizzle(gl::GLContext* gl, GLenum target, GLenum internalformat);
|
||||
|
||||
size_t GetBitsPerTexel(TexInternalFormat effectiveinternalformat);
|
||||
|
||||
// For use with the different texture calls, i.e.
|
||||
|
|
|
@ -96,6 +96,7 @@ static const char *sExtensionNames[] = {
|
|||
"GL_ARB_texture_non_power_of_two",
|
||||
"GL_ARB_texture_rectangle",
|
||||
"GL_ARB_texture_storage",
|
||||
"GL_ARB_texture_swizzle",
|
||||
"GL_ARB_transform_feedback2",
|
||||
"GL_ARB_uniform_buffer_object",
|
||||
"GL_ARB_vertex_array_object",
|
||||
|
|
|
@ -128,6 +128,7 @@ enum class GLFeature {
|
|||
texture_half_float_linear,
|
||||
texture_non_power_of_two,
|
||||
texture_storage,
|
||||
texture_swizzle,
|
||||
transform_feedback2,
|
||||
uniform_buffer_object,
|
||||
uniform_matrix_nonsquare,
|
||||
|
@ -389,6 +390,7 @@ public:
|
|||
ARB_texture_non_power_of_two,
|
||||
ARB_texture_rectangle,
|
||||
ARB_texture_storage,
|
||||
ARB_texture_swizzle,
|
||||
ARB_transform_feedback2,
|
||||
ARB_uniform_buffer_object,
|
||||
ARB_vertex_array_object,
|
||||
|
|
|
@ -603,6 +603,15 @@ static const FeatureInfo sFeatureInfoArr[] = {
|
|||
GLContext::Extensions_End
|
||||
}
|
||||
},
|
||||
{
|
||||
"texture_swizzle",
|
||||
GLVersion::GL3_3,
|
||||
GLESVersion::ES3,
|
||||
GLContext::ARB_texture_swizzle,
|
||||
{
|
||||
GLContext::Extensions_End
|
||||
}
|
||||
},
|
||||
{
|
||||
"transform_feedback2",
|
||||
GLVersion::GL4,
|
||||
|
|
Загрузка…
Ссылка в новой задаче