PDA

View Full Version : Geometry Shader crashing



ED_RockStarGuy
07-06-2016, 11:11 AM
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;
}

john_connor
07-06-2016, 12:38 PM
im using also glfw 3, and my graphics card supportd also OpenGL 4.5, and i dont get those errors, it compiles successfully

GClements
07-06-2016, 08:24 PM
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

Check that you are actually compiling this as a geometry shader, i.e. the shader was created with glCreateShader(GL_GEOMETRY_SHADER) and that shader is the one you're actually using (i.e. you didn't accidentally overwrite the name with that for a different shader, or pass the wrong name to glShaderSource(), or whatever).

ED_RockStarGuy
07-07-2016, 01:28 AM
Check that you are actually compiling this as a geometry shader, i.e. the shader was created with glCreateShader(GL_GEOMETRY_SHADER) and that shader is the one you're actually using (i.e. you didn't accidentally overwrite the name with that for a different shader, or pass the wrong name to glShaderSource(), or whatever).

I have checked and I am compiling as a Geometry shader and the source file is correct.

johnh
11-08-2016, 11:42 AM
I have checked and I am compiling as a Geometry shader and the source file is correct.

Have you had any luck fixing this? I am also getting the same error in a Geometry shader. I have also checked I am compiling a Geometry shader but agree that the error codes seem to say that it is not. I am using OpenGL 4.5 on NVIDIA hardware (latest drivers).