mirror of
https://github.com/MapMakersAndProgrammers/Alternativa3D.git
synced 2025-10-26 01:49:07 -07:00
Init mouse events data on first render
This commit is contained in:
@@ -63,7 +63,7 @@ package alternativa.engine3d.core {
|
||||
|
||||
private static var properties:Dictionary = new Dictionary(true);
|
||||
private var cachedContext3D:Context3D;
|
||||
private var context3DViewProperties:Context3DViewProperties;
|
||||
private var context3DProperties:Context3DViewProperties;
|
||||
|
||||
static private var drawDistanceFragment:Linker;
|
||||
static private var drawDistanceVertexProcedure:Procedure;
|
||||
@@ -109,11 +109,6 @@ package alternativa.engine3d.core {
|
||||
*/
|
||||
alternativa3d var _height:int;
|
||||
|
||||
private var backBufferContext3D:Context3D;
|
||||
private var backBufferWidth:int = -1;
|
||||
private var backBufferHeight:int = -1;
|
||||
private var backBufferAntiAlias:int = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -495,11 +490,47 @@ package alternativa.engine3d.core {
|
||||
createRenderBitmap();
|
||||
}
|
||||
}
|
||||
if (_width != backBufferWidth || _height != backBufferHeight || antiAlias != backBufferAntiAlias || context != backBufferContext3D) {
|
||||
backBufferWidth = _width;
|
||||
backBufferHeight = _height;
|
||||
backBufferAntiAlias = antiAlias;
|
||||
backBufferContext3D = context;
|
||||
if (context != cachedContext3D) {
|
||||
// Get properties.
|
||||
cachedContext3D = context;
|
||||
context3DProperties = properties[cachedContext3D];
|
||||
if (context3DProperties == null) {
|
||||
context3DProperties = new Context3DViewProperties();
|
||||
// Inititalize data for mouse events
|
||||
var rectGeometry:Geometry = new Geometry(4);
|
||||
rectGeometry.addVertexStream([VertexAttributes.POSITION, VertexAttributes.POSITION, VertexAttributes.POSITION, VertexAttributes.TEXCOORDS[0], VertexAttributes.TEXCOORDS[0]]);
|
||||
rectGeometry.setAttributeValues(VertexAttributes.POSITION, Vector.<Number>([0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1]));
|
||||
rectGeometry.setAttributeValues(VertexAttributes.TEXCOORDS[0], Vector.<Number>([0, 0, 0, 1, 1, 1, 1, 0]));
|
||||
rectGeometry.indices = Vector.<uint>([0, 1, 3, 2, 3, 1]);
|
||||
rectGeometry.upload(context);
|
||||
var vLinker:Linker = new Linker(Context3DProgramType.VERTEX);
|
||||
vLinker.addProcedure(Procedure.compileFromArray([
|
||||
"#a0=a0",
|
||||
"#c0=c0",
|
||||
"mul t0.x, a0.x, c0.x",
|
||||
"mul t0.y, a0.y, c0.y",
|
||||
"add o0.x, t0.x, c0.z",
|
||||
"add o0.y, t0.y, c0.w",
|
||||
"mov o0.z, a0.z",
|
||||
"mov o0.w, a0.z",
|
||||
]));
|
||||
var fLinker:Linker = new Linker(Context3DProgramType.FRAGMENT);
|
||||
fLinker.addProcedure(Procedure.compileFromArray([
|
||||
"#c0=c0",
|
||||
"mov o0, c0",
|
||||
]));
|
||||
var coloredRectProgram:ShaderProgram = new ShaderProgram(vLinker, fLinker);
|
||||
coloredRectProgram.upload(context);
|
||||
|
||||
context3DProperties.drawRectGeometry = rectGeometry;
|
||||
context3DProperties.drawColoredRectProgram = coloredRectProgram;
|
||||
properties[cachedContext3D] = context3DProperties;
|
||||
}
|
||||
}
|
||||
if (_width != context3DProperties.backBufferWidth || _height != context3DProperties.backBufferHeight || antiAlias != context3DProperties.backBufferAntiAlias) {
|
||||
context3DProperties.backBufferWidth = _width;
|
||||
context3DProperties.backBufferHeight = _height;
|
||||
context3DProperties.backBufferAntiAlias = antiAlias;
|
||||
context.configureBackBuffer(_width, _height, antiAlias);
|
||||
}
|
||||
var r:Number = ((backgroundColor >> 16) & 0xff)/0xff;
|
||||
@@ -647,45 +678,8 @@ package alternativa.engine3d.core {
|
||||
context.setVertexBufferAt(6, null);
|
||||
context.setVertexBufferAt(7, null);
|
||||
|
||||
if (context != cachedContext3D) {
|
||||
// Get properties.
|
||||
cachedContext3D = context;
|
||||
context3DViewProperties = properties[cachedContext3D];
|
||||
if (context3DViewProperties == null) {
|
||||
// TODO: create programs on first render
|
||||
context3DViewProperties = new Context3DViewProperties();
|
||||
var rectGeometry:Geometry = new Geometry(4);
|
||||
rectGeometry.addVertexStream([VertexAttributes.POSITION, VertexAttributes.POSITION, VertexAttributes.POSITION, VertexAttributes.TEXCOORDS[0], VertexAttributes.TEXCOORDS[0]]);
|
||||
rectGeometry.setAttributeValues(VertexAttributes.POSITION, Vector.<Number>([0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1]));
|
||||
rectGeometry.setAttributeValues(VertexAttributes.TEXCOORDS[0], Vector.<Number>([0, 0, 0, 1, 1, 1, 1, 0]));
|
||||
rectGeometry.indices = Vector.<uint>([0, 1, 3, 2, 3, 1]);
|
||||
rectGeometry.upload(context);
|
||||
vLinker = new Linker(Context3DProgramType.VERTEX);
|
||||
vLinker.addProcedure(Procedure.compileFromArray([
|
||||
"#a0=a0",
|
||||
"#c0=c0",
|
||||
"mul t0.x, a0.x, c0.x",
|
||||
"mul t0.y, a0.y, c0.y",
|
||||
"add o0.x, t0.x, c0.z",
|
||||
"add o0.y, t0.y, c0.w",
|
||||
"mov o0.z, a0.z",
|
||||
"mov o0.w, a0.z",
|
||||
]));
|
||||
fLinker = new Linker(Context3DProgramType.FRAGMENT);
|
||||
fLinker.addProcedure(Procedure.compileFromArray([
|
||||
"#c0=c0",
|
||||
"mov o0, c0",
|
||||
]));
|
||||
var coloredRectProgram:ShaderProgram = new ShaderProgram(vLinker, fLinker);
|
||||
coloredRectProgram.upload(context);
|
||||
|
||||
context3DViewProperties.drawRectGeometry = rectGeometry;
|
||||
context3DViewProperties.drawColoredRectProgram = coloredRectProgram;
|
||||
properties[cachedContext3D] = context3DViewProperties;
|
||||
}
|
||||
}
|
||||
var drawRectGeometry:Geometry = context3DViewProperties.drawRectGeometry;
|
||||
var drawColoredRectProgram:ShaderProgram = context3DViewProperties.drawColoredRectProgram;
|
||||
var drawRectGeometry:Geometry = context3DProperties.drawRectGeometry;
|
||||
var drawColoredRectProgram:ShaderProgram = context3DProperties.drawColoredRectProgram;
|
||||
|
||||
// Rectangle
|
||||
var vLinker:Linker, fLinker:Linker;
|
||||
@@ -791,7 +785,7 @@ package alternativa.engine3d.core {
|
||||
var procedure:Procedure = procedures[index];
|
||||
var object:Object3D = surface.object;
|
||||
// Program
|
||||
var drawDistanceProgram:ShaderProgram = context3DViewProperties.drawDistancePrograms[procedure];
|
||||
var drawDistanceProgram:ShaderProgram = context3DProperties.drawDistancePrograms[procedure];
|
||||
if (drawDistanceProgram == null) {
|
||||
// Assembling the vertex shader
|
||||
var vertex:Linker = new Linker(Context3DProgramType.VERTEX);
|
||||
@@ -810,7 +804,7 @@ package alternativa.engine3d.core {
|
||||
drawDistanceProgram = new ShaderProgram(vertex, drawDistanceFragment);
|
||||
drawDistanceProgram.fragmentShader.varyings = drawDistanceProgram.vertexShader.varyings;
|
||||
drawDistanceProgram.upload(context);
|
||||
context3DViewProperties.drawDistancePrograms[procedure] = drawDistanceProgram;
|
||||
context3DProperties.drawDistancePrograms[procedure] = drawDistanceProgram;
|
||||
}
|
||||
var buffer:VertexBuffer3D = geometry.getVertexBuffer(VertexAttributes.POSITION);
|
||||
if (buffer == null) return;
|
||||
@@ -1423,6 +1417,12 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user