Bug 968374 - Implement WEBGL_debug_shaders. r=bjacob

This commit is contained in:
Jeff Gilbert 2014-02-11 17:37:06 -05:00
parent c52788043c
commit 57f9c5bee8
9 changed files with 90 additions and 2 deletions

View File

@ -367,6 +367,7 @@ public:
void GetShaderInfoLog(WebGLShader *shader, nsACString& retval);
void GetShaderInfoLog(WebGLShader *shader, nsAString& retval);
void GetShaderSource(WebGLShader *shader, nsAString& retval);
void GetShaderTranslatedSource(WebGLShader *shader, nsAString& retval);
JS::Value GetTexParameter(GLenum target, GLenum pname);
JS::Value GetTexParameter(JSContext * /* unused */, GLenum target,
GLenum pname) {
@ -906,6 +907,7 @@ protected:
WEBGL_compressed_texture_pvrtc,
WEBGL_compressed_texture_s3tc,
WEBGL_debug_renderer_info,
WEBGL_debug_shaders,
WEBGL_depth_texture,
WEBGL_lose_context,
WEBGL_draw_buffers,

View File

@ -29,6 +29,7 @@ static const char *sExtensionNames[] = {
"WEBGL_compressed_texture_pvrtc",
"WEBGL_compressed_texture_s3tc",
"WEBGL_debug_renderer_info",
"WEBGL_debug_shaders",
"WEBGL_depth_texture",
"WEBGL_lose_context",
"WEBGL_draw_buffers",
@ -68,6 +69,8 @@ bool WebGLContext::IsExtensionSupported(JSContext *cx, WebGLExtensionID ext) con
switch (ext) {
case WEBGL_debug_renderer_info:
return true;
case WEBGL_debug_shaders:
return true;
default:
// For warnings-as-errors.
break;
@ -259,6 +262,9 @@ WebGLContext::EnableExtension(WebGLExtensionID ext)
case WEBGL_debug_renderer_info:
obj = new WebGLExtensionDebugRendererInfo(this);
break;
case WEBGL_debug_shaders:
obj = new WebGLExtensionDebugShaders(this);
break;
case WEBGL_depth_texture:
obj = new WebGLExtensionDepthTexture(this);
break;

View File

@ -3306,6 +3306,8 @@ WebGLContext::CompileShader(WebGLShader *shader)
translatedSrc.SetLength(len);
ShGetObjectCode(compiler, translatedSrc.BeginWriting());
CopyASCIItoUTF16(translatedSrc, shader->mTranslatedSource);
const char *ts = translatedSrc.get();
#ifdef WEBGL2_BYPASS_ANGLE
@ -3324,6 +3326,8 @@ WebGLContext::CompileShader(WebGLShader *shader)
// that's really bad, as that means we can't be 100% conformant. We should work towards always
// using ANGLE identifier mapping.
gl->fShaderSource(shadername, 1, &s, nullptr);
CopyASCIItoUTF16(s, shader->mTranslatedSource);
}
shader->SetTranslationSuccess();
@ -3617,8 +3621,7 @@ WebGLContext::GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype)
void
WebGLContext::GetShaderSource(WebGLShader *shader, nsAString& retval)
{
if (IsContextLost())
{
if (IsContextLost()) {
retval.SetIsVoid(true);
return;
}
@ -3651,6 +3654,20 @@ WebGLContext::ShaderSource(WebGLShader *shader, const nsAString& source)
shader->SetNeedsTranslation();
}
void
WebGLContext::GetShaderTranslatedSource(WebGLShader *shader, nsAString& retval)
{
if (IsContextLost()) {
retval.SetIsVoid(true);
return;
}
if (!ValidateObject("getShaderTranslatedSource: shader", shader))
return;
retval.Assign(shader->TranslatedSource());
}
GLenum WebGLContext::CheckedTexImage2D(GLenum target,
GLint level,
GLenum internalFormat,

View File

@ -0,0 +1,36 @@
/* -*- 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 "WebGLContext.h"
#include "WebGLExtensions.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
using namespace mozilla;
WebGLExtensionDebugShaders::WebGLExtensionDebugShaders(WebGLContext* context)
: WebGLExtensionBase(context)
{
}
WebGLExtensionDebugShaders::~WebGLExtensionDebugShaders()
{
}
/* If no source has been defined, compileShader() has not been called,
* or the translation has failed for shader, an empty string is
* returned; otherwise, return the translated source.
*/
void
WebGLExtensionDebugShaders::GetTranslatedShaderSource(WebGLShader* shader,
nsAString& retval)
{
mContext->GetShaderTranslatedSource(shader, retval);
if (retval.IsVoid()) {
CopyASCIItoUTF16("", retval);
}
}
IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDebugShaders)

View File

@ -76,6 +76,18 @@ public:
DECL_WEBGL_EXTENSION_GOOP
};
class WebGLExtensionDebugShaders
: public WebGLExtensionBase
{
public:
WebGLExtensionDebugShaders(WebGLContext*);
virtual ~WebGLExtensionDebugShaders();
void GetTranslatedShaderSource(WebGLShader* shader, nsAString& retval);
DECL_WEBGL_EXTENSION_GOOP
};
class WebGLExtensionDepthTexture
: public WebGLExtensionBase
{

View File

@ -72,6 +72,8 @@ public:
const nsCString& TranslationLog() const { return mTranslationLog; }
const nsString& TranslatedSource() const { return mTranslatedSource; }
WebGLContext *GetParentObject() const {
return Context();
}
@ -87,6 +89,7 @@ protected:
GLuint mGLName;
GLenum mType;
nsString mSource;
nsString mTranslatedSource;
nsCString mTranslationLog; // The translation log should contain only ASCII characters
bool mNeedsTranslation;
nsTArray<WebGLMappedIdentifier> mAttributes;

View File

@ -48,6 +48,7 @@ if CONFIG['MOZ_WEBGL']:
'WebGLExtensionCompressedTexturePVRTC.cpp',
'WebGLExtensionCompressedTextureS3TC.cpp',
'WebGLExtensionDebugRendererInfo.cpp',
'WebGLExtensionDebugShaders.cpp',
'WebGLExtensionDepthTexture.cpp',
'WebGLExtensionDrawBuffers.cpp',
'WebGLExtensionElementIndexUint.cpp',

View File

@ -1370,6 +1370,11 @@ DOMInterfaces = {
'headerFile': 'WebGLExtensions.h'
},
'WebGLExtensionDebugShaders': {
'nativeType': 'mozilla::WebGLExtensionDebugShaders',
'headerFile': 'WebGLExtensions.h'
},
'WebGLExtensionElementIndexUint': {
'nativeType': 'mozilla::WebGLExtensionElementIndexUint',
'headerFile': 'WebGLExtensions.h'

View File

@ -805,6 +805,12 @@ interface WebGLExtensionDebugRendererInfo
const GLenum UNMASKED_RENDERER_WEBGL = 0x9246;
};
[NoInterfaceObject]
interface WebGLExtensionDebugShaders
{
DOMString getTranslatedShaderSource(WebGLShader? shader);
};
[NoInterfaceObject]
interface WebGLExtensionDepthTexture
{