<p>Assuming you use this structure within an actual UBO (which your example code doesn't do), just use an array of <code>ivec4</code> and two indices.</p>

<pre><code>const ivec3 cluster_max = ivec3(16, 8, 8);
const int cluster_max_lights = 4;

const int plix_count = cluster_max.x * cluster_max.y * cluster_max.z * cluster_max_lights;
const int plix_index_size = pl_count / 4;

const int plpt_count = cluster_max.x * cluster_max.y * cluster_max.z;
const int plpt_index_size = plpt_count / 4;

struct GlobalShaderData
{
    ivec4 pointLightIndices[plix_index_size];
    ivec4 pointLightsPerTile[plpt_index_size];
};

layout(std140) uniform shaderData
{
    GlobalShaderData globalShaderData;
};
</code></pre>

<p>To access a value from the arrays, you will have to divide the index by 4 to get the <code>ivec4</code> index, then take the original index mod 4 and use that to index the <code>ivec4</code>.
To get the </p>

CC BY-SA 4.0
2020-06-08T04:06:26.570Z
2020-06-08T04:06:26.570Z
Nicol Bolas
<p>I have following structure which i use as an uniform buffer object.</p>

<pre><code>struct GlobalShaderData
{
    #define CLUSTER_X_MAX 16
    #define CLUSTER_Y_MAX 8
    #define CLUSTER_Z_MAX 8
    #define CLUSTER_MAX_LIGHTS 4
    int pointLightIndices[CLUSTER_X_MAX * CLUSTER_Y_MAX * CLUSTER_Z_MAX * CLUSTER_MAX_LIGHTS];
    int pointLightsPerTile[CLUSTER_X_MAX * CLUSTER_Y_MAX * CLUSTER_Z_MAX];
};
GlobalShaderData globalShaderData;
</code></pre>

<p>The total size of the first int array should be 4 bytes * 16 * 8 * 8 * 4 = 16384 bytes, thus the maximum ubo memory is not exceeded.</p>

<p>However, when compiling the shaders I receive an "out of resource" error message.</p>

<p>I guess the integer actually takes 16 bytes on the glsl side to align with a vec4.
Because if we calculate with 16 bytes * 16 * 8 * 8 * 4 = 65536 bytes, which just exceedes the maximum capacity.</p>

<p>What are my options to have an smaller integer array on glsl side.</p>

<p>(I know that I could use other storage buffers but thats not relevant to the question.)</p>

CC BY-SA 4.0
2020-06-08T04:03:53.760Z
"*thus the maximum ubo memory is not exceeded.*" That's not a UBO; your `globalShaderData` variable isn't even a uniform.
Nicol Bolas
CC BY-SA 4.0
2020-06-09T10:21:14.803Z
That is true. It is the c++ side structure, I should have made it more clear.
MrRabbit
<opengl><glsl><memory><uniform-buffer-object>
Force int array to compact memory
MrRabbit
# Force int array to compact memory

(Asked by: username_0 on 2020-06-07)

I have following structure which i use as an uniform buffer object.

```
struct GlobalShaderData
{
    #define CLUSTER_X_MAX 16
    #define CLUSTER_Y_MAX 8
    #define CLUSTER_Z_MAX 8
    #define CLUSTER_MAX_LIGHTS 4
    int pointLightIndices[CLUSTER_X_MAX * CLUSTER_Y_MAX * CLUSTER_Z_MAX * CLUSTER_MAX_LIGHTS];
    int pointLightsPerTile[CLUSTER_X_MAX * CLUSTER_Y_MAX * CLUSTER_Z_MAX];
};
GlobalShaderData globalShaderData;

```

The total size of the first int array should be 4 bytes \* 16 \* 8 \* 8 \* 4 = 16384 bytes, thus the maximum ubo memory is not exceeded.

However, when compiling the shaders I receive an "out of resource" error message.

I guess the integer actually takes 16 bytes on the glsl side to align with a vec4.
Because if we calculate with 16 bytes \* 16 \* 8 \* 8 \* 4 = 65536 bytes, which just exceedes the maximum capacity.

What are my options to have an smaller integer array on glsl side.

(I know that I could use other storage buffers but thats not relevant to the question.)

**Tags:** opengl, glsl, memory, uniform-buffer-object

> **Comments:**
> **username_1**: "*thus the maximum ubo memory is not exceeded.*" That's not a UBO; your `globalShaderData` variable isn't even a uniform.  
> **username_0**: That is true. It is the c++ side structure, I should have made it more clear.  

---

## 1 answers

### Answer by username_1 on 2020-06-08. Score: 0 | Accepted answer

Assuming you use this structure within an actual UBO (which your example code doesn't do), just use an array of `ivec4` and two indices.

```
const ivec3 cluster_max = ivec3(16, 8, 8);
const int cluster_max_lights = 4;

const int plix_count = cluster_max.x * cluster_max.y * cluster_max.z * cluster_max_lights;
const int plix_index_size = pl_count / 4;

const int plpt_count = cluster_max.x * cluster_max.y * cluster_max.z;
const int plpt_index_size = plpt_count / 4;

struct GlobalShaderData
{
    ivec4 pointLightIndices[plix_index_size];
    ivec4 pointLightsPerTile[plpt_index_size];
};

layout(std140) uniform shaderData
{
    GlobalShaderData globalShaderData;
};

```

To access a value from the arrays, you will have to divide the index by 4 to get the `ivec4` index, then take the original index mod 4 and use that to index the `ivec4`.
To get the


---

