mirror of
https://github.com/MapMakersAndProgrammers/Alternativa3D.git
synced 2025-10-26 09:59:10 -07:00
Clear context after renderToTexture
This commit is contained in:
@@ -243,9 +243,8 @@ public class Camera3D extends Object3D {
|
|||||||
renderer.camera = this;
|
renderer.camera = this;
|
||||||
// Projection argument calculating
|
// Projection argument calculating
|
||||||
calculateProjection(view._width, view._height);
|
calculateProjection(view._width, view._height);
|
||||||
// TODO: clear after shadows rendering
|
|
||||||
// Preparing to rendering
|
// Preparing to rendering
|
||||||
view.prepareToRender(stage3D, context3D);
|
view.configureContext3D(stage3D, context3D, this);
|
||||||
// Transformations calculating
|
// Transformations calculating
|
||||||
if (transformChanged) composeTransforms();
|
if (transformChanged) composeTransforms();
|
||||||
localToGlobalTransform.copy(transform);
|
localToGlobalTransform.copy(transform);
|
||||||
@@ -274,7 +273,7 @@ public class Camera3D extends Object3D {
|
|||||||
} else {
|
} else {
|
||||||
root.culling = 63;
|
root.culling = 63;
|
||||||
}
|
}
|
||||||
// Calculations of conent visibility
|
// Calculations of content visibility
|
||||||
if (root.culling >= 0) root.calculateVisibility(this);
|
if (root.culling >= 0) root.calculateVisibility(this);
|
||||||
// Calculations visibility of children
|
// Calculations visibility of children
|
||||||
root.calculateChildrenVisibility(this);
|
root.calculateChildrenVisibility(this);
|
||||||
@@ -357,6 +356,16 @@ public class Camera3D extends Object3D {
|
|||||||
}
|
}
|
||||||
raysLength = view.raysLength;
|
raysLength = view.raysLength;
|
||||||
|
|
||||||
|
var r:Number = ((view.backgroundColor >> 16) & 0xff)/0xff;
|
||||||
|
var g:Number = ((view.backgroundColor >> 8) & 0xff)/0xff;
|
||||||
|
var b:Number = (view.backgroundColor & 0xff)/0xff;
|
||||||
|
if (view._canvas != null) {
|
||||||
|
r *= view.backgroundAlpha;
|
||||||
|
g *= view.backgroundAlpha;
|
||||||
|
b *= view.backgroundAlpha;
|
||||||
|
}
|
||||||
|
context3D.clear(r, g, b, view.backgroundAlpha);
|
||||||
|
|
||||||
// Check getting in frustum and occluding
|
// Check getting in frustum and occluding
|
||||||
if (root.culling >= 0 && (root.boundBox == null || occludersLength == 0 || !root.boundBox.checkOcclusion(occluders, occludersLength, root.localToCameraTransform))) {
|
if (root.culling >= 0 && (root.boundBox == null || occludersLength == 0 || !root.boundBox.checkOcclusion(occluders, occludersLength, root.localToCameraTransform))) {
|
||||||
// Check if the ray crossing the bounding box
|
// Check if the ray crossing the bounding box
|
||||||
@@ -410,7 +419,6 @@ public class Camera3D extends Object3D {
|
|||||||
}
|
}
|
||||||
// Gather the draws for children
|
// Gather the draws for children
|
||||||
root.collectChildrenDraws(this, lights, lightsLength, root.useShadow);
|
root.collectChildrenDraws(this, lights, lightsLength, root.useShadow);
|
||||||
|
|
||||||
// Mouse events prosessing
|
// Mouse events prosessing
|
||||||
view.processMouseEvents(context3D, this);
|
view.processMouseEvents(context3D, this);
|
||||||
// Render
|
// Render
|
||||||
|
|||||||
@@ -8,7 +8,11 @@
|
|||||||
|
|
||||||
package alternativa.engine3d.core {
|
package alternativa.engine3d.core {
|
||||||
|
|
||||||
|
import alternativa.engine3d.materials.ShaderProgram;
|
||||||
|
import alternativa.engine3d.resources.Geometry;
|
||||||
|
|
||||||
import flash.display3D.Program3D;
|
import flash.display3D.Program3D;
|
||||||
|
import flash.utils.Dictionary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -18,6 +22,10 @@ package alternativa.engine3d.core {
|
|||||||
|
|
||||||
public var isConstrained:Boolean = false;
|
public var isConstrained:Boolean = false;
|
||||||
|
|
||||||
|
public var backBufferWidth:int = -1;
|
||||||
|
public var backBufferHeight:int = -1;
|
||||||
|
public var backBufferAntiAlias:int = -1;
|
||||||
|
|
||||||
public var usedBuffers:uint = 0;
|
public var usedBuffers:uint = 0;
|
||||||
public var usedTextures:uint = 0;
|
public var usedTextures:uint = 0;
|
||||||
|
|
||||||
@@ -26,5 +34,11 @@ package alternativa.engine3d.core {
|
|||||||
public var blendSource:String;
|
public var blendSource:String;
|
||||||
public var blendDestination:String;
|
public var blendDestination:String;
|
||||||
|
|
||||||
|
// View: mouse events
|
||||||
|
// Key - vertex program of object, value - program.
|
||||||
|
public var drawDistancePrograms:Dictionary = new Dictionary();
|
||||||
|
public var drawColoredRectProgram:ShaderProgram;
|
||||||
|
public var drawRectGeometry:Geometry;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,10 +61,6 @@ package alternativa.engine3d.core {
|
|||||||
|
|
||||||
private static const renderEvent:MouseEvent = new MouseEvent("render");
|
private static const renderEvent:MouseEvent = new MouseEvent("render");
|
||||||
|
|
||||||
private static var properties:Dictionary = new Dictionary(true);
|
|
||||||
private var cachedContext3D:Context3D;
|
|
||||||
private var context3DProperties:Context3DViewProperties;
|
|
||||||
|
|
||||||
static private var drawDistanceFragment:Linker;
|
static private var drawDistanceFragment:Linker;
|
||||||
static private var drawDistanceVertexProcedure:Procedure;
|
static private var drawDistanceVertexProcedure:Procedure;
|
||||||
|
|
||||||
@@ -538,7 +534,7 @@ package alternativa.engine3d.core {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
alternativa3d function prepareToRender(stage3D:Stage3D, context:Context3D):void {
|
alternativa3d function configureContext3D(stage3D:Stage3D, context3D:Context3D, camera:Camera3D):void {
|
||||||
if (_canvas == null) {
|
if (_canvas == null) {
|
||||||
var vis:Boolean = this.visible;
|
var vis:Boolean = this.visible;
|
||||||
for (var parent:DisplayObject = this.parent; parent != null; parent = parent.parent) {
|
for (var parent:DisplayObject = this.parent; parent != null; parent = parent.parent) {
|
||||||
@@ -558,70 +554,55 @@ package alternativa.engine3d.core {
|
|||||||
createRenderBitmap();
|
createRenderBitmap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (context != cachedContext3D) {
|
var context3DProperties:RendererContext3DProperties = camera.context3DProperties;
|
||||||
// Get properties.
|
if (context3DProperties.drawRectGeometry == null) {
|
||||||
cachedContext3D = context;
|
// Inititalize data for mouse events
|
||||||
context3DProperties = properties[cachedContext3D];
|
var rectGeometry:Geometry = new Geometry(4);
|
||||||
if (context3DProperties == null) {
|
rectGeometry.addVertexStream([VertexAttributes.POSITION, VertexAttributes.POSITION, VertexAttributes.POSITION, VertexAttributes.TEXCOORDS[0], VertexAttributes.TEXCOORDS[0]]);
|
||||||
context3DProperties = new Context3DViewProperties();
|
rectGeometry.setAttributeValues(VertexAttributes.POSITION, Vector.<Number>([0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1]));
|
||||||
// Inititalize data for mouse events
|
rectGeometry.setAttributeValues(VertexAttributes.TEXCOORDS[0], Vector.<Number>([0, 0, 0, 1, 1, 1, 1, 0]));
|
||||||
var rectGeometry:Geometry = new Geometry(4);
|
rectGeometry.indices = Vector.<uint>([0, 1, 3, 2, 3, 1]);
|
||||||
rectGeometry.addVertexStream([VertexAttributes.POSITION, VertexAttributes.POSITION, VertexAttributes.POSITION, VertexAttributes.TEXCOORDS[0], VertexAttributes.TEXCOORDS[0]]);
|
rectGeometry.upload(context3D);
|
||||||
rectGeometry.setAttributeValues(VertexAttributes.POSITION, Vector.<Number>([0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1]));
|
var vLinker:Linker = new Linker(Context3DProgramType.VERTEX);
|
||||||
rectGeometry.setAttributeValues(VertexAttributes.TEXCOORDS[0], Vector.<Number>([0, 0, 0, 1, 1, 1, 1, 0]));
|
vLinker.addProcedure(Procedure.compileFromArray([
|
||||||
rectGeometry.indices = Vector.<uint>([0, 1, 3, 2, 3, 1]);
|
"#a0=a0",
|
||||||
rectGeometry.upload(context);
|
"#c0=c0",
|
||||||
var vLinker:Linker = new Linker(Context3DProgramType.VERTEX);
|
"mul t0.x, a0.x, c0.x",
|
||||||
vLinker.addProcedure(Procedure.compileFromArray([
|
"mul t0.y, a0.y, c0.y",
|
||||||
"#a0=a0",
|
"add o0.x, t0.x, c0.z",
|
||||||
"#c0=c0",
|
"add o0.y, t0.y, c0.w",
|
||||||
"mul t0.x, a0.x, c0.x",
|
"mov o0.z, a0.z",
|
||||||
"mul t0.y, a0.y, c0.y",
|
"mov o0.w, a0.z",
|
||||||
"add o0.x, t0.x, c0.z",
|
]));
|
||||||
"add o0.y, t0.y, c0.w",
|
var fLinker:Linker = new Linker(Context3DProgramType.FRAGMENT);
|
||||||
"mov o0.z, a0.z",
|
fLinker.addProcedure(Procedure.compileFromArray([
|
||||||
"mov o0.w, a0.z",
|
"#c0=c0",
|
||||||
]));
|
"mov o0, c0",
|
||||||
var fLinker:Linker = new Linker(Context3DProgramType.FRAGMENT);
|
]));
|
||||||
fLinker.addProcedure(Procedure.compileFromArray([
|
var coloredRectProgram:ShaderProgram = new ShaderProgram(vLinker, fLinker);
|
||||||
"#c0=c0",
|
coloredRectProgram.upload(context3D);
|
||||||
"mov o0, c0",
|
|
||||||
]));
|
|
||||||
var coloredRectProgram:ShaderProgram = new ShaderProgram(vLinker, fLinker);
|
|
||||||
coloredRectProgram.upload(context);
|
|
||||||
|
|
||||||
context3DProperties.drawRectGeometry = rectGeometry;
|
context3DProperties.drawRectGeometry = rectGeometry;
|
||||||
context3DProperties.drawColoredRectProgram = coloredRectProgram;
|
context3DProperties.drawColoredRectProgram = coloredRectProgram;
|
||||||
properties[cachedContext3D] = context3DProperties;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (_width != context3DProperties.backBufferWidth || _height != context3DProperties.backBufferHeight || antiAlias != context3DProperties.backBufferAntiAlias) {
|
if (_width != context3DProperties.backBufferWidth || _height != context3DProperties.backBufferHeight || antiAlias != context3DProperties.backBufferAntiAlias) {
|
||||||
context3DProperties.backBufferWidth = _width;
|
context3DProperties.backBufferWidth = _width;
|
||||||
context3DProperties.backBufferHeight = _height;
|
context3DProperties.backBufferHeight = _height;
|
||||||
context3DProperties.backBufferAntiAlias = antiAlias;
|
context3DProperties.backBufferAntiAlias = antiAlias;
|
||||||
context.configureBackBuffer(_width, _height, antiAlias);
|
context3D.configureBackBuffer(_width, _height, antiAlias);
|
||||||
}
|
}
|
||||||
var r:Number = ((backgroundColor >> 16) & 0xff)/0xff;
|
|
||||||
var g:Number = ((backgroundColor >> 8) & 0xff)/0xff;
|
|
||||||
var b:Number = (backgroundColor & 0xff)/0xff;
|
|
||||||
if (canvas != null) {
|
|
||||||
r *= backgroundAlpha;
|
|
||||||
g *= backgroundAlpha;
|
|
||||||
b *= backgroundAlpha;
|
|
||||||
}
|
|
||||||
context.clear(r, g, b, backgroundAlpha);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
alternativa3d function processMouseEvents(context:Context3D, camera:Camera3D):void {
|
alternativa3d function processMouseEvents(context3D:Context3D, camera:Camera3D):void {
|
||||||
var i:int;
|
var i:int;
|
||||||
// Mouse events
|
// Mouse events
|
||||||
if (eventsLength > 0) {
|
if (eventsLength > 0) {
|
||||||
if (surfacesLength > 0) {
|
if (surfacesLength > 0) {
|
||||||
// Calculating the depth
|
// Calculating the depth
|
||||||
calculateSurfacesDepths(context, camera, _width, _height);
|
calculateSurfacesDepths(context3D, camera, _width, _height);
|
||||||
// Sorting by decreasing the depth
|
// Sorting by decreasing the depth
|
||||||
for (i = 0; i < raysLength; i++) {
|
for (i = 0; i < raysLength; i++) {
|
||||||
var raySurfaces:Vector.<Surface> = raysSurfaces[i];
|
var raySurfaces:Vector.<Surface> = raysSurfaces[i];
|
||||||
@@ -781,8 +762,8 @@ package alternativa.engine3d.core {
|
|||||||
context.setVertexBufferAt(6, null);
|
context.setVertexBufferAt(6, null);
|
||||||
context.setVertexBufferAt(7, null);
|
context.setVertexBufferAt(7, null);
|
||||||
|
|
||||||
var drawRectGeometry:Geometry = context3DProperties.drawRectGeometry;
|
var drawRectGeometry:Geometry = camera.context3DProperties.drawRectGeometry;
|
||||||
var drawColoredRectProgram:ShaderProgram = context3DProperties.drawColoredRectProgram;
|
var drawColoredRectProgram:ShaderProgram = camera.context3DProperties.drawColoredRectProgram;
|
||||||
|
|
||||||
// Rectangle
|
// Rectangle
|
||||||
var vLinker:Linker, fLinker:Linker;
|
var vLinker:Linker, fLinker:Linker;
|
||||||
@@ -888,7 +869,7 @@ package alternativa.engine3d.core {
|
|||||||
var procedure:Procedure = procedures[index];
|
var procedure:Procedure = procedures[index];
|
||||||
var object:Object3D = surface.object;
|
var object:Object3D = surface.object;
|
||||||
// Program
|
// Program
|
||||||
var drawDistanceProgram:ShaderProgram = context3DProperties.drawDistancePrograms[procedure];
|
var drawDistanceProgram:ShaderProgram = camera.context3DProperties.drawDistancePrograms[procedure];
|
||||||
if (drawDistanceProgram == null) {
|
if (drawDistanceProgram == null) {
|
||||||
// Assembling the vertex shader
|
// Assembling the vertex shader
|
||||||
var vertex:Linker = new Linker(Context3DProgramType.VERTEX);
|
var vertex:Linker = new Linker(Context3DProgramType.VERTEX);
|
||||||
@@ -907,7 +888,7 @@ package alternativa.engine3d.core {
|
|||||||
drawDistanceProgram = new ShaderProgram(vertex, drawDistanceFragment);
|
drawDistanceProgram = new ShaderProgram(vertex, drawDistanceFragment);
|
||||||
drawDistanceProgram.fragmentShader.varyings = drawDistanceProgram.vertexShader.varyings;
|
drawDistanceProgram.fragmentShader.varyings = drawDistanceProgram.vertexShader.varyings;
|
||||||
drawDistanceProgram.upload(context);
|
drawDistanceProgram.upload(context);
|
||||||
context3DProperties.drawDistancePrograms[procedure] = drawDistanceProgram;
|
camera.context3DProperties.drawDistancePrograms[procedure] = drawDistanceProgram;
|
||||||
}
|
}
|
||||||
var buffer:VertexBuffer3D = geometry.getVertexBuffer(VertexAttributes.POSITION);
|
var buffer:VertexBuffer3D = geometry.getVertexBuffer(VertexAttributes.POSITION);
|
||||||
if (buffer == null) return;
|
if (buffer == null) return;
|
||||||
@@ -1410,9 +1391,6 @@ package alternativa.engine3d.core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
import alternativa.engine3d.materials.ShaderProgram;
|
|
||||||
import alternativa.engine3d.resources.Geometry;
|
|
||||||
|
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.events.MouseEvent;
|
import flash.events.MouseEvent;
|
||||||
@@ -1420,7 +1398,6 @@ import flash.geom.ColorTransform;
|
|||||||
import flash.geom.Matrix;
|
import flash.geom.Matrix;
|
||||||
import flash.net.URLRequest;
|
import flash.net.URLRequest;
|
||||||
import flash.net.navigateToURL;
|
import flash.net.navigateToURL;
|
||||||
import flash.utils.Dictionary;
|
|
||||||
|
|
||||||
class Logo extends Sprite {
|
class Logo extends Sprite {
|
||||||
|
|
||||||
@@ -1518,17 +1495,3 @@ class Logo extends Sprite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Context3DViewProperties {
|
|
||||||
public var backBufferWidth:int = -1;
|
|
||||||
public var backBufferHeight:int = -1;
|
|
||||||
public var backBufferAntiAlias:int = -1;
|
|
||||||
|
|
||||||
// Mouse events
|
|
||||||
|
|
||||||
// Key - vertex program of object, value - program.
|
|
||||||
public var drawDistancePrograms:Dictionary = new Dictionary();
|
|
||||||
public var drawColoredRectProgram:ShaderProgram;
|
|
||||||
public var drawRectGeometry:Geometry;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user