Texture Lock very slow

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
PhilK
Posts: 5
Joined: Mon Dec 15, 2003 1:00 pm

Texture Lock very slow

Post by PhilK »

I need to update a texture dynamically for real time video streaming.
I have successfully done this in Direct3D directly without much performance decreas, although video streaming needs heavy thread syncronization.

Unfortunatly calling ITexture:lock() & ITexture:unlock() in irrlich is very slow.
I have created a 32Bit texture and fill it every render loop with buffered video stream data. I do not write to the texture in a different thread, so that cannot be the problem.

I have modified Direct3D device creation inside irrlich to support Multithreading though.

I have also disabled mip maps on the texture I want to draw into.
Without locking the texture I get about 500fps, if I lock it and just unlock it right away the framerate drops to 37fps.

The prefered texture creation bit depth is set to 32bits.

:?

Is that a known issue? Or am I doing something wrong?

Thanks for your help!
Phil
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

As you can see in the code (hope you use 0.4.2), the Lock() and Unlock() work like the Direct3D versions, there is almost no overhead. The OpenGL version, however is slower, because the texture is copied after unlocking it.
PhilK
Posts: 5
Joined: Mon Dec 15, 2003 1:00 pm

Post by PhilK »

Thanks for your fast reply Niko.
First of all let me tell you I really appreciate the strict and clean OOD design of your engine.

I will have to dig deeper in the D3D implementation of it to find the reason for the problem. Maybe I create the D3D device or textures in a very different way than you do. Also I dont see why it is neccesary to create IImage and copy the (empty) image onto the texture when I call "addTexture". Is there any reason for that?

So far I see no differences in your code and the directx9 sample code i use for reference testing. The only difference is that the swap effect used. But I dont see that has any relevance in windowed mode.

Keep up the work!
Phil
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

PhilK wrote:Also I dont see why it is neccesary to create IImage and copy the (empty) image onto the texture when I call "addTexture". Is there any reason for that?
You're right, there is no reason. If you want to create an empty texture, just use addTexture(const core::dimension2d< s32 > & size, const c8 * name);
johnjones
Posts: 5
Joined: Sun Sep 05, 2004 1:12 am

Post by johnjones »

How do you alter an image after you lock it?

I want to write a 2d game that uses simple actor-world collision detection by checking the color of pixels in a bitmap used as a level mask. I think I can just use IImage and getPixel (x, y) and check the color, certain colors for passable or unpassable. But I also want to be able to add walls or destroy them while in the game. How could I edit this bitmap in game? I know I can lock the bitmap and get a pointer to it, but what do I do after that if say I wanted to draw a line or circle in it?
stampsm
Posts: 142
Joined: Mon Nov 10, 2003 5:52 pm
Location: Las Vegas

Post by stampsm »

i wouldn't use a bitmap for that. it looks like you are trying to create a map of 2d coordinates that are used to check for a specified attribute at those coordinates. when you use a bitmap it has to take the input then encode it in the proper format to be stored in the image and them possibly transfer that data to the video card. the best method would be to use a 2d array to store ints that is used to check what is at that coordinate. this way you do not have to call lock on the bitmap and you can access the needed info directly.
Post Reply