Jump to content


HLSL global variables


2 replies to this topic

#1 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1227 posts
  • LocationOttawa, Ontario, Canada

Posted 07 January 2010 - 02:47 PM

Hi all,

How can I declare global temporaries (i.e. variables accessible to all functions within a shader) in HLSL?

Trying to do this the straightforward way gives a compiler error. The manual also mentions that global variables are considered uniforms (i.e. shader constants). Is there any way to declare them to be temporaries? Is there some convenient alternative approach? I'm trying to translate some C/C++ to HLSL...

Thanks,

Nicolas

#2 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 07 January 2010 - 04:21 PM

Shouldn't the static modifier on a global be enough?

Quote

static - Mark a local variable so that it is initialized one time and persists between function calls. If the declaration does not include an initializer, the value is set to zero. A global variable marked static is not visible to an application.

.edit: just tried, static indeed seems to work :)
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#3 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1227 posts
  • LocationOttawa, Ontario, Canada

Posted 08 January 2010 - 01:00 PM

Excellent, thanks!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users