Skip to main content
GameDev.net gamedev.net
🔒 Locked

template texture object as function parameter in sm4+

Started by zero_t98 May 23, 2012 at 10:19 PM 2 replies 1.5k views
Original Post
zero_t98
zero_t98
Hi,

In SM4 or above, we have


Texture Object (DirectX HLSL). Here is the syntax for creating all texture objects (except multisampled objects).
Object1 [] 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

Texture2D

Texture2D

Texture2D etc.

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


MyFunc(Texture2D tex2d)
MyFunc(Texture2D tex2d)
MyFunc(Texture2D tex2d)
MyFunc(Texture2D tex2d)

ideally, I want something like
template

MyFunc(Texture2D tex2d){}

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

any idea? thank you very much for your help.
MJP
MJP
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.
pcmaster
pcmaster
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.
zero_t98
zero_t98
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,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.