mirror of
https://github.com/MapMakersAndProgrammers/Alternativa3D.git
synced 2025-10-26 09:59:10 -07:00
Free Context3D buffers and textures after render. Closes #3
This commit is contained in:
@@ -37,6 +37,9 @@ package alternativa.engine3d.core {
|
|||||||
|
|
||||||
public static const NEXT_LAYER:int = 50;
|
public static const NEXT_LAYER:int = 50;
|
||||||
|
|
||||||
|
// Key - context, value - properties.
|
||||||
|
protected static var properties:Dictionary = new Dictionary(true);
|
||||||
|
|
||||||
// Collector
|
// Collector
|
||||||
protected var collector:DrawUnit;
|
protected var collector:DrawUnit;
|
||||||
|
|
||||||
@@ -44,9 +47,6 @@ package alternativa.engine3d.core {
|
|||||||
|
|
||||||
alternativa3d var drawUnits:Vector.<DrawUnit> = new Vector.<DrawUnit>();
|
alternativa3d var drawUnits:Vector.<DrawUnit> = new Vector.<DrawUnit>();
|
||||||
|
|
||||||
// Key - context, value - properties.
|
|
||||||
protected static var properties:Dictionary = new Dictionary(true);
|
|
||||||
|
|
||||||
protected var _context3D:Context3D;
|
protected var _context3D:Context3D;
|
||||||
protected var _contextProperties:RendererContext3DProperties;
|
protected var _contextProperties:RendererContext3DProperties;
|
||||||
|
|
||||||
@@ -90,10 +90,7 @@ package alternativa.engine3d.core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_contextProperties.culling = null;
|
freeContext3DProperties(context3D);
|
||||||
_contextProperties.blendSource = null;
|
|
||||||
_contextProperties.blendDestination = null;
|
|
||||||
_contextProperties.program = null;
|
|
||||||
// Clear
|
// Clear
|
||||||
drawUnits.length = 0;
|
drawUnits.length = 0;
|
||||||
}
|
}
|
||||||
@@ -134,8 +131,6 @@ package alternativa.engine3d.core {
|
|||||||
context.setCulling(drawUnit.culling);
|
context.setCulling(drawUnit.culling);
|
||||||
_contextProperties.culling = drawUnit.culling;
|
_contextProperties.culling = drawUnit.culling;
|
||||||
}
|
}
|
||||||
var _usedBuffers:uint = _contextProperties.usedBuffers;
|
|
||||||
var _usedTextures:uint = _contextProperties.usedTextures;
|
|
||||||
|
|
||||||
var bufferIndex:int;
|
var bufferIndex:int;
|
||||||
var bufferBit:int;
|
var bufferBit:int;
|
||||||
@@ -147,7 +142,6 @@ package alternativa.engine3d.core {
|
|||||||
bufferIndex = drawUnit.vertexBuffersIndexes[i];
|
bufferIndex = drawUnit.vertexBuffersIndexes[i];
|
||||||
bufferBit = 1 << bufferIndex;
|
bufferBit = 1 << bufferIndex;
|
||||||
currentBuffers |= bufferBit;
|
currentBuffers |= bufferBit;
|
||||||
_usedBuffers &= ~bufferBit;
|
|
||||||
context.setVertexBufferAt(bufferIndex, drawUnit.vertexBuffers[i], drawUnit.vertexBuffersOffsets[i], drawUnit.vertexBuffersFormats[i]);
|
context.setVertexBufferAt(bufferIndex, drawUnit.vertexBuffers[i], drawUnit.vertexBuffersOffsets[i], drawUnit.vertexBuffersFormats[i]);
|
||||||
}
|
}
|
||||||
if (drawUnit.vertexConstantsRegistersCount > 0) {
|
if (drawUnit.vertexConstantsRegistersCount > 0) {
|
||||||
@@ -160,13 +154,14 @@ package alternativa.engine3d.core {
|
|||||||
textureSampler = drawUnit.texturesSamplers[i];
|
textureSampler = drawUnit.texturesSamplers[i];
|
||||||
textureBit = 1 << textureSampler;
|
textureBit = 1 << textureSampler;
|
||||||
currentTextures |= textureBit;
|
currentTextures |= textureBit;
|
||||||
_usedTextures &= ~textureBit;
|
|
||||||
context.setTextureAt(textureSampler, drawUnit.textures[i]);
|
context.setTextureAt(textureSampler, drawUnit.textures[i]);
|
||||||
}
|
}
|
||||||
if (_contextProperties.program != drawUnit.program) {
|
if (_contextProperties.program != drawUnit.program) {
|
||||||
context.setProgram(drawUnit.program);
|
context.setProgram(drawUnit.program);
|
||||||
_contextProperties.program = drawUnit.program;
|
_contextProperties.program = drawUnit.program;
|
||||||
}
|
}
|
||||||
|
var _usedBuffers:uint = _contextProperties.usedBuffers & ~currentBuffers;
|
||||||
|
var _usedTextures:uint = _contextProperties.usedTextures & ~currentTextures;
|
||||||
for (bufferIndex = 0; _usedBuffers > 0; bufferIndex++) {
|
for (bufferIndex = 0; _usedBuffers > 0; bufferIndex++) {
|
||||||
bufferBit = _usedBuffers & 1;
|
bufferBit = _usedBuffers & 1;
|
||||||
_usedBuffers >>= 1;
|
_usedBuffers >>= 1;
|
||||||
@@ -195,6 +190,36 @@ package alternativa.engine3d.core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
alternativa3d function freeContext3DProperties(context3D:Context3D):void {
|
||||||
|
_contextProperties.culling = null;
|
||||||
|
_contextProperties.blendSource = null;
|
||||||
|
_contextProperties.blendDestination = null;
|
||||||
|
_contextProperties.program = null;
|
||||||
|
|
||||||
|
var usedBuffers:uint = _contextProperties.usedBuffers;
|
||||||
|
var usedTextures:uint = _contextProperties.usedTextures;
|
||||||
|
|
||||||
|
var bufferIndex:int;
|
||||||
|
var bufferBit:int;
|
||||||
|
var textureSampler:int;
|
||||||
|
var textureBit:int;
|
||||||
|
for (bufferIndex = 0; usedBuffers > 0; bufferIndex++) {
|
||||||
|
bufferBit = usedBuffers & 1;
|
||||||
|
usedBuffers >>= 1;
|
||||||
|
if (bufferBit) context3D.setVertexBufferAt(bufferIndex, null);
|
||||||
|
}
|
||||||
|
for (textureSampler = 0; usedTextures > 0; textureSampler++) {
|
||||||
|
textureBit = usedTextures & 1;
|
||||||
|
usedTextures >>= 1;
|
||||||
|
if (textureBit) context3D.setTextureAt(textureSampler, null);
|
||||||
|
}
|
||||||
|
_contextProperties.usedBuffers = 0;
|
||||||
|
_contextProperties.usedTextures = 0;
|
||||||
|
}
|
||||||
|
|
||||||
alternativa3d function sortByAverageZ(list:DrawUnit, direction:Boolean = true):DrawUnit {
|
alternativa3d function sortByAverageZ(list:DrawUnit, direction:Boolean = true):DrawUnit {
|
||||||
var left:DrawUnit = list;
|
var left:DrawUnit = list;
|
||||||
var right:DrawUnit = list.next;
|
var right:DrawUnit = list.next;
|
||||||
|
|||||||
Reference in New Issue
Block a user