Bug 1248580 - strip the uploading element num according to the uniform array size. r=jgilbert a=ritu
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -490,19 +490,20 @@ WebGLContext::ValidateUniformArraySetter
return false;
if (!loc->ValidateSizeAndType(setterElemSize, setterType, this, funcName))
return false;
if (!loc->ValidateArrayLength(setterElemSize, setterArraySize, this, funcName))
return false;
+ MOZ_ASSERT((size_t)loc->mActiveInfo->mElemCount > loc->mArrayIndex);
+ size_t uniformElemCount = loc->mActiveInfo->mElemCount - loc->mArrayIndex;
*out_rawLoc = loc->mLoc;
- *out_numElementsToUpload = std::min((size_t)loc->mActiveInfo->mElemCount,
- setterArraySize / setterElemSize);
+ *out_numElementsToUpload = std::min(uniformElemCount, setterArraySize / setterElemSize);
return true;
}
bool
WebGLContext::ValidateUniformMatrixArraySetter(WebGLUniformLocation* loc,
uint8_t setterCols,
uint8_t setterRows,
GLenum setterType,
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -780,18 +780,24 @@ WebGLProgram::GetUniformLocation(const n
if (!IsLinked()) {
mContext->ErrorInvalidOperation("getUniformLocation: `program` must be linked.");
return nullptr;
}
const NS_LossyConvertUTF16toASCII userName(userName_wide);
nsDependentCString baseUserName;
- bool isArray;
- size_t arrayIndex;
+ bool isArray = false;
+ // GLES 2.0.25, Section 2.10, p35
+ // If the the uniform location is an array, then the location of the first
+ // element of that array can be retrieved by either using the name of the
+ // uniform array, or the name of the uniform array appended with "[0]".
+ // The ParseName() can't recognize this rule. So always initialize
+ // arrayIndex with 0.
+ size_t arrayIndex = 0;
if (!ParseName(userName, &baseUserName, &isArray, &arrayIndex))
return nullptr;
const WebGLActiveInfo* activeInfo;
if (!LinkInfo()->FindUniform(baseUserName, &activeInfo))
return nullptr;
const nsCString& baseMappedName = activeInfo->mBaseMappedName;
@@ -806,17 +812,18 @@ WebGLProgram::GetUniformLocation(const n
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);
+ loc, arrayIndex,
+ activeInfo);
return locObj.forget();
}
void
WebGLProgram::GetUniformIndices(const dom::Sequence<nsString>& uniformNames,
dom::Nullable< nsTArray<GLuint> >& retval) const
{
size_t count = uniformNames.Length();
--- a/dom/canvas/WebGLUniformLocation.cpp
+++ b/dom/canvas/WebGLUniformLocation.cpp
@@ -11,20 +11,23 @@
#include "WebGLActiveInfo.h"
#include "WebGLContext.h"
#include "WebGLProgram.h"
namespace mozilla {
WebGLUniformLocation::WebGLUniformLocation(WebGLContext* webgl,
const webgl::LinkedProgramInfo* linkInfo,
- GLuint loc, const WebGLActiveInfo* activeInfo)
+ GLuint loc,
+ size_t arrayIndex,
+ const WebGLActiveInfo* activeInfo)
: WebGLContextBoundObject(webgl)
, mLinkInfo(linkInfo)
, mLoc(loc)
+ , mArrayIndex(arrayIndex)
, mActiveInfo(activeInfo)
{ }
WebGLUniformLocation::~WebGLUniformLocation()
{ }
bool
WebGLUniformLocation::ValidateForProgram(WebGLProgram* prog, WebGLContext* webgl,
--- a/dom/canvas/WebGLUniformLocation.h
+++ b/dom/canvas/WebGLUniformLocation.h
@@ -36,20 +36,21 @@ public:
virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
WebGLContext* GetParentObject() const {
return mContext;
}
const WeakPtr<const webgl::LinkedProgramInfo> mLinkInfo;
const GLuint mLoc;
+ const size_t mArrayIndex;
const WebGLActiveInfo* const mActiveInfo;
WebGLUniformLocation(WebGLContext* webgl, const webgl::LinkedProgramInfo* linkInfo,
- GLuint loc, const WebGLActiveInfo* activeInfo);
+ GLuint loc, size_t arrayIndex, const WebGLActiveInfo* activeInfo);
bool ValidateForProgram(WebGLProgram* prog, WebGLContext* webgl,
const char* funcName) const;
bool ValidateSamplerSetter(GLint value, WebGLContext* webgl,
const char* funcName) const;
bool ValidateSizeAndType(uint8_t setterElemSize, GLenum setterType,
WebGLContext* webgl, const char* funcName) const;
bool ValidateArrayLength(uint8_t setterElemSize, size_t setterArraySize,