Sign in to follow this  

How do i do this?

This topic is 4861 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
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
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

This topic is 4861 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this