Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix u_mouse and u_resolution #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dist/GlslCanvas.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ var GlslCanvas = function () {
this.uniforms = {};
this.vbo = {};
this.isValid = false;
this.animationFrameRequest = undefined;

this.BUFFER_COUNT = 0;
// this.TEXTURE_COUNT = 0;
Expand Down Expand Up @@ -1092,7 +1093,7 @@ var GlslCanvas = function () {
}

sandbox.render();
window.requestAnimationFrame(RenderLoop);
sandbox.animationFrameRequest = window.requestAnimationFrame(RenderLoop);
}

// Start
Expand All @@ -1104,6 +1105,9 @@ var GlslCanvas = function () {
createClass(GlslCanvas, [{
key: 'destroy',
value: function destroy() {
// Stop the animation
cancelAnimationFrame(this.animationFrameRequest);

this.animated = false;
this.isValid = false;
for (var tex in this.textures) {
Expand All @@ -1121,6 +1125,7 @@ var GlslCanvas = function () {
var buffer = this.buffers[key];
this.gl.deleteProgram(buffer.program);
}

this.program = null;
this.gl = null;
}
Expand Down Expand Up @@ -1329,7 +1334,7 @@ var GlslCanvas = function () {
if (mouse && mouse.x && mouse.x >= rect.left && mouse.x <= rect.right && mouse.y && mouse.y >= rect.top && mouse.y <= rect.bottom) {

var mouse_x = (mouse.x - rect.left) * this.realToCSSPixels;
var mouse_y = this.canvas.height - (mouse.y - rect.top) * this.realToCSSPixels;
var mouse_y = this.height - (mouse.y - rect.top) * this.realToCSSPixels;

this.uniform('2f', 'vec2', 'u_mouse', mouse_x, mouse_y);
}
Expand Down Expand Up @@ -1443,7 +1448,7 @@ var GlslCanvas = function () {
}

// set the resolution uniform
this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width, this.canvas.height);
this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width * this.realToCSSPixels, this.canvas.height * this.realToCSSPixels);

for (var key in this.buffers) {
var buffer = this.buffers[key];
Expand Down
11 changes: 8 additions & 3 deletions dist/GlslCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,7 @@ var GlslCanvas = function () {
this.uniforms = {};
this.vbo = {};
this.isValid = false;
this.animationFrameRequest = undefined;

this.BUFFER_COUNT = 0;
// this.TEXTURE_COUNT = 0;
Expand Down Expand Up @@ -1497,7 +1498,7 @@ var GlslCanvas = function () {
}

sandbox.render();
window.requestAnimationFrame(RenderLoop);
sandbox.animationFrameRequest = window.requestAnimationFrame(RenderLoop);
}

// Start
Expand All @@ -1509,6 +1510,9 @@ var GlslCanvas = function () {
createClass(GlslCanvas, [{
key: 'destroy',
value: function destroy() {
// Stop the animation
cancelAnimationFrame(this.animationFrameRequest);

this.animated = false;
this.isValid = false;
for (var tex in this.textures) {
Expand All @@ -1526,6 +1530,7 @@ var GlslCanvas = function () {
var buffer = this.buffers[key];
this.gl.deleteProgram(buffer.program);
}

this.program = null;
this.gl = null;
}
Expand Down Expand Up @@ -1734,7 +1739,7 @@ var GlslCanvas = function () {
if (mouse && mouse.x && mouse.x >= rect.left && mouse.x <= rect.right && mouse.y && mouse.y >= rect.top && mouse.y <= rect.bottom) {

var mouse_x = (mouse.x - rect.left) * this.realToCSSPixels;
var mouse_y = this.canvas.height - (mouse.y - rect.top) * this.realToCSSPixels;
var mouse_y = this.height - (mouse.y - rect.top) * this.realToCSSPixels;

this.uniform('2f', 'vec2', 'u_mouse', mouse_x, mouse_y);
}
Expand Down Expand Up @@ -1848,7 +1853,7 @@ var GlslCanvas = function () {
}

// set the resolution uniform
this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width, this.canvas.height);
this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width * this.realToCSSPixels, this.canvas.height * this.realToCSSPixels);

for (var key in this.buffers) {
var buffer = this.buffers[key];
Expand Down
2 changes: 1 addition & 1 deletion dist/GlslCanvas.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/GlslCanvas.min.js.map

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions lib/GlslCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,7 @@ var GlslCanvas = function () {
this.uniforms = {};
this.vbo = {};
this.isValid = false;
this.animationFrameRequest = undefined;

this.BUFFER_COUNT = 0;
// this.TEXTURE_COUNT = 0;
Expand Down Expand Up @@ -1493,7 +1494,7 @@ var GlslCanvas = function () {
}

sandbox.render();
window.requestAnimationFrame(RenderLoop);
sandbox.animationFrameRequest = window.requestAnimationFrame(RenderLoop);
}

// Start
Expand All @@ -1505,6 +1506,9 @@ var GlslCanvas = function () {
createClass(GlslCanvas, [{
key: 'destroy',
value: function destroy() {
// Stop the animation
cancelAnimationFrame(this.animationFrameRequest);

this.animated = false;
this.isValid = false;
for (var tex in this.textures) {
Expand All @@ -1522,6 +1526,7 @@ var GlslCanvas = function () {
var buffer = this.buffers[key];
this.gl.deleteProgram(buffer.program);
}

this.program = null;
this.gl = null;
}
Expand Down Expand Up @@ -1730,7 +1735,7 @@ var GlslCanvas = function () {
if (mouse && mouse.x && mouse.x >= rect.left && mouse.x <= rect.right && mouse.y && mouse.y >= rect.top && mouse.y <= rect.bottom) {

var mouse_x = (mouse.x - rect.left) * this.realToCSSPixels;
var mouse_y = this.canvas.height - (mouse.y - rect.top) * this.realToCSSPixels;
var mouse_y = this.height - (mouse.y - rect.top) * this.realToCSSPixels;

this.uniform('2f', 'vec2', 'u_mouse', mouse_x, mouse_y);
}
Expand Down Expand Up @@ -1844,7 +1849,7 @@ var GlslCanvas = function () {
}

// set the resolution uniform
this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width, this.canvas.height);
this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width * this.realToCSSPixels, this.canvas.height * this.realToCSSPixels);

for (var key in this.buffers) {
var buffer = this.buffers[key];
Expand Down
19 changes: 12 additions & 7 deletions src/GlslCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class GlslCanvas {
this.uniforms = {};
this.vbo = {};
this.isValid = false;
this.animationFrameRequest = undefined;

this.BUFFER_COUNT = 0;
// this.TEXTURE_COUNT = 0;
Expand Down Expand Up @@ -171,9 +172,9 @@ void main(){
if (sandbox.resize()) {
sandbox.forceRender = true;
}

sandbox.render();
window.requestAnimationFrame(RenderLoop);
sandbox.animationFrameRequest = window.requestAnimationFrame(RenderLoop);
}

// Start
Expand All @@ -183,6 +184,9 @@ void main(){
}

destroy() {
// Stop the animation
cancelAnimationFrame(this.animationFrameRequest);

this.animated = false;
this.isValid = false;
for (let tex in this.textures) {
Expand All @@ -200,6 +204,7 @@ void main(){
const buffer = this.buffers[key];
this.gl.deleteProgram(buffer.program);
}

this.program = null;
this.gl = null;
}
Expand Down Expand Up @@ -275,7 +280,7 @@ void main(){
}
this.buffers = buffers;
this.texureIndex = this.BUFFER_COUNT;

// Trigger event
this.trigger('load', {});

Expand Down Expand Up @@ -404,15 +409,15 @@ void main(){
mouse.y && mouse.y >= rect.top && mouse.y <= rect.bottom) {

let mouse_x = (mouse.x - rect.left ) * this.realToCSSPixels;
let mouse_y = (this.canvas.height - (mouse.y - rect.top) * this.realToCSSPixels);
let mouse_y = (this.height - (mouse.y - rect.top) * this.realToCSSPixels);

this.uniform('2f', 'vec2', 'u_mouse', mouse_x, mouse_y);
}
}

// ex: program.uniform('3f', 'position', x, y, z);
uniform (method, type, name, ...value) { // 'value' is a method-appropriate arguments list
this.uniforms[name] = this.uniforms[name] || {};
this.uniforms[name] = this.uniforms[name] || {};
let uniform = this.uniforms[name];
let change = isDiff(uniform.value, value);

Expand Down Expand Up @@ -510,7 +515,7 @@ void main(){
}

// set the resolution uniform
this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width, this.canvas.height);
this.uniform('2f', 'vec2', 'u_resolution', this.canvas.width * this.realToCSSPixels, this.canvas.height * this.realToCSSPixels);

for (let key in this.buffers) {
const buffer = this.buffers[key];
Expand Down Expand Up @@ -714,4 +719,4 @@ function loadAllGlslCanvas() {

window.addEventListener('load', function () {
loadAllGlslCanvas();
});
});