Jump to content

  • Log In with Google      Sign In   
  • Create Account


How do you manipulate individual pixels in a texture in Direct3D on the CPU?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Veil   Members   -  Reputation: 143

Like
0Likes
Like

Posted 31 May 2012 - 03:35 PM

I know that in Allegro it's

BITMAP* tex[10];
int& pixel(BITMAP* bmp, int x, int y)
{
    return ((int**)(bmp->line))[y][x];
}

but what's the syntax for this in DirectX?

Sponsor:

#2 jamby   Members   -  Reputation: 147

Like
0Likes
Like

Posted 31 May 2012 - 03:42 PM

You need to call Map() on the texture to get access to the texture data. Don't forget to call Unmap() afterwards. You will have had to create the texture with the proper flags to be able to write to the texture.

ID3D10Texture2D

#3 Veil   Members   -  Reputation: 143

Like
0Likes
Like

Posted 31 May 2012 - 03:43 PM

You need to call Map() on the texture to get access to the texture data. Don't forget to call Unmap() afterwards. You will have had to create the texture with the proper flags to be able to write to the texture.

ID3D10Texture2D


wait will this work on directx 9?

edit:IDirect3DTexture9 has LockRect() method,but I'm not sure exactly how to use it,could someone explain it's arguments:

[in]   UINT Level,
  [out]  D3DLOCKED_RECT *pLockedRect,
  [in]   const RECT *pRect,
  [in]   DWORD Flags

Edited by Bogomil, 31 May 2012 - 04:08 PM.


#4 mhagain   Crossbones+   -  Reputation: 6328

Like
1Likes
Like

Posted 31 May 2012 - 04:40 PM

Map/Unmap are only present in D3D10 and 11, and - yes - the OP did tag the question as [D3D9].

For LockRect you should look at the documentation in the SDK - also available here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205913%28v=vs.85%29.aspx

If you have any specific questions about it's usage (which can differ depending on what exactly you're trying to achieve), it would be best to ask them after reading the documentation and experimenting a little with it.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 jamby   Members   -  Reputation: 147

Like
0Likes
Like

Posted 31 May 2012 - 05:52 PM

the OP did tag the question as [D3D9].


Hmm...sorry. Never saw any tag because they don't show on the "Interesting Topics" list on the home page where I saw the thread.

#6 hupsilardee   Members   -  Reputation: 485

Like
0Likes
Like

Posted 31 May 2012 - 07:07 PM

Also be wary that it won't let you LockRect on textures that were created in the default pool, or created - D3D9 is full of these little special cases and corner cases and vendor-specific features and the nightmare that is D3DCAPS9, thank goodness for D3D10+ restoring sanity to the API

#7 InvalidPointer   Members   -  Reputation: 1270

Like
0Likes
Like

Posted 31 May 2012 - 08:10 PM

Since this hasn't been asked yet, I'll go ahead and bite the bullet: What Are You Doing, Really? Any time the subject of CPU readbacks come up, there's like a 90% chance a better way to do what you're trying to accomplish exists.

Edited by InvalidPointer, 31 May 2012 - 08:10 PM.

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#8 Veil   Members   -  Reputation: 143

Like
0Likes
Like

Posted 31 May 2012 - 09:25 PM

Since this hasn't been asked yet, I'll go ahead and bite the bullet: What Are You Doing, Really? Any time the subject of CPU readbacks come up, there's like a 90% chance a better way to do what you're trying to accomplish exists.


Well,I have a server program that sends to the client a data struct with info for the current terrain piece.The info is generated randomly by the server and sent to the client,so I want the client to draw a terrain blendmap with the info from the received struct and then use the blendmap in the shader.This only happens when the client receives a new terrain piece(the player walks into a new zone)or when he burns the ground or something.Still it's not every frame,so I suppose it shouldn't cause a noticeable slowdown?

#9 Bacterius   Crossbones+   -  Reputation: 7009

Like
0Likes
Like

Posted 31 May 2012 - 09:39 PM


Since this hasn't been asked yet, I'll go ahead and bite the bullet: What Are You Doing, Really? Any time the subject of CPU readbacks come up, there's like a 90% chance a better way to do what you're trying to accomplish exists.


Well,I have a server program that sends to the client a data struct with info for the current terrain piece.The info is generated randomly by the server and sent to the client,so I want the client to draw a terrain blendmap with the info from the received struct and then use the blendmap in the shader.This only happens when the client receives a new terrain piece(the player walks into a new zone)or when he burns the ground or something.Still it's not every frame,so I suppose it shouldn't cause a noticeable slowdown?

The client really should be the one generating this stuff, sending actual assets over the network isn't the best use of bandwidth (of course, maybe you have something different in mind, but from what you said it sounds like an overly complicated method to do things)

"The best comment is a deleted comment."


#10 Veil   Members   -  Reputation: 143

Like
0Likes
Like

Posted 31 May 2012 - 09:51 PM

The client really should be the one generating this stuff, sending actual assets over the network isn't the best use of bandwidth (of course, maybe you have something different in mind, but from what you said it sounds like an overly complicated method to do things)


The thing is,the terrain must be persistent and stay on the server and during the game players can affect and change it from time to time,but it's not really a problem - each zone has a tileset and each tileset has 8 different terrain types,so that's 0-7(3 bits for the tile type) and same for the tileset - 8 tileset types.

The point is I have to get the client to turn this received info into a blendmap pixel by pixel when receiving the terrain chunk data.

Edited by Bogomil, 31 May 2012 - 09:54 PM.


#11 InvalidPointer   Members   -  Reputation: 1270

Like
0Likes
Like

Posted 01 June 2012 - 08:45 PM

Dumb idea, but you could try drawing a point list for all updated tiles. This won't introduce any pipeline bubbles but could conceivably do the scattered write you want.

(I assume the blendmap is a 1:1 texel:tile map)

Edited by InvalidPointer, 01 June 2012 - 08:47 PM.

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS