0

I have a program set up with deferred rendering. I am in the process of removing my position texture in favour of reconstructing positions from depth. I have done this before with no trouble but now for some reason I am getting a segfault when trying to access matrices I pass in through uniforms!

My fragment shader (vertex shader irrelevant):

#version 430 core

layout(location = 0) uniform sampler2D depth;
layout(location = 1) uniform sampler2D diffuse;
layout(location = 2) uniform sampler2D normal;
layout(location = 3) uniform sampler2D specular;

layout(location = 4) uniform mat4 view_mat;
layout(location = 5) uniform mat4 inv_view_proj_mat;

layout(std140) uniform light_data{
    // position ect, works fine
} light;

in vec2 uv_f;

vec3 recontruct_pos(){
    float z = texture(depth, uv_f);
    vec4 pos = vec4(uv_f * 2.0 - 1.0, z * 2.0 - 1.0, 1.0);

    //pos = inv_view_proj_mat * pos; //un-commenting this line causes segfault

    return pos.xyz / pos.w;
}

layout(location = 3) out vec4 lit; // location 3 is lighting texture

void main(){
    vec3 pos = reconstruct_pos();
    lit = vec4(0.0, 1.0, 1.0, 1.0); // just fill screen with light blue
}

And as you can see the code causing this segfault is shown in the reconstruct_pos() function.

Why is this causing a segfault? I have checked the data within the application, it is correct.


EDIT:

The code I use to update my matrix uniforms:

// bind program

glUniformMatrix4fv(4, 1, GL_FALSE, &view_mat[0][0]);
glUniformMatrix4fv(5, 1, GL_FALSE, &inv_view_proj_mat[0][0]);

// do draw calls
RamblingMad
  • 5,332
  • 2
  • 24
  • 48

2 Answers2

0

The problem was my call to glBindBufferBase when allocating my light buffer. Now that I have corrected the arguments I am passing, everything works fine with no segfaults.

Now the next question is: Why are all of my uniform locations reporting to be -1 O_o Maybe it's the default location, who knows.

RamblingMad
  • 5,332
  • 2
  • 24
  • 48
  • `glGetUniformLocation()` returns `-1` if the name was not found. Are you calling it after the program is linked? Do the names match the variable names in your shaders? – Reto Koradi May 15 '14 at 13:59
  • Please ask separate questions as separate questions. The comments system isn't made for answering questions. – Colonel Thirty Two May 15 '14 at 14:57
  • @ColonelThirtyTwo I wasn't literally asking a question. If you look at my statement you can clearly see that it's a closed question, with me answering it "who knows". – RamblingMad May 15 '14 at 15:05
  • Except, as Reto Koradi pointed out, it actually has significance, and is not purely rhetorical. – Colonel Thirty Two May 15 '14 at 15:17
  • @ColonelThirtyTwo I suppose, but I still hold that it isn't literally a question :L – RamblingMad May 15 '14 at 15:19
0

glUniformMatrix() method expects the input data be a flattened array with column major order (i.e. float array[16];), not a two-dimensional array (i.e. float array[4][4]). The latter may cause you either a segfault or a program malfunction, due to the 4 single-dimensional arrays composing the 2-dimensional array not being located sequentially.