Skip to content

Commit

Permalink
Ohghi Syndrome
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Orangemoon authored Jul 24, 2024
1 parent 909932c commit cd49d1c
Showing 1 changed file with 82 additions and 65 deletions.
147 changes: 82 additions & 65 deletions extensions/PenP/experi.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
const gl = renderer._gl;

const isWebGL2 = gl.getParameter(gl.VERSION).includes("2.0");

let currentFilter = gl.NEAREST;

//Native size. The size of the pen-layer.
let nativeSize = renderer.useHighQualityRender
? [canvas.width, canvas.height]
: renderer._nativeSize;

//If we have webGL2 add the float color buffer extension!
if (isWebGL2) {
const ext = gl.getExtension("EXT_color_buffer_float");
}
Expand All @@ -76,6 +76,7 @@
];
const triBufferInfo = twgl.createFramebufferInfo(gl, triBufferAttachments);

//Our lastFB variable
let lastFB = gl.getParameter(gl.FRAMEBUFFER_BINDING);

//?Neato uniform for universally transforming triangles to fit the screen
Expand Down Expand Up @@ -127,6 +128,7 @@
}
}

//Just a function that checks for pen.
const checkForPen = (util) => {
const curTarget = util.target;
const customState = curTarget["_customState"];
Expand Down Expand Up @@ -260,55 +262,6 @@
},
ProgramInf: null,
},
createAndCompileShaders: (vert, frag) => {
//? compile vertex Shader
const vertShader = gl.createShader(gl.VERTEX_SHADER);
try {
gl.shaderSource(vertShader, vert.trim());
gl.compileShader(vertShader);
if (!gl.getShaderParameter(vertShader, gl.COMPILE_STATUS)) {
throw gl.getShaderInfoLog(vertShader);
}
} catch (error) {
console.error(error);
}

//? compile fragment Shader
const fragShader = gl.createShader(gl.FRAGMENT_SHADER);
try {
gl.shaderSource(fragShader, frag.trim());
gl.compileShader(fragShader);
if (!gl.getShaderParameter(fragShader, gl.COMPILE_STATUS)) {
throw gl.getShaderInfoLog(fragShader);
}
} catch (error) {
console.error(error);
}

//? compile program
const program = gl.createProgram();
try {
gl.attachShader(program, vertShader);
gl.attachShader(program, fragShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw gl.getProgramInfoLog(program);
}

gl.validateProgram(program);
if (!gl.getProgramParameter(program, gl.VALIDATE_STATUS)) {
throw gl.getProgramInfoLog(program);
}
} catch (error) {
console.error(error);
}

return {
program: program,
vert: vertShader,
frag: fragShader,
};
},
};

//Used for the popup animation
Expand Down Expand Up @@ -538,6 +491,20 @@
},
};

frameBufferAttachmentSettings = [
{
internalFormat: gl.RGBA,
format: gl.RGBA,
type: gl.UNSIGNED_BYTE,
wrap: gl.CLAMP_TO_EDGE,
premultiplyAlpha: true,

//Texture
min: gl.LINEAR
},
{ format: gl.DEPTH_STENCIL },
];

//?Optimizations for single tri
triShader;
triIsDefault;
Expand Down Expand Up @@ -676,7 +643,7 @@
twgl.resizeFramebufferInfo(
gl,
this.currentRenderTexture,
triBufferAttachments,
this.currentAttachmentInfo,
Scratch.Cast.toNumber(nativeSize[0]),
Scratch.Cast.toNumber(nativeSize[1])
);
Expand Down Expand Up @@ -993,6 +960,9 @@
culling = false;
cullMode = 0;

//Filtering mode
currentFilter = gl.NEAREST;

shaders = Object.create(null);
programs = Object.create(null);

Expand All @@ -1005,6 +975,7 @@

renderTextures = Object.create(null);
currentRenderTexture = triBufferInfo;
currentAttachmentInfo = triBufferAttachments;

blockIcons = {
undo: "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxOS40NDU0NCIgaGVpZ2h0PSIxMC42MzM1MSIgdmlld0JveD0iMCwwLDE5LjQ0NTQ0LDEwLjYzMzUxIj48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMjMxLjE1NDU0LC0xNzMuNTc1OTkpIj48ZyBkYXRhLXBhcGVyLWRhdGE9InsmcXVvdDtpc1BhaW50aW5nTGF5ZXImcXVvdDs6dHJ1ZX0iIGZp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Y5NzA2LDEuNjk3MDZjMC4yODI4NCwwLjI4Mjg0IDAuMjgyODQsMC43MDcxMSAwLDAuOTg5OTVjLTAuMTQxNDIsMC4xNDE0MiAtMC4yODI4NCwwLjE0MTQyIC0wLjQyNDI2LDAuMTQxNDJsLTYuMjIyNTQsMGMtMC40MjQyNiwwIC0wLjcwNzExLC0wLjI4Mjg0IC0wLjYzNjQsLTAuNjM2NGwwLC02LjIyMjU0YzAsLTAuNDI0MjYgMC4xNDE0MiwtMC43MDcxMSAwLjQyNDI2LC0wLjg0ODUzYzAuMjgyODQsLTAuMTQxNDIgMC40MjQyNiwwIDAuNTY1NjksMC4xNDE0MnoiIGZpbGw9IiNmZmZmZmYiLz48L2c+PC9nPjwvc3ZnPjwhLS1yb3RhdGlvbkNlbnRlcjo4Ljg0NTQ2Mzg5MDkwNTQ3ODo2LjQyNDAxMjQ0MTg5NTI4Ni0tPg==",
Expand Down Expand Up @@ -2663,6 +2634,17 @@
blockType: Scratch.BlockType.LABEL,
text: "Render Textures",
},
{
opcode: "setRenderTextureType",
blockType: Scratch.BlockType.COMMAND,
text: "set type of created render textures to [type]",
arguments: {
type: {
type: Scratch.ArgumentType.STRING,
menu:"textureTypes"
}
}
},
{
opcode: "createRenderTexture",
blockType: Scratch.BlockType.COMMAND,
Expand Down Expand Up @@ -2800,7 +2782,7 @@
{
opcode: "clearDepth",
blockType: Scratch.BlockType.COMMAND,
text: "Erase Depth",
text: "erase depth",
},
{
hideFromPalette: true,
Expand Down Expand Up @@ -3015,6 +2997,10 @@
],
acceptReporters: true,
},
textureTypes: {
items:"_textureTypeMenu",
acceptReporters:true
}
},
name: "Pen+ Experimental",
id: "penP",
Expand Down Expand Up @@ -3140,6 +3126,21 @@
}
return sprites;
}
_textureTypeMenu() {
const returned = [
{text:"Standard",value:`[${gl.RGBA},${gl.UNSIGNED_BYTE},${gl.RGBA}]`},
{text:"No Alpha",value:`[${gl.RGB},${gl.UNSIGNED_BYTE},${gl.RGB}]`}
]

if (isWebGL2) {
returned.push(
{text:"Higher Range",value:`[${gl.RGBA32F},${gl.FLOAT},${gl.RGBA}]`},
{text:"Red Only",value:`[${gl.R8},${gl.UNSIGNED_BYTE},${gl.RED}]`},
{text:"Higher Range Red Only",value:`[${gl.R32F},${gl.FLOAT},${gl.RED}]`},
)
}
return returned;
}
//From lily's list tools... With permission of course.
_getLists() {
const lists =
Expand All @@ -3155,6 +3156,7 @@
return [""];
}
}

//And the associated helper function
_getVarObjectFromName(name, util, type) {
const stageTarget = runtime.getTargetForStage();
Expand Down Expand Up @@ -3216,8 +3218,8 @@
if (currentTexture) {
//Set the filter mode
gl.bindTexture(gl.TEXTURE_2D, currentTexture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, currentFilter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, currentFilter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.currentFilter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.currentFilter);
}

return currentTexture;
Expand Down Expand Up @@ -3652,7 +3654,7 @@

//?Triangle stuffs
setTriangleFilterMode({ filter }) {
currentFilter = filter;
this.currentFilter = filter;
}
setTrianglePointAttribute({ point, attribute, value }, util) {
const trianglePointStart = (point - 1) * 8;
Expand Down Expand Up @@ -3950,7 +3952,7 @@
this.triIsDefault = true;

this.triDefaultAttributes.u_transform = transform_Matrix;
this.triDefaultAttributes.u_texture = currentTexture;
if (currentTexture != null) this.triDefaultAttributes.u_texture = currentTexture;
}

//?Color Stuff
Expand Down Expand Up @@ -5795,12 +5797,12 @@
gl.texParameteri(
gl.TEXTURE_CUBE_MAP,
gl.TEXTURE_MIN_FILTER,
currentFilter
this.currentFilter
);
gl.texParameteri(
gl.TEXTURE_CUBE_MAP,
gl.TEXTURE_MAG_FILTER,
currentFilter
this.currentFilter
);
} else {
if (curCostume >= 0) {
Expand All @@ -5824,12 +5826,12 @@
gl.texParameteri(
gl.TEXTURE_CUBE_MAP,
gl.TEXTURE_MIN_FILTER,
currentFilter
this.currentFilter
);
gl.texParameteri(
gl.TEXTURE_CUBE_MAP,
gl.TEXTURE_MAG_FILTER,
currentFilter
this.currentFilter
);
};

Expand Down Expand Up @@ -6178,6 +6180,15 @@
return JSON.stringify(Object.keys(this.renderTextures));
}

setRenderTextureType({ type }) {
const parsed = JSON.parse(type);
this.frameBufferAttachmentSettings[0].internalFormat = parsed[0];
this.frameBufferAttachmentSettings[0].format = parsed[2];
this.frameBufferAttachmentSettings[0].type = parsed[1];
console.log(this.frameBufferAttachmentSettings[0]);
console.log(parsed);
}

createRenderTexture({ name }) {
//If it is named scratch stage get that stuff out of here
if (name == "Scratch Stage") return;
Expand All @@ -6191,9 +6202,10 @@

//Add it
this.renderTextures[this.prefixes.renderTextures + name] =
twgl.createFramebufferInfo(gl, triBufferAttachments);
twgl.createFramebufferInfo(gl, this.frameBufferAttachmentSettings);
this.renderTextures[this.prefixes.renderTextures + name].resizing = true;
this.renderTextures[this.prefixes.renderTextures + name].name = name;
this.renderTextures[this.prefixes.renderTextures + name].attachmentInfo = this.frameBufferAttachmentSettings;
}

createRenderTextureOfSize({ name, width, height }) {
Expand All @@ -6209,16 +6221,17 @@

//Add it
this.renderTextures[this.prefixes.renderTextures + name] =
twgl.createFramebufferInfo(gl, triBufferAttachments);
twgl.createFramebufferInfo(gl, this.frameBufferAttachmentSettings);
twgl.resizeFramebufferInfo(
gl,
this.renderTextures[this.prefixes.renderTextures + name],
triBufferAttachments,
this.frameBufferAttachmentSettings,
width,
height
);
this.renderTextures[this.prefixes.renderTextures + name].resizing = false;
this.renderTextures[this.prefixes.renderTextures + name].name = name;
this.renderTextures[this.prefixes.renderTextures + name].attachmentInfo = this.frameBufferAttachmentSettings;
}

clearRenderTexture({ name }) {
Expand Down Expand Up @@ -6246,6 +6259,7 @@
//If we are deleting the one we are on failsafe to the default stage buffer
if (this.currentRenderTexture.name == name) {
this.currentRenderTexture = triBufferInfo;
this.currentAttachmentInfo = triBufferAttachments;
gl.bindFramebuffer(
gl.FRAMEBUFFER,
this.currentRenderTexture.framebuffer
Expand All @@ -6266,10 +6280,12 @@
//Check for the scratch stage
if (name == "Scratch Stage") {
this.currentRenderTexture = triBufferInfo;
this.currentAttachmentInfo = triBufferAttachments;
}
//Check for the render texture inside of the list
else if (this.renderTextures[name]) {
this.currentRenderTexture = this.renderTextures[name];
this.currentAttachmentInfo = this.renderTextures[name].attachmentInfo;

//if we detect that ANY I MEAN ANY shader has THIS texture destroy it.
Object.keys(this.programs).forEach((programKey) => {
Expand All @@ -6290,6 +6306,7 @@
//if all else fails use the tri buffer render texture.
else {
this.currentRenderTexture = triBufferInfo;
this.currentAttachmentInfo = triBufferAttachments;
}
this.tryFinalizeDraw(null,null,null,null,true);

Expand All @@ -6311,7 +6328,7 @@
twgl.resizeFramebufferInfo(
gl,
this.currentRenderTexture,
triBufferAttachments,
this.currentAttachmentInfo,
Scratch.Cast.toNumber(nativeSize[0]),
Scratch.Cast.toNumber(nativeSize[1])
);
Expand Down

0 comments on commit cd49d1c

Please sign in to comment.