|
@@ -126,6 +126,7 @@ class GlDriver extends Driver {
|
|
var defStencil : Stencil;
|
|
var defStencil : Stencil;
|
|
var programs : Map<Int, CompiledProgram>;
|
|
var programs : Map<Int, CompiledProgram>;
|
|
var frame : Int;
|
|
var frame : Int;
|
|
|
|
+ var lastActiveIndex : Int = 0;
|
|
|
|
|
|
var bufferWidth : Int;
|
|
var bufferWidth : Int;
|
|
var bufferHeight : Int;
|
|
var bufferHeight : Int;
|
|
@@ -390,6 +391,7 @@ class GlDriver extends Driver {
|
|
gl.activeTexture(GL.TEXTURE0 + i);
|
|
gl.activeTexture(GL.TEXTURE0 + i);
|
|
gl.uniform1i(pt, i);
|
|
gl.uniform1i(pt, i);
|
|
gl.bindTexture(mode, t.t.t);
|
|
gl.bindTexture(mode, t.t.t);
|
|
|
|
+ lastActiveIndex = i;
|
|
|
|
|
|
var mip = Type.enumIndex(t.mipMap);
|
|
var mip = Type.enumIndex(t.mipMap);
|
|
var filter = Type.enumIndex(t.filter);
|
|
var filter = Type.enumIndex(t.filter);
|
|
@@ -615,7 +617,8 @@ class GlDriver extends Driver {
|
|
|
|
|
|
override function allocTexture( t : h3d.mat.Texture ) : Texture {
|
|
override function allocTexture( t : h3d.mat.Texture ) : Texture {
|
|
var tt = gl.createTexture();
|
|
var tt = gl.createTexture();
|
|
- var tt : Texture = { t : tt, width : t.width, height : t.height, internalFmt : GL.RGBA, pixelFmt : GL.UNSIGNED_BYTE, bits : -1 };
|
|
|
|
|
|
+ var bind = t.flags.has(Cube) ? GL.TEXTURE_CUBE_MAP : GL.TEXTURE_2D;
|
|
|
|
+ var tt : Texture = { t : tt, width : t.width, height : t.height, internalFmt : GL.RGBA, pixelFmt : GL.UNSIGNED_BYTE, bits : -1, bind : bind };
|
|
switch( t.format ) {
|
|
switch( t.format ) {
|
|
case RGBA:
|
|
case RGBA:
|
|
// default
|
|
// default
|
|
@@ -646,7 +649,6 @@ class GlDriver extends Driver {
|
|
}
|
|
}
|
|
t.lastFrame = frame;
|
|
t.lastFrame = frame;
|
|
t.flags.unset(WasCleared);
|
|
t.flags.unset(WasCleared);
|
|
- var bind = t.flags.has(Cube) ? GL.TEXTURE_CUBE_MAP : GL.TEXTURE_2D;
|
|
|
|
gl.bindTexture(bind, tt.t);
|
|
gl.bindTexture(bind, tt.t);
|
|
var outOfMem = false;
|
|
var outOfMem = false;
|
|
if( t.flags.has(Cube) ) {
|
|
if( t.flags.has(Cube) ) {
|
|
@@ -662,7 +664,7 @@ class GlDriver extends Driver {
|
|
if( gl.getError() == GL.OUT_OF_MEMORY )
|
|
if( gl.getError() == GL.OUT_OF_MEMORY )
|
|
outOfMem = true;
|
|
outOfMem = true;
|
|
}
|
|
}
|
|
- gl.bindTexture(bind, null);
|
|
|
|
|
|
+ restoreBind();
|
|
|
|
|
|
if( outOfMem ) {
|
|
if( outOfMem ) {
|
|
gl.deleteTexture(tt.t);
|
|
gl.deleteTexture(tt.t);
|
|
@@ -672,6 +674,14 @@ class GlDriver extends Driver {
|
|
return tt;
|
|
return tt;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function restoreBind() {
|
|
|
|
+ var t = boundTextures[lastActiveIndex];
|
|
|
|
+ if( t == null )
|
|
|
|
+ gl.bindTexture(GL.TEXTURE_2D, null);
|
|
|
|
+ else
|
|
|
|
+ gl.bindTexture(t.bind, t.t);
|
|
|
|
+ }
|
|
|
|
+
|
|
override function allocDepthBuffer( b : h3d.mat.DepthBuffer ) : DepthBuffer {
|
|
override function allocDepthBuffer( b : h3d.mat.DepthBuffer ) : DepthBuffer {
|
|
var r = gl.createRenderbuffer();
|
|
var r = gl.createRenderbuffer();
|
|
gl.bindRenderbuffer(GL.RENDERBUFFER, r);
|
|
gl.bindRenderbuffer(GL.RENDERBUFFER, r);
|
|
@@ -742,6 +752,9 @@ class GlDriver extends Driver {
|
|
var tt = t.t;
|
|
var tt = t.t;
|
|
if( tt == null ) return;
|
|
if( tt == null ) return;
|
|
t.t = null;
|
|
t.t = null;
|
|
|
|
+ for( i in 0...boundTextures.length )
|
|
|
|
+ if( boundTextures[i] == tt )
|
|
|
|
+ boundTextures[i] = null;
|
|
gl.deleteTexture(tt.t);
|
|
gl.deleteTexture(tt.t);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -757,7 +770,7 @@ class GlDriver extends Driver {
|
|
var bind = t.flags.has(Cube) ? GL.TEXTURE_CUBE_MAP : GL.TEXTURE_2D;
|
|
var bind = t.flags.has(Cube) ? GL.TEXTURE_CUBE_MAP : GL.TEXTURE_2D;
|
|
gl.bindTexture(bind, t.t.t);
|
|
gl.bindTexture(bind, t.t.t);
|
|
gl.generateMipmap(bind);
|
|
gl.generateMipmap(bind);
|
|
- gl.bindTexture(bind, null);
|
|
|
|
|
|
+ restoreBind();
|
|
}
|
|
}
|
|
|
|
|
|
override function uploadTextureBitmap( t : h3d.mat.Texture, bmp : hxd.BitmapData, mipLevel : Int, side : Int ) {
|
|
override function uploadTextureBitmap( t : h3d.mat.Texture, bmp : hxd.BitmapData, mipLevel : Int, side : Int ) {
|
|
@@ -777,7 +790,7 @@ class GlDriver extends Driver {
|
|
gl.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);
|
|
gl.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);
|
|
#end
|
|
#end
|
|
gl.texImage2D(GL.TEXTURE_2D, mipLevel, t.t.internalFmt, getChannels(t.t), t.t.pixelFmt, img.getImageData(0, 0, bmp.width, bmp.height));
|
|
gl.texImage2D(GL.TEXTURE_2D, mipLevel, t.t.internalFmt, getChannels(t.t), t.t.pixelFmt, img.getImageData(0, 0, bmp.width, bmp.height));
|
|
- gl.bindTexture(GL.TEXTURE_2D, null);
|
|
|
|
|
|
+ restoreBind();
|
|
}
|
|
}
|
|
#end
|
|
#end
|
|
}
|
|
}
|
|
@@ -864,7 +877,7 @@ class GlDriver extends Driver {
|
|
gl.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, cubic ? 0 : 1);
|
|
gl.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, cubic ? 0 : 1);
|
|
gl.texImage2D(face, mipLevel, t.t.internalFmt, pixels.width, pixels.height, 0, getChannels(t.t), t.t.pixelFmt, bytesToUint8Array(pixels.bytes));
|
|
gl.texImage2D(face, mipLevel, t.t.internalFmt, pixels.width, pixels.height, 0, getChannels(t.t), t.t.pixelFmt, bytesToUint8Array(pixels.bytes));
|
|
#end
|
|
#end
|
|
- gl.bindTexture(bind, null);
|
|
|
|
|
|
+ restoreBind();
|
|
}
|
|
}
|
|
|
|
|
|
override function uploadVertexBuffer( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : hxd.FloatBuffer, bufPos : Int ) {
|
|
override function uploadVertexBuffer( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : hxd.FloatBuffer, bufPos : Int ) {
|
|
@@ -1039,7 +1052,7 @@ class GlDriver extends Driver {
|
|
var bind = tex.flags.has(Cube) ? GL.TEXTURE_CUBE_MAP : GL.TEXTURE_2D;
|
|
var bind = tex.flags.has(Cube) ? GL.TEXTURE_CUBE_MAP : GL.TEXTURE_2D;
|
|
gl.bindTexture(bind, tex.t.t);
|
|
gl.bindTexture(bind, tex.t.t);
|
|
gl.generateMipmap(bind);
|
|
gl.generateMipmap(bind);
|
|
- gl.bindTexture(bind, null);
|
|
|
|
|
|
+ restoreBind();
|
|
}
|
|
}
|
|
|
|
|
|
tex.flags.set(WasCleared); // once we draw to, do not clear again
|
|
tex.flags.set(WasCleared); // once we draw to, do not clear again
|