Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Fixing WebGL #160

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
2 changes: 1 addition & 1 deletion src/Foundation/Actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,7 @@ CAAT.Module({
glSetShader:function (director) {

var tp = this.getTextureGLPage();
if (tp !== director.currentTexturePage) {
if (tp && tp !== director.currentTexturePage) {
director.setGLTexturePage(tp);
}

Expand Down
19 changes: 15 additions & 4 deletions src/Foundation/Director.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,12 @@ CAAT.Module({

this.canvas.width = this.referenceWidth * factor;
this.canvas.height = this.referenceHeight * factor;
this.ctx = this.canvas.getContext(this.glEnabled ? 'experimental-webgl' : '2d');
if (this.glEnabled) {
this.ctx = this.canvas.getContext('webgl') || this.canvas.getContext('experimental-webgl');
}
else {
this.ctx = this.canvas.getContext('2d');
}

this.__setupRetina();

Expand Down Expand Up @@ -620,7 +625,12 @@ CAAT.Module({
this.canvas.height = h;
}

this.ctx = this.canvas.getContext(this.glEnabled ? 'experimental-webgl' : '2d');
if (this.gl) {
this.ctx = this.canvas.getContext('webgl') || this.canvas.getContext('experimental-webgl');
}
else {
this.ctx = this.canvas.getContext('2d');
}

this.__setupRetina();

Expand Down Expand Up @@ -718,7 +728,7 @@ CAAT.Module({
var i;

try {
this.gl = canvas.getContext("experimental-webgl"/*, {antialias: false}*/);
this.gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
this.gl.viewportWidth = width;
this.gl.viewportHeight = height;
CAAT.GLRENDER = true;
Expand Down Expand Up @@ -759,6 +769,7 @@ CAAT.Module({
this.checkDebug();
} else {
// fallback to non gl enabled canvas.
CAAT.log("WebGL not supported, falling back to 2D canvas.")
return this.initialize(width, height, canvas);
}

Expand Down Expand Up @@ -1443,7 +1454,7 @@ CAAT.Module({
var ssin = this.scenes[ inSceneIndex ];
var sout = this.scenes[ outSceneIndex ];

if (!CAAT.__CSS__ && CAAT.CACHE_SCENE_ON_CHANGE) {
if (!CAAT.__CSS__ && !this.glEnabled && CAAT.CACHE_SCENE_ON_CHANGE) {
this.renderToContext(this.transitionScene.ctx, sout);
sout = this.transitionScene;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/SpriteImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ CAAT.Module({
initialize:function (image, rows, columns) {

if (!image) {
console.log("Null image for SpriteImage.");
CAAT.log("Error: got null instead of image object.");
}

if ( isString(image) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/Modules/TexturePacker/TexturePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ CAAT.Module( {
img.__h= newHeight;

this.scan.substract(where.x,where.y,w,h);
} else {
CAAT.log('Imagen ',img.src,' de tamano ',img.width,img.height,' no cabe.');
// } else {
// CAAT.log('Image ',img.src,' of size ',img.width,img.height,' does not fit into texture page.');
}
},
changeHeuristic : function(criteria) {
Expand Down
2 changes: 1 addition & 1 deletion src/WebGL/ColorProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ CAAT.Module( {

this.gl.vertexAttribPointer(
this.shaderProgram.vertexColorAttribute,
this.colorBuffer,
4,
this.gl.FLOAT,
false,
0,
Expand Down
1 change: 1 addition & 0 deletions src/WebGL/Program.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ CAAT.Module( {
return this;
},
setMatrixUniform : function( caatMatrix4 ) {
this.gl.useProgram(this.shaderProgram);
this.gl.uniformMatrix4fv(
this.shaderProgram.pMatrixUniform,
false,
Expand Down