Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

template texture object as function parameter in sm4+

4: Adsense

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
3 replies to this topic

#1 zero_t98   Members   

130
Like
0Likes
Like

Posted 23 May 2012 - 04:19 PM

Hi,

In SM4 or above, we have


Texture Object (DirectX HLSL). Here is the syntax for creating all texture objects (except multisampled objects).
Object1 [<Type>] Name;

Suppose I want to write a function that takes a Texture2D parameter. What should the syntax look like?

Depends on the surface format, Texture2D could have many declarations like

Texture2D<int>

Texture2D<int2>

Texture2D<float>

Texture2D<float4> etc.

It is unrealistic to write functions for all possible combinations, say


MyFunc(Texture2D<int> tex2d)
MyFunc(Texture2D<int2> tex2d)
MyFunc(Texture2D<float> tex2d)
MyFunc(Texture2D<float4> tex2d)

ideally, I want something like
template<type>

MyFunc(Texture2D<type> tex2d){}

but it gives me errror message like
error X3000: syntax error: unexpected token 'template'

any idea? thank you very much for your help.

#2 MJP   Moderators   

19420
Like
1Likes
Like

Posted 23 May 2012 - 06:19 PM

You can't template functions in HLSL. The best that you could do is use macros, but that would be pretty ugly. So I'm afraid that you're out of luck on this one.

#3 pcmaster   Members   

956
Like
0Likes
Like

Posted 24 May 2012 - 07:09 AM

Will you ever need to call your function on ALL possible texture types? I don't believe. So every-time a need for a new type arises, add a new overload. That's about the best you can do, if you don't want a MACRO-hell. You'll have to hard-code them all.

#4 zero_t98   Members   

130
Like
0Likes
Like

Posted 24 May 2012 - 11:39 AM

hi pcmaster,

you raised a good point. and, I am writing a library for others to use. thus, I guess i have to handle all possiblities.

thank you,




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.