“当前GLSL版本中没有变量”

时间:2014-10-17 10:08:06

标签: opengl glsl lwjgl

我正在尝试创建曲面细分着色器:

#version 410 core                                                                               

// define the number of CPs in the output patch                                                 
layout (vertices = 3) out;                                                                      

uniform vec3 gEyeWorldPos;                                                                      

// attributes of the input CPs                                                                  
in vec3 WorldPos_CS_in[];                                                                       
in vec2 TexCoord_CS_in[];                                                                       
in vec3 Normal_CS_in[];                                                                         

// attributes of the output CPs                                                                 
out vec3 WorldPos_ES_in[];                                                                      
out vec2 TexCoord_ES_in[];                                                                      
out vec3 Normal_ES_in[];                                                                        

float GetTessLevel(float Distance0, float Distance1)                                            
{                                                                                               
float AvgDistance = (Distance0 + Distance1) / 2.0;                                          

if (AvgDistance <= 2.0) {                                                                   
    return 10.0;                                                                            
}                                                                                           
else if (AvgDistance <= 5.0) {                                                              
    return 7.0;                                                                             
}                                                                                           
else {                                                                                      
    return 3.0;                                                                             
}                                                                                           
}                                                                                               

void main()                                                                                     
{                                                                                               
// Set the control points of the output patch                                               
TexCoord_ES_in[gl_InvocationID] = TexCoord_CS_in[gl_InvocationID];                          
Normal_ES_in[gl_InvocationID]   = Normal_CS_in[gl_InvocationID];                            
WorldPos_ES_in[gl_InvocationID] = WorldPos_CS_in[gl_InvocationID];                          

// Calculate the distance from the camera to the three control points                       
float EyeToVertexDistance0 = distance(gEyeWorldPos, WorldPos_ES_in[0]);                     
float EyeToVertexDistance1 = distance(gEyeWorldPos, WorldPos_ES_in[1]);                     
float EyeToVertexDistance2 = distance(gEyeWorldPos, WorldPos_ES_in[2]);                     

// Calculate the tessellation levels                                                        
gl_TessLevelOuter[0] = GetTessLevel(EyeToVertexDistance1, EyeToVertexDistance2);            
gl_TessLevelOuter[1] = GetTessLevel(EyeToVertexDistance2, EyeToVertexDistance0);            
gl_TessLevelOuter[2] = GetTessLevel(EyeToVertexDistance0, EyeToVertexDistance1);            
gl_TessLevelInner[0] = gl_TessLevelOuter[2];                                                
}

然而,当我运行游戏时,我收到以下错误:

Error: 1281
Tessellation shader wasn't able to be compiled correctly. Error log:
ERROR: 0:? : '' :  Incorrect GLSL version: 410
WARNING: -1:65535: 'GL_ARB_explicit_attrib_location' :  extension is not available in current GLSL          version
WARNING: 0:4: 'vertices' : symbol not available in current GLSL version 
WARNING: 0:? : 'gl_InvocationID' : variable is not available in current GLSL version 
WARNING: 0:? : 'gl_InvocationID' : variable is not available in current GLSL version 
WARNING: 0:? : 'gl_InvocationID' : variable is not available in current GLSL version 
WARNING: 0:? : 'gl_InvocationID' : variable is not available in current GLSL version 
WARNING: 0:? : 'gl_InvocationID' : variable is not available in current GLSL version 
WARNING: 0:? : 'gl_InvocationID' : variable is not available in current GLSL version 
WARNING: 0:? : 'gl_TessLevelOuter' : variable is not available in current GLSL version 
WARNING: 0:? : 'gl_TessLevelOuter' : variable is not available in current GLSL version 
WARNING: 0:? : 'gl_TessLevelOuter' : variable is not available in current GLSL version 
WARNING: 0:? : '

我的游戏似乎忽略了着色器,但我想这会有很多错误吗? enter image description here

我已经尝试了googling the error,但我无法找到任何解决方案,甚至无法找到有关原因的信息。

如何修复上述错误,以便我的着色器可以正常运行?

1 个答案:

答案 0 :(得分:0)

嗯,你可能没有开始使用OpenGL-4.1核心上下文,因此你的着色器不会编译。我建议您不要调试着色器,而是仔细查看您的上下文创建代码,并仔细检查您的系统是否可以为您提供4.1版本的上下文。