mirror of
https://github.com/MapMakersAndProgrammers/Alternativa3D.git
synced 2025-10-27 02:19:11 -07:00
Merge branch with constrained mode support
This commit is contained in:
@@ -46,6 +46,12 @@ package alternativa.engine3d.core {
|
|||||||
*/
|
*/
|
||||||
public class Camera3D extends Object3D {
|
public class Camera3D extends Object3D {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* Key - context, value - properties.
|
||||||
|
*/
|
||||||
|
alternativa3d static var context3DPropertiesPool:Dictionary = new Dictionary(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The viewport defines part of screen to which renders image seen by the camera.
|
* The viewport defines part of screen to which renders image seen by the camera.
|
||||||
* If viewport is not defined, the camera would not draws anything.
|
* If viewport is not defined, the camera would not draws anything.
|
||||||
@@ -156,6 +162,11 @@ public class Camera3D extends Object3D {
|
|||||||
*/
|
*/
|
||||||
alternativa3d var context3D:Context3D;
|
alternativa3d var context3D:Context3D;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
alternativa3d var context3DProperties:RendererContext3DProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* Camera's renderer. If is not defined, the camera will no draw anything.
|
* Camera's renderer. If is not defined, the camera will no draw anything.
|
||||||
@@ -195,7 +206,6 @@ public class Camera3D extends Object3D {
|
|||||||
* @param stage3D <code>Stage3D</code> to which image will be rendered.
|
* @param stage3D <code>Stage3D</code> to which image will be rendered.
|
||||||
*/
|
*/
|
||||||
public function render(stage3D:Stage3D):void {
|
public function render(stage3D:Stage3D):void {
|
||||||
// TODO: don't check mouse events if no listeners
|
|
||||||
var i:int;
|
var i:int;
|
||||||
var j:int;
|
var j:int;
|
||||||
var light:Light3D;
|
var light:Light3D;
|
||||||
@@ -214,11 +224,26 @@ public class Camera3D extends Object3D {
|
|||||||
ambient[2] = 0;
|
ambient[2] = 0;
|
||||||
ambient[3] = 1;
|
ambient[3] = 1;
|
||||||
// Receiving the context
|
// Receiving the context
|
||||||
context3D = stage3D.context3D;
|
var currentContext3D:Context3D = stage3D.context3D;
|
||||||
|
if (currentContext3D != context3D) {
|
||||||
|
if (currentContext3D != null) {
|
||||||
|
context3DProperties = context3DPropertiesPool[currentContext3D];
|
||||||
|
if (context3DProperties == null) {
|
||||||
|
context3DProperties = new RendererContext3DProperties();
|
||||||
|
context3DProperties.isConstrained = currentContext3D.driverInfo.lastIndexOf("(Baseline Constrained)") >= 0;
|
||||||
|
context3DPropertiesPool[currentContext3D] = context3DProperties;
|
||||||
|
}
|
||||||
|
context3D = currentContext3D;
|
||||||
|
} else {
|
||||||
|
context3D = null;
|
||||||
|
context3DProperties = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (context3D != null && view != null && renderer != null && (view.stage != null || view._canvas != null)) {
|
if (context3D != null && view != null && renderer != null && (view.stage != null || view._canvas != null)) {
|
||||||
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.prepareToRender(stage3D, context3D);
|
||||||
// Transformations calculating
|
// Transformations calculating
|
||||||
@@ -403,7 +428,6 @@ public class Camera3D extends Object3D {
|
|||||||
lights.length = 0;
|
lights.length = 0;
|
||||||
childLights.length = 0;
|
childLights.length = 0;
|
||||||
occluders.length = 0;
|
occluders.length = 0;
|
||||||
context3D = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
* You may add additional accurate notices of copyright ownership.
|
* You may add additional accurate notices of copyright ownership.
|
||||||
*
|
*
|
||||||
* It is desirable to notify that Covered Software was "Powered by AlternativaPlatform" with link to http://www.alternativaplatform.com/
|
* It is desirable to notify that Covered Software was "Powered by AlternativaPlatform" with link to http://www.alternativaplatform.com/
|
||||||
* */
|
*
|
||||||
|
*/
|
||||||
package alternativa.engine3d.core {
|
package alternativa.engine3d.core {
|
||||||
|
|
||||||
import alternativa.engine3d.alternativa3d;
|
import alternativa.engine3d.alternativa3d;
|
||||||
@@ -16,7 +16,6 @@ package alternativa.engine3d.core {
|
|||||||
import flash.display3D.Context3DProgramType;
|
import flash.display3D.Context3DProgramType;
|
||||||
import flash.display3D.IndexBuffer3D;
|
import flash.display3D.IndexBuffer3D;
|
||||||
import flash.display3D.Program3D;
|
import flash.display3D.Program3D;
|
||||||
import flash.utils.Dictionary;
|
|
||||||
|
|
||||||
use namespace alternativa3d;
|
use namespace alternativa3d;
|
||||||
|
|
||||||
@@ -37,9 +36,6 @@ 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;
|
||||||
|
|
||||||
@@ -47,7 +43,6 @@ package alternativa.engine3d.core {
|
|||||||
|
|
||||||
alternativa3d var drawUnits:Vector.<DrawUnit> = new Vector.<DrawUnit>();
|
alternativa3d var drawUnits:Vector.<DrawUnit> = new Vector.<DrawUnit>();
|
||||||
|
|
||||||
protected var _context3D:Context3D;
|
|
||||||
protected var _contextProperties:RendererContext3DProperties;
|
protected var _contextProperties:RendererContext3DProperties;
|
||||||
|
|
||||||
alternativa3d function render(context3D:Context3D):void {
|
alternativa3d function render(context3D:Context3D):void {
|
||||||
@@ -59,29 +54,29 @@ package alternativa.engine3d.core {
|
|||||||
if (list != null) {
|
if (list != null) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case SKY:
|
case SKY:
|
||||||
_context3D.setDepthTest(false, Context3DCompareMode.ALWAYS);
|
context3D.setDepthTest(false, Context3DCompareMode.ALWAYS);
|
||||||
break;
|
break;
|
||||||
case OPAQUE:
|
case OPAQUE:
|
||||||
_context3D.setDepthTest(true, Context3DCompareMode.LESS);
|
context3D.setDepthTest(true, Context3DCompareMode.LESS);
|
||||||
break;
|
break;
|
||||||
case OPAQUE_OVERHEAD:
|
case OPAQUE_OVERHEAD:
|
||||||
_context3D.setDepthTest(false, Context3DCompareMode.EQUAL);
|
context3D.setDepthTest(false, Context3DCompareMode.EQUAL);
|
||||||
break;
|
break;
|
||||||
case DECALS:
|
case DECALS:
|
||||||
_context3D.setDepthTest(false, Context3DCompareMode.LESS_EQUAL);
|
context3D.setDepthTest(false, Context3DCompareMode.LESS_EQUAL);
|
||||||
break;
|
break;
|
||||||
case TRANSPARENT_SORT:
|
case TRANSPARENT_SORT:
|
||||||
if (list.next != null) list = sortByAverageZ(list);
|
if (list.next != null) list = sortByAverageZ(list);
|
||||||
_context3D.setDepthTest(false, Context3DCompareMode.LESS);
|
context3D.setDepthTest(false, Context3DCompareMode.LESS);
|
||||||
break;
|
break;
|
||||||
case NEXT_LAYER:
|
case NEXT_LAYER:
|
||||||
_context3D.setDepthTest(false, Context3DCompareMode.ALWAYS);
|
context3D.setDepthTest(false, Context3DCompareMode.ALWAYS);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Rendering
|
// Rendering
|
||||||
while (list != null) {
|
while (list != null) {
|
||||||
var next:DrawUnit = list.next;
|
var next:DrawUnit = list.next;
|
||||||
renderDrawUnit(list, _context3D, camera);
|
renderDrawUnit(list, context3D, camera);
|
||||||
// Send to collector
|
// Send to collector
|
||||||
list.clear();
|
list.clear();
|
||||||
list.next = collector;
|
list.next = collector;
|
||||||
@@ -90,6 +85,7 @@ package alternativa.engine3d.core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: not free buffers and textures in each renderer, only when full camera cycle finishes.
|
||||||
freeContext3DProperties(context3D);
|
freeContext3DProperties(context3D);
|
||||||
// Clear
|
// Clear
|
||||||
drawUnits.length = 0;
|
drawUnits.length = 0;
|
||||||
@@ -180,14 +176,7 @@ package alternativa.engine3d.core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function updateContext3D(value:Context3D):void {
|
protected function updateContext3D(value:Context3D):void {
|
||||||
if (_context3D != value) {
|
_contextProperties = camera.context3DProperties;
|
||||||
_contextProperties = properties[value];
|
|
||||||
if (_contextProperties == null) {
|
|
||||||
_contextProperties = new RendererContext3DProperties();
|
|
||||||
properties[value] = _contextProperties;
|
|
||||||
}
|
|
||||||
_context3D = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ package alternativa.engine3d.core {
|
|||||||
*/
|
*/
|
||||||
public class RendererContext3DProperties {
|
public class RendererContext3DProperties {
|
||||||
|
|
||||||
|
public var isConstrained:Boolean = false;
|
||||||
|
|
||||||
public var usedBuffers:uint = 0;
|
public var usedBuffers:uint = 0;
|
||||||
public var usedTextures:uint = 0;
|
public var usedTextures:uint = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -310,6 +310,15 @@ package alternativa.engine3d.materials {
|
|||||||
"mov v0, a0"
|
"mov v0, a0"
|
||||||
], "passLightMapUVProcedure");
|
], "passLightMapUVProcedure");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
alternativa3d static var fallbackTextureMaterial:TextureMaterial = new TextureMaterial();
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
alternativa3d static var fallbackLightMapMaterial:LightMapMaterial = new LightMapMaterial();
|
||||||
|
|
||||||
private var _normalMapSpace:int = NormalMapSpace.TANGENT_RIGHT_HANDED;
|
private var _normalMapSpace:int = NormalMapSpace.TANGENT_RIGHT_HANDED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -815,6 +824,31 @@ package alternativa.engine3d.materials {
|
|||||||
if (_normalMap != null && _normalMap._texture == null) return;
|
if (_normalMap != null && _normalMap._texture == null) return;
|
||||||
if (_reflectionMap != null && _reflectionMap._texture == null) return;
|
if (_reflectionMap != null && _reflectionMap._texture == null) return;
|
||||||
if (_lightMap != null && _lightMap._texture == null) return;
|
if (_lightMap != null && _lightMap._texture == null) return;
|
||||||
|
|
||||||
|
if (camera.context3DProperties.isConstrained) {
|
||||||
|
// fallback to simpler material
|
||||||
|
if (lightMap == null) {
|
||||||
|
fallbackTextureMaterial.diffuseMap = diffuseMap;
|
||||||
|
fallbackTextureMaterial.opacityMap = opacityMap;
|
||||||
|
fallbackTextureMaterial.alphaThreshold = alphaThreshold;
|
||||||
|
fallbackTextureMaterial.alpha = alpha;
|
||||||
|
fallbackTextureMaterial.opaquePass = opaquePass;
|
||||||
|
fallbackTextureMaterial.transparentPass = transparentPass;
|
||||||
|
fallbackTextureMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
|
||||||
|
} else {
|
||||||
|
fallbackLightMapMaterial.diffuseMap = diffuseMap;
|
||||||
|
fallbackLightMapMaterial.lightMap = lightMap;
|
||||||
|
fallbackLightMapMaterial.lightMapChannel = lightMapChannel;
|
||||||
|
fallbackLightMapMaterial.opacityMap = opacityMap;
|
||||||
|
fallbackLightMapMaterial.alphaThreshold = alphaThreshold;
|
||||||
|
fallbackLightMapMaterial.alpha = alpha;
|
||||||
|
fallbackLightMapMaterial.opaquePass = opaquePass;
|
||||||
|
fallbackLightMapMaterial.transparentPass = transparentPass;
|
||||||
|
fallbackLightMapMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var object:Object3D = surface.object;
|
var object:Object3D = surface.object;
|
||||||
|
|
||||||
// Program
|
// Program
|
||||||
|
|||||||
@@ -307,6 +307,15 @@ package alternativa.engine3d.materials {
|
|||||||
"mov v0, a0"
|
"mov v0, a0"
|
||||||
], "passLightMapUVProcedure");
|
], "passLightMapUVProcedure");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
alternativa3d static var fallbackTextureMaterial:TextureMaterial = new TextureMaterial();
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
alternativa3d static var fallbackLightMapMaterial:LightMapMaterial = new LightMapMaterial();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normal map.
|
* Normal map.
|
||||||
*/
|
*/
|
||||||
@@ -986,6 +995,30 @@ package alternativa.engine3d.materials {
|
|||||||
// Check if textures uploaded in to the context.
|
// Check if textures uploaded in to the context.
|
||||||
if (opacityMap != null && opacityMap._texture == null || glossinessMap != null && glossinessMap._texture == null || specularMap != null && specularMap._texture == null || lightMap != null && lightMap._texture == null) return;
|
if (opacityMap != null && opacityMap._texture == null || glossinessMap != null && glossinessMap._texture == null || specularMap != null && specularMap._texture == null || lightMap != null && lightMap._texture == null) return;
|
||||||
|
|
||||||
|
if (camera.context3DProperties.isConstrained) {
|
||||||
|
// fallback to simpler material
|
||||||
|
if (lightMap == null) {
|
||||||
|
fallbackTextureMaterial.diffuseMap = diffuseMap;
|
||||||
|
fallbackTextureMaterial.opacityMap = opacityMap;
|
||||||
|
fallbackTextureMaterial.alphaThreshold = alphaThreshold;
|
||||||
|
fallbackTextureMaterial.alpha = alpha;
|
||||||
|
fallbackTextureMaterial.opaquePass = opaquePass;
|
||||||
|
fallbackTextureMaterial.transparentPass = transparentPass;
|
||||||
|
fallbackTextureMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
|
||||||
|
} else {
|
||||||
|
fallbackLightMapMaterial.diffuseMap = diffuseMap;
|
||||||
|
fallbackLightMapMaterial.lightMap = lightMap;
|
||||||
|
fallbackLightMapMaterial.lightMapChannel = lightMapChannel;
|
||||||
|
fallbackLightMapMaterial.opacityMap = opacityMap;
|
||||||
|
fallbackLightMapMaterial.alphaThreshold = alphaThreshold;
|
||||||
|
fallbackLightMapMaterial.alpha = alpha;
|
||||||
|
fallbackLightMapMaterial.opaquePass = opaquePass;
|
||||||
|
fallbackLightMapMaterial.transparentPass = transparentPass;
|
||||||
|
fallbackLightMapMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var object:Object3D = surface.object;
|
var object:Object3D = surface.object;
|
||||||
|
|
||||||
// Buffers
|
// Buffers
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ package alternativa.engine3d.materials {
|
|||||||
|
|
||||||
private static const _lightsProcedures:Dictionary = new Dictionary(true);
|
private static const _lightsProcedures:Dictionary = new Dictionary(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
alternativa3d static var fallbackMaterial:TextureMaterial = new TextureMaterial();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new VertexLightTextureMaterial instance.
|
* Creates a new VertexLightTextureMaterial instance.
|
||||||
*
|
*
|
||||||
@@ -282,6 +287,18 @@ package alternativa.engine3d.materials {
|
|||||||
override alternativa3d function collectDraws(camera:Camera3D, surface:Surface, geometry:Geometry, lights:Vector.<Light3D>, lightsLength:int, useShadow:Boolean, objectRenderPriority:int = -1):void {
|
override alternativa3d function collectDraws(camera:Camera3D, surface:Surface, geometry:Geometry, lights:Vector.<Light3D>, lightsLength:int, useShadow:Boolean, objectRenderPriority:int = -1):void {
|
||||||
if (diffuseMap == null || diffuseMap._texture == null || opacityMap != null && opacityMap._texture == null) return;
|
if (diffuseMap == null || diffuseMap._texture == null || opacityMap != null && opacityMap._texture == null) return;
|
||||||
|
|
||||||
|
if (camera.context3DProperties.isConstrained) {
|
||||||
|
// fallback to texture material
|
||||||
|
fallbackMaterial.diffuseMap = diffuseMap;
|
||||||
|
fallbackMaterial.opacityMap = opacityMap;
|
||||||
|
fallbackMaterial.alphaThreshold = alphaThreshold;
|
||||||
|
fallbackMaterial.alpha = alpha;
|
||||||
|
fallbackMaterial.opaquePass = opaquePass;
|
||||||
|
fallbackMaterial.transparentPass = transparentPass;
|
||||||
|
fallbackMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var object:Object3D = surface.object;
|
var object:Object3D = surface.object;
|
||||||
|
|
||||||
// Buffers
|
// Buffers
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ package alternativa.engine3d.objects {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
override alternativa3d function calculateVisibility(camera:Camera3D):void {
|
override alternativa3d function calculateVisibility(camera:Camera3D):void {
|
||||||
|
// TODO: optimize - use square of distance
|
||||||
var distance:Number = Math.sqrt(localToCameraTransform.d*localToCameraTransform.d + localToCameraTransform.h*localToCameraTransform.h + localToCameraTransform.l*localToCameraTransform.l);
|
var distance:Number = Math.sqrt(localToCameraTransform.d*localToCameraTransform.d + localToCameraTransform.h*localToCameraTransform.h + localToCameraTransform.l*localToCameraTransform.l);
|
||||||
for (level = levelList; level != null; level = level.next) {
|
for (level = levelList; level != null; level = level.next) {
|
||||||
if (distance <= level.distance) {
|
if (distance <= level.distance) {
|
||||||
|
|||||||
Reference in New Issue
Block a user