Problem in D3D textures plz help

Started by
9 comments, last by circlesoft 17 years, 9 months ago
I am using managed direct3d with c#. I loaded a bitmap in texture Texture t=new Texture(Device,bitmap,Usage,Pool); Then i need to change some pixels in the texture, i noticed that I should change what i want in the bitmap and load it again with the same function(above). I worked but too slow. The second solution i found is using saving the bitmap into memorystream and loading the texture from it. Bitmap bmp; MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); ms.Seek(0, 0); Texture texture = TextureLoader.FromStream(device, ms); It also worked but when the bitmap is big, it is too slow.. is there a way to access the image data in the texture directly ? If someone knows plz respond ASAP, thnx.
Advertisement
Look into the Texture::LockRectangle(...) function. There are some contraints to using it. The Texture must be created with the Usage.Dynamic flag, for instance.

I'm not sure if that forces it out of video memory or not. If it doesn't work or is still too slow, try Device::UpdateSurface(...) or Device::UpdateTexture(...).

Sorry if that's no help. I'm not too familiar with managed direct X.
thnx for response, but i am afraid the problem is not solved. If use

Texture t;
t.LockRectangle(level,LockFlags);

what should i do then ?

or if i use Surface, how should i use it with texture ? plz tell me how..

and also i dont know what to do with updatesurface,

device.UpdateSurface(sourcesurface, destinationsurface);

or UpdateTexture(...) plz helps ASAP, thnx..
I need help plz
I need response urgently plz
Quote:Original post by radiationz
thnx for response, but i am afraid the problem is not solved. If use

Texture t;
t.LockRectangle(level,LockFlags);

what should i do then ?

or if i use Surface, how should i use it with texture ? plz tell me how..

Look at the docs for this function. Depending on which overload you use, you get back a GraphicsStream of pixels or an Array of them. You modify that data as you wish, then call UnlockRectangle()

Btw, you can only bump after 24 hours.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
well that's nice, but how can i use GraphicsStream ? how can i change pixels in the image stored in the graphics stream ?
Well i want to know how to read or write from GraphicsStream or Array that is returned from LockRectangle(...), actually i want to use Graphics class functions like DrawEllipse(...) on it . plz some one help ASAP, thnx.
Here's an example from the sdk documentation that uses a graphics stream to alter a vertex buffer. The Lock function of the Texture class is the same basic concept, hopefully this will get you going in the right direction.

using System;using Microsoft.DirectX;using Microsoft.DirectX.Direct3D;public struct PositionNormalTexVertex{	public Vector3 Position;	public Vector3 Normal;	public  float Tu0, Tv0;	public static readonly VertexFormats FVF = VertexFormats.Position | VertexFormats.Texture1;}public class Example{	public unsafe void  GraphicsStreamReadWrite()	{		//Create a vertex buffer in the managed pool		VertexBuffer vb = new VertexBuffer(typeof(PositionNormalTexVertex), 100, device, Usage.None, PositionNormalTexVertex.FVF, Pool.Managed);		//First, fill an array of PositionNormalTexVertex elements with data.		PositionNormalTexVertex[] vertices = new PositionNormalTexVertex[50];		for(int i=0; i<50; i++)		{			//fill the vertices with some data...			vertices.Position = new Vector3(3f,4f,5f);		}		//The size of the verticies are 32-bytes each (float3 (12) + float3 (12) + float(4) + float(4))		//To lock 50 verticies, the size of the lock would be 1600 (32 * 50)		GraphicsStream vbData =  vb.Lock(0,1600, LockFlags.None);		//copy the vertex data into the vertex buffer		vbData.Write(vertices);		//Unlock the VB		vb.Unlock();		//This time, lock the entire VertexBuffer		vbData =  vb.Lock(0, 3200, LockFlags.None);		//Cast the InternalDataPointer (a void pointer) to an array of verticies		PositionNormalTexVertex* vbArray = (PositionNormalTexVertex*) vbData.InternalDataPointer;		for(int i=0; i<100; i++)		{			//perform some operations on the data			vbArray.Tu0 = i;			vbArray.Tv0 = vbArray.Tu0 * 2;			Console.WriteLine(vbArray.Tv0.ToString());		}		//Unlock the buffer		vb.Unlock();		vb.Dispose();	}}
what is the fastest way to load a bitmap into a texture ? plz respond ASAP

This topic is closed to new replies.

Advertisement