Bläddra i källkod

a bit of support for alternate texture format (not complete)

Nicolas Cannasse 11 år sedan
förälder
incheckning
91691dc486
3 ändrade filer med 28 tillägg och 4 borttagningar
  1. 1 1
      h3d/impl/Driver.hx
  2. 11 3
      h3d/impl/GlDriver.hx
  3. 16 0
      h3d/mat/Data.hx

+ 1 - 1
h3d/impl/Driver.hx

@@ -7,7 +7,7 @@ typedef Texture = flash.display3D.textures.TextureBase;
 #elseif js
 typedef IndexBuffer = js.html.webgl.Buffer;
 typedef VertexBuffer = { b : js.html.webgl.Buffer, stride : Int };
-typedef Texture = { t : js.html.webgl.Texture, width : Int, height : Int, ?fb : js.html.webgl.Framebuffer, ?rb : js.html.webgl.Renderbuffer };
+typedef Texture = { t : js.html.webgl.Texture, width : Int, height : Int, fmt : Int, ?fb : js.html.webgl.Framebuffer, ?rb : js.html.webgl.Renderbuffer };
 #elseif cpp
 typedef IndexBuffer = openfl.gl.GLBuffer;
 typedef VertexBuffer = { b : openfl.gl.GLBuffer, stride : Int };

+ 11 - 3
h3d/impl/GlDriver.hx

@@ -288,13 +288,21 @@ class GlDriver extends Driver {
 	
 	override function allocTexture( t : h3d.mat.Texture ) : Texture {
 		var tt = gl.createTexture();
-		var tt : Texture = { t : tt, width : t.width, height : t.height };
+		var tt : Texture = { t : tt, width : t.width, height : t.height, fmt : GL.UNSIGNED_BYTE };
+		if( t.flags.has(FmtFloat) )
+			tt.fmt = GL.FLOAT;
+		else if( t.flags.has(Fmt5_5_5_1) )
+			tt.fmt = GL.UNSIGNED_SHORT_5_5_5_1;
+		else if( t.flags.has(Fmt5_6_5) )
+			tt.fmt = GL.UNSIGNED_SHORT_5_6_5;
+		else if( t.flags.has(Fmt4_4_4_4) )
+			tt.fmt = GL.UNSIGNED_SHORT_4_4_4_4;
 		t.lastFrame = frame;
 		gl.bindTexture(GL.TEXTURE_2D, tt.t);
 		var mipMap = t.flags.has(MipMapped) ? GL.LINEAR_MIPMAP_NEAREST : GL.LINEAR;
 		gl.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, mipMap);
 		gl.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, mipMap);
-		gl.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, tt.width, tt.height, 0, GL.RGBA, GL.UNSIGNED_BYTE, null);
+		gl.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, tt.width, tt.height, 0, GL.RGBA, tt.fmt, null);
 		if( t.flags.has(Target) ) {
 			var fb = gl.createFramebuffer();
 			gl.bindFramebuffer(GL.FRAMEBUFFER, fb);
@@ -476,7 +484,7 @@ class GlDriver extends Driver {
 		case StandardDerivatives:
 			gl.getExtension('OES_standard_derivatives') != null;
 		case FloatTextures:
-			gl.getExtension('OES_texture_float') != null;
+			gl.getExtension('OES_texture_float') != null && gl.getExtension('OES_texture_float_linear') != null;
 		}
 	}
 	

+ 16 - 0
h3d/mat/Data.hx

@@ -97,4 +97,20 @@ enum TextureFlags {
 		Inform that we will often perform upload operations on this texture
 	**/
 	Dynamic;
+	/**
+		The texture format will contain Float values
+	**/
+	FmtFloat;
+	/**
+		16-bit RGB format
+	**/
+	Fmt5_6_5;
+	/**
+		16-bit RGBA format
+	**/
+	Fmt4_4_4_4;
+	/**
+		16-bit RGBA format (1 bit of alpha)
+	**/
+	Fmt5_5_5_1;
 }