Skip to content

Commit 7d7ddf2

Browse files
committed
fix framebuffer texture bug
1 parent d747730 commit 7d7ddf2

File tree

2 files changed

+52
-50
lines changed

2 files changed

+52
-50
lines changed

glutil.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,10 @@ BufferedMesh.prototype.primitiveCount=function(){
11241124
function FrameBuffer(context, width, height){
11251125
if(width<0 || height<0)throw new Error("width or height negative");
11261126
this.context=context;
1127-
this.textureUnit=1;
1127+
// give the framebuffer its own texture unit, since the
1128+
// shader program may bind samplers to other texture
1129+
// units, such as texture unit 0
1130+
this.textureUnit=1;
11281131
this.buffer=context.createFramebuffer();
11291132
// create color texture
11301133
this.colorTexture = context.createTexture();
@@ -1160,13 +1163,6 @@ function FrameBuffer(context, width, height){
11601163
this.context.renderbufferStorage(
11611164
context.RENDERBUFFER,context.DEPTH_COMPONENT16,
11621165
this.width,this.height);
1163-
// attach color and depth buffers
1164-
this.context.framebufferTexture2D(
1165-
context.FRAMEBUFFER,context.COLOR_ATTACHMENT0,
1166-
context.TEXTURE_2D,this.colorTexture,0);
1167-
this.context.framebufferRenderbuffer(
1168-
context.FRAMEBUFFER,context.DEPTH_ATTACHMENT,
1169-
context.RENDERBUFFER,this.depthbuffer);
11701166
this.context.bindFramebuffer(
11711167
context.FRAMEBUFFER,oldBuffer);
11721168
}
@@ -1186,27 +1182,27 @@ FrameBuffer.prototype.bind=function(program){
11861182
throw new Error("can't bind buffer: context mismatch");
11871183
}
11881184
this.context.activeTexture(this.context.TEXTURE0+this.textureUnit);
1185+
this.context.bindFramebuffer(
1186+
this.context.FRAMEBUFFER,this.buffer);
11891187
this.context.framebufferTexture2D(
11901188
this.context.FRAMEBUFFER,this.context.COLOR_ATTACHMENT0,
11911189
this.context.TEXTURE_2D,this.colorTexture,0);
11921190
this.context.framebufferRenderbuffer(
11931191
this.context.FRAMEBUFFER,this.context.DEPTH_ATTACHMENT,
11941192
this.context.RENDERBUFFER,this.depthbuffer);
1195-
this.context.bindFramebuffer(
1196-
this.context.FRAMEBUFFER,this.buffer);
11971193
}
11981194
/**
11991195
* Unbinds this frame buffer from its associated WebGL this.context.
12001196
*/
12011197
FrameBuffer.prototype.unbind=function(){
1202-
this.context.bindFramebuffer(
1203-
this.context.FRAMEBUFFER,null);
12041198
this.context.framebufferTexture2D(
12051199
this.context.FRAMEBUFFER,this.context.COLOR_ATTACHMENT0,
1206-
this.context.TEXTURE_2D,0,0);
1200+
this.context.TEXTURE_2D,null,0);
12071201
this.context.framebufferRenderbuffer(
12081202
this.context.FRAMEBUFFER,this.context.DEPTH_ATTACHMENT,
1209-
this.context.RENDERBUFFER,0);
1203+
this.context.RENDERBUFFER,null);
1204+
this.context.bindFramebuffer(
1205+
this.context.FRAMEBUFFER,null);
12101206
}
12111207
/**
12121208
* Disposes all resources from this frame buffer object.
@@ -1925,6 +1921,7 @@ Scene3D.prototype._renderInner=function(){
19251921
*/
19261922
function ShapeGroup(){
19271923
this.shapes=[];
1924+
this.parent=null;
19281925
this.transform=new Transform();
19291926
}
19301927
/**
@@ -1947,11 +1944,16 @@ ShapeGroup.prototype.getTransform=function(){
19471944
* Not documented yet.
19481945
*/
19491946
ShapeGroup.prototype.getMatrix=function(){
1950-
return this.getTransform().getMatrix();
1947+
var mat=this.getTransform().getMatrix();
1948+
if(this.parent!=null){
1949+
var pmat=this.parent.getMatrix();
1950+
mat=GLMath.mat4multiply(pmat,mat);
1951+
}
1952+
return mat;
19511953
}
19521954
/**
19531955
* Not documented yet.
1954-
* @param {*} transform
1956+
* @param {Transform} transform
19551957
*/
19561958
ShapeGroup.prototype.setTransform=function(transform){
19571959
this.transform=transform.copy();

0 commit comments

Comments
 (0)