c++ - DirectX Game LPD3DX9Sprite Rendering Slow -
hey trying build 2d engine in c++ can handle thousands of sprites @ time using directx sdl. heard lpd3dx9sprite efficient , coming xna style familiar me. doing performance testing, batching multiple sprites (same texture , settings) in 1 time. however, there seems issues performance , idk why.
void draw() { graphics::direct3d_device->clear(1, null, d3dclear_target, d3dcolor_argb(255, 0, 0, 0), 0, 0); graphics::direct3d_device->beginscene(); graphics::spritebatch->begin(d3dxsprite_alphablend); string fs = std::to_string(fps); (int = 0; < 1000; i++) test.draw(); drawtextstring(32, 64, fs.c_str()); graphics::spritebatch->end(); graphics::direct3d_device->endscene(); graphics::direct3d_device->present(null, null, null, null); }
this draw code calls function calls drawmethod of lpd3dx9sprite object. nothing else going on in game drawing code.
according fps counter getting 4fps. vsync enabled slowdown occurs regardless. there can this?
i find odd simple test game in c++ no real logic crawling compared full game engine in c# runs flawlessly many sprites rendering.
it's fair culprit:
for (int = 0; < 1000; i++) test.draw();
along contents of test.draw();
, claim be:
graphics::spritebatch->draw(texture, &sourcerect, &originpos, &d3dxvector3(position.x,position.y,0), color);
despite fact relatively simple command, it's quite expensive command have push graphics card over-and-over-and-over. don't know underlying mechanics of library you're using, when commands written this, evokes style of coding in opengl1.x, vertices , textures streamed graphics card they're needed, rather preloading them , calling commands draw preloaded vertices. need research whether library has capacity load data onto graphics card ahead of time using vertex buffer objects , other similar constructs.
if doesn't, you'll need learn , implement concepts yourself.
also:
i heard lpd3dx9sprite efficient...
generally speaking, situation you're using directx9 is, definition, not going fast. not unless you're using feature set of dx10 , dx11, in case, there's no reason using dx9 features in first place.
Comments
Post a Comment