mirror of
https://github.com/MapMakersAndProgrammers/Alternativa3D.git
synced 2025-10-26 18:09:14 -07:00
Get context properties in Camera3D
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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,9 +43,6 @@ package alternativa.engine3d.core {
|
|||||||
|
|
||||||
alternativa3d var drawUnits:Vector.<DrawUnit> = new Vector.<DrawUnit>();
|
alternativa3d var drawUnits:Vector.<DrawUnit> = new Vector.<DrawUnit>();
|
||||||
|
|
||||||
alternativa3d var isConstrainedMode:Boolean = false;
|
|
||||||
|
|
||||||
protected var _context3D:Context3D;
|
|
||||||
protected var _contextProperties:RendererContext3DProperties;
|
protected var _contextProperties:RendererContext3DProperties;
|
||||||
|
|
||||||
alternativa3d function render(context3D:Context3D):void {
|
alternativa3d function render(context3D:Context3D):void {
|
||||||
@@ -61,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;
|
||||||
@@ -92,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;
|
||||||
@@ -182,15 +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;
|
|
||||||
isConstrainedMode = _context3D.driverInfo.lastIndexOf("(Baseline Constrained)") >= 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -825,7 +825,7 @@ package alternativa.engine3d.materials {
|
|||||||
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.renderer.isConstrainedMode) {
|
if (camera.context3DProperties.isConstrained) {
|
||||||
// fallback to simpler material
|
// fallback to simpler material
|
||||||
if (lightMap == null) {
|
if (lightMap == null) {
|
||||||
fallbackTextureMaterial.diffuseMap = diffuseMap;
|
fallbackTextureMaterial.diffuseMap = diffuseMap;
|
||||||
|
|||||||
@@ -995,7 +995,7 @@ 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.renderer.isConstrainedMode) {
|
if (camera.context3DProperties.isConstrained) {
|
||||||
// fallback to simpler material
|
// fallback to simpler material
|
||||||
if (lightMap == null) {
|
if (lightMap == null) {
|
||||||
fallbackTextureMaterial.diffuseMap = diffuseMap;
|
fallbackTextureMaterial.diffuseMap = diffuseMap;
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ 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.renderer.isConstrainedMode) {
|
if (camera.context3DProperties.isConstrained) {
|
||||||
// fallback to texture material
|
// fallback to texture material
|
||||||
fallbackMaterial.diffuseMap = diffuseMap;
|
fallbackMaterial.diffuseMap = diffuseMap;
|
||||||
fallbackMaterial.opacityMap = opacityMap;
|
fallbackMaterial.opacityMap = opacityMap;
|
||||||
|
|||||||
@@ -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