Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualChr1sen

Posted 01 January 2013 - 06:53 AM

Thanks. I got everything working now.

It's a shame that I really didn't see people use the "Pitch" property. I guess they are mostly dealing textures that have the Pitch same as Source width.
 

		/// <summary>
		/// Copies content into destinationBuffer.
		/// </summary>
		/// <param name="texture">actual texture </param>
		/// <param name="contentToCopy">source bfufer</param>
		/// <param name="sourcePitch">source stride</param>
		private static void CopyToTexture(Texture texture, byte[] contentToCopy, int sourcePitch)
		{
			var data = texture.LockRectangle(0, LockFlags.Discard);
			var y = 0;

			for (var scanLineStart = 0; scanLineStart < contentToCopy.Length; scanLineStart += sourcePitch, y++)
			{
				data.Data.WriteRange(contentToCopy, scanLineStart, sourcePitch);
				data.Data.Seek((y + 1)*data.Pitch, SeekOrigin.Begin);
			}

			texture.UnlockRectangle(0);
		}

 


And if anyone is interested, then I ended up using this for my YUV->RGB shader:
http://subversion.assembla.com/svn/AvP/branches/workbranch/trunk/shaders/fmvPixel.psh

though I am thinking about writing my own shader that could use only one sampler2D, so I could pass packed YUV formats directly into the GPU. Though I am not sure where to begin. Is that even a good idea? The texture is defintely gonna be huge as hell though.


#2Chr1sen

Posted 01 January 2013 - 06:52 AM

Thanks. I got everything working now.

It's a shame that I really didn't see people use the "Pitch" property. I guess they are mostly dealing textures that have the Pitch same as Source width.


/// <summary>		/// Copies content into destinationBuffer.		/// </summary>		/// <param name="texture">actual texture </param>		/// <param name="contentToCopy">source bfufer</param>		/// <param name="sourceStride">source stride</param>		private void CopyToTexture(Texture texture, byte[] contentToCopy, int sourceStride)		{			var data = texture.LockRectangle(0, LockFlags.Discard);			var y = 0;				for (var scanLineStart = 0; scanLineStart < contentToCopy.Length; scanLineStart += sourceStride, y++)			{				data.Data.WriteRange(contentToCopy, scanLineStart, sourceStride);				data.Data.Seek((y+1)*data.Pitch, SeekOrigin.Begin);			}			texture.UnlockRectangle(0);		}



And if anyone is interested, then I ended up using this for my YUV->RGB shader:
http://subversion.assembla.com/svn/AvP/branches/workbranch/trunk/shaders/fmvPixel.psh

though I am thinking about writing my own shader that could use only one sampler2D, so I could pass packed YUV formats directly into the GPU. Though I am not sure where to begin. Is that even a good idea? The texture is defintely gonna be huge as hell though.

#1Chr1sen

Posted 01 January 2013 - 06:28 AM

Thanks. I got everything working now.

 

It's a shame that I really didn't see people use the "Pitch" property. I guess they are mostly dealing textures that have the Pitch same as Source width.

 

 

 

		/// <summary>
		/// Copies content into destinationBuffer.
		/// </summary>
		/// <param name="texture">actual texture </param>
		/// <param name="contentToCopy">source bfufer</param>
		/// <param name="sourceStride">source stride</param>
		private void CopyToTexture(Texture texture, byte[] contentToCopy, int sourceStride)
		{
			var data = texture.LockRectangle(0, LockFlags.Discard);
			var y = 0;

				for (var scanLineStart = 0; scanLineStart < contentToCopy.Length; scanLineStart += sourceStride, y++)
			{
				data.Data.WriteRange(contentToCopy, scanLineStart, sourceStride);
				data.Data.Seek(y*data.Pitch, SeekOrigin.Begin);
			}

			texture.UnlockRectangle(0);
		}

 

There is just a little problem left. I am getting weird artifacts(green) when SourceStride == texturePitch. And sometimes they are even jumbling, mumbling around. I believe I am forgetting to fill something in here.

 

So I added the condition:

 

			if (data.Pitch == sourceStride)
			{
				data.Data.WriteRange(contentToCopy, 0, contentToCopy.Length);
				texture.UnlockRectangle(0);
				return;
			} 

 

and it fixed the green lines, though I still don't understand what did I do wrong.

 

 

 

And if anyone is interested, then I ended up using this for my YUV->RGB shader:

http://subversion.assembla.com/svn/AvP/branches/workbranch/trunk/shaders/fmvPixel.psh

 

though I am thinking about writing my own shader that could use only one sampler2D, so I could pass packed YUV formats directly into the GPU. Though I am not sure where to begin. Is that even a good idea? The texture is defintely gonna be huge as hell though. 

 

 

 


PARTNERS