mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
5e324904fd
- Bug 1252212. Make the RIL WorkerRun implemetations not leave exceptions on the JSContext. r=khuey (a96b929707) - Bug 1267893 part 4 - Make setting the start time set 'did seek' to true; r=hiro (581d057f37) - Bug 1263063 - Part 6: Use TimingParams::EndTime() instead of re-calculation ComputedTiming each time. r=dholbert (1c70d3dd80) - Bug 1244637 - implement AnimationEffectTiming fill. r=hiro (83f10328cf) - Bug 1244642 - Implement AnimationEffectTiming.direction r=hiro (5fb010e6f4) - Bug 1267937 - Part 1: Clear mProgressOnLastCompose once we are not in effect. r=birtles (ccc5ee4594) - Bug 1267937 - Part 2: A reftest which checks mProgressOnLastCompose is surely cleared in before phase. r=birtles (850fb3a6b1) - Bug 1259733 - use forward declarations for nsIDocument in a few places; r=dholbert (1cc3af25b0) - Bug 1232906 - Use channel.asyncOpen2 within dom/apps/AppsUtils.jsm (r=sicking) (f8fe88724f) - Bug 1250464 - Remove workaround to get path from AppsUtils.jsm. r=myk (e1c76d7a13) - Bug 1263158 - Check if key is present in manifest object before using it. r=fabrice (44fe2c0468) - Bug 1230091 - ReferenceError on using not defined aApp variable in OfflineCacheInstaller.jsm, r=fabrice (8c6ab3d45c) - Bug 1228974 - correct the group ID in Offline Cache Installer, r=fabrice (f30de7eb6c) - var-let (364b37d086) - Bug 1267718 - Add a nsPIDOMWindow::GetScriptableParentOrNull method. r=bz (2cf8533883) - Bug 1268953. The load events we fire on iframe/frame/object (in the document case) should not be cancelable. r=smaug (ec36a6e8c8) - Bug 1266194 - Implement boolean or EventListenerOptions as 3rd param to addEventListener, r=smaug (069c30d74f) - Bug 944616 - "Blob URLs don't allow query or fragment parts". r=bz (85923ee174) - minor (bd5daf4059) - Bug 1167395 - Mark CharacterDataChangeInfo::Details as MOZ_STACK_CLASS, and mark mNextSibling as MOZ_NON_OWNING_REF. r=smaug (83eb176677) - Bug 1192855 - Check validity in advance for nsRange::InsertNode; r=hsivonen (485bd59ff4) - Bug 1214495 - Bonus fix. r=bz (bf6a4b33ec) - Bug 1266889 - Plugin block list blocks SWF network requests, but does not prevent plugin instantiation. r=francois (be7237639a) - Bug 1183891 - Remove warning if invalid node type is passed to nsRange::SetStart. r=smaug (8ce58952af) - Bug 1183893 - Remove warning if invalid node type is passed to nsRange::SetEnd. r=smaug (8675f2e21f) - Bug 1163105 - Make nsReferencedElement work with referencing elements that are not in their document's DOM tree. r=roc (83bc0fc078) - Bug 1172144 - Improve the size check of nsTextFragment::Append, r=ehsan (e6d47af1b1) - Bug 1151366 - remove nsGkAtoms::mozdonotsend from treesanitizer. r=ehsan (9237c22bdb) - Bug 1158500 - make writing-mode a mapped CSS property. r=cam (8d50bfb287) - bit of 1131348 (f2b234976b) - Bug 1245533 - nsXHTMLContentSerializer::CheckElementEnd - small compilation issue, r=smaug (85d8a50ddb) - align tests (cfb773549f) - Bug 1248836 - HID Features Implementation, r=jocelyn (0cb4482faf) - Bug 1239979: Close sockets when deinitializing Bluetooth profile managers, r=btian (c8c449767b) - Bug 1238991: Don't connect Bluetooth OPP manager before service channel is known, r=btian (9ad0d9ff7e) - Bug 1239979: Get pointers to Bluetooth managers during each shutdown, r=shuang (71959acf40) - Bug 1229697 - Cancel bond when user inputs empty pincode for pairing, r=shuang (e70ee96e6b) - Bug 1252787 - Patch : Add HID profile when device is remote, r=shawnjohnjr (bbadf5f42b) - Bug 1236724: Check the maximum length of each array in IPC; f=jhector, r=btian (e961ee7756) - align tests (17b6369dfa) - Bug 1268688 - Start browser API for frames swapping to HTML. r=bz (4a17ea38c7) - Bug 1265427 - nsDOMCameraControl needs an mOwnedStream to be consistent towards its VideoStreamTrack r=me (e008b0e4c1) - Bug 1154665 - Part 1. Provide gps processing data to avoid setParameters fail. r=aosmond (0564b157d3) - Bug 1154665 - Part 2. Testcase against gps parameter. r=aosmond (c52efbcd07) - Bug 1239752 - Create ImageBitmap from ImageData should preserve alpha. r=roc (1ec8ccd266) - Bug 1266432: Use CopySurface in ImageBitmap::PrepareForDrawing even when using D2D 1.1. r=kaku (c27dcf42f2) - Bug 1265598: Deal with the possibility of a write map failing. r=kaku r=milan (1916e69db1) - Bug 1266390: Preserver mIsPremultipliedAlpha when creating an ImageBitmap from an existing ImageBitmap. r=kaku (385ad1f750) - Bug 1267100 - add makeCurrent() for WebGLContext::GetFramebufferAttachmentParameter(). r=jgilbert (d7f957610b) - Bug 1266262 - Remove nearly-unused GLContext::mGLFormats. - r=jrmuizel (039e2a851f) - Bug 1186688 - Remove cached state check for DrawBuffer maximums, since it's invalid with min-cap mode. - r=jrmuizel (dc92031951) - Bug 1193526 - Add generated files. r=jgilbert (c3f54b6cef) - Bug 1264214 - WebGL check the conflict name when LinkProgram. r=jgilbert (1f268acc58) - Bug 842818 - Inline CloneData() and clean up ImportKeyTask::SetKeyData() r=rbarnes (299a32176c) - Bug 1137987 - Remove nonstandard let block from dom/downloads/tests. r=aus (94e98d64ff) - Bug 1211454 - Avoid requesting a zero-terminated string in TextEncoder when zero-termination is not needed. r=emk. (2d52f98e86) - Bug 1259669 Rename WidgetCommandEvent::command to WidgetCommandEvent::mCommand r=masayuki (744c283978) - Bug 1264380 - Get Composed Document of Shadow DOM Element Properly. r=wchen (0b4404ef19) - Bug 1188539 - Remove the deprecated TouchList::identifiedTouch method; r=jst (926c24d74d) - Bug 918706 - Return NS_ERROR_DOM_SYNTAX_ERR if method is invalid, r=khuey (f209944a0c) - Bug 1265610 - test_postMessages.html and some dom/filesystem tests requires 'dom.input.dirpicker' to be true, r=smaug (7092cef989) - Bug 1265610 - Fixing a JS error in the tests, CLOSED TREE r=me (d203807a1e) - Bug 1137151: Marked destructors of refcounted FM-radio classes as protected, r=pzhang (5b2ad86c5e) - Bug 1206174 - Improve code readability of FMRadioService r=alwu (bfcf897714) - Bug 1254298 - Bypass Gamepad Service Shutdown Timer on e10s; r=ted r=cleu (c40fcae327) - Bug 1156957 - Make gamepad mochitests work on e10s; r=ted (f0a1be1440) - Bug 1248794 - Clean up observer on WindowsGamepadService shutdown; r=ted r=smaug sec-approval=abillings (06660cc3fc) - Bug 1237896 - [Gamepad] Button Event cannot be correctly triggered after reconnect. r=qdot (fa21602600) - Bug 1249833 - Typo in nsGeolocation.h. r=jdm (42dad72688) - Bug 1255198 - [Telemetry] Add geolocation Telemetry probes to record fulfilled requests according to document.isVisible. r=jdm, data-review=bsmedberg (5e4f5db476) - Bug 1218080 - Don't send the url to the parent process when opening new windows, because it is not actually used. r=smaug (fca00714f6) - Bug 1256061 - Hold a strong reference to a request when we call a method on it. r=jdm (7ed037ef37) - Bug 1263001 - Don't Notify() an unlinked nsGeolocationRequest. r=jdm (0693c4688f) - missing bit of Bug 1242668 - Hold more references. r=sotaro (ba173e46f1) - Bug 1267246 - Remove bogus assertion. r=nical (c8ccfb73c8) - Bug 1265638 - Reset some properties when the backend of SharedSurface is switching from Basic to layer-accelerated backend. r=jgilbert (a6cf6598b7) - Bug 1266484 - Fix crash in libsystem_kernel.dylib@0x16db6 when using Pinboard bookmarklet. r=gabor (1a96a797c6) - Bug 1253959 - per comment 10, #ifdef code that causes ReadMetadata() to fail on Windows XP debug. r=cpearce. (ab2e19f621) - Bug 1256038: Remove special NotifyDataArrived handling in the DirectShow reader. r=cpearce (441a26dd97) - Bug 1284198 - Don't USE_CLOCK_API on macOS. r=terrence (659cecb516) - Bug 956899 - Add comments to ConditionVariable and handle some edge cases gracefully; r=froydnj (be45b6b271) - Bug 1268822 - rename mozilla::gmp::Runnable/SyncRunnable in order not to confuse NS_LOG_ADDREF/NS_LOG_RELEASE. r=rjesup. (18aec0cd35)
1193 lines
39 KiB
C++
1193 lines
39 KiB
C++
/* -*- 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 "WebGLProgram.h"
|
|
|
|
#include "GLContext.h"
|
|
#include "mozilla/CheckedInt.h"
|
|
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
|
#include "mozilla/RefPtr.h"
|
|
#include "WebGLActiveInfo.h"
|
|
#include "WebGLContext.h"
|
|
#include "WebGLShader.h"
|
|
#include "WebGLUniformLocation.h"
|
|
#include "WebGLValidateStrings.h"
|
|
|
|
namespace mozilla {
|
|
|
|
/* If `name`: "foo[3]"
|
|
* Then returns true, with
|
|
* `out_baseName`: "foo"
|
|
* `out_isArray`: true
|
|
* `out_index`: 3
|
|
*
|
|
* If `name`: "foo"
|
|
* Then returns true, with
|
|
* `out_baseName`: "foo"
|
|
* `out_isArray`: false
|
|
* `out_index`: <not written>
|
|
*/
|
|
static bool
|
|
ParseName(const nsCString& name, nsCString* const out_baseName,
|
|
bool* const out_isArray, size_t* const out_arrayIndex)
|
|
{
|
|
int32_t indexEnd = name.RFind("]");
|
|
if (indexEnd == -1 ||
|
|
(uint32_t)indexEnd != name.Length() - 1)
|
|
{
|
|
*out_baseName = name;
|
|
*out_isArray = false;
|
|
return true;
|
|
}
|
|
|
|
int32_t indexOpenBracket = name.RFind("[");
|
|
if (indexOpenBracket == -1)
|
|
return false;
|
|
|
|
uint32_t indexStart = indexOpenBracket + 1;
|
|
uint32_t indexLen = indexEnd - indexStart;
|
|
if (indexLen == 0)
|
|
return false;
|
|
|
|
const nsAutoCString indexStr(Substring(name, indexStart, indexLen));
|
|
|
|
nsresult errorcode;
|
|
int32_t indexNum = indexStr.ToInteger(&errorcode);
|
|
if (NS_FAILED(errorcode))
|
|
return false;
|
|
|
|
if (indexNum < 0)
|
|
return false;
|
|
|
|
*out_baseName = StringHead(name, indexOpenBracket);
|
|
*out_isArray = true;
|
|
*out_arrayIndex = indexNum;
|
|
return true;
|
|
}
|
|
|
|
static void
|
|
AddActiveInfo(WebGLContext* webgl, GLint elemCount, GLenum elemType, bool isArray,
|
|
const nsACString& baseUserName, const nsACString& baseMappedName,
|
|
std::vector<RefPtr<WebGLActiveInfo>>* activeInfoList,
|
|
std::map<nsCString, const WebGLActiveInfo*>* infoLocMap)
|
|
{
|
|
RefPtr<WebGLActiveInfo> info = new WebGLActiveInfo(webgl, elemCount, elemType,
|
|
isArray, baseUserName,
|
|
baseMappedName);
|
|
activeInfoList->push_back(info);
|
|
|
|
infoLocMap->insert(std::make_pair(info->mBaseUserName, info.get()));
|
|
}
|
|
|
|
static void
|
|
AddActiveBlockInfo(const nsACString& baseUserName,
|
|
const nsACString& baseMappedName,
|
|
std::vector<RefPtr<webgl::UniformBlockInfo>>* activeInfoList)
|
|
{
|
|
RefPtr<webgl::UniformBlockInfo> info = new webgl::UniformBlockInfo(baseUserName, baseMappedName);
|
|
|
|
activeInfoList->push_back(info);
|
|
}
|
|
|
|
//#define DUMP_SHADERVAR_MAPPINGS
|
|
|
|
static already_AddRefed<const webgl::LinkedProgramInfo>
|
|
QueryProgramInfo(WebGLProgram* prog, gl::GLContext* gl)
|
|
{
|
|
RefPtr<webgl::LinkedProgramInfo> info(new webgl::LinkedProgramInfo(prog));
|
|
|
|
GLuint maxAttribLenWithNull = 0;
|
|
gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_ATTRIBUTE_MAX_LENGTH,
|
|
(GLint*)&maxAttribLenWithNull);
|
|
if (maxAttribLenWithNull < 1)
|
|
maxAttribLenWithNull = 1;
|
|
|
|
GLuint maxUniformLenWithNull = 0;
|
|
gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORM_MAX_LENGTH,
|
|
(GLint*)&maxUniformLenWithNull);
|
|
if (maxUniformLenWithNull < 1)
|
|
maxUniformLenWithNull = 1;
|
|
|
|
GLuint maxUniformBlockLenWithNull = 0;
|
|
if (gl->IsSupported(gl::GLFeature::uniform_buffer_object)) {
|
|
gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH,
|
|
(GLint*)&maxUniformBlockLenWithNull);
|
|
if (maxUniformBlockLenWithNull < 1)
|
|
maxUniformBlockLenWithNull = 1;
|
|
}
|
|
|
|
GLuint maxTransformFeedbackVaryingLenWithNull = 0;
|
|
if (gl->IsSupported(gl::GLFeature::transform_feedback2)) {
|
|
gl->fGetProgramiv(prog->mGLName, LOCAL_GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH,
|
|
(GLint*)&maxTransformFeedbackVaryingLenWithNull);
|
|
if (maxTransformFeedbackVaryingLenWithNull < 1)
|
|
maxTransformFeedbackVaryingLenWithNull = 1;
|
|
}
|
|
|
|
|
|
#ifdef DUMP_SHADERVAR_MAPPINGS
|
|
printf_stderr("maxAttribLenWithNull: %d\n", maxAttribLenWithNull);
|
|
printf_stderr("maxUniformLenWithNull: %d\n", maxUniformLenWithNull);
|
|
printf_stderr("maxUniformBlockLenWithNull: %d\n", maxUniformBlockLenWithNull);
|
|
#endif
|
|
|
|
// Attribs
|
|
|
|
GLuint numActiveAttribs = 0;
|
|
gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES,
|
|
(GLint*)&numActiveAttribs);
|
|
|
|
for (GLuint i = 0; i < numActiveAttribs; i++) {
|
|
nsAutoCString mappedName;
|
|
mappedName.SetLength(maxAttribLenWithNull - 1);
|
|
|
|
GLsizei lengthWithoutNull = 0;
|
|
GLint elemCount = 0; // `size`
|
|
GLenum elemType = 0; // `type`
|
|
gl->fGetActiveAttrib(prog->mGLName, i, mappedName.Length()+1, &lengthWithoutNull,
|
|
&elemCount, &elemType, mappedName.BeginWriting());
|
|
|
|
mappedName.SetLength(lengthWithoutNull);
|
|
|
|
// Collect ActiveInfos:
|
|
|
|
// Attribs can't be arrays, so we can skip some of the mess we have in the Uniform
|
|
// path.
|
|
nsDependentCString userName;
|
|
if (!prog->FindAttribUserNameByMappedName(mappedName, &userName))
|
|
userName.Rebind(mappedName, 0);
|
|
|
|
#ifdef DUMP_SHADERVAR_MAPPINGS
|
|
printf_stderr("[attrib %i] %s/%s\n", i, mappedName.BeginReading(),
|
|
userName.BeginReading());
|
|
printf_stderr(" lengthWithoutNull: %d\n", lengthWithoutNull);
|
|
#endif
|
|
|
|
const bool isArray = false;
|
|
AddActiveInfo(prog->mContext, elemCount, elemType, isArray, userName, mappedName,
|
|
&info->activeAttribs, &info->attribMap);
|
|
|
|
// Collect active locations:
|
|
GLint loc = gl->fGetAttribLocation(prog->mGLName, mappedName.BeginReading());
|
|
if (loc == -1) {
|
|
if (mappedName != "gl_InstanceID")
|
|
MOZ_CRASH("Active attrib has no location.");
|
|
} else {
|
|
info->activeAttribLocs.insert(loc);
|
|
}
|
|
}
|
|
|
|
// Uniforms
|
|
|
|
const bool needsCheckForArrays = gl->WorkAroundDriverBugs();
|
|
|
|
GLuint numActiveUniforms = 0;
|
|
gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORMS,
|
|
(GLint*)&numActiveUniforms);
|
|
|
|
for (GLuint i = 0; i < numActiveUniforms; i++) {
|
|
nsAutoCString mappedName;
|
|
mappedName.SetLength(maxUniformLenWithNull - 1);
|
|
|
|
GLsizei lengthWithoutNull = 0;
|
|
GLint elemCount = 0; // `size`
|
|
GLenum elemType = 0; // `type`
|
|
gl->fGetActiveUniform(prog->mGLName, i, mappedName.Length()+1, &lengthWithoutNull,
|
|
&elemCount, &elemType, mappedName.BeginWriting());
|
|
|
|
mappedName.SetLength(lengthWithoutNull);
|
|
|
|
nsAutoCString baseMappedName;
|
|
bool isArray;
|
|
size_t arrayIndex;
|
|
if (!ParseName(mappedName, &baseMappedName, &isArray, &arrayIndex))
|
|
MOZ_CRASH("Failed to parse `mappedName` received from driver.");
|
|
|
|
// Note that for good drivers, `isArray` should already be correct.
|
|
// However, if FindUniform succeeds, it will be validator-guaranteed correct.
|
|
|
|
nsAutoCString baseUserName;
|
|
if (!prog->FindUniformByMappedName(baseMappedName, &baseUserName, &isArray)) {
|
|
baseUserName = baseMappedName;
|
|
|
|
if (needsCheckForArrays && !isArray) {
|
|
// By GLES 3, GetUniformLocation("foo[0]") should return -1 if `foo` is
|
|
// not an array. Our current linux Try slaves return the location of `foo`
|
|
// anyways, though.
|
|
std::string mappedNameStr = baseMappedName.BeginReading();
|
|
mappedNameStr += "[0]";
|
|
|
|
GLint loc = gl->fGetUniformLocation(prog->mGLName, mappedNameStr.c_str());
|
|
if (loc != -1)
|
|
isArray = true;
|
|
}
|
|
}
|
|
|
|
#ifdef DUMP_SHADERVAR_MAPPINGS
|
|
printf_stderr("[uniform %i] %s/%i/%s/%s\n", i, mappedName.BeginReading(),
|
|
(int)isArray, baseMappedName.BeginReading(),
|
|
baseUserName.BeginReading());
|
|
printf_stderr(" lengthWithoutNull: %d\n", lengthWithoutNull);
|
|
printf_stderr(" isArray: %d\n", (int)isArray);
|
|
#endif
|
|
|
|
AddActiveInfo(prog->mContext, elemCount, elemType, isArray, baseUserName,
|
|
baseMappedName, &info->activeUniforms, &info->uniformMap);
|
|
}
|
|
|
|
// Uniform Blocks
|
|
|
|
if (gl->IsSupported(gl::GLFeature::uniform_buffer_object)) {
|
|
GLuint numActiveUniformBlocks = 0;
|
|
gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORM_BLOCKS,
|
|
(GLint*)&numActiveUniformBlocks);
|
|
|
|
for (GLuint i = 0; i < numActiveUniformBlocks; i++) {
|
|
nsAutoCString mappedName;
|
|
mappedName.SetLength(maxUniformBlockLenWithNull - 1);
|
|
|
|
GLint lengthWithoutNull;
|
|
gl->fGetActiveUniformBlockiv(prog->mGLName, i, LOCAL_GL_UNIFORM_BLOCK_NAME_LENGTH, &lengthWithoutNull);
|
|
gl->fGetActiveUniformBlockName(prog->mGLName, i, maxUniformBlockLenWithNull, &lengthWithoutNull, mappedName.BeginWriting());
|
|
mappedName.SetLength(lengthWithoutNull);
|
|
|
|
nsAutoCString baseMappedName;
|
|
bool isArray;
|
|
size_t arrayIndex;
|
|
if (!ParseName(mappedName, &baseMappedName, &isArray, &arrayIndex))
|
|
MOZ_CRASH("Failed to parse `mappedName` received from driver.");
|
|
|
|
nsAutoCString baseUserName;
|
|
if (!prog->FindUniformBlockByMappedName(baseMappedName, &baseUserName,
|
|
&isArray))
|
|
{
|
|
baseUserName = baseMappedName;
|
|
|
|
if (needsCheckForArrays && !isArray) {
|
|
std::string mappedNameStr = baseMappedName.BeginReading();
|
|
mappedNameStr += "[0]";
|
|
|
|
GLuint loc = gl->fGetUniformBlockIndex(prog->mGLName,
|
|
mappedNameStr.c_str());
|
|
if (loc != LOCAL_GL_INVALID_INDEX)
|
|
isArray = true;
|
|
}
|
|
}
|
|
|
|
#ifdef DUMP_SHADERVAR_MAPPINGS
|
|
printf_stderr("[uniform block %i] %s/%i/%s/%s\n", i, mappedName.BeginReading(),
|
|
(int)isArray, baseMappedName.BeginReading(),
|
|
baseUserName.BeginReading());
|
|
printf_stderr(" lengthWithoutNull: %d\n", lengthWithoutNull);
|
|
printf_stderr(" isArray: %d\n", (int)isArray);
|
|
#endif
|
|
|
|
AddActiveBlockInfo(baseUserName, baseMappedName, &info->uniformBlocks);
|
|
}
|
|
}
|
|
|
|
// Transform feedback varyings
|
|
|
|
if (gl->IsSupported(gl::GLFeature::transform_feedback2)) {
|
|
GLuint numTransformFeedbackVaryings = 0;
|
|
gl->fGetProgramiv(prog->mGLName, LOCAL_GL_TRANSFORM_FEEDBACK_VARYINGS,
|
|
(GLint*)&numTransformFeedbackVaryings);
|
|
|
|
for (GLuint i = 0; i < numTransformFeedbackVaryings; i++) {
|
|
nsAutoCString mappedName;
|
|
mappedName.SetLength(maxTransformFeedbackVaryingLenWithNull - 1);
|
|
|
|
GLint lengthWithoutNull;
|
|
GLsizei size;
|
|
GLenum type;
|
|
gl->fGetTransformFeedbackVarying(prog->mGLName, i, maxTransformFeedbackVaryingLenWithNull,
|
|
&lengthWithoutNull, &size, &type,
|
|
mappedName.BeginWriting());
|
|
mappedName.SetLength(lengthWithoutNull);
|
|
|
|
nsAutoCString baseMappedName;
|
|
bool isArray;
|
|
size_t arrayIndex;
|
|
if (!ParseName(mappedName, &baseMappedName, &isArray, &arrayIndex))
|
|
MOZ_CRASH("Failed to parse `mappedName` received from driver.");
|
|
|
|
nsAutoCString baseUserName;
|
|
if (!prog->FindVaryingByMappedName(mappedName, &baseUserName, &isArray)) {
|
|
baseUserName = baseMappedName;
|
|
|
|
if (needsCheckForArrays && !isArray) {
|
|
std::string mappedNameStr = baseMappedName.BeginReading();
|
|
mappedNameStr += "[0]";
|
|
|
|
GLuint loc = gl->fGetUniformBlockIndex(prog->mGLName,
|
|
mappedNameStr.c_str());
|
|
if (loc != LOCAL_GL_INVALID_INDEX)
|
|
isArray = true;
|
|
}
|
|
}
|
|
|
|
AddActiveInfo(prog->mContext, size, type, isArray, baseUserName, mappedName,
|
|
&info->transformFeedbackVaryings,
|
|
&info->transformFeedbackVaryingsMap);
|
|
}
|
|
}
|
|
|
|
return info.forget();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
webgl::LinkedProgramInfo::LinkedProgramInfo(WebGLProgram* prog)
|
|
: prog(prog)
|
|
{ }
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// WebGLProgram
|
|
|
|
static GLuint
|
|
CreateProgram(gl::GLContext* gl)
|
|
{
|
|
gl->MakeCurrent();
|
|
return gl->fCreateProgram();
|
|
}
|
|
|
|
WebGLProgram::WebGLProgram(WebGLContext* webgl)
|
|
: WebGLContextBoundObject(webgl)
|
|
, mGLName(CreateProgram(webgl->GL()))
|
|
, mTransformFeedbackBufferMode(LOCAL_GL_NONE)
|
|
{
|
|
mContext->mPrograms.insertBack(this);
|
|
}
|
|
|
|
WebGLProgram::~WebGLProgram()
|
|
{
|
|
DeleteOnce();
|
|
}
|
|
|
|
void
|
|
WebGLProgram::Delete()
|
|
{
|
|
gl::GLContext* gl = mContext->GL();
|
|
|
|
gl->MakeCurrent();
|
|
gl->fDeleteProgram(mGLName);
|
|
|
|
mVertShader = nullptr;
|
|
mFragShader = nullptr;
|
|
|
|
mMostRecentLinkInfo = nullptr;
|
|
|
|
LinkedListElement<WebGLProgram>::removeFrom(mContext->mPrograms);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// GL funcs
|
|
|
|
void
|
|
WebGLProgram::AttachShader(WebGLShader* shader)
|
|
{
|
|
WebGLRefPtr<WebGLShader>* shaderSlot;
|
|
switch (shader->mType) {
|
|
case LOCAL_GL_VERTEX_SHADER:
|
|
shaderSlot = &mVertShader;
|
|
break;
|
|
case LOCAL_GL_FRAGMENT_SHADER:
|
|
shaderSlot = &mFragShader;
|
|
break;
|
|
default:
|
|
mContext->ErrorInvalidOperation("attachShader: Bad type for shader.");
|
|
return;
|
|
}
|
|
|
|
if (*shaderSlot) {
|
|
if (shader == *shaderSlot) {
|
|
mContext->ErrorInvalidOperation("attachShader: `shader` is already attached.");
|
|
} else {
|
|
mContext->ErrorInvalidOperation("attachShader: Only one of each type of"
|
|
" shader may be attached to a program.");
|
|
}
|
|
return;
|
|
}
|
|
|
|
*shaderSlot = shader;
|
|
|
|
mContext->MakeContextCurrent();
|
|
mContext->gl->fAttachShader(mGLName, shader->mGLName);
|
|
}
|
|
|
|
void
|
|
WebGLProgram::BindAttribLocation(GLuint loc, const nsAString& name)
|
|
{
|
|
if (!ValidateGLSLVariableName(name, mContext, "bindAttribLocation"))
|
|
return;
|
|
|
|
if (loc >= mContext->MaxVertexAttribs()) {
|
|
mContext->ErrorInvalidValue("bindAttribLocation: `location` must be less than"
|
|
" MAX_VERTEX_ATTRIBS.");
|
|
return;
|
|
}
|
|
|
|
if (StringBeginsWith(name, NS_LITERAL_STRING("gl_"))) {
|
|
mContext->ErrorInvalidOperation("bindAttribLocation: Can't set the location of a"
|
|
" name that starts with 'gl_'.");
|
|
return;
|
|
}
|
|
|
|
NS_LossyConvertUTF16toASCII asciiName(name);
|
|
|
|
auto res = mBoundAttribLocs.insert(std::pair<nsCString, GLuint>(asciiName, loc));
|
|
|
|
const bool wasInserted = res.second;
|
|
if (!wasInserted) {
|
|
auto itr = res.first;
|
|
itr->second = loc;
|
|
}
|
|
}
|
|
|
|
void
|
|
WebGLProgram::DetachShader(WebGLShader* shader)
|
|
{
|
|
MOZ_ASSERT(shader);
|
|
|
|
WebGLRefPtr<WebGLShader>* shaderSlot;
|
|
switch (shader->mType) {
|
|
case LOCAL_GL_VERTEX_SHADER:
|
|
shaderSlot = &mVertShader;
|
|
break;
|
|
case LOCAL_GL_FRAGMENT_SHADER:
|
|
shaderSlot = &mFragShader;
|
|
break;
|
|
default:
|
|
mContext->ErrorInvalidOperation("attachShader: Bad type for shader.");
|
|
return;
|
|
}
|
|
|
|
if (*shaderSlot != shader) {
|
|
mContext->ErrorInvalidOperation("detachShader: `shader` is not attached.");
|
|
return;
|
|
}
|
|
|
|
*shaderSlot = nullptr;
|
|
|
|
mContext->MakeContextCurrent();
|
|
mContext->gl->fDetachShader(mGLName, shader->mGLName);
|
|
}
|
|
|
|
already_AddRefed<WebGLActiveInfo>
|
|
WebGLProgram::GetActiveAttrib(GLuint index) const
|
|
{
|
|
if (!mMostRecentLinkInfo) {
|
|
RefPtr<WebGLActiveInfo> ret = WebGLActiveInfo::CreateInvalid(mContext);
|
|
return ret.forget();
|
|
}
|
|
|
|
const auto& activeList = mMostRecentLinkInfo->activeAttribs;
|
|
|
|
if (index >= activeList.size()) {
|
|
mContext->ErrorInvalidValue("`index` (%i) must be less than %s (%i).",
|
|
index, "ACTIVE_ATTRIBS", activeList.size());
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<WebGLActiveInfo> ret = activeList[index];
|
|
return ret.forget();
|
|
}
|
|
|
|
already_AddRefed<WebGLActiveInfo>
|
|
WebGLProgram::GetActiveUniform(GLuint index) const
|
|
{
|
|
if (!mMostRecentLinkInfo) {
|
|
// According to the spec, this can return null.
|
|
RefPtr<WebGLActiveInfo> ret = WebGLActiveInfo::CreateInvalid(mContext);
|
|
return ret.forget();
|
|
}
|
|
|
|
const auto& activeList = mMostRecentLinkInfo->activeUniforms;
|
|
|
|
if (index >= activeList.size()) {
|
|
mContext->ErrorInvalidValue("`index` (%i) must be less than %s (%i).",
|
|
index, "ACTIVE_UNIFORMS", activeList.size());
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<WebGLActiveInfo> ret = activeList[index];
|
|
return ret.forget();
|
|
}
|
|
|
|
void
|
|
WebGLProgram::GetAttachedShaders(nsTArray<RefPtr<WebGLShader>>* const out) const
|
|
{
|
|
out->TruncateLength(0);
|
|
|
|
if (mVertShader)
|
|
out->AppendElement(mVertShader);
|
|
|
|
if (mFragShader)
|
|
out->AppendElement(mFragShader);
|
|
}
|
|
|
|
GLint
|
|
WebGLProgram::GetAttribLocation(const nsAString& userName_wide) const
|
|
{
|
|
if (!ValidateGLSLVariableName(userName_wide, mContext, "getAttribLocation"))
|
|
return -1;
|
|
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getAttribLocation: `program` must be linked.");
|
|
return -1;
|
|
}
|
|
|
|
const NS_LossyConvertUTF16toASCII userName(userName_wide);
|
|
|
|
const WebGLActiveInfo* info;
|
|
if (!LinkInfo()->FindAttrib(userName, &info))
|
|
return -1;
|
|
|
|
const nsCString& mappedName = info->mBaseMappedName;
|
|
|
|
gl::GLContext* gl = mContext->GL();
|
|
gl->MakeCurrent();
|
|
|
|
return gl->fGetAttribLocation(mGLName, mappedName.BeginReading());
|
|
}
|
|
|
|
GLint
|
|
WebGLProgram::GetFragDataLocation(const nsAString& userName_wide) const
|
|
{
|
|
if (!ValidateGLSLVariableName(userName_wide, mContext, "getFragDataLocation"))
|
|
return -1;
|
|
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getFragDataLocation: `program` must be linked.");
|
|
return -1;
|
|
}
|
|
|
|
const NS_LossyConvertUTF16toASCII userName(userName_wide);
|
|
|
|
nsCString mappedName;
|
|
if (!FindActiveOutputMappedNameByUserName(userName, &mappedName)) {
|
|
mappedName = userName;
|
|
}
|
|
|
|
gl::GLContext* gl = mContext->GL();
|
|
gl->MakeCurrent();
|
|
|
|
return gl->fGetFragDataLocation(mGLName, mappedName.BeginReading());
|
|
}
|
|
|
|
void
|
|
WebGLProgram::GetProgramInfoLog(nsAString* const out) const
|
|
{
|
|
CopyASCIItoUTF16(mLinkLog, *out);
|
|
}
|
|
|
|
static GLint
|
|
GetProgramiv(gl::GLContext* gl, GLuint program, GLenum pname)
|
|
{
|
|
GLint ret = 0;
|
|
gl->fGetProgramiv(program, pname, &ret);
|
|
return ret;
|
|
}
|
|
|
|
JS::Value
|
|
WebGLProgram::GetProgramParameter(GLenum pname) const
|
|
{
|
|
gl::GLContext* gl = mContext->gl;
|
|
gl->MakeCurrent();
|
|
|
|
if (mContext->IsWebGL2()) {
|
|
switch (pname) {
|
|
case LOCAL_GL_ACTIVE_UNIFORM_BLOCKS:
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
|
|
return JS::Int32Value(GetProgramiv(gl, mGLName, pname));
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_VARYINGS:
|
|
return JS::Int32Value(mTransformFeedbackVaryings.size());
|
|
}
|
|
}
|
|
|
|
switch (pname) {
|
|
case LOCAL_GL_ATTACHED_SHADERS:
|
|
case LOCAL_GL_ACTIVE_UNIFORMS:
|
|
case LOCAL_GL_ACTIVE_ATTRIBUTES:
|
|
return JS::Int32Value(GetProgramiv(gl, mGLName, pname));
|
|
|
|
case LOCAL_GL_DELETE_STATUS:
|
|
return JS::BooleanValue(IsDeleteRequested());
|
|
|
|
case LOCAL_GL_LINK_STATUS:
|
|
return JS::BooleanValue(IsLinked());
|
|
|
|
case LOCAL_GL_VALIDATE_STATUS:
|
|
#ifdef XP_MACOSX
|
|
// See comment in ValidateProgram.
|
|
if (gl->WorkAroundDriverBugs())
|
|
return JS::BooleanValue(true);
|
|
#endif
|
|
return JS::BooleanValue(bool(GetProgramiv(gl, mGLName, pname)));
|
|
|
|
default:
|
|
mContext->ErrorInvalidEnumInfo("getProgramParameter: `pname`",
|
|
pname);
|
|
return JS::NullValue();
|
|
}
|
|
}
|
|
|
|
GLuint
|
|
WebGLProgram::GetUniformBlockIndex(const nsAString& userName_wide) const
|
|
{
|
|
if (!ValidateGLSLVariableName(userName_wide, mContext, "getUniformBlockIndex"))
|
|
return LOCAL_GL_INVALID_INDEX;
|
|
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getUniformBlockIndex: `program` must be linked.");
|
|
return LOCAL_GL_INVALID_INDEX;
|
|
}
|
|
|
|
const NS_LossyConvertUTF16toASCII userName(userName_wide);
|
|
|
|
nsDependentCString baseUserName;
|
|
bool isArray;
|
|
size_t arrayIndex;
|
|
if (!ParseName(userName, &baseUserName, &isArray, &arrayIndex))
|
|
return LOCAL_GL_INVALID_INDEX;
|
|
|
|
RefPtr<const webgl::UniformBlockInfo> info;
|
|
if (!LinkInfo()->FindUniformBlock(baseUserName, &info)) {
|
|
return LOCAL_GL_INVALID_INDEX;
|
|
}
|
|
|
|
const nsCString& baseMappedName = info->mBaseMappedName;
|
|
nsAutoCString mappedName(baseMappedName);
|
|
if (isArray) {
|
|
mappedName.AppendLiteral("[");
|
|
mappedName.AppendInt(uint32_t(arrayIndex));
|
|
mappedName.AppendLiteral("]");
|
|
}
|
|
|
|
gl::GLContext* gl = mContext->GL();
|
|
gl->MakeCurrent();
|
|
|
|
return gl->fGetUniformBlockIndex(mGLName, mappedName.BeginReading());
|
|
}
|
|
|
|
void
|
|
WebGLProgram::GetActiveUniformBlockName(GLuint uniformBlockIndex, nsAString& retval) const
|
|
{
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getActiveUniformBlockName: `program` must be linked.");
|
|
return;
|
|
}
|
|
|
|
const webgl::LinkedProgramInfo* linkInfo = LinkInfo();
|
|
GLuint uniformBlockCount = (GLuint) linkInfo->uniformBlocks.size();
|
|
if (uniformBlockIndex >= uniformBlockCount) {
|
|
mContext->ErrorInvalidValue("getActiveUniformBlockName: index %u invalid.", uniformBlockIndex);
|
|
return;
|
|
}
|
|
|
|
const webgl::UniformBlockInfo* blockInfo = linkInfo->uniformBlocks[uniformBlockIndex];
|
|
|
|
retval.Assign(NS_ConvertASCIItoUTF16(blockInfo->mBaseUserName));
|
|
}
|
|
|
|
void
|
|
WebGLProgram::GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname,
|
|
dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval) const
|
|
{
|
|
retval.SetNull();
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getActiveUniformBlockParameter: `program` must be linked.");
|
|
return;
|
|
}
|
|
|
|
const webgl::LinkedProgramInfo* linkInfo = LinkInfo();
|
|
GLuint uniformBlockCount = (GLuint)linkInfo->uniformBlocks.size();
|
|
if (uniformBlockIndex >= uniformBlockCount) {
|
|
mContext->ErrorInvalidValue("getActiveUniformBlockParameter: index %u invalid.", uniformBlockIndex);
|
|
return;
|
|
}
|
|
|
|
gl::GLContext* gl = mContext->GL();
|
|
GLint param = 0;
|
|
|
|
switch (pname) {
|
|
case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
|
|
case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
|
|
gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex, pname, ¶m);
|
|
retval.SetValue().SetAsBoolean() = (param != 0);
|
|
return;
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_BINDING:
|
|
case LOCAL_GL_UNIFORM_BLOCK_DATA_SIZE:
|
|
case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
|
|
gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex, pname, ¶m);
|
|
retval.SetValue().SetAsUnsignedLong() = param;
|
|
return;
|
|
}
|
|
}
|
|
|
|
void
|
|
WebGLProgram::GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex,
|
|
dom::Nullable<dom::OwningUnsignedLongOrUint32ArrayOrBoolean>& retval,
|
|
ErrorResult& rv) const
|
|
{
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getActiveUniformBlockParameter: `program` must be linked.");
|
|
return;
|
|
}
|
|
|
|
const webgl::LinkedProgramInfo* linkInfo = LinkInfo();
|
|
GLuint uniformBlockCount = (GLuint)linkInfo->uniformBlocks.size();
|
|
if (uniformBlockIndex >= uniformBlockCount) {
|
|
mContext->ErrorInvalidValue("getActiveUniformBlockParameter: index %u invalid.", uniformBlockIndex);
|
|
return;
|
|
}
|
|
|
|
gl::GLContext* gl = mContext->GL();
|
|
GLint activeUniformCount = 0;
|
|
gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex,
|
|
LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS,
|
|
&activeUniformCount);
|
|
JS::RootedObject obj(cx, dom::Uint32Array::Create(cx, mContext, activeUniformCount,
|
|
nullptr));
|
|
if (!obj) {
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
return;
|
|
}
|
|
|
|
dom::Uint32Array result;
|
|
DebugOnly<bool> inited = result.Init(obj);
|
|
MOZ_ASSERT(inited);
|
|
result.ComputeLengthAndData();
|
|
gl->fGetActiveUniformBlockiv(mGLName, uniformBlockIndex,
|
|
LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES,
|
|
(GLint*)result.Data());
|
|
|
|
inited = retval.SetValue().SetAsUint32Array().Init(obj);
|
|
MOZ_ASSERT(inited);
|
|
}
|
|
|
|
already_AddRefed<WebGLUniformLocation>
|
|
WebGLProgram::GetUniformLocation(const nsAString& userName_wide) const
|
|
{
|
|
if (!ValidateGLSLVariableName(userName_wide, mContext, "getUniformLocation"))
|
|
return nullptr;
|
|
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getUniformLocation: `program` must be linked.");
|
|
return nullptr;
|
|
}
|
|
|
|
const NS_LossyConvertUTF16toASCII userName(userName_wide);
|
|
|
|
nsDependentCString baseUserName;
|
|
bool isArray;
|
|
size_t arrayIndex;
|
|
if (!ParseName(userName, &baseUserName, &isArray, &arrayIndex))
|
|
return nullptr;
|
|
|
|
const WebGLActiveInfo* activeInfo;
|
|
if (!LinkInfo()->FindUniform(baseUserName, &activeInfo))
|
|
return nullptr;
|
|
|
|
const nsCString& baseMappedName = activeInfo->mBaseMappedName;
|
|
|
|
nsAutoCString mappedName(baseMappedName);
|
|
if (isArray) {
|
|
mappedName.AppendLiteral("[");
|
|
mappedName.AppendInt(uint32_t(arrayIndex));
|
|
mappedName.AppendLiteral("]");
|
|
}
|
|
|
|
gl::GLContext* gl = mContext->GL();
|
|
gl->MakeCurrent();
|
|
|
|
GLint loc = gl->fGetUniformLocation(mGLName, mappedName.BeginReading());
|
|
if (loc == -1)
|
|
return nullptr;
|
|
|
|
RefPtr<WebGLUniformLocation> locObj = new WebGLUniformLocation(mContext, LinkInfo(),
|
|
loc, activeInfo);
|
|
return locObj.forget();
|
|
}
|
|
|
|
void
|
|
WebGLProgram::GetUniformIndices(const dom::Sequence<nsString>& uniformNames,
|
|
dom::Nullable< nsTArray<GLuint> >& retval) const
|
|
{
|
|
size_t count = uniformNames.Length();
|
|
nsTArray<GLuint>& arr = retval.SetValue();
|
|
|
|
gl::GLContext* gl = mContext->GL();
|
|
gl->MakeCurrent();
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
const NS_LossyConvertUTF16toASCII userName(uniformNames[i]);
|
|
|
|
nsDependentCString baseUserName;
|
|
bool isArray;
|
|
size_t arrayIndex;
|
|
if (!ParseName(userName, &baseUserName, &isArray, &arrayIndex)) {
|
|
arr.AppendElement(LOCAL_GL_INVALID_INDEX);
|
|
continue;
|
|
}
|
|
|
|
const WebGLActiveInfo* activeInfo;
|
|
if (!LinkInfo()->FindUniform(baseUserName, &activeInfo)) {
|
|
arr.AppendElement(LOCAL_GL_INVALID_INDEX);
|
|
continue;
|
|
}
|
|
|
|
const nsCString& baseMappedName = activeInfo->mBaseMappedName;
|
|
|
|
nsAutoCString mappedName(baseMappedName);
|
|
if (isArray) {
|
|
mappedName.AppendLiteral("[");
|
|
mappedName.AppendInt(uint32_t(arrayIndex));
|
|
mappedName.AppendLiteral("]");
|
|
}
|
|
|
|
const GLchar* mappedNameBytes = mappedName.BeginReading();
|
|
|
|
GLuint index = 0;
|
|
gl->fGetUniformIndices(mGLName, 1, &mappedNameBytes, &index);
|
|
arr.AppendElement(index);
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
WebGLProgram::UniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) const
|
|
{
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getActiveUniformBlockName: `program` must be linked.");
|
|
return;
|
|
}
|
|
|
|
const webgl::LinkedProgramInfo* linkInfo = LinkInfo();
|
|
GLuint uniformBlockCount = (GLuint)linkInfo->uniformBlocks.size();
|
|
if (uniformBlockIndex >= uniformBlockCount) {
|
|
mContext->ErrorInvalidValue("getActiveUniformBlockName: index %u invalid.", uniformBlockIndex);
|
|
return;
|
|
}
|
|
|
|
if (uniformBlockBinding > mContext->mGLMaxUniformBufferBindings) {
|
|
mContext->ErrorInvalidEnum("getActiveUniformBlockName: binding %u invalid.", uniformBlockBinding);
|
|
return;
|
|
}
|
|
|
|
gl::GLContext* gl = mContext->GL();
|
|
gl->MakeCurrent();
|
|
gl->fUniformBlockBinding(mGLName, uniformBlockIndex, uniformBlockBinding);
|
|
}
|
|
|
|
void
|
|
WebGLProgram::LinkProgram()
|
|
{
|
|
mContext->InvalidateBufferFetching(); // we do it early in this function
|
|
// as some of the validation below changes program state
|
|
|
|
mLinkLog.Truncate();
|
|
mMostRecentLinkInfo = nullptr;
|
|
|
|
if (!mVertShader || !mVertShader->IsCompiled()) {
|
|
mLinkLog.AssignLiteral("Must have a compiled vertex shader attached.");
|
|
mContext->GenerateWarning("linkProgram: %s", mLinkLog.BeginReading());
|
|
return;
|
|
}
|
|
|
|
if (!mFragShader || !mFragShader->IsCompiled()) {
|
|
mLinkLog.AssignLiteral("Must have an compiled fragment shader attached.");
|
|
mContext->GenerateWarning("linkProgram: %s", mLinkLog.BeginReading());
|
|
return;
|
|
}
|
|
|
|
if (!mFragShader->CanLinkTo(mVertShader, &mLinkLog)) {
|
|
mContext->GenerateWarning("linkProgram: %s", mLinkLog.BeginReading());
|
|
return;
|
|
}
|
|
|
|
gl::GLContext* gl = mContext->gl;
|
|
gl->MakeCurrent();
|
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
|
mContext->mIsMesa)
|
|
{
|
|
// Bug 777028: Mesa can't handle more than 16 samplers per program,
|
|
// counting each array entry.
|
|
size_t numSamplerUniforms_upperBound = mVertShader->CalcNumSamplerUniforms() +
|
|
mFragShader->CalcNumSamplerUniforms();
|
|
if (numSamplerUniforms_upperBound > 16) {
|
|
mLinkLog.AssignLiteral("Programs with more than 16 samplers are disallowed on"
|
|
" Mesa drivers to avoid crashing.");
|
|
mContext->GenerateWarning("linkProgram: %s", mLinkLog.BeginReading());
|
|
return;
|
|
}
|
|
|
|
// Bug 1203135: Mesa crashes internally if we exceed the reported maximum attribute count.
|
|
if (mVertShader->NumAttributes() > mContext->MaxVertexAttribs()) {
|
|
mLinkLog.AssignLiteral("Number of attributes exceeds Mesa's reported max attribute count.");
|
|
mContext->GenerateWarning("linkProgram: %s", mLinkLog.BeginReading());
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Bind the attrib locations.
|
|
// This can't be done trivially, because we have to deal with mapped attrib names.
|
|
for (auto itr = mBoundAttribLocs.begin(); itr != mBoundAttribLocs.end(); ++itr) {
|
|
const nsCString& name = itr->first;
|
|
GLuint index = itr->second;
|
|
|
|
mVertShader->BindAttribLocation(mGLName, name, index);
|
|
}
|
|
|
|
if (!mTransformFeedbackVaryings.empty()) {
|
|
// Bind the transform feedback varyings.
|
|
// This can't be done trivially, because we have to deal with mapped names too.
|
|
mVertShader->ApplyTransformFeedbackVaryings(mGLName,
|
|
mTransformFeedbackVaryings,
|
|
mTransformFeedbackBufferMode,
|
|
&mTempMappedVaryings);
|
|
}
|
|
|
|
LinkAndUpdate();
|
|
if (IsLinked()) {
|
|
// Check if the attrib name conflicting to uniform name
|
|
for (const auto& uniform : mMostRecentLinkInfo->uniformMap) {
|
|
if (mMostRecentLinkInfo->attribMap.find(uniform.first) != mMostRecentLinkInfo->attribMap.end()) {
|
|
mLinkLog = nsPrintfCString("The uniform name (%s) conflicts with attribute name.",
|
|
uniform.first.get());
|
|
mMostRecentLinkInfo = nullptr;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (mMostRecentLinkInfo)
|
|
return;
|
|
|
|
// Failed link.
|
|
if (mContext->ShouldGenerateWarnings()) {
|
|
// report shader/program infoLogs as warnings.
|
|
// note that shader compilation errors can be deferred to linkProgram,
|
|
// which is why we can't do anything in compileShader. In practice we could
|
|
// report in compileShader the translation errors generated by ANGLE,
|
|
// but it seems saner to keep a single way of obtaining shader infologs.
|
|
if (!mLinkLog.IsEmpty()) {
|
|
mContext->GenerateWarning("linkProgram: Failed to link, leaving the following"
|
|
" log:\n%s\n",
|
|
mLinkLog.BeginReading());
|
|
}
|
|
}
|
|
}
|
|
|
|
bool
|
|
WebGLProgram::UseProgram() const
|
|
{
|
|
if (!mMostRecentLinkInfo) {
|
|
mContext->ErrorInvalidOperation("useProgram: Program has not been successfully"
|
|
" linked.");
|
|
return false;
|
|
}
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->InvalidateBufferFetching();
|
|
|
|
mContext->gl->fUseProgram(mGLName);
|
|
return true;
|
|
}
|
|
|
|
void
|
|
WebGLProgram::ValidateProgram() const
|
|
{
|
|
mContext->MakeContextCurrent();
|
|
gl::GLContext* gl = mContext->gl;
|
|
|
|
#ifdef XP_MACOSX
|
|
// See bug 593867 for NVIDIA and bug 657201 for ATI. The latter is confirmed
|
|
// with Mac OS 10.6.7.
|
|
if (gl->WorkAroundDriverBugs()) {
|
|
mContext->GenerateWarning("validateProgram: Implemented as a no-op on"
|
|
" Mac to work around crashes.");
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
gl->fValidateProgram(mGLName);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
WebGLProgram::LinkAndUpdate()
|
|
{
|
|
mMostRecentLinkInfo = nullptr;
|
|
|
|
gl::GLContext* gl = mContext->gl;
|
|
gl->fLinkProgram(mGLName);
|
|
|
|
// Grab the program log.
|
|
GLuint logLenWithNull = 0;
|
|
gl->fGetProgramiv(mGLName, LOCAL_GL_INFO_LOG_LENGTH, (GLint*)&logLenWithNull);
|
|
if (logLenWithNull > 1) {
|
|
mLinkLog.SetLength(logLenWithNull - 1);
|
|
gl->fGetProgramInfoLog(mGLName, logLenWithNull, nullptr, mLinkLog.BeginWriting());
|
|
} else {
|
|
mLinkLog.SetLength(0);
|
|
}
|
|
|
|
// Post link, temporary mapped varying names for transform feedback can be discarded.
|
|
// The memory can only be deleted after log is queried or the link status will fail.
|
|
std::vector<std::string> empty;
|
|
empty.swap(mTempMappedVaryings);
|
|
|
|
GLint ok = 0;
|
|
gl->fGetProgramiv(mGLName, LOCAL_GL_LINK_STATUS, &ok);
|
|
if (!ok)
|
|
return;
|
|
|
|
mMostRecentLinkInfo = QueryProgramInfo(this, gl);
|
|
MOZ_RELEASE_ASSERT(mMostRecentLinkInfo);
|
|
}
|
|
|
|
bool
|
|
WebGLProgram::FindActiveOutputMappedNameByUserName(const nsACString& userName,
|
|
nsCString* const out_mappedName) const
|
|
{
|
|
if (mFragShader->FindActiveOutputMappedNameByUserName(userName, out_mappedName)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
WebGLProgram::FindAttribUserNameByMappedName(const nsACString& mappedName,
|
|
nsDependentCString* const out_userName) const
|
|
{
|
|
if (mVertShader->FindAttribUserNameByMappedName(mappedName, out_userName))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
WebGLProgram::FindVaryingByMappedName(const nsACString& mappedName,
|
|
nsCString* const out_userName,
|
|
bool* const out_isArray) const
|
|
{
|
|
if (mVertShader->FindVaryingByMappedName(mappedName, out_userName, out_isArray))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
bool
|
|
WebGLProgram::FindUniformByMappedName(const nsACString& mappedName,
|
|
nsCString* const out_userName,
|
|
bool* const out_isArray) const
|
|
{
|
|
if (mVertShader->FindUniformByMappedName(mappedName, out_userName, out_isArray))
|
|
return true;
|
|
|
|
if (mFragShader->FindUniformByMappedName(mappedName, out_userName, out_isArray))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
void
|
|
WebGLProgram::TransformFeedbackVaryings(const dom::Sequence<nsString>& varyings,
|
|
GLenum bufferMode)
|
|
{
|
|
if (bufferMode != LOCAL_GL_INTERLEAVED_ATTRIBS &&
|
|
bufferMode != LOCAL_GL_SEPARATE_ATTRIBS)
|
|
{
|
|
mContext->ErrorInvalidEnum("transformFeedbackVaryings: `bufferMode` %s is "
|
|
"invalid. Must be one of gl.INTERLEAVED_ATTRIBS or "
|
|
"gl.SEPARATE_ATTRIBS.",
|
|
mContext->EnumName(bufferMode));
|
|
return;
|
|
}
|
|
|
|
size_t varyingsCount = varyings.Length();
|
|
if (bufferMode == LOCAL_GL_SEPARATE_ATTRIBS &&
|
|
varyingsCount >= mContext->mGLMaxTransformFeedbackSeparateAttribs)
|
|
{
|
|
mContext->ErrorInvalidValue("transformFeedbackVaryings: Number of `varyings` exc"
|
|
"eeds gl.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS.");
|
|
return;
|
|
}
|
|
|
|
std::vector<nsCString> asciiVaryings;
|
|
for (size_t i = 0; i < varyingsCount; i++) {
|
|
if (!ValidateGLSLVariableName(varyings[i], mContext, "transformFeedbackVaryings"))
|
|
return;
|
|
|
|
NS_LossyConvertUTF16toASCII asciiName(varyings[i]);
|
|
asciiVaryings.push_back(asciiName);
|
|
}
|
|
|
|
// All validated. Translate the strings and store them until
|
|
// program linking.
|
|
mTransformFeedbackBufferMode = bufferMode;
|
|
mTransformFeedbackVaryings.swap(asciiVaryings);
|
|
}
|
|
|
|
already_AddRefed<WebGLActiveInfo>
|
|
WebGLProgram::GetTransformFeedbackVarying(GLuint index)
|
|
{
|
|
// No docs in the WebGL 2 spec for this function. Taking the language for
|
|
// getActiveAttrib, which states that the function returns null on any error.
|
|
if (!IsLinked()) {
|
|
mContext->ErrorInvalidOperation("getTransformFeedbackVarying: `program` must be "
|
|
"linked.");
|
|
return nullptr;
|
|
}
|
|
|
|
if (index >= LinkInfo()->transformFeedbackVaryings.size()) {
|
|
mContext->ErrorInvalidValue("getTransformFeedbackVarying: `index` is greater or "
|
|
"equal to TRANSFORM_FEEDBACK_VARYINGS.");
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<WebGLActiveInfo> ret = LinkInfo()->transformFeedbackVaryings[index];
|
|
return ret.forget();
|
|
}
|
|
|
|
bool
|
|
WebGLProgram::FindUniformBlockByMappedName(const nsACString& mappedName,
|
|
nsCString* const out_userName,
|
|
bool* const out_isArray) const
|
|
{
|
|
if (mVertShader->FindUniformBlockByMappedName(mappedName, out_userName, out_isArray))
|
|
return true;
|
|
|
|
if (mFragShader->FindUniformBlockByMappedName(mappedName, out_userName, out_isArray))
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
JSObject*
|
|
WebGLProgram::WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto)
|
|
{
|
|
return dom::WebGLProgramBinding::Wrap(js, this, givenProto);
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebGLProgram, mVertShader, mFragShader)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLProgram, AddRef)
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLProgram, Release)
|
|
|
|
} // namespace mozilla
|