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

Variable index

Started by bdubreuil Jan 16, 2012 at 12:33 AM 2 replies 2.7k views
Original Post
bdubreuil
bdubreuil
Hi,

I am a beginner with hlsl and I'd like to know if you actually can do something like this, which is setting a global variable's index with another global scalar variable:


int t = 5;
float g[t];


If you can't do something like this in hlsl, then can you change the array to a greater or lower number through xna?

Thank you smile.png
Thecheeselover
Hide yo cheese! Hide yo wife!
ViperG
ViperG
You can do something like this:

#define Global 5;

float g[Global];
int t = Global;
int z = Global;
Black Sky A Star Control 2/Elite like game
MJP
MJP
Arrays in HLSL need to have a length that is static at compile time. So in other words..

// You can do this...
static const uint ArraySize = 5
float Array[ArraySize];

// Or you can do this...
#define ArraySize 5
float Array[ArraySize];

// But you can't do this
uint ArraySize = 5;
float Array[ArraySize];


Usually what you do, is you define the array to some maximum size and then set another variable to a value representing how many values to actually use from the array. Like this:

static const uint MaxValues = 5;
float Values[MaxValues];
uint NumValuesToUse;


Just be careful...depending on the shader profile you use the compiler's ability to represent loops in shader assembly may be limited.
bdubreuil
bdubreuil
Thank you both!
Hide yo cheese! Hide yo wife!

Topic Locked

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

Sign in to reply to this topic.