简体   繁体   中英

Does this look like a vertex attribute/layout issue?

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.

在此处输入图片说明

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.

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM