This beauty...

Started by
16 comments, last by wodinoneeye 10 years, 6 months ago

Just saw this beauty from some example code:


DXT3AlphaBlock compressDXT3Alpha(vec4 colors[16])
{
	DXT3AlphaBlock dxt3Alpha;

	unsigned int quantizedAlpha0 = quantize4(int(colors[0].w * 255.0 + .5));
	unsigned int quantizedAlpha1 = quantize4(int(colors[1].w * 255.0 + .5));
	unsigned int quantizedAlpha2 = quantize4(int(colors[2].w * 255.0 + .5));
	unsigned int quantizedAlpha3 = quantize4(int(colors[3].w * 255.0 + .5));
	unsigned int quantizedAlpha4 = quantize4(int(colors[4].w * 255.0 + .5));
	unsigned int quantizedAlpha5 = quantize4(int(colors[5].w * 255.0 + .5));
	unsigned int quantizedAlpha6 = quantize4(int(colors[6].w * 255.0 + .5));
	unsigned int quantizedAlpha7 = quantize4(int(colors[7].w * 255.0 + .5));
	dxt3Alpha.alphas[0] =
		quantizedAlpha0 << unsigned int(0) |
		quantizedAlpha1 << unsigned int(4) |
		quantizedAlpha2 << unsigned int(8) |
		quantizedAlpha3 << unsigned int(12) |
		quantizedAlpha4 << unsigned int(16) |
		quantizedAlpha5 << unsigned int(20) |
		quantizedAlpha6 << unsigned int(24) |
		quantizedAlpha7 << unsigned int(28);
	
	unsigned int quantizedAlpha8 = quantize4(int(colors[8].w * 255.0 + .5));
	unsigned int quantizedAlpha9 = quantize4(int(colors[9].w * 255.0 + .5));
	unsigned int quantizedAlpha10 = quantize4(int(colors[10].w * 255.0 + .5));
	unsigned int quantizedAlpha11 = quantize4(int(colors[11].w * 255.0 + .5));
	unsigned int quantizedAlpha12 = quantize4(int(colors[12].w * 255.0 + .5));
	unsigned int quantizedAlpha13 = quantize4(int(colors[13].w * 255.0 + .5));
	unsigned int quantizedAlpha14 = quantize4(int(colors[14].w * 255.0 + .5));
	unsigned int quantizedAlpha15 = quantize4(int(colors[15].w * 255.0 + .5));
	dxt3Alpha.alphas[1] =
		quantizedAlpha8 << unsigned int(0) |
		quantizedAlpha9 << unsigned int(4) |
		quantizedAlpha10 << unsigned int(8) |
		quantizedAlpha11 << unsigned int(12) |
		quantizedAlpha12 << unsigned int(16) |
		quantizedAlpha13 << unsigned int(20) |
		quantizedAlpha14 << unsigned int(24) |
		quantizedAlpha15 << unsigned int(28);
	
	return dxt3Alpha;
}

What do you think?

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement

Who ever coded that doesn't know what "funroll-all-loops" is :P and tried to achieve same result by hand.

Feel free to comment and star my project! <https://github.com/Ghrum/Ghrum>

Almost looks like ASCII art - is that a Death Star turret gun?

Almost looks like ASCII art - is that a Death Star turret gun?

Hah! Never saw that coming, but now when I look at it... huh.png

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Could be code generated by a tool, although it would be unusual to see that in sample code.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Hasn't really been all that many years since hand unrolling was a common practice. Still, it is pretty unusual to see it nowadays.

I actually find that the original version is more easily understood than doing it with loops tongue.png


DXT3AlphaBlock compressDXT3Alpha(vec4 colors[16])
{
	DXT3AlphaBlock dxt3Alpha;

	for( int j=0; j!=2; ++j )
	{
		unsigned int result = 0;
		for( int i=7; i>=0; --i )
		{
			unsigned int quantized = quantize4(int(colors[i+j*8].w * 255.0 + .5));
			result = result<<2 | quantized;
		}
		dxt3Alpha.alphas[j] = result;
	}

	return dxt3Alpha;
}

Not that bad. Probably about the same amount of time to write either way. More thought in a loop, more copypasta and speed typing in the unrolled version. Loop is quicker to edit later, but it doesn't look like the kind of thing that would ever need editing. I think it's more readable in the unrolled form.

Amateur. I've once dealt with code written... I think in Korea. The variables were numbered up to... like 74, in a convenient 800 LOC function.

Previously "Krohm"

Not that bad. Probably about the same amount of time to write either way. More thought in a loop, more copypasta and speed typing in the unrolled version. Loop is quicker to edit later, but it doesn't look like the kind of thing that would ever need editing. I think it's more readable in the unrolled form.

I agree, imo loop version is probably somewhat better for me but this is okay too

This topic is closed to new replies.

Advertisement