How to texture2d setpixel ?

Hi.

I’m created 1920x1028 (FHD) texture.

i’m want many rectangle 2x2 (10k more?) and one draw call.

because 2x2 rectangle draw call 10k that is very slow. so I’am texture direct set pixel first draw 10k rectangle.

and one draw call. so only one draw call is very fast.

how can i do??? my think is possble ?

can i see example ? or tutorial ?

thank you.

Hi dongdong - I am not sure if I understand your problem correctly.

why is 2x2 = 10k more?

10.000 quads is no problem for modern hardware if done right

fyi: a texture should be a power of 2 for performance reasons

@dongdong 你是中国人吗?

@reiti.net I think dongdong means 2x2 pixel rectangle objects?

Hmm, Is this for static objects or moving objects? level or moving objects? I think the optimisation would depend on this question…

Well, a draw call for a 2x2px rectangle is actually less expensive as for a 200x200 rectangle. While the VertexShader does basically the same, the PixelShader needs less fill/work for the 2x2 quad.

It’s basically what particle systems do (but they use several optimizations like a fixed ring buffer for example - so as MrValentine said, optimization highly depends on what you want to achieve

你也是中国人吗???????????????

不, 与中国的悠久历史, 我说的语言很多。

Oh my god.!!!

Thank you ! Mr.Valentine.You are very kind.

Yes. my 2x2 rectangle is just example.
and i don’t need 3D(quad) object. just only 2D.(super fast…)

so i’m question setpixel.

because First. Big texture(1920x1080) create.

and texture setPixel (10x10 or 4x4 or …rectangle).

Last only one draw call texture.

This is example. i want many rectangle one draw.
I don’t need 3D. just 2D fast draw.

Thank you for your advice.

Thank you!! Mr reiti.net

I want this. many rectangle.
I don’t need 3D. just fast 2D draw Rectangle.

So. i am quetion setpixel.
Because Big Texture (1920x1080) creat.
And setPixel many rectangle.
Last draw big texture. So. only one draw texture. very fast.

This is example. I want this.

Thank you for your advice…

You can just render all that as you normally would, but render it to a RenderTarget2D - this single RenderTarget2D can then be used as a texture as often as you like. I guess this is what you want to do.

// do this once:
device.SetRenderTarget(mybigtex);
spriteBatch.Begin();
... 10.000 times 2x2 texture draws
spriteBatch.End();
device.SetRenderTarget(null);

// do this in consecutive calls
spriteBatch.Begin();
spriteBatch.Draw(mybigtex,...);
spriteBatch.End();

But you are always drawing 3D Quads - because it is actually way faster then traditional 2D (parallel processing in GPU)

1 Like