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 = 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; 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, arrayIndex, activeInfo); return locObj.forget(); }
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::UniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) const { const char funcName[] = "getActiveUniformBlockName"; if (!IsLinked()) { mContext->ErrorInvalidOperation("%s: `program` must be linked.", funcName); return; } const auto& uniformBlocks = LinkInfo()->uniformBlocks; if (uniformBlockIndex >= uniformBlocks.size()) { mContext->ErrorInvalidValue("%s: Index %u invalid.", funcName, uniformBlockIndex); return; } const auto& uniformBlock = uniformBlocks[uniformBlockIndex]; const auto& indexedBindings = mContext->mIndexedUniformBufferBindings; if (uniformBlockBinding >= indexedBindings.size()) { mContext->ErrorInvalidValue("%s: Binding %u invalid.", funcName, uniformBlockBinding); return; } const auto& indexedBinding = indexedBindings[uniformBlockBinding]; //// gl::GLContext* gl = mContext->GL(); gl->MakeCurrent(); gl->fUniformBlockBinding(mGLName, uniformBlockIndex, uniformBlockBinding); //// uniformBlock->mBinding = &indexedBinding; }
JS::Value WebGLProgram::GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname) const { if (!IsLinked()) { mContext->ErrorInvalidOperation("getActiveUniformBlockParameter: `program` must be linked."); return JS::NullValue(); } const webgl::LinkedProgramInfo* linkInfo = LinkInfo(); GLuint uniformBlockCount = (GLuint)linkInfo->uniformBlocks.size(); if (uniformBlockIndex >= uniformBlockCount) { mContext->ErrorInvalidValue("getActiveUniformBlockParameter: index %u invalid.", uniformBlockIndex); return JS::NullValue(); } 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); return JS::BooleanValue(bool(param)); 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); return JS::NumberValue(param); default: MOZ_CRASH("bad `pname`."); } }
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 >= mTransformFeedbackVaryings.size()) { mContext->ErrorInvalidValue("getTransformFeedbackVarying: `index` is greater or " "equal to TRANSFORM_FEEDBACK_VARYINGS."); return nullptr; } const nsCString& varyingUserName = mTransformFeedbackVaryings[index]; WebGLActiveInfo* info; LinkInfo()->FindAttrib(varyingUserName, (const WebGLActiveInfo**) &info); MOZ_ASSERT(info); RefPtr<WebGLActiveInfo> ret(info); return ret.forget(); }
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 InterpositionServer::injectClient(Ref<EnvMap> map) { map->insert("CODETIPS_SOCKET", socketPath()); String libPath = LinkInfo((void*)&codetips_hook).libraryPath().replace("codetips.", "codetipsclient."); #ifdef __MACH__ map->insert("DYLD_FORCE_FLAT_NAMESPACE", ""); map->insert("DYLD_INSERT_LIBRARIES", libPath); #else map->insert("LD_PRELOAD", libPath); #endif }
void WebGLProgram::GetUniformIndices(const dom::Sequence<nsString>& uniformNames, dom::Nullable< nsTArray<GLuint> >& retval) const { const char funcName[] = "getUniformIndices"; if (!IsLinked()) { mContext->ErrorInvalidOperation("%s: `program` must be linked.", funcName); return; } 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; } webgl::UniformInfo* info; if (!LinkInfo()->FindUniform(baseUserName, &info)) { arr.AppendElement(LOCAL_GL_INVALID_INDEX); continue; } nsAutoCString mappedName(info->mActiveInfo->mBaseMappedName); 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::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)); }
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 webgl::AttribInfo* info; if (!LinkInfo()->FindAttrib(userName, &info)) return -1; return GLint(info->mLoc); }
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); }
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 (!LinkInfo()->FindFragData(userName, &mappedName)) return -1; gl::GLContext* gl = mContext->GL(); gl->MakeCurrent(); return gl->fGetFragDataLocation(mGLName, mappedName.BeginReading()); }
JS::Value WebGLProgram::GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex, ErrorResult* const out_error) const { const char funcName[] = "getActiveUniformBlockParameter"; if (!IsLinked()) { mContext->ErrorInvalidOperation("%s: `program` must be linked.", funcName); return JS::NullValue(); } const webgl::LinkedProgramInfo* linkInfo = LinkInfo(); GLuint uniformBlockCount = (GLuint)linkInfo->uniformBlocks.size(); if (uniformBlockIndex >= uniformBlockCount) { mContext->ErrorInvalidValue("%s: Index %u invalid.", funcName, uniformBlockIndex); return JS::NullValue(); } 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) { *out_error = NS_ERROR_OUT_OF_MEMORY; return JS::NullValue(); } 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()); return JS::ObjectValue(*obj); }
void WebGLProgram::UniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) const { if (!IsLinked()) { mContext->ErrorInvalidOperation("getActiveUniformBlockName: `program` must be linked."); return; } const webgl::LinkedProgramInfo* linkInfo = LinkInfo(); if (uniformBlockIndex >= linkInfo->uniformBlocks.size()) { 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); }
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()); }