Преглед на файлове

common 2d/3d render context + 2d texture cache

Nicolas Cannasse преди 10 години
родител
ревизия
d3a845ad79
променени са 4 файла, в които са добавени 25 реда и са изтрити 19 реда
  1. 5 9
      h2d/RenderContext.hx
  2. 17 0
      h3d/impl/RenderContext.hx
  3. 1 1
      h3d/pass/TextureCache.hx
  4. 2 9
      h3d/scene/RenderContext.hx

+ 5 - 9
h2d/RenderContext.hx

@@ -1,15 +1,12 @@
 package h2d;
 
-class RenderContext {
-
-	public var engine : h3d.Engine;
-	public var time : Float;
-	public var elapsedTime : Float;
-	public var frame : Int;
+class RenderContext extends h3d.impl.RenderContext {
 
 	public var buffer : hxd.FloatBuffer;
 	public var bufPos : Int;
 
+	public var textures : h3d.pass.TextureCache;
+
 	public var tmpBounds = new h2d.col.Bounds();
 	var texture : h3d.mat.Texture;
 	var baseShader : h3d.shader.Base2d;
@@ -25,10 +22,8 @@ class RenderContext {
 	var targetsStack : Array<{ t : h3d.mat.Texture, x : Int, y : Int }>;
 
 	public function new(s2d) {
+		super();
 		this.s2d = s2d;
-		frame = 0;
-		time = 0.;
-		elapsedTime = 1. / hxd.Stage.getInstance().getFrameRate();
 		buffer = new hxd.FloatBuffer();
 		bufPos = 0;
 		manager = new h3d.shader.Manager(["output.position", "output.color"]);
@@ -40,6 +35,7 @@ class RenderContext {
 		baseShader.zValue = 0.;
 		baseShaderList = new hxsl.ShaderList(baseShader);
 		targetsStack = [];
+		textures = new h3d.pass.TextureCache();
 	}
 
 	public function begin() {

+ 17 - 0
h3d/impl/RenderContext.hx

@@ -0,0 +1,17 @@
+package h3d.impl;
+
+class RenderContext {
+
+	public var engine : h3d.Engine;
+	public var time : Float;
+	public var elapsedTime : Float;
+	public var frame : Int;
+
+	function new() {
+		engine = h3d.Engine.getCurrent();
+		frame = 0;
+		time = 0.;
+		elapsedTime = 1. / hxd.Stage.getInstance().getFrameRate();
+	}
+
+}

+ 1 - 1
h3d/pass/TextureCache.hx

@@ -19,7 +19,7 @@ class TextureCache {
 		return cache[index];
 	}
 
-	public function allocTarget( name : String, ctx : h3d.scene.RenderContext, width : Int, height : Int, hasDepth=true ) {
+	public function allocTarget( name : String, ctx : h3d.impl.RenderContext, width : Int, height : Int, hasDepth=true ) {
 		if( frame != ctx.frame ) {
 			// dispose extra textures we didn't use
 			while( cache.length > position ) {

+ 2 - 9
h3d/scene/RenderContext.hx

@@ -1,14 +1,9 @@
 package h3d.scene;
 import h3d.pass.Object in ObjectPass;
 
-class RenderContext {
+class RenderContext extends h3d.impl.RenderContext {
 
-	public var engine : h3d.Engine;
 	public var camera : h3d.Camera;
-	public var time : Float;
-	public var elapsedTime : Float;
-	public var frame : Int;
-
 	public var drawPass : ObjectPass;
 
 	public var sharedGlobals : Map<Int,Dynamic>;
@@ -23,9 +18,7 @@ class RenderContext {
 	var lights : Light;
 
 	public function new() {
-		frame = 0;
-		time = 0.;
-		elapsedTime = 1. / hxd.Stage.getInstance().getFrameRate();
+		super();
 		cachedShaderList = [];
 	}