Sfoglia il codice sorgente

added camera.setCubeMap, allowed right handed camera rendering in GL

ncannasse 7 anni fa
parent
commit
e51551cd9a
4 ha cambiato i file con 57 aggiunte e 1 eliminazioni
  1. 22 0
      h3d/Camera.hx
  2. 10 0
      h3d/impl/Driver.hx
  3. 18 1
      h3d/impl/GlDriver.hx
  4. 7 0
      h3d/scene/Scene.hx

+ 22 - 0
h3d/Camera.hx

@@ -113,6 +113,28 @@ class Camera {
 		return miview;
 	}
 
+	/**
+		Setup camera for cubemap rendering on the given face.
+	**/
+	public function setCubeMap( face : Int ) {
+		var dx = 0, dy = 0, dz = 0;
+		switch( face ) {
+		case 0: dx = 1; up.set(0,1,0);
+		case 1: dx = -1; up.set(0,1,0);
+		case 2: dy = 1; up.set(0,0,-1);
+		case 3: dy = -1; up.set(0,0,1);
+		case 4: dz = 1; up.set(0,1,0);
+		case 5: dz = -1; up.set(0,1,0);
+		}
+		#if !hldx
+		rightHanded = true;
+		up.scale3(-1);
+		#end
+		pos.set(0,0,0);
+		target.set(dx,dy,dz);
+		setFovX(90,1);
+	}
+
 	/**
 		Transforms a 2D screen position into the 3D one according to the current camera.
 		The screenX and screenY values must be in the [-1,1] range.

+ 10 - 0
h3d/impl/Driver.hx

@@ -108,6 +108,13 @@ enum QueryKind {
 	Samples;
 }
 
+enum RenderFlag {
+	/**
+		0 = LeftHanded (default), 1 = RightHanded. Affects the meaning of triangle culling value.
+	**/
+	CameraHandness;
+}
+
 class Driver {
 
 	public var logEnable : Bool;
@@ -116,6 +123,9 @@ class Driver {
 		return false;
 	}
 
+	public function setRenderFlag( r : RenderFlag, value : Int ) {
+	}
+
 	public function isSupportedFormat( fmt : h3d.mat.Data.TextureFormat ) {
 		return false;
 	}

+ 18 - 1
h3d/impl/GlDriver.hx

@@ -165,6 +165,7 @@ class GlDriver extends Driver {
 	var glES : Null<Float>;
 	var shaderVersion : Null<Int>;
 	var firstShader = true;
+	var rightHanded = false;
 
 	public function new(antiAlias=0) {
 		#if js
@@ -219,6 +220,14 @@ class GlDriver extends Driver {
 		#end
 	}
 
+	override function setRenderFlag( r : RenderFlag, value : Int ) {
+		switch( r ) {
+		case CameraHandness:
+			rightHanded = value > 0;
+		default:
+		}
+	}
+
 	override function logImpl( str : String ) {
 		#if js
 		untyped console.log(str);
@@ -506,7 +515,15 @@ class GlDriver extends Driver {
 	}
 
 	override function selectMaterial( pass : Pass ) {
-		selectMaterialBits(@:privateAccess pass.bits);
+		var bits = @:privateAccess pass.bits;
+		if( rightHanded ) {
+			switch( pass.culling ) {
+			case Back: bits = (bits & ~Pass.culling_mask) | (2 << Pass.culling_offset);
+			case Front: bits = (bits & ~Pass.culling_mask) | (1 << Pass.culling_offset);
+			default:
+			}
+		}
+		selectMaterialBits(bits);
 		var s = defStencil;
 		if( pass.stencil == null ) {
 			if( curStEnabled ) {

+ 7 - 0
h3d/scene/Scene.hx

@@ -323,6 +323,10 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		else
 			camera.screenRatio = t.width / t.height;
 		camera.update();
+
+		if( camera.rightHanded )
+			engine.driver.setRenderFlag(CameraHandness,1);
+
 		ctx.camera = camera;
 		ctx.engine = engine;
 		ctx.scene = this;
@@ -370,6 +374,9 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		}
 		#end
 
+		if( camera.rightHanded )
+			engine.driver.setRenderFlag(CameraHandness,0);
+
 		ctx.done();
 		ctx.scene = null;
 		ctx.camera = null;