Skip to content

Commit

Permalink
context error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishab87 committed Dec 24, 2024
1 parent 7de0a53 commit 2318e5b
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/webgl/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,22 @@ function material(p5, fn){
* @alt
* A rectangle with a shader applied to it.
*/
p5.prototype.loadFilterShader = async function (fragFilename, successCallback, failureCallback) {
fn.loadFilterShader = async function (fragFilename, successCallback, failureCallback) {
p5._validateParameters('loadFilterShader', arguments);
try {
// Define the default vertex shaders for different WebGL versions

// Load the fragment shader
const fragSrc = await this.loadStrings(fragFilename);
const fragString = await fragSrc.join('\n');

// Create the shader using createFilterShader
const loadedShader = this.createFilterShader(fragString);

const loadedShader = this.createFilterShader(fragString, true);

if (this._renderer.GL) {
loadedShader.ensureCompiledOnContext(this._renderer);
} else {
loadedShader.ensureCompiledOnContext(this);
}

if (successCallback) {
successCallback(loadedShader);
}
Expand All @@ -569,7 +574,7 @@ function material(p5, fn){
if (failureCallback) {
failureCallback(err);
} else {
console.error(err);
console.error(err);
}
}
};
Expand Down Expand Up @@ -664,7 +669,7 @@ function material(p5, fn){
* </code>
* </div>
*/
fn.createFilterShader = function (fragSrc) {
fn.createFilterShader = function (fragSrc, skipContextCheck = false) {
p5._validateParameters('createFilterShader', arguments);
let defaultVertV1 = `
uniform mat4 uModelViewMatrix;
Expand Down Expand Up @@ -708,10 +713,12 @@ function material(p5, fn){
`;
let vertSrc = fragSrc.includes('#version 300 es') ? defaultVertV2 : defaultVertV1;
const shader = new Shader(this._renderer, vertSrc, fragSrc);
if (this._renderer.GL) {
shader.ensureCompiledOnContext(this._renderer);
} else {
shader.ensureCompiledOnContext(this);
if (!skipContextCheck) {
if (this._renderer.GL) {
shader.ensureCompiledOnContext(this._renderer);
} else {
shader.ensureCompiledOnContext(this);
}
}
return shader;
};
Expand Down

0 comments on commit 2318e5b

Please sign in to comment.