| 
									
										
										
										
											2013-04-17 23:09:55 -04:00
										 |  |  | // Copyright 2013 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include <cmath>
 | 
					
						
							|  |  |  | #include <cstdio>
 | 
					
						
							| 
									
										
										
										
											2009-10-14 01:58:39 +00:00
										 |  |  | #include <locale.h>
 | 
					
						
							| 
									
										
										
										
											2013-06-15 13:21:57 +02:00
										 |  |  | #ifdef __APPLE__
 | 
					
						
							|  |  |  | 	#include <xlocale.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-09-03 19:24:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 12:38:29 +13:00
										 |  |  | #include "Common/MathUtil.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "VideoCommon/BPMemory.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-19 02:27:20 +01:00
										 |  |  | #include "VideoCommon/RenderBase.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "VideoCommon/TextureConversionShader.h"
 | 
					
						
							|  |  |  | #include "VideoCommon/TextureDecoder.h"
 | 
					
						
							|  |  |  | #include "VideoCommon/VideoConfig.h"
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define WRITE p+=sprintf
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char text[16384]; | 
					
						
							| 
									
										
										
										
											2009-10-25 02:35:21 +00:00
										 |  |  | static bool IntensityConstantAdded =  false; | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace TextureConversionShader | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | u16 GetEncodedSampleCount(u32 format) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-24 09:21:54 -04:00
										 |  |  | 	switch (format) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	case GX_TF_I4: return 8; | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	case GX_TF_I8: return 4; | 
					
						
							|  |  |  | 	case GX_TF_IA4: return 4; | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	case GX_TF_IA8: return 2; | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	case GX_TF_RGB565: return 2; | 
					
						
							|  |  |  | 	case GX_TF_RGB5A3: return 2; | 
					
						
							|  |  |  | 	case GX_TF_RGBA8: return 1; | 
					
						
							|  |  |  | 	case GX_CTF_R4: return 8; | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	case GX_CTF_RA4: return 4; | 
					
						
							|  |  |  | 	case GX_CTF_RA8: return 2; | 
					
						
							|  |  |  | 	case GX_CTF_A8: return 4; | 
					
						
							|  |  |  | 	case GX_CTF_R8: return 4; | 
					
						
							|  |  |  | 	case GX_CTF_G8: return 4; | 
					
						
							|  |  |  | 	case GX_CTF_B8: return 4; | 
					
						
							|  |  |  | 	case GX_CTF_RG8: return 2; | 
					
						
							|  |  |  | 	case GX_CTF_GB8: return 2; | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	case GX_TF_Z8: return 4; | 
					
						
							|  |  |  | 	case GX_TF_Z16: return 2; | 
					
						
							|  |  |  | 	case GX_TF_Z24X8: return 1; | 
					
						
							|  |  |  | 	case GX_CTF_Z4: return 8; | 
					
						
							|  |  |  | 	case GX_CTF_Z8M: return 4; | 
					
						
							|  |  |  | 	case GX_CTF_Z8L: return 4; | 
					
						
							|  |  |  | 	case GX_CTF_Z16L: return 2; | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	default: return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | // block dimensions : widthStride, heightStride
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | // texture dims : width, height, x offset, y offset
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-25 16:19:08 +01:00
										 |  |  | 	// left, top, of source rectangle within source texture
 | 
					
						
							|  |  |  | 	// width of the destination rectangle, scale_factor (1 or 2)
 | 
					
						
							| 
									
										
										
										
											2014-01-05 09:52:26 +01:00
										 |  |  | 	WRITE(p, "uniform int4 position;\n"); | 
					
						
							| 
									
										
										
										
											2013-01-14 12:37:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-04 12:38:01 +01:00
										 |  |  | 	int blkW = TexDecoder_GetBlockWidthInTexels(format); | 
					
						
							|  |  |  | 	int blkH = TexDecoder_GetBlockHeightInTexels(format); | 
					
						
							|  |  |  | 	int samples = GetEncodedSampleCount(format); | 
					
						
							| 
									
										
										
										
											2014-02-24 16:15:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	if (ApiType == API_OPENGL) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-01-19 00:39:31 +01:00
										 |  |  | 		WRITE(p, "#define samp0 samp9\n"); | 
					
						
							| 
									
										
										
										
											2014-06-07 00:29:21 -05:00
										 |  |  | 		WRITE(p, "SAMPLER_BINDING(9) uniform sampler2D samp0;\n"); | 
					
						
							| 
									
										
										
										
											2010-07-12 19:30:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-03 20:56:24 +02:00
										 |  |  | 		WRITE(p, "  out vec4 ocol0;\n"); | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 		WRITE(p, "void main()\n"); | 
					
						
							| 
									
										
										
										
											2010-07-12 19:30:25 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-22 18:07:21 +02:00
										 |  |  | 	else // D3D
 | 
					
						
							| 
									
										
										
										
											2010-07-12 19:30:25 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-09-22 18:07:21 +02:00
										 |  |  | 		WRITE(p,"sampler samp0 : register(s0);\n"); | 
					
						
							|  |  |  | 		WRITE(p, "Texture2D Tex0 : register(t0);\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 		WRITE(p,"void main(\n"); | 
					
						
							| 
									
										
										
										
											2013-11-25 15:01:18 +01:00
										 |  |  | 		WRITE(p,"  out float4 ocol0 : SV_Target)\n"); | 
					
						
							| 
									
										
										
										
											2010-07-12 19:30:25 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-22 18:07:21 +02:00
										 |  |  | 	WRITE(p, "{\n" | 
					
						
							| 
									
										
										
										
											2013-11-25 15:49:13 +01:00
										 |  |  | 	"  int2 sampleUv;\n" | 
					
						
							| 
									
										
										
										
											2013-11-25 16:34:08 +01:00
										 |  |  | 	"  int2 uv1 = int2(gl_FragCoord.xy);\n" | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2013-11-25 15:49:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-25 16:06:55 +01:00
										 |  |  | 	WRITE(p, "  int y_block_position = uv1.y & %d;\n", ~(blkH - 1)); | 
					
						
							|  |  |  | 	WRITE(p, "  int y_offset_in_block = uv1.y & %d;\n", blkH - 1); | 
					
						
							| 
									
										
										
										
											2014-02-24 16:15:44 +01:00
										 |  |  | 	WRITE(p, "  int x_virtual_position = (uv1.x << %d) + y_offset_in_block * position.z;\n", Log2(samples)); | 
					
						
							| 
									
										
										
										
											2014-02-25 16:06:55 +01:00
										 |  |  | 	WRITE(p, "  int x_block_position = (x_virtual_position >> %d) & %d;\n", Log2(blkH), ~(blkW - 1)); | 
					
						
							| 
									
										
										
										
											2014-02-24 16:15:44 +01:00
										 |  |  | 	if (samples == 1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-02-26 12:48:52 +01:00
										 |  |  | 		// 32 bit textures (RGBA8 and Z24) are stored in 2 cache line increments
 | 
					
						
							| 
									
										
										
										
											2014-02-24 16:15:44 +01:00
										 |  |  | 		WRITE(p, "  bool first = 0 == (x_virtual_position & %d);\n", 8 * samples); // first cache line, used in the encoders
 | 
					
						
							|  |  |  | 		WRITE(p, "  x_virtual_position = x_virtual_position << 1;\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-25 16:06:55 +01:00
										 |  |  | 	WRITE(p, "  int x_offset_in_block = x_virtual_position & %d;\n", blkW - 1); | 
					
						
							|  |  |  | 	WRITE(p, "  int y_offset = (x_virtual_position >> %d) & %d;\n", Log2(blkW), blkH - 1); | 
					
						
							| 
									
										
										
										
											2013-11-25 15:49:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-24 16:15:44 +01:00
										 |  |  | 	WRITE(p, "  sampleUv.x = x_offset_in_block + x_block_position;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  sampleUv.y = y_block_position + y_offset;\n"); | 
					
						
							| 
									
										
										
										
											2014-02-25 22:21:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WRITE(p, "  float2 uv0 = float2(sampleUv);\n");                // sampleUv is the sample position in (int)gx_coords
 | 
					
						
							|  |  |  | 	WRITE(p, "  uv0 += float2(0.5, 0.5);\n");                      // move to center of pixel
 | 
					
						
							| 
									
										
										
										
											2014-02-26 12:48:52 +01:00
										 |  |  | 	WRITE(p, "  uv0 *= float(position.w);\n");                     // scale by two if needed (also move to pixel borders so that linear filtering will average adjacent pixel)
 | 
					
						
							|  |  |  | 	WRITE(p, "  uv0 += float2(position.xy);\n");                   // move to copied rect
 | 
					
						
							|  |  |  | 	WRITE(p, "  uv0 /= float2(%d, %d);\n", EFB_WIDTH, EFB_HEIGHT); // normalize to [0:1]
 | 
					
						
							|  |  |  | 	if (ApiType == API_OPENGL)                                     // ogl has to flip up and down
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		WRITE(p, "  uv0.y = 1.0-uv0.y;\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-25 22:21:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-22 15:48:26 -05:00
										 |  |  | 	WRITE(p, "  float sample_offset = float(position.w) / float(%d);\n", EFB_WIDTH); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteSampleColor(char*& p, const char* colorComp, const char* dest, int xoffset, API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-25 22:21:15 +01:00
										 |  |  | 	WRITE(p, "  %s = texture(samp0, uv0 + float2(%d, 0) * sample_offset).%s;\n", | 
					
						
							|  |  |  | 		dest, xoffset, colorComp | 
					
						
							| 
									
										
										
										
											2013-11-25 15:49:13 +01:00
										 |  |  | 	); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteColorToIntensity(char*& p, const char* src, const char* dest) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	if (!IntensityConstantAdded) | 
					
						
							| 
									
										
										
										
											2009-10-25 02:35:21 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		WRITE(p, "  float4 IntensityConst = float4(0.257f,0.504f,0.098f,0.0625f);\n"); | 
					
						
							|  |  |  | 		IntensityConstantAdded = true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-12-19 21:05:41 +00:00
										 |  |  | 	WRITE(p, "  %s = dot(IntensityConst.rgb, %s.rgb);\n", dest, src); | 
					
						
							|  |  |  | 	// don't add IntensityConst.a yet, because doing it later is faster and uses less instructions, due to vectorization
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-04 12:38:01 +01:00
										 |  |  | 	WRITE(p, "  %s = floor(%s * 255.0 / exp2(8.0 - %d.0));\n", dest, src, depth); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteEncoderEnd(char*& p, API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-10-25 02:35:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	WRITE(p, "}\n"); | 
					
						
							|  |  |  | 	IntensityConstantAdded = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteI8Encoder(char*& p, API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_TF_I8, ApiType); | 
					
						
							| 
									
										
										
										
											2013-09-22 18:07:21 +02:00
										 |  |  | 	WRITE(p, "  float3 texSample;\n"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "ocol0.b"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "ocol0.g"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 2, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "ocol0.r"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 3, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "ocol0.a"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-19 21:05:41 +00:00
										 |  |  | 	WRITE(p, "  ocol0.rgba += IntensityConst.aaaa;\n"); // see WriteColorToIntensity
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteI4Encoder(char*& p, API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_TF_I4, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  float3 texSample;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color1;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color0.b"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color1.b"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 2, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color0.g"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 3, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color1.g"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 4, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color0.r"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 5, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color1.r"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 6, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color0.a"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "texSample", 7, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color1.a"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-19 21:05:41 +00:00
										 |  |  | 	WRITE(p, "  color0.rgba += IntensityConst.aaaa;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.rgba += IntensityConst.aaaa;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteToBitDepth(p, 4, "color0", "color0"); | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 4, "color1", "color1"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0 = (color0 * 16.0 + color1) / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteIA8Encoder(char*& p,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_TF_IA8, ApiType); | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | 	WRITE(p, "  float4 texSample;\n"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  ocol0.b = texSample.a;\n"); | 
					
						
							|  |  |  | 	WriteColorToIntensity(p, "texSample", "ocol0.g"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  ocol0.r = texSample.a;\n"); | 
					
						
							|  |  |  | 	WriteColorToIntensity(p, "texSample", "ocol0.a"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-19 21:05:41 +00:00
										 |  |  | 	WRITE(p, "  ocol0.ga += IntensityConst.aa;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteIA4Encoder(char*& p,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_TF_IA4, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  float4 texSample;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color1;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.b = texSample.a;\n"); | 
					
						
							|  |  |  | 	WriteColorToIntensity(p, "texSample", "color1.b"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.g = texSample.a;\n"); | 
					
						
							|  |  |  | 	WriteColorToIntensity(p, "texSample", "color1.g"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 2, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.r = texSample.a;\n"); | 
					
						
							|  |  |  | 	WriteColorToIntensity(p, "texSample", "color1.r"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 3, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.a = texSample.a;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 09:00:43 +00:00
										 |  |  | 	WriteColorToIntensity(p, "texSample", "color1.a"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-19 21:05:41 +00:00
										 |  |  | 	WRITE(p, "  color1.rgba += IntensityConst.aaaa;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteToBitDepth(p, 4, "color0", "color0"); | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 4, "color1", "color1"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0 = (color0 * 16.0 + color1) / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteRGB565Encoder(char*& p,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_TF_RGB565, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgb", "float3 texSample0", 0, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, "rgb", "float3 texSample1", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2011-12-07 22:47:13 -06:00
										 |  |  | 	WRITE(p, "  float2 texRs = float2(texSample0.r, texSample1.r);\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float2 texGs = float2(texSample0.g, texSample1.g);\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float2 texBs = float2(texSample0.b, texSample1.b);\n"); | 
					
						
							| 
									
										
										
										
											2013-09-22 18:07:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-19 21:05:41 +00:00
										 |  |  | 	WriteToBitDepth(p, 6, "texGs", "float2 gInt"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  float2 gUpper = floor(gInt / 8.0);\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float2 gLower = gInt - gUpper * 8.0;\n"); | 
					
						
							| 
									
										
										
										
											2010-12-19 21:05:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 5, "texRs", "ocol0.br"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.br = ocol0.br * 8.0 + gUpper;\n"); | 
					
						
							| 
									
										
										
										
											2010-12-19 21:05:41 +00:00
										 |  |  | 	WriteToBitDepth(p, 5, "texBs", "ocol0.ga"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.ga = ocol0.ga + gLower * 32.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0 = ocol0 / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteRGB5A3Encoder(char*& p,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_TF_RGB5A3, ApiType); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WRITE(p, "  float4 texSample;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float color0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float gUpper;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float gLower;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	// 0.8784 = 224 / 255 which is the maximum alpha value that can be represented in 3 bits
 | 
					
						
							|  |  |  | 	WRITE(p, "if(texSample.a > 0.878f) {\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 5, "texSample.g", "color0"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  gUpper = floor(color0 / 8.0);\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  gLower = color0 - gUpper * 8.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 5, "texSample.r", "ocol0.b"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.b = ocol0.b * 4.0 + gUpper + 128.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 	WriteToBitDepth(p, 5, "texSample.b", "ocol0.g"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.g = ocol0.g + gLower * 32.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "} else {\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WriteToBitDepth(p, 4, "texSample.r", "ocol0.b"); | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 4, "texSample.b", "ocol0.g"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WriteToBitDepth(p, 3, "texSample.a", "color0"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "ocol0.b = ocol0.b + color0 * 16.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 	WriteToBitDepth(p, 4, "texSample.g", "color0"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "ocol0.g = ocol0.g + color0 * 16.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "}\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "if(texSample.a > 0.878f) {\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 5, "texSample.g", "color0"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  gUpper = floor(color0 / 8.0);\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  gLower = color0 - gUpper * 8.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 5, "texSample.r", "ocol0.r"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.r = ocol0.r * 4.0 + gUpper + 128.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WriteToBitDepth(p, 5, "texSample.b", "ocol0.a"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.a = ocol0.a + gLower * 32.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "} else {\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WriteToBitDepth(p, 4, "texSample.r", "ocol0.r"); | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 4, "texSample.b", "ocol0.a"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WriteToBitDepth(p, 3, "texSample.a", "color0"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "ocol0.r = ocol0.r + color0 * 16.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 	WriteToBitDepth(p, 4, "texSample.g", "color0"); | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "ocol0.a = ocol0.a + color0 * 16.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "}\n"); | 
					
						
							| 
									
										
										
										
											2009-03-22 03:25:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0 = ocol0 / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteRGBA8Encoder(char*& p,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-25 16:19:08 +01:00
										 |  |  | 	WriteSwizzler(p, GX_TF_RGBA8, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WRITE(p, "  float4 texSample;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color1;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 	WRITE(p, "  color0.b = texSample.a;\n"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.g = texSample.r;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.b = texSample.g;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.g = texSample.b;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "rgba", "texSample", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 	WRITE(p, "  color0.r = texSample.a;\n"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.a = texSample.r;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.r = texSample.g;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.a = texSample.b;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-13 12:10:17 +01:00
										 |  |  | 	WRITE(p, "  ocol0 = first ? color0 : color1;\n"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteC4Encoder(char*& p, const char* comp,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_CTF_R4, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  float4 color0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color1;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, comp, "color0.b", 0, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "color1.b", 1, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "color0.g", 2, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "color1.g", 3, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "color0.r", 4, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "color1.r", 5, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "color0.a", 6, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "color1.a", 7, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 4, "color0", "color0"); | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 4, "color1", "color1"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0 = (color0 * 16.0 + color1) / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteC8Encoder(char*& p, const char* comp,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_CTF_R8, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, comp, "ocol0.b", 0, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "ocol0.g", 1, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "ocol0.r", 2, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "ocol0.a", 3, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteCC4Encoder(char*& p, const char* comp,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_CTF_RA4, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  float2 texSample;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float4 color1;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, comp, "texSample", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.b = texSample.x;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.b = texSample.y;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, comp, "texSample", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.g = texSample.x;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.g = texSample.y;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, comp, "texSample", 2, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.r = texSample.x;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.r = texSample.y;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, comp, "texSample", 3, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	WRITE(p, "  color0.a = texSample.x;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  color1.a = texSample.y;\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 4, "color0", "color0"); | 
					
						
							|  |  |  | 	WriteToBitDepth(p, 4, "color1", "color1"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0 = (color0 * 16.0 + color1) / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteCC8Encoder(char*& p, const char* comp, API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_CTF_RA8, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, comp, "ocol0.bg", 0, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, comp, "ocol0.ra", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteZ8Encoder(char*& p, const char* multiplier,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	WriteSwizzler(p, GX_CTF_Z8M, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, " float depth;\n"); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth", 2, ApiType); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth", 3, ApiType); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:04:37 -06:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteZ16Encoder(char*& p,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WriteSwizzler(p, GX_TF_Z16, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "  float depth;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float3 expanded;\n"); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	// byte order is reversed
 | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  depth *= 16777215.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  expanded.r = floor(depth / (256.0 * 256.0));\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  depth -= expanded.r * 256.0 * 256.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  expanded.g = floor(depth / 256.0);\n"); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.b = expanded.g / 255.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  ocol0.g = expanded.r / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  depth *= 16777215.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  expanded.r = floor(depth / (256.0 * 256.0));\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  depth -= expanded.r * 256.0 * 256.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  expanded.g = floor(depth / 256.0);\n"); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.r = expanded.g / 255.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  ocol0.a = expanded.r / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteZ16LEncoder(char*& p,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WriteSwizzler(p, GX_CTF_Z16L, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "  float depth;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float3 expanded;\n"); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	// byte order is reversed
 | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth", 0, ApiType); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  depth *= 16777215.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  expanded.r = floor(depth / (256.0 * 256.0));\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  depth -= expanded.r * 256.0 * 256.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  expanded.g = floor(depth / 256.0);\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  depth -= expanded.g * 256.0;\n"); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "  expanded.b = depth;\n"); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  ocol0.b = expanded.b / 255.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  ocol0.g = expanded.g / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "  depth *= 16777215.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  expanded.r = floor(depth / (256.0 * 256.0));\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  depth -= expanded.r * 256.0 * 256.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  expanded.g = floor(depth / 256.0);\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  depth -= expanded.g * 256.0;\n"); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "  expanded.b = depth;\n"); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-12 13:32:06 +13:00
										 |  |  | 	WRITE(p, "  ocol0.r = expanded.b / 255.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  ocol0.a = expanded.g / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-08 14:29:26 +02:00
										 |  |  | static void WriteZ24Encoder(char*& p, API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-25 16:19:08 +01:00
										 |  |  | 	WriteSwizzler(p, GX_TF_Z24X8, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WRITE(p, "  float depth0;\n"); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "  float depth1;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float3 expanded0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "  float3 expanded1;\n"); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-25 17:01:35 +01:00
										 |  |  | 	WriteSampleColor(p, "b", "depth0", 0, ApiType); | 
					
						
							|  |  |  | 	WriteSampleColor(p, "b", "depth1", 1, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	for (int i = 0; i < 2; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 		WRITE(p, "  depth%i *= 16777215.0;\n", i); | 
					
						
							| 
									
										
										
										
											2009-12-02 04:17:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 		WRITE(p, "  expanded%i.r = floor(depth%i / (256.0 * 256.0));\n", i, i); | 
					
						
							|  |  |  | 		WRITE(p, "  depth%i -= expanded%i.r * 256.0 * 256.0;\n", i, i); | 
					
						
							|  |  |  | 		WRITE(p, "  expanded%i.g = floor(depth%i / 256.0);\n", i, i); | 
					
						
							|  |  |  | 		WRITE(p, "  depth%i -= expanded%i.g * 256.0;\n", i, i); | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WRITE(p, "  expanded%i.b = depth%i;\n", i, i); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-11 00:30:55 +13:00
										 |  |  | 	WRITE(p, "  if (!first) {\n"); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	// upper 16
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "     ocol0.b = expanded0.g / 255.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "     ocol0.g = expanded0.b / 255.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "     ocol0.r = expanded1.g / 255.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "     ocol0.a = expanded1.b / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "  } else {\n"); | 
					
						
							|  |  |  | 	// lower 8
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 	WRITE(p, "     ocol0.b = 1.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "     ocol0.g = expanded0.r / 255.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "     ocol0.r = 1.0;\n"); | 
					
						
							|  |  |  | 	WRITE(p, "     ocol0.a = expanded1.r / 255.0;\n"); | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	WRITE(p, "  }\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WriteEncoderEnd(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-05-15 02:39:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 19:30:25 +00:00
										 |  |  | const char *GenerateEncodingShader(u32 format,API_TYPE ApiType) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-16 14:34:23 +02:00
										 |  |  | #ifndef ANDROID
 | 
					
						
							| 
									
										
										
										
											2014-03-09 21:14:26 +01:00
										 |  |  | 	locale_t locale = newlocale(LC_NUMERIC_MASK, "C", nullptr); // New locale for compilation
 | 
					
						
							| 
									
										
										
										
											2013-06-15 13:21:57 +02:00
										 |  |  | 	locale_t old_locale = uselocale(locale); // Apply the locale for this thread
 | 
					
						
							| 
									
										
										
										
											2013-06-16 14:34:23 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	text[sizeof(text) - 1] = 0x7C;  // canary
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	char *p = text; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 	switch (format) | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	case GX_TF_I4: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteI4Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_I8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteI8Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_IA4: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteIA4Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_IA8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteIA8Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_RGB565: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteRGB565Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_RGB5A3: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteRGB5A3Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_RGBA8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteRGBA8Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-03-22 09:00:43 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	case GX_CTF_R4: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteC4Encoder(p, "r", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_RA4: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteCC4Encoder(p, "ar", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_RA8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteCC8Encoder(p, "ar", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_A8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteC8Encoder(p, "a", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_R8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteC8Encoder(p, "r", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_G8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteC8Encoder(p, "g", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_B8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteC8Encoder(p, "b", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_RG8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteCC8Encoder(p, "rg", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_GB8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteCC8Encoder(p, "gb", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_Z8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteC8Encoder(p, "b", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_Z16: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteZ16Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_TF_Z24X8: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteZ24Encoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_Z4: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteC4Encoder(p, "b", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_Z8M: | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 		WriteZ8Encoder(p, "256.0", ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_Z8L: | 
					
						
							| 
									
										
										
										
											2013-10-06 03:12:13 -05:00
										 |  |  | 		WriteZ8Encoder(p, "65536.0" , ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case GX_CTF_Z16L: | 
					
						
							| 
									
										
										
										
											2011-12-26 00:15:54 -05:00
										 |  |  | 		WriteZ16LEncoder(p, ApiType); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-22 09:00:43 +00:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 		PanicAlert("Unknown texture copy format: 0x%x\n", format); | 
					
						
							| 
									
										
										
										
											2013-09-22 18:07:21 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (text[sizeof(text) - 1] != 0x7C) | 
					
						
							|  |  |  | 		PanicAlert("TextureConversionShader generator - buffer too small, canary has been eaten!"); | 
					
						
							| 
									
										
										
										
											2013-09-22 18:07:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-16 14:34:23 +02:00
										 |  |  | #ifndef ANDROID
 | 
					
						
							| 
									
										
										
										
											2013-06-15 13:21:57 +02:00
										 |  |  | 	uselocale(old_locale); // restore locale
 | 
					
						
							|  |  |  | 	freelocale(locale); | 
					
						
							| 
									
										
										
										
											2013-06-16 14:34:23 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-03-19 21:51:12 -04:00
										 |  |  | 	return text; | 
					
						
							| 
									
										
										
										
											2009-02-23 06:15:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace
 |