0

I have a project that's been working fine using floats, and I've changed it to use doubles instead of floats, and it doesn't work anymore. I've got a feeling it's maybe the layout of my Vertex, and now the Vertex has 3 position doubles, 3 normal doubles, and 2 texCoord floats. Does the following image look like this is a vertex layout/stride/size issue? Looks strange to me.

enter image description here

Here is my Vertex struct:

struct Vertex
{
    glm::dvec3 position;   // 24 bytes 
    glm::dvec3 normal;     // 24 bytes
    glm::vec2 texCoords;   // 8 bytes
};  On the CPU there is no padding. Shader side there would be for a block, but for attributes I don't think it matters.

My vertex shader looks like this:

layout (location = 0) in dvec3 position;         
layout (location = 2) in dvec3 vertNormal;
layout (location = 4) in vec2 vertTexCoords;
layout (location = 0) out dvec3 fragWorldPos;
layout (location = 2) out dvec3 fragNormal;
layout (location = 4) out vec2 fragTexCoords;

My fragment shader:

layout (location = 0) flat in dvec3 fragWorldPos;
layout (location = 2) flat in dvec3 fragNormal;
layout (location = 4) in vec2 fragTexCoords;
layout (location = 5) out vec4 outFragColour;

And my vertex attributes:

glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 56, (void*)nullptr);
    glEnableVertexAttribArray(0);

    glVertexAttribPointer(1 (should be 2?), 3, GL_DOUBLE, GL_FALSE, 56, (void*)(3 * sizeof(double)));
    glEnableVertexAttribArray(1); //Should be ?

    glVertexAttribPointer(2 (should be 4?), 2, GL_FLOAT, GL_FALSE, 56, (void*)(48));
    glEnableVertexAttribArray(2); //Should be ? 

It basically looks like what happens when you're graphics card is about to die. It flickers a lot.

Zebrafish
  • 11,682
  • 3
  • 43
  • 119
  • Offtopic - what is this fancy debug GUI? – Starl1ght Nov 28 '16 at 10:17
  • @Starl1ght It's called ImGUI, it's one of the more popular immediate mode GUIs, fairly minimal, simple, and good for what it is, but I'm not a fan of the whole immediate mode thing. Can you recommend any good ones? I haven't tried AntTweak bar. Eventually I'll want something prettier and with more features for a game. – Zebrafish Nov 28 '16 at 10:23
  • @TitoneMaurice: you are not sending any 64bit floats to the shader, you are telling the GL to convert it to float first, and accessing that as a `dvec` is just undefined behavior. See for example [this question](http://stackoverflow.com/questions/10823811/glsl-double-precision-vertex-buffer) and [this question](http://stackoverflow.com/questions/28014864/why-different-variations-of-glvertexattribpointer-do-exist) for details. – derhass Nov 28 '16 at 19:09

1 Answers1

0
  1. location in vertex shader must match glVertexAttribPointer and glEnableVertexAttribArray. So, vertex shader must be edited.

  2. afaik, you should not specify location for out argument in vertex shader and for any arguments in fragment shader, they should be just passed as-is by name.

Starl1ght
  • 4,422
  • 1
  • 21
  • 49
  • Thank you. The reason I'm using location explicitly is because I'm using separate programs bound to a pipeline object. I think it's a more new feature that let's you mix and match different shader programs, and the matching rules are a bit different. So the location must match the vertexAttrib functions? Because in the docs they call it the index. That's good to know. I changed it but it didn't fix the problem. I didn't change it in the shader because in the shader they need to be 0, 2 and 4, as dvec takes two locations. This is really hard. – Zebrafish Nov 28 '16 at 10:56
  • 1
    yep, match it in vertexAttrib function then. – Starl1ght Nov 28 '16 at 10:58
  • Have you used Vulkan? I know Vulkan is harder than OpenGL, but just between you and me, I'm not particularly fond of OpenGL. – Zebrafish Nov 28 '16 at 11:09
  • @TitoneMaurice never used it, but afaik, Vulkan is far more complex, since it exposes a lot of low-level stuff, hidden in OpenGL – Starl1ght Nov 28 '16 at 11:38
  • @Starl1ght: "*you should not specify location for out argument in vertex shader and for any arguments in fragment shader, they should be just passed as-is by name.*" Nonsense. [Interfaces can match by location too](https://www.opengl.org/wiki/Shader_Compilation#Interface_matching), given an appropriate OpenGL version. Not to mention, FS output locations [have to be mapped to color attachments](https://www.opengl.org/wiki/Fragment_Shader#Output_buffers), so specifying them is rather important. – Nicol Bolas Nov 28 '16 at 15:59