Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

This beauty...

This topic is 2110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

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;
}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!