Ver Fonte

partial SRGB texture support

ncannasse há 7 anos atrás
pai
commit
7db048e23e
6 ficheiros alterados com 29 adições e 6 exclusões
  1. 1 1
      h3d/impl/DirectXDriver.hx
  2. 4 0
      h3d/impl/Driver.hx
  3. 16 3
      h3d/impl/GlDriver.hx
  4. 4 0
      h3d/mat/Texture.hx
  5. 2 0
      hxd/PixelFormat.hx
  6. 2 2
      hxd/Pixels.hx

+ 1 - 1
h3d/impl/DirectXDriver.hx

@@ -660,7 +660,7 @@ class DirectXDriver extends h3d.impl.Driver {
 
 	override function hasFeature(f:Feature) {
 		return switch(f) {
-		case StandardDerivatives, FloatTextures, AllocDepthBuffer, HardwareAccelerated, MultipleRenderTargets:
+		case StandardDerivatives, FloatTextures, AllocDepthBuffer, HardwareAccelerated, MultipleRenderTargets, SRGBTextures:
 			true;
 		case Queries:
 			false;

+ 4 - 0
h3d/impl/Driver.hx

@@ -83,6 +83,10 @@ enum Feature {
 		Does it supports query objects API.
 	*/
 	Queries;
+	/*
+		Supports gamma correct textures
+	*/
+	SRGBTextures;
 }
 
 enum QueryKind {

+ 16 - 3
h3d/impl/GlDriver.hx

@@ -21,6 +21,10 @@ private extern class GL2 extends js.html.webgl.GL {
 	static inline var RGBA8	   = 0x8058;
 	static inline var BGRA 		 = 0x80E1;
 	static inline var HALF_FLOAT = 0x140B;
+	static inline var SRGB       = 0x8C40;
+	static inline var SRGB8      = 0x8C41;
+	static inline var SRGB_ALPHA = 0x8C42;
+	static inline var SRGB8_ALPHA = 0x8C43;
 }
 private typedef Uniform = js.html.webgl.UniformLocation;
 private typedef Program = js.html.webgl.Program;
@@ -639,9 +643,10 @@ class GlDriver extends Driver {
 
 	function getChannels( t : Texture ) {
 		return switch( t.internalFmt ) {
-		case GL2.RGBA32F, GL2.RGBA16F: GL.RGBA;
+		case GL2.RGBA32F, GL2.RGBA16F, GL2.SRGB_ALPHA, GL2.SRGB8_ALPHA: GL.RGBA;
 		case GL2.ALPHA16F, GL2.ALPHA32F: GL.ALPHA;
 		case GL2.RGBA8: GL2.BGRA;
+		case GL2.SRGB, GL2.SRGB8: GL.RGB;
 		case GL.RGBA: GL.RGBA;
 		case GL.ALPHA: GL.ALPHA;
 		default: throw "Invalid format " + t.internalFmt;
@@ -652,6 +657,7 @@ class GlDriver extends Driver {
 		return switch( fmt ) {
 		case RGBA, ALPHA8: true;
 		case RGBA16F, RGBA32F, ALPHA16F, ALPHA32F: hasFeature(FloatTextures);
+		case SRGB, SRGB_ALPHA: hasFeature(SRGBTextures);
 		default: false;
 		}
 	}
@@ -679,6 +685,10 @@ class GlDriver extends Driver {
 			tt.internalFmt = GL2.ALPHA32F;
 		case BGRA:
 			tt.internalFmt = GL2.RGBA8;
+		case SRGB:
+			tt.internalFmt = GL2.SRGB8;
+		case SRGB_ALPHA:
+			tt.internalFmt = GL2.SRGB8_ALPHA;
 		default:
 			throw "Unsupported texture format "+t.format;
 		}
@@ -1204,12 +1214,12 @@ class GlDriver extends Driver {
 		return switch( f ) {
 		#if hl
 
-		case StandardDerivatives, FloatTextures, MultipleRenderTargets, Queries:
+		case StandardDerivatives, FloatTextures, MultipleRenderTargets, Queries, SRGBTextures:
 			true;
 
 		#else
 
-		case StandardDerivatives, MultipleRenderTargets if( glES >= 3 ):
+		case StandardDerivatives, MultipleRenderTargets, SRGBTextures if( glES >= 3 ):
 			true;
 
 		case FloatTextures if( glES >= 3 ):
@@ -1222,6 +1232,9 @@ class GlDriver extends Driver {
 			gl.getExtension('OES_texture_float') != null && gl.getExtension('OES_texture_float_linear') != null &&
 			gl.getExtension('OES_texture_half_float') != null && gl.getExtension('OES_texture_half_float_linear') != null;
 
+		case SRGBTextures:
+			gl.getExtension('EXT_sRGB') != null;
+
 		case MultipleRenderTargets:
 			mrtExt != null || (mrtExt = gl.getExtension('WEBGL_draw_buffers')) != null;
 

+ 4 - 0
h3d/mat/Texture.hx

@@ -97,6 +97,10 @@ class Texture {
 			mem.allocTexture(this);
 	}
 
+	public function isSRGB() {
+		return format.match(SRGB | SRGB_ALPHA);
+	}
+
 	public function clone( ?allocPos : h3d.impl.AllocPos ) {
 		var old = lastFrame;
 		preventAutoDispose();

+ 2 - 0
hxd/PixelFormat.hx

@@ -9,4 +9,6 @@ enum PixelFormat {
 	ALPHA8;
 	ALPHA16F;
 	ALPHA32F;
+	SRGB;
+	SRGB_ALPHA;
 }

+ 2 - 2
hxd/Pixels.hx

@@ -374,7 +374,7 @@ class Pixels {
 	public static function bytesPerPixel( format : PixelFormat ) {
 		return switch( format ) {
 		case ALPHA8: 1;
-		case ARGB, BGRA, RGBA: 4;
+		case ARGB, BGRA, RGBA, SRGB, SRGB_ALPHA: 4;
 		case RGBA16F: 8;
 		case RGBA32F: 16;
 		case ALPHA16F: 2;
@@ -394,7 +394,7 @@ class Pixels {
 			[1, 2, 3, 0][channel.toInt()];
 		case BGRA:
 			[2, 1, 0, 3][channel.toInt()];
-		case RGBA:
+		case RGBA, SRGB, SRGB_ALPHA:
 			channel.toInt();
 		case RGBA16F:
 			channel.toInt() * 2;