Jump to content

  • Log In with Google      Sign In   
  • Create Account

Help on reducing DrawPrimitive calls


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Intimidated   Members   -  Reputation: 107

Like
0Likes
Like

Posted 04 September 2012 - 10:07 AM

Hi folks.

I'm rather new to DirectX/Direct3D and i'm in the planning stage of my project.

Put simply, my question is:

Is it possible in either DirectX 9 (or a more recent version of the api) to draw a cube with a different texture on each face, using less than 6 DrawPrimitive calls?

In more detail:

I'm building an application which will involve large numbers of cubes, each with different textures on each face. I am concerned that this will involve a huge number of DrawPrimitive calls and it'll cause a huge bottleneck.

Sponsor:

#2 BCullis   Members   -  Reputation: 1683

Like
1Likes
Like

Posted 04 September 2012 - 10:17 AM

Why not put all 6 textures on a single texture map/atlas, and assign uv coordinates to the cube face triangles accordingly? Are you talking about 6 total textures, or 6 * number of cubes total textures?

Also, your large number of cubes problem sounds like a perfect situation for instancing.
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#3 Intimidated   Members   -  Reputation: 107

Like
0Likes
Like

Posted 04 September 2012 - 11:50 AM

Unfortunately these textures would be user provided content, so atlasing isn't possible unless I precompiled them, and I'm not sure I can justify that cost.

Is it possible to use multiple different textures on instanced objects?

#4 quiSHADgho   Members   -  Reputation: 324

Like
1Likes
Like

Posted 04 September 2012 - 12:02 PM

You could use texture arrays so you could provide each face with an index to access the right texture. But as far as I know you will be limited by the maximum number of textures your graphics card can support at one time. I don't how many textures can be handled by todays cards, mine is supporting 8. So if you make sure not to use more than six at a time there should be no problem.

#5 Intimidated   Members   -  Reputation: 107

Like
0Likes
Like

Posted 05 September 2012 - 05:28 AM

Thanks for your reply, quiSHADgho.

However, I can't find anything on google which suggests how to implement the method you mention.

Of course I can make an array of textures, but how do I feed them into DirectX?

Apologies if i'm being stupid or blind :) Thanks again!

#6 Hodgman   Moderators   -  Reputation: 14301

Like
1Likes
Like

Posted 05 September 2012 - 06:16 AM

Texture arrays were added in DX10/11, which allow you to create an "array texture", out of many individual 2D images -- this is a separate kind of texture to a regular 2D texture (not just an array of regular textures). When sampling from the "array texture", the z component of the tex-coord selects which 'slice' of the array to use.

On DX9, texture arrays aren't supported so atlassing is usually used instead. Even if your textures are dynamic, you can generate the atlas at runtime - e.g. just render each of your sub-textures into a larger texture at the appropriate locations.

Edited by Hodgman, 05 September 2012 - 06:27 AM.


#7 quiSHADgho   Members   -  Reputation: 324

Like
1Likes
Like

Posted 05 September 2012 - 09:10 AM

In DX9 you can still use six single textures and a sampler array and access it with an index.

This is from one of my shaders:
Texture Layer1;
Texture Layer2;
Texture Layer3;
Texture Layer4;
sampler LayerSampler[4] = {
sampler_state { texture = <Layer1>; magfilter = Linear; minfilter = Linear; mipfilter = Point; AddressU = clamp; AddressV = clamp;},
sampler_state { texture = <Layer2>; magfilter = Linear; minfilter = Linear; mipfilter = Point; AddressU = clamp; AddressV = clamp;},
sampler_state { texture = <Layer3>; magfilter = Linear; minfilter = Linear; mipfilter = Point; AddressU = clamp; AddressV = clamp;},
sampler_state { texture = <Layer4>; magfilter = Linear; minfilter = Linear; mipfilter = Point; AddressU = clamp; AddressV = clamp;}};

Edited by quiSHADgho, 05 September 2012 - 09:12 AM.


#8 CC Ricers   Members   -  Reputation: 623

Like
1Likes
Like

Posted 05 September 2012 - 09:41 AM

I would second the recommendation to atlas your textures at runtime if texture arrays aren't available. It's not expensive to do once for each cube and you're just limited by the max texture resolution the API supports. (I commonly use texture atlasing for shadow mapping and those textures are updated each frame.)
My development blog: Electronic Meteor




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS