Jump to content
  • Advertisement
Sign in to follow this  
dave

How do i do this?

This topic is 5134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

for a test run i have 100 quads stored in a single vertex buffer, supposing i want to run through the vb and apply a different texture to each quad, how do i go about this?

Share this post


Link to post
Share on other sites
Advertisement
To my knowledge, the only way to do it is:


/* psuedocode */
vertex_buffer *vb;
int x;
int maxobjects;
textures texturearray[maxobjects];

for (x=0;x<maxobjects;x++){
settexture(texturearray[x]);
draw(vb+sizeof(object)*x , sizeof(1 * object) );
}

Share this post


Link to post
Share on other sites
I don't understand why this is hard at all.. You just split it up, or you call DP multiple times.

You're a programmer, not a follower. Think up your own ways, at least try.

Don't come to GDNet with every question that pops up. It's getting annoying.

Sorry to be rude, but I couldn't stand it.


[edit] Yeah rate me down, I don't care. [edit2](Not specifically at ace)

[Edited by - Pipo DeClown on August 28, 2004 4:14:49 AM]

Share this post


Link to post
Share on other sites

guiroot->d3ddev->SetStreamSource(0,tmp,0,sizeof(ro_d3d_vertex));
foo=guiroot->d3ddev->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);
foo=guiroot->d3ddev->SetTexture(0,tptr);
for (int m=0;m<lpcount;m++){
// render a 2 count triangle strip starting at vertex m*4
// [because there's 4 vertices per square, start at square 0...]
foo=guiroot->d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP,m*4,2);
}




This draws a bunch of textured quads all over the place. To change the texture per quad, move the SetTexture call inside the loop and change tptr.

tmp is the vertex buffer, lpcount is the number of quads.

[edit: oh, and actually do more error checking than I do :D ]

Share this post


Link to post
Share on other sites
What I did was, I batched as many textures into large ones depending on the remainder and D3DCAPS9 max texture size it supports, so it creates textures big enough and as few as possible. I then rendered by texture, and then by render states, for as few render calls as possible. I'm not sure if doing it the other way around is faster or not.
You just have to learn how to write to the texture surface for starters, and then plan out how you're going to get the things onto one texture (expect a gap on some texture dimensions depending on the sub textures!) because there aren't any resources that I know of that teaches how to do this.

Share this post


Link to post
Share on other sites
Depending on how many different textures there are, creating a single texture resource for each different texture and then just sorting your polygons by texture before rendering can be good enough. Once you start batching multiple textures onto a single resource, that should cut down on the state changes but it also means you have to introduce a bunch of extra classes and utilities just to manage this new "aggregate" texture, as well as adjust texture coordinates, etc. It's a hassle, and might not be worth it. But if every polygon in the scene has a different texture, and there are a lot of textures, you just might have to.

I was faced with a similar situation recently in regard to lightmaps. Each face had a different lightmap, and there were upward of 1000 polygons a scene after PVS and culling. Having a texture resource for each lightmap killed the application when it actually had to create and dispose these resources. Not only that, but the texture state changes themselves cost a lot. So I combined them into as large a texture I could. It made things more complicated, but increased performance drastically.

Share this post


Link to post
Share on other sites
Quote:
Original post by ace_lovegrove
idiot

get a mirror? no wait, get two and place them parallel to each other, stand between them and look at one of them.

Share this post


Link to post
Share on other sites
Quote:
Original post by ace_lovegrove
Pipo calm down, i dont ever ask here without having tried


Perhaps what he means to say is that you'll learn more if you spend more time thinking about the problem rather than asking someone else too soon.
You might also bennefit from taking the time to post in the right forum.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!