3
\$\begingroup\$

I keep getting some strange errors in my Geometry shader and when I search for the cause of the errors, it returns nothing substantial. Here is the code.

Shader

#version 450 core

layout(triangles) in;
layout(points, max_vertices = 3)out;

void main(void) {
    int i;
    for (i = 0; i < gl_in.length(); i++) {
        gl_Position = gl_in[i].gl_Position;
        EmitVertex();
    }
}

Log.

0(4) : error C3008: unknown layout specifier 'max_vertices = 3'
0(4) : error C3008: unknown layout specifier 'points'
0(10) : error C3004: function "void EmitVertex();" not supported in this profile

I'm using OpenGL 4.5 (My pc supports it before anyone asks :p) and and glfw 3.2

EDIT: Here is the steps I'm using to load up my shader.

Creating a shader instance:

shader = new StaticShader("VertexShader.shader", "TesselationControl.shader", 
"TessilationEvaluation.shader", "Geometry.shader", "FragmentShader.shader");

StaticShader Constructor

ShaderProgram::ShaderProgram(const char * vertex_file_path, const char * tesselation_controll_shader_path,
    const char * tesselation_evaluation_shader_path, const char * geometry_shader_path, const char * fragment_file_path) {
    vertexShaderID = loadShader(vertex_file_path, GL_VERTEX_SHADER);
    tessControllShaderID = loadShader(tesselation_controll_shader_path, GL_TESS_CONTROL_SHADER);
    tessEvaluationShaderID = loadShader(tesselation_evaluation_shader_path, GL_TESS_EVALUATION_SHADER);
    geometryShaderID = loadShader(geometry_shader_path, GL_GEOMETRY_SHADER);
    fragmentShaderID = loadShader(fragment_file_path, GL_FRAGMENT_SHADER);
    Status("ShaderProgram", "Initilizing shader program");
    programID = glCreateProgram();
    glAttachShader(programID, vertexShaderID);
    glAttachShader(programID, tessControllShaderID);
    glAttachShader(programID, tessEvaluationShaderID);
    glAttachShader(programID, geometryShaderID);
    glAttachShader(programID, fragmentShaderID);
    bindAttributes();
    glLinkProgram(programID);

    GLint isLinked = 0;
    glGetProgramiv(programID, GL_LINK_STATUS, (int *)&isLinked);
    if (isLinked == GL_FALSE) {

        GLint maxLength = 0;
        glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &maxLength);

        if (maxLength > 1) {
            GLchar* infoLog = (GLchar*)malloc(maxLength);
            glGetProgramInfoLog(programID, maxLength, &maxLength, &infoLog[0]);
            std::cout << infoLog;
        }

        StatusError();
        exit(0);
    }
    StatusOkay();

    //Clean Up
    glDetachShader(programID, vertexShaderID);
    glDetachShader(programID, tessControllShaderID);
    glDetachShader(programID, tessEvaluationShaderID);
    glDetachShader(programID, geometryShaderID);
    glDetachShader(programID, fragmentShaderID);

    glDeleteShader(vertexShaderID);
    glDeleteShader(tessControllShaderID);
    glDeleteShader(tessEvaluationShaderID);
    glDeleteShader(geometryShaderID);
    glDeleteShader(fragmentShaderID);
}

Load shader function:

GLuint ShaderProgram::loadShader(const char * file_path, int type) {
    GLuint shaderID = glCreateShader(type);
    std::string shaderCode = FileManager::readFile(file_path);
    char const * sourcePointer = shaderCode.c_str();
    Status("ShaderObject", "Compiling Shader " + std::string(file_path));
    glShaderSource(shaderID, 1, &sourcePointer, NULL);
    glCompileShader(shaderID);
    GLint isCompiled = 0;
    glGetShaderiv(shaderID, GL_COMPILE_STATUS, &isCompiled);
    if (isCompiled == GL_FALSE){

        GLint maxLength = 0;
        glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &maxLength);

        if (maxLength > 1) {
            GLchar* infoLog = (GLchar*)malloc(maxLength);
            glGetShaderInfoLog(shaderID, maxLength, &maxLength, &infoLog[0]);
            std::cout << infoLog;
        }

        StatusError();
        exit(0);
    }
    StatusOkay();
    return shaderID;
}
\$\endgroup\$
10
  • 1
    \$\begingroup\$ Are you sure you are requesting an OpenGL 4.5 core context from GLFW? \$\endgroup\$
    – user5665
    Jul 5, 2016 at 21:52
  • \$\begingroup\$ @MattJensJensen Yes I am, this is what i'm using; 'glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);' \$\endgroup\$
    – 0xen
    Jul 5, 2016 at 21:56
  • \$\begingroup\$ Hmm, what OS are you running (specific version is helpful)? GPU? and are you using GLEW? \$\endgroup\$
    – user5665
    Jul 5, 2016 at 21:58
  • \$\begingroup\$ @MattJensJensen I am using windows 10 Pro, I have tested the code on a computer using a GTX 1080 and a GTX 770, and I am using GLEW 1.13 \$\endgroup\$
    – 0xen
    Jul 5, 2016 at 22:05
  • \$\begingroup\$ The unknown layout specifiers also make me think that it's trying to compile it as something other than a geometry shader. Are you sure you used glCreateShader(GL_GEOMETRY_SHADER)? \$\endgroup\$
    – user5665
    Jul 5, 2016 at 22:06

0

You must log in to answer this question.

Browse other questions tagged .